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