#include "ZUnitTest.hpp" #include #include #include static const char* test_PutProducesValidNodes(); static const char* test_GetAfterPut(); static const char* test_Erase(); static const char* test_EraseHierarchy(); //List of unit tests ZUnitTest ZRegistryUnitTests[] = { { "ZRegistry: Put() produces valid nodes.", test_PutProducesValidNodes }, { "ZRegistry: Get() after Put() finds the value.", test_GetAfterPut }, { "ZRegistry: Erase", test_Erase }, { "ZRegistry: Erase hierarchy", test_EraseHierarchy }, }; DECLARE_ZTESTBLOCK(ZRegistry); /*************************************************************************/ static const char* test_PutProducesValidNodes() { ZRegistry reg; reg.Put("A.B.C", "100"); TASSERT(reg.Get("A").Valid(), "Registry failed to create first key node!"); TASSERT(reg.Get("A.B").Valid(), "Registry failed to create first key node!"); TASSERT(reg.Get("A.B.C").Valid(), "Registry failed to create first key node!"); return ZTEST_SUCCESS; } /*************************************************************************/ static const char* test_GetAfterPut() { ZRegistry reg; reg.Put("A", "10"); reg.Put("A.B", "20"); TASSERT(reg.Get("A").GetString() == "10", "Registry does not contain correct string value!"); TASSERT(reg.Get("A").GetInt() == 10, "Registry did not convert correct integer value!"); TASSERT(reg.Get("A").GetDouble() == 10.0, "ZRegistry did not convert correct double value!"); TASSERT(reg.Get("A.B").GetString() == "20", "Registry does not contain correct string value!"); TASSERT(reg.Get("A.B").GetInt() == 20, "Registry did not convert correct integer value!"); TASSERT(reg.Get("A.B").GetDouble() == 20.0, "ZRegistry did not convert correct double value!"); return ZTEST_SUCCESS; } /*************************************************************************/ static const char* test_Erase() { ZRegistry reg; reg.Put("A", "Test"); reg.Erase("A"); TASSERT(!reg.Get("A").Valid(), "Erased value still queryable"); return ZTEST_SUCCESS; } /*************************************************************************/ static const char* test_EraseHierarchy() { ZRegistry reg; reg.Put("A.B", "Test2"); reg.Erase("A"); TASSERT(!reg.Get("A.B").Valid(), "Child node should have been erased but was not"); return ZTEST_SUCCESS; }