| Flutter Linux Embedder |

fl_value_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_value.h"
6
7 #include <gmodule.h>
8
9 #include <cmath>
10 #include "gtest/gtest.h"
11
12 TEST(FlDartProjectTest, Null) {
13 g_autoptr(FlValue) value = fl_value_new_null();
14 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_NULL);
15 }
16
17 TEST(FlValueTest, NullEqual) {
18 g_autoptr(FlValue) value1 = fl_value_new_null();
19 g_autoptr(FlValue) value2 = fl_value_new_null();
20 EXPECT_TRUE(fl_value_equal(value1, value2));
21 }
22
23 TEST(FlValueTest, NullToString) {
24 g_autoptr(FlValue) value = fl_value_new_null();
25 g_autofree gchar* text = fl_value_to_string(value);
26 EXPECT_STREQ(text, "null");
27 }
28
29 TEST(FlValueTest, BoolTrue) {
30 g_autoptr(FlValue) value = fl_value_new_bool(TRUE);
31 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_BOOL);
32 EXPECT_TRUE(fl_value_get_bool(value));
33 }
34
35 TEST(FlValueTest, BoolFalse) {
36 g_autoptr(FlValue) value = fl_value_new_bool(FALSE);
37 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_BOOL);
38 EXPECT_FALSE(fl_value_get_bool(value));
39 }
40
41 TEST(FlValueTest, BoolEqual) {
42 g_autoptr(FlValue) value1 = fl_value_new_bool(TRUE);
43 g_autoptr(FlValue) value2 = fl_value_new_bool(TRUE);
44 EXPECT_TRUE(fl_value_equal(value1, value2));
45 }
46
47 TEST(FlValueTest, BoolNotEqual) {
48 g_autoptr(FlValue) value1 = fl_value_new_bool(TRUE);
49 g_autoptr(FlValue) value2 = fl_value_new_bool(FALSE);
50 EXPECT_FALSE(fl_value_equal(value1, value2));
51 }
52
53 TEST(FlValueTest, BoolTrueToString) {
54 g_autoptr(FlValue) value = fl_value_new_bool(TRUE);
55 g_autofree gchar* text = fl_value_to_string(value);
56 EXPECT_STREQ(text, "true");
57 }
58
59 TEST(FlValueTest, BoolFalseToString) {
60 g_autoptr(FlValue) value = fl_value_new_bool(FALSE);
61 g_autofree gchar* text = fl_value_to_string(value);
62 EXPECT_STREQ(text, "false");
63 }
64
65 TEST(FlValueTest, IntZero) {
66 g_autoptr(FlValue) value = fl_value_new_int(0);
67 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
68 EXPECT_EQ(fl_value_get_int(value), 0);
69 }
70
71 TEST(FlValueTest, IntOne) {
72 g_autoptr(FlValue) value = fl_value_new_int(1);
73 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
74 EXPECT_EQ(fl_value_get_int(value), 1);
75 }
76
77 TEST(FlValueTest, IntMinusOne) {
78 g_autoptr(FlValue) value = fl_value_new_int(-1);
79 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
80 EXPECT_EQ(fl_value_get_int(value), -1);
81 }
82
83 TEST(FlValueTest, IntMin) {
84 g_autoptr(FlValue) value = fl_value_new_int(G_MININT64);
85 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
86 EXPECT_EQ(fl_value_get_int(value), G_MININT64);
87 }
88
89 TEST(FlValueTest, IntMax) {
90 g_autoptr(FlValue) value = fl_value_new_int(G_MAXINT64);
91 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT);
92 EXPECT_EQ(fl_value_get_int(value), G_MAXINT64);
93 }
94
95 TEST(FlValueTest, IntEqual) {
96 g_autoptr(FlValue) value1 = fl_value_new_int(42);
97 g_autoptr(FlValue) value2 = fl_value_new_int(42);
98 EXPECT_TRUE(fl_value_equal(value1, value2));
99 }
100
101 TEST(FlValueTest, IntNotEqual) {
102 g_autoptr(FlValue) value1 = fl_value_new_int(42);
103 g_autoptr(FlValue) value2 = fl_value_new_int(99);
104 EXPECT_FALSE(fl_value_equal(value1, value2));
105 }
106
107 TEST(FlValueTest, IntToString) {
108 g_autoptr(FlValue) value = fl_value_new_int(42);
109 g_autofree gchar* text = fl_value_to_string(value);
110 EXPECT_STREQ(text, "42");
111 }
112
113 TEST(FlValueTest, FloatZero) {
114 g_autoptr(FlValue) value = fl_value_new_float(0.0);
115 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
116 EXPECT_EQ(fl_value_get_float(value), 0.0);
117 }
118
119 TEST(FlValueTest, FloatOne) {
120 g_autoptr(FlValue) value = fl_value_new_float(1.0);
121 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
122 EXPECT_EQ(fl_value_get_float(value), 1.0);
123 }
124
125 TEST(FlValueTest, FloatMinusOne) {
126 g_autoptr(FlValue) value = fl_value_new_float(-1.0);
127 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
128 EXPECT_EQ(fl_value_get_float(value), -1.0);
129 }
130
131 TEST(FlValueTest, FloatPi) {
132 g_autoptr(FlValue) value = fl_value_new_float(M_PI);
133 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT);
134 EXPECT_EQ(fl_value_get_float(value), M_PI);
135 }
136
137 TEST(FlValueTest, FloatEqual) {
138 g_autoptr(FlValue) value1 = fl_value_new_float(M_PI);
139 g_autoptr(FlValue) value2 = fl_value_new_float(M_PI);
140 EXPECT_TRUE(fl_value_equal(value1, value2));
141 }
142
143 TEST(FlValueTest, FloatNotEqual) {
144 g_autoptr(FlValue) value1 = fl_value_new_float(M_PI);
145 g_autoptr(FlValue) value2 = fl_value_new_float(M_E);
146 EXPECT_FALSE(fl_value_equal(value1, value2));
147 }
148
149 TEST(FlValueTest, FloatToString) {
150 g_autoptr(FlValue) value = fl_value_new_float(M_PI);
151 g_autofree gchar* text = fl_value_to_string(value);
152 EXPECT_STREQ(text, "3.1415926535897931");
153 }
154
155 TEST(FlValueTest, String) {
156 g_autoptr(FlValue) value = fl_value_new_string("hello");
157 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
158 EXPECT_STREQ(fl_value_get_string(value), "hello");
159 }
160
161 TEST(FlValueTest, StringEmpty) {
162 g_autoptr(FlValue) value = fl_value_new_string("");
163 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
164 EXPECT_STREQ(fl_value_get_string(value), "");
165 }
166
167 TEST(FlValueTest, StringSized) {
168 g_autoptr(FlValue) value = fl_value_new_string_sized("hello", 2);
169 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
170 EXPECT_STREQ(fl_value_get_string(value), "he");
171 }
172
173 TEST(FlValueTest, StringSizedNullptr) {
174 g_autoptr(FlValue) value = fl_value_new_string_sized(nullptr, 0);
175 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
176 EXPECT_STREQ(fl_value_get_string(value), "");
177 }
178
179 TEST(FlValueTest, StringSizedZeroLength) {
180 g_autoptr(FlValue) value = fl_value_new_string_sized("hello", 0);
181 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_STRING);
182 EXPECT_STREQ(fl_value_get_string(value), "");
183 }
184
185 TEST(FlValueTest, StringEqual) {
186 g_autoptr(FlValue) value1 = fl_value_new_string("hello");
187 g_autoptr(FlValue) value2 = fl_value_new_string("hello");
188 EXPECT_TRUE(fl_value_equal(value1, value2));
189 }
190
191 TEST(FlValueTest, StringNotEqual) {
192 g_autoptr(FlValue) value1 = fl_value_new_string("hello");
193 g_autoptr(FlValue) value2 = fl_value_new_string("world");
194 EXPECT_FALSE(fl_value_equal(value1, value2));
195 }
196
197 TEST(FlValueTest, StringToString) {
198 g_autoptr(FlValue) value = fl_value_new_string("hello");
199 g_autofree gchar* text = fl_value_to_string(value);
200 EXPECT_STREQ(text, "hello");
201 }
202
203 TEST(FlValueTest, Uint8List) {
204 uint8_t data[] = {0x00, 0x01, 0xFE, 0xFF};
205 g_autoptr(FlValue) value = fl_value_new_uint8_list(data, 4);
206 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_UINT8_LIST);
207 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(4));
208 EXPECT_EQ(fl_value_get_uint8_list(value)[0], 0x00);
209 EXPECT_EQ(fl_value_get_uint8_list(value)[1], 0x01);
210 EXPECT_EQ(fl_value_get_uint8_list(value)[2], 0xFE);
211 EXPECT_EQ(fl_value_get_uint8_list(value)[3], 0xFF);
212 }
213
214 TEST(FlValueTest, Uint8ListNullptr) {
215 g_autoptr(FlValue) value = fl_value_new_uint8_list(nullptr, 0);
216 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_UINT8_LIST);
217 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
218 }
219
220 TEST(FlValueTest, Uint8ListEqual) {
221 uint8_t data1[] = {1, 2, 3};
222 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data1, 3);
223 uint8_t data2[] = {1, 2, 3};
224 g_autoptr(FlValue) value2 = fl_value_new_uint8_list(data2, 3);
225 EXPECT_TRUE(fl_value_equal(value1, value2));
226 }
227
228 TEST(FlValueTest, Uint8ListEmptyEqual) {
229 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(nullptr, 0);
230 g_autoptr(FlValue) value2 = fl_value_new_uint8_list(nullptr, 0);
231 EXPECT_TRUE(fl_value_equal(value1, value2));
232 }
233
234 TEST(FlValueTest, Uint8ListNotEqualSameSize) {
235 uint8_t data1[] = {1, 2, 3};
236 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data1, 3);
237 uint8_t data2[] = {1, 2, 4};
238 g_autoptr(FlValue) value2 = fl_value_new_uint8_list(data2, 3);
239 EXPECT_FALSE(fl_value_equal(value1, value2));
240 }
241
242 TEST(FlValueTest, Uint8ListNotEqualDifferentSize) {
243 uint8_t data1[] = {1, 2, 3};
244 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data1, 3);
245 uint8_t data2[] = {1, 2, 3, 4};
246 g_autoptr(FlValue) value2 = fl_value_new_uint8_list(data2, 4);
247 EXPECT_FALSE(fl_value_equal(value1, value2));
248 }
249
250 TEST(FlValueTest, Uint8ListEmptyNotEqual) {
251 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(nullptr, 0);
252 uint8_t data[] = {1, 2, 3};
253 g_autoptr(FlValue) value2 = fl_value_new_uint8_list(data, 3);
254 EXPECT_FALSE(fl_value_equal(value1, value2));
255 }
256
257 TEST(FlValueTest, Uint8ListToString) {
258 uint8_t data[] = {0x00, 0x01, 0xFE, 0xFF};
259 g_autoptr(FlValue) value = fl_value_new_uint8_list(data, 4);
260 g_autofree gchar* text = fl_value_to_string(value);
261 EXPECT_STREQ(text, "[0, 1, 254, 255]");
262 }
263
264 TEST(FlValueTest, Int32List) {
265 int32_t data[] = {0, -1, G_MAXINT32, G_MININT32};
266 g_autoptr(FlValue) value = fl_value_new_int32_list(data, 4);
267 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT32_LIST);
268 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(4));
269 EXPECT_EQ(fl_value_get_int32_list(value)[0], 0);
270 EXPECT_EQ(fl_value_get_int32_list(value)[1], -1);
271 EXPECT_EQ(fl_value_get_int32_list(value)[2], G_MAXINT32);
272 EXPECT_EQ(fl_value_get_int32_list(value)[3], G_MININT32);
273 }
274
275 TEST(FlValueTest, Int32ListNullptr) {
276 g_autoptr(FlValue) value = fl_value_new_int32_list(nullptr, 0);
277 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT32_LIST);
278 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
279 }
280
281 TEST(FlValueTest, Int32ListEqual) {
282 int32_t data1[] = {0, G_MAXINT32, G_MININT32};
283 g_autoptr(FlValue) value1 = fl_value_new_int32_list(data1, 3);
284 int32_t data2[] = {0, G_MAXINT32, G_MININT32};
285 g_autoptr(FlValue) value2 = fl_value_new_int32_list(data2, 3);
286 EXPECT_TRUE(fl_value_equal(value1, value2));
287 }
288
289 TEST(FlValueTest, Int32ListEmptyEqual) {
290 g_autoptr(FlValue) value1 = fl_value_new_int32_list(nullptr, 0);
291 g_autoptr(FlValue) value2 = fl_value_new_int32_list(nullptr, 0);
292 EXPECT_TRUE(fl_value_equal(value1, value2));
293 }
294
295 TEST(FlValueTest, Int32ListNotEqualSameSize) {
296 int32_t data1[] = {0, G_MAXINT32, G_MININT32};
297 g_autoptr(FlValue) value1 = fl_value_new_int32_list(data1, 3);
298 int32_t data2[] = {0, G_MININT32, G_MAXINT32};
299 g_autoptr(FlValue) value2 = fl_value_new_int32_list(data2, 3);
300 EXPECT_FALSE(fl_value_equal(value1, value2));
301 }
302
303 TEST(FlValueTest, Int32ListNotEqualDifferentSize) {
304 int32_t data1[] = {0, G_MAXINT32, G_MININT32};
305 g_autoptr(FlValue) value1 = fl_value_new_int32_list(data1, 3);
306 int32_t data2[] = {0, G_MAXINT32, G_MININT32, -1};
307 g_autoptr(FlValue) value2 = fl_value_new_int32_list(data2, 4);
308 EXPECT_FALSE(fl_value_equal(value1, value2));
309 }
310
311 TEST(FlValueTest, Int32ListEmptyNotEqual) {
312 g_autoptr(FlValue) value1 = fl_value_new_int32_list(nullptr, 0);
313 int32_t data[] = {0, G_MAXINT32, G_MININT32};
314 g_autoptr(FlValue) value2 = fl_value_new_int32_list(data, 3);
315 EXPECT_FALSE(fl_value_equal(value1, value2));
316 }
317
318 TEST(FlValueTest, Int32ListToString) {
319 int32_t data[] = {0, G_MAXINT32, G_MININT32};
320 g_autoptr(FlValue) value = fl_value_new_int32_list(data, 3);
321 g_autofree gchar* text = fl_value_to_string(value);
322 EXPECT_STREQ(text, "[0, 2147483647, -2147483648]");
323 }
324
325 TEST(FlValueTest, Int64List) {
326 int64_t data[] = {0, -1, G_MAXINT64, G_MININT64};
327 g_autoptr(FlValue) value = fl_value_new_int64_list(data, 4);
328 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT64_LIST);
329 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(4));
330 EXPECT_EQ(fl_value_get_int64_list(value)[0], 0);
331 EXPECT_EQ(fl_value_get_int64_list(value)[1], -1);
332 EXPECT_EQ(fl_value_get_int64_list(value)[2], G_MAXINT64);
333 EXPECT_EQ(fl_value_get_int64_list(value)[3], G_MININT64);
334 }
335
336 TEST(FlValueTest, Int64ListNullptr) {
337 g_autoptr(FlValue) value = fl_value_new_int64_list(nullptr, 0);
338 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_INT64_LIST);
339 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
340 }
341
342 TEST(FlValueTest, Int64ListEqual) {
343 int64_t data1[] = {0, G_MAXINT64, G_MININT64};
344 g_autoptr(FlValue) value1 = fl_value_new_int64_list(data1, 3);
345 int64_t data2[] = {0, G_MAXINT64, G_MININT64};
346 g_autoptr(FlValue) value2 = fl_value_new_int64_list(data2, 3);
347 EXPECT_TRUE(fl_value_equal(value1, value2));
348 }
349
350 TEST(FlValueTest, Int64ListEmptyEqual) {
351 g_autoptr(FlValue) value1 = fl_value_new_int64_list(nullptr, 0);
352 g_autoptr(FlValue) value2 = fl_value_new_int64_list(nullptr, 0);
353 EXPECT_TRUE(fl_value_equal(value1, value2));
354 }
355
356 TEST(FlValueTest, Int64ListNotEqualSameSize) {
357 int64_t data1[] = {0, G_MAXINT64, G_MININT64};
358 g_autoptr(FlValue) value1 = fl_value_new_int64_list(data1, 3);
359 int64_t data2[] = {0, G_MININT64, G_MAXINT64};
360 g_autoptr(FlValue) value2 = fl_value_new_int64_list(data2, 3);
361 EXPECT_FALSE(fl_value_equal(value1, value2));
362 }
363
364 TEST(FlValueTest, Int64ListNotEqualDifferentSize) {
365 int64_t data1[] = {0, G_MAXINT64, G_MININT64};
366 g_autoptr(FlValue) value1 = fl_value_new_int64_list(data1, 3);
367 int64_t data2[] = {0, G_MAXINT64, G_MININT64, -1};
368 g_autoptr(FlValue) value2 = fl_value_new_int64_list(data2, 4);
369 EXPECT_FALSE(fl_value_equal(value1, value2));
370 }
371
372 TEST(FlValueTest, Int64ListEmptyNotEqual) {
373 g_autoptr(FlValue) value1 = fl_value_new_int64_list(nullptr, 0);
374 int64_t data[] = {0, G_MAXINT64, G_MININT64};
375 g_autoptr(FlValue) value2 = fl_value_new_int64_list(data, 3);
376 EXPECT_FALSE(fl_value_equal(value1, value2));
377 }
378
379 TEST(FlValueTest, Int64ListToString) {
380 int64_t data[] = {0, G_MAXINT64, G_MININT64};
381 g_autoptr(FlValue) value = fl_value_new_int64_list(data, 3);
382 g_autofree gchar* text = fl_value_to_string(value);
383 EXPECT_STREQ(text, "[0, 9223372036854775807, -9223372036854775808]");
384 }
385
386 TEST(FlValueTest, FloatList) {
387 double data[] = {0.0, -1.0, M_PI};
388 g_autoptr(FlValue) value = fl_value_new_float_list(data, 3);
389 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT_LIST);
390 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(3));
391 EXPECT_EQ(fl_value_get_float_list(value)[0], 0);
392 EXPECT_EQ(fl_value_get_float_list(value)[1], -1.0);
393 EXPECT_EQ(fl_value_get_float_list(value)[2], M_PI);
394 }
395
396 TEST(FlValueTest, FloatListNullptr) {
397 g_autoptr(FlValue) value = fl_value_new_float_list(nullptr, 0);
398 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_FLOAT_LIST);
399 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
400 }
401
402 TEST(FlValueTest, FloatListEqual) {
403 double data1[] = {0, -0.5, M_PI};
404 g_autoptr(FlValue) value1 = fl_value_new_float_list(data1, 3);
405 double data2[] = {0, -0.5, M_PI};
406 g_autoptr(FlValue) value2 = fl_value_new_float_list(data2, 3);
407 EXPECT_TRUE(fl_value_equal(value1, value2));
408 }
409
410 TEST(FlValueTest, FloatListEmptyEqual) {
411 g_autoptr(FlValue) value1 = fl_value_new_float_list(nullptr, 0);
412 g_autoptr(FlValue) value2 = fl_value_new_float_list(nullptr, 0);
413 EXPECT_TRUE(fl_value_equal(value1, value2));
414 }
415
416 TEST(FlValueTest, FloatListNotEqualSameSize) {
417 double data1[] = {0, -0.5, M_PI};
418 g_autoptr(FlValue) value1 = fl_value_new_float_list(data1, 3);
419 double data2[] = {0, -0.5, M_E};
420 g_autoptr(FlValue) value2 = fl_value_new_float_list(data2, 3);
421 EXPECT_FALSE(fl_value_equal(value1, value2));
422 }
423
424 TEST(FlValueTest, FloatListNotEqualDifferentSize) {
425 double data1[] = {0, -0.5, M_PI};
426 g_autoptr(FlValue) value1 = fl_value_new_float_list(data1, 3);
427 double data2[] = {0, -0.5, M_PI, 42};
428 g_autoptr(FlValue) value2 = fl_value_new_float_list(data2, 4);
429 EXPECT_FALSE(fl_value_equal(value1, value2));
430 }
431
432 TEST(FlValueTest, FloatListEmptyNotEqual) {
433 g_autoptr(FlValue) value1 = fl_value_new_float_list(nullptr, 0);
434 double data[] = {0, -0.5, M_PI};
435 g_autoptr(FlValue) value2 = fl_value_new_float_list(data, 3);
436 EXPECT_FALSE(fl_value_equal(value1, value2));
437 }
438
439 TEST(FlValueTest, FloatListToString) {
440 double data[] = {0, -0.5, M_PI};
441 g_autoptr(FlValue) value = fl_value_new_float_list(data, 3);
442 g_autofree gchar* text = fl_value_to_string(value);
443 EXPECT_STREQ(text, "[0.0, -0.5, 3.1415926535897931]");
444 }
445
446 TEST(FlValueTest, ListEmpty) {
447 g_autoptr(FlValue) value = fl_value_new_list();
448 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
449 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
450 }
451
452 TEST(FlValueTest, ListAdd) {
453 g_autoptr(FlValue) value = fl_value_new_list();
454 g_autoptr(FlValue) child = fl_value_new_null();
455 fl_value_append(value, child);
456 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
457 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
458 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 0)),
459 FL_VALUE_TYPE_NULL);
460 }
461
462 TEST(FlValueTest, ListAddTake) {
463 g_autoptr(FlValue) value = fl_value_new_list();
464 fl_value_append_take(value, fl_value_new_null());
465 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
466 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
467 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 0)),
468 FL_VALUE_TYPE_NULL);
469 }
470
471 TEST(FlValueTest, ListChildTypes) {
472 g_autoptr(FlValue) value = fl_value_new_list();
473 fl_value_append_take(value, fl_value_new_null());
474 fl_value_append_take(value, fl_value_new_bool(TRUE));
475 fl_value_append_take(value, fl_value_new_int(42));
476 fl_value_append_take(value, fl_value_new_float(M_PI));
477 fl_value_append_take(value, fl_value_new_uint8_list(nullptr, 0));
478 fl_value_append_take(value, fl_value_new_int32_list(nullptr, 0));
479 fl_value_append_take(value, fl_value_new_int64_list(nullptr, 0));
480 fl_value_append_take(value, fl_value_new_float_list(nullptr, 0));
481 fl_value_append_take(value, fl_value_new_list());
482 fl_value_append_take(value, fl_value_new_map());
483 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
484 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(10));
485 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 0)),
486 FL_VALUE_TYPE_NULL);
487 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 1)),
488 FL_VALUE_TYPE_BOOL);
489 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 2)),
490 FL_VALUE_TYPE_INT);
491 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 3)),
492 FL_VALUE_TYPE_FLOAT);
493 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 4)),
494 FL_VALUE_TYPE_UINT8_LIST);
495 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 5)),
496 FL_VALUE_TYPE_INT32_LIST);
497 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 6)),
498 FL_VALUE_TYPE_INT64_LIST);
499 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 7)),
500 FL_VALUE_TYPE_FLOAT_LIST);
501 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 8)),
502 FL_VALUE_TYPE_LIST);
503 EXPECT_EQ(fl_value_get_type(fl_value_get_list_value(value, 9)),
504 FL_VALUE_TYPE_MAP);
505 }
506
507 TEST(FlValueTest, ListStrv) {
508 g_auto(GStrv) words = g_strsplit("hello:world", ":", -1);
509 g_autoptr(FlValue) value = fl_value_new_list_from_strv(words);
510 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
511 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(2));
512 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 0)),
513 FL_VALUE_TYPE_STRING);
514 EXPECT_STREQ(fl_value_get_string(fl_value_get_list_value(value, 0)), "hello");
515 ASSERT_EQ(fl_value_get_type(fl_value_get_list_value(value, 1)),
516 FL_VALUE_TYPE_STRING);
517 EXPECT_STREQ(fl_value_get_string(fl_value_get_list_value(value, 1)), "world");
518 }
519
520 TEST(FlValueTest, ListStrvEmpty) {
521 g_auto(GStrv) words = g_strsplit("", ":", -1);
522 g_autoptr(FlValue) value = fl_value_new_list_from_strv(words);
523 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_LIST);
524 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
525 }
526
527 TEST(FlValueTest, ListEqual) {
528 g_autoptr(FlValue) value1 = fl_value_new_list();
529 fl_value_append_take(value1, fl_value_new_int(1));
530 fl_value_append_take(value1, fl_value_new_int(2));
531 fl_value_append_take(value1, fl_value_new_int(3));
532 g_autoptr(FlValue) value2 = fl_value_new_list();
533 fl_value_append_take(value2, fl_value_new_int(1));
534 fl_value_append_take(value2, fl_value_new_int(2));
535 fl_value_append_take(value2, fl_value_new_int(3));
536 EXPECT_TRUE(fl_value_equal(value1, value2));
537 }
538
539 TEST(FlValueTest, ListEmptyEqual) {
540 g_autoptr(FlValue) value1 = fl_value_new_list();
541 g_autoptr(FlValue) value2 = fl_value_new_list();
542 EXPECT_TRUE(fl_value_equal(value1, value2));
543 }
544
545 TEST(FlValueTest, ListNotEqualSameSize) {
546 g_autoptr(FlValue) value1 = fl_value_new_list();
547 fl_value_append_take(value1, fl_value_new_int(1));
548 fl_value_append_take(value1, fl_value_new_int(2));
549 fl_value_append_take(value1, fl_value_new_int(3));
550 g_autoptr(FlValue) value2 = fl_value_new_list();
551 fl_value_append_take(value2, fl_value_new_int(1));
552 fl_value_append_take(value2, fl_value_new_int(2));
553 fl_value_append_take(value2, fl_value_new_int(4));
554 EXPECT_FALSE(fl_value_equal(value1, value2));
555 }
556
557 TEST(FlValueTest, ListNotEqualDifferentSize) {
558 g_autoptr(FlValue) value1 = fl_value_new_list();
559 fl_value_append_take(value1, fl_value_new_int(1));
560 fl_value_append_take(value1, fl_value_new_int(2));
561 fl_value_append_take(value1, fl_value_new_int(3));
562 g_autoptr(FlValue) value2 = fl_value_new_list();
563 fl_value_append_take(value2, fl_value_new_int(1));
564 fl_value_append_take(value2, fl_value_new_int(2));
565 fl_value_append_take(value2, fl_value_new_int(3));
566 fl_value_append_take(value2, fl_value_new_int(4));
567 EXPECT_FALSE(fl_value_equal(value1, value2));
568 }
569
570 TEST(FlValueTest, ListEmptyNotEqual) {
571 g_autoptr(FlValue) value1 = fl_value_new_list();
572 g_autoptr(FlValue) value2 = fl_value_new_list();
573 fl_value_append_take(value2, fl_value_new_int(1));
574 fl_value_append_take(value2, fl_value_new_int(2));
575 fl_value_append_take(value2, fl_value_new_int(3));
576 EXPECT_FALSE(fl_value_equal(value1, value2));
577 }
578
579 TEST(FlValueTest, ListToString) {
580 g_autoptr(FlValue) value = fl_value_new_list();
581 fl_value_append_take(value, fl_value_new_null());
582 fl_value_append_take(value, fl_value_new_bool(TRUE));
583 fl_value_append_take(value, fl_value_new_int(42));
584 fl_value_append_take(value, fl_value_new_float(M_PI));
585 fl_value_append_take(value, fl_value_new_uint8_list(nullptr, 0));
586 fl_value_append_take(value, fl_value_new_int32_list(nullptr, 0));
587 fl_value_append_take(value, fl_value_new_int64_list(nullptr, 0));
588 fl_value_append_take(value, fl_value_new_float_list(nullptr, 0));
589 fl_value_append_take(value, fl_value_new_list());
590 fl_value_append_take(value, fl_value_new_map());
591 g_autofree gchar* text = fl_value_to_string(value);
592 EXPECT_STREQ(text,
593 "[null, true, 42, 3.1415926535897931, [], [], [], [], [], {}]");
594 }
595
596 TEST(FlValueTest, MapEmpty) {
597 g_autoptr(FlValue) value = fl_value_new_map();
598 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
599 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
600 }
601
602 TEST(FlValueTest, MapSet) {
603 g_autoptr(FlValue) value = fl_value_new_map();
604 g_autoptr(FlValue) k = fl_value_new_string("count");
605 g_autoptr(FlValue) v = fl_value_new_int(42);
606 fl_value_set(value, k, v);
607 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
608 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
609 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
610 FL_VALUE_TYPE_STRING);
611 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
612 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
613 FL_VALUE_TYPE_INT);
614 EXPECT_EQ(fl_value_get_int(fl_value_get_map_value(value, 0)), 42);
615 }
616
617 TEST(FlValueTest, MapSetTake) {
618 g_autoptr(FlValue) value = fl_value_new_map();
619 fl_value_set_take(value, fl_value_new_string("count"), fl_value_new_int(42));
620 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
621 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
622 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
623 FL_VALUE_TYPE_STRING);
624 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
625 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
626 FL_VALUE_TYPE_INT);
627 EXPECT_EQ(fl_value_get_int(fl_value_get_map_value(value, 0)), 42);
628 }
629
630 TEST(FlValueTest, MapSetString) {
631 g_autoptr(FlValue) value = fl_value_new_map();
632 g_autoptr(FlValue) v = fl_value_new_int(42);
633 fl_value_set_string(value, "count", v);
634 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
635 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
636 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
637 FL_VALUE_TYPE_STRING);
638 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
639 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
640 FL_VALUE_TYPE_INT);
641 EXPECT_EQ(fl_value_get_int(fl_value_get_map_value(value, 0)), 42);
642 }
643
644 TEST(FlValueTest, MapSetStringTake) {
645 g_autoptr(FlValue) value = fl_value_new_map();
646 fl_value_set_string_take(value, "count", fl_value_new_int(42));
647 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
648 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
649 ASSERT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
650 FL_VALUE_TYPE_STRING);
651 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
652 ASSERT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
653 FL_VALUE_TYPE_INT);
654 EXPECT_EQ(fl_value_get_int(fl_value_get_map_value(value, 0)), 42);
655 }
656
657 TEST(FlValueTest, MapLookup) {
658 g_autoptr(FlValue) value = fl_value_new_map();
659 fl_value_set_string_take(value, "one", fl_value_new_int(1));
660 fl_value_set_string_take(value, "two", fl_value_new_int(2));
661 fl_value_set_string_take(value, "three", fl_value_new_int(3));
662 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
663 g_autoptr(FlValue) two_key = fl_value_new_string("two");
664 FlValue* v = fl_value_lookup(value, two_key);
665 ASSERT_NE(v, nullptr);
666 ASSERT_EQ(fl_value_get_type(v), FL_VALUE_TYPE_INT);
667 EXPECT_EQ(fl_value_get_int(v), 2);
668 g_autoptr(FlValue) four_key = fl_value_new_string("four");
669 v = fl_value_lookup(value, four_key);
670 ASSERT_EQ(v, nullptr);
671 }
672
673 TEST(FlValueTest, MapLookupString) {
674 g_autoptr(FlValue) value = fl_value_new_map();
675 fl_value_set_string_take(value, "one", fl_value_new_int(1));
676 fl_value_set_string_take(value, "two", fl_value_new_int(2));
677 fl_value_set_string_take(value, "three", fl_value_new_int(3));
678 FlValue* v = fl_value_lookup_string(value, "two");
679 ASSERT_NE(v, nullptr);
680 ASSERT_EQ(fl_value_get_type(v), FL_VALUE_TYPE_INT);
681 EXPECT_EQ(fl_value_get_int(v), 2);
682 v = fl_value_lookup_string(value, "four");
683 ASSERT_EQ(v, nullptr);
684 }
685
686 TEST(FlValueTest, MapValueypes) {
687 g_autoptr(FlValue) value = fl_value_new_map();
688 fl_value_set_take(value, fl_value_new_string("null"), fl_value_new_null());
689 fl_value_set_take(value, fl_value_new_string("bool"),
690 fl_value_new_bool(TRUE));
691 fl_value_set_take(value, fl_value_new_string("int"), fl_value_new_int(42));
692 fl_value_set_take(value, fl_value_new_string("float"),
693 fl_value_new_float(M_PI));
694 fl_value_set_take(value, fl_value_new_string("uint8_list"),
695 fl_value_new_uint8_list(nullptr, 0));
696 fl_value_set_take(value, fl_value_new_string("int32_list"),
697 fl_value_new_int32_list(nullptr, 0));
698 fl_value_set_take(value, fl_value_new_string("int64_list"),
699 fl_value_new_int64_list(nullptr, 0));
700 fl_value_set_take(value, fl_value_new_string("float_list"),
701 fl_value_new_float_list(nullptr, 0));
702 fl_value_set_take(value, fl_value_new_string("list"), fl_value_new_list());
703 fl_value_set_take(value, fl_value_new_string("map"), fl_value_new_map());
704 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
705 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(10));
706 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 0)),
707 FL_VALUE_TYPE_NULL);
708 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 1)),
709 FL_VALUE_TYPE_BOOL);
710 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 2)),
711 FL_VALUE_TYPE_INT);
712 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 3)),
713 FL_VALUE_TYPE_FLOAT);
714 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 4)),
715 FL_VALUE_TYPE_UINT8_LIST);
716 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 5)),
717 FL_VALUE_TYPE_INT32_LIST);
718 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 6)),
719 FL_VALUE_TYPE_INT64_LIST);
720 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 7)),
721 FL_VALUE_TYPE_FLOAT_LIST);
722 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 8)),
723 FL_VALUE_TYPE_LIST);
724 EXPECT_EQ(fl_value_get_type(fl_value_get_map_value(value, 9)),
725 FL_VALUE_TYPE_MAP);
726 }
727
728 TEST(FlValueTest, MapKeyTypes) {
729 g_autoptr(FlValue) value = fl_value_new_map();
730 fl_value_set_take(value, fl_value_new_null(), fl_value_new_string("null"));
731 fl_value_set_take(value, fl_value_new_bool(TRUE),
732 fl_value_new_string("bool"));
733 fl_value_set_take(value, fl_value_new_int(42), fl_value_new_string("int"));
734 fl_value_set_take(value, fl_value_new_float(M_PI),
735 fl_value_new_string("float"));
736 fl_value_set_take(value, fl_value_new_uint8_list(nullptr, 0),
737 fl_value_new_string("uint8_list"));
738 fl_value_set_take(value, fl_value_new_int32_list(nullptr, 0),
739 fl_value_new_string("int32_list"));
740 fl_value_set_take(value, fl_value_new_int64_list(nullptr, 0),
741 fl_value_new_string("int64_list"));
742 fl_value_set_take(value, fl_value_new_float_list(nullptr, 0),
743 fl_value_new_string("float_list"));
744 fl_value_set_take(value, fl_value_new_list(), fl_value_new_string("list"));
745 fl_value_set_take(value, fl_value_new_map(), fl_value_new_string("map"));
746 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_MAP);
747 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(10));
748 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 0)),
749 FL_VALUE_TYPE_NULL);
750 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 1)),
751 FL_VALUE_TYPE_BOOL);
752 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 2)),
753 FL_VALUE_TYPE_INT);
754 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 3)),
755 FL_VALUE_TYPE_FLOAT);
756 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 4)),
757 FL_VALUE_TYPE_UINT8_LIST);
758 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 5)),
759 FL_VALUE_TYPE_INT32_LIST);
760 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 6)),
761 FL_VALUE_TYPE_INT64_LIST);
762 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 7)),
763 FL_VALUE_TYPE_FLOAT_LIST);
764 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 8)),
765 FL_VALUE_TYPE_LIST);
766 EXPECT_EQ(fl_value_get_type(fl_value_get_map_key(value, 9)),
767 FL_VALUE_TYPE_MAP);
768 }
769
770 TEST(FlValueTest, MapEqual) {
771 g_autoptr(FlValue) value1 = fl_value_new_map();
772 fl_value_set_string_take(value1, "one", fl_value_new_int(1));
773 fl_value_set_string_take(value1, "two", fl_value_new_int(2));
774 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
775 g_autoptr(FlValue) value2 = fl_value_new_map();
776 fl_value_set_string_take(value2, "one", fl_value_new_int(1));
777 fl_value_set_string_take(value2, "two", fl_value_new_int(2));
778 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
779 EXPECT_TRUE(fl_value_equal(value1, value2));
780 }
781
782 TEST(FlValueTest, MapEqualDifferentOrder) {
783 g_autoptr(FlValue) value1 = fl_value_new_map();
784 fl_value_set_string_take(value1, "one", fl_value_new_int(1));
785 fl_value_set_string_take(value1, "two", fl_value_new_int(2));
786 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
787 g_autoptr(FlValue) value2 = fl_value_new_map();
788 fl_value_set_string_take(value2, "one", fl_value_new_int(1));
789 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
790 fl_value_set_string_take(value2, "two", fl_value_new_int(2));
791 EXPECT_TRUE(fl_value_equal(value1, value2));
792 }
793
794 TEST(FlValueTest, MapEmptyEqual) {
795 g_autoptr(FlValue) value1 = fl_value_new_map();
796 g_autoptr(FlValue) value2 = fl_value_new_map();
797 EXPECT_TRUE(fl_value_equal(value1, value2));
798 }
799
800 TEST(FlValueTest, MapNotEqualSameSizeDifferentKeys) {
801 g_autoptr(FlValue) value1 = fl_value_new_map();
802 fl_value_set_string_take(value1, "one", fl_value_new_int(1));
803 fl_value_set_string_take(value1, "two", fl_value_new_int(2));
804 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
805 g_autoptr(FlValue) value2 = fl_value_new_map();
806 fl_value_set_string_take(value2, "one", fl_value_new_int(1));
807 fl_value_set_string_take(value2, "two", fl_value_new_int(2));
808 fl_value_set_string_take(value2, "four", fl_value_new_int(3));
809 EXPECT_FALSE(fl_value_equal(value1, value2));
810 }
811
812 TEST(FlValueTest, MapNotEqualSameSizeDifferentValues) {
813 g_autoptr(FlValue) value1 = fl_value_new_map();
814 fl_value_set_string_take(value1, "one", fl_value_new_int(1));
815 fl_value_set_string_take(value1, "two", fl_value_new_int(2));
816 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
817 g_autoptr(FlValue) value2 = fl_value_new_map();
818 fl_value_set_string_take(value2, "one", fl_value_new_int(1));
819 fl_value_set_string_take(value2, "two", fl_value_new_int(2));
820 fl_value_set_string_take(value2, "three", fl_value_new_int(4));
821 EXPECT_FALSE(fl_value_equal(value1, value2));
822 }
823
824 TEST(FlValueTest, MapNotEqualDifferentSize) {
825 g_autoptr(FlValue) value1 = fl_value_new_map();
826 fl_value_set_string_take(value1, "one", fl_value_new_int(1));
827 fl_value_set_string_take(value1, "two", fl_value_new_int(2));
828 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
829 g_autoptr(FlValue) value2 = fl_value_new_map();
830 fl_value_set_string_take(value2, "one", fl_value_new_int(1));
831 fl_value_set_string_take(value2, "two", fl_value_new_int(2));
832 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
833 fl_value_set_string_take(value2, "four", fl_value_new_int(4));
834 EXPECT_FALSE(fl_value_equal(value1, value2));
835 }
836
837 TEST(FlValueTest, MapEmptyNotEqual) {
838 g_autoptr(FlValue) value1 = fl_value_new_map();
839 g_autoptr(FlValue) value2 = fl_value_new_map();
840 fl_value_set_string_take(value2, "one", fl_value_new_int(1));
841 fl_value_set_string_take(value2, "two", fl_value_new_int(2));
842 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
843 EXPECT_FALSE(fl_value_equal(value1, value2));
844 }
845
846 TEST(FlValueTest, MapToString) {
847 g_autoptr(FlValue) value = fl_value_new_map();
848 fl_value_set_take(value, fl_value_new_string("null"), fl_value_new_null());
849 fl_value_set_take(value, fl_value_new_string("bool"),
850 fl_value_new_bool(TRUE));
851 fl_value_set_take(value, fl_value_new_string("int"), fl_value_new_int(42));
852 fl_value_set_take(value, fl_value_new_string("float"),
853 fl_value_new_float(M_PI));
854 fl_value_set_take(value, fl_value_new_string("uint8_list"),
855 fl_value_new_uint8_list(nullptr, 0));
856 fl_value_set_take(value, fl_value_new_string("int32_list"),
857 fl_value_new_int32_list(nullptr, 0));
858 fl_value_set_take(value, fl_value_new_string("int64_list"),
859 fl_value_new_int64_list(nullptr, 0));
860 fl_value_set_take(value, fl_value_new_string("float_list"),
861 fl_value_new_float_list(nullptr, 0));
862 fl_value_set_take(value, fl_value_new_string("list"), fl_value_new_list());
863 fl_value_set_take(value, fl_value_new_string("map"), fl_value_new_map());
864 fl_value_set_take(value, fl_value_new_null(), fl_value_new_string("null"));
865 fl_value_set_take(value, fl_value_new_bool(TRUE),
866 fl_value_new_string("bool"));
867 fl_value_set_take(value, fl_value_new_int(42), fl_value_new_string("int"));
868 fl_value_set_take(value, fl_value_new_float(M_PI),
869 fl_value_new_string("float"));
870 fl_value_set_take(value, fl_value_new_uint8_list(nullptr, 0),
871 fl_value_new_string("uint8_list"));
872 fl_value_set_take(value, fl_value_new_int32_list(nullptr, 0),
873 fl_value_new_string("int32_list"));
874 fl_value_set_take(value, fl_value_new_int64_list(nullptr, 0),
875 fl_value_new_string("int64_list"));
876 fl_value_set_take(value, fl_value_new_float_list(nullptr, 0),
877 fl_value_new_string("float_list"));
878 fl_value_set_take(value, fl_value_new_list(), fl_value_new_string("list"));
879 fl_value_set_take(value, fl_value_new_map(), fl_value_new_string("map"));
880 g_autofree gchar* text = fl_value_to_string(value);
881 EXPECT_STREQ(text,
882 "{null: null, bool: true, int: 42, float: 3.1415926535897931, "
883 "uint8_list: [], int32_list: [], int64_list: [], float_list: "
884 "[], list: [], map: {}, null: null, true: bool, 42: int, "
885 "3.1415926535897931: float, []: uint8_list, []: int32_list, []: "
886 "int64_list, []: float_list, []: list, {}: map}");
887 }
888
889 TEST(FlDartProjectTest, Custom) {
890 g_autoptr(FlValue) value =
891 fl_value_new_custom(128, g_strdup("Hello World"), g_free);
892 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_CUSTOM);
893 ASSERT_EQ(fl_value_get_custom_type(value), 128);
894 ASSERT_STREQ(reinterpret_cast<const gchar*>(fl_value_get_custom_value(value)),
895 "Hello World");
896 }
897
898 TEST(FlDartProjectTest, CustomNoDestroyNotify) {
899 g_autoptr(FlValue) value = fl_value_new_custom(128, "Hello World", nullptr);
900 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_CUSTOM);
901 ASSERT_EQ(fl_value_get_custom_type(value), 128);
902 ASSERT_STREQ(reinterpret_cast<const gchar*>(fl_value_get_custom_value(value)),
903 "Hello World");
904 }
905
906 TEST(FlDartProjectTest, CustomObject) {
907 g_autoptr(GObject) v = G_OBJECT(g_object_new(G_TYPE_OBJECT, nullptr));
908 g_autoptr(FlValue) value = fl_value_new_custom_object(128, v);
909 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_CUSTOM);
910 ASSERT_EQ(fl_value_get_custom_type(value), 128);
911 ASSERT_TRUE(G_IS_OBJECT(fl_value_get_custom_value_object(value)));
912 }
913
914 TEST(FlDartProjectTest, CustomObjectTake) {
915 g_autoptr(FlValue) value = fl_value_new_custom_object_take(
916 128, G_OBJECT(g_object_new(G_TYPE_OBJECT, nullptr)));
917 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_CUSTOM);
918 ASSERT_EQ(fl_value_get_custom_type(value), 128);
919 ASSERT_TRUE(G_IS_OBJECT(fl_value_get_custom_value_object(value)));
920 }
921
922 TEST(FlValueTest, CustomEqual) {
923 g_autoptr(FlValue) value1 = fl_value_new_custom(128, "Hello World", nullptr);
924 g_autoptr(FlValue) value2 = fl_value_new_custom(128, "Hello World", nullptr);
925 EXPECT_FALSE(fl_value_equal(value1, value2));
926 }
927
928 TEST(FlValueTest, CustomToString) {
929 g_autoptr(FlValue) value = fl_value_new_custom(128, nullptr, nullptr);
930 g_autofree gchar* text = fl_value_to_string(value);
931 EXPECT_STREQ(text, "(custom 128)");
932 }
933
934 TEST(FlValueTest, EqualSameObject) {
935 g_autoptr(FlValue) value = fl_value_new_null();
936 EXPECT_TRUE(fl_value_equal(value, value));
937 }
938
939 TEST(FlValueTest, NullIntNotEqual) {
940 g_autoptr(FlValue) value1 = fl_value_new_null();
941 g_autoptr(FlValue) value2 = fl_value_new_int(0);
942 EXPECT_FALSE(fl_value_equal(value1, value2));
943 }
944
945 TEST(FlValueTest, NullBoolNotEqual) {
946 g_autoptr(FlValue) value1 = fl_value_new_bool(FALSE);
947 g_autoptr(FlValue) value2 = fl_value_new_int(0);
948 EXPECT_FALSE(fl_value_equal(value1, value2));
949 }
950
951 TEST(FlValueTest, StringUint8ListNotEqual) {
952 uint8_t data[] = {'h', 'e', 'l', 'l', 'o'};
953 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data, 5);
954 g_autoptr(FlValue) value2 = fl_value_new_string("hello");
955 EXPECT_FALSE(fl_value_equal(value1, value2));
956 }
957
958 TEST(FlValueTest, Uint8ListInt32ListNotEqual) {
959 uint8_t data8[] = {0, 1, 2, 3, 4};
960 int32_t data32[] = {0, 1, 2, 3, 4};
961 g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data8, 5);
962 g_autoptr(FlValue) value2 = fl_value_new_int32_list(data32, 5);
963 EXPECT_FALSE(fl_value_equal(value1, value2));
964 }
965
966 TEST(FlValueTest, Int32ListInt64ListNotEqual) {
967 int32_t data32[] = {0, 1, 2, 3, 4};
968 int64_t data64[] = {0, 1, 2, 3, 4};
969 g_autoptr(FlValue) value1 = fl_value_new_int32_list(data32, 5);
970 g_autoptr(FlValue) value2 = fl_value_new_int64_list(data64, 5);
971 EXPECT_FALSE(fl_value_equal(value1, value2));
972 }
973
974 TEST(FlValueTest, Int64ListFloatListNotEqual) {
975 int64_t data64[] = {0, 1, 2, 3, 4};
976 double dataf[] = {0.0, 1.0, 2.0, 3.0, 4.0};
977 g_autoptr(FlValue) value1 = fl_value_new_int64_list(data64, 5);
978 g_autoptr(FlValue) value2 = fl_value_new_float_list(dataf, 5);
979 EXPECT_FALSE(fl_value_equal(value1, value2));
980 }
981
982 TEST(FlValueTest, ListMapNotEqual) {
983 g_autoptr(FlValue) value1 = fl_value_new_list();
984 g_autoptr(FlValue) value2 = fl_value_new_map();
985 EXPECT_FALSE(fl_value_equal(value1, value2));
986 }
g_autoptr
g_autoptr(GMutexLocker) locker
TRUE
return TRUE
Definition: fl_compositor_software.cc:69
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_new_int32_list
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
Definition: fl_value.cc:309
fl_value_get_map_value
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition: fl_value.cc:792
fl_value_set_string
G_MODULE_EXPORT void fl_value_set_string(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:639
fl_value_new_float
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269
fl_value_new_custom_object
G_MODULE_EXPORT FlValue * fl_value_new_custom_object(int type, GObject *object)
Definition: fl_value.cc:385
fl_value_lookup
G_MODULE_EXPORT FlValue * fl_value_lookup(FlValue *self, FlValue *key)
Definition: fl_value.cc:800
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
fl_value_set_string_take
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
fl_value_new_custom
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
Definition: fl_value.cc:374
fl_value_get_float_list
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:717
fl_value_get_list_value
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:776
fl_value_new_int64_list
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
Definition: fl_value.cc:319
fl_value_to_string
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition: fl_value.cc:846
fl_value_get_uint8_list
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:689
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
fl_value_append
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:592
fl_value_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
fl_value_get_custom_type
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
Definition: fl_value.cc:822
fl_value_new_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
fl_value_new_string_sized
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:283
fl_value_get_custom_value
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition: fl_value.cc:830
fl_value_get_bool
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:661
fl_value_new_float_list
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
Definition: fl_value.cc:339
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
fl_value_get_map_key
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition: fl_value.cc:784
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
fl_value_new_custom_object_take
G_MODULE_EXPORT FlValue * fl_value_new_custom_object_take(int type, GObject *object)
Definition: fl_value.cc:389
fl_value_get_int64_list
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:703
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_get_custom_value_object
G_MODULE_EXPORT GObject * fl_value_get_custom_value_object(FlValue *self)
Definition: fl_value.cc:838
fl_value_new_list_from_strv
G_MODULE_EXPORT FlValue * fl_value_new_list_from_strv(const gchar *const *str_array)
Definition: fl_value.cc:356
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
fl_value_new_uint8_list
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:292
fl_value_get_float
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:675
fl_value_get_int32_list
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:696
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
fl_value_set
G_MODULE_EXPORT void fl_value_set(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:609
fl_value.h
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:64
FL_VALUE_TYPE_INT
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:66
FL_VALUE_TYPE_BOOL
@ FL_VALUE_TYPE_BOOL
Definition: fl_value.h:65
FL_VALUE_TYPE_INT32_LIST
@ FL_VALUE_TYPE_INT32_LIST
Definition: fl_value.h:70
FL_VALUE_TYPE_UINT8_LIST
@ FL_VALUE_TYPE_UINT8_LIST
Definition: fl_value.h:69
FL_VALUE_TYPE_LIST
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:73
FL_VALUE_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:74
FL_VALUE_TYPE_INT64_LIST
@ FL_VALUE_TYPE_INT64_LIST
Definition: fl_value.h:71
FL_VALUE_TYPE_FLOAT_LIST
@ FL_VALUE_TYPE_FLOAT_LIST
Definition: fl_value.h:72
FL_VALUE_TYPE_CUSTOM
@ FL_VALUE_TYPE_CUSTOM
Definition: fl_value.h:76
FL_VALUE_TYPE_FLOAT
@ FL_VALUE_TYPE_FLOAT
Definition: fl_value.h:67
TEST
TEST(FlDartProjectTest, Null)
Definition: fl_value_test.cc:12