]> Creatis software - gdcm.git/blobdiff - Testing/TestBuildUpDicomDir.cxx
Fix mistypings
[gdcm.git] / Testing / TestBuildUpDicomDir.cxx
index 1aa9cb6fcf95cc0873c0a785bd55a13bf68e8d97..0fa3cedaa65866fb833472151b1eb798883cc5b3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestBuildUpDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/19 13:15:36 $
-  Version:   $Revision: 1.6 $
+  Date:      $Date: 2008/09/15 15:49:21 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -39,13 +39,17 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    {
       std::cerr << "Usage: " << argv[0] << " dummy " << std::endl;
    }
-
-   gdcm::DicomDir *dcmdir;
+   
+ // GDCM_NAME_SPACE::Debug::DebugOn();
+   bool errorFound = false; 
+   GDCM_NAME_SPACE::DicomDir *dcmdir;
    std::string dirName;  
 
-   dcmdir = new gdcm::DicomDir();
+   dcmdir = GDCM_NAME_SPACE::DicomDir::New();
 
-   gdcm::DicomDirPatient *p1;
+   GDCM_NAME_SPACE::DicomDirPatient *p1;
+   
    // --- Forget these 4 lines :
    // just to improve test coverage.
    p1=dcmdir->GetFirstPatient();
@@ -60,7 +64,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    p1->SetEntryString("patientONE",0x0010, 0x0010);
    // fill here other patient characteristics
 
-   gdcm::DicomDirStudy *s11;
+   GDCM_NAME_SPACE::DicomDirStudy *s11;
    // --- Forget these 4 lines :
    // just to improve test coverage.
    s11=p1->GetFirstStudy();
@@ -73,20 +77,20 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    s11 = p1->NewStudy();  
    s11->SetEntryString("StudyDescrOne.One_",0x0008, 0x1030);
    // we know entry (0008,1060) is not yet created
-   s11->InsertEntryString("Dr Mabuse",     0x0008, 0x1060);
+   s11->InsertEntryString("Dr^Mabuse",     0x0008, 0x1060, "PN");
    // fill here other Study characteristics
 
-   gdcm::DicomDirStudy *s12 = p1->NewStudy();    
+   GDCM_NAME_SPACE::DicomDirStudy *s12 = p1->NewStudy();    
    s12->SetEntryString("StudyDescrOne.Two",0x0008, 0x1030);
-   s12->InsertEntryString("Dr Zorglub",    0x0008, 0x1060);
+   s12->InsertEntryString("Dr^Zorglub",    0x0008, 0x1060, "PN");
    // fill here other Study characteristics
 
-   gdcm::DicomDirStudy *s13 = p1->NewStudy();  
+   GDCM_NAME_SPACE::DicomDirStudy *s13 = p1->NewStudy();  
    s13->SetEntryString("StudyDescrOne.Tree",0x0008, 0x1030);
-   s13->InsertEntryString("Dr Follamour",   0x0008, 0x1060);
+   s13->InsertEntryString("Dr^Follamour",   0x0008, 0x1060, "PN");
    // fill here other Study characteristics
  
-   gdcm::DicomDirSerie *s111;
+   GDCM_NAME_SPACE::DicomDirSerie *s111;
    // --- Forget these 4 lines :
    // just to improve test coverage.
    s111=s11->GetFirstSerie();
@@ -100,7 +104,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    s111->SetEntryString("01-01-111", 0x0008, 0x0021);
    // fill here other Serie characteristics
 
-   gdcm::DicomDirImage *s1111;
+   GDCM_NAME_SPACE::DicomDirImage *s1111;
 
    // --- Forget these 4 lines :
    // just to improve test coverage.
@@ -113,56 +117,67 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    // Let's create and add a Image for this Serie
    s1111 = s111->NewImage();
    s1111->SetEntryString("imageFileName1111",0x0004,0x1500);
-
-   gdcm::DicomDirImage *s1112 = s111->NewImage();
+   GDCM_NAME_SPACE::DicomDirImage *s1112 = s111->NewImage();
    s1112->SetEntryString("imageFileName1112",0x0004,0x1500);
 
    // Create patient TWO
    // ------------------
-   gdcm::DicomDirPatient *p2 = dcmdir->NewPatient();
+   GDCM_NAME_SPACE::DicomDirPatient *p2 = dcmdir->NewPatient();
    p2->SetEntryString("patientTWO",0x0010, 0x0010); 
    // fill here other patient characteristics
     
-   gdcm::DicomDirStudy *s21 = p2->NewStudy();  
+   GDCM_NAME_SPACE::DicomDirStudy *s21 = p2->NewStudy();  
    s21->SetEntryString("StudyDescrTwo.One",0x0008, 0x1030);        
    // fill here other Study characteristics
 
-   gdcm::DicomDirSerie *s211 = s21->NewSerie();
+   GDCM_NAME_SPACE::DicomDirSerie *s211 = s21->NewSerie();
    s111->SetEntryString("01-01-211", 0x0008, 0x0021);
    // fill here other Serie characteristics
 
-   gdcm::DicomDirImage *s2111 = s211->NewImage();
+   GDCM_NAME_SPACE::DicomDirImage *s2111 = s211->NewImage();
    s2111->SetEntryString("imageFileName2111",0x0004,0x1500);
    // fill here other Image characteristics
 
-   gdcm::DicomDirImage *s2112 = s211->NewImage();
+   GDCM_NAME_SPACE::DicomDirImage *s2112 = s211->NewImage();
    s2112->SetEntryString("imageFileName1122",0x0004,0x1500);
    // fill here other Image characteristics
 
    // Create patient TREE
    // -------------------
-   gdcm::DicomDirPatient *p3 = dcmdir->NewPatient();
+   GDCM_NAME_SPACE::DicomDirPatient *p3 = dcmdir->NewPatient();
    p3->SetEntryString("patientTHREE",0x0010, 0x0010);
    // fill here other Patient characteristics
 
    // Add a new Serie/Image for a Patient's Study created a long time ago
    // -------------------------------------------------------------------
-   gdcm::DicomDirSerie *s131 = s13->NewSerie();
+   GDCM_NAME_SPACE::DicomDirSerie *s131 = s13->NewSerie();
    s111->SetEntryString("01-01-131", 0x0008, 0x0021);
    // fill here other Serie characteristics
 
-   gdcm::DicomDirImage *s1311 = s131->NewImage();
+   GDCM_NAME_SPACE::DicomDirImage *s1311 = s131->NewImage();
    s1311->SetEntryString("imageFileName1311",0x0004,0x1500);
    // fill here other Image characteristics
      
    // Print
    std::cout << "Test/BuildUpDicomDir: Test Print of patients\n";
    p1->Print();
-   std::cout << "Test/BuildUpDicomDir: -------------------\n";
+   std::cout << "Test/BuildUpDicomDir: end of P1-------------------\n";
    p2->Print();
-   std::cout << "Test/BuildUpDicomDir: -------------------\n";
+   std::cout << "Test/BuildUpDicomDir: end of P2-------------------\n";
    p3->Print();
+   std::cout << "Test/BuildUpDicomDir: end of P3-------------------\n";   
    std::cout << "Test/BuildUpDicomDir: Test Print of patients ended\n";
+   
+ // Let's loop on Patients.  
+   GDCM_NAME_SPACE::DicomDirPatient *p;
+   p=dcmdir->GetFirstPatient();
+   while (p) {
+      std::cout << "one more patient\n";
+      p->Print();
+      p=dcmdir->GetNextPatient();
+   }
+
   
    if( !dcmdir->IsReadable() )
    {
@@ -170,7 +185,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
                <<" is not readable"<<std::endl
                <<"          ...Failed"<<std::endl;
 
-      delete dcmdir;
+      dcmdir->Delete();
       return 1;
    }
 
@@ -183,10 +198,10 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    // Write it on disc
    dcmdir->Write("NewDICOMDIR");
 
-   delete dcmdir;
+   dcmdir->Delete();
 
    // Read the newly written DicomDir
-   gdcm::DicomDir *newDicomDir = new gdcm::DicomDir();
+   GDCM_NAME_SPACE::DicomDir *newDicomDir = GDCM_NAME_SPACE::DicomDir::New();
    newDicomDir->SetFileName("NewDICOMDIR");
    newDicomDir->Load( );
    if( !newDicomDir->IsReadable() )
@@ -195,10 +210,21 @@ int TestBuildUpDicomDir(int argc, char *argv[])
                <<" is not readable"<<std::endl
                <<"          ...Failed"<<std::endl;
 
-      delete newDicomDir;
+      newDicomDir->Delete();
       return 1;
    }
    // Check some value we are sure
+   
+   int numberOfPatients = newDicomDir->GetNumberOfPatients();
+   if (numberOfPatients != 3)
+   {
+      std::cout<<"  wrong GetNumberOfPatients() : " << newDicomDir->GetNumberOfPatients()
+               <<" (should be 3)" <<std::endl;
+
+      newDicomDir->Delete();
+      return 1;   
+   }
+   
    p1 = newDicomDir->GetFirstPatient();
    p2 = newDicomDir->GetNextPatient();
    p3 = newDicomDir->GetNextPatient();
@@ -207,7 +233,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
    {
       std::cout << "A patient is missing in written DicomDir"
           << std::endl;
-      delete newDicomDir;
+      newDicomDir->Delete();
       return 1;
    }
 
@@ -215,7 +241,6 @@ int TestBuildUpDicomDir(int argc, char *argv[])
              << "----------Final Check ---------------------" 
              <<std::endl;
  
-   bool errorFound = false; 
    std::string valueStuff;  
    for (;;) // exit on 'break'
    {
@@ -251,7 +276,9 @@ int TestBuildUpDicomDir(int argc, char *argv[])
                 << "]" << std::endl;
  
       valueStuff = s11->GetEntryString(0x0008, 0x1060);
-      if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Mabuse") )
+std::cout << "----------------length-----------------" << valueStuff.length() <<
+std::endl;     
+      if (!GDCM_NAME_SPACE::Util::DicomStringEqual(valueStuff, "Dr^Mabuse") )
       {
          std::cout << "2 : 0x0008,0x1060 [" 
                    << s11->GetEntryString(0x0008,0x1060)
@@ -259,7 +286,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
          errorFound = true;
          break;
       }
-      std::cout << "Pysician : [" 
+      std::cout << "Physician : [" 
                 << valueStuff
                 << "]" << std::endl;
       if ( (s12 = p1->GetNextStudy()) == 0 )
@@ -267,7 +294,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
          errorFound = true;
          break;
       }
-      if ( gdcm::Util::DicomStringEqual(s12->GetEntryString(0x0008,
+      if ( GDCM_NAME_SPACE::Util::DicomStringEqual(s12->GetEntryString(0x0008,
                                            0x1030),"StudyDescrOne.Two " ))
       {
          std::cout << "3 0x0008,0x1030 [" 
@@ -280,8 +307,8 @@ int TestBuildUpDicomDir(int argc, char *argv[])
                 << s12->GetEntryString(0x0008,0x1030)
                 << "]" << std::endl;
 
-      if ( gdcm::Util::DicomStringEqual(s12->GetEntryString(0x0008,
-                                           0x1060),"Dr Zorglub " ))
+      if ( GDCM_NAME_SPACE::Util::DicomStringEqual(s12->GetEntryString(0x0008,
+                                           0x1060),"Dr^Zorglub " ))
       {
          std::cout << "4 0x0008,0x1060 [" 
                    << s12->GetEntryString(0x0008,0x1060)
@@ -289,7 +316,8 @@ int TestBuildUpDicomDir(int argc, char *argv[])
          errorFound = true;
          break;
       }
-      std::cout << "Pysician : [" 
+   std::cout << "___________________________________" << std::endl;
+      std::cout << "Pysician Reading Study: [" 
                 << s12->GetEntryString(0x0008,0x1060)
                 << "]" << std::endl;
 
@@ -308,7 +336,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
                 << "]" << std::endl;
 
       valueStuff = s13->GetEntryString(0x0008, 0x1060);
-      if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Follamour") )
+      if (!GDCM_NAME_SPACE::Util::DicomStringEqual(valueStuff, "Dr^Follamour") )
       {
          std::cout << "5 0x0008,0x1060 [" 
                    << valueStuff
@@ -328,7 +356,7 @@ int TestBuildUpDicomDir(int argc, char *argv[])
       }
 
       valueStuff = s111->GetEntryString(0x0008, 0x0021);
-      if (!gdcm::Util::DicomStringEqual(valueStuff, "01-01-131") )
+      if (!GDCM_NAME_SPACE::Util::DicomStringEqual(valueStuff, "01-01-131") )
       {
          std::cout << "6 0x0008,0x0021 [" 
                    << valueStuff
@@ -357,14 +385,13 @@ int TestBuildUpDicomDir(int argc, char *argv[])
       break; // No error found. Stop looping
    }
 
-   delete newDicomDir;
    if ( errorFound )
    {
       std::cout << "MissWritting / MissReading " << std::endl;
-      std::cout<<std::flush;
-      return(1);
    }
 
    std::cout<<std::flush;
-   return 0;
+   newDicomDir->Delete();
+
+   return errorFound;
 }