#include <ctype.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#include "mitkLog.h"Go to the source code of this file.
Classes | |
| struct | functionMapEntry |
Typedefs | |
| typedef int(* | MainFuncPointer )(int, char *[]) |
Functions | |
| int | mitkSceneIOTest (int, char *[]) |
| char * | lowercase (const char *string) |
| int | main (int ac, char *av[]) |
Variables | |
| functionMapEntry | cmakeGeneratedFunctionMapEntries [] |
| typedef int(* MainFuncPointer)(int, char *[]) |
Definition at line 16 of file SceneSerializationTestDriver.cpp.
| char* lowercase | ( | const char * | string ) |
Definition at line 35 of file SceneSerializationTestDriver.cpp.
{
char *new_string, *p;
#ifdef __cplusplus
new_string = static_cast<char *>(malloc(sizeof(char) *
static_cast<size_t>(strlen(string) + 1)));
#else
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
#endif
if (!new_string)
{
return 0;
}
strcpy(new_string, string);
p = new_string;
while (*p != 0)
{
#ifdef __cplusplus
*p = static_cast<char>(tolower(*p));
#else
*p = (char)(tolower(*p));
#endif
++p;
}
return new_string;
}
| int main | ( | int | ac, |
| char * | av[] | ||
| ) |
Definition at line 65 of file SceneSerializationTestDriver.cpp.
References functionMapEntry::func, lowercase(), functionMapEntry::name, mitk::LoggingBackend::Register(), and mitk::LoggingBackend::Unregister().
{
int i, NumTests, testNum, partial_match;
char *arg, *test_name;
int count;
int testToRun = -1;
for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
{
}
NumTests = count;
/* If no test name was given */
/* process command line with user function. */
if (ac < 2)
{
/* Ask for a test. */
printf("Available tests:\n");
for (i =0; i < NumTests; ++i)
{
printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
}
printf("To run a test, enter the test number: ");
fflush(stdout);
testNum = 0;
if( scanf("%d", &testNum) != 1 )
{
printf("Couldn't parse that input as a number\n");
return -1;
}
if (testNum >= NumTests)
{
printf("%3d is an invalid test number.\n", testNum);
return -1;
}
testToRun = testNum;
ac--;
av++;
}
partial_match = 0;
arg = 0;
/* If partial match is requested. */
if(testToRun == -1 && ac > 1)
{
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
}
if (partial_match && ac < 3)
{
printf("-R needs an additional parameter.\n");
return -1;
}
if(testToRun == -1)
{
arg = lowercase(av[1 + partial_match]);
}
for (i =0; i < NumTests && testToRun == -1; ++i)
{
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
if (partial_match && strstr(test_name, arg) != NULL)
{
testToRun = i;
ac -=2;
av += 2;
}
else if (!partial_match && strcmp(test_name, arg) == 0)
{
testToRun = i;
ac--;
av++;
}
free(test_name);
}
if(arg)
{
free(arg);
}
if(testToRun != -1)
{
int result;
mitk::LoggingBackend::Register(); ;
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
mitk::LoggingBackend::Unregister();
return result;
}
/* Nothing was run, display the test names. */
printf("Available tests:\n");
for (i =0; i < NumTests; ++i)
{
printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
}
printf("Failed: %s is an invalid test name.\n", av[1]);
return -1;
}
| int mitkSceneIOTest | ( | int | , |
| char * | [] | ||
| ) |
Definition at line 213 of file mitkSceneIOTest.cpp.
References SceneIOTestClass::FillStorage(), mitk::TestManager::GetInstance(), MITK_TEST_BEGIN, MITK_TEST_CONDITION_REQUIRED, MITK_TEST_END, MITK_TEST_OUTPUT, MITK_TEST_OUTPUT_DIR, MITK_TEST_OUTPUT_NO_ENDL, mitk::StandaloneDataStorage::New(), mitk::SceneIO::New(), and SceneIOTestClass::VerifyStorage().
{
MITK_TEST_BEGIN("SceneIO")
std::string sceneFileName;
for (unsigned int i = 0; i < 1; ++i) // TODO change to " < 2" to check cases where file system would be full
{
if (i == 1)
{
// call ulimit and restrict maximum file size to something small
#ifndef WIN32
errno = 0;
long int value = ulimit(UL_SETFSIZE, 1);
MITK_TEST_CONDITION_REQUIRED( value != -1, "ulimit() returned with errno = " << errno );
#else
continue;
#endif
}
// create a data storage and fill it with some test data
mitk::SceneIO::Pointer sceneIO = mitk::SceneIO::New();
MITK_TEST_CONDITION_REQUIRED(sceneIO.IsNotNull(),"SceneIO instantiation")
mitk::DataStorage::Pointer storage = mitk::StandaloneDataStorage::New().GetPointer();
MITK_TEST_CONDITION_REQUIRED(storage.IsNotNull(),"StandaloneDataStorage instantiation");
SceneIOTestClass::FillStorage(storage);
// attempt to save it
Poco::Path newname( Poco::TemporaryFile::tempName() );
sceneFileName = std::string( MITK_TEST_OUTPUT_DIR ) + Poco::Path::separator() + newname.getFileName() + ".zip";
MITK_TEST_CONDITION_REQUIRED( sceneIO->SaveScene( storage->GetAll(), storage, sceneFileName), "Saving scene file '" << sceneFileName << "'");
// test if no errors were reported
mitk::SceneIO::FailedBaseDataListType::ConstPointer failedNodes = sceneIO->GetFailedNodes();
if (failedNodes.IsNotNull() && !failedNodes->empty())
{
MITK_TEST_OUTPUT( << "The following nodes could not be serialized:");
for ( mitk::SceneIO::FailedBaseDataListType::const_iterator iter = failedNodes->begin();
iter != failedNodes->end();
++iter )
{
MITK_TEST_OUTPUT_NO_ENDL( << " - ");
if ( mitk::BaseData* data =(*iter)->GetData() )
{
MITK_TEST_OUTPUT_NO_ENDL( << data->GetNameOfClass());
}
else
{
MITK_TEST_OUTPUT_NO_ENDL( << "(NULL)");
}
MITK_TEST_OUTPUT( << " contained in node '" << (*iter)->GetName() << "'");
// \TODO: should we fail the test case if failed properties exist?
}
}
mitk::PropertyList::ConstPointer failedProperties = sceneIO->GetFailedProperties();
if (failedProperties.IsNotNull() && !failedProperties->IsEmpty())
{
MITK_TEST_OUTPUT( << "The following properties could not be serialized:");
const mitk::PropertyList::PropertyMap* propmap = failedProperties->GetMap();
for ( mitk::PropertyList::PropertyMap::const_iterator iter = propmap->begin();
iter != propmap->end();
++iter )
{
MITK_TEST_OUTPUT( << " - " << iter->second.first->GetNameOfClass() << " associated to key '" << iter->first << "'");
// \TODO: should we fail the test case if failed properties exist?
}
}
MITK_TEST_CONDITION_REQUIRED(failedProperties.IsNotNull() && failedProperties->IsEmpty(), "Checking if all properties have been saved.")
MITK_TEST_CONDITION_REQUIRED(failedNodes.IsNotNull() && failedNodes->empty(), "Checking if all nodes have been saved.")
//Now do the loading part
sceneIO = mitk::SceneIO::New();
//Load scene into the datastorage and clean the DS first
MITK_TEST_OUTPUT(<< "Loading scene again");
storage = sceneIO->LoadScene(sceneFileName,storage,true);
// test if no errors were reported
failedNodes = sceneIO->GetFailedNodes();
if (failedNodes.IsNotNull() && !failedNodes->empty())
{
MITK_TEST_OUTPUT( << "The following nodes could not be serialized:");
for ( mitk::SceneIO::FailedBaseDataListType::const_iterator iter = failedNodes->begin();
iter != failedNodes->end();
++iter )
{
MITK_TEST_OUTPUT_NO_ENDL( << " - ");
if ( mitk::BaseData* data =(*iter)->GetData() )
{
MITK_TEST_OUTPUT_NO_ENDL( << data->GetNameOfClass());
}
else
{
MITK_TEST_OUTPUT_NO_ENDL( << "(NULL)");
}
MITK_TEST_OUTPUT( << " contained in node '" << (*iter)->GetName() << "'");
// \TODO: should we fail the test case if failed properties exist?
}
}
failedProperties = sceneIO->GetFailedProperties();
if (failedProperties.IsNotNull() && !failedProperties->IsEmpty())
{
MITK_TEST_OUTPUT( << "The following properties could not be serialized:");
const mitk::PropertyList::PropertyMap* propmap = failedProperties->GetMap();
for ( mitk::PropertyList::PropertyMap::const_iterator iter = propmap->begin();
iter != propmap->end();
++iter )
{
MITK_TEST_OUTPUT( << " - " << iter->second.first->GetNameOfClass() << " associated to key '" << iter->first << "'");
// \TODO: should we fail the test case if failed properties exist?
}
}
// check if data storage content has been restored correctly
SceneIOTestClass::VerifyStorage(storage);
}
// if no sub-test failed remove the scene file, otherwise it is kept for debugging purposes
if ( mitk::TestManager::GetInstance()->NumberOfFailedTests() == 0 )
{
Poco::File pocoSceneFile( sceneFileName );
MITK_TEST_CONDITION_REQUIRED( pocoSceneFile.exists(), "Checking if scene file still exists before cleaning up." )
pocoSceneFile.remove();
}
MITK_TEST_END();
}
{
{
"mitkSceneIOTest",
mitkSceneIOTest
},
{0,0}
}
Definition at line 23 of file SceneSerializationTestDriver.cpp.
1.7.2