From 7181c49bfb2887246e540c3f6290f6a6a4591334 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Tue, 11 Dec 2018 15:47:37 +0000 Subject: [PATCH] test: Add properties to slightly improve serialization coverage --- test/samples/serialization_binary_file.bin | Bin 365 -> 1229 bytes test/samples/serialization_binary_regular.bin | Bin 161 -> 985 bytes test/src/unit-serialization.cpp | 49 +++++++++++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/test/samples/serialization_binary_file.bin b/test/samples/serialization_binary_file.bin index a97f44b2095efda94d66ff7d225fd419d5b35fec..c67b1ef3c42582dd738d1da0c30c9ebdb2c1b93d 100644 GIT binary patch literal 1229 zcmeIx-AmI^9LMqR9^IyMo6cHh`ZIelYxZoGJ#4mC+Jl*^tY-e^94YN0*d|0HMo@H9 zh=z0(1`@0?iY|g(2}V~z(Pdq<5Q69;@9U!Xsrf&2(b#L>&pC(hkMTR_7(}GMy6;-^ zI*}0h&FA~sZnMbqJF~XlBTPJ*oXZ+c5*)WZH6~*}>Dx@+Wwn@f;`OJGT@JggEJwCl z-nyzhZdawVqFi-GjW^o3(3!iN8E)7?&0%7G@~V;QMG?7tG+78; z4(G@^Uf3V_45j?O>D4?@iWMTYFTW2Cs{tRiuAX56?^Z0Zq6{|J;XpZP6(=g;f*T%G zp&IIc)LDLrR3g&pYNY$b4n3_|$wQf4A Q?n>cxJe;HIQ0pe@Z|1Xyk^lez delta 76 zcmX@h`Id=`k%56BLO8fugL@+vJL6xzs@ij9s;gI(-l z9|t(Z5sq extra_value; }; /** @@ -190,8 +203,12 @@ public: INIT_PROPERTY(float32, "float") INIT_PROPERTY(float64, "double") INIT_PROPERTY(vector3d, "struct Vector3D") + INIT_PROPERTY(int_ptr, "int") + INIT_PROPERTY(value_object, "class NestedTestObjectA") INIT_PROPERTY(not_null_object, "class NestedTestObject") INIT_PROPERTY(null_object, "class NestedTestObject") + INIT_PROPERTY(collection, "int") + INIT_PROPERTY(ptr_collection, "int") INIT_PROPERTY(objects, "class NestedTestObject") {} @@ -222,10 +239,18 @@ public: // Test writing custom defined primitives pclass::StaticProperty vector3d; + // Test dereferencing when writing pointers to primitives + pclass::StaticProperty int_ptr; + // Test writing a single instance of another object + pclass::StaticProperty value_object; pclass::StaticProperty not_null_object; pclass::StaticProperty null_object; + // Test writing collections of primitives + pclass::VectorProperty collection; + pclass::VectorProperty ptr_collection; + // Test writing multiple instances of another object pclass::VectorProperty objects; }; @@ -272,6 +297,9 @@ void define_types() #define EXPECTED_float32 3.1415927410125732421875f #define EXPECTED_float64 3.141592653589793115997963468544185161590576171875 #define EXPECTED_vector3d Vector3D(24.0f, 61.0f, 3.62f) +#define EXPECTED_int_ptr 52 +#define EXPECTED_value_object_extra_value 20 +#define EXPECTED_collection_size 100 #define SET_EXPECTED(object, identifier) object.identifier = EXPECTED_##identifier #define IS_EXPECTED(object, identifier) object.identifier.get() == EXPECTED_##identifier @@ -298,8 +326,17 @@ void configure_test_object(TestObject &object) SET_EXPECTED(object, float32); SET_EXPECTED(object, float64); SET_EXPECTED(object, vector3d); + object.int_ptr = new int(EXPECTED_int_ptr); + // Configure the collection of integers + for (auto i = 0; i < EXPECTED_collection_size; ++i) + { + object.collection.push_back(i); + object.ptr_collection.push_back(new int(i)); + } + // Configure nested objects + object.value_object.get().extra_value = EXPECTED_value_object_extra_value; object.not_null_object = g_type_system->instantiate("class NestedTestObject"); object.null_object = nullptr; object.objects.push_back( @@ -333,8 +370,19 @@ void validate_test_object(TestObject &object) REQUIRE(IS_EXPECTED(object, float32)); REQUIRE(IS_EXPECTED(object, float64)); REQUIRE(IS_EXPECTED(object, vector3d)); + REQUIRE(*object.int_ptr == EXPECTED_int_ptr); + + // Validate both collections + REQUIRE(object.collection.size() == EXPECTED_collection_size); + REQUIRE(object.ptr_collection.size() == EXPECTED_collection_size); + for (auto i = 0; i < EXPECTED_collection_size; i++) + { + REQUIRE(object.collection[i] == i); + REQUIRE(*object.ptr_collection[i] == i); + } // Validate nested objects + REQUIRE(object.value_object.get().extra_value == EXPECTED_value_object_extra_value); REQUIRE(object.not_null_object.get() != nullptr); REQUIRE(object.not_null_object.get()->get_kind() == NestedObjectKind::OBJECT); REQUIRE(object.null_object.get() == nullptr); @@ -387,7 +435,6 @@ void test_serializer( // Validate the contents of the stream const auto stream_size = (end_pos - start_pos).as_bytes(); - REQUIRE(stream_size == sample_size); auto *stream_data = new uint8_t[stream_size]; stream.seek(start_pos);