std::string TestBase::getTestTempFile() { char buf[32]; snprintf(buf, sizeof(buf), "%08X", myrand()); return getTestTempDirectory() + DIR_DELIM + buf + ".tmp"; }
void TestMapSettingsManager::testMapMetaSaveLoad() { Settings conf; std::string path = getTestTempDirectory() + DIR_DELIM + "foobar" + DIR_DELIM + "map_meta.txt"; // Create a set of mapgen params and save them to map meta conf.set("seed", "12345"); conf.set("water_level", "5"); MapSettingsManager mgr1(&conf, path); MapgenParams *params1 = mgr1.makeMapgenParams(); UASSERT(params1); UASSERT(mgr1.saveMapMeta()); // Now try loading the map meta to mapgen params conf.set("seed", "67890"); conf.set("water_level", "32"); MapSettingsManager mgr2(&conf, path); UASSERT(mgr2.loadMapMeta()); MapgenParams *params2 = mgr2.makeMapgenParams(); UASSERT(params2); // Check that both results are correct UASSERTEQ(u64, params1->seed, 12345); UASSERTEQ(s16, params1->water_level, 5); UASSERTEQ(u64, params2->seed, 12345); UASSERTEQ(s16, params2->water_level, 5); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QString AdjustOutputDirectory(const QString& pipelineFile) { QString contents; // Read the Source File QFileInfo fi(pipelineFile); QFile source(pipelineFile); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); QString searchString = QString::fromLatin1("Data/Output/"); QStringList outLines; QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); while (sourceLines.hasNext()) { QString line = sourceLines.next(); if( line.contains(QString("Data/")) == true && line.contains(searchString) == false ) { line = line.replace(QString("Data/"), getDream3dDataDir() + "/Data/"); } if(line.contains(searchString) ) { line = line.replace(searchString, getTestTempDirectory()); } outLines.push_back(line); } QString outFile = getTestTempDirectory() + fi.fileName(); writeOutput(true, outLines, outFile); return outFile; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- int main (int argc, char* argv[]) { // Instantiate the QCoreApplication that we need to get the current path and load plugins. QCoreApplication app(argc, argv); QCoreApplication::setOrganizationName("BlueQuartz Software"); QCoreApplication::setOrganizationDomain("bluequartz.net"); QCoreApplication::setApplicationName("PipelineRunnerTest"); // We need to change our working directory into the "DREAM3D_Data" directory because all the pipelines use relative paths QDir dataDir = QDir(getDream3dDataDir()); #ifdef _MSC_VER _chdir(dataDir.absolutePath().toLatin1().constData()); #else chdir(dataDir.absolutePath().toLatin1().constData()); #endif // Register all the filters including trying to load those from Plugins FilterManager* fm = FilterManager::Instance(); SIMPLibPluginLoader::LoadPluginFilters(fm); // Send progress messages from PipelineBuilder to this object for display QMetaObjectUtilities::RegisterMetaTypes(); int err = 0; // Read in the contents of the PipelineList file which contains all the Pipelines that we want // to execute QString contents; { // Read the Source File QFileInfo fi(getPipelineListFile()); QFile source(getPipelineListFile()); source.open(QFile::ReadOnly); contents = source.readAll(); source.close(); } // Split the file into tokens using the newline character QStringList list = contents.split(QRegExp("\\n")); QStringListIterator sourceLines(list); // Iterate over all the entries in the file and process each pipeline. Note that the order of the // pipelines will probably matter int testNum = 0; while (sourceLines.hasNext()) { QString pipelineFile = sourceLines.next(); pipelineFile = pipelineFile.trimmed(); if(pipelineFile.isEmpty()) { continue; } try { QFileInfo fi(pipelineFile); pipelineFile = AdjustOutputDirectory(pipelineFile); DREAM3D::unittest::CurrentMethod = fi.fileName().toStdString(); DREAM3D::unittest::numTests++; std::cout << "\"" << testNum++ << "\": {" << std::endl; ExecutePipeline(pipelineFile); TestPassed(fi.fileName().toStdString()); std::cout << "}," << std::endl; DREAM3D::unittest::CurrentMethod = ""; } catch (TestException& e) { TestFailed(DREAM3D::unittest::CurrentMethod); std::cout << e.what() << std::endl; err = EXIT_FAILURE; } } QDir tempDir(getTestTempDirectory()); tempDir.removeRecursively(); return err; }