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 
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();
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);
31  EXPECT_TRUE(fl_value_get_bool(value));
32 }
33 
34 TEST(FlValueTest, BoolFalse) {
35  g_autoptr(FlValue) value = fl_value_new_bool(FALSE);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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");
157  EXPECT_STREQ(fl_value_get_string(value), "hello");
158 }
159 
160 TEST(FlValueTest, StringEmpty) {
161  g_autoptr(FlValue) value = fl_value_new_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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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();
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);
456  ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(1));
459 }
460 
461 TEST(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 
470 TEST(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 
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);
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 
519 TEST(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 
526 TEST(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 
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();
549  g_autoptr(FlValue) value2 = fl_value_new_list();
553  EXPECT_FALSE(fl_value_equal(value1, value2));
554 }
555 
556 TEST(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 
569 TEST(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 
578 TEST(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 
595 TEST(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 
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);
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");
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();
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");
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);
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");
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();
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");
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();
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();
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();
692  fl_value_new_float(M_PI));
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 
727 TEST(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 
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();
852  fl_value_new_float(M_PI));
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 
888 TEST(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 
897 TEST(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 
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);
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) {
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 
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 }
fl_value_get_int32_list
const G_MODULE_EXPORT int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:696
FL_VALUE_TYPE_UINT8_LIST
@ FL_VALUE_TYPE_UINT8_LIST
Definition: fl_value.h:70
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_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:75
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_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_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
fl_value_get_float_list
const G_MODULE_EXPORT double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:717
fl_value_new_bool
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:255
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
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_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
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_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251
FL_VALUE_TYPE_LIST
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:74
fl_value_get_bool
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:661
fl_value_get_uint8_list
const G_MODULE_EXPORT uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:689
fl_value_set
G_MODULE_EXPORT void fl_value_set(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:609
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262
fl_value_get_string
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:65
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
FL_VALUE_TYPE_CUSTOM
@ FL_VALUE_TYPE_CUSTOM
Definition: fl_value.h:77
TEST
TEST(FlDartProjectTest, Null)
Definition: fl_value_test.cc:11
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
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_custom_object_take
G_MODULE_EXPORT FlValue * fl_value_new_custom_object_take(int type, GObject *object)
Definition: fl_value.cc:389
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:69
fl_value_get_custom_value
G_MODULE_EXPORT gconstpointer fl_value_get_custom_value(FlValue *self)
Definition: fl_value.cc:830
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
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
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_float
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:675
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
FL_VALUE_TYPE_INT64_LIST
@ FL_VALUE_TYPE_INT64_LIST
Definition: fl_value.h:72
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471
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_TYPE_INT
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:67
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_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.h
fl_value_get_custom_type
G_MODULE_EXPORT int fl_value_get_custom_type(FlValue *self)
Definition: fl_value.cc:822
FL_VALUE_TYPE_FLOAT_LIST
@ FL_VALUE_TYPE_FLOAT_LIST
Definition: fl_value.h:73
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_append
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:592
FL_VALUE_TYPE_FLOAT
@ FL_VALUE_TYPE_FLOAT
Definition: fl_value.h:68
FL_VALUE_TYPE_INT32_LIST
@ FL_VALUE_TYPE_INT32_LIST
Definition: fl_value.h:71
fl_value_new_float
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:269
fl_value_lookup
G_MODULE_EXPORT FlValue * fl_value_lookup(FlValue *self, FlValue *key)
Definition: fl_value.cc:800
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_int64_list
const G_MODULE_EXPORT int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:703
FL_VALUE_TYPE_BOOL
@ FL_VALUE_TYPE_BOOL
Definition: fl_value.h:66
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
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_to_string
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition: fl_value.cc:846
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276