Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkPointSetReader.h"
00019 #include "mitkPointSetWriter.h"
00020 #include "mitkStandardFileLocations.h"
00021 #include "mitkTestingMacros.h"
00022 #include <list>
00023 #include <fstream>
00024 #include <iostream>
00025 #include <string>
00026
00027 bool ChangeLocale(const std::string& locale)
00028 {
00029 try
00030 {
00031 MITK_TEST_OUTPUT(<< "\n** Changing locale from " << setlocale(LC_ALL, NULL) << " to '" << locale << "'");
00032 setlocale(LC_ALL, locale.c_str());
00033
00034 std::locale l( locale.c_str() );
00035 std::cin.imbue(l);
00036 std::cout.imbue(l);
00037
00038 return true;
00039
00040 }
00041 catch(...)
00042 {
00043 MITK_TEST_OUTPUT(<< "Could not activate locale" << locale << "\n");
00044 return false;
00045 }
00046 }
00047
00048 void ReaderLocaleTest(mitk::Point3D & refPoint)
00049 {
00050 MITK_TEST_OUTPUT(<< "---- Reader Test ---- ");
00051 mitk::StandardFileLocations::Pointer locator = mitk::StandardFileLocations::GetInstance();
00052 MITK_TEST_CONDITION_REQUIRED(locator.IsNotNull(),"Instantiating StandardFileLocations");
00053 std::string filename = locator->FindFile("pointSet.mps", "Core/Code/Testing/Data/");
00054
00055 mitk::PointSetReader::Pointer reader = mitk::PointSetReader::New();
00056 reader -> SetFileName(filename);
00057 reader -> Update();
00058 mitk::PointSet::Pointer pointSet = reader -> GetOutput();
00059
00060 mitk::Point3D point;
00061 if (pointSet->GetPointIfExists(0, &point))
00062 {
00063
00064 MITK_TEST_CONDITION_REQUIRED(fabs(refPoint[0] - point[0]) < 0.00001, "read x correct");
00065 MITK_TEST_CONDITION_REQUIRED(fabs(refPoint[1] - point[1]) < 0.00001, "read y correct");
00066 MITK_TEST_CONDITION_REQUIRED(fabs(refPoint[2] - point[2]) < 0.00001, "read z correct");
00067 }else
00068 {
00069 MITK_TEST_FAILED_MSG(<< "File "<< filename << " can not be read - test will not applied." );
00070 return;
00071 }
00072 }
00073
00074 void WriterLocaleTest(mitk::Point3D & refPoint)
00075 {
00076 MITK_TEST_OUTPUT(<< "---- Writer Test---- ");
00077
00078 mitk::PointSet::Pointer refPointSet = mitk::PointSet::New();
00079 refPointSet->SetPoint(0, refPoint);
00080
00081
00082 mitk::StandardFileLocations::Pointer locator = mitk::StandardFileLocations::GetInstance();
00083 MITK_TEST_CONDITION_REQUIRED(locator.IsNotNull(),"Instantiating StandardFileLocations");
00084 std::string filename = locator->FindFile("pointSet.mps", "Core/Code/Testing/Data/");
00085 std::string testFileName = "testPointSet.mps";
00086
00087
00088 mitk::PointSetWriter::Pointer writer = mitk::PointSetWriter::New();
00089 writer -> SetFileName(testFileName);
00090 writer -> SetInput(refPointSet);
00091 writer -> Write();
00092
00093
00094 std::ifstream refStream (filename.c_str());
00095 std::ifstream stream (testFileName.c_str());
00096
00097 MITK_TEST_CONDITION_REQUIRED(refStream,"Read reference point set");
00098 MITK_TEST_CONDITION_REQUIRED(stream,"Read point set");
00099
00100 std::string streamLine;
00101 std::string refStreamLine;
00102
00103 bool differ = false;
00104 if (stream.is_open() && refStream.is_open())
00105 {
00106 std::string streamLine;
00107 std::string refStreamLine;
00108 while(!stream.eof() && ! refStream.eof())
00109 {
00110 getline(stream, streamLine);
00111 getline(refStream, refStreamLine);
00112 if(streamLine.compare(refStreamLine) != 0)
00113 {
00114 differ = true;
00115 break;
00116 }
00117 }
00118 stream.close();
00119 refStream.close();
00120 }
00121 MITK_TEST_CONDITION_REQUIRED(!differ, "Write point set correct");
00122 }
00123
00124 int mitkPointSetLocaleTest(int , char* [])
00125 {
00126 MITK_TEST_BEGIN("PointSetLocaleTest");
00127
00128
00129 mitk::PointSet::Pointer refPointSet = mitk::PointSet::New();
00130 mitk::Point3D refPoint;
00131 refPoint[0] = 32.2946;
00132 refPoint[1] = -17.7359;
00133 refPoint[2] = 29.6502;
00134 refPointSet->SetPoint(0, refPoint);
00135
00136
00137 std::ofstream stream;
00138 std::locale previousLocale(stream.getloc());
00139
00140 typedef std::list<std::string> StringList;
00141 StringList alllocales;
00142 alllocales.push_back("de_DE");
00143 alllocales.push_back("de_DE.utf8");
00144 alllocales.push_back("de_DE.UTF-8");
00145 alllocales.push_back("de_DE@euro");
00146 alllocales.push_back("German_Germany");
00147
00148
00149
00150 #if defined (__APPLE__) || defined(MACOSX)
00151 alllocales.push_back("C");
00152 #endif
00153
00154 unsigned int numberOfTestedGermanLocales(0);
00155 for (StringList::iterator iter = alllocales.begin();
00156 iter != alllocales.end();
00157 ++iter)
00158 {
00159 if ( ChangeLocale(*iter) )
00160 {
00161 ++numberOfTestedGermanLocales;
00162 WriterLocaleTest(refPoint);
00163 ReaderLocaleTest(refPoint);
00164 }
00165 }
00166 MITK_TEST_CONDITION_REQUIRED( numberOfTestedGermanLocales > 0, "Verify that at least one German locale has been tested.");
00167 MITK_TEST_END();
00168 }
00169