Flutter Engine
The Flutter Engine
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
11TEST(FlDartProjectTest, Null) {
12 g_autoptr(FlValue) value = fl_value_new_null();
14}
15
16TEST(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
22TEST(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
28TEST(FlValueTest, BoolTrue) {
29 g_autoptr(FlValue) value = fl_value_new_bool(TRUE);
32}
33
34TEST(FlValueTest, BoolFalse) {
37 EXPECT_FALSE(fl_value_get_bool(value));
38}
39
40TEST(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
46TEST(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
52TEST(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
58TEST(FlValueTest, BoolFalseToString) {
60 g_autofree gchar* text = fl_value_to_string(value);
61 EXPECT_STREQ(text, "false");
62}
63
64TEST(FlValueTest, IntZero) {
65 g_autoptr(FlValue) value = fl_value_new_int(0);
67 EXPECT_EQ(fl_value_get_int(value), 0);
68}
69
70TEST(FlValueTest, IntOne) {
71 g_autoptr(FlValue) value = fl_value_new_int(1);
73 EXPECT_EQ(fl_value_get_int(value), 1);
74}
75
76TEST(FlValueTest, IntMinusOne) {
77 g_autoptr(FlValue) value = fl_value_new_int(-1);
79 EXPECT_EQ(fl_value_get_int(value), -1);
80}
81
82TEST(FlValueTest, IntMin) {
83 g_autoptr(FlValue) value = fl_value_new_int(G_MININT64);
85 EXPECT_EQ(fl_value_get_int(value), G_MININT64);
86}
87
88TEST(FlValueTest, IntMax) {
89 g_autoptr(FlValue) value = fl_value_new_int(G_MAXINT64);
91 EXPECT_EQ(fl_value_get_int(value), G_MAXINT64);
92}
93
94TEST(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
100TEST(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
106TEST(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
112TEST(FlValueTest, FloatZero) {
113 g_autoptr(FlValue) value = fl_value_new_float(0.0);
115 EXPECT_EQ(fl_value_get_float(value), 0.0);
116}
117
118TEST(FlValueTest, FloatOne) {
119 g_autoptr(FlValue) value = fl_value_new_float(1.0);
121 EXPECT_EQ(fl_value_get_float(value), 1.0);
122}
123
124TEST(FlValueTest, FloatMinusOne) {
125 g_autoptr(FlValue) value = fl_value_new_float(-1.0);
127 EXPECT_EQ(fl_value_get_float(value), -1.0);
128}
129
130TEST(FlValueTest, FloatPi) {
131 g_autoptr(FlValue) value = fl_value_new_float(M_PI);
133 EXPECT_EQ(fl_value_get_float(value), M_PI);
134}
135
136TEST(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
142TEST(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
148TEST(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
154TEST(FlValueTest, String) {
155 g_autoptr(FlValue) value = fl_value_new_string("hello");
157 EXPECT_STREQ(fl_value_get_string(value), "hello");
158}
159
160TEST(FlValueTest, StringEmpty) {
161 g_autoptr(FlValue) value = fl_value_new_string("");
163 EXPECT_STREQ(fl_value_get_string(value), "");
164}
165
166TEST(FlValueTest, StringSized) {
167 g_autoptr(FlValue) value = fl_value_new_string_sized("hello", 2);
169 EXPECT_STREQ(fl_value_get_string(value), "he");
170}
171
172TEST(FlValueTest, StringSizedNullptr) {
173 g_autoptr(FlValue) value = fl_value_new_string_sized(nullptr, 0);
175 EXPECT_STREQ(fl_value_get_string(value), "");
176}
177
178TEST(FlValueTest, StringSizedZeroLength) {
179 g_autoptr(FlValue) value = fl_value_new_string_sized("hello", 0);
181 EXPECT_STREQ(fl_value_get_string(value), "");
182}
183
184TEST(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
190TEST(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
196TEST(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
202TEST(FlValueTest, Uint8List) {
203 uint8_t data[] = {0x00, 0x01, 0xFE, 0xFF};
204 g_autoptr(FlValue) value = fl_value_new_uint8_list(data, 4);
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
213TEST(FlValueTest, Uint8ListNullptr) {
214 g_autoptr(FlValue) value = fl_value_new_uint8_list(nullptr, 0);
216 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
217}
218
219TEST(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
227TEST(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
233TEST(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
241TEST(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
249TEST(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
256TEST(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
263TEST(FlValueTest, Int32List) {
264 int32_t data[] = {0, -1, G_MAXINT32, G_MININT32};
265 g_autoptr(FlValue) value = fl_value_new_int32_list(data, 4);
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
274TEST(FlValueTest, Int32ListNullptr) {
275 g_autoptr(FlValue) value = fl_value_new_int32_list(nullptr, 0);
277 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
278}
279
280TEST(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
288TEST(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
294TEST(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
302TEST(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
310TEST(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
317TEST(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
324TEST(FlValueTest, Int64List) {
325 int64_t data[] = {0, -1, G_MAXINT64, G_MININT64};
326 g_autoptr(FlValue) value = fl_value_new_int64_list(data, 4);
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
335TEST(FlValueTest, Int64ListNullptr) {
336 g_autoptr(FlValue) value = fl_value_new_int64_list(nullptr, 0);
338 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
339}
340
341TEST(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
349TEST(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
355TEST(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
363TEST(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
371TEST(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
378TEST(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
385TEST(FlValueTest, FloatList) {
386 double data[] = {0.0, -1.0, M_PI};
387 g_autoptr(FlValue) value = fl_value_new_float_list(data, 3);
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
395TEST(FlValueTest, FloatListNullptr) {
396 g_autoptr(FlValue) value = fl_value_new_float_list(nullptr, 0);
398 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
399}
400
401TEST(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
409TEST(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
415TEST(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
423TEST(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
431TEST(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
438TEST(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
445TEST(FlValueTest, ListEmpty) {
446 g_autoptr(FlValue) value = fl_value_new_list();
448 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
449}
450
451TEST(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);
456 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
459}
460
461TEST(FlValueTest, ListAddTake) {
462 g_autoptr(FlValue) value = fl_value_new_list();
465 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
468}
469
470TEST(FlValueTest, ListChildTypes) {
471 g_autoptr(FlValue) value = fl_value_new_list();
483 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(10));
504}
505
506TEST(FlValueTest, ListStrv) {
507 g_auto(GStrv) words = g_strsplit("hello:world", ":", -1);
508 g_autoptr(FlValue) value = fl_value_new_list_from_strv(words);
510 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(2));
513 EXPECT_STREQ(fl_value_get_string(fl_value_get_list_value(value, 0)), "hello");
516 EXPECT_STREQ(fl_value_get_string(fl_value_get_list_value(value, 1)), "world");
517}
518
519TEST(FlValueTest, ListStrvEmpty) {
520 g_auto(GStrv) words = g_strsplit("", ":", -1);
521 g_autoptr(FlValue) value = fl_value_new_list_from_strv(words);
523 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
524}
525
526TEST(FlValueTest, ListEqual) {
527 g_autoptr(FlValue) value1 = fl_value_new_list();
531 g_autoptr(FlValue) value2 = fl_value_new_list();
535 EXPECT_TRUE(fl_value_equal(value1, value2));
536}
537
538TEST(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
544TEST(FlValueTest, ListNotEqualSameSize) {
545 g_autoptr(FlValue) value1 = fl_value_new_list();
549 g_autoptr(FlValue) value2 = fl_value_new_list();
553 EXPECT_FALSE(fl_value_equal(value1, value2));
554}
555
556TEST(FlValueTest, ListNotEqualDifferentSize) {
557 g_autoptr(FlValue) value1 = fl_value_new_list();
561 g_autoptr(FlValue) value2 = fl_value_new_list();
566 EXPECT_FALSE(fl_value_equal(value1, value2));
567}
568
569TEST(FlValueTest, ListEmptyNotEqual) {
570 g_autoptr(FlValue) value1 = fl_value_new_list();
571 g_autoptr(FlValue) value2 = fl_value_new_list();
575 EXPECT_FALSE(fl_value_equal(value1, value2));
576}
577
578TEST(FlValueTest, ListToString) {
579 g_autoptr(FlValue) value = fl_value_new_list();
590 g_autofree gchar* text = fl_value_to_string(value);
591 EXPECT_STREQ(text,
592 "[null, true, 42, 3.1415926535897931, [], [], [], [], [], {}]");
593}
594
595TEST(FlValueTest, MapEmpty) {
596 g_autoptr(FlValue) value = fl_value_new_map();
598 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
599}
600
601TEST(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);
607 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
610 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
614}
615
616TEST(FlValueTest, MapSetTake) {
617 g_autoptr(FlValue) value = fl_value_new_map();
620 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
623 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
627}
628
629TEST(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);
634 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
637 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
641}
642
643TEST(FlValueTest, MapSetStringTake) {
644 g_autoptr(FlValue) value = fl_value_new_map();
647 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
650 EXPECT_STREQ(fl_value_get_string(fl_value_get_map_key(value, 0)), "count");
654}
655
656TEST(FlValueTest, MapLookup) {
657 g_autoptr(FlValue) value = fl_value_new_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);
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
672TEST(FlValueTest, MapLookupString) {
673 g_autoptr(FlValue) value = fl_value_new_map();
678 ASSERT_NE(v, nullptr);
680 EXPECT_EQ(fl_value_get_int(v), 2);
681 v = fl_value_lookup_string(value, "four");
682 ASSERT_EQ(v, nullptr);
683}
684
685TEST(FlValueTest, MapValueypes) {
686 g_autoptr(FlValue) value = fl_value_new_map();
694 fl_value_new_uint8_list(nullptr, 0));
696 fl_value_new_int32_list(nullptr, 0));
698 fl_value_new_int64_list(nullptr, 0));
700 fl_value_new_float_list(nullptr, 0));
704 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(10));
725}
726
727TEST(FlValueTest, MapKeyTypes) {
728 g_autoptr(FlValue) value = fl_value_new_map();
731 fl_value_new_string("bool"));
734 fl_value_new_string("float"));
736 fl_value_new_string("uint8_list"));
738 fl_value_new_string("int32_list"));
740 fl_value_new_string("int64_list"));
742 fl_value_new_string("float_list"));
746 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(10));
767}
768
769TEST(FlValueTest, MapEqual) {
770 g_autoptr(FlValue) value1 = fl_value_new_map();
773 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
774 g_autoptr(FlValue) value2 = fl_value_new_map();
777 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
778 EXPECT_TRUE(fl_value_equal(value1, value2));
779}
780
781TEST(FlValueTest, MapEqualDifferentOrder) {
782 g_autoptr(FlValue) value1 = fl_value_new_map();
785 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
786 g_autoptr(FlValue) value2 = fl_value_new_map();
788 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
790 EXPECT_TRUE(fl_value_equal(value1, value2));
791}
792
793TEST(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
799TEST(FlValueTest, MapNotEqualSameSizeDifferentKeys) {
800 g_autoptr(FlValue) value1 = fl_value_new_map();
803 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
804 g_autoptr(FlValue) value2 = fl_value_new_map();
807 fl_value_set_string_take(value2, "four", fl_value_new_int(3));
808 EXPECT_FALSE(fl_value_equal(value1, value2));
809}
810
811TEST(FlValueTest, MapNotEqualSameSizeDifferentValues) {
812 g_autoptr(FlValue) value1 = fl_value_new_map();
815 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
816 g_autoptr(FlValue) value2 = fl_value_new_map();
819 fl_value_set_string_take(value2, "three", fl_value_new_int(4));
820 EXPECT_FALSE(fl_value_equal(value1, value2));
821}
822
823TEST(FlValueTest, MapNotEqualDifferentSize) {
824 g_autoptr(FlValue) value1 = fl_value_new_map();
827 fl_value_set_string_take(value1, "three", fl_value_new_int(3));
828 g_autoptr(FlValue) value2 = fl_value_new_map();
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
836TEST(FlValueTest, MapEmptyNotEqual) {
837 g_autoptr(FlValue) value1 = fl_value_new_map();
838 g_autoptr(FlValue) value2 = fl_value_new_map();
841 fl_value_set_string_take(value2, "three", fl_value_new_int(3));
842 EXPECT_FALSE(fl_value_equal(value1, value2));
843}
844
845TEST(FlValueTest, MapToString) {
846 g_autoptr(FlValue) value = fl_value_new_map();
854 fl_value_new_uint8_list(nullptr, 0));
856 fl_value_new_int32_list(nullptr, 0));
858 fl_value_new_int64_list(nullptr, 0));
860 fl_value_new_float_list(nullptr, 0));
865 fl_value_new_string("bool"));
868 fl_value_new_string("float"));
870 fl_value_new_string("uint8_list"));
872 fl_value_new_string("int32_list"));
874 fl_value_new_string("int64_list"));
876 fl_value_new_string("float_list"));
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
888TEST(FlDartProjectTest, Custom) {
889 g_autoptr(FlValue) value =
890 fl_value_new_custom(128, g_strdup("Hello World"), g_free);
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
897TEST(FlDartProjectTest, CustomNoDestroyNotify) {
898 g_autoptr(FlValue) value = fl_value_new_custom(128, "Hello World", nullptr);
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
905TEST(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);
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
913TEST(FlDartProjectTest, CustomObjectTake) {
915 128, G_OBJECT(g_object_new(G_TYPE_OBJECT, nullptr)));
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
921TEST(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
927TEST(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
933TEST(FlValueTest, EqualSameObject) {
934 g_autoptr(FlValue) value = fl_value_new_null();
936}
937
938TEST(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
944TEST(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
950TEST(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
957TEST(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
965TEST(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
973TEST(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
981TEST(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}
#define M_PI
uint8_t value
G_MODULE_EXPORT void fl_value_set_string(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:639
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
G_MODULE_EXPORT FlValue * fl_value_new_custom_object_take(int type, GObject *object)
Definition: fl_value.cc:389
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:717
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition: fl_value.cc:846
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
G_MODULE_EXPORT FlValue * fl_value_new_custom(int type, gconstpointer value, GDestroyNotify destroy_notify)
Definition: fl_value.cc:374
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
Definition: fl_value.cc:309
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:592
G_MODULE_EXPORT FlValue * fl_value_new_custom_object(int type, GObject *object)
Definition: fl_value.cc:385
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition: fl_value.cc:784
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
Definition: fl_value.cc:822
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269
G_MODULE_EXPORT FlValue * fl_value_new_list_from_strv(const gchar *const *str_array)
Definition: fl_value.cc:356
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:689
G_MODULE_EXPORT FlValue * fl_value_lookup(FlValue *self, FlValue *key)
Definition: fl_value.cc:800
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition: fl_value.cc:830
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:776
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:661
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:292
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
Definition: fl_value.cc:339
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:283
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
Definition: fl_value.cc:319
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition: fl_value.cc:792
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:675
G_MODULE_EXPORT GObject * fl_value_get_custom_value_object(FlValue *self)
Definition: fl_value.cc:838
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:696
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:703
G_MODULE_EXPORT void fl_value_set(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:609
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:65
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:67
@ FL_VALUE_TYPE_BOOL
Definition: fl_value.h:66
@ FL_VALUE_TYPE_INT32_LIST
Definition: fl_value.h:71
@ FL_VALUE_TYPE_UINT8_LIST
Definition: fl_value.h:70
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:74
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:75
@ FL_VALUE_TYPE_INT64_LIST
Definition: fl_value.h:72
@ FL_VALUE_TYPE_FLOAT_LIST
Definition: fl_value.h:73
@ FL_VALUE_TYPE_CUSTOM
Definition: fl_value.h:77
@ FL_VALUE_TYPE_FLOAT
Definition: fl_value.h:68
TEST(FlDartProjectTest, Null)
std::u16string text
return FALSE
SK_API sk_sp< SkSurface > Null(int width, int height)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678