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 
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, 4);
389  ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(4));
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(FlValueTest, EqualSameObject) {
889  g_autoptr(FlValue) value = fl_value_new_null();
890  EXPECT_TRUE(fl_value_equal(value, value));
891 }
892 
893 TEST(FlValueTest, NullIntNotEqual) {
894  g_autoptr(FlValue) value1 = fl_value_new_null();
895  g_autoptr(FlValue) value2 = fl_value_new_int(0);
896  EXPECT_FALSE(fl_value_equal(value1, value2));
897 }
898 
899 TEST(FlValueTest, NullBoolNotEqual) {
900  g_autoptr(FlValue) value1 = fl_value_new_bool(FALSE);
901  g_autoptr(FlValue) value2 = fl_value_new_int(0);
902  EXPECT_FALSE(fl_value_equal(value1, value2));
903 }
904 
905 TEST(FlValueTest, StringUint8ListNotEqual) {
906  uint8_t data[] = {'h', 'e', 'l', 'l', 'o'};
907  g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data, 5);
908  g_autoptr(FlValue) value2 = fl_value_new_string("hello");
909  EXPECT_FALSE(fl_value_equal(value1, value2));
910 }
911 
912 TEST(FlValueTest, Uint8ListInt32ListNotEqual) {
913  uint8_t data8[] = {0, 1, 2, 3, 4};
914  int32_t data32[] = {0, 1, 2, 3, 4};
915  g_autoptr(FlValue) value1 = fl_value_new_uint8_list(data8, 5);
916  g_autoptr(FlValue) value2 = fl_value_new_int32_list(data32, 5);
917  EXPECT_FALSE(fl_value_equal(value1, value2));
918 }
919 
920 TEST(FlValueTest, Int32ListInt64ListNotEqual) {
921  int32_t data32[] = {0, 1, 2, 3, 4};
922  int64_t data64[] = {0, 1, 2, 3, 4};
923  g_autoptr(FlValue) value1 = fl_value_new_int32_list(data32, 5);
924  g_autoptr(FlValue) value2 = fl_value_new_int64_list(data64, 5);
925  EXPECT_FALSE(fl_value_equal(value1, value2));
926 }
927 
928 TEST(FlValueTest, Int64ListFloatListNotEqual) {
929  int64_t data64[] = {0, 1, 2, 3, 4};
930  double dataf[] = {0.0, 1.0, 2.0, 3.0, 4.0};
931  g_autoptr(FlValue) value1 = fl_value_new_int64_list(data64, 5);
932  g_autoptr(FlValue) value2 = fl_value_new_float_list(dataf, 5);
933  EXPECT_FALSE(fl_value_equal(value1, value2));
934 }
935 
936 TEST(FlValueTest, ListMapNotEqual) {
937  g_autoptr(FlValue) value1 = fl_value_new_list();
938  g_autoptr(FlValue) value2 = fl_value_new_map();
939  EXPECT_FALSE(fl_value_equal(value1, value2));
940 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:240
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:263
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
Definition: fl_value.cc:290
G_MODULE_EXPORT void fl_value_set(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:523
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:327
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
Definition: fl_value.cc:280
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:624
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:582
G_MODULE_EXPORT FlValue * fl_value_new_list_from_strv(const gchar *const *str_array)
Definition: fl_value.cc:317
TEST(FlDartProjectTest, Null)
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:617
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:226
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:603
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:400
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:506
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:589
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
uint8_t value
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:532
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:712
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:677
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition: fl_value.cc:693
G_MODULE_EXPORT gchar * fl_value_to_string(FlValue *value)
Definition: fl_value.cc:723
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247
G_MODULE_EXPORT FlValue * fl_value_lookup(FlValue *self, FlValue *key)
Definition: fl_value.cc:701
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition: fl_value.cc:685
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:610
return TRUE
Definition: fl_view.cc:107
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
G_MODULE_EXPORT void fl_value_set_string(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:553
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:564
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
Definition: fl_value.cc:300
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:254
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:631
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:575