diff --git a/Modules/Core/test/mitkUIDGeneratorTest.cpp b/Modules/Core/test/mitkUIDGeneratorTest.cpp index 9000834607..31469faf8b 100644 --- a/Modules/Core/test/mitkUIDGeneratorTest.cpp +++ b/Modules/Core/test/mitkUIDGeneratorTest.cpp @@ -1,85 +1,99 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// std includes +#include +// MITK includes #include "mitkUIDGenerator.h" #include -#include +// VTK includes +#include -void newGeneratorInstancesHeapTest() +class mitkUIDGeneratorTestSuite : public mitk::TestFixture { - auto uidGen1 = new mitk::UIDGenerator("UID_", 8); - mitk::UIDGenerator *uidGen2 = uidGen1; - std::string uid1_1, uid2_1; - - uid1_1 = uidGen1->GetUID(); - - uidGen1 = new mitk::UIDGenerator("UID_", 8); - - uid2_1 = uidGen1->GetUID(); - - delete uidGen1; - delete uidGen2; - - MITK_TEST_CONDITION(uid1_1 != uid2_1, "Different UIDs are not allowed to be equal"); -} - -void multipleUIDsFromSameGeneratorTest(int /*UIDlength*/) -{ - auto uidGen = new mitk::UIDGenerator("UID_", 8); - std::string uid1, uid2; - uid1 = uidGen->GetUID(); - uid2 = uidGen->GetUID(); - delete uidGen; - MITK_TEST_CONDITION(uid1 != uid2, - "Testing two UIDs from the same generator. Different UIDs are not allowed to be equal"); -} - -void newGeneratorInstancesTest() -{ - mitk::UIDGenerator uidGen1("UID_", 8); - std::string uid1_1, uid2_1; - - uid1_1 = uidGen1.GetUID(); - - uidGen1 = mitk::UIDGenerator("UID_", 8); - - uid2_1 = uidGen1.GetUID(); - - MITK_TEST_CONDITION(uid1_1 != uid2_1, "Different UIDs are not allowed to be equal"); -} - -void severalGeneratorInstancesTest() -{ - mitk::UIDGenerator uidGen1("UID_", 8); - mitk::UIDGenerator uidGen2("UID_", 8); - std::string uid1_1, uid2_1; - - uid1_1 = uidGen1.GetUID(); - uid2_1 = uidGen2.GetUID(); - - MITK_TEST_CONDITION(uid1_1 != uid2_1, "Different UIDs are not allowed to be equal"); -} - -int mitkUIDGeneratorTest(int /*argc*/, char * /*argv*/ []) -{ - MITK_TEST_BEGIN("mitkUIDGeneratorTest"); - severalGeneratorInstancesTest(); - newGeneratorInstancesTest(); - newGeneratorInstancesHeapTest(); - multipleUIDsFromSameGeneratorTest(8); - multipleUIDsFromSameGeneratorTest(16); - MITK_TEST_END(); -} + CPPUNIT_TEST_SUITE(mitkUIDGeneratorTestSuite); + MITK_TEST(newGeneratorInstancesHeap_DifferentUIDs); + MITK_TEST(multipleUIDsFromSameGenerator_DifferentUIDs); + MITK_TEST(newGeneratorInstances_DifferentUIDs); + MITK_TEST(severalGeneratorInstances_DifferentUIDs); + CPPUNIT_TEST_SUITE_END(); + + +private: + std::string m_Uid1, m_Uid2; + +public: + void setUp() + { + } + + void tearDown() + { + m_Uid1 = ""; + m_Uid2 = ""; + } + + void newGeneratorInstancesHeap_DifferentUIDs() + { + auto uidGen1 = new mitk::UIDGenerator("UID_", 8); + mitk::UIDGenerator *uidGen2 = uidGen1; + m_Uid1 = uidGen1->GetUID(); + + uidGen1 = new mitk::UIDGenerator("UID_", 8); + + m_Uid2 = uidGen1->GetUID(); + + delete uidGen1; + delete uidGen2; + + CPPUNIT_ASSERT_MESSAGE("First UIDs of two different generators are not allowed to be equal.", m_Uid1 != m_Uid2); + } + + void multipleUIDsFromSameGenerator_DifferentUIDs() + { + auto uidGen = new mitk::UIDGenerator("UID_", 8); + m_Uid1 = uidGen->GetUID(); + m_Uid2 = uidGen->GetUID(); + delete uidGen; + CPPUNIT_ASSERT_MESSAGE("Testing two UIDs from the same generator. Different UIDs are not allowed to be equal", m_Uid1 != m_Uid2); + } + + void newGeneratorInstances_DifferentUIDs() + { + mitk::UIDGenerator uidGen1("UID_", 8); + m_Uid1 = uidGen1.GetUID(); + + uidGen1 = mitk::UIDGenerator("UID_", 8); + m_Uid2 = uidGen1.GetUID(); + + CPPUNIT_ASSERT_MESSAGE("Testing two UIDs from new Instances. Different UIDs are not allowed to be equal", m_Uid1 != m_Uid2); + } + + void severalGeneratorInstances_DifferentUIDs() + { + mitk::UIDGenerator uidGen1("UID_", 8); + mitk::UIDGenerator uidGen2("UID_", 8); + + m_Uid1 = uidGen1.GetUID(); + m_Uid2 = uidGen2.GetUID(); + + CPPUNIT_ASSERT_MESSAGE("Testing two UIDs from different Generators. Different UIDs are not allowed to be equal", m_Uid1 != m_Uid2); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkUIDGenerator)