From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../Serialize/TransferFunctions/YAMLWriteTests.cpp | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp (limited to 'Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp') diff --git a/Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp b/Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp new file mode 100644 index 0000000..b0596d6 --- /dev/null +++ b/Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp @@ -0,0 +1,58 @@ +#include "UnityPrefix.h" + +#ifdef ENABLE_UNIT_TESTS + +#include "YAMLWrite.h" +#include "Runtime/Testing/Testing.h" +#include + +SUITE (YAMLWriteTests) +{ + struct Fixture + { + YAMLWrite instanceUnderTest; + Fixture () + : instanceUnderTest (0) {} + }; + + #define ROOT (yaml_document_get_root_node (instanceUnderTest.GetDocument ())) + #define FIRST_KEY_OF(node) (yaml_document_get_node (instanceUnderTest.GetDocument (), node->data.mapping.pairs.start->key)) + #define FIRST_VALUE_OF(node) (yaml_document_get_node (instanceUnderTest.GetDocument (), node->data.mapping.pairs.start->value)) + + TEST_FIXTURE (Fixture, TransferSTLStyleMap_WithEmptyMap_ProducesMappingNode) + { + std::map testMap; + instanceUnderTest.TransferSTLStyleMap (testMap); + CHECK (ROOT->type == YAML_MAPPING_NODE); + } + + TEST_FIXTURE (Fixture, TransferSTLStyleMap_WithComplexKey_WritesDataChild) + { + // Arrange. + std::map, UnityStr> testMap; + testMap[PPtr ()] = "bar"; + + // Act. + instanceUnderTest.TransferSTLStyleMap (testMap); + + // Assert. + CHECK (FIRST_KEY_OF (ROOT)->type == YAML_SCALAR_NODE); + CHECK (strcmp ((const char*) FIRST_KEY_OF (ROOT)->data.scalar.value, "data") == 0); + } + + TEST_FIXTURE (Fixture, TransferSTLStyleMap_WithBasicTypeKey_DoesNotWriteDataChild) + { + // Arrange. + std::map testMap; + testMap[1234] = "bar"; + + // Act. + instanceUnderTest.TransferSTLStyleMap (testMap); + + // Assert. + CHECK (FIRST_KEY_OF (ROOT)->type == YAML_SCALAR_NODE); + CHECK (strcmp ((const char*) FIRST_KEY_OF (ROOT)->data.scalar.value, "1234") == 0); + } +} + +#endif // ENABLE_UNIT_TESTS -- cgit v1.1-26-g67d0