00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __TestingMacros_h
00014 #define __TestingMacros_h
00015
00016 #include "vtkDebugLeaks.h"
00017 #include "vtkSmartPointer.h"
00018 #include "vtkMath.h"
00019
00021 #define DEBUG_LEAKS_ENABLE_EXIT_ERROR() \
00022 vtkDebugLeaks::SetExitError(true);
00023
00025 #define EXERCISE_BASIC_OBJECT_METHODS( object ) \
00026 { \
00027 if ( object == NULL ) \
00028 { \
00029 std::cerr << "EXERCISE_BASIC_OBJECT_METHODS( with NULL object )" << std::endl; \
00030 return EXIT_FAILURE; \
00031 } \
00032 object->Print( std::cout ); \
00033 std::cout << "Name of Class = " << object->GetClassName() << std::endl; \
00034 std::cout << "Name of Superclass = " << object->Superclass::GetClassName() << std::endl; \
00035 }
00036
00038 #define TRY_EXPECT_ITK_EXCEPTION( command ) \
00039 try \
00040 { \
00041 std::cout << "Trying " << #command << std::endl; \
00042 command; \
00043 std::cerr << "Failed to catch expected exception" << std::endl; \
00044 return EXIT_FAILURE; \
00045 } \
00046 catch( itk::ExceptionObject & excp ) \
00047 { \
00048 std::cout << "Caught expected exception" << std::endl; \
00049 std::cout << excp << std::endl; \
00050 }
00051
00053 #define TRY_EXPECT_NO_ITK_EXCEPTION( command ) \
00054 try \
00055 { \
00056 std::cout << "Trying " << #command << std::endl; \
00057 command; \
00058 } \
00059 catch( itk::ExceptionObject & excp ) \
00060 { \
00061 std::cerr << excp << std::endl; \
00062 return EXIT_FAILURE; \
00063 }
00064
00066 #define TEST_ITK_SET_GET( variable, command ) \
00067 if( variable.GetPointer() != command ) \
00068 { \
00069 std::cerr << "Error in " << #command << std::endl; \
00070 std::cerr << "Expected " << variable.GetPointer() << std::endl; \
00071 std::cerr << "but got " << command << std::endl; \
00072 return EXIT_FAILURE; \
00073 }
00074
00076 #define TEST_ITK_SET_GET_VALUE( variable, command ) \
00077 if( variable != command ) \
00078 { \
00079 std::cerr << "Error in " << #command << std::endl; \
00080 std::cerr << "Expected " << variable << std::endl; \
00081 std::cerr << "but got " << command << std::endl; \
00082 return EXIT_FAILURE; \
00083 }
00084
00086 #define TEST_SET_GET_BOOLEAN( object, variable ) \
00087 object->Set##variable( false ); \
00088 object->Set##variable( true ); \
00089 if( object->Get##variable() != 1 ) \
00090 { \
00091 std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \
00092 return EXIT_FAILURE; \
00093 } \
00094 object->Set##variable( false ); \
00095 if( object->Get##variable() != 0 ) \
00096 { \
00097 std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \
00098 return EXIT_FAILURE; \
00099 } \
00100 object->variable##On(); \
00101 if( object->Get##variable() != 1 ) \
00102 { \
00103 std::cerr << "Error in On/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \
00104 return EXIT_FAILURE; \
00105 } \
00106 object->variable##Off(); \
00107 if( object->Get##variable() != 0 ) \
00108 { \
00109 std::cerr << "Error in Off/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \
00110 return EXIT_FAILURE; \
00111 }
00112
00115 #define TEST_SET_GET_INT( object, variable, value ) \
00116 { \
00117 object->Set##variable( value ); \
00118 if( object->Get##variable() != value ) \
00119 { \
00120 std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
00121 return EXIT_FAILURE; \
00122 } \
00123 }
00124
00129 #define TEST_SET_GET_INT_RANGE( object, variable, min, max ) \
00130 { \
00131 int epsilon = 1; \
00132 int val = min - epsilon; \
00133 TEST_SET_GET_INT( object, variable, val); \
00134 val = min; \
00135 TEST_SET_GET_INT( object, variable, val); \
00136 val = min + epsilon; \
00137 TEST_SET_GET_INT( object, variable, val); \
00138 val = (min + max) / 2; \
00139 TEST_SET_GET_INT( object, variable, val); \
00140 val = max - epsilon; \
00141 TEST_SET_GET_INT( object, variable, val); \
00142 val = max; \
00143 TEST_SET_GET_INT( object, variable, val); \
00144 val = max + epsilon; \
00145 TEST_SET_GET_INT( object, variable, val); \
00146 }
00147
00150 #define TEST_SET_GET_INT_RANDOM( object, variable, max ) \
00151 { \
00152 int val = (int)(vtkMath::Random() * max); \
00153 object->Set##variable( val ); \
00154 if( object->Get##variable() != val ) \
00155 { \
00156 std::cerr << "Error in Set/Get"#variable << " using random value " << val << std::endl; \
00157 return EXIT_FAILURE; \
00158 } \
00159 }
00160
00163 #define TEST_SET_GET_DOUBLE( object, variable, value ) \
00164 { \
00165 object->Set##variable( value ); \
00166 if( object->Get##variable() != value ) \
00167 { \
00168 std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
00169 return EXIT_FAILURE; \
00170 } \
00171 }
00172
00177 #define TEST_SET_GET_DOUBLE_RANGE( object, variable, min, max ) \
00178 { \
00179 double epsilon = 1.0; \
00180 double val = min - epsilon; \
00181 TEST_SET_GET_DOUBLE( object, variable, val); \
00182 val = min; \
00183 TEST_SET_GET_DOUBLE( object, variable, val); \
00184 val = min + epsilon; \
00185 TEST_SET_GET_DOUBLE( object, variable, val); \
00186 val = (min + max) / 2.0; \
00187 TEST_SET_GET_DOUBLE( object, variable, val); \
00188 val = max - epsilon; \
00189 TEST_SET_GET_DOUBLE( object, variable, val); \
00190 val = max; \
00191 TEST_SET_GET_DOUBLE( object, variable, val); \
00192 val = max + epsilon; \
00193 TEST_SET_GET_DOUBLE( object, variable, val); \
00194 }
00195
00198 #define TEST_SET_GET_DOUBLE_RANDOM( object, variable, max ) \
00199 { \
00200 double val = vtkMath::Random() * max; \
00201 object->Set##variable( val ); \
00202 if( object->Get##variable() != val ) \
00203 { \
00204 std::cerr << "Error in Set/Get"#variable << ", using random value " << val << std::endl; \
00205 return EXIT_FAILURE; \
00206 } \
00207 }
00208
00211 #define TEST_SET_GET_VECTOR3_DOUBLE( object, variable, x, y, z ) \
00212 { \
00213 object->Set##variable( x, y, z ); \
00214 double *val = object->Get##variable(); \
00215 if( val == NULL || val[0] != x || val[1] != y || val[2] != z ) \
00216 { \
00217 std::cerr << "Error in Set/Get"#variable << std::endl; \
00218 return EXIT_FAILURE; \
00219 } \
00220 }
00221
00227 #define TEST_SET_GET_VECTOR3_DOUBLE_RANGE( object, variable, min, max ) \
00228 { \
00229 double epsilon = 1.0; \
00230 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min - epsilon, min - epsilon, min - epsilon); \
00231 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min, min, min); \
00232 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min + epsilon, min + epsilon, min + epsilon); \
00233 double half = (min+max/2.0); \
00234 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, half, half, half); \
00235 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max - epsilon, max - epsilon, max - epsilon); \
00236 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max, max, max); \
00237 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max + epsilon, max + epsilon, max + epsilon); \
00238 }
00239
00242 #define TEST_SET_GET_VECTOR3_DOUBLE_RANDOM( object, variable, max ) \
00243 { \
00244 double x = vtkMath::Random() * max; \
00245 double y = vtkMath::Random() * max; \
00246 double z = vtkMath::Random() * max; \
00247 object->Set##variable( x, y, z ); \
00248 double *val = object->Get##variable(); \
00249 if( val == NULL || val[0] != x || val[1] != y || val[2] != z ) \
00250 { \
00251 std::cerr << "Error in Set/Get"#variable << " with " << x << ", " << y << ", " << z << std::endl; \
00252 return EXIT_FAILURE; \
00253 } \
00254 }
00255
00257 #define TEST_SET_GET_STRING( object, variable ) \
00258 { \
00259 const char * originalStringPointer = object->Get##variable(); \
00260 std::string originalString; \
00261 if( originalStringPointer != NULL ) \
00262 { \
00263 originalString = originalStringPointer; \
00264 } \
00265 object->Set##variable( "testing with a const char"); \
00266 if( strcmp(object->Get##variable(), "testing with a const char") != 0) \
00267 { \
00268 std::cerr << "Error in Set/Get"#variable << " with a string literal" << std::endl; \
00269 return EXIT_FAILURE; \
00270 } \
00271 std::string string1 = "testingIsGood"; \
00272 object->Set##variable( string1.c_str() ); \
00273 if( object->Get##variable() != string1 ) \
00274 { \
00275 std::cerr << "Error in Set/Get"#variable << std::endl; \
00276 return EXIT_FAILURE; \
00277 } \
00278 std::string string2 = "moreTestingIsBetter"; \
00279 object->Set##variable( string2.c_str() ); \
00280 if( object->Get##variable() != string2 ) \
00281 { \
00282 std::cerr << "Error in Set/Get"#variable << std::endl; \
00283 return EXIT_FAILURE; \
00284 } \
00285 if( originalStringPointer != NULL ) \
00286 { \
00287 object->Set##variable( originalString.c_str() ); \
00288 } \
00289 else \
00290 { \
00291 object->Set##variable( NULL ); \
00292 } \
00293 } \
00294
00296 #define EXERCISE_BASIC_MRML_METHODS( className, node ) \
00297 {\
00298 vtkMRMLNode * newNode = node1->CreateNodeInstance(); \
00299 if( newNode == NULL ) \
00300 { \
00301 std::cerr << "Error in CreateNodeInstance()" << std::endl; \
00302 return EXIT_FAILURE; \
00303 } \
00304 newNode->Delete(); \
00305 node->UpdateScene(NULL); \
00306 vtkSmartPointer < className > node1 = vtkSmartPointer < className >::New(); \
00307 node1->Copy(node); \
00308 node->Reset(); \
00309 int mod = node->StartModify(); \
00310 std::string nodeTagName = node->GetNodeTagName(); \
00311 std::cout << "Node Tag Name = " << nodeTagName << std::endl; \
00312 std::string attributeName = std::string("attName"); \
00313 std::string attributeValue = std::string("attValue"); \
00314 node->SetAttribute( attributeName.c_str(), attributeValue.c_str() ); \
00315 std::string attributeValue2 = node->GetAttribute( attributeName.c_str() ); \
00316 if( attributeValue != attributeValue2 ) \
00317 { \
00318 std::cerr << "Error in Set/GetAttribute() " << std::endl; \
00319 return EXIT_FAILURE; \
00320 } \
00321 node->EndModify(mod); \
00322 TEST_SET_GET_BOOLEAN( node, HideFromEditors ); \
00323 TEST_SET_GET_BOOLEAN( node, Selectable ); \
00324 TEST_SET_GET_STRING( node, Description ); \
00325 TEST_SET_GET_STRING( node, SceneRootDir ); \
00326 TEST_SET_GET_STRING( node, Name ); \
00327 node->UpdateID("newID"); \
00328 if (strcmp(node->GetID(), "newID") != 0) \
00329 { \
00330 std::cerr << "Error in UpdateID()" << std::endl; \
00331 return EXIT_FAILURE; \
00332 } \
00333 node->CopyID(node1); \
00334 if (node->GetID() != node1->GetID()) \
00335 { \
00336 std::cerr << "Error in CopyID()" << std::endl; \
00337 return EXIT_FAILURE; \
00338 } \
00339 TEST_SET_GET_STRING( node, SingletonTag ); \
00340 TEST_SET_GET_BOOLEAN( node, ModifiedSinceRead ); \
00341 TEST_SET_GET_BOOLEAN( node, SaveWithScene ); \
00342 TEST_SET_GET_BOOLEAN( node, AddToScene ); \
00343 TEST_SET_GET_BOOLEAN( node, DisableModifiedEvent); \
00344 TEST_SET_GET_BOOLEAN( node, Selected ); \
00345 node->Modified(); \
00346 node->InvokePendingModifiedEvent(); \
00347 node1->SetName("copywithsinglemodified"); \
00348 node->CopyWithSingleModifiedEvent(node1); \
00349 node1->SetName("copywithoutmodified"); \
00350 node->CopyWithoutModifiedEvent(node1); \
00351 node1->SetName("copywithscenewithsinglemodified"); \
00352 node->CopyWithSceneWithSingleModifiedEvent(node1); \
00353 node1->SetName("copywithscenewithoutmodified"); \
00354 node->CopyWithSceneWithoutModifiedEvent(node1); \
00355 vtkMRMLScene * scene = node->GetScene(); \
00356 \
00357 if( scene != NULL ) \
00358 { \
00359 std::cerr << "Error in GetScene() " << std::endl; \
00360 return EXIT_FAILURE; \
00361 } \
00362 \
00363 node->UpdateReferences(); \
00364 node->UpdateReferenceID("oldID", "newID"); \
00365 \
00366 std::string stringToEncode = "Thou Shall Test !"; \
00367 std::string stringURLEncoded = node1->URLEncodeString( stringToEncode.c_str() ); \
00368 std::string stringDecoded = node1->URLDecodeString( stringURLEncoded.c_str() ); \
00369 if( stringDecoded != stringToEncode ) \
00370 { \
00371 std::cerr << "Error in URLEncodeString/URLDecodeString() " << std::endl; \
00372 return EXIT_FAILURE; \
00373 } \
00374 \
00375 const char *atts[] = {"id", "vtkMRMLNodeTest1", "name", "MyName", "description", "Testing a mrml node", "hideFromEditors", "false", "selectable", "true", "selected", "true", NULL}; \
00376 node->ReadXMLAttributes(atts); \
00377 if (strcmp(node->GetID(), "vtkMRMLNodeTest1") != 0) \
00378 { \
00379 std::cerr << "Error in ReadXMLAttributes! id should be vtkMRMLNodeTest1, but is " << node->GetID() << std::endl; \
00380 return EXIT_FAILURE; \
00381 } \
00382 node->WriteXML(std::cout, 0); \
00383 std::cout << std::endl; \
00384 }
00385
00388 #define EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS( className, node ) \
00389 { \
00390 EXERCISE_BASIC_MRML_METHODS(className, node); \
00391 vtkMRMLTransformNode *tnode2 = node->GetParentTransformNode(); \
00392 if (tnode2 != NULL)\
00393 {\
00394 std::cerr << "ERROR: parent transform node is not null" << std::endl;\
00395 return EXIT_FAILURE; \
00396 }\
00397 node1->SetAndObserveTransformNodeID(NULL);\
00398 const char *node_tid = node1->GetTransformNodeID();\
00399 if (node_tid != NULL) \
00400 {\
00401 std::cerr << "ERROR: with observing transform node id" << std::endl;\
00402 return EXIT_FAILURE; \
00403 }\
00404 bool canApplyNonLinear = node->CanApplyNonLinearTransforms();\
00405 std::cout << "Node can apply non linear transforms? " << (canApplyNonLinear == true ? "yes" : "no") << std::endl;\
00406 }
00407
00410 #include "vtkMRMLStorageNode.h"
00411 #define EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ) \
00412 { \
00413 EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS(className, node ); \
00414 if (node->GetNumberOfStorageNodes() != 0) \
00415 { \
00416 std::cerr << "Error in getting number of storage nodes." << std::endl; \
00417 return EXIT_FAILURE; \
00418 } \
00419 node->SetAndObserveStorageNodeID("noid"); \
00420 node->AddAndObserveStorageNodeID("badid"); \
00421 node->SetAndObserveNthStorageNodeID(2, "nothing"); \
00422 node->SetSlicerDataType("testing"); \
00423 if (strcmp(node->GetSlicerDataType(), "testing") != 0) \
00424 { \
00425 std::cerr << "ERROR set/get slicer data type" << std::endl; \
00426 return EXIT_FAILURE; \
00427 } \
00428 const char *snodeid = node->GetNthStorageNodeID(0); \
00429 if (strcmp(snodeid, "noid") != 0) \
00430 { \
00431 std::cerr << "ERROR getting 0th storage node id, instead of noid got " << (snodeid == NULL ? "null" : snodeid) << std::endl; \
00432 return EXIT_FAILURE; \
00433 } \
00434 vtkMRMLStorageNode *snode = node->GetNthStorageNode(0); \
00435 if (snode != NULL) \
00436 { \
00437 std::cerr << "ERROR getting 0th storage node" << std::endl; \
00438 return EXIT_FAILURE; \
00439 } \
00440 snode = node->CreateDefaultStorageNode(); \
00441 if (snode == NULL) \
00442 { \
00443 std::cerr << "ERROR creating and getting default storage node" << std::endl; \
00444 return EXIT_FAILURE; \
00445 } \
00446 snode->Delete(); \
00447 vtkTagTable *tagtable = node->GetUserTagTable(); \
00448 if (tagtable == NULL) \
00449 { \
00450 std::cerr << "ERROR getting tag table" << std::endl; \
00451 return EXIT_FAILURE; \
00452 } \
00453 }
00454
00457 #define EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS( className, node ) \
00458 { \
00459 EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ); \
00460 if (node->GetNumberOfDisplayNodes() != 0) \
00461 { \
00462 std::cerr << "Error in getting number of display nodes." << std::endl; \
00463 return EXIT_FAILURE; \
00464 } \
00465 node->SetAndObserveDisplayNodeID("noid"); \
00466 node->AddAndObserveDisplayNodeID("badid"); \
00467 node->SetAndObserveNthDisplayNodeID(2, "nothing"); \
00468 const char *dnodeid = node->GetNthDisplayNodeID(0); \
00469 if (strcmp(dnodeid, "noid") != 0) \
00470 { \
00471 std::cerr << "ERROR getting 0th display node id, instead of noid got " << (dnodeid == NULL ? "null" : dnodeid) << std::endl; \
00472 return EXIT_FAILURE; \
00473 } \
00474 vtkMRMLDisplayNode *dnode = node->GetNthDisplayNode(0); \
00475 if (dnode != NULL) \
00476 { \
00477 std::cerr << "ERROR getting 0th display node" << std::endl; \
00478 return EXIT_FAILURE; \
00479 } \
00480 vtkPolyData *pdata = node1->GetPolyData(); \
00481 if (pdata != NULL) \
00482 { \
00483 std::cerr << "ERROR getting null polydata" << std::endl; \
00484 return EXIT_FAILURE; \
00485 } \
00486 pdata = vtkPolyData::New(); \
00487 node1->SetAndObservePolyData(pdata); \
00488 if (node1->GetPolyData() != pdata) \
00489 { \
00490 std::cerr << "ERROR getting polydata" << std::endl; \
00491 return EXIT_FAILURE; \
00492 } \
00493 pdata->Delete(); \
00494 }
00495
00498 #define EXERCISE_BASIC_DISPLAY_MRML_METHODS( className, node ) \
00499 { \
00500 EXERCISE_BASIC_MRML_METHODS( className, node); \
00501 if (node->GetPolyData() != NULL) \
00502 { \
00503 std::cout << "Warning: After "#className << " node created, polydata is not null" << std::endl; \
00504 } \
00505 if (node->GetImageData() != NULL) \
00506 { \
00507 std::cout << "Warning: After "#className << " node create, image data is not null" << std::endl; \
00508 } \
00509 vtkMRMLDisplayableNode *dnode = node->GetDisplayableNode(); \
00510 if (dnode != NULL) \
00511 { \
00512 std::cerr << "Error getting null displayable node" << std::endl; \
00513 return EXIT_FAILURE; \
00514 } \
00515 node->UpdatePolyDataPipeline(); \
00516 node->UpdateImageDataPipeline(); \
00517 node->SetAndObserveTextureImageData(NULL); \
00518 if (node->GetTextureImageData() != NULL) \
00519 { \
00520 std::cerr << "Error getting null texture image data " << std::endl; \
00521 return EXIT_FAILURE; \
00522 } \
00523 node->SetAndObserveColorNodeID(NULL); \
00524 if (node->GetColorNodeID() != NULL) \
00525 { \
00526 std::cerr << "Error getting null color node id " << std::endl; \
00527 return EXIT_FAILURE; \
00528 } \
00529 if (node->GetColorNode() != NULL) \
00530 { \
00531 std::cerr << "Error getting null color node " << std::endl; \
00532 return EXIT_FAILURE; \
00533 } \
00534 node->SetActiveScalarName("testingScalar"); \
00535 if (strcmp(node->GetActiveScalarName(), "testingScalar") != 0) \
00536 { \
00537 std::cerr << "Error getting active scalar name" << std::endl; \
00538 return EXIT_FAILURE; \
00539 } \
00540 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node, Color, 0.0, 1.0); \
00541 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node, SelectedColor, 0.0, 1.0); \
00542 TEST_SET_GET_DOUBLE_RANGE(node, SelectedAmbient, 0.0, 1.0); \
00543 TEST_SET_GET_DOUBLE_RANGE(node, SelectedSpecular, 0.0, 1.0); \
00544 TEST_SET_GET_DOUBLE_RANGE(node, Opacity, 0.0, 1.0); \
00545 TEST_SET_GET_DOUBLE_RANGE(node, Ambient, 0.0, 1.0); \
00546 TEST_SET_GET_DOUBLE_RANGE(node, Diffuse, 0.0, 1.0); \
00547 TEST_SET_GET_DOUBLE_RANGE(node, Specular, 0.0, 1.0); \
00548 TEST_SET_GET_DOUBLE_RANGE(node, Power, 0.0, 1.0); \
00549 TEST_SET_GET_BOOLEAN(node, Visibility); \
00550 TEST_SET_GET_BOOLEAN(node, Clipping); \
00551 TEST_SET_GET_BOOLEAN(node, SliceIntersectionVisibility); \
00552 TEST_SET_GET_BOOLEAN(node, BackfaceCulling); \
00553 TEST_SET_GET_BOOLEAN(node, ScalarVisibility); \
00554 TEST_SET_GET_BOOLEAN(node, VectorVisibility); \
00555 TEST_SET_GET_BOOLEAN(node, TensorVisibility); \
00556 TEST_SET_GET_BOOLEAN(node, AutoScalarRange); \
00557 double range[2] = {-10, 10}; \
00558 node->SetScalarRange(range); \
00559 double *getrange = node->GetScalarRange(); \
00560 if (getrange == NULL || getrange[0] != range[0] || getrange[1] != range[1]) \
00561 { \
00562 std::cerr << "ERROR getting range" << std::endl; \
00563 return EXIT_FAILURE; \
00564 } \
00565 }
00566
00567 #include <vtkStringArray.h>
00568
00571 #define EXERCISE_BASIC_STORAGE_MRML_METHODS( className, node ) \
00572 { \
00573 EXERCISE_BASIC_MRML_METHODS(className, node); \
00574 node->ReadData(NULL); \
00575 node->WriteData(NULL); \
00576 node->StageReadData(NULL); \
00577 node->StageWriteData(NULL); \
00578 TEST_SET_GET_STRING(node, FileName); \
00579 TEST_SET_GET_STRING(node, TempFileName); \
00580 const char *f0 = node->GetNthFileName(0); \
00581 std::cout << "Filename 0 = " << (f0 == NULL ? "NULL" : f0) << std::endl; \
00582 TEST_SET_GET_BOOLEAN(node, UseCompression); \
00583 TEST_SET_GET_STRING(node, URI); \
00584 vtkURIHandler *handler = vtkURIHandler::New(); \
00585 node->SetURIHandler(NULL); \
00586 if (node->GetURIHandler() != NULL) \
00587 { \
00588 std::cerr << "ERROR getting null uri handler" << std::endl; \
00589 return EXIT_FAILURE; \
00590 } \
00591 node->SetURIHandler(handler); \
00592 if (node->GetURIHandler() == NULL) \
00593 { \
00594 std::cerr << "ERROR getting not null uri handler" << std::endl; \
00595 return EXIT_FAILURE; \
00596 } \
00597 node->SetURIHandler(NULL); \
00598 handler->Delete(); \
00599 TEST_SET_GET_INT_RANGE(node, ReadState, 0, 5); \
00600 const char *rstate = node->GetReadStateAsString(); \
00601 std::cout << "Read state, after int test = " << rstate << std::endl; \
00602 node->SetReadStatePending(); \
00603 rstate = node->GetReadStateAsString(); \
00604 std::cout << "Read state, Pending = " << rstate << std::endl; \
00605 node->SetReadStateIdle(); \
00606 rstate = node->GetReadStateAsString(); \
00607 std::cout << "Read state, Idle = " << rstate << std::endl; \
00608 node->SetReadStateScheduled(); \
00609 rstate = node->GetReadStateAsString(); \
00610 std::cout << "Read state, Scheduled = " << rstate << std::endl; \
00611 node->SetReadStateTransferring(); \
00612 rstate = node->GetReadStateAsString(); \
00613 std::cout << "Read state, Transferring = " << rstate << std::endl; \
00614 node->SetReadStateTransferDone(); \
00615 rstate = node->GetReadStateAsString(); \
00616 std::cout << "Read state, TransfrerDone = " << rstate << std::endl; \
00617 node->SetReadStateCancelled(); \
00618 rstate = node->GetReadStateAsString(); \
00619 std::cout << "Read state, Cancelled = " << rstate << std::endl; \
00620 \
00621 TEST_SET_GET_INT_RANGE(node, WriteState, 0, 5); \
00622 const char *wstate = node->GetWriteStateAsString(); \
00623 std::cout << "Write state, after int test = " << wstate << std::endl; \
00624 node->SetWriteStatePending(); \
00625 wstate = node->GetWriteStateAsString(); \
00626 std::cout << "Write state, Pending = " << wstate << std::endl; \
00627 node->SetWriteStateIdle(); \
00628 wstate = node->GetWriteStateAsString(); \
00629 std::cout << "Write state, Idle = " << wstate << std::endl; \
00630 node->SetWriteStateScheduled(); \
00631 wstate = node->GetWriteStateAsString(); \
00632 std::cout << "Write state, Scheduled = " << wstate << std::endl; \
00633 node->SetWriteStateTransferring(); \
00634 wstate = node->GetWriteStateAsString(); \
00635 std::cout << "Write state, Transferring = " << wstate << std::endl; \
00636 node->SetWriteStateTransferDone(); \
00637 wstate = node->GetWriteStateAsString(); \
00638 std::cout << "Write state, TransfrerDone = " << wstate << std::endl; \
00639 node->SetWriteStateCancelled(); \
00640 wstate = node->GetWriteStateAsString(); \
00641 std::cout << "Write state, Cancelled = " << wstate << std::endl; \
00642 \
00643 std::string fullName = node->GetFullNameFromFileName(); \
00644 std::cout << "fullName = " << fullName.c_str() << std::endl; \
00645 std::string fullName0 = node->GetFullNameFromNthFileName(0); \
00646 std::cout << "fullName0 = " << fullName0.c_str() << std::endl; \
00647 \
00648 vtkSmartPointer<vtkStringArray> types = node->GetSupportedWriteFileTypes(); \
00649 std::cout << "Supported write types: (" << types->GetNumberOfValues() << ")" << std::endl; \
00650 for (vtkIdType i = 0; i < types->GetNumberOfValues(); i++) \
00651 { \
00652 std::cout << "\t" << types->GetValue(i).c_str() << std::endl; \
00653 } \
00654 int sup = node->SupportedFileType(NULL); \
00655 std::cout << "Filename or uri supported? " << sup << std::endl; \
00656 sup = node->SupportedFileType("testing.vtk"); \
00657 std::cout << ".vtk supported? " << sup << std::endl; \
00658 sup = node->SupportedFileType("testing.nrrd"); \
00659 std::cout << ".nrrd supported? " << sup << std::endl; \
00660 sup = node->SupportedFileType("testing.mgz"); \
00661 std::cout << ".mgz supported? " << sup << std::endl; \
00662 \
00663 TEST_SET_GET_STRING(node, WriteFileFormat); \
00664 node->AddFileName("testing.txt"); \
00665 std::cout << "Number of file names = " << node->GetNumberOfFileNames() << std::endl; \
00666 int check = node->FileNameIsInList("testing.txt");\
00667 if (check != 1) \
00668 { \
00669 std::cerr << "ERROR: file name not in list!" << std::endl; \
00670 return EXIT_FAILURE; \
00671 } \
00672 node->ResetNthFileName(0, "moretesting.txt"); \
00673 node->ResetNthFileName(100, "notinlist.txt"); \
00674 node->ResetNthFileName(0, NULL); \
00675 check = node->FileNameIsInList("notinlist"); \
00676 if (check != 0) \
00677 { \
00678 std::cerr << "ERROR: bad file is in list!" << std::endl; \
00679 return EXIT_FAILURE; \
00680 } \
00681 node->ResetFileNameList(); \
00682 if (node->GetNumberOfFileNames() != 0) \
00683 { \
00684 std::cerr << "ERROR: " << node->GetNumberOfFileNames() << " files left in list after reset!" << std::endl; \
00685 return EXIT_FAILURE; \
00686 } \
00687 \
00688 node->ResetURIList(); \
00689 std::cout << "Number of uri's after resetting list = " << node->GetNumberOfURIs() << std::endl; \
00690 node->AddURI("http://www.nowhere.com/filename.txt"); \
00691 if ( node->GetNumberOfURIs() != 1) \
00692 { \
00693 std::cerr << "Error adding one uri, number of uris is incorrect: " << node->GetNumberOfURIs()<< std::endl; \
00694 return EXIT_FAILURE; \
00695 } \
00696 const char *uri = node->GetNthURI(0); \
00697 if (uri == NULL || strcmp(uri, "http://www.nowhere.com/filename.txt") != 0) \
00698 { \
00699 std::cerr << "0th URI " << uri << " is incorrect." << std::endl; \
00700 return EXIT_FAILURE; \
00701 } \
00702 node->ResetNthURI(0, "http://www.nowhere.com/newfilename.txt"); \
00703 node->ResetNthURI(100, "ftp://not.in.list"); \
00704 node->ResetNthURI(100, NULL); \
00705 const char *dataDirName = "/testing/a/directory"; \
00706 node->SetDataDirectory(dataDirName); \
00707 node->SetFileName("/tmp/file.txt"); \
00708 node->SetDataDirectory(dataDirName); \
00709 const char *uriPrefix = "http://www.somewhere.com/"; \
00710 node->SetURIPrefix(uriPrefix); \
00711 \
00712 const char *defaultExt = node->GetDefaultWriteFileExtension(); \
00713 std::cout << "Default write extension = " << (defaultExt == NULL ? "null" : defaultExt) << std::endl; \
00714 \
00715 std::cout << "Is null file path relative? " << node->IsFilePathRelative(NULL) << std::endl; \
00716 std::cout << "Is absolute file path relative? " << node->IsFilePathRelative("/spl/tmp/file.txt") << std::endl; \
00717 std::cout << "Is relative file path relative? " << node->IsFilePathRelative("tmp/file.txt") << std::endl; \
00718 const char *absPath = node->GetAbsoluteFilePath("tmp/file.txt"); \
00719 std::cout << "Get absolute path from tmp/file.txt: " << (absPath == NULL ? "NULL" : absPath) << std::endl; \
00720 }
00721
00722 #include "vtkMatrix4x4.h"
00725 #define EXERCISE_BASIC_TRANSFORM_MRML_METHODS( className, node ) \
00726 { \
00727 EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ); \
00728 std::cout << "IsLinear = " << node->IsLinear()<< std:: endl; \
00729 vtkSmartPointer<vtkGeneralTransform> g = vtkSmartPointer<vtkGeneralTransform>::New(); \
00730 g = node->GetTransformToParent(); \
00731 if (g == NULL) \
00732 { \
00733 std::cout << "Warning: transform node has a null transform to parent" << std::endl; \
00734 } \
00735 std::cout << "IsTransformToWorldLinear = " << node->IsTransformToWorldLinear() << std::endl; \
00736 vtkSmartPointer < className > t = vtkSmartPointer < className >::New(); \
00737 std::cout << "IsTransformToNodeLinear = " << node->IsTransformToNodeLinear(t) << std::endl; \
00738 node->GetTransformToWorld(g); \
00739 node->GetTransformToNode(t, g); \
00740 vtkSmartPointer<vtkMatrix4x4> m = vtkSmartPointer<vtkMatrix4x4>::New(); \
00741 int retval = node->GetMatrixTransformToWorld(m); \
00742 if (retval == 0) \
00743 { \
00744 std::cout << "Warning: can't get matrix transform to world." << std::endl; \
00745 } \
00746 retval = node->GetMatrixTransformToNode(t, m); \
00747 if (retval == 0) \
00748 { \
00749 std::cout << "Warning: can't get matrix transform to node." << std::endl; \
00750 } \
00751 std::cout << "IsTransformNodeMyParent = " << node->IsTransformNodeMyParent(t) << std::endl; \
00752 std::cout << "IsTransformNodeMyChild = " << node->IsTransformNodeMyChild(t) << std::endl; \
00753 }
00754
00755 #endif
00756
00757
00758
00759
00760 #define ctkFail(MSG) \
00761 std::cerr << "line " << __LINE__ << " - " << MSG << std::endl;
00762
00763
00764
00765
00766
00767 #define ctkVerify2(CONDITION, MSG) \
00768 if (!(CONDITION)) \
00769 { \
00770 ctkFail("Assert(" << #CONDITION \
00771 << ") " << MSG); \
00772 return EXIT_FAILURE; \
00773 }
00774
00775
00776
00777
00778
00779 #define ctkVerify(CONDITION) \
00780 ctkVerify2(CONDITION, "")
00781
00782
00783
00784
00785 #define ctkCompare(ACTUAL_VALUE, EXPECTED_VALUE) \
00786 if (ACTUAL_VALUE != EXPECTED_VALUE) \
00787 { \
00788 ctkFail("Compare failed (" << #ACTUAL_VALUE << "!=" \
00789 << #EXPECTED_VALUE << ")" << std::endl \
00790 << " Current:" << ACTUAL_VALUE << std::endl \
00791 << " Expected:"<< EXPECTED_VALUE); \
00792 return EXIT_FAILURE; \
00793 }
00794
00795
00796 #define ctkExerciseMethod(OBJECT, SETTER, GETTER, VALUE_TO_SET, EXPECTED_VALUE) \
00797 (OBJECT)->SETTER(VALUE_TO_SET); \
00798 ctkCompare((OBJECT)->GETTER(), EXPECTED_VALUE)