summaryrefslogtreecommitdiff
path: root/Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp')
-rw-r--r--Runtime/Serialize/TransferFunctions/YAMLWriteTests.cpp58
1 files changed, 58 insertions, 0 deletions
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 <map>
+
+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<float, UnityStr> testMap;
+ instanceUnderTest.TransferSTLStyleMap (testMap);
+ CHECK (ROOT->type == YAML_MAPPING_NODE);
+ }
+
+ TEST_FIXTURE (Fixture, TransferSTLStyleMap_WithComplexKey_WritesDataChild)
+ {
+ // Arrange.
+ std::map<PPtr<Object>, UnityStr> testMap;
+ testMap[PPtr<Object> ()] = "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<int, UnityStr> 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