[Repository Listing] / [Slicer3] / oldtrunk / TestingMacros.h
 

View of /oldtrunk/TestingMacros.h

Parent Directory Parent Directory Revision Log Revision Log


Revision 15040  Download Blame
File MIME type: text/plain
File size: 47614 byte(s)
ENH: implementing changes described in the email linked below.
http://massmail.spl.harvard.edu/public-archives/slicer-devel/2010/005338.html
1 /*=auto=========================================================================
2
3 Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH)
4 All Rights Reserved.
5
6 See Doc/copyright/copyright.txt
7 or http://www.slicer.org/copyright/copyright.txt for details.
8
9 Program: 3D Slicer
10
11 =========================================================================auto=*/
12
13 #ifndef __TestingMacros_h
14 #define __TestingMacros_h
15
16 #include "vtkDebugLeaks.h"
17 #include "vtkSmartPointer.h"
18 #include "vtkMath.h"
19
20 /// turns on exiting with an error if there are leaks
21 #define DEBUG_LEAKS_ENABLE_EXIT_ERROR() \
22 vtkDebugLeaks::SetExitError(true);
23
24 /// tests basic vtkObject methods
25 #define EXERCISE_BASIC_OBJECT_METHODS( object ) \
26 { \
27 if ( object == NULL ) \
28 { \
29 std::cerr << "EXERCISE_BASIC_OBJECT_METHODS( with NULL object )" << std::endl; \
30 return EXIT_FAILURE; \
31 } \
32 object->Print( std::cout ); \
33 std::cout << "Name of Class = " << object->GetClassName() << std::endl; \
34 std::cout << "Name of Superclass = " << object->Superclass::GetClassName() << std::endl; \
35 }
36
37 /// try the itk command passed in, succeeding if catch an exception
38 #define TRY_EXPECT_ITK_EXCEPTION( command ) \
39 try \
40 { \
41 std::cout << "Trying " << #command << std::endl; \
42 command; \
43 std::cerr << "Failed to catch expected exception" << std::endl; \
44 return EXIT_FAILURE; \
45 } \
46 catch( itk::ExceptionObject & excp ) \
47 { \
48 std::cout << "Caught expected exception" << std::endl; \
49 std::cout << excp << std::endl; \
50 }
51
52 /// try the command passed in, succeeding if no exception
53 #define TRY_EXPECT_NO_ITK_EXCEPTION( command ) \
54 try \
55 { \
56 std::cout << "Trying " << #command << std::endl; \
57 command; \
58 } \
59 catch( itk::ExceptionObject & excp ) \
60 { \
61 std::cerr << excp << std::endl; \
62 return EXIT_FAILURE; \
63 }
64
65 /// test itk set/get
66 #define TEST_ITK_SET_GET( variable, command ) \
67 if( variable.GetPointer() != command ) \
68 { \
69 std::cerr << "Error in " << #command << std::endl; \
70 std::cerr << "Expected " << variable.GetPointer() << std::endl; \
71 std::cerr << "but got " << command << std::endl; \
72 return EXIT_FAILURE; \
73 }
74
75 /// test itk set/get
76 #define TEST_ITK_SET_GET_VALUE( variable, command ) \
77 if( variable != command ) \
78 { \
79 std::cerr << "Error in " << #command << std::endl; \
80 std::cerr << "Expected " << variable << std::endl; \
81 std::cerr << "but got " << command << std::endl; \
82 return EXIT_FAILURE; \
83 }
84
85 /// test object by calling Set on the variable with false, true, 0, 1, On, Off
86 #define TEST_SET_GET_BOOLEAN( object, variable ) \
87 object->Set##variable( false ); \
88 object->Set##variable( true ); \
89 if( object->Get##variable() != 1 ) \
90 { \
91 std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \
92 return EXIT_FAILURE; \
93 } \
94 object->Set##variable( false ); \
95 if( object->Get##variable() != 0 ) \
96 { \
97 std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \
98 return EXIT_FAILURE; \
99 } \
100 object->variable##On(); \
101 if( object->Get##variable() != 1 ) \
102 { \
103 std::cerr << "Error in On/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \
104 return EXIT_FAILURE; \
105 } \
106 object->variable##Off(); \
107 if( object->Get##variable() != 0 ) \
108 { \
109 std::cerr << "Error in Off/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \
110 return EXIT_FAILURE; \
111 }
112
113 /// test an integer variable on the object by setting it to input value using Set, and
114 /// testing it via the Get
115 #define TEST_SET_GET_INT( object, variable, value ) \
116 { \
117 object->Set##variable( value ); \
118 if( object->Get##variable() != value ) \
119 { \
120 std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
121 return EXIT_FAILURE; \
122 } \
123 }
124
125 /// Test an integer variable on object over the range, calls test set get in
126 /// with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max,
127 /// max + epsilon, where first and last test should report errors
128 /// epsilon defined as 1
129 #define TEST_SET_GET_INT_RANGE( object, variable, min, max ) \
130 { \
131 int epsilon = 1; \
132 int val = min - epsilon; \
133 TEST_SET_GET_INT( object, variable, val); \
134 val = min; \
135 TEST_SET_GET_INT( object, variable, val); \
136 val = min + epsilon; \
137 TEST_SET_GET_INT( object, variable, val); \
138 val = (min + max) / 2; \
139 TEST_SET_GET_INT( object, variable, val); \
140 val = max - epsilon; \
141 TEST_SET_GET_INT( object, variable, val); \
142 val = max; \
143 TEST_SET_GET_INT( object, variable, val); \
144 val = max + epsilon; \
145 TEST_SET_GET_INT( object, variable, val); \
146 }
147
148 /// test an integer variable on the object by setting it to a random value up
149 /// to max using Set, and testing it via the Get
150 #define TEST_SET_GET_INT_RANDOM( object, variable, max ) \
151 { \
152 int val = (int)(vtkMath::Random() * max); \
153 object->Set##variable( val ); \
154 if( object->Get##variable() != val ) \
155 { \
156 std::cerr << "Error in Set/Get"#variable << " using random value " << val << std::endl; \
157 return EXIT_FAILURE; \
158 } \
159 }
160
161 /// test a double variable on the object by setting it to input value using Set, and
162 /// testing it via the Get
163 #define TEST_SET_GET_DOUBLE( object, variable, value ) \
164 { \
165 object->Set##variable( value ); \
166 if( object->Get##variable() != value ) \
167 { \
168 std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
169 return EXIT_FAILURE; \
170 } \
171 }
172
173 /// Test a double variable on object over the range, calls test set get in
174 /// with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max,
175 /// max + epsilon, where first and last test should report errors
176 /// epsilon set to 1.0
177 #define TEST_SET_GET_DOUBLE_RANGE( object, variable, min, max ) \
178 { \
179 double epsilon = 1.0; \
180 double val = min - epsilon; \
181 TEST_SET_GET_DOUBLE( object, variable, val); \
182 val = min; \
183 TEST_SET_GET_DOUBLE( object, variable, val); \
184 val = min + epsilon; \
185 TEST_SET_GET_DOUBLE( object, variable, val); \
186 val = (min + max) / 2.0; \
187 TEST_SET_GET_DOUBLE( object, variable, val); \
188 val = max - epsilon; \
189 TEST_SET_GET_DOUBLE( object, variable, val); \
190 val = max; \
191 TEST_SET_GET_DOUBLE( object, variable, val); \
192 val = max + epsilon; \
193 TEST_SET_GET_DOUBLE( object, variable, val); \
194 }
195
196 /// test an integer variable on the object by setting it to a random value up
197 /// to max using Set, and testing it via the Get
198 #define TEST_SET_GET_DOUBLE_RANDOM( object, variable, max ) \
199 { \
200 double val = vtkMath::Random() * max; \
201 object->Set##variable( val ); \
202 if( object->Get##variable() != val ) \
203 { \
204 std::cerr << "Error in Set/Get"#variable << ", using random value " << val << std::endl; \
205 return EXIT_FAILURE; \
206 } \
207 }
208
209 /// test a vector variable on the object by setting it to a the values x, y, z
210 /// passed in using Set, and testing it via the Get
211 #define TEST_SET_GET_VECTOR3_DOUBLE( object, variable, x, y, z ) \
212 { \
213 object->Set##variable( x, y, z ); \
214 double *val = object->Get##variable(); \
215 if( val == NULL || val[0] != x || val[1] != y || val[2] != z ) \
216 { \
217 std::cerr << "Error in Set/Get"#variable << std::endl; \
218 return EXIT_FAILURE; \
219 } \
220 }
221
222 /// Test a double vector variable on object over the range, calls test set get in
223 /// with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max,
224 /// max + epsilon, where first and last test should report errors. For now all
225 /// three elements are set to the same thing each time.
226 /// epsilon set to 1.0
227 #define TEST_SET_GET_VECTOR3_DOUBLE_RANGE( object, variable, min, max ) \
228 { \
229 double epsilon = 1.0; \
230 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min - epsilon, min - epsilon, min - epsilon); \
231 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min, min, min); \
232 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min + epsilon, min + epsilon, min + epsilon); \
233 double half = (min+max/2.0); \
234 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, half, half, half); \
235 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max - epsilon, max - epsilon, max - epsilon); \
236 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max, max, max); \
237 TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max + epsilon, max + epsilon, max + epsilon); \
238 }
239
240 /// test a vector variable on the object by setting all it's elements to the same random value up
241 /// to max using Set, and testing it via the Get
242 #define TEST_SET_GET_VECTOR3_DOUBLE_RANDOM( object, variable, max ) \
243 { \
244 double x = vtkMath::Random() * max; \
245 double y = vtkMath::Random() * max; \
246 double z = vtkMath::Random() * max; \
247 object->Set##variable( x, y, z ); \
248 double *val = object->Get##variable(); \
249 if( val == NULL || val[0] != x || val[1] != y || val[2] != z ) \
250 { \
251 std::cerr << "Error in Set/Get"#variable << " with " << x << ", " << y << ", " << z << std::endl; \
252 return EXIT_FAILURE; \
253 } \
254 }
255
256 /// test a string variable on the object by calling Set/Get
257 #define TEST_SET_GET_STRING( object, variable ) \
258 { \
259 const char * originalStringPointer = object->Get##variable(); \
260 std::string originalString; \
261 if( originalStringPointer != NULL ) \
262 { \
263 originalString = originalStringPointer; \
264 } \
265 object->Set##variable( "testing with a const char"); \
266 if( strcmp(object->Get##variable(), "testing with a const char") != 0) \
267 { \
268 std::cerr << "Error in Set/Get"#variable << " with a string literal" << std::endl; \
269 return EXIT_FAILURE; \
270 } \
271 std::string string1 = "testingIsGood"; \
272 object->Set##variable( string1.c_str() ); \
273 if( object->Get##variable() != string1 ) \
274 { \
275 std::cerr << "Error in Set/Get"#variable << std::endl; \
276 return EXIT_FAILURE; \
277 } \
278 std::string string2 = "moreTestingIsBetter"; \
279 object->Set##variable( string2.c_str() ); \
280 if( object->Get##variable() != string2 ) \
281 { \
282 std::cerr << "Error in Set/Get"#variable << std::endl; \
283 return EXIT_FAILURE; \
284 } \
285 if( originalStringPointer != NULL ) \
286 { \
287 object->Set##variable( originalString.c_str() ); \
288 } \
289 else \
290 { \
291 object->Set##variable( NULL ); \
292 } \
293 } \
294
295 /// Slicer Libs/MRML/vtkMRMLNode exercises
296 #define EXERCISE_BASIC_MRML_METHODS( className, node ) \
297 {\
298 vtkMRMLNode * newNode = node1->CreateNodeInstance(); \
299 if( newNode == NULL ) \
300 { \
301 std::cerr << "Error in CreateNodeInstance()" << std::endl; \
302 return EXIT_FAILURE; \
303 } \
304 newNode->Delete(); \
305 node->UpdateScene(NULL); \
306 vtkSmartPointer < className > node1 = vtkSmartPointer < className >::New(); \
307 node1->Copy(node); \
308 node->Reset(); \
309 int mod = node->StartModify(); \
310 std::string nodeTagName = node->GetNodeTagName(); \
311 std::cout << "Node Tag Name = " << nodeTagName << std::endl; \
312 std::string attributeName = std::string("attName"); \
313 std::string attributeValue = std::string("attValue"); \
314 node->SetAttribute( attributeName.c_str(), attributeValue.c_str() ); \
315 std::string attributeValue2 = node->GetAttribute( attributeName.c_str() ); \
316 if( attributeValue != attributeValue2 ) \
317 { \
318 std::cerr << "Error in Set/GetAttribute() " << std::endl; \
319 return EXIT_FAILURE; \
320 } \
321 node->EndModify(mod); \
322 TEST_SET_GET_BOOLEAN( node, HideFromEditors ); \
323 TEST_SET_GET_BOOLEAN( node, Selectable ); \
324 TEST_SET_GET_STRING( node, Description ); \
325 TEST_SET_GET_STRING( node, SceneRootDir ); \
326 TEST_SET_GET_STRING( node, Name ); \
327 node->UpdateID("newID"); \
328 if (strcmp(node->GetID(), "newID") != 0) \
329 { \
330 std::cerr << "Error in UpdateID()" << std::endl; \
331 return EXIT_FAILURE; \
332 } \
333 node->CopyID(node1); \
334 if (node->GetID() != node1->GetID()) \
335 { \
336 std::cerr << "Error in CopyID()" << std::endl; \
337 return EXIT_FAILURE; \
338 } \
339 TEST_SET_GET_STRING( node, SingletonTag ); \
340 TEST_SET_GET_BOOLEAN( node, ModifiedSinceRead ); \
341 TEST_SET_GET_BOOLEAN( node, SaveWithScene ); \
342 TEST_SET_GET_BOOLEAN( node, AddToScene ); \
343 TEST_SET_GET_BOOLEAN( node, DisableModifiedEvent); \
344 TEST_SET_GET_BOOLEAN( node, Selected ); \
345 node->Modified(); \
346 node->InvokePendingModifiedEvent(); \
347 node1->SetName("copywithsinglemodified"); \
348 node->CopyWithSingleModifiedEvent(node1); \
349 node1->SetName("copywithoutmodified"); \
350 node->CopyWithoutModifiedEvent(node1); \
351 node1->SetName("copywithscenewithsinglemodified"); \
352 node->CopyWithSceneWithSingleModifiedEvent(node1); \
353 node1->SetName("copywithscenewithoutmodified"); \
354 node->CopyWithSceneWithoutModifiedEvent(node1); \
355 vtkMRMLScene * scene = node->GetScene(); \
356 \
357 if( scene != NULL ) \
358 { \
359 std::cerr << "Error in GetScene() " << std::endl; \
360 return EXIT_FAILURE; \
361 } \
362 \
363 node->UpdateReferences(); \
364 node->UpdateReferenceID("oldID", "newID"); \
365 \
366 std::string stringToEncode = "Thou Shall Test !"; \
367 std::string stringURLEncoded = node1->URLEncodeString( stringToEncode.c_str() ); \
368 std::string stringDecoded = node1->URLDecodeString( stringURLEncoded.c_str() ); \
369 if( stringDecoded != stringToEncode ) \
370 { \
371 std::cerr << "Error in URLEncodeString/URLDecodeString() " << std::endl; \
372 return EXIT_FAILURE; \
373 } \
374 \
375 const char *atts[] = {"id", "vtkMRMLNodeTest1", "name", "MyName", "description", "Testing a mrml node", "hideFromEditors", "false", "selectable", "true", "selected", "true", NULL}; \
376 node->ReadXMLAttributes(atts); \
377 if (strcmp(node->GetID(), "vtkMRMLNodeTest1") != 0) \
378 { \
379 std::cerr << "Error in ReadXMLAttributes! id should be vtkMRMLNodeTest1, but is " << node->GetID() << std::endl; \
380 return EXIT_FAILURE; \
381 } \
382 node->WriteXML(std::cout, 0); \
383 std::cout << std::endl; \
384 }
385
386 /// For testing nodes in Libs/MRML that are transformable. Calls the basic
387 /// mrml methods macro first.
388 #define EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS( className, node ) \
389 { \
390 EXERCISE_BASIC_MRML_METHODS(className, node); \
391 vtkMRMLTransformNode *tnode2 = node->GetParentTransformNode(); \
392 if (tnode2 != NULL)\
393 {\
394 std::cerr << "ERROR: parent transform node is not null" << std::endl;\
395 return EXIT_FAILURE; \
396 }\
397 node1->SetAndObserveTransformNodeID(NULL);\
398 const char *node_tid = node1->GetTransformNodeID();\
399 if (node_tid != NULL) \
400 {\
401 std::cerr << "ERROR: with observing transform node id" << std::endl;\
402 return EXIT_FAILURE; \
403 }\
404 bool canApplyNonLinear = node->CanApplyNonLinearTransforms();\
405 std::cout << "Node can apply non linear transforms? " << (canApplyNonLinear == true ? "yes" : "no") << std::endl;\
406 }
407
408 /// For testing nodes in Libs/MRML that are storable. Calls the basic
409 /// transformable mrml methods macro first.
410 #include "vtkMRMLStorageNode.h"
411 #define EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ) \
412 { \
413 EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS(className, node ); \
414 if (node->GetNumberOfStorageNodes() != 0) \
415 { \
416 std::cerr << "Error in getting number of storage nodes." << std::endl; \
417 return EXIT_FAILURE; \
418 } \
419 node->SetAndObserveStorageNodeID("noid"); \
420 node->AddAndObserveStorageNodeID("badid"); \
421 node->SetAndObserveNthStorageNodeID(2, "nothing"); \
422 node->SetSlicerDataType("testing"); \
423 if (strcmp(node->GetSlicerDataType(), "testing") != 0) \
424 { \
425 std::cerr << "ERROR set/get slicer data type" << std::endl; \
426 return EXIT_FAILURE; \
427 } \
428 const char *snodeid = node->GetNthStorageNodeID(0); \
429 if (strcmp(snodeid, "noid") != 0) \
430 { \
431 std::cerr << "ERROR getting 0th storage node id, instead of noid got " << (snodeid == NULL ? "null" : snodeid) << std::endl; \
432 return EXIT_FAILURE; \
433 } \
434 vtkMRMLStorageNode *snode = node->GetNthStorageNode(0); \
435 if (snode != NULL) \
436 { \
437 std::cerr << "ERROR getting 0th storage node" << std::endl; \
438 return EXIT_FAILURE; \
439 } \
440 snode = node->CreateDefaultStorageNode(); \
441 if (snode == NULL) \
442 { \
443 std::cerr << "ERROR creating and getting default storage node" << std::endl; \
444 return EXIT_FAILURE; \
445 } \
446 snode->Delete(); \
447 vtkTagTable *tagtable = node->GetUserTagTable(); \
448 if (tagtable == NULL) \
449 { \
450 std::cerr << "ERROR getting tag table" << std::endl; \
451 return EXIT_FAILURE; \
452 } \
453 }
454
455 /// For testing nodes in Libs/MRML that are displayable. Calls the basic
456 /// transformable mrml methods macro first.
457 #define EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS( className, node ) \
458 { \
459 EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ); \
460 if (node->GetNumberOfDisplayNodes() != 0) \
461 { \
462 std::cerr << "Error in getting number of display nodes." << std::endl; \
463 return EXIT_FAILURE; \
464 } \
465 node->SetAndObserveDisplayNodeID("noid"); \
466 node->AddAndObserveDisplayNodeID("badid"); \
467 node->SetAndObserveNthDisplayNodeID(2, "nothing"); \
468 const char *dnodeid = node->GetNthDisplayNodeID(0); \
469 if (strcmp(dnodeid, "noid") != 0) \
470 { \
471 std::cerr << "ERROR getting 0th display node id, instead of noid got " << (dnodeid == NULL ? "null" : dnodeid) << std::endl; \
472 return EXIT_FAILURE; \
473 } \
474 vtkMRMLDisplayNode *dnode = node->GetNthDisplayNode(0); \
475 if (dnode != NULL) \
476 { \
477 std::cerr << "ERROR getting 0th display node" << std::endl; \
478 return EXIT_FAILURE; \
479 } \
480 vtkPolyData *pdata = node1->GetPolyData(); \
481 if (pdata != NULL) \
482 { \
483 std::cerr << "ERROR getting null polydata" << std::endl; \
484 return EXIT_FAILURE; \
485 } \
486 pdata = vtkPolyData::New(); \
487 node1->SetAndObservePolyData(pdata); \
488 if (node1->GetPolyData() != pdata) \
489 { \
490 std::cerr << "ERROR getting polydata" << std::endl; \
491 return EXIT_FAILURE; \
492 } \
493 pdata->Delete(); \
494 }
495
496 /// For testing nodes in Libs/MRML that are subclasses of the display node. Calls the basic
497 /// mrml methods macro first.
498 #define EXERCISE_BASIC_DISPLAY_MRML_METHODS( className, node ) \
499 { \
500 EXERCISE_BASIC_MRML_METHODS( className, node); \
501 if (node->GetPolyData() != NULL) \
502 { \
503 std::cout << "Warning: After "#className << " node created, polydata is not null" << std::endl; \
504 } \
505 if (node->GetImageData() != NULL) \
506 { \
507 std::cout << "Warning: After "#className << " node create, image data is not null" << std::endl; \
508 } \
509 vtkMRMLDisplayableNode *dnode = node->GetDisplayableNode(); \
510 if (dnode != NULL) \
511 { \
512 std::cerr << "Error getting null displayable node" << std::endl; \
513 return EXIT_FAILURE; \
514 } \
515 node->UpdatePolyDataPipeline(); \
516 node->UpdateImageDataPipeline(); \
517 node->SetAndObserveTextureImageData(NULL); \
518 if (node->GetTextureImageData() != NULL) \
519 { \
520 std::cerr << "Error getting null texture image data " << std::endl; \
521 return EXIT_FAILURE; \
522 } \
523 node->SetAndObserveColorNodeID(NULL); \
524 if (node->GetColorNodeID() != NULL) \
525 { \
526 std::cerr << "Error getting null color node id " << std::endl; \
527 return EXIT_FAILURE; \
528 } \
529 if (node->GetColorNode() != NULL) \
530 { \
531 std::cerr << "Error getting null color node " << std::endl; \
532 return EXIT_FAILURE; \
533 } \
534 node->SetActiveScalarName("testingScalar"); \
535 if (strcmp(node->GetActiveScalarName(), "testingScalar") != 0) \
536 { \
537 std::cerr << "Error getting active scalar name" << std::endl; \
538 return EXIT_FAILURE; \
539 } \
540 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node, Color, 0.0, 1.0); \
541 TEST_SET_GET_VECTOR3_DOUBLE_RANGE(node, SelectedColor, 0.0, 1.0); \
542 TEST_SET_GET_DOUBLE_RANGE(node, SelectedAmbient, 0.0, 1.0); \
543 TEST_SET_GET_DOUBLE_RANGE(node, SelectedSpecular, 0.0, 1.0); \
544 TEST_SET_GET_DOUBLE_RANGE(node, Opacity, 0.0, 1.0); \
545 TEST_SET_GET_DOUBLE_RANGE(node, Ambient, 0.0, 1.0); \
546 TEST_SET_GET_DOUBLE_RANGE(node, Diffuse, 0.0, 1.0); \
547 TEST_SET_GET_DOUBLE_RANGE(node, Specular, 0.0, 1.0); \
548 TEST_SET_GET_DOUBLE_RANGE(node, Power, 0.0, 1.0); \
549 TEST_SET_GET_BOOLEAN(node, Visibility); \
550 TEST_SET_GET_BOOLEAN(node, Clipping); \
551 TEST_SET_GET_BOOLEAN(node, SliceIntersectionVisibility); \
552 TEST_SET_GET_BOOLEAN(node, BackfaceCulling); \
553 TEST_SET_GET_BOOLEAN(node, ScalarVisibility); \
554 TEST_SET_GET_BOOLEAN(node, VectorVisibility); \
555 TEST_SET_GET_BOOLEAN(node, TensorVisibility); \
556 TEST_SET_GET_BOOLEAN(node, AutoScalarRange); \
557 double range[2] = {-10, 10}; \
558 node->SetScalarRange(range); \
559 double *getrange = node->GetScalarRange(); \
560 if (getrange == NULL || getrange[0] != range[0] || getrange[1] != range[1]) \
561 { \
562 std::cerr << "ERROR getting range" << std::endl; \
563 return EXIT_FAILURE; \
564 } \
565 }
566
567 #include <vtkStringArray.h>
568
569 /// For testing nodes in Libs/MRML that are subclasses of the storage node. Calls the basic
570 /// mrml methods macro first.
571 #define EXERCISE_BASIC_STORAGE_MRML_METHODS( className, node ) \
572 { \
573 EXERCISE_BASIC_MRML_METHODS(className, node); \
574 node->ReadData(NULL); \
575 node->WriteData(NULL); \
576 node->StageReadData(NULL); \
577 node->StageWriteData(NULL); \
578 TEST_SET_GET_STRING(node, FileName); \
579 const char *f0 = node->GetNthFileName(0); \
580 std::cout << "Filename 0 = " << (f0 == NULL ? "NULL" : f0) << std::endl; \
581 TEST_SET_GET_BOOLEAN(node, UseCompression); \
582 TEST_SET_GET_STRING(node, URI); \
583 vtkURIHandler *handler = vtkURIHandler::New(); \
584 node->SetURIHandler(NULL); \
585 if (node->GetURIHandler() != NULL) \
586 { \
587 std::cerr << "ERROR getting null uri handler" << std::endl; \
588 return EXIT_FAILURE; \
589 } \
590 node->SetURIHandler(handler); \
591 if (node->GetURIHandler() == NULL) \
592 { \
593 std::cerr << "ERROR getting not null uri handler" << std::endl; \
594 return EXIT_FAILURE; \
595 } \
596 node->SetURIHandler(NULL); \
597 handler->Delete(); \
598 TEST_SET_GET_INT_RANGE(node, ReadState, 0, 5); \
599 const char *rstate = node->GetReadStateAsString(); \
600 std::cout << "Read state, after int test = " << rstate << std::endl; \
601 node->SetReadStatePending(); \
602 rstate = node->GetReadStateAsString(); \
603 std::cout << "Read state, Pending = " << rstate << std::endl; \
604 node->SetReadStateIdle(); \
605 rstate = node->GetReadStateAsString(); \
606 std::cout << "Read state, Idle = " << rstate << std::endl; \
607 node->SetReadStateScheduled(); \
608 rstate = node->GetReadStateAsString(); \
609 std::cout << "Read state, Scheduled = " << rstate << std::endl; \
610 node->SetReadStateTransferring(); \
611 rstate = node->GetReadStateAsString(); \
612 std::cout << "Read state, Transferring = " << rstate << std::endl; \
613 node->SetReadStateTransferDone(); \
614 rstate = node->GetReadStateAsString(); \
615 std::cout << "Read state, TransfrerDone = " << rstate << std::endl; \
616 node->SetReadStateCancelled(); \
617 rstate = node->GetReadStateAsString(); \
618 std::cout << "Read state, Cancelled = " << rstate << std::endl; \
619 \
620 TEST_SET_GET_INT_RANGE(node, WriteState, 0, 5); \
621 const char *wstate = node->GetWriteStateAsString(); \
622 std::cout << "Write state, after int test = " << wstate << std::endl; \
623 node->SetWriteStatePending(); \
624 wstate = node->GetWriteStateAsString(); \
625 std::cout << "Write state, Pending = " << wstate << std::endl; \
626 node->SetWriteStateIdle(); \
627 wstate = node->GetWriteStateAsString(); \
628 std::cout << "Write state, Idle = " << wstate << std::endl; \
629 node->SetWriteStateScheduled(); \
630 wstate = node->GetWriteStateAsString(); \
631 std::cout << "Write state, Scheduled = " << wstate << std::endl; \
632 node->SetWriteStateTransferring(); \
633 wstate = node->GetWriteStateAsString(); \
634 std::cout << "Write state, Transferring = " << wstate << std::endl; \
635 node->SetWriteStateTransferDone(); \
636 wstate = node->GetWriteStateAsString(); \
637 std::cout << "Write state, TransfrerDone = " << wstate << std::endl; \
638 node->SetWriteStateCancelled(); \
639 wstate = node->GetWriteStateAsString(); \
640 std::cout << "Write state, Cancelled = " << wstate << std::endl; \
641 \
642 std::string fullName = node->GetFullNameFromFileName(); \
643 std::cout << "fullName = " << fullName.c_str() << std::endl; \
644 std::string fullName0 = node->GetFullNameFromNthFileName(0); \
645 std::cout << "fullName0 = " << fullName0.c_str() << std::endl; \
646 \
647 vtkStringArray *types = node->GetSupportedWriteFileTypes(); \
648 std::cout << "Supported write types:" << std::endl; \
649 for (vtkIdType i = 0; i < types->GetNumberOfValues(); i++) \
650 { \
651 std::cout << "\t" << types->GetValue(i).c_str() << std::endl; \
652 } \
653 int sup = node->SupportedFileType(NULL); \
654 std::cout << "Filename or uri supported? " << sup << std::endl; \
655 sup = node->SupportedFileType("testing.vtk"); \
656 std::cout << ".vtk supported? " << sup << std::endl; \
657 sup = node->SupportedFileType("testing.nrrd"); \
658 std::cout << ".nrrd supported? " << sup << std::endl; \
659 sup = node->SupportedFileType("testing.mgz"); \
660 std::cout << ".mgz supported? " << sup << std::endl; \
661 \
662 TEST_SET_GET_STRING(node, WriteFileFormat); \
663 node->AddFileName("testing.txt"); \
664 std::cout << "Number of file names = " << node->GetNumberOfFileNames() << std::endl; \
665 int check = node->FileNameIsInList("testing.txt");\
666 if (check != 1) \
667 { \
668 std::cerr << "ERROR: file name not in list!" << std::endl; \
669 return EXIT_FAILURE; \
670 } \
671 node->ResetNthFileName(0, "moretesting.txt"); \
672 node->ResetNthFileName(100, "notinlist.txt"); \
673 node->ResetNthFileName(0, NULL); \
674 check = node->FileNameIsInList("notinlist"); \
675 if (check != 0) \
676 { \
677 std::cerr << "ERROR: bad file is in list!" << std::endl; \
678 return EXIT_FAILURE; \
679 } \
680 node->ResetFileNameList(); \
681 if (node->GetNumberOfFileNames() != 0) \
682 { \
683 std::cerr << "ERROR: " << node->GetNumberOfFileNames() << " files left in list after reset!" << std::endl; \
684 return EXIT_FAILURE; \
685 } \
686 \
687 node->ResetURIList(); \
688 std::cout << "Number of uri's after resetting list = " << node->GetNumberOfURIs() << std::endl; \
689 node->AddURI("http://www.nowhere.com/filename.txt"); \
690 if ( node->GetNumberOfURIs() != 1) \
691 { \
692 std::cerr << "Error adding one uri, number of uris is incorrect: " << node->GetNumberOfURIs()<< std::endl; \
693 return EXIT_FAILURE; \
694 } \
695 const char *uri = node->GetNthURI(0); \
696 if (uri == NULL || strcmp(uri, "http://www.nowhere.com/filename.txt") != 0) \
697 { \
698 std::cerr << "0th URI " << uri << " is incorrect." << std::endl; \
699 return EXIT_FAILURE; \
700 } \
701 node->ResetNthURI(0, "http://www.nowhere.com/newfilename.txt"); \
702 node->ResetNthURI(100, "ftp://not.in.list"); \
703 node->ResetNthURI(100, NULL); \
704 const char *dataDirName = "/testing/a/directory"; \
705 node->SetDataDirectory(dataDirName); \
706 node->SetFileName("/tmp/file.txt"); \
707 node->SetDataDirectory(dataDirName); \
708 const char *uriPrefix = "http://www.somewhere.com/"; \
709 node->SetURIPrefix(uriPrefix); \
710 \
711 const char *defaultExt = node->GetDefaultWriteFileExtension(); \
712 std::cout << "Default write extension = " << (defaultExt == NULL ? "null" : defaultExt) << std::endl; \
713 \
714 std::cout << "Is null file path relative? " << node->IsFilePathRelative(NULL) << std::endl; \
715 std::cout << "Is absolute file path relative? " << node->IsFilePathRelative("/spl/tmp/file.txt") << std::endl; \
716 std::cout << "Is relative file path relative? " << node->IsFilePathRelative("tmp/file.txt") << std::endl; \
717 }
718
719 #include "vtkMatrix4x4.h"
720 /// For testing nodes in Libs/MRML that are transform nodes. Calls the basic
721 /// storable mrml methods macro first.
722 #define EXERCISE_BASIC_TRANSFORM_MRML_METHODS( className, node ) \
723 { \
724 EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ); \
725 std::cout << "IsLinear = " << node->IsLinear()<< std:: endl; \
726 vtkSmartPointer<vtkGeneralTransform> g = vtkSmartPointer<vtkGeneralTransform>::New(); \
727 g = node->GetTransformToParent(); \
728 if (g == NULL) \
729 { \
730 std::cout << "Warning: transform node has a null transform to parent" << std::endl; \
731 } \
732 std::cout << "IsTransformToWorldLinear = " << node->IsTransformToWorldLinear() << std::endl; \
733 vtkSmartPointer < className > t = vtkSmartPointer < className >::New(); \
734 std::cout << "IsTransformToNodeLinear = " << node->IsTransformToNodeLinear(t) << std::endl; \
735 node->GetTransformToWorld(g); \
736 node->GetTransformToNode(t, g); \
737 vtkSmartPointer<vtkMatrix4x4> m = vtkSmartPointer<vtkMatrix4x4>::New(); \
738 int retval = node->GetMatrixTransformToWorld(m); \
739 if (retval == 0) \
740 { \
741 std::cout << "Warning: can't get matrix transform to world." << std::endl; \
742 } \
743 retval = node->GetMatrixTransformToNode(t, m); \
744 if (retval == 0) \
745 { \
746 std::cout << "Warning: can't get matrix transform to node." << std::endl; \
747 } \
748 std::cout << "IsTransformNodeMyParent = " << node->IsTransformNodeMyParent(t) << std::endl; \
749 std::cout << "IsTransformNodeMyChild = " << node->IsTransformNodeMyChild(t) << std::endl; \
750 }
751
752 #endif
753
754 // --------------------------------------------------------------------------
755 // The ctkFail() macro print the line it's invoking from and an associated message
756 //
757 #define ctkFail(MSG) \
758 std::cerr << "line " << __LINE__ << " - " << MSG << std::endl;
759
760 // --------------------------------------------------------------------------
761 // The ctkVerify2() macro behaves exactly like ctkVerify(), except that it outputs a verbose
762 // message when condition is false.
763 //
764 #define ctkVerify2(CONDITION, MSG) \
765 if (!(CONDITION)) \
766 { \
767 ctkFail("Assert(" << #CONDITION \
768 << ") " << MSG); \
769 return EXIT_FAILURE; \
770 }
771
772 // --------------------------------------------------------------------------
773 // The ctkVerify() macro checks whether the condition is true or not.
774 // If it is true, execution continues.
775 //
776 #define ctkVerify(CONDITION) \
777 ctkVerify2(CONDITION, "")
778
779 // --------------------------------------------------------------------------
780 // The ctkCompare macro compares an actual value to an expected value using the equals operator.
781 // If actual and expected are identical, execution continues.
782 #define ctkCompare(ACTUAL_VALUE, EXPECTED_VALUE) \
783 if (ACTUAL_VALUE != EXPECTED_VALUE) \
784 { \
785 ctkFail("Compare failed (" << #ACTUAL_VALUE << "!=" \
786 << #EXPECTED_VALUE << ")" << std::endl \
787 << " Current:" << ACTUAL_VALUE << std::endl \
788 << " Expected:"<< EXPECTED_VALUE); \
789 return EXIT_FAILURE; \
790 }
791
792 // --------------------------------------------------------------------------
793 #define ctkExerciseMethod(OBJECT, SETTER, GETTER, VALUE_TO_SET, EXPECTED_VALUE) \
794 (OBJECT)->SETTER(VALUE_TO_SET); \
795 ctkCompare((OBJECT)->GETTER(), EXPECTED_VALUE)

  Subversion  TortoiseSVN  ViewVC