Lines Matching +full:d3 +full:- +full:hierarchy
8 * http://www.apache.org/licenses/LICENSE-2.0
41 …"monster_test_bfbs_generated.h" // Generated using --bfbs-comments --bfbs-builtins --cpp --bfbs-g…
49 // clang-format off
57 // Ensure IEEE-754 support if tests of floats with NaN/Inf will run.
60 "IEC-559 (IEEE-754) standard required");
62 // clang-format on
110 2, [&](size_t i, Test *s) -> void { *s = tests[i]; }); in CreateFlatBufferTest()
134 -> flatbuffers::Offset<flatbuffers::String> { in CreateFlatBufferTest()
136 return b->CreateSharedString(names[i]); in CreateFlatBufferTest()
203 // buffer contains 64-bit elements, they may not be correctly aligned. We fix in CreateFlatBufferTest()
208 // can substitute flatbuffers::largest_scalar_t (64-bit) for the alignment, or in CreateFlatBufferTest()
221 // pre-C++11 (enum class) enums whose size likely is int, yet its declared in CreateFlatBufferTest()
237 // clang-format off in CreateFlatBufferTest()
244 // clang-format on in CreateFlatBufferTest()
263 // clang-format off in AccessFlatBufferTest()
278 // clang-format on in AccessFlatBufferTest()
287 TEST_EQ(monster->hp(), 80); in AccessFlatBufferTest()
288 TEST_EQ(monster->mana(), 150); // default in AccessFlatBufferTest()
289 TEST_EQ_STR(monster->name()->c_str(), "MyMonster"); in AccessFlatBufferTest()
294 auto pos = monster->pos(); in AccessFlatBufferTest()
296 TEST_EQ(pos->z(), 3); in AccessFlatBufferTest()
297 TEST_EQ(pos->test3().a(), 10); in AccessFlatBufferTest()
298 TEST_EQ(pos->test3().b(), 20); in AccessFlatBufferTest()
300 auto inventory = monster->inventory(); in AccessFlatBufferTest()
305 std::vector<unsigned char> inv_vec(inventory->begin(), inventory->end()); in AccessFlatBufferTest()
307 for (auto it = inventory->begin(); it != inventory->end(); ++it, ++n) { in AccessFlatBufferTest()
308 auto indx = it - inventory->begin(); in AccessFlatBufferTest()
309 TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check. in AccessFlatBufferTest()
315 for (auto it = inventory->cbegin(); it != inventory->cend(); ++it, ++n) { in AccessFlatBufferTest()
316 auto indx = it - inventory->cbegin(); in AccessFlatBufferTest()
317 TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check. in AccessFlatBufferTest()
323 for (auto it = inventory->rbegin(); it != inventory->rend(); ++it, ++n) { in AccessFlatBufferTest()
324 auto indx = inventory->rend() - it - 1; in AccessFlatBufferTest()
325 TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check. in AccessFlatBufferTest()
331 for (auto it = inventory->crbegin(); it != inventory->crend(); ++it, ++n) { in AccessFlatBufferTest()
332 auto indx = inventory->crend() - it - 1; in AccessFlatBufferTest()
333 TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check. in AccessFlatBufferTest()
338 TEST_EQ(monster->color(), Color_Blue); in AccessFlatBufferTest()
341 TEST_EQ(monster->test_type(), Any_Monster); // First make sure which it is. in AccessFlatBufferTest()
342 auto monster2 = reinterpret_cast<const Monster *>(monster->test()); in AccessFlatBufferTest()
344 TEST_EQ_STR(monster2->name()->c_str(), "Fred"); in AccessFlatBufferTest()
347 auto vecofstrings = monster->testarrayofstring(); in AccessFlatBufferTest()
348 TEST_EQ(vecofstrings->size(), 4U); in AccessFlatBufferTest()
349 TEST_EQ_STR(vecofstrings->Get(0)->c_str(), "bob"); in AccessFlatBufferTest()
350 TEST_EQ_STR(vecofstrings->Get(1)->c_str(), "fred"); in AccessFlatBufferTest()
353 TEST_EQ(vecofstrings->Get(0)->c_str(), vecofstrings->Get(2)->c_str()); in AccessFlatBufferTest()
354 TEST_EQ(vecofstrings->Get(1)->c_str(), vecofstrings->Get(3)->c_str()); in AccessFlatBufferTest()
357 auto vecofstrings2 = monster->testarrayofstring2(); in AccessFlatBufferTest()
359 TEST_EQ(vecofstrings2->size(), 2U); in AccessFlatBufferTest()
360 TEST_EQ_STR(vecofstrings2->Get(0)->c_str(), "jane"); in AccessFlatBufferTest()
361 TEST_EQ_STR(vecofstrings2->Get(1)->c_str(), "mary"); in AccessFlatBufferTest()
365 auto vecoftables = monster->testarrayoftables(); in AccessFlatBufferTest()
366 TEST_EQ(vecoftables->size(), 3U); in AccessFlatBufferTest()
367 for (auto it = vecoftables->begin(); it != vecoftables->end(); ++it) { in AccessFlatBufferTest()
368 TEST_EQ(strlen(it->name()->c_str()) >= 4, true); in AccessFlatBufferTest()
370 TEST_EQ_STR(vecoftables->Get(0)->name()->c_str(), "Barney"); in AccessFlatBufferTest()
371 TEST_EQ(vecoftables->Get(0)->hp(), 1000); in AccessFlatBufferTest()
372 TEST_EQ_STR(vecoftables->Get(1)->name()->c_str(), "Fred"); in AccessFlatBufferTest()
373 TEST_EQ_STR(vecoftables->Get(2)->name()->c_str(), "Wilma"); in AccessFlatBufferTest()
374 TEST_NOTNULL(vecoftables->LookupByKey("Barney")); in AccessFlatBufferTest()
375 TEST_NOTNULL(vecoftables->LookupByKey("Fred")); in AccessFlatBufferTest()
376 TEST_NOTNULL(vecoftables->LookupByKey("Wilma")); in AccessFlatBufferTest()
379 auto vecofstructs = monster->testarrayofsortedstruct(); in AccessFlatBufferTest()
381 for (flatbuffers::uoffset_t i = 0; i < vecofstructs->size() - 1; i++) { in AccessFlatBufferTest()
382 auto left = vecofstructs->Get(i); in AccessFlatBufferTest()
383 auto right = vecofstructs->Get(i + 1); in AccessFlatBufferTest()
384 TEST_EQ(true, (left->KeyCompareLessThan(right))); in AccessFlatBufferTest()
386 TEST_NOTNULL(vecofstructs->LookupByKey(0)); // test default value in AccessFlatBufferTest()
387 TEST_NOTNULL(vecofstructs->LookupByKey(3)); in AccessFlatBufferTest()
389 vecofstructs->LookupByKey(5)); in AccessFlatBufferTest()
392 if (auto vec_of_stat = monster->scalar_key_sorted_tables()) { in AccessFlatBufferTest()
393 auto stat_0 = vec_of_stat->LookupByKey(static_cast<uint16_t>(0u)); in AccessFlatBufferTest()
395 TEST_NOTNULL(stat_0->id()); in AccessFlatBufferTest()
396 TEST_EQ(0, stat_0->count()); in AccessFlatBufferTest()
397 TEST_EQ_STR("miss", stat_0->id()->c_str()); in AccessFlatBufferTest()
401 auto nested_buffer = monster->testnestedflatbuffer(); in AccessFlatBufferTest()
406 auto nested_monster = monster->testnestedflatbuffer_nested_root(); in AccessFlatBufferTest()
407 TEST_EQ_STR(nested_monster->name()->c_str(), "NestedMonster"); in AccessFlatBufferTest()
411 auto flex = monster->flex(); in AccessFlatBufferTest()
413 TEST_EQ(flex->size(), 4); // Encoded FlexBuffer bytes. in AccessFlatBufferTest()
416 TEST_EQ(monster->flex_flexbuffer_root().AsInt16(), 1234); in AccessFlatBufferTest()
419 auto colors = monster->vector_of_enums(); in AccessFlatBufferTest()
421 TEST_EQ(colors->size(), 2); in AccessFlatBufferTest()
422 TEST_EQ(colors->Get(0), Color_Blue); in AccessFlatBufferTest()
423 TEST_EQ(colors->Get(1), Color_Green); in AccessFlatBufferTest()
433 monster->test4(), in AccessFlatBufferTest()
434 monster->test5(), in AccessFlatBufferTest()
439 auto test_0 = tests->Get(0); in AccessFlatBufferTest()
440 auto test_1 = tests->Get(1); in AccessFlatBufferTest()
441 TEST_EQ(test_0->a(), 10); in AccessFlatBufferTest()
442 TEST_EQ(test_0->b(), 20); in AccessFlatBufferTest()
443 TEST_EQ(test_1->a(), 30); in AccessFlatBufferTest()
444 TEST_EQ(test_1->b(), 40); in AccessFlatBufferTest()
445 for (auto it = tests->begin(); it != tests->end(); ++it) { in AccessFlatBufferTest()
446 TEST_EQ(it->a() == 10 || it->a() == 30, true); // Just testing iterators. in AccessFlatBufferTest()
458 // Change a FlatBuffer in-place, after it has been constructed.
460 // Get non-const pointer to root. in MutateFlatBuffersTest()
465 auto hp_ok = monster->mutate_hp(10); in MutateFlatBuffersTest()
467 TEST_EQ(monster->hp(), 10); in MutateFlatBuffersTest()
469 auto hp_ok_default = monster->mutate_hp(100); in MutateFlatBuffersTest()
471 TEST_EQ(monster->hp(), 100); in MutateFlatBuffersTest()
473 auto hp_ok_2 = monster->mutate_hp(20); in MutateFlatBuffersTest()
475 TEST_EQ(monster->hp(), 20); in MutateFlatBuffersTest()
476 monster->mutate_hp(80); in MutateFlatBuffersTest()
479 auto mana_default_ok = monster->mutate_mana(150); // Mutate to default value. in MutateFlatBuffersTest()
482 TEST_EQ(monster->mana(), 150); in MutateFlatBuffersTest()
483 auto mana_ok = monster->mutate_mana(10); in MutateFlatBuffersTest()
485 TEST_EQ(monster->mana(), 150); in MutateFlatBuffersTest()
488 auto pos = monster->mutable_pos(); in MutateFlatBuffersTest()
489 auto test3 = pos->mutable_test3(); // Struct inside a struct. in MutateFlatBuffersTest()
495 auto inventory = monster->mutable_inventory(); in MutateFlatBuffersTest()
496 inventory->Mutate(9, 100); in MutateFlatBuffersTest()
497 TEST_EQ(inventory->Get(9), 100); in MutateFlatBuffersTest()
498 inventory->Mutate(9, 9); in MutateFlatBuffersTest()
500 auto tables = monster->mutable_testarrayoftables(); in MutateFlatBuffersTest()
501 auto first = tables->GetMutableObject(0); in MutateFlatBuffersTest()
502 TEST_EQ(first->hp(), 1000); in MutateFlatBuffersTest()
503 first->mutate_hp(0); in MutateFlatBuffersTest()
504 TEST_EQ(first->hp(), 0); in MutateFlatBuffersTest()
505 first->mutate_hp(1000); in MutateFlatBuffersTest()
508 TEST_NOTNULL(tables->MutableLookupByKey("Barney")); in MutateFlatBuffersTest()
510 tables->MutableLookupByKey("DoesntExist")); in MutateFlatBuffersTest()
511 TEST_EQ(tables->MutableLookupByKey("Barney")->hp(), 1000); in MutateFlatBuffersTest()
512 TEST_EQ(tables->MutableLookupByKey("Barney")->mutate_hp(0), true); in MutateFlatBuffersTest()
513 TEST_EQ(tables->LookupByKey("Barney")->hp(), 0); in MutateFlatBuffersTest()
514 TEST_EQ(tables->MutableLookupByKey("Barney")->mutate_hp(1000), true); in MutateFlatBuffersTest()
523 TEST_EQ(monster2->hp, 80); in CheckMonsterObject()
524 TEST_EQ(monster2->mana, 150); // default in CheckMonsterObject()
525 TEST_EQ_STR(monster2->name.c_str(), "MyMonster"); in CheckMonsterObject()
527 auto &pos = monster2->pos; in CheckMonsterObject()
529 TEST_EQ(pos->z(), 3); in CheckMonsterObject()
530 TEST_EQ(pos->test3().a(), 10); in CheckMonsterObject()
531 TEST_EQ(pos->test3().b(), 20); in CheckMonsterObject()
533 auto &inventory = monster2->inventory; in CheckMonsterObject()
537 TEST_EQ(*it, inv_data[it - inventory.begin()]); in CheckMonsterObject()
539 TEST_EQ(monster2->color, Color_Blue); in CheckMonsterObject()
541 auto monster3 = monster2->test.AsMonster(); in CheckMonsterObject()
543 TEST_EQ_STR(monster3->name.c_str(), "Fred"); in CheckMonsterObject()
545 auto &vecofstrings = monster2->testarrayofstring; in CheckMonsterObject()
550 auto &vecofstrings2 = monster2->testarrayofstring2; in CheckMonsterObject()
555 auto &vecoftables = monster2->testarrayoftables; in CheckMonsterObject()
557 TEST_EQ_STR(vecoftables[0]->name.c_str(), "Barney"); in CheckMonsterObject()
558 TEST_EQ(vecoftables[0]->hp, 1000); in CheckMonsterObject()
559 TEST_EQ_STR(vecoftables[1]->name.c_str(), "Fred"); in CheckMonsterObject()
560 TEST_EQ_STR(vecoftables[2]->name.c_str(), "Wilma"); in CheckMonsterObject()
562 auto &tests = monster2->test4; in CheckMonsterObject()
581 [](void *pointer) -> flatbuffers::hash_value_t { in ObjectFlatBuffersTest()
589 // Re-serialize the data. in ObjectFlatBuffersTest()
594 // Unpack again, and re-serialize again. in ObjectFlatBuffersTest()
600 // Now we've gone full round-trip, the two buffers should match. in ObjectFlatBuffersTest()
638 TEST_EQ(m->mana(), 200); in SizePrefixedTest()
639 TEST_EQ(m->hp(), 300); in SizePrefixedTest()
640 TEST_EQ_STR(m->name()->c_str(), "bob"); in SizePrefixedTest()
644 // clang-format off in TriviallyCopyableTest()
653 // clang-format on in TriviallyCopyableTest()
769 // The IEEE-754 quiet_NaN is not simple binary constant.
773 // It is assumed that endianness of floating-point is same as integer.
801 TEST_EQ(is_quiet_nan(-infinity_f), false); in TestMonsterExtraFloats()
827 TEST_EQ(is_quiet_nan(def_extra->f0()), true); in TestMonsterExtraFloats()
828 TEST_EQ(is_quiet_nan(def_extra->f1()), true); in TestMonsterExtraFloats()
829 TEST_EQ(def_extra->f2(), +infinity_f); in TestMonsterExtraFloats()
830 TEST_EQ(def_extra->f3(), -infinity_f); in TestMonsterExtraFloats()
831 TEST_EQ(is_quiet_nan(def_extra->d0()), true); in TestMonsterExtraFloats()
832 TEST_EQ(is_quiet_nan(def_extra->d1()), true); in TestMonsterExtraFloats()
833 TEST_EQ(def_extra->d2(), +infinity_d); in TestMonsterExtraFloats()
834 TEST_EQ(def_extra->d3(), -infinity_d); in TestMonsterExtraFloats()
842 TEST_EQ(std::string::npos != jsongen.find("f3: -inf"), true); in TestMonsterExtraFloats()
846 TEST_EQ(std::string::npos != jsongen.find("d3: -inf"), true); in TestMonsterExtraFloats()
858 TEST_EQ(is_quiet_nan(extra->f0()), true); in TestMonsterExtraFloats()
859 TEST_EQ(is_quiet_nan(extra->f1()), true); in TestMonsterExtraFloats()
860 TEST_EQ(extra->f2(), +infinity_f); in TestMonsterExtraFloats()
861 TEST_EQ(extra->f3(), -infinity_f); in TestMonsterExtraFloats()
862 TEST_EQ(is_quiet_nan(extra->d0()), true); in TestMonsterExtraFloats()
863 TEST_EQ(extra->d1(), +infinity_d); in TestMonsterExtraFloats()
864 TEST_EQ(extra->d2(), -infinity_d); in TestMonsterExtraFloats()
865 TEST_EQ(is_quiet_nan(extra->d3()), true); in TestMonsterExtraFloats()
866 TEST_NOTNULL(extra->fvec()); in TestMonsterExtraFloats()
867 TEST_EQ(extra->fvec()->size(), 4); in TestMonsterExtraFloats()
868 TEST_EQ(extra->fvec()->Get(0), 1.0f); in TestMonsterExtraFloats()
869 TEST_EQ(extra->fvec()->Get(1), -infinity_f); in TestMonsterExtraFloats()
870 TEST_EQ(extra->fvec()->Get(2), +infinity_f); in TestMonsterExtraFloats()
871 TEST_EQ(is_quiet_nan(extra->fvec()->Get(3)), true); in TestMonsterExtraFloats()
872 TEST_NOTNULL(extra->dvec()); in TestMonsterExtraFloats()
873 TEST_EQ(extra->dvec()->size(), 4); in TestMonsterExtraFloats()
874 TEST_EQ(extra->dvec()->Get(0), 2.0); in TestMonsterExtraFloats()
875 TEST_EQ(extra->dvec()->Get(1), +infinity_d); in TestMonsterExtraFloats()
876 TEST_EQ(extra->dvec()->Get(2), -infinity_d); in TestMonsterExtraFloats()
877 TEST_EQ(is_quiet_nan(extra->dvec()->Get(3)), true); in TestMonsterExtraFloats()
963 // Generate text for UTF-8 strings without escapes. in ParseAndGenerateTextTest()
969 // To ensure it is correct, generate utf-8 text back from the binary. in ParseAndGenerateTextTest()
971 // request natural printing for utf-8 strings in ParseAndGenerateTextTest()
997 TEST_EQ_STR(root_table->name()->c_str(), "MyGame.Example.Monster"); in ReflectionTest()
998 TEST_EQ_STR(root_table->declaration_file()->c_str(), "//monster_test.fbs"); in ReflectionTest()
1000 schema.objects()->LookupByKey("TableA")->declaration_file()->c_str(), in ReflectionTest()
1003 ->LookupByKey("MyGame.OtherNameSpace.Unused") in ReflectionTest()
1004 ->declaration_file() in ReflectionTest()
1005 ->c_str(), in ReflectionTest()
1008 ->LookupByKey("MyGame.OtherNameSpace.FromInclude") in ReflectionTest()
1009 ->declaration_file() in ReflectionTest()
1010 ->c_str(), in ReflectionTest()
1014 TEST_EQ(schema.fbs_files()->size(), 3); in ReflectionTest()
1016 const auto fbs0 = schema.fbs_files()->Get(0); in ReflectionTest()
1017 TEST_EQ_STR(fbs0->filename()->c_str(), "//include_test/include_test1.fbs"); in ReflectionTest()
1018 const auto fbs0_includes = fbs0->included_filenames(); in ReflectionTest()
1019 TEST_EQ(fbs0_includes->size(), 2); in ReflectionTest()
1022 TEST_EQ_STR(fbs0_includes->Get(0)->c_str(), in ReflectionTest()
1024 TEST_EQ_STR(fbs0_includes->Get(1)->c_str(), in ReflectionTest()
1027 const auto fbs1 = schema.fbs_files()->Get(1); in ReflectionTest()
1028 TEST_EQ_STR(fbs1->filename()->c_str(), in ReflectionTest()
1030 const auto fbs1_includes = fbs1->included_filenames(); in ReflectionTest()
1031 TEST_EQ(fbs1_includes->size(), 2); in ReflectionTest()
1032 TEST_EQ_STR(fbs1_includes->Get(0)->c_str(), in ReflectionTest()
1034 TEST_EQ_STR(fbs1_includes->Get(1)->c_str(), in ReflectionTest()
1037 const auto fbs2 = schema.fbs_files()->Get(2); in ReflectionTest()
1038 TEST_EQ_STR(fbs2->filename()->c_str(), "//monster_test.fbs"); in ReflectionTest()
1039 const auto fbs2_includes = fbs2->included_filenames(); in ReflectionTest()
1040 TEST_EQ(fbs2_includes->size(), 1); in ReflectionTest()
1041 TEST_EQ_STR(fbs2_includes->Get(0)->c_str(), in ReflectionTest()
1045 auto fields = root_table->fields(); in ReflectionTest()
1046 auto hp_field_ptr = fields->LookupByKey("hp"); in ReflectionTest()
1049 TEST_EQ_STR(hp_field.name()->c_str(), "hp"); in ReflectionTest()
1051 TEST_EQ(hp_field.type()->base_type(), reflection::Short); in ReflectionTest()
1053 auto friendly_field_ptr = fields->LookupByKey("friendly"); in ReflectionTest()
1055 TEST_NOTNULL(friendly_field_ptr->attributes()); in ReflectionTest()
1056 TEST_NOTNULL(friendly_field_ptr->attributes()->LookupByKey("priority")); in ReflectionTest()
1059 auto pos_field_ptr = fields->LookupByKey("pos"); in ReflectionTest()
1061 TEST_EQ(pos_field_ptr->type()->base_type(), reflection::Obj); in ReflectionTest()
1062 auto pos_table_ptr = schema.objects()->Get(pos_field_ptr->type()->index()); in ReflectionTest()
1064 TEST_EQ_STR(pos_table_ptr->name()->c_str(), "MyGame.Example.Vec3"); in ReflectionTest()
1066 // Test nullability of fields: hp is a 0-default scalar, pos is a struct => in ReflectionTest()
1069 TEST_EQ(pos_field_ptr->optional(), true); in ReflectionTest()
1070 TEST_EQ(fields->LookupByKey("name")->optional(), false); in ReflectionTest()
1095 *pos_table_ptr->fields()->LookupByKey("z")), in ReflectionTest()
1098 auto test3_field = pos_table_ptr->fields()->LookupByKey("test3"); in ReflectionTest()
1101 auto test3_object = schema.objects()->Get(test3_field->type()->index()); in ReflectionTest()
1104 *test3_object->fields()->LookupByKey("a")), in ReflectionTest()
1130 // More advanced functionality: changing the size of items in-line! in ReflectionTest()
1134 auto &name_field = *fields->LookupByKey("name"); in ReflectionTest()
1143 TEST_EQ_STR(GetFieldS(**rroot, name_field)->c_str(), "totally new string"); in ReflectionTest()
1144 // Now lets extend a vector by 100 elements (10 -> 110). in ReflectionTest()
1145 auto &inventory_field = *fields->LookupByKey("inventory"); in ReflectionTest()
1151 TEST_EQ(rinventory->Get(10), 50); in ReflectionTest()
1158 auto &testarrayofstring_field = *fields->LookupByKey("testarrayofstring"); in ReflectionTest()
1178 rtestarrayofstring->MutateOffset(2, string_ptr); in ReflectionTest()
1179 TEST_EQ_STR(rtestarrayofstring->Get(0)->c_str(), "bob"); in ReflectionTest()
1180 TEST_EQ_STR(rtestarrayofstring->Get(2)->c_str(), "hank"); in ReflectionTest()
1194 // rather than changing the string in-place. in ReflectionTest()
1196 TEST_EQ_STR(GetFieldS(**rroot, name_field)->c_str(), "hank"); in ReflectionTest()
1320 // Parse proto with --oneof-union option. in ParseProtoTest()
1372 // Parse proto with --oneof-union option. in ParseProtoTestWithSuffix()
1441 // Parse proto with --oneof-union option. in ParseProtoTestWithIncludes()
1460 T read = table->GetField(voffset, static_cast<T>(0)); in CompareTableFieldValue()
1562 const int8_t char_val = -127; // 0x81 in FuzzTest1()
1564 const int16_t short_val = -32222; // 0x8222; in FuzzTest1()
1616 auto table = reinterpret_cast<flatbuffers::Table *>(eob - objects[i]); in FuzzTest1()
1667 // clang-format off in FuzzTest2()
1675 // clang-format on in FuzzTest2()
1686 // hierarchy, we get some variety by picking one randomly. in FuzzTest2()
1697 const bool is_last_field = field == fields_per_definition - 1; in FuzzTest2()
1754 deprecated ? "" : "255"); // No fixed-length arrays in tables. in FuzzTest2()
1781 schema += "root_type D" + flatbuffers::NumToString(num_definitions - 1); in FuzzTest2()
1794 definitions[num_definitions - 1].instances[0] + "\n"; in FuzzTest2()
1810 i -= std::min(static_cast<size_t>(10), i); // show some context; in FuzzTest2()
1818 TEST_NOTNULL(nullptr); //-V501 (this comment supresses CWE-570 warning) in FuzzTest2()
1821 // clang-format off in FuzzTest2()
1827 // clang-format on in FuzzTest2()
1920 // Array of non-scalar in ErrorTest()
1923 // Non-snake case field names in ErrorTest()
1931 // An identifier can't start from sign (+|-) in ErrorTest()
1932 TestError("table X { -Y: int; } root_type Y: {Y:1.0}", "identifier"); in ErrorTest()
1957 parser.opts.indent_step = -1; in TestValue()
1965 return root->GetField<T>(flatbuffers::FieldIndexToOffset(0), 0); in TestValue()
1968 bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; } in FloatCompare()
1982 TEST_EQ(FloatCompare(TestValue<float>("{ y:cos(rad(180)) }", "float"), -1), in ValueTest()
1986 TEST_EQ(TestValue<int>("{ y:\"-876\" }", "int=-123"), -876); in ValueTest()
1987 TEST_EQ(TestValue<int>("{ y:\"876\" }", "int=-123"), 876); in ValueTest()
1990 TEST_EQ(TestValue<int>("{ y:-0x8ea0 }", "int=-0x8ea0"), -36512); in ValueTest()
1991 TEST_EQ(TestValue<int>(nullptr, "int=-0x8ea0"), -36512); in ValueTest()
2049 // 2) Valid enum range: [0; 2^(ceil(log2(Color_ANY))) - 1]. in EnumNamesTest()
2052 …// stackoverflow.com/questions/18195312/what-happens-if-you-static-cast-invalid-value-to-enum-class in EnumNamesTest()
2054 TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY - 1))); in EnumNamesTest()
2060 TestError("enum X:byte { Y = -129 }", "enum value does not fit"); in EnumOutOfRangeTest()
2062 TestError("enum X:ubyte { Y = -1 }", "enum value does not fit"); in EnumOutOfRangeTest()
2065 TestError("table Y{} union X { Y = -1 }", "enum value does not fit"); in EnumOutOfRangeTest()
2068 TestError("enum X:int { Y = -2147483649 }", "enum value does not fit"); in EnumOutOfRangeTest()
2070 TestError("enum X:uint { Y = -1 }", "enum value does not fit"); in EnumOutOfRangeTest()
2075 TestError("enum X:ulong { Y = -1 }", "does not fit"); in EnumOutOfRangeTest()
2077 TestError("enum X:byte (bit_flags) { Y=7 }", "must be unsigned"); // -128 in EnumOutOfRangeTest()
2106 // Assign non-enum value to enum field. Is it right? in EnumValueTest()
2108 // Check that non-ascending values are valid. in EnumValueTest()
2115 TestError("table T { F:byte; } root_type T; { F:-129 }", in IntegerOutOfRangeTest()
2119 TestError("table T { F:ubyte; } root_type T; { F:-1 }", in IntegerOutOfRangeTest()
2123 TestError("table T { F:short; } root_type T; { F:-32769 }", in IntegerOutOfRangeTest()
2127 TestError("table T { F:ushort; } root_type T; { F:-1 }", in IntegerOutOfRangeTest()
2131 TestError("table T { F:int; } root_type T; { F:-2147483649 }", in IntegerOutOfRangeTest()
2135 TestError("table T { F:uint; } root_type T; { F:-1 }", in IntegerOutOfRangeTest()
2138 TestError("table X { Y:uint8; } root_type X; { Y: -1 }", "does not fit"); in IntegerOutOfRangeTest()
2140 TestError("table X { Y:uint16; } root_type X; { Y: -1 }", "does not fit"); in IntegerOutOfRangeTest()
2142 TestError("table X { Y:uint32; } root_type X; { Y: -1 }", ""); in IntegerOutOfRangeTest()
2145 TestError("table X { Y:uint64; } root_type X; { Y: -1 }", ""); in IntegerOutOfRangeTest()
2146 TestError("table X { Y:uint64; } root_type X; { Y: -9223372036854775809 }", in IntegerOutOfRangeTest()
2151 TestError("table X { Y:int8; } root_type X; { Y: -129 }", "does not fit"); in IntegerOutOfRangeTest()
2153 TestError("table X { Y:int16; } root_type X; { Y: -32769 }", "does not fit"); in IntegerOutOfRangeTest()
2155 TestError("table X { Y:int32; } root_type X; { Y: -2147483649 }", ""); in IntegerOutOfRangeTest()
2158 TestError("table X { Y:int64; } root_type X; { Y: -9223372036854775809 }", in IntegerOutOfRangeTest()
2162 // check out-of-int64 as int8 in IntegerOutOfRangeTest()
2163 TestError("table X { Y:int8; } root_type X; { Y: -9223372036854775809 }", in IntegerOutOfRangeTest()
2169 TestError("table X { Y:int64=-9223372036854775809; } root_type X; {}", in IntegerOutOfRangeTest()
2173 TestError("table X { Y:uint64; } root_type X; { Y: -1 }", ""); in IntegerOutOfRangeTest()
2174 TestError("table X { Y:uint64=-9223372036854775809; } root_type X; {}", in IntegerOutOfRangeTest()
2181 // Check numerical compatibility with non-C++ languages. in IntegerBoundaryTest()
2183 // -9223372036854775807 (-2^63+1) or less* The Flatbuffers grammar and most of in IntegerBoundaryTest()
2184 // the languages (C#, Java, Rust) expect that minimum values are: -128, in IntegerBoundaryTest()
2185 // -32768,.., -9223372036854775808. Since C++20, in IntegerBoundaryTest()
2186 // static_cast<int64>(0x8000000000000000ULL) is well-defined two's complement in IntegerBoundaryTest()
2187 // cast. Therefore -9223372036854775808 should be valid negative value. in IntegerBoundaryTest()
2188 TEST_EQ(flatbuffers::numeric_limits<int8_t>::min(), -128); in IntegerBoundaryTest()
2190 TEST_EQ(flatbuffers::numeric_limits<int16_t>::min(), -32768); in IntegerBoundaryTest()
2192 TEST_EQ(flatbuffers::numeric_limits<int32_t>::min() + 1, -2147483647); in IntegerBoundaryTest()
2195 -9223372036854775807LL); in IntegerBoundaryTest()
2204 TEST_EQ(TestValue<int8_t>("{ y:-128 }", "byte"), -128); in IntegerBoundaryTest()
2208 TEST_EQ(TestValue<int16_t>("{ y:-32768 }", "short"), -32768); in IntegerBoundaryTest()
2212 TEST_EQ(TestValue<int32_t>("{ y:-2147483648 }", "int") + 1, -2147483647); in IntegerBoundaryTest()
2217 TEST_EQ(TestValue<int64_t>("{ y:-9223372036854775808 }", "long") + 1LL, in IntegerBoundaryTest()
2218 -9223372036854775807LL); in IntegerBoundaryTest()
2232 TEST_EQ(TestValue<float>("{ y:-3.4029e+38 }", "float"), -infinity_f); in ValidFloatTest()
2234 TEST_EQ(TestValue<double>("{ y:-1.7977e+308 }", "double"), -infinity_d); in ValidFloatTest()
2248 TEST_EQ(TestValue<float>("{ y:-1. }", "float"), -1.0f); in ValidFloatTest()
2251 TEST_EQ(TestValue<float>("{ y:1.e-0 }", "float"), 1.0f); in ValidFloatTest()
2254 TEST_EQ(TestValue<float>("{ y:-.125 }", "float"), -0.125f); in ValidFloatTest()
2261 // https://www.exploringbinary.com/visual-c-plus-plus-strtod-still-broken/ in ValidFloatTest()
2269 TEST_EQ(std::isnan(TestValue<float>("{ y:\"-nan\" }", "float")), true); in ValidFloatTest()
2271 TEST_EQ(std::isnan(TestValue<float>("{ y:-nan }", "float")), true); in ValidFloatTest()
2273 TEST_EQ(std::isnan(TestValue<float>(nullptr, "float=-nan")), true); in ValidFloatTest()
2277 TEST_EQ(TestValue<float>("{ y:\"-inf\" }", "float"), -infinity_f); in ValidFloatTest()
2280 TEST_EQ(TestValue<float>("{ y:-inf }", "float"), -infinity_f); in ValidFloatTest()
2282 TEST_EQ(TestValue<float>(nullptr, "float=-inf"), -infinity_f); in ValidFloatTest()
2284 "{ y: [0.2, .2, 1.0, -1.0, -2., 2., 1e0, -1e0, 1.0e0, -1.0e0, -3.e2, " in ValidFloatTest()
2288 "{ y: [0.2, .2, 1.0, -1.0, -2., 2., 1e0, -1e0, 1.0e0, -1.0e0, -3.e2, " in ValidFloatTest()
2294 // 0x11.12p-1 = (1*16^1 + 2*16^0 + 3*16^-1 + 4*16^-2) * 2^-1 = in ValidFloatTest()
2295 TEST_EQ(TestValue<double>("{ y:0x12.34p-1 }", "double"), 9.1015625); in ValidFloatTest()
2297 TEST_EQ(TestValue<float>("{ y:-0x0.2p0 }", "float"), -0.125f); in ValidFloatTest()
2298 TEST_EQ(TestValue<float>("{ y:-0x.2p1 }", "float"), -0.25f); in ValidFloatTest()
2304 TestValue<double>("{ y: [0x20.4ep1, +0x20.4ep1, -0x20.4ep1] }", "[double]"); in ValidFloatTest()
2305 TestValue<float>("{ y: [0x20.4ep1, +0x20.4ep1, -0x20.4ep1] }", "[float]"); in ValidFloatTest()
2317 TestError("table T { F:float; } root_type T; { F:- }", invalid_msg); in InvalidFloatTest()
2319 TestError("table T { F:float; } root_type T; { F:-. }", invalid_msg); in InvalidFloatTest()
2322 TestError("table T { F:float; } root_type T; { F:-e }", invalid_msg); in InvalidFloatTest()
2324 TestError("table T { F:float; } root_type T; { F:-.e }", invalid_msg); in InvalidFloatTest()
2326 TestError("table T { F:float; } root_type T; { F:-e1 }", invalid_msg); in InvalidFloatTest()
2329 TestError("table T { F:float; } root_type T; { F:1.0e- }", invalid_msg); in InvalidFloatTest()
2330 // exponent pP is mandatory for hex-float in InvalidFloatTest()
2332 TestError("table T { F:float; } root_type T; { F:-0x. }", invalid_msg); in InvalidFloatTest()
2337 // eE not exponent in hex-float! in InvalidFloatTest()
2339 TestError("table T { F:float; } root_type T; { F:0x0.0e- }", invalid_msg); in InvalidFloatTest()
2342 TestError("table T { F:float; } root_type T; { F:0x0.0p- }", invalid_msg); in InvalidFloatTest()
2345 TestError("table T { F:float; } root_type T; { F:0x0.0e- }", invalid_msg); in InvalidFloatTest()
2347 TestError("table T { F:float; } root_type T; { F:0x0.0e-0 }", invalid_msg); in InvalidFloatTest()
2349 TestError("table T { F:float; } root_type T; { F:0x0.0ep- }", invalid_msg); in InvalidFloatTest()
2356 TestError("table T { F:float; } root_type T; { F:+-1.0 }", invalid_msg); in InvalidFloatTest()
2357 TestError("table T { F:float; } root_type T; { F:1.0e+-1 }", invalid_msg); in InvalidFloatTest()
2358 TestError("table T { F:float; } root_type T; { F:\"1.0e+-1\" }", invalid_msg); in InvalidFloatTest()
2369 // disable escapes for "number-in-string" in InvalidFloatTest()
2395 opt.indent_step = -1; in GenerateTableTextTest()
2402 const auto abilities = monster->testarrayofsortedstruct(); in GenerateTableTextTest()
2403 TEST_EQ(abilities->size(), 3); in GenerateTableTextTest()
2404 TEST_EQ(abilities->Get(0)->id(), 0); in GenerateTableTextTest()
2405 TEST_EQ(abilities->Get(0)->distance(), 45); in GenerateTableTextTest()
2406 TEST_EQ(abilities->Get(1)->id(), 1); in GenerateTableTextTest()
2407 TEST_EQ(abilities->Get(1)->distance(), 21); in GenerateTableTextTest()
2408 TEST_EQ(abilities->Get(2)->id(), 5); in GenerateTableTextTest()
2409 TEST_EQ(abilities->Get(2)->distance(), 12); in GenerateTableTextTest()
2416 const Vec3 *pos = monster->pos(); in GenerateTableTextTest()
2423 const Test &test3 = pos->test3(); in GenerateTableTextTest()
2429 const Test *test4 = monster->test4()->Get(0); in GenerateTableTextTest()
2460 TEST_EQ(f, -flatbuffers::numeric_limits<T>::infinity()); in NumericUtilsTestFloat()
2464 NumericUtilsTestInteger<uint64_t>("-1", "18446744073709551616"); in NumericUtilsTest()
2465 NumericUtilsTestInteger<uint8_t>("-1", "256"); in NumericUtilsTest()
2466 NumericUtilsTestInteger<int64_t>("-9223372036854775809", in NumericUtilsTest()
2468 NumericUtilsTestInteger<int8_t>("-129", "128"); in NumericUtilsTest()
2469 NumericUtilsTestFloat<float>("-3.4029e+38", "+3.4029e+38"); in NumericUtilsTest()
2470 NumericUtilsTestFloat<float>("-1.7977e+308", "+1.7977e+308"); in NumericUtilsTest()
2474 char c = -128; in IsAsciiUtilsTest()
2490 // sequences which are then validated as UTF-8. in UnicodeTest()
2498 parser.opts.indent_step = -1; in UnicodeTest()
2518 parser.opts.indent_step = -1; in UnicodeTestAllowNonUTF8()
2530 // Allow non-UTF-8 initially to model what happens when we load a binary in UnicodeTestGenerateTextFailsOnNonUTF8()
2531 // flatbuffer from disk which contains non-UTF-8 strings. in UnicodeTestGenerateTextFailsOnNonUTF8()
2541 parser.opts.indent_step = -1; in UnicodeTestGenerateTextFailsOnNonUTF8()
2542 // Now, disallow non-UTF-8 (the default behavior) so GenerateText indicates in UnicodeTestGenerateTextFailsOnNonUTF8()
2559 auto string = root->GetPointer<flatbuffers::String *>( in UnicodeSurrogatesTest()
2561 TEST_EQ_STR(string->c_str(), "\xF0\x9F\x92\xA9"); in UnicodeSurrogatesTest()
2598 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2604 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2610 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2616 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2622 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2628 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2634 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2640 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2646 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2652 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2659 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2664 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2669 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2676 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2681 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2688 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2690 // UTF-16 surrogate values between U+D800 and U+DFFF cannot be encoded in in InvalidUTF8Test()
2691 // UTF-8 in InvalidUTF8Test()
2697 "illegal UTF-8 sequence"); in InvalidUTF8Test()
2702 locale_ident += static_cast<char>(-32); // unsigned 0xE0 in InvalidUTF8Test()
2728 parser.opts.indent_step = -1; in UnknownFieldsTest()
2855 TEST_ASSERT(nullptr == root_v1_viewed_from_v2->k()); in EvolutionTest()
2857 TEST_EQ(root_v1_viewed_from_v2->l(), 56); in EvolutionTest()
2859 TEST_ASSERT(nullptr == root_v1_viewed_from_v2->e()->c()); in EvolutionTest()
2861 TEST_ASSERT(nullptr == root_v1_viewed_from_v2->c_as_TableC()); in EvolutionTest()
2863 TEST_ASSERT(root_v1_viewed_from_v2->c_type() == Evolution::V2::Union::TableB); in EvolutionTest()
2866 TEST_EQ(root_v1_viewed_from_v2->ff()->a(), 16); in EvolutionTest()
2872 TEST_EQ(static_cast<uint8_t>(root_v2_viewed_from_v1->c_type()), 3); in EvolutionTest()
2873 TEST_NOTNULL(root_v2_viewed_from_v1->c()); in EvolutionTest()
2876 TEST_EQ(static_cast<int8_t>(root_v2_viewed_from_v1->d()), 3); in EvolutionTest()
2879 TEST_EQ(root_v2_viewed_from_v1->a(), 0); in EvolutionTest()
2882 TEST_EQ(root_v2_viewed_from_v1->f()->a(), 35); in EvolutionTest()
2916 auto j_type_field = v2->fields.Lookup("j_type"); in UnionDeprecationTest()
2918 TEST_ASSERT(j_type_field->deprecated); in UnionDeprecationTest()
2970 TEST_EQ(movie->main_character_type() == Character_Rapunzel, true); in UnionVectorTest()
2972 auto cts = movie->characters_type(); in UnionVectorTest()
2973 TEST_EQ(movie->characters_type()->size(), 5); in UnionVectorTest()
2974 TEST_EQ(cts->GetEnum<Character>(0) == Character_Belle, true); in UnionVectorTest()
2975 TEST_EQ(cts->GetEnum<Character>(1) == Character_MuLan, true); in UnionVectorTest()
2976 TEST_EQ(cts->GetEnum<Character>(2) == Character_BookFan, true); in UnionVectorTest()
2977 TEST_EQ(cts->GetEnum<Character>(3) == Character_Other, true); in UnionVectorTest()
2978 TEST_EQ(cts->GetEnum<Character>(4) == Character_Unused, true); in UnionVectorTest()
2980 auto rapunzel = movie->main_character_as_Rapunzel(); in UnionVectorTest()
2982 TEST_EQ(rapunzel->hair_length(), 6); in UnionVectorTest()
2984 auto cs = movie->characters(); in UnionVectorTest()
2985 TEST_EQ(cs->size(), 5); in UnionVectorTest()
2986 auto belle = cs->GetAs<BookReader>(0); in UnionVectorTest()
2987 TEST_EQ(belle->books_read(), 7); in UnionVectorTest()
2988 auto mu_lan = cs->GetAs<Attacker>(1); in UnionVectorTest()
2989 TEST_EQ(mu_lan->sword_attack_damage(), 5); in UnionVectorTest()
2990 auto book_fan = cs->GetAs<BookReader>(2); in UnionVectorTest()
2991 TEST_EQ(book_fan->books_read(), 2); in UnionVectorTest()
2992 auto other = cs->GetAsString(3); in UnionVectorTest()
2993 TEST_EQ_STR(other->c_str(), "Other"); in UnionVectorTest()
2994 auto unused = cs->GetAsString(4); in UnionVectorTest()
2995 TEST_EQ_STR(unused->c_str(), "Unused"); in UnionVectorTest()
3007 auto movie_object = flat_movie->UnPack(); in UnionVectorTest()
3008 TEST_EQ(movie_object->main_character.AsRapunzel()->hair_length(), 6); in UnionVectorTest()
3009 TEST_EQ(movie_object->characters[0].AsBelle()->books_read(), 7); in UnionVectorTest()
3010 TEST_EQ(movie_object->characters[1].AsMuLan()->sword_attack_damage, 5); in UnionVectorTest()
3011 TEST_EQ(movie_object->characters[2].AsBookFan()->books_read(), 2); in UnionVectorTest()
3012 TEST_EQ_STR(movie_object->characters[3].AsOther()->c_str(), "Other"); in UnionVectorTest()
3013 TEST_EQ_STR(movie_object->characters[4].AsUnused()->c_str(), "Unused"); in UnionVectorTest()
3024 // Generate text using mini-reflection. in UnionVectorTest()
3099 auto ok = flatbuffers::Verify(*schema, *schema->root_table(), in UnionVectorTest()
3185 // { vec: [ -100, "Fred", 4.0, false ], bar: [ 1, 2, 3 ], bar3: [ 1, 2, 3 ], in FlexBuffersTest()
3191 slb += -100; // Equivalent to slb.Add(-100) or slb.Int(-100); in FlexBuffersTest()
3213 // clang-format off in FlexBuffersTest()
3219 // clang-format on in FlexBuffersTest()
3230 TEST_EQ(vec[0].AsInt64(), -100); in FlexBuffersTest()
3238 TEST_EQ(vec[0].As<int64_t>(), -100); in FlexBuffersTest()
3266 TEST_EQ(vec[0].MutateInt(-99), true); in FlexBuffersTest()
3267 TEST_EQ(vec[0].AsInt64(), -99); in FlexBuffersTest()
3334 // Parse floating-point values from JSON: in FlexBuffersFloatingPointTest()
3338 "{ a: [1.0, nan, inf, infinity, -inf, +inf, -infinity, 8.0] }"; in FlexBuffersFloatingPointTest()
3351 TEST_EQ(-infinity_d, jvec[4].AsDouble()); in FlexBuffersFloatingPointTest()
3353 TEST_EQ(-infinity_d, jvec[6].AsDouble()); in FlexBuffersFloatingPointTest()
3365 // get the bit-width for the size field of the string, which in this case in FlexBuffersDeprecatedTest()
3366 // isn't present, and instead defaults to 8-bit. This means that any strings in FlexBuffersDeprecatedTest()
3372 // This one will have a 16-bit size field. in FlexBuffersDeprecatedTest()
3374 // This one will have an 8-bit size field. in FlexBuffersDeprecatedTest()
3377 // fixed size (false). The type will be FBT_VECTOR_STRING with a bit-width in FlexBuffersDeprecatedTest()
3378 // of whatever the offsets in the vector need, the bit-widths of the strings in FlexBuffersDeprecatedTest()
3379 // are not stored(!) <- the actual design flaw. in FlexBuffersDeprecatedTest()
3393 // bit-width of the size field of the string is, we are going to ignore this in FlexBuffersDeprecatedTest()
3394 // field, and instead treat these strings as FBT_KEY (null-terminated), so we in FlexBuffersDeprecatedTest()
3403 // since it would read the high-byte of the 16-bit length. in FlexBuffersDeprecatedTest()
3440 TEST_EQ(ta->i8(), flatbuffers::numeric_limits<int8_t>::min()); in TypeAliasesTest()
3441 TEST_EQ(ta->u8(), flatbuffers::numeric_limits<uint8_t>::max()); in TypeAliasesTest()
3442 TEST_EQ(ta->i16(), flatbuffers::numeric_limits<int16_t>::min()); in TypeAliasesTest()
3443 TEST_EQ(ta->u16(), flatbuffers::numeric_limits<uint16_t>::max()); in TypeAliasesTest()
3444 TEST_EQ(ta->i32(), flatbuffers::numeric_limits<int32_t>::min()); in TypeAliasesTest()
3445 TEST_EQ(ta->u32(), flatbuffers::numeric_limits<uint32_t>::max()); in TypeAliasesTest()
3446 TEST_EQ(ta->i64(), flatbuffers::numeric_limits<int64_t>::min()); in TypeAliasesTest()
3447 TEST_EQ(ta->u64(), flatbuffers::numeric_limits<uint64_t>::max()); in TypeAliasesTest()
3448 TEST_EQ(ta->f32(), 2.3f); in TypeAliasesTest()
3449 TEST_EQ(ta->f64(), 2.3); in TypeAliasesTest()
3451 static_assert(is_same<decltype(ta->i8()), int8_t>::value, "invalid type"); in TypeAliasesTest()
3452 static_assert(is_same<decltype(ta->i16()), int16_t>::value, "invalid type"); in TypeAliasesTest()
3453 static_assert(is_same<decltype(ta->i32()), int32_t>::value, "invalid type"); in TypeAliasesTest()
3454 static_assert(is_same<decltype(ta->i64()), int64_t>::value, "invalid type"); in TypeAliasesTest()
3455 static_assert(is_same<decltype(ta->u8()), uint8_t>::value, "invalid type"); in TypeAliasesTest()
3456 static_assert(is_same<decltype(ta->u16()), uint16_t>::value, "invalid type"); in TypeAliasesTest()
3457 static_assert(is_same<decltype(ta->u32()), uint32_t>::value, "invalid type"); in TypeAliasesTest()
3458 static_assert(is_same<decltype(ta->u64()), uint64_t>::value, "invalid type"); in TypeAliasesTest()
3459 static_assert(is_same<decltype(ta->f32()), float>::value, "invalid type"); in TypeAliasesTest()
3460 static_assert(is_same<decltype(ta->f64()), double>::value, "invalid type"); in TypeAliasesTest()
3492 auto vec = uvt->test4(); in UninitializedVectorTest()
3494 auto test_0 = vec->Get(0); in UninitializedVectorTest()
3495 auto test_1 = vec->Get(1); in UninitializedVectorTest()
3496 TEST_EQ(test_0->a(), 10); in UninitializedVectorTest()
3497 TEST_EQ(test_0->b(), 20); in UninitializedVectorTest()
3498 TEST_EQ(test_1->a(), 30); in UninitializedVectorTest()
3499 TEST_EQ(test_1->b(), 40); in UninitializedVectorTest()
3524 a.enemy->mana = 33; in EqualOperatorTest()
3531 b.enemy->mana = 33; in EqualOperatorTest()
3538 b.enemy->mana = 150; in EqualOperatorTest()
3572 c->hp = 1; in EqualOperatorTest()
3573 d->hp = 2; in EqualOperatorTest()
3598 (test_data_path + "fuzzer/your-filename-here").c_str(), true, in LoadVerifyBinaryTest()
3639 TEST_EQ_STR(monster->name()->c_str(), "two"); in CreateSharedStringTest()
3640 const auto *testarrayofstring = monster->testarrayofstring(); in CreateSharedStringTest()
3641 TEST_EQ(testarrayofstring->size(), flatbuffers::uoffset_t(7)); in CreateSharedStringTest()
3643 TEST_EQ_STR(a[0]->c_str(), "one"); in CreateSharedStringTest()
3644 TEST_EQ_STR(a[1]->c_str(), "two"); in CreateSharedStringTest()
3645 TEST_EQ_STR(a[2]->c_str(), "one"); in CreateSharedStringTest()
3646 TEST_EQ_STR(a[3]->c_str(), "onetwo"); in CreateSharedStringTest()
3647 TEST_EQ(a[4]->str(), (std::string(chars_b, sizeof(chars_b)))); in CreateSharedStringTest()
3648 TEST_EQ(a[5]->str(), (std::string(chars_c, sizeof(chars_c)))); in CreateSharedStringTest()
3649 TEST_EQ(a[6]->str(), (std::string(chars_b, sizeof(chars_b)))); in CreateSharedStringTest()
3665 // Compile-time checking of non-const [] to const [] conversions. in FlatbuffersSpanTest()
3692 // Make const span from a non-const one. in FlatbuffersSpanTest()
3694 // Construct from a C-array. in FlatbuffersSpanTest()
3753 nStruct0.mutable_a()->Mutate(0, 1); in FixedLengthArrayTest()
3754 nStruct0.mutable_a()->Mutate(1, 2); in FixedLengthArrayTest()
3756 nStruct0.mutable_c()->Mutate(0, MyGame::Example::TestEnum::C); in FixedLengthArrayTest()
3757 nStruct0.mutable_c()->Mutate(1, MyGame::Example::TestEnum::A); in FixedLengthArrayTest()
3759 nStruct0.mutable_d()->Mutate(0, flatbuffers::numeric_limits<int64_t>::max()); in FixedLengthArrayTest()
3760 nStruct0.mutable_d()->Mutate(1, flatbuffers::numeric_limits<int64_t>::min()); in FixedLengthArrayTest()
3763 nStruct1.mutable_a()->Mutate(0, 3); in FixedLengthArrayTest()
3764 nStruct1.mutable_a()->Mutate(1, 4); in FixedLengthArrayTest()
3766 nStruct1.mutable_c()->Mutate(0, MyGame::Example::TestEnum::C); in FixedLengthArrayTest()
3767 nStruct1.mutable_c()->Mutate(1, MyGame::Example::TestEnum::A); in FixedLengthArrayTest()
3769 nStruct1.mutable_d()->Mutate(0, flatbuffers::numeric_limits<int64_t>::min()); in FixedLengthArrayTest()
3770 nStruct1.mutable_d()->Mutate(1, flatbuffers::numeric_limits<int64_t>::max()); in FixedLengthArrayTest()
3776 for (int i = 0; i < aStruct.b()->size(); i++) in FixedLengthArrayTest()
3777 aStruct.mutable_b()->Mutate(i, i + 1); in FixedLengthArrayTest()
3778 aStruct.mutable_d()->Mutate(0, nStruct0); in FixedLengthArrayTest()
3779 aStruct.mutable_d()->Mutate(1, nStruct1); in FixedLengthArrayTest()
3787 auto mArStruct = p->mutable_a(); in FixedLengthArrayTest()
3789 TEST_NOTNULL(mArStruct->b()); in FixedLengthArrayTest()
3790 TEST_NOTNULL(mArStruct->d()); in FixedLengthArrayTest()
3791 TEST_NOTNULL(mArStruct->f()); in FixedLengthArrayTest()
3792 TEST_NOTNULL(mArStruct->mutable_b()); in FixedLengthArrayTest()
3793 TEST_NOTNULL(mArStruct->mutable_d()); in FixedLengthArrayTest()
3794 TEST_NOTNULL(mArStruct->mutable_f()); in FixedLengthArrayTest()
3795 TEST_EQ(mArStruct->a(), 2); in FixedLengthArrayTest()
3796 TEST_EQ(mArStruct->b()->size(), 15); in FixedLengthArrayTest()
3797 mArStruct->mutable_b()->Mutate(14, -14); in FixedLengthArrayTest()
3798 TEST_EQ(mArStruct->b()->Get(14), -14); in FixedLengthArrayTest()
3799 TEST_EQ(mArStruct->c(), 12); in FixedLengthArrayTest()
3800 TEST_NOTNULL(mArStruct->d()->Get(0)); in FixedLengthArrayTest()
3801 TEST_NOTNULL(mArStruct->d()->Get(0)->a()); in FixedLengthArrayTest()
3802 TEST_EQ(mArStruct->d()->Get(0)->a()->Get(0), 1); in FixedLengthArrayTest()
3803 TEST_EQ(mArStruct->d()->Get(0)->a()->Get(1), 2); in FixedLengthArrayTest()
3804 TEST_NOTNULL(mArStruct->d()->Get(1)); in FixedLengthArrayTest()
3805 TEST_NOTNULL(mArStruct->d()->Get(1)->a()); in FixedLengthArrayTest()
3806 TEST_EQ(mArStruct->d()->Get(1)->a()->Get(0), 3); in FixedLengthArrayTest()
3807 TEST_EQ(mArStruct->d()->Get(1)->a()->Get(1), 4); in FixedLengthArrayTest()
3808 TEST_NOTNULL(mArStruct->mutable_d()->GetMutablePointer(1)); in FixedLengthArrayTest()
3809 TEST_NOTNULL(mArStruct->mutable_d()->GetMutablePointer(1)->mutable_a()); in FixedLengthArrayTest()
3810 mArStruct->mutable_d()->GetMutablePointer(1)->mutable_a()->Mutate(1, 5); in FixedLengthArrayTest()
3811 TEST_EQ(5, mArStruct->d()->Get(1)->a()->Get(1)); in FixedLengthArrayTest()
3812 TEST_EQ(MyGame::Example::TestEnum::B, mArStruct->d()->Get(0)->b()); in FixedLengthArrayTest()
3813 TEST_NOTNULL(mArStruct->d()->Get(0)->c()); in FixedLengthArrayTest()
3814 TEST_EQ(MyGame::Example::TestEnum::C, mArStruct->d()->Get(0)->c()->Get(0)); in FixedLengthArrayTest()
3815 TEST_EQ(MyGame::Example::TestEnum::A, mArStruct->d()->Get(0)->c()->Get(1)); in FixedLengthArrayTest()
3817 mArStruct->d()->Get(0)->d()->Get(0)); in FixedLengthArrayTest()
3819 mArStruct->d()->Get(0)->d()->Get(1)); in FixedLengthArrayTest()
3820 TEST_EQ(MyGame::Example::TestEnum::C, mArStruct->d()->Get(1)->b()); in FixedLengthArrayTest()
3821 TEST_NOTNULL(mArStruct->d()->Get(1)->c()); in FixedLengthArrayTest()
3822 TEST_EQ(MyGame::Example::TestEnum::C, mArStruct->d()->Get(1)->c()->Get(0)); in FixedLengthArrayTest()
3823 TEST_EQ(MyGame::Example::TestEnum::A, mArStruct->d()->Get(1)->c()->Get(1)); in FixedLengthArrayTest()
3825 mArStruct->d()->Get(1)->d()->Get(0)); in FixedLengthArrayTest()
3827 mArStruct->d()->Get(1)->d()->Get(1)); in FixedLengthArrayTest()
3828 for (int i = 0; i < mArStruct->b()->size() - 1; i++) in FixedLengthArrayTest()
3829 TEST_EQ(mArStruct->b()->Get(i), i + 1); in FixedLengthArrayTest()
3831 TEST_EQ(0, reinterpret_cast<uintptr_t>(mArStruct->d()) % 8); in FixedLengthArrayTest()
3832 TEST_EQ(0, reinterpret_cast<uintptr_t>(mArStruct->f()) % 8); in FixedLengthArrayTest()
3839 // after placement-new it should be all 0's in FixedLengthArrayTest()
3861 const int64_t int64_2[2] = { -2, -1 }; in FixedLengthArrayConstructorTest()
3875 -17, init_d, 10, int64_2); in FixedLengthArrayConstructorTest()
3877 TEST_EQ(arr_struct.b()->Get(2), 3); in FixedLengthArrayConstructorTest()
3878 TEST_EQ(arr_struct.c(), -17); in FixedLengthArrayConstructorTest()
3881 const auto &arr_d_0 = *arr_struct.d()->Get(0); in FixedLengthArrayConstructorTest()
3882 TEST_EQ(arr_d_0.a()->Get(0), 1); in FixedLengthArrayConstructorTest()
3883 TEST_EQ(arr_d_0.a()->Get(1), 2); in FixedLengthArrayConstructorTest()
3885 TEST_EQ(arr_d_0.c()->Get(0), MyGame::Example::TestEnum::A); in FixedLengthArrayConstructorTest()
3886 TEST_EQ(arr_d_0.c()->Get(1), MyGame::Example::TestEnum::B); in FixedLengthArrayConstructorTest()
3887 TEST_EQ(arr_d_0.d()->Get(0), -2); in FixedLengthArrayConstructorTest()
3888 TEST_EQ(arr_d_0.d()->Get(1), -1); in FixedLengthArrayConstructorTest()
3889 const auto &arr_d_1 = *arr_struct.d()->Get(1); in FixedLengthArrayConstructorTest()
3890 TEST_EQ(arr_d_1.a()->Get(0), 1); in FixedLengthArrayConstructorTest()
3891 TEST_EQ(arr_d_1.a()->Get(1), 2); in FixedLengthArrayConstructorTest()
3893 TEST_EQ(arr_d_1.c()->Get(0), MyGame::Example::TestEnum::A); in FixedLengthArrayConstructorTest()
3894 TEST_EQ(arr_d_1.c()->Get(1), MyGame::Example::TestEnum::B); in FixedLengthArrayConstructorTest()
3895 TEST_EQ(arr_d_1.d()->Get(0), 12); in FixedLengthArrayConstructorTest()
3896 TEST_EQ(arr_d_1.d()->Get(1), 13); in FixedLengthArrayConstructorTest()
3899 TEST_EQ(arr_struct.f()->Get(0), -2); in FixedLengthArrayConstructorTest()
3900 TEST_EQ(arr_struct.f()->Get(1), -1); in FixedLengthArrayConstructorTest()
3926 const Native::Vector3D &v = dstDataT->vectors[i]; in NativeTypeTest()
3931 const Native::Vector3D &v2 = dstDataT->vectors_alt[i]; in NativeTypeTest()
4022 auto table_struct = p->mutable_a(); in FixedLengthArraySpanTest()
4024 TEST_EQ(2, table_struct->d()->size()); in FixedLengthArraySpanTest()
4025 TEST_NOTNULL(table_struct->d()); in FixedLengthArraySpanTest()
4026 TEST_NOTNULL(table_struct->mutable_d()); in FixedLengthArraySpanTest()
4028 auto const_d = flatbuffers::make_span(*table_struct->d()); in FixedLengthArraySpanTest()
4029 auto mutable_d = flatbuffers::make_span(*table_struct->mutable_d()); in FixedLengthArraySpanTest()
4064 TEST_EQ(-1, const_d_a[0]); in FixedLengthArraySpanTest()
4139 TEST_ASSERT(parser.Parse(s->c_str())); in StringVectorDefaultsTest()
4140 const auto *mana = parser.structs_.Lookup("Monster")->fields.Lookup("mana"); in StringVectorDefaultsTest()
4141 TEST_EQ(mana->IsDefault(), true); in StringVectorDefaultsTest()
4175 const bool has_null = schema->find("null") != std::string::npos; in OptionalScalarsTest()
4177 TEST_ASSERT(parser.Parse(schema->c_str())); in OptionalScalarsTest()
4178 const auto *mana = parser.structs_.Lookup("Monster")->fields.Lookup("mana"); in OptionalScalarsTest()
4179 TEST_EQ(mana->IsOptional(), has_null); in OptionalScalarsTest()
4191 auto done = parser.Parse(schema->c_str()); in OptionalScalarsTest()
4202 TEST_ASSERT(!opts->maybe_bool()); in OptionalScalarsTest()
4203 TEST_ASSERT(!opts->maybe_f32().has_value()); in OptionalScalarsTest()
4204 TEST_ASSERT(opts->maybe_i8().has_value()); in OptionalScalarsTest()
4205 TEST_EQ(opts->maybe_i8().value(), 2); in OptionalScalarsTest()
4206 TEST_ASSERT(opts->mutate_maybe_i8(3)); in OptionalScalarsTest()
4207 TEST_ASSERT(opts->maybe_i8().has_value()); in OptionalScalarsTest()
4208 TEST_EQ(opts->maybe_i8().value(), 3); in OptionalScalarsTest()
4209 TEST_ASSERT(!opts->mutate_maybe_i16(-10)); in OptionalScalarsTest()
4214 opts->UnPackTo(&obj); in OptionalScalarsTest()
4219 obj.maybe_i32 = -1; in OptionalScalarsTest()
4225 TEST_ASSERT(opts->maybe_i8().has_value()); in OptionalScalarsTest()
4226 TEST_EQ(opts->maybe_i8().value(), 3); in OptionalScalarsTest()
4227 TEST_ASSERT(opts->maybe_i32().has_value()); in OptionalScalarsTest()
4228 TEST_EQ(opts->maybe_i32().value(), -1); in OptionalScalarsTest()
4229 TEST_EQ(opts->maybe_enum().value(), optional_scalars::OptionalByte_Two); in OptionalScalarsTest()
4230 TEST_ASSERT(opts->maybe_i32() == flatbuffers::Optional<int64_t>(-1)); in OptionalScalarsTest()
4236 // TODO(cneo): Json -> Flatbuffers test once some language can generate code in ParseFlexbuffersFromJsonWithNullTest()
4269 // non-integer `id` should be rejected in FieldIdentifierTest()
4274 TEST_EQ(false, Parser().Parse("table T{ f: int (id:-1); g: int (id:0); }")); in FieldIdentifierTest()
4387 TEST_EQ(parser.ParseJson("{name:-1}"), false); in ParseIncorrectMonsterJsonTest()
4388 TEST_EQ(parser.ParseJson("{name:-f}"), false); in ParseIncorrectMonsterJsonTest()
4408 for (auto it = tested.rbegin(); it != tested.rend(); ++it, --k) { in TestIterators()
4409 const auto &e = expected.at(k - 1); in TestIterators()
4432 TEST_EQ_STR("MyMonster", mon.name()->c_str()); in FlatbuffersIteratorsTest()
4447 auto &int_15 = *array_table.a()->b(); in FlatbuffersIteratorsTest()
4486 "enum Race:byte (private) { None = -1, Human = 0, }"); in PrivateAnnotationsLeaks()
4492 "enum Race:byte { None = -1, Human = 0, }"); in PrivateAnnotationsLeaks()
4498 "enum Race:byte (private) { None = -1, Human = 0, }" in PrivateAnnotationsLeaks()
4505 "enum Race:byte { None = -1, Human = 0, }" in PrivateAnnotationsLeaks()
4517 "enum Race:byte { None = -1, Human = 0, }"); in PrivateAnnotationsLeaks()
4521 "enum Race:byte { None = -1, Human = 0, }" in PrivateAnnotationsLeaks()
4535 "enum Race:byte { None = -1, Human = 0, }" in PrivateAnnotationsLeaks()
4545 "enum Race:byte (private) { None = -1, Human = 0, }" in PrivateAnnotationsLeaks()
4555 TEST_ASSERT(parser.Parse(schema->c_str())); in PrivateAnnotationsLeaks()
4561 TEST_EQ(false, parser.Parse(schema->c_str())); in PrivateAnnotationsLeaks()
4568 TEST_ASSERT(parser.Parse(schema->c_str())); in PrivateAnnotationsLeaks()
4574 TEST_ASSERT(parser.Parse(schema->c_str())); in PrivateAnnotationsLeaks()
4595 TEST_NOTNULL(monster->testarrayoftables()->LookupByKey("aaa")); in JsonUnsortedArrayTest()
4596 TEST_NOTNULL(monster->testarrayoftables()->LookupByKey("bbb")); in JsonUnsortedArrayTest()
4597 TEST_NOTNULL(monster->testarrayoftables()->LookupByKey("ccc")); in JsonUnsortedArrayTest()
4613 TEST_NOTNULL(monster->inventory()); in VectorSpanTest()
4616 flatbuffers::make_span(*monster->inventory()); in VectorSpanTest()
4622 flatbuffers::make_span(*mutable_monster->mutable_inventory()); in VectorSpanTest()
4635 TEST_EQ(flatbuffers::VectorLength(monster->inventory()), 10); in VectorSpanTest()
4638 flatbuffers::make_span(monster->inventory()); in VectorSpanTest()
4644 flatbuffers::make_span(mutable_monster->mutable_inventory()); in VectorSpanTest()
4657 TEST_ASSERT(nullptr == monster->testnestedflatbuffer()); in VectorSpanTest()
4659 TEST_EQ(flatbuffers::VectorLength(monster->testnestedflatbuffer()), 0); in VectorSpanTest()
4662 flatbuffers::make_span(monster->testnestedflatbuffer()); in VectorSpanTest()
4666 flatbuffers::make_span(mutable_monster->mutable_testnestedflatbuffer()); in VectorSpanTest()
4672 // clang-format off in FlatBufferTests()
4717 // clang-format on in FlatBufferTests()
4786 if (arg == "--test_path") { in main()
4809 TEST_OUTPUT_LINE("The global C-locale changed: %s", the_locale.c_str()); in main()