void ClangInstanceTest::testGetTranslationUnitWithCompilationError() { try { _instance->getTranslationUnit(); TS_FAIL("empty translation unit exception expected"); } catch (GenericException& ex) { // } }
void TestPerformRosetteRankDecrease() throw (Exception) { // Let us first create a protorosette MutableVertexMesh<2,2>* p_mesh = ConstructFiveCellRosette(); Node<2>* p_node_0 = p_mesh->GetNode(0); // Perform the protorosette resolution p_mesh->PerformRosetteRankDecrease(p_node_0); /** * We now need to check that this has been done correctly */ // The number of nodes in the mesh should have increase by one (from 11 to 12) TS_ASSERT_EQUALS(p_mesh->GetNumNodes(), 12u); Node<2>* p_node_11 = p_mesh->GetNode(11); // Two elements should now have five nodes, and the other three should have four std::vector<VertexElement<2,2>* > five_node_elems; std::vector<VertexElement<2,2>* > four_node_elems; for (unsigned elem_idx = 0 ; elem_idx < 5 ; elem_idx++) { VertexElement<2,2>* p_current_element = p_mesh->GetElement(elem_idx); if (p_current_element->GetNumNodes() == 4) { four_node_elems.push_back(p_current_element); } else if (p_current_element->GetNumNodes() == 5) { five_node_elems.push_back(p_current_element); } else { TS_FAIL("No element should contain this number of nodes"); } } TS_ASSERT_EQUALS(five_node_elems.size(), 2u); TS_ASSERT_EQUALS(four_node_elems.size(), 3u); // The five-node elements should be separated by one (0,2 or 1,3 or 2,4 or 3,0) TS_ASSERT( ( (five_node_elems[0]->GetIndex() + 2) % 5 == five_node_elems[1]->GetIndex() ) || ( (five_node_elems[1]->GetIndex() + 2) % 5 == five_node_elems[0]->GetIndex() ) ); // We can also check the location of the new node, which should be a distance from the origin given by // CellRearrangementThreshold * CellRearrangementRatio. Node 0 should not have moved double node_spacing = p_mesh->GetCellRearrangementThreshold() * p_mesh->GetCellRearrangementRatio(); c_vector<double, 2> node_0_pos = p_node_0->rGetLocation(); c_vector<double, 2> node_11_pos = p_node_11->rGetLocation(); TS_ASSERT_DELTA(norm_2(node_0_pos), 0.0, 1e-10); TS_ASSERT_DELTA(norm_2(node_11_pos), node_spacing, 1e-10); delete p_mesh; }
void ClangInstanceTest::testCodeCompilationFailException() { try { const char * const argv[] = { "test/samples/CompilationFail.txt" }; _instance->compileSourceFileToTranslationUnit(argv, 1); TS_FAIL("compilation error exception expected"); } catch (GenericException& ex) { // } }
void ClangInstanceTest::testGetTranslationUnitWithDiagnosticErrors() { try { const char * const argv[] = { "test/samples/CompilerDiagnostics.cpp" }; _instance->compileSourceFileToTranslationUnit(argv, 1); _instance->getTranslationUnit(); TS_FAIL("questionable translation unit exception expected"); } catch (GenericException& ex) { // } }
void RunTests(const std::string& rOutputDirName, const std::vector<std::string>& rModels, const std::vector<std::string>& rArgs, bool testLookupTables=false, double tableTestV=-1000, bool warningsOk=true) { OutputFileHandler handler(rOutputDirName); // Clear folder (collective) PetscTools::IsolateProcesses(true); // Simple parallelism std::vector<std::string> failures; for (unsigned i=0; i<rModels.size(); ++i) { if (PetscTools::IsParallel() && i % PetscTools::GetNumProcs() != PetscTools::GetMyRank()) { continue; // Let someone else do this model } try { unsigned num_failed_asserts = CxxTest::tracker().testFailedAsserts(); RunTest(rOutputDirName + "/" + rModels[i], rModels[i], rArgs, testLookupTables, tableTestV); if (CxxTest::tracker().testFailedAsserts() > num_failed_asserts) { EXCEPTION((CxxTest::tracker().testFailedAsserts() - num_failed_asserts) << " test assertion failure(s)."); } } catch (const Exception& e) { failures.push_back(rModels[i]); TS_FAIL("Failure testing cell model " + rModels[i] + ": " + e.GetMessage()); } if (!warningsOk) { TS_ASSERT_EQUALS(Warnings::Instance()->GetNumWarnings(), 0u); } Warnings::NoisyDestroy(); // Print out any warnings now, not at program exit } // Wait for all simulations to finish before printing summary of failures PetscTools::IsolateProcesses(false); PetscTools::Barrier("RunTests"); if (!failures.empty()) { std::cout << failures.size() << " models failed for " << rOutputDirName << ":" << std::endl; for (unsigned i=0; i<failures.size(); ++i) { std::cout << " " << failures[i] << std::endl; } } }
void TestOpenFutureBoostArchive() throw (Exception) { //Check testout/archive/specific_secondary.arch FileFinder archive_dir("global/test/data", RelativeTo::ChasteSourceRoot); std::string archive_file = "future_boost.arch"; // future_boost has got archive version 14 in it // 33 => 3 // 34 => 4 // 36 => 5 // 37 => 5 // 40 => 5 // 42 => 7 // 46 => 9 // 48 => 9 // 49 => 9 // 51 => 9 // 52 => ?? // 53 => 10 // 54 => 10 // 55 => 10 // 56 => 11 // 57 => 11 // 58 => 12 // 59 => 13 #ifndef BOOST_VERSION TS_FAIL("This test needs to know the version of Boost with which it was compiled."); return; #endif //#if BOOST_VERSION >= 999999 // InputArchiveOpener archive_opener_in(archive_dir, archive_file, 0); // boost::archive::text_iarchive* p_arch = archive_opener_in.GetCommonArchive(); // boost::archive::text_iarchive* p_process_arch = ProcessSpecificArchive<boost::archive::text_iarchive>::Get(); // // const unsigned test_int = 321; // unsigned test_int1, test_int2; // (*p_arch) & test_int1; // (*p_process_arch) & test_int2; // // TS_ASSERT_EQUALS(test_int1, test_int); // TS_ASSERT_EQUALS(test_int2, 0u); //#else //Current Boost can't read this archive... TS_ASSERT_THROWS_CONTAINS(InputArchiveOpener archive_opener_in(archive_dir, archive_file, 0), "Could not open Boost archive '"); //#endif }
void msgHandler(IEC61162::Alarm msg,void *param) { AISAlarm_Test *caller = static_cast<AISAlarm_Test *>(param); if (caller) { // check the decoded message's content against the references data const struct AISAlarm_Data *test_data = caller->currentMsg; char buffer[255]; sprintf(buffer,"checking message %s...\n",test_data->rawMsg); TS_TRACE(buffer); const time_t ref = getTime(test_data->hour,test_data->minutes,test_data->seconds); TS_ASSERT_EQUALS(msg->get_timeOfAlarmCondictionChange(),ref); TS_ASSERT_EQUALS(msg->get_id(),test_data->id); TS_ASSERT_EQUALS(msg->get_condition(),test_data->condition); TS_ASSERT_EQUALS(msg->get_state(),test_data->state); TS_ASSERT_EQUALS(msg->get_description(),test_data->description); } else { TS_FAIL("caller parameter is NULL"); } }
void msgHandler(IEC61162::AISMsg26 msg,void *param) { AISMsg26_Tests *caller = static_cast<AISMsg26_Tests *>(param); if (caller) { // check the decoded message's content against the references data const struct AISMsg26_Data *test_data = caller->currentMsg; TS_ASSERT_EQUALS(msg->get_repeatIndicator(),test_data->repeatIndicator); TS_ASSERT_EQUALS(msg->get_sourceID(),test_data->sourceID); //const IEC61162::BinaryData *binData = msg->get_binaryData(); TS_ASSERT_EQUALS(msg->get_destinationIndicator(),test_data->destinationIndicator); TS_ASSERT_EQUALS(msg->get_binaryDataFlag(),test_data->binaryDataFlag); TS_ASSERT_EQUALS(msg->get_destinationID(),test_data->destinationID); TS_ASSERT_EQUALS(msg->get_applicationIdentifier(),test_data->applicationIdentifier); TS_ASSERT_EQUALS(msg->get_binaryDataSize(),test_data->binaryDataSize); TS_ASSERT_EQUALS(msg->get_communicationStateSelectorFlag(),test_data->communicationStateSelectorFlag); TS_ASSERT_EQUALS(msg->get_communicationState(),test_data->communicationState); //IEC61162::Byte binaryData[(128/8)+(224/8)+(224/8)+(224/8)+(224/8)]; //1024 bits } else { TS_FAIL("caller parameter is NULL"); } }
void msgHandler(IEC61162::AISMsg13 msg,void *param) { AISMsg13_Tests *caller = static_cast<AISMsg13_Tests *>(param); if (caller) { // check the decoded message's content against the references data const struct AISMsg13_Data *test_data = caller->currentMsg; TS_ASSERT_EQUALS(msg->get_repeatIndicator(),test_data->repeatIndicator); TS_ASSERT_EQUALS(msg->get_sourceID(),test_data->sourceID); TS_ASSERT_EQUALS(msg->get_destinationID1(),test_data->destinationID1); TS_ASSERT_EQUALS(msg->get_sequenceNumberForID1(),test_data->sequenceNumberForID1); TS_ASSERT_EQUALS(msg->get_destinationID2(),test_data->destinationID2); TS_ASSERT_EQUALS(msg->get_sequenceNumberForID2(),test_data->sequenceNumberForID2); TS_ASSERT_EQUALS(msg->get_destinationID3(),test_data->destinationID3); TS_ASSERT_EQUALS(msg->get_sequenceNumberForID3(),test_data->sequenceNumberForID3); TS_ASSERT_EQUALS(msg->get_destinationID4(),test_data->destinationID4); TS_ASSERT_EQUALS(msg->get_sequenceNumberForID4(),test_data->sequenceNumberForID4); } else { TS_FAIL("caller parameter is NULL"); } }
// // BAD test - fails with HYPRE (for some reason HYPRE can't solve the one of the linear systems, and // the search direction in the end doesn't decrease the residual), and also with ILU if you increase // the number of elements (whether LR91 or N98 is used). Probably the active tension is too high. // // Now removed // void removedTestExplicitSolverWithNash2004() throw(Exception) { #ifdef MECH_USE_HYPRE TS_FAIL("This test is known to fail with HYPRE - see comments in test"); return; #endif PlaneStimulusCellFactory<CML_noble_varghese_kohl_noble_1998_basic_with_sac, 2> cell_factory(-1000*1000); HeartConfig::Instance()->SetSimulationDuration(20.0); CardiacElectroMechProbRegularGeom<2> problem(INCOMPRESSIBLE, 0.05, /* width (cm) */ 1, /* mech mesh size*/ 5, /* elec elem each dir */ &cell_factory, NASH2004, 1.0, /* mechanics solve timestep */ 0.01, /* nash ode timestep */ "TestExplicitWithNash"); c_vector<double,2> pos; pos(0) = 0.05; pos(1) = 0.0; problem.SetWatchedPosition(pos); problem.SetNoElectricsOutput(); problem.Initialise(); problem.Solve(); //visualise to verify // hardcoded result TS_ASSERT_EQUALS(problem.mWatchedMechanicsNodeIndex, 1u); TS_ASSERT_DELTA(problem.rGetDeformedPosition()[1](0), 0.0419, 0.0002); }
uint32_t rcTestCalloutNoneDeconfig() { uint32_t l_result = 0; errlHndl_t l_errl = NULL; bool l_hw_callout_found = false; FAPI_INF("rcTestCalloutNoneDeconfig running"); TARGETING::TargetHandleList l_dimmList; TARGETING::getAllLogicalCards(l_dimmList, TARGETING::TYPE_DIMM, false); TARGETING::Target * l_Dimm = NULL; //Take the first dimm if (l_dimmList.size() > 0) { l_Dimm = l_dimmList[0]; } else { TS_FAIL("No dimms found"); } //Convert to fapi2 target for the HWP below fapi2::Target<fapi2::TARGET_TYPE_DIMM> fapi2_dimmTarget(l_Dimm); FAPI_INVOKE_HWP(l_errl, p9_deconfigCalloutNone, fapi2_dimmTarget); if(l_errl != NULL) { FAPI_INF("rcTestCalloutNoneDeconfig: p9_deconfigCalloutNone " "returned errl (expected)"); //Get the User Data fields of the errl. They are returned as //vector<void*>, so iterate over them. for( auto l_callout_raw : l_errl-> getUDSections( ERRL_COMP_ID, ERRORLOG::ERRL_UDT_CALLOUT ) ) { HWAS::callout_ud_t* l_callout_entry = reinterpret_cast<HWAS::callout_ud_t*>(l_callout_raw); if(l_callout_entry->type == HWAS::HW_CALLOUT) { l_hw_callout_found = true; FAPI_INF("rcTestCalloutNoneDeconfig: hw callout found"); if(l_callout_entry->deconfigState == HWAS::DELAYED_DECONFIG) { FAPI_INF("rcTestCalloutNoneDeconfig: Target is deconfigured"); } else { TS_FAIL("rcTestCalloutNoneDeconfig: Target is NOT deconfigured"); l_result = 1; break; } } } if(!l_hw_callout_found) { TS_FAIL("rcTestCalloutNoneDeconfig: hw callout NOT found"); l_result = 2; } } else { TS_FAIL("rcTestCalloutNoneDeconfig: No error was returned from" " p9_deconfigCalloutNone !!"); l_result = 3; } //l_errl->setSev(ERRORLOG::ERRL_SEV_RECOVERED); //errlCommit(l_errl,CXXTEST_COMP_ID); delete l_errl; l_errl = NULL; // Now try it the way HWP people do it ReturnCode l_rc; FAPI_EXEC_HWP(l_rc, p9_deconfigCalloutNone, fapi2_dimmTarget); if (l_rc != fapi2::FAPI2_RC_SUCCESS) { // log the error but don't fail the unit test FAPI_INF("rcTestCalloutNoneDeconfig: logError called"); fapi2::logError(l_rc, fapi2::FAPI2_ERRL_SEV_RECOVERED, true); } else { TS_FAIL("rcTestCalloutNoneDeconfig: No error was returned from " "FAPI_EXEC_HWP p9_deconfigCalloutNone !!"); l_result = 4; } FAPI_INF("rcTestCalloutNoneDeconfig finished"); return l_result; }
uint32_t rcTestCalloutDeconfig() { uint32_t l_result = 0; errlHndl_t l_errl = NULL; bool l_hw_callout_found = false; FAPI_INF("rcTestCalloutDeconfig running"); TARGETING::TargetHandleList l_dimmList; TARGETING::getAllLogicalCards(l_dimmList, TARGETING::TYPE_DIMM, false); TARGETING::Target * l_Dimm = NULL; //Take the first dimm if (l_dimmList.size() > 0) { l_Dimm = l_dimmList[0]; } else { TS_FAIL("No dimms found"); } //Convert to fapi2 target for the HWP below fapi2::Target<fapi2::TARGET_TYPE_DIMM> fapi2_dimmTarget(l_Dimm); FAPI_INVOKE_HWP(l_errl, p9_deconfigCallout, fapi2_dimmTarget); if(l_errl != NULL) { FAPI_INF("rcTestCalloutDeconfig: p9_deconfigCallout returned errl " "(expected)"); //Get the User Data fields of the errl. They are returned as //vector<void*>, so iterate over them. for( auto l_callout_raw : l_errl-> getUDSections( ERRL_COMP_ID, ERRORLOG::ERRL_UDT_CALLOUT ) ) { HWAS::callout_ud_t* l_callout_entry = reinterpret_cast<HWAS::callout_ud_t*>(l_callout_raw); if(l_callout_entry->type == HWAS::HW_CALLOUT) { l_hw_callout_found = true; FAPI_INF("rcTestCalloutDeconfig: hw callout found"); if(l_callout_entry->deconfigState == HWAS::DELAYED_DECONFIG) { FAPI_INF("rcTestCalloutDeconfig: Target is deconfigured"); } else { TS_FAIL("rcTestCalloutDeconfig: Target is NOT deconfigured"); l_result = 1; break; } } } if(!l_hw_callout_found) { TS_FAIL("rcTestCalloutDeconfig: hw callout NOT found"); l_result = 2; } } else { TS_FAIL("rcTestCalloutDeconfig: No error was returned from" " p9_deconfigCallout !!"); l_result = 3; } delete l_errl; l_errl = NULL; FAPI_INF("rcTestCalloutDeconfig finished"); return l_result; }
uint32_t rcTestCalloutDeconfigGard() { uint32_t l_result = 0; errlHndl_t l_errl = NULL; bool l_hw_callout_found = false; FAPI_INF("rcTestCalloutDeconfigGard running"); TARGETING::TargetHandleList l_chipList; TARGETING::getAllChips(l_chipList, TARGETING::TYPE_PROC, false); TARGETING::Target * l_Proc = NULL; //Grab the first chip if there are multiple if (l_chipList.size() > 0) { l_Proc = l_chipList[0]; } else { TS_FAIL("No proc chips found"); } //Convert to fapi2 target for the HWP below fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP> fapi2_procTarget(l_Proc); FAPI_INVOKE_HWP(l_errl, p9_gardAndDeconfig, fapi2_procTarget); if(l_errl != NULL) { FAPI_INF("rcTestCalloutDeconfigGard: p9_gardAndDeconfig " "returned errl (expected)"); //Get the User Data fields of the errl. They are returned as //vector<void*>, so iterate over them. for( auto l_callout_raw : l_errl-> getUDSections( ERRL_COMP_ID, ERRORLOG::ERRL_UDT_CALLOUT ) ) { HWAS::callout_ud_t* l_callout_entry = reinterpret_cast<HWAS::callout_ud_t*>(l_callout_raw); if(l_callout_entry->type == HWAS::HW_CALLOUT) { l_hw_callout_found = true; FAPI_INF("rcTestCalloutDeconfigGard: found hw callout"); if(l_callout_entry->gardErrorType == HWAS::GARD_Unrecoverable) { FAPI_INF("rcTestCalloutDeconfigGard: " "Gard Error Type matches"); } else { TS_FAIL("rcTestCalloutDeconfigGard: " "Gard Error Type does NOT match. Expected: %x Actual: %x", HWAS::GARD_Unrecoverable, l_callout_entry->gardErrorType); l_result = 1; break; } if(l_callout_entry->deconfigState == HWAS::DELAYED_DECONFIG) { FAPI_INF("rcTestCalloutDeconfigGard: Target deconfigured"); } else { TS_FAIL("rcTestCalloutDeconfigGard: " "Target is NOT deconfigured"); l_result = 2; break; } } } if(!l_hw_callout_found) { TS_FAIL("rcTestCalloutDeconfigGard: hw callout not found"); l_result = 3; } } else { TS_FAIL("rcTestCalloutDeconfigGard: No error was returned " "from p9_gardAndDeconfig !!"); l_result = 4; } delete l_errl; l_errl = NULL; FAPI_INF("rcTestCalloutDeconfigGard finished"); return l_result; }
uint32_t rcTestCalloutHw() { uint32_t l_result = 0; errlHndl_t l_errl = NULL; bool l_hw_callout_found = false; FAPI_INF("rcTestCalloutHw running"); TARGETING::TargetHandleList l_coreList; TARGETING::getAllChiplets(l_coreList, TARGETING::TYPE_CORE, false); TARGETING::Target * l_Core = NULL; //Get the first core if(l_coreList.size() > 0) { l_Core = l_coreList[0]; } else { TS_FAIL("No cores found"); } //Convert to fapi2 target for HWP fapi2::Target<fapi2::TARGET_TYPE_CORE> fapi2_coreTarget(l_Core); FAPI_INVOKE_HWP(l_errl, p9_hwCallout, fapi2_coreTarget); if(l_errl != NULL) { FAPI_INF("rcTestCalloutHw: p9_hwCallout returned errl (expected)"); //Get the User Data fields of the errl. They are returned as //vector<void*>, so iterate over them. for( auto l_callout_raw : l_errl-> getUDSections( ERRL_COMP_ID, ERRORLOG::ERRL_UDT_CALLOUT ) ) { HWAS::callout_ud_t* l_callout_entry = reinterpret_cast<HWAS::callout_ud_t*>(l_callout_raw); if(l_callout_entry->type == HWAS::HW_CALLOUT) { l_hw_callout_found = true; FAPI_INF("rcTestCalloutHw: hw callout found"); if(l_callout_entry->priority == HWAS::SRCI_PRIORITY_LOW) { FAPI_INF("rcTestCalloutHw: low priority hw callout found"); } else { TS_FAIL("rcTestCalloutHw: incorrect hw callout priority." " Expected: %x Actual: %x", HWAS::SRCI_PRIORITY_LOW, l_callout_entry->priority); l_result = 1; break; } } } if(!l_hw_callout_found) { TS_FAIL("rcTestCalloutHw: hw callout NOT found"); l_result = 2; } } else { TS_FAIL("rcTestCalloutHw: No error was returned from p9_hwCallout !!"); l_result = 3; } delete l_errl; l_errl = NULL; FAPI_INF("rcTestCalloutHw finished"); return l_result; }
uint32_t rcTestCalloutProcedure() { uint32_t l_result = 0; errlHndl_t l_errl = NULL; bool l_procedure_found = false; FAPI_INF("rcTestCalloutProcedure running"); FAPI_INVOKE_HWP(l_errl, p9_procedureCallout); if(l_errl != NULL) { FAPI_INF("rcTestCalloutProcedure: " "p9_procedureCallout returned errl (expected)"); //Get the User Data fields of the errl. They are returned as //vector<void*>, so iterate over them. for( auto l_callout_raw : l_errl-> getUDSections( ERRL_COMP_ID, ERRORLOG::ERRL_UDT_CALLOUT ) ) { HWAS::callout_ud_t* l_callout_entry = reinterpret_cast<HWAS::callout_ud_t*>(l_callout_raw); if(l_callout_entry->type == HWAS::PROCEDURE_CALLOUT) { l_procedure_found = true; FAPI_INF("rcTestCalloutProcedure: procedure callout found"); if(l_callout_entry->priority == HWAS::SRCI_PRIORITY_HIGH) { FAPI_INF("rcTestCalloutProcedure: " "high priority procedure callout found"); } else { TS_FAIL("rcTestCalloutProcedure: " "incorrect procedure callout priority. Expected: %x" " Actual: %x", HWAS::SRCI_PRIORITY_HIGH, l_callout_entry->priority); l_result = 1; break; } } } if(!l_procedure_found) { TS_FAIL("rcTestCalloutProcedure: procedure callout NOT found"); l_result = 2; } } else { TS_FAIL("rcTestCalloutProcedure: No error was returned " "from p9_procedureCallout !!"); l_result = 3; } delete l_errl; l_errl = NULL; FAPI_INF("rcTestCalloutProcedure finished"); return l_result; }
void Read3DDataTest::TestReadDicomDirDataSet() { try { //Working directory of the application std::string wd = std::string(CISTIB_TOOLKIT_FOLDER) + "/Data/Tests/DcmAPI/DICOMDIR_1/"; std::string dicomDir = wd+"DICOMDIR"; //Data to compare in the tests unsigned int patientsNumber = 1; unsigned int studiesNumber = 1; unsigned int seriesNumber = 1; unsigned int timePointsNumber = 1; unsigned int slicesNumber = 14; //static std::string const patientIds[]={"161006"}; //static std::string const studiesIds[]={"1.2.250.1.46.30.60526.20061013113008.849668687"}; //static std::string const seriesIds[]={"1.2.840.113619.2.134.1762890972.2671.1160720118.659"}; const std::string patientIds[]={"1"}; const std::string studiesIds[]={"1"}; const std::string seriesIds[]={"1"}; const std::string timePointsIds[]={"1"}; const std::string sliceIds[] = {"1"}; const std::string sliceFileName[] = {"IM000001"}; const std::string sliceFilePath[] = {wd + "IM000001"}; dcmAPI::DataSet::Pointer dcmData = dcmAPI::DataSet::New(); // scan the current working folder for dicom files dcmAPI::DataSetReader::Pointer reader = dcmAPI::DataSetReader::New( ); reader->SetDataSet( dcmData ); reader->ReadDicomDir(dicomDir); dcmAPI::Slice::Pointer Myslice = dcmData->GetSlice( patientIds[0], studiesIds[0], seriesIds[0], timePointsIds[0], sliceIds[0] ); TS_ASSERT(Myslice); TS_ASSERT_EQUALS(sliceFileName[0], Myslice->GetTagAsText(dcmAPI::tags::SliceFileName)); //Get the vector of patients Ids dcmAPI::PatientIdVectorPtr patiendIdVector = dcmData->GetPatientIds(); //Check if the number of patients is correct TS_ASSERT_EQUALS(patientsNumber,patiendIdVector->size()); //Patients in the Dataset; for(unsigned int i=0; i < patiendIdVector->size(); i++) { std::string patientId = patiendIdVector->at(i); dcmAPI::Patient::Pointer patient = dcmData->GetPatient(patientId); //Check if the number of patients is correct TS_ASSERT_EQUALS(patientIds[i], patient->GetTagAsText(dcmAPI::tags::PatientId)); dcmAPI::StudyIdVectorPtr studiesIdVector = patient->StudyIds(); //Check if the number of studies is correct TS_ASSERT_EQUALS(studiesNumber, studiesIdVector->size()); //Studies of the patient for(unsigned int j=0; j < studiesIdVector->size(); j++) { std::string studyId = studiesIdVector->at(j); dcmAPI::Study::Pointer study = patient->Study(studyId); TS_ASSERT_EQUALS(studiesIds[j], study->GetTagAsText(dcmAPI::tags::StudyId)); dcmAPI::SeriesIdVectorPtr seriesIdVector = study->SeriesIds(); //Check if the number of Series is correct TS_ASSERT_EQUALS(seriesNumber, seriesIdVector->size()); //Prints the all the Series of the Study for(unsigned int k=0; k < seriesIdVector->size(); k++) { std::string seriesId = seriesIdVector->at(k); dcmAPI::Series::Pointer series = study->Series(seriesId); TS_ASSERT_EQUALS(seriesIds[k], series->GetTagAsText(dcmAPI::tags::SeriesId)); //Prints the all the TimePoints dcmAPI::TimePointIdVectorPtr timePointIdVector = series->TimePointIds(); //Check if the number of TimePoints is correct TS_ASSERT_EQUALS(timePointsNumber, timePointIdVector->size()); for(unsigned int p=0; p < timePointIdVector->size(); p++) { std::string timePointId = timePointIdVector->at(p); dcmAPI::TimePoint::Pointer timePoint = series->TimePoint(timePointId); TS_ASSERT_EQUALS(timePointsIds[p], timePoint->GetTagAsText(dcmAPI::tags::TimePointId)); dcmAPI::SliceIdVectorPtr sliceIdVector = timePoint->SliceIds(); //Check if the number of Slices is correct TS_ASSERT_EQUALS(slicesNumber, sliceIdVector->size()); //iterate over the Slices for(unsigned int q=0; q < sliceIdVector->size(); q++) { //std::string sliceId = sliceIdVector->at(q); dcmAPI::Slice::Pointer slice = timePoint->Slice(sliceIds[0]); TS_ASSERT_EQUALS(sliceFilePath[q], slice->GetTagAsText(dcmAPI::tags::SliceFilePath)); TS_ASSERT_EQUALS(sliceFileName[q], slice->GetTagAsText(dcmAPI::tags::SliceFileName)); break; } break; } break; } break; } break; } } catch(...) { TS_FAIL("TestReadDicomDir failed: exception was thrown"); } }
void TestChebyshevAdaptiveVsNoAdaptive() throw (Exception) { unsigned num_nodes = 1331; DistributedVectorFactory factory(num_nodes); Vec parallel_layout = factory.CreateVec(2); // Solving with zero guess for coverage Vec zero_guess = factory.CreateVec(2); double zero = 0.0; #if (PETSC_VERSION_MAJOR == 2 && PETSC_VERSION_MINOR == 2) VecSet(&zero, zero_guess); #else VecSet(zero_guess, zero); #endif Mat system_matrix; // Note that this test deadlocks if the file's not on the disk PetscTools::ReadPetscObject(system_matrix, "linalg/test/data/matrices/cube_6000elems_half_activated.mat", parallel_layout); Vec system_rhs; // Note that this test deadlocks if the file's not on the disk PetscTools::ReadPetscObject(system_rhs, "linalg/test/data/matrices/cube_6000elems_half_activated.vec", parallel_layout); // Make sure we are not inheriting a non-default number of iterations from previous test std::stringstream num_it_str; num_it_str << 1000; PetscOptionsSetValue("-ksp_max_it", num_it_str.str().c_str()); try { LinearSystem ls = LinearSystem(system_rhs, system_matrix); ls.SetMatrixIsSymmetric(); // Solve to relative convergence for coverage ls.SetRelativeTolerance(1e-6); ls.SetPcType("jacobi"); ls.SetKspType("chebychev"); ls.SetUseFixedNumberIterations(true, 64); // Solving with zero guess for coverage. Vec solution = ls.Solve(zero_guess); unsigned chebyshev_adaptive_its = ls.GetNumIterations(); TS_ASSERT_EQUALS(chebyshev_adaptive_its, 40u); TS_ASSERT_DELTA(ls.mEigMin, 0.0124, 1e-4); TS_ASSERT_DELTA(ls.mEigMax, 1.8810, 1e-4); PetscTools::Destroy(solution); } catch (Exception& e) { if (e.GetShortMessage() == "Chebyshev with fixed number of iterations is known to be broken in PETSc <= 2.3.2") { WARNING(e.GetShortMessage()); } else { TS_FAIL(e.GetShortMessage()); } } // Make sure we are not inheriting a non-default number of iterations from previous test PetscOptionsSetValue("-ksp_max_it", num_it_str.str().c_str()); { LinearSystem ls = LinearSystem(system_rhs, system_matrix); ls.SetMatrixIsSymmetric(); ls.SetRelativeTolerance(1e-6); ls.SetPcType("jacobi"); ls.SetKspType("chebychev"); Vec solution = ls.Solve(zero_guess); unsigned chebyshev_no_adaptive_its = ls.GetNumIterations(); TS_ASSERT_LESS_THAN(chebyshev_no_adaptive_its, 100u); // Normally 88, but 99 on maverick & natty TS_ASSERT_DELTA(ls.mEigMin, 0.0124, 1e-4); TS_ASSERT_DELTA(ls.mEigMax, 1.8841, 1e-4); PetscTools::Destroy(solution); } // Make sure we are not inheriting a non-default number of iterations from previous test PetscOptionsSetValue("-ksp_max_it", num_it_str.str().c_str()); { LinearSystem ls = LinearSystem(system_rhs, system_matrix); ls.SetMatrixIsSymmetric(); ls.SetRelativeTolerance(1e-6); ls.SetPcType("jacobi"); ls.SetKspType("cg"); Vec solution = ls.Solve(zero_guess); unsigned cg_its = ls.GetNumIterations(); TS_ASSERT_EQUALS(cg_its, 40u); TS_ASSERT_EQUALS(ls.mEigMin, DBL_MAX); TS_ASSERT_EQUALS(ls.mEigMax, DBL_MIN); PetscTools::Destroy(solution); } PetscTools::Destroy(system_matrix); PetscTools::Destroy(system_rhs); PetscTools::Destroy(parallel_layout); PetscTools::Destroy(zero_guess); }
bool Read3DDataTest::ReadAndCompare( const std::string& dcmInputNameEnd, const std::string& vtkFileNameEnd, const TYPE& inputType ) const { try { // Working directory of the test const std::string dcmInputName = std::string(CISTIB_TOOLKIT_FOLDER) + dcmInputNameEnd; const std::string vtkFileName = std::string(CISTIB_TOOLKIT_FOLDER) + vtkFileNameEnd; // Check if the vtk file exists std::ifstream ifs2( vtkFileName.c_str() ); TSM_ASSERT( "The input VTK file does not exist.", !ifs2.fail() ); if( ifs2.fail() ) return false; ifs2.close(); // read input vtkSmartPointer<vtkImageData> vtkDicomImage; switch( inputType ) { case FILE: { // Check if the dicom file exists std::ifstream ifs1( dcmInputName.c_str() ); TSM_ASSERT( "The input DICOM file does not exist.", !ifs1.fail() ); if( ifs1.fail() ) return false; ifs1.close(); // Read using dcmAPI::ImageUtilities vtkDicomImage = dcmAPI::ImageUtilities::ReadVtkImageFromFile< unsigned short, 3 >( dcmInputName.c_str(), true ); } break; case FOLDER: { // Check if the folder exists if ( !boost::filesystem::exists( dcmInputName ) ) return false; // create list of files std::vector< std::string > dcmFileNames; boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end for( boost::filesystem::directory_iterator itr( dcmInputName ); itr != end_itr; ++itr ) { if( is_regular_file(itr->status()) && itr->leaf() != "DICOMDIR") { dcmFileNames.push_back( dcmInputName + "/" + itr->leaf() ); } } // sort the files alphabetically std::sort(dcmFileNames.begin(), dcmFileNames.end()); // Read using dcmAPI::ImageUtilities vtkDicomImage = dcmAPI::ImageUtilities::ReadMultiSliceVtkImageFromFiles< unsigned short, 3 >( dcmFileNames, true ); } break; case DICOMDIR: { // Data set dcmAPI::DataSet::Pointer dcmData = dcmAPI::DataSet::New(); // scan the current working folder for dicom files dcmAPI::DataSetReader::Pointer reader = dcmAPI::DataSetReader::New( ); reader->SetDataSet( dcmData ); reader->ReadDicomDir( dcmInputName ); // Patient const dcmAPI::Patient::Pointer patient = dcmData->GetPatient( dcmData->GetPatientIds()->at(0) ); // Study const dcmAPI::Study::Pointer study = patient->Study( patient->StudyIds()->at(0) ); // Serie const dcmAPI::Series::Pointer series = study->Series( study->SeriesIds()->at(0) ); // TimePoint const dcmAPI::TimePoint::Pointer timePoint = series->TimePoint( series->TimePointIds()->at(0) ); // Slice const dcmAPI::SliceIdVectorPtr sliceIdVector = timePoint->SliceIds(); std::vector< std::string > dcmFileNames; for( unsigned int i=0; i < sliceIdVector->size(); ++i) { const dcmAPI::Slice::Pointer slice = timePoint->Slice(sliceIdVector->at(i)); const std::string filePath = slice->GetTagAsText(dcmAPI::tags::SliceFilePath); dcmFileNames.push_back( filePath ); } // Read using dcmAPI::ImageUtilities vtkDicomImage = dcmAPI::ImageUtilities::ReadMultiSliceVtkImageFromFiles< unsigned short, 3 >( dcmFileNames, true ); } break; default: { TS_FAIL("Read3DDataTest::ReadAndCompare failed: unknwown case."); return false; } } // Read using BaseLib vtkSmartPointer<vtkImageData> vtkImage = blImageUtils::LoadImageFromFileAsVTK( vtkFileName.c_str() ); // Compare image content return blImageUtils::CompareImages( vtkDicomImage, vtkImage, 1e-5 ); } catch(...) { TS_FAIL("Read3DDataTest::ReadAndCompare failed: thrown exception."); return false; } }