/* Test-ZName.cpp Author: James Russell Purpose: Unit Test the ZName class. Changelog: 12/18/2011 - Removed dependency on ZString (crertel) 2011/04/07 - creation (jcrussell) */ #include "ZUnitTest.hpp" #include static const char* test_Constructors(); static const char* test_Operators(); static const char* test_ToString(); //List of unit tests ZUnitTest ZNameUnitTests[] = { { "ZName: Constructors", test_Constructors }, { "ZName: Operators", test_Operators }, { "ZName: String Conversion", test_ToString } }; //Now declare the ZUnitTestBlock associated with this. DECLARE_ZTESTBLOCK(ZName); /*************************************************************************/ static bool testFunction(ZName _name, ZString _string) { return _name.ToString() == _string; } static const char* test_Constructors() { ZName name1("TestName1"); ZName name2("TestName2"); TASSERT(testFunction(name1, "TestName1"), "ZName: Failed to copy construct and compare correctly!"); TASSERT(!testFunction(name2, "WRONG!"), "ZName: Failed to copy construct and compare incorrectly!") return ZTEST_SUCCESS; } /*************************************************************************/ static const char* test_Operators() { ZName testName1 = "Name1"; ZName testName2("Name2"); ZName testName3; ZName testName4 = "TestName4"; ZName testName5("TestName5"); ZName testName6; testName3 = "Name3"; TASSERT(testName1 == "Name1", "ZName : Setting testName1 Failed!"); TASSERT(testName2 == "Name2", "ZName : Setting testName2 Failed!"); TASSERT(testName3 == "Name3", "ZName : Setting testName3 Failed!"); TASSERT(testName1 != testName2, "ZName : Comparison of testName1 and testName2 Failed!"); TASSERT(testName1 != testName3, "ZName : Comparison of testName1 and testName3 Failed!"); TASSERT(testName2 != testName3, "ZName : Comparison of testName1 and testName2 Failed!"); testName6 = "TestName6"; TASSERT(testName4 == "TestName4", "ZName : Setting testName4 Failed!"); TASSERT(testName5 == "TestName5", "ZName : Setting testName5 Failed!"); TASSERT(testName6 == "TestName6", "ZName : Setting testName6 Failed!"); TASSERT(testName4 != testName5, "ZName : Comparison of testName4 and testName5 Failed!"); TASSERT(testName4 != testName6, "ZName : Comparison of testName4 and testName6 Failed!"); TASSERT(testName5 != testName6, "ZName : Comparison of testName5 and testName6 Failed!"); return ZTEST_SUCCESS; } /*************************************************************************/ static const char* test_ToString() { ZName testName1 = "Name1"; ZString testString1 = testName1.ToString(); TASSERT(testString1 == "Name1", "ZName : Unable to convert to ZString!"); TASSERT(testString1.PopBack() == '1', "ZName : Unable to manipulate converted ZString!"); return ZTEST_SUCCESS; }