File: TestMediaStorage.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 (110 lines) | stat: -rw-r--r-- 3,274 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
/*=========================================================================

  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 "gdcmMediaStorage.h"
#include "gdcmFile.h"
#include "gdcmDataElement.h"

int TestMediaStorage(int argc, char *argv[])
{
  (void)argc;
  (void)argv;
  gdcm::MediaStorage ms;
  if( !ms.IsUndefined() )
    {
    std::cerr << "ms.IsUndefined" << std::endl;
    return 1;
    }
  ms = gdcm::MediaStorage::SecondaryCaptureImageStorage;
  if( ms != gdcm::MediaStorage::SecondaryCaptureImageStorage )
    {
    std::cerr << "SecondaryCaptureImageStorage" << std::endl;
    return 1;
    }
  ms.GuessFromModality( "MR" );
  if( ms != gdcm::MediaStorage::MRImageStorage )
    {
    std::cerr << "MRImageStorage" << std::endl;
    return 1;
    }
  ms.GuessFromModality( "MR" , 3 );
  if( ms != gdcm::MediaStorage::EnhancedMRImageStorage )
    {
    std::cerr << "EnhancedMRImageStorage" << std::endl;
    return 1;
    }
  //checks *MSStrings[] and MSModalityTypes[] length
  gdcm::MediaStorage::MSType mst;
  for ( mst = gdcm::MediaStorage::MediaStorageDirectoryStorage; mst < gdcm::MediaStorage::MS_END; mst = (gdcm::MediaStorage::MSType)(mst + 1) )
    {
    if ( gdcm::MediaStorage::GetMSString(mst) == nullptr )
      {
      std::cerr << "GetMSString" << std::endl;
      return 1;
      }
    }
  mst = gdcm::MediaStorage::MS_END;
  if ( gdcm::MediaStorage::GetMSString(mst) != nullptr )
    {
    std::cerr << "2: GetMSString" << std::endl;
    return 1;
    }
  gdcm::MediaStorage ms2;
  if ( ms2.GetModality() )
    {
    return 1;
    }

  // MediaStorage is really poorly implemented. We need to add a test to avoid dev shooting themself in the foot.
  unsigned int nMSType = gdcm::MediaStorage::GetNumberOfMSType();
  unsigned int nMSString = gdcm::MediaStorage::GetNumberOfMSString();
  unsigned int nMSMod = gdcm::MediaStorage::GetNumberOfModality();
  if( nMSType != nMSString || nMSType != nMSMod )
    {
    std::cerr << "you are shooting yourself in the foot, dear.: " << nMSType << "," << nMSString << "," << nMSMod << std::endl;
    return 1;
    }

{
  gdcm::File f;
  gdcm::DataSet &ds = f.GetDataSet();
  gdcm::DataElement de;
  de.SetTag( gdcm::Tag(0x8,0x16) );
  ds.Insert( de );
  gdcm::MediaStorage ms3;
  ms3.SetFromFile( f );
  if( ms3 != gdcm::MediaStorage::SecondaryCaptureImageStorage )
    {
    std::cerr << "SecondaryCaptureImageStorage" << std::endl;
    return 1;
    }
}
{
  gdcm::File f;
  gdcm::FileMetaInformation &fmi  = f.GetHeader();
  gdcm::DataElement de;
  de.SetTag( gdcm::Tag(0x2,0x2) );
  // de.SetByteValue( "", 0 );
  fmi.Insert( de );
  gdcm::MediaStorage ms4;
  ms4.SetFromFile( f );
  if( ms4 != gdcm::MediaStorage::SecondaryCaptureImageStorage )
    {
    std::cerr << "SecondaryCaptureImageStorage" << std::endl;
    return 1;
    }
}
  

  return 0;
}