Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkPropertyList.h"
00019 #include "mitkProperties.h"
00020 #include "mitkLookupTables.h"
00021 #include "mitkStringProperty.h"
00022 #include <iostream>
00023
00024 int mitkPropertyListTest(int , char* [])
00025 {
00026 mitk::PropertyList::Pointer propList;
00027 std::cout << "Testing mitk::PropertyList::New(): ";
00028 propList = mitk::PropertyList::New();
00029 if (propList.IsNull()) {
00030 std::cout << "[FAILED]" << std::endl;
00031 return EXIT_FAILURE;
00032 }
00033 else {
00034 std::cout << "[PASSED]" << std::endl;
00035 }
00036 mitk::BoolProperty::Pointer boolProp = mitk::BoolProperty::New(false);
00037 mitk::BoolProperty::Pointer boolProp2 = mitk::BoolProperty::New(false);
00038 std::cout << "Testing BoolProperty ==: ";
00039 if (! (*boolProp2 == *boolProp) ) {
00040
00041 std::cout << "[FAILED]" << std::endl;
00042 return EXIT_FAILURE;
00043 }
00044 std::cout << "[PASSED]" << std::endl;
00045 unsigned long tBefore,tAfter;
00046
00047 std::cout << "Testing SetProperty() with new key value: ";
00048 tBefore = propList->GetMTime();
00049 propList->SetProperty("test",boolProp);
00050 tAfter = propList->GetMTime();
00051 if (! ( tAfter > tBefore) ) {
00052 std::cout << "[FAILED]" << std::endl;
00053 return EXIT_FAILURE;
00054 }
00055 std::cout << "[PASSED]" << std::endl;
00056
00057 std::cout << "Testing SetProperty() with changed property value: ";
00058 tBefore = propList->GetMTime();
00059 propList->SetProperty("test",mitk::BoolProperty::New(true));
00060 tAfter = propList->GetMTime();
00061 if (! (tAfter > tBefore) ) {
00062 std::cout << "[FAILED]" << std::endl;
00063 return EXIT_FAILURE;
00064 }
00065 std::cout << "[PASSED]" << std::endl;
00066
00067 std::cout << "Testing SetProperty() with unchanged property value: ";
00068 tBefore = propList->GetMTime();
00069 propList->SetProperty("test",mitk::BoolProperty::New(true));
00070 tAfter = propList->GetMTime();
00071 if ( tBefore != tAfter ) {
00072 std::cout << "[FAILED]" << std::endl;
00073 return EXIT_FAILURE;
00074 }
00075 std::cout << "[PASSED]" << std::endl;
00076
00077 std::cout << "Testing MTime correctness when changing property value: ";
00078 boolProp = mitk::BoolProperty::New(true);
00079 propList->ReplaceProperty("test",boolProp);
00080 tBefore = propList->GetMTime();
00081 boolProp->SetValue(true);
00082 tAfter = propList->GetMTime();
00083 boolProp->SetValue(false);
00084 unsigned long tAfterAll = propList->GetMTime();
00085
00086 if (tBefore != tAfter || tAfterAll <= tAfter) {
00087 std::cout << "[FAILED]" << std::endl;
00088 return EXIT_FAILURE;
00089 }
00090 std::cout << "[PASSED]" << std::endl;
00091
00092 std::cout << "Testing MTime correctness when calling SetProperty twice: ";
00093 boolProp = mitk::BoolProperty::New(true);
00094 propList->SetProperty("test",boolProp);
00095 tBefore = propList->GetMTime();
00096 propList->SetProperty("test",boolProp);
00097 tAfter = propList->GetMTime();
00098
00099 if (tBefore != tAfter) {
00100 std::cout << "[FAILED]" << std::endl;
00101 return EXIT_FAILURE;
00102 }
00103 std::cout << "[PASSED]" << std::endl;
00104
00105
00106 std::cout << "Testing if existing properties survive SetProperty: ";
00107 propList->SetProperty("test",boolProp);
00108 mitk::BaseProperty* bpBefore = propList->GetProperty("test");
00109 propList->SetProperty("test",boolProp2);
00110 mitk::BaseProperty* bpAfter = propList->GetProperty("test");
00111
00112 if (bpBefore != bpAfter || bpAfter == NULL) {
00113 std::cout << std::endl;
00114 std::cout << "[FAILED]" << std::endl;
00115 return EXIT_FAILURE;
00116 }
00117 std::cout << "[PASSED]" << std::endl;
00118
00119 std::cout << "Testing if existing properties survive ReplaceProperty: ";
00120 propList->SetProperty("test",boolProp);
00121 bpBefore = propList->GetProperty("test");
00122 propList->ReplaceProperty("test",boolProp2);
00123 bpAfter = propList->GetProperty("test");
00124
00125 if (bpBefore == bpAfter || bpAfter == NULL) {
00126 std::cout << std::endl;
00127 std::cout << "[FAILED]" << std::endl;
00128 return EXIT_FAILURE;
00129 }
00130 std::cout << "[PASSED]" << std::endl;
00131
00132
00133
00134
00135
00136
00137
00138 std::cout << "Testing GetPropertyValue(bool): ";
00139 mitk::BoolProperty::Pointer gpvTest = mitk::BoolProperty::New(true);
00140 propList->SetProperty("gpvBool", gpvTest);
00141 bool b = false;
00142 bool getPropertyValueReturnValue = propList->GetPropertyValue<bool>("gpvBool", b);
00143 if ((getPropertyValueReturnValue == true) && (b == gpvTest->GetValue()))
00144 std::cout << "[PASSED]" << std::endl;
00145 else
00146 {
00147 std::cout << "Oh, not goot:"
00148 "\nWe called propList->GetPropertyValue<bool>('gpvBool', b) and it returned " << getPropertyValueReturnValue <<
00149 "\nThen we compared b [" << b << "] and gpvTest->GetValue() [" << gpvTest->GetValue() << "]" << std::endl;
00150 std::cout << "[FAILED]" << std::endl;
00151 return EXIT_FAILURE;
00152 }
00153
00154 std::cout << "Testing GetPropertyValue(float): ";
00155 mitk::FloatProperty::Pointer gpvTest2 = mitk::FloatProperty::New(3.1337);
00156 propList->SetProperty("gpvfloat", gpvTest2);
00157 float v = -1.23;
00158 if ((propList->GetPropertyValue<float>("gpvfloat", v) == true) && (v == gpvTest2->GetValue()))
00159 std::cout << "[PASSED]" << std::endl;
00160 else
00161 {
00162 std::cout << "[FAILED]" << std::endl;
00163 return EXIT_FAILURE;
00164 }
00165
00166 std::cout << "Testing GetPropertyValue(BoolLookupTable): ";
00167 mitk::BoolLookupTable blt;
00168 blt.SetTableValue(17, true);
00169 propList->SetProperty("blutprop", mitk::BoolLookupTableProperty::New(blt));
00170 try
00171 {
00172 mitk::BoolLookupTable blut;
00173 if ((propList->GetPropertyValue<mitk::BoolLookupTable>("blutprop", blut) == true) && (blut.GetTableValue(17) == true))
00174 std::cout << "[PASSED]" << std::endl;
00175 else
00176 {
00177 std::cout << "[FAILED]" << std::endl;
00178 return EXIT_FAILURE;
00179 }
00180 }
00181 catch(...)
00182 {
00183 std::cout << "Exception thrown! [FAILED]" << std::endl;
00184 return EXIT_FAILURE;
00185 }
00186
00187 {
00188 std::cout << "Testing GetBoolProperty(): ";
00189 mitk::BoolProperty::Pointer prop = mitk::BoolProperty::New(true);
00190 propList->ReplaceProperty("test", prop);
00191 bool v = false;
00192 if ((propList->GetBoolProperty("test", v) == true) && (v == prop->GetValue()))
00193 std::cout << "[PASSED]" << std::endl;
00194 else
00195 {
00196 std::cout << "[FAILED]" << std::endl;
00197 return EXIT_FAILURE;
00198 }
00199 }
00200 {
00201 std::cout << "Testing GetIntProperty(): ";
00202 mitk::IntProperty::Pointer prop = mitk::IntProperty::New(31337);
00203 propList->ReplaceProperty("test", prop);
00204 int v = 1;
00205 if ((propList->GetIntProperty("test", v) == true) && (v == prop->GetValue()))
00206 std::cout << "[PASSED]" << std::endl;
00207 else
00208 {
00209 std::cout << "[FAILED]" << std::endl;
00210 return EXIT_FAILURE;
00211 }
00212 }
00213 {
00214 std::cout << "Testing GetFloatProperty(): ";
00215 mitk::FloatProperty::Pointer prop = mitk::FloatProperty::New(31.337);
00216 propList->ReplaceProperty("test", prop);
00217 float v = 1.2;
00218 if ((propList->GetFloatProperty("test", v) == true) && (v == prop->GetValue()))
00219 std::cout << "[PASSED]" << std::endl;
00220 else
00221 {
00222 std::cout << "[FAILED]" << std::endl;
00223 return EXIT_FAILURE;
00224 }
00225 }
00226 {
00227 std::cout << "Testing GetStringProperty(): ";
00228 mitk::StringProperty::Pointer prop = mitk::StringProperty::New("MITK");
00229 propList->ReplaceProperty("test", prop);
00230 std::string v = "";
00231 if ((propList->GetStringProperty("test", v) == true) && (v == prop->GetValue()))
00232 std::cout << "[PASSED]" << std::endl;
00233 else
00234 {
00235 std::cout << "[FAILED]" << std::endl;
00236 return EXIT_FAILURE;
00237 }
00238 }
00239
00240 std::cout << "[TEST DONE]" << std::endl;
00241 return EXIT_SUCCESS;
00242 }