File: TestCodeString.cxx

package info (click to toggle)
gdcm 3.0.24-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,856 kB
  • sloc: cpp: 203,722; ansic: 76,471; xml: 48,131; python: 3,473; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 97
file content (156 lines) | stat: -rw-r--r-- 3,728 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
/*=========================================================================

  Program: GDCM (Grassroots DICOM). A DICOM library

  Copyright (c) 2006-2011 Mathieu Malaterre
  All rights reserved.
  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "gdcmCodeString.h"
#include "gdcmAttribute.h"

#include <iostream>

int TestCodeString(int , char *[])
{
    {
    gdcm::Attribute<0x0008,0x0008> at3;
    static const gdcm::CSComp values[] = {"DERIVED","SECONDARY"};
    at3.SetValues( values, 2, true );
    if( at3.GetNumberOfValues() != 2 ) return 1;
    }

  const char fn1[] = "IMG01";

  gdcm::Attribute< 0x0004, 0x1500 > at;
  at.SetNumberOfValues( 1 );
  at.SetValue( fn1 );

  unsigned int n = at.GetNumberOfValues();
  if( n != 1 ) return 1;

    {
    const char fn2[] = "SUBDIR\\IMG01";
    at.SetNumberOfValues( 2 );
    at.SetValue( fn2 );
    n = at.GetNumberOfValues();
    if( n != 2 ) return 1;
    }

  const char fn3[] = "SUBDIR1\\SUBDIR2\\IMG01 ";
    {
    gdcm::DataElement de( at.GetTag() );
    de.SetByteValue( fn3, (uint32_t)strlen(fn3) );

    at.SetFromDataElement( de );
    n = at.GetNumberOfValues();
    //std::cout << n << std::endl;
    if( n != 3 ) return 1;

    for( unsigned int i = 0; i < n; ++i)
      {
      gdcm::CodeString cs = at.GetValue( i );
      if( !cs.IsValid() )
        {
        std::cerr << "Invalid CS: " << cs << std::endl;
        return 1;
        }
      }
    }

  const char fn4[] = "SUBDIR1\\SUBDIR2\\IMG01";
    {
    std::string copy = fn4;
    if( copy.size() % 2 )
      {
      copy.push_back( ' ' );
      }
    gdcm::DataElement de( at.GetTag() );
    de.SetByteValue( copy.c_str(), (uint32_t)copy.size() );

    at.SetFromDataElement( de );
    n = at.GetNumberOfValues();
    //std::cout << n << std::endl;
    if( n != 3 ) return 1;

    for( unsigned int i = 0; i < n; ++i)
      {
      gdcm::CodeString cs = at.GetValue( i );
      if( !cs.IsValid() )
        {
        std::cerr << "Invalid CS: " << cs << std::endl;
        return 1;
        }
      }
    }

  const char fn5[] = R"(SUBDIR1\SUBDIR2\LONGSUBDIR\IMG01)";
    {
    std::string copy = fn5;
    if( copy.size() % 2 )
      {
      copy.push_back( ' ' );
      }

    gdcm::DataElement de( at.GetTag() );
    de.SetByteValue( copy.c_str(), (uint32_t)copy.size() );

    at.SetFromDataElement( de );
    n = at.GetNumberOfValues();
    //std::cout << n << std::endl;
    if( n != 4 ) return 1;

    for( unsigned int i = 0; i < n; ++i)
      {
      gdcm::CodeString cs = at.GetValue( i );
      if( !cs.IsValid() )
        {
        std::cerr << "Invalid CS: " << cs << std::endl;
        return 1;
        }
      }

    if( strlen(at.GetValue(2) ) < 8 )
      {
      return 1;
      }
    }

    {
    gdcm::CodeString cs0 = " SUB\\DIR ";
    if(  cs0.IsValid() ) return 1;

    gdcm::CodeString cs1 = " SUBDIR ";
    if( !cs1.IsValid() ) return 1;

    gdcm::CodeString cs2 = " SUBDIR_0123456789 ";
    // len == 19 => invalid
    if( cs2.IsValid() ) return 1;

    gdcm::CodeString cs3 = " IMG_0123456789 ";
    if( !cs3.IsValid() ) return 1;

    // cstor should trim on the fly:
    gdcm::CodeString cs4 = "  IMG_0123456789  ";
    if( !cs4.IsValid() ) return 1;

    if( !(cs3 == cs4) ) return 1;

    if( cs3 != cs4 ) return 1;

    gdcm::CodeString cs5 = "IMG";
    if( cs5 != "IMG ")
      return 1;


    // Begin ugly internals.

    }

  return 0;
}