00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkTestingMacros.h"
00019 #include "mitkGenericProperty.h"
00020 #include "mitkStringProperty.h"
00021 #include "mitkProperties.h"
00022 #include "mitkVector.h"
00023
00024 #include <iostream>
00025 #include <string>
00026
00027
00028 template <typename T>
00029 int TestGenericPropertyForDataType(typename T::ValueType testValue1, typename T::ValueType testValue2, std::string testValue1AsString, std::string testValue2AsString, std::string type)
00030 {
00031 std::cout << "Testing mitk::GenericProperty<" << type << ">(" << testValue1AsString << ", " << testValue2AsString << ") \n";
00032
00033 typename T::Pointer prop(T::New());
00034 typename T::Pointer prop2(T::New(testValue1));
00035 typename T::Pointer prop3(T::New(testValue2));
00036
00037 unsigned long tBefore = prop->GetMTime();
00038 prop->SetValue(testValue1);
00039 unsigned long tAfter = prop->GetMTime();
00040 prop->SetValue(testValue1);
00041 unsigned long tAfterAll = prop->GetMTime();
00042
00043 MITK_TEST_CONDITION_REQUIRED(prop->GetValue() == testValue1 && prop->GetValueAsString() == testValue1AsString,"Testing SetValue")
00044
00045 MITK_TEST_CONDITION_REQUIRED((*prop == *prop2),"Testing equality operator (operator==)");
00046
00047 prop->SetValue(testValue2);
00048 unsigned long tAfterEverything = prop->GetMTime();
00049
00050 std::cout << " Testing MTime correctness when changing property value: ";
00051 if (tBefore >= tAfter || tAfterAll != tAfter || tAfterEverything <= tAfterAll) {
00052 std::cout << "[FAILED]" << std::endl;
00053 return EXIT_FAILURE;
00054 }
00055 std::cout << "[PASSED]" << std::endl;
00056
00057 prop->SetValue(testValue1);
00058 std::cout << " Testing assignment operator (operator=): ";
00059 *prop = *prop3;
00060 if ( (! (*prop == *prop3)) || (*prop == *prop2) ) {
00061 std::cout << " [FAILED]" << std::endl;
00062 return EXIT_FAILURE;
00063 }
00064 std::cout << "[PASSED]" << std::endl;
00065 std::cout << std::endl;
00066
00067 return EXIT_SUCCESS;
00068 }
00069
00070
00071 int mitkGenericPropertyTest(int , char* [])
00072 {
00073 MITK_TEST_BEGIN(GenericPropertyTest)
00074
00075
00076 TestGenericPropertyForDataType<mitk::IntProperty>(1, 2, "1", "2", "int");
00077 TestGenericPropertyForDataType<mitk::BoolProperty>(true, false, "1", "0", "bool");
00078 TestGenericPropertyForDataType<mitk::FloatProperty>(1.0, -1.0, "1", "-1", "float");
00079 TestGenericPropertyForDataType<mitk::DoubleProperty>(1.0, -1.0, "1", "-1", "double");
00080
00081 TestGenericPropertyForDataType<mitk::StringProperty>(std::string("eins"), std::string("zwei"), std::string("eins"), std::string("zwei"), "std::string");
00082
00083 {
00084 mitk::Point3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0;
00085 mitk::Point3D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0;
00086 TestGenericPropertyForDataType<mitk::Point3dProperty>( p1, p2, "[2, 3, 4]", "[-1, 2, 3]", "mitk::Point3D");
00087 }
00088
00089 {
00090 mitk::Point4D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; p1[3] =-2.0;
00091 mitk::Point4D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0; p2[3] = 5.0;
00092 TestGenericPropertyForDataType<mitk::Point4dProperty>( p1, p2, "[2, 3, 4, -2]", "[-1, 2, 3, 5]", "mitk::Point4D");
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 {
00104 mitk::Vector3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0;
00105 mitk::Vector3D p2; p2[0] =-1.0; p2[1] = 2.0; p2[2] = 3.0;
00106 TestGenericPropertyForDataType<mitk::Vector3DProperty>( p1, p2, "[2, 3, 4]", "[-1, 2, 3]", "mitk::Vector3D");
00107 }
00108
00109 MITK_TEST_END();
00110 }