]> Creatis software - gdcm.git/blobdiff - Testing/TestDataEntry.cxx
* Add a RefCounter object that is deleted only when it's reference count is
[gdcm.git] / Testing / TestDataEntry.cxx
index b9b2e54203a7d22dbccee0e1c0bf63c26185165f..7c2977c65753c98222f4ae888491c78df3577c0b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: TestDataEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/10/18 08:35:46 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/10/20 15:24:05 $
+  Version:   $Revision: 1.5 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -33,14 +33,14 @@ unsigned long nbvalue = 5;
 /**
   * \brief Test the DataEntry object
   */  
-int TestDataEntry(int argc, char *argv[])
+int TestDataEntry(int , char *[])
 {
-   unsigned int error = 0;
+   unsigned int i;
    gdcm::DictEntry *dict;
    gdcm::DataEntry *entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("US");
 
@@ -53,8 +53,10 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetValueCount() != 1 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: 1" << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -66,8 +68,10 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetValueCount() != 2 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: 2" << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -79,18 +83,20 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetValueCount() != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: 0" << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("LT");
 
@@ -102,16 +108,20 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetLength() != strlen(data) + strlen(data)%2 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Size of string is incorrect" << std::endl;
-      delete dict;
+                << "   Size of string is incorrect" << std::endl
+                << "   Found: " << entry->GetLength() 
+                << " - Must be: " << strlen(data) + strlen(data)%2 << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
@@ -119,37 +129,40 @@ int TestDataEntry(int argc, char *argv[])
    {
       std::cout << "   Failed" << std::endl
                 << "   Content of bin area is incorrect" << std::endl;
-      delete dict;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << data << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != svalue[i] )
       {
          std::cout << "   Failed" << std::endl
                    << "   Content of entry's values is incorrect : id " << i << std::endl
-                   << "   Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl;
-         delete dict;
+                   << "   Found " << entry->GetValue(i)
+                   << " - Must be " << svalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("US");
 
@@ -162,34 +175,42 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetLength() != nbvalue*sizeof(uint16_t) )
    {
       std::cout << "   Failed" << std::endl
-                << "   BinArea length is incorrect" << std::endl;
-      delete dict;
+                << "   BinArea length is incorrect" << std::endl
+                << "   Found: " << entry->GetLength()
+                << " - Must be: " << nbvalue*sizeof(uint16_t) << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << data << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount()
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != svalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << svalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -204,37 +225,43 @@ int TestDataEntry(int argc, char *argv[])
    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << data << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != svalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << svalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("UL");
 
@@ -247,35 +274,42 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetLength() != nbvalue*sizeof(uint32_t) )
    {
       std::cout << "   Failed" << std::endl
-                << "   BinArea length is incorrect" << std::endl;
-      delete dict;
+                << "   BinArea length is incorrect" << std::endl
+                << "   Found: " << entry->GetLength()
+                << " - Must be: " << nbvalue*sizeof(uint32_t) << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      std::cout<<"#"<<entry->GetString()<<"#"<<" / "<<"#"<<data<<"#"<<std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << data << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != lvalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << lvalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -290,37 +324,43 @@ int TestDataEntry(int argc, char *argv[])
    if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str() 
+                << " - Must be: " << data << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != lvalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << lvalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("FL");
 
@@ -333,34 +373,42 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetLength() != nbvalue*sizeof(float) )
    {
       std::cout << "   Failed" << std::endl
-                << "   BinArea length is incorrect" << std::endl;
-      delete dict;
+                << "   BinArea length is incorrect" << std::endl
+                << "   Found: " << entry->GetLength() 
+                << " - Must be: " << nbvalue*sizeof(float) << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << fdata << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != fvalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << fvalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -375,37 +423,43 @@ int TestDataEntry(int argc, char *argv[])
    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << fdata << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != fvalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << fvalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------
-   dict = new gdcm::DictEntry(0x0000,0x0000);
+   dict = gdcm::DictEntry::New(0x0000,0x0000);
    entry = new gdcm::DataEntry(dict);
    dict->SetVR("FD");
 
@@ -418,34 +472,42 @@ int TestDataEntry(int argc, char *argv[])
    if( entry->GetLength() != nbvalue*sizeof(double) )
    {
       std::cout << "   Failed" << std::endl
-                << "   BinArea length is incorrect" << std::endl;
-      delete dict;
+                << "   BinArea length is incorrect" << std::endl
+                << "   Found: " << entry->GetLength()
+                << " - Must be: " << nbvalue*sizeof(double) << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << fdata << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != dvalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << dvalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
@@ -460,33 +522,39 @@ int TestDataEntry(int argc, char *argv[])
    if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 )
    {
       std::cout << "   Failed" << std::endl
-                << "   Content of string is incorrect" << std::endl;
-      delete dict;
+                << "   Content of string is incorrect" << std::endl
+                << "   Found: " << entry->GetString().c_str()
+                << " - Must be: " << fdata << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
    if( entry->GetValueCount() != nbvalue )
    {
       std::cout << "   Failed" << std::endl
-                << "   Number of content values is incorrect" << std::endl;
-      delete dict;
+                << "   Number of content values is incorrect" << std::endl
+                << "   Found: " << entry->GetValueCount() 
+                << " - Must be: " << nbvalue << std::endl;
+      dict->Delete();
       delete entry;
       return(1);
    }
-   for(unsigned int i=0;i<entry->GetValueCount();i++)
+   for(i=0;i<entry->GetValueCount();i++)
    {
       if( entry->GetValue(i) != dvalue[i] )
       {
          std::cout << "   Failed" << std::endl
-                   << "   Content of entry's values is incorrect : id " << i << std::endl;
-         delete dict;
+                   << "   Content of entry's values is incorrect : id " << i << std::endl
+                   << "   Found: " << entry->GetValue(i)
+                   << " - Must be: " << dvalue[i] << std::endl;
+         dict->Delete();
          delete entry;
          return(1);
       }
    }
 
    std::cout << std::endl;
-   delete dict;
+   dict->Delete();
    delete entry;
 
    //------------------------------------------------------------------