File: TestDICOMValue.cxx

package info (click to toggle)
vtk-dicom 0.8.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,176 kB
  • sloc: cpp: 113,811; python: 2,041; makefile: 43; tcl: 10
file content (622 lines) | stat: -rw-r--r-- 21,739 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
#include "vtkDICOMValue.h"
#include "vtkDICOMSequence.h"
#include "vtkDICOMItem.h"

#include <sstream>

#include <string.h>
#include <stdlib.h>

// macro for performing tests
#define TestAssert(t) \
if (!(t)) \
{ \
  cout << exename << ": Assertion Failed: " << #t << "\n"; \
  cout << __FILE__ << ":" << __LINE__ << "\n"; \
  cout.flush(); \
  rval |= 1; \
}

int TestDICOMValue(int argc, char *argv[])
{
  int rval = 0;
  const char *exename = (argc > 0 ? argv[0] : "TestDICOMValue");

  // remove path portion of exename
  const char *cp = exename + strlen(exename);
  while (cp != exename && cp[-1] != '\\' && cp[-1] != '/') { --cp; }
  exename = cp;

  { // test empty value
  vtkDICOMValue v;
  TestAssert(!v.IsValid());
  const char *sp = "hello";
  v = vtkDICOMValue(vtkDICOMVR::SH, sp, strlen(sp));
  TestAssert(v.IsValid());
  v.Clear();
  TestAssert(!v.IsValid());
  }

  { // test VR and VL
  const char *sp = "HELLO\\THERE";
  vtkDICOMValue v = vtkDICOMValue(vtkDICOMVR::CS, sp, strlen(sp));
  TestAssert(v.GetVR() == vtkDICOMVR::CS);
  TestAssert(v.GetVL() == 12); // padded to even
  }

  { // test constructors and number of values
  vtkDICOMValue v;
  // backslash-separated values
  const char *sp = "HELLO\\THERE";
  v = vtkDICOMValue(vtkDICOMVR::CS, sp, strlen(sp));
  TestAssert(v.GetNumberOfValues() == 2);
  // numerical values
  static const double dbl[3] = { 1.0, 1.5, 1e200 };
  v = vtkDICOMValue(vtkDICOMVR::FD, dbl, 3);
  TestAssert(v.GetNumberOfValues() == 3);
  TestAssert(v.GetVL() == 24);
  TestAssert(memcmp(v.GetDoubleData(), dbl, 24) == 0);
  // numerical values converted to strings
  static const short ssi[5] = { 1, 3, -2, 60, 13 };
  v = vtkDICOMValue(vtkDICOMVR::IS, ssi, 5);
  TestAssert(v.GetNumberOfValues() == 5);
  TestAssert(v.GetVL() == 12);
  TestAssert(strcmp(v.GetCharData(), "1\\3\\-2\\60\\13") == 0);
  // string values converted to numbers
  static const char *flts = "1\\2.5\\-1e-5\\-4.23460975";
  static const float flt[4] = { 1.0f, 2.5f, -1e-5f, -4.23460975f };
  v = vtkDICOMValue(vtkDICOMVR::FL, flts, strlen(flts));
  TestAssert(v.GetNumberOfValues() == 4);
  TestAssert(v.GetVL() == 16);
  TestAssert(memcmp(v.GetFloatData(), flt, 16) == 0);
  // string values converted to tags
  static const char *tagstring = "(ff00,0123)\\(0FA2,0001)";
  v = vtkDICOMValue(vtkDICOMVR::AT, tagstring, strlen(tagstring));
  TestAssert(v.GetNumberOfValues() == 2);
  TestAssert(v.GetVL() == 8);
  TestAssert(v.GetTag(0) == vtkDICOMTag(0xff00,0x0123));
  TestAssert(v.GetTag(1) == vtkDICOMTag(0x0fa2,0x0001));
  // tags constructed from enums
  v = vtkDICOMValue(vtkDICOMVR::AT, DC::FrameTimeVector);
  TestAssert(v.GetNumberOfValues() == 1);
  TestAssert(v.GetVL() == 4);
  TestAssert(v.AsTag() == vtkDICOMTag(0x0018,0x1065));
  // these text VRs should always report 1 value
  const char *hp = "he\\llo";
  size_t sl = strlen(hp);
  v = vtkDICOMValue(vtkDICOMVR::ST, hp, sl);
  TestAssert(v.GetNumberOfValues() == 1);
  TestAssert(v.GetVL() == 6);
  TestAssert(strcmp(v.GetCharData(), hp) == 0);
  v = vtkDICOMValue(vtkDICOMVR::LT, hp, sl);
  TestAssert(v.GetNumberOfValues() == 1);
  TestAssert(v.GetVL() == 6);
  TestAssert(strcmp(v.GetCharData(), hp) == 0);
  v = vtkDICOMValue(vtkDICOMVR::UT, hp, sl);
  TestAssert(v.GetNumberOfValues() == 1);
  TestAssert(v.GetVL() == 6);
  TestAssert(strcmp(v.GetCharData(), hp) == 0);
  // these data VRs should always report 1 value
  static const unsigned char uci[6] = { 1, 255, 12, 8, 9, 12 };
  v = vtkDICOMValue(vtkDICOMVR::UN, uci, 6);
  TestAssert(v.GetNumberOfValues() == 6);
  TestAssert(v.GetVL() == 6);
  TestAssert(memcmp(v.GetUnsignedCharData(), uci, 6) == 0);
  v = vtkDICOMValue(vtkDICOMVR::OB, uci, 6);
  TestAssert(v.GetNumberOfValues() == 6);
  TestAssert(v.GetVL() == 6);
  TestAssert(memcmp(v.GetUnsignedCharData(), uci, 6) == 0);
  static const short data[5] = { 1, 3, -2, 60, 13 };
  v = vtkDICOMValue(vtkDICOMVR::OW, data, 5);
  TestAssert(v.GetNumberOfValues() == 5);
  TestAssert(v.GetVL() == 10);
  TestAssert(memcmp(v.GetShortData(), data, 10) == 0);
  TestAssert(memcmp(v.GetUnsignedShortData(), data, 10) == 0);
  static const float fdata[5] = { 1.0f, 3.5f, -2.0f, 6.0f, 0.13f };
  v = vtkDICOMValue(vtkDICOMVR::OF, fdata, 5);
  TestAssert(v.GetNumberOfValues() == 5);
  TestAssert(v.GetVL() == 20);
  TestAssert(memcmp(v.GetFloatData(), fdata, 20) == 0);
  }

  { // test getting numerical values
  vtkDICOMValue v;
  static const float flt1[2] = { 1.0f, 2.5f };
  float flt2[2];
  short shrt[2];
  // store floats as doubles with VR=FD
  v = vtkDICOMValue(vtkDICOMVR::FD, flt1, 2);
  v.GetValues(flt2, 2, 0);
  TestAssert(flt1[0] == flt2[0] && flt1[1] == flt2[1]);
  flt2[0] = flt2[1] = 0;
  v.GetValues(&flt2[0], 1, 0);
  v.GetValues(&flt2[1], 1, 1);
  TestAssert(flt1[0] == flt2[0] && flt1[1] == flt2[1]);
  v.GetValues(shrt, 2, 0);
  TestAssert(static_cast<int>(flt1[0]) == shrt[0]);
  TestAssert(static_cast<int>(flt1[1]) == shrt[1]);
  // store floats as decimal strings with VR=DS
  v = vtkDICOMValue(vtkDICOMVR::DS, flt1, 2);
  v.GetValues(flt2, 2, 0);
  TestAssert(flt1[0] == flt2[0] && flt1[1] == flt2[1]);
  flt2[0] = flt2[1] = 0;
  v.GetValues(&flt2[0], 1, 0);
  v.GetValues(&flt2[1], 1, 1);
  TestAssert(flt1[0] == flt2[0] && flt1[1] == flt2[1]);
  v.GetValues(shrt, 2, 0);
  TestAssert(static_cast<int>(flt1[0]) == shrt[0]);
  TestAssert(static_cast<int>(flt1[1]) == shrt[1]);
  // store floats as integer strings with VR=IS
  v = vtkDICOMValue(vtkDICOMVR::IS, flt1, 2);
  v.GetValues(flt2, 2, 0);
  TestAssert(static_cast<float>(static_cast<int>(flt1[0])) == flt2[0] &&
             static_cast<float>(static_cast<int>(flt1[1])) == flt2[1]);
  flt2[0] = flt2[1] = 0;
  v.GetValues(&flt2[0], 1, 0);
  v.GetValues(&flt2[1], 1, 1);
  TestAssert(static_cast<float>(static_cast<int>(flt1[0])) == flt2[0] &&
             static_cast<float>(static_cast<int>(flt1[1])) == flt2[1]);
  v.GetValues(shrt, 2, 0);
  TestAssert(static_cast<int>(flt1[0]) == shrt[0]);
  TestAssert(static_cast<int>(flt1[1]) == shrt[1]);
  }

  { // test getting text values
  vtkDICOMValue v;
  std::string sa[2];
  static const float flt1[2] = { 1.0f, 2.5f };
  // store floats as doubles with VR=FD
  v = vtkDICOMValue(vtkDICOMVR::FD, flt1, 2);
  v.GetValues(sa, 2, 0);
  TestAssert(sa[0] == "1.0" && sa[1] == "2.5");
  // store floats as text with VR=DS
  sa[0] = "";
  sa[1] = "";
  v = vtkDICOMValue(vtkDICOMVR::DS, flt1, 2);
  v.GetValues(sa, 2, 0);
  TestAssert(sa[0] == "1" && sa[1] == "2.5");
  // store floats as text with VR=IS
  sa[0] = "";
  sa[1] = "";
  v = vtkDICOMValue(vtkDICOMVR::IS, flt1, 2);
  v.GetValues(sa, 2, 0);
  TestAssert(sa[0] == "1" && sa[1] == "2");
  // get just the first value
  sa[0] = "";
  sa[1] = "";
  v = vtkDICOMValue(vtkDICOMVR::IS, flt1, 2);
  v.GetValues(sa, 1, 0);
  TestAssert(sa[0] == "1" && sa[1] == "");
  // get just the second value
  sa[0] = "";
  sa[1] = "";
  v = vtkDICOMValue(vtkDICOMVR::IS, flt1, 2);
  v.GetValues(sa, 1, 1);
  TestAssert(sa[0] == "2" && sa[1] == "");
  }

  { // test allowed range of decimal strings
  vtkDICOMValue v;
  static const double dbl[4] = { 1e200, -1e200, 1e-200, -1e-200 };
  static const char *dblt = "9.999999999e+99\\-9.999999999e+99\\0\\0";
  v = vtkDICOMValue(vtkDICOMVR::DS, dbl, 4);
  TestAssert(strcmp(v.GetCharData(), dblt) == 0);
  }

  { // test equality
  vtkDICOMValue v, u;
  v = vtkDICOMValue(vtkDICOMVR::CS, "hello");
  u = vtkDICOMValue(vtkDICOMVR::CS, "hello");
  TestAssert(u == v);
  v = vtkDICOMValue(vtkDICOMVR::CS, "hello");
  u = vtkDICOMValue(vtkDICOMVR::DS, "1.234");
  TestAssert(u != v);
  v = vtkDICOMValue(vtkDICOMVR::CS, "hello");
  u = vtkDICOMValue(vtkDICOMVR::CS, "there");
  TestAssert(u != v);
  v = vtkDICOMValue(vtkDICOMVR::CS, "hello");
  u = vtkDICOMValue(vtkDICOMVR::SH, "hello");
  TestAssert(u != v);
  short data[5] = { 1, 3, -2, 60, 13 };
  v = vtkDICOMValue(vtkDICOMVR::SS, data, 5);
  u = vtkDICOMValue(vtkDICOMVR::SS, data, 5);
  TestAssert(u == v);
  data[2] = 0;
  u = vtkDICOMValue(vtkDICOMVR::SS, data, 5);
  TestAssert(u != v);
  }

  { // test stream operator
  std::stringstream os;
  vtkDICOMValue v;
  static const float flt1[2] = { 1.0f, 2.5f };
  // print the invalid value
  os << v;
  TestAssert(os.str() == "empty[0]");
  os.str("");
  // store floats as doubles with VR=FD
  v = vtkDICOMValue(vtkDICOMVR::FD, flt1, 2);
  os << v;
  TestAssert(os.str() == "1.0,2.5");
  os.str("");
  // store floats as decimal strings with VR=DS
  v = vtkDICOMValue(vtkDICOMVR::DS, flt1, 2);
  os << v;
  TestAssert(os.str() == "1\\2.5");
  os.str("");
  // store floats as float data with VR=OF
  v = vtkDICOMValue(vtkDICOMVR::OF, flt1, 2);
  os << v;
  TestAssert(os.str() == "floats[2]");
  os.str("");
  // store attribute tags
  static const unsigned short tags[4] = { 0x0002, 0x0020, 0xF001, 0x0001 };
  v = vtkDICOMValue(vtkDICOMVR::AT, tags, 4);
  os << v;
  TestAssert(os.str() == "(0002,0020),(F001,0001)");
  os.str("");
  }

  { // test multiplexing
  vtkDICOMValue v;
  vtkDICOMValue *vptr = v.AllocateMultiplexData(vtkDICOMVR::DS, 3);
  vptr[0] = vtkDICOMValue(vtkDICOMVR::DS, "1.3234");
  vptr[1] = vtkDICOMValue(vtkDICOMVR::DS, "1.4");
  vptr[2] = vtkDICOMValue(vtkDICOMVR::DS, "-1e-5");
  const vtkDICOMValue *vptr2 = v.GetMultiplexData();
  TestAssert(strcmp(vptr2[0].GetCharData(),"1.3234") == 0);
  TestAssert(strcmp(vptr2[1].GetCharData(),"1.4 ") == 0); // padded to even
  TestAssert(strcmp(vptr2[2].GetCharData(),"-1e-5 ") == 0); // padded to even
  vtkDICOMValue u;
  vtkDICOMValue *uptr = u.AllocateMultiplexData(vtkDICOMVR::DS, 3);
  uptr[0] = vtkDICOMValue(vtkDICOMVR::DS, "1.3234");
  uptr[1] = vtkDICOMValue(vtkDICOMVR::DS, "1.4");
  uptr[2] = vtkDICOMValue(vtkDICOMVR::DS, "-1e-5");
  TestAssert(v == v);
  TestAssert(u == v);
  uptr[1] = vtkDICOMValue(vtkDICOMVR::DS, "1");
  TestAssert(u != v);
  vptr[1] = vtkDICOMValue(vtkDICOMVR::IS, "1");
  TestAssert(u != v);
  vptr[0] = uptr[0];
  vptr[1] = uptr[1];
  vptr[2] = uptr[2];
  TestAssert(u == v);
  u = v;
  TestAssert(u == v);
  }

  { // test AsString
  vtkDICOMValue v;
  v = vtkDICOMValue(vtkDICOMVR::US, "3\\2\\1");
  TestAssert(v.GetNumberOfValues() == 3);
  TestAssert(v.AsString() == "3\\2\\1");
  TestAssert(v.AsInt() == 3);
  v = vtkDICOMValue(vtkDICOMVR::IS, "3\\2\\1");
  TestAssert(v.GetNumberOfValues() == 3);
  TestAssert(v.AsString() == "3\\2\\1");
  TestAssert(v.AsInt() == 3);
  v = vtkDICOMValue(vtkDICOMVR::UT, "3\\2\\1");
  TestAssert(v.GetNumberOfValues() == 1);
  TestAssert(v.AsString() == "3\\2\\1");
  TestAssert(v.AsInt() == 0);
  }

  { // test AsUTF8String
  vtkDICOMValue v;
  std::string s;
  // backslash interpreted as backslash
  v = vtkDICOMValue(
    vtkDICOMVR::LO, vtkDICOMCharacterSet("ISO 2022 IR 13\\ISO 2022 IR 87"),
    "\xd4\xcf\xc0\xde^\xc0\xdb\xb3\\\x1b$B;3ED\x1b(J^\x1b$BB@O:\x1b(J");
  s = "\xef\xbe\x94\xef\xbe\x8f\xef\xbe\x80\xef\xbe\x9e^\xef\xbe\x80\xef\xbe\x9b\xef\xbd\xb3\\\xe5\xb1\xb1\xe7\x94\xb0^\xe5\xa4\xaa\xe9\x83\x8e";
  TestAssert(v.AsUTF8String() == s);
  // backslash interpreted according to character set
  v = vtkDICOMValue(
    vtkDICOMVR::LT, vtkDICOMCharacterSet("ISO 2022 IR 13\\ISO 2022 IR 87"),
    "\xd4\xcf\xc0\xde^\xc0\xdb\xb3\\\x1b$B;3ED\x1b(J^\x1b$BB@O:\x1b(J");
  s = "\xef\xbe\x94\xef\xbe\x8f\xef\xbe\x80\xef\xbe\x9e^\xef\xbe\x80\xef\xbe\x9b\xef\xbd\xb3\xc2\xa5\xe5\xb1\xb1\xe7\x94\xb0^\xe5\xa4\xaa\xe9\x83\x8e";
  TestAssert(v.AsUTF8String() == s);
  }

  { // test Matches for query matching
  vtkDICOMValue v;
  vtkDICOMValue u;

  // test comparison of null values
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO");
  TestAssert(!v.Matches(u));
  TestAssert(u.Matches(v));

  // test comparison of empty values
  v = vtkDICOMValue(vtkDICOMVR::CS, "");
  TestAssert(v.GetVL() == 0);
  TestAssert(u.Matches(v));
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "");
  TestAssert(v.Matches(u));

  // test comparison of identical values
  v = vtkDICOMValue(vtkDICOMVR::CS, "HELLO");
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HEL");
  TestAssert(!v.Matches(u));
  v = vtkDICOMValue(vtkDICOMVR::US, 10);
  u = vtkDICOMValue(vtkDICOMVR::US, 10);
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::US, 9);
  TestAssert(!v.Matches(u));

  // test wildcards
  v = vtkDICOMValue(vtkDICOMVR::CS, "HELLO");
  u = vtkDICOMValue(vtkDICOMVR::CS, "*");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "*LO");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "H?LLO");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "H*?LLO");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "H?LO");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "H*P");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELL*");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO*");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELL?");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO?");
  TestAssert(!v.Matches(u));

  // test multiple values in the query
  v = vtkDICOMValue(vtkDICOMVR::UI, "10.3000.11.6");
  u = vtkDICOMValue(vtkDICOMVR::UI, "10.3000.11.6\\10.3000.10.6");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::UI, "10.3000.10.6\\10.3000.11.6");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::UI, "10.3000.11.7\\10.3000.10.6");
  TestAssert(!v.Matches(u));

  // test multiple values in the value
  v = vtkDICOMValue(vtkDICOMVR::CS, "HELLO\\THERE");
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO\\THERE");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "THERE\\HELLO");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO\\THER");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "HELLO");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "THERE");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "ELLO\\THER");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::CS, "ELLO");
  TestAssert(!v.Matches(u));

  // test string-encoded numbers
  v = vtkDICOMValue(vtkDICOMVR::IS, "5\\6\\10");
  u = vtkDICOMValue(vtkDICOMVR::IS, "5\\6\\10");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::IS, "5\\6");
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::IS, "6\\10");
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::IS, "5\\10");
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::IS, "6");
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::IS, "10\\5");
  TestAssert(!v.Matches(u));
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::IS, "6\\5");
  TestAssert(!v.Matches(u));
  TestAssert(!v.Matches(u));

  // test backslash on ST, LT, UT
  v = vtkDICOMValue(vtkDICOMVR::UT, "HELLO\\THERE");
  u = vtkDICOMValue(vtkDICOMVR::UT, "HELLO\\THERE");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::UT, "HELLO");
  TestAssert(!v.Matches(u));

  // test matches for binary data
  static const short vals[3] = { 10, 11, 12 };
  static const short vals2[2] = { 10, 11 };
  static const short vals3[2] = { 10, 12 };
  static const short vals4[2] = { 11, 10 };
  v = vtkDICOMValue(vtkDICOMVR::SS, vals, 3);
  u = vtkDICOMValue(vtkDICOMVR::SS, 10);
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::SS, 11);
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::SS, 12);
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::SS, 13);
  TestAssert(!v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::SS, vals2, 2);
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::SS, vals3, 2);
  TestAssert(v.Matches(u));
  TestAssert(!u.Matches(v));
  u = vtkDICOMValue(vtkDICOMVR::SS, vals4, 2);
  TestAssert(!v.Matches(u));
  TestAssert(!u.Matches(v));

  // test matches for binary data OW
  v = vtkDICOMValue(vtkDICOMVR::OW, vals, 3);
  u = vtkDICOMValue(vtkDICOMVR::OW, vals, 3);
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::OW, vals, 1);
  TestAssert(!v.Matches(u));
  TestAssert(!v.Matches(u));

  // test date
  v = vtkDICOMValue(vtkDICOMVR::DA, "20070125");
  u = vtkDICOMValue(vtkDICOMVR::DA, "20070124");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::DA, "2007");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::DA, "20070124-");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::DA, "20070124-20080124");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::DA, "20070126-20080124");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::DA, "-20070124");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::DA, "-20070126");
  TestAssert(v.Matches(u));

  // test time
  v = vtkDICOMValue(vtkDICOMVR::TM, "114501.00");
  u = vtkDICOMValue(vtkDICOMVR::TM, "114501");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::TM, "11");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::TM, "1145-");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::TM, "1146");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::TM, "-1146");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::TM, "0800-1146");
  TestAssert(v.Matches(u));

  // test sequences
  vtkDICOMSequence su(1);
  vtkDICOMItem item;
  item.Set(DC::ImageType, "ORIGINAL");
  item.Set(DC::StudyDate, "20070124-20080124");
  item.Set(DC::StudyTime, "");
  su.SetItem(0, item);
  u = su;
  vtkDICOMSequence sv;
  v = sv;
  TestAssert(!v.Matches(u));
  vtkDICOMItem item1;
  item1.Set(DC::ImageType, "DERIVED\\PRIMARY\\AXIAL");
  item1.Set(DC::StudyDate, "20070513");
  item1.Set(DC::StudyTime, "083045.210000");
  sv.AddItem(item1);
  v = sv;
  TestAssert(!v.Matches(u));
  vtkDICOMItem item2;
  item2.Set(DC::ImageType, "ORIGINAL\\PRIMARY\\AXIAL");
  item2.Set(DC::StudyDate, "20070513");
  item2.Set(DC::StudyTime, "083045.210000");
  sv.AddItem(item2);
  v = sv;
  TestAssert(v.Matches(u));
  vtkDICOMValue ve;
  vtkDICOMSequence su2;
  u = su2;
  TestAssert(v.Matches(u));
  TestAssert(ve.Matches(u));
  su2.AddItem(vtkDICOMItem());
  u = su2;
  TestAssert(v.Matches(u));
  TestAssert(ve.Matches(u));

  // test comparisons of encoded strings
  v = vtkDICOMValue(vtkDICOMVR::SH, vtkDICOMCharacterSet::ISO_IR_100,
    "p\373ddle");
  u = vtkDICOMValue(vtkDICOMVR::SH, vtkDICOMCharacterSet::ISO_IR_100,
    "puddle");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::SH, vtkDICOMCharacterSet::ISO_IR_6,
    "p?ddle");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::SH, vtkDICOMCharacterSet::ISO_IR_192,
    "p\303\273ddle");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::SH, vtkDICOMCharacterSet::ISO_IR_100,
    "puddle");
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::SH, vtkDICOMCharacterSet::ISO_IR_6,
    "p?ddle");
  TestAssert(v.Matches(u));

  // test comparisons of names
  const char *names[] = {
    "Gobbi", "Gobbi^David", "Gobbi^^Gregory^", "Gobbi^David^Gregory",
    "Gobb", "Gobbi^Kevin"
  };
  v = vtkDICOMValue(vtkDICOMVR::PN, names[3]);
  u = vtkDICOMValue(vtkDICOMVR::PN, names[0]);
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::PN, names[1]);
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::PN, names[2]);
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::PN, names[3]);
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::PN, names[4]);
  TestAssert(!v.Matches(u));
  u = vtkDICOMValue(vtkDICOMVR::PN, names[5]);
  TestAssert(!v.Matches(u));

  // test comparison with character sets
  v = vtkDICOMValue(
    vtkDICOMVR::LO, vtkDICOMCharacterSet("ISO 2022 IR 13\\ISO 2022 IR 87"),
    "\xd4\xcf\xc0\xde^\xc0\xdb\xb3\\\x1b$B;3ED\x1b(J^\x1b$BB@O:\x1b(J");
  u = vtkDICOMValue(
    vtkDICOMVR::LO, vtkDICOMCharacterSet("ISO_IR 13"),
    "\xd4\xcf\xc0\xde^\xc0\xdb\xb3");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(
    vtkDICOMVR::LO, vtkDICOMCharacterSet("ISO 2022 IR 13\\ISO 2022 IR 87"),
    "\x1b$B;3ED\x1b(J^\x1b$BB@O:\x1b(J");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(
    vtkDICOMVR::LO, vtkDICOMCharacterSet("ISO_IR 192"),
    "\xef\xbe\x94\xef\xbe\x8f\xef\xbe\x80\xef\xbe\x9e^\xef\xbe\x80\xef\xbe\x9b\xef\xbd\xb3");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(
    vtkDICOMVR::LO, vtkDICOMCharacterSet("ISO_IR 192"),
    "\xe5\xb1\xb1\xe7\x94\xb0^\xe5\xa4\xaa\xe9\x83\x8e");

  // test comparison with character sets specifically for PN
  v = vtkDICOMValue(
    vtkDICOMVR::PN, vtkDICOMCharacterSet("ISO 2022 IR 13\\ISO 2022 IR 87"),
    "\xd4\xcf\xc0\xde^\xc0\xdb\xb3\\\x1b$B;3ED\x1b(J^\x1b$BB@O:\x1b(J");
  u = vtkDICOMValue(
    vtkDICOMVR::PN, vtkDICOMCharacterSet("ISO_IR 13"),
    "\xd4\xcf\xc0\xde^\xc0\xdb\xb3");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(
    vtkDICOMVR::PN, vtkDICOMCharacterSet("ISO 2022 IR 13\\ISO 2022 IR 87"),
    "\x1b$B;3ED\x1b(J^\x1b$BB@O:\x1b(J");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(
    vtkDICOMVR::PN, vtkDICOMCharacterSet("ISO_IR 192"),
    "\xef\xbe\x94\xef\xbe\x8f\xef\xbe\x80\xef\xbe\x9e^\xef\xbe\x80\xef\xbe\x9b\xef\xbd\xb3");
  TestAssert(v.Matches(u));
  u = vtkDICOMValue(
    vtkDICOMVR::PN, vtkDICOMCharacterSet("ISO_IR 192"),
    "\xe5\xb1\xb1\xe7\x94\xb0^\xe5\xa4\xaa\xe9\x83\x8e");
  TestAssert(v.Matches(u));
  }

  return rval;
}

#ifdef VTK_DICOM_SEPARATE_TESTS
int main(int argc, char *argv[])
{
  return TestDICOMValue(argc, argv);
}
#endif