From 4adec8d2bf3f86d65cb8785ecfa2dbad71902855 Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Tue, 16 Jan 2018 15:49:26 +0100 Subject: [PATCH] #2380 AppFwk: Make template function to find all PdmFields of a type --- .../UnitTests/CMakeLists_files.cmake | 1 + .../UnitTests/RimRelocatePath-Test.cpp | 70 +++ .../TestData/RimRelocatePath/RelocatePath.rsp | 534 ++++++++++++++++++ 3 files changed, 605 insertions(+) create mode 100644 ApplicationCode/UnitTests/RimRelocatePath-Test.cpp create mode 100644 ApplicationCode/UnitTests/TestData/RimRelocatePath/RelocatePath.rsp diff --git a/ApplicationCode/UnitTests/CMakeLists_files.cmake b/ApplicationCode/UnitTests/CMakeLists_files.cmake index c979307ca3..cceb7d1db9 100644 --- a/ApplicationCode/UnitTests/CMakeLists_files.cmake +++ b/ApplicationCode/UnitTests/CMakeLists_files.cmake @@ -41,6 +41,7 @@ ${CEE_CURRENT_LIST_DIR}RigTimeCurveHistoryMerger-Test.cpp ${CEE_CURRENT_LIST_DIR}ListKeywordsForObjectsAndFields-Test.cpp ${CEE_CURRENT_LIST_DIR}RiaProjectFileVersionTools-Test.cpp ${CEE_CURRENT_LIST_DIR}RifElementPropertyTableReader-Test.cpp +${CEE_CURRENT_LIST_DIR}RimRelocatePath-Test.cpp ) if (RESINSIGHT_ENABLE_PROTOTYPE_FEATURE_FRACTURES) diff --git a/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp b/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp new file mode 100644 index 0000000000..a66882283c --- /dev/null +++ b/ApplicationCode/UnitTests/RimRelocatePath-Test.cpp @@ -0,0 +1,70 @@ +#include "gtest/gtest.h" + +#include "RiaTestDataDirectory.h" +#include "RimProject.h" + +#include "cafPdmObjectHandle.h" +#include "cafFilePath.h" + +#include + +#include + + +static const QString TEST_DATA_DIRECTORY = QString("%1/RimRelocatePath/").arg(TEST_DATA_DIR); + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +template +void fieldByType(caf::PdmObjectHandle* object, std::vector< caf::PdmField* >* typedFields) +{ + if (!typedFields) return; + if (!object) return; + + std::vector fields; + object->fields(fields); + + std::vector children; + + for (const auto& field : fields) + { + caf::PdmField* typedField = dynamic_cast*>(field); + if (typedField) typedFields->push_back(typedField); + + field->childObjects(&children); + } + + for (const auto& child : children) + { + fieldByType(child, typedFields); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST(RimRelocatePathTest, findPathsInProjectFile) +{ + QString fileName = TEST_DATA_DIRECTORY + "RelocatePath.rsp"; + + if (fileName.isEmpty()) return; + + RimProject project; + + project.fileName = fileName; + project.readFile(); + + std::vector< caf::PdmField>* > filePathsVectors; + + fieldByType(&project, &filePathsVectors); + + for (auto fpVec : filePathsVectors) + { + for (auto fp : fpVec->v()) + { + std::cout << fp.path().toStdString() << std::endl; + } + } +} diff --git a/ApplicationCode/UnitTests/TestData/RimRelocatePath/RelocatePath.rsp b/ApplicationCode/UnitTests/TestData/RimRelocatePath/RelocatePath.rsp new file mode 100644 index 0000000000..9a7c58cb58 --- /dev/null +++ b/ApplicationCode/UnitTests/TestData/RimRelocatePath/RelocatePath.rsp @@ -0,0 +1,534 @@ + + + C:/Users/Rebecca Cox/Desktop/regression-tests/ProjectFiles/element_properties.rsp + 2018.01.00-dev.01 + 0 + 0 + + + + + + + + + + + + + smal_synt + -1 + + + + + 0 + 0 + TS_ALL + 1 + + + C:\Users\Rebecca Cox\Desktop\regression-tests\ModelData\smal_synt.odb + + + + + 0 + 0 + 0 + 1034 + 547 + True + + + True + View 1 + -0.594 -0.283646 -0.752801 -5819.28 -0.489311 0.870164 0.0582249 -656.548 0.638544 0.402939 -0.655668 -21775.3 0 0 0 1 + 3800 1686.01 -4633.9 + True + 5 + 0.694118 0.772549 0.870588 + 10 + True + 0 + FULL_MESH + SURFACE + True + False + + + + True + + + + + + + True + + + + + True + + + + + True + True + True + True + True + False + ALL_TIMESTEPS + ALL_CELLS + + + + + ELEMENT + Density + + False + 0 + + + 8 + 4 + FIXED + NORMAL + LinearContinuous + AUTOMATIC_ALLTIMESTEPS + 1 + 0 + + + + + + + + True + + + E, Density, (1500 .. 2652.75) + True + INCLUDE + + + + ELEMENT + Density + + False + 0 + + + 1500 + 2652.75 + + + + + + + + + 0 + 0 + 0 + 1034 + 547 + True + + + True + View 2 + 0.843247 0.06208 -0.533929 -11599.1 -0.347573 0.820684 -0.45351 -7654.19 0.410033 0.568 0.713617 -9392.31 0 0 0 1 + 0 0 0 + True + 5 + 0.694118 0.772549 0.870588 + 10 + True + 0 + FULL_MESH + SURFACE + True + False + + + + True + + + + + + + True + + + + + True + + + + + True + True + True + True + True + False + ALL_TIMESTEPS + ALL_CELLS + + + + + ELEMENT + MODULUS + + False + 0 + + + 8 + 4 + FIXED + NORMAL + LinearContinuous + USER_DEFINED_MAX_MIN + 17.41 + 5.316 + + + + + + + + True + + + E, Young's Modulus, (10.4982 .. 17.4091) + True + INCLUDE + + + + ELEMENT + MODULUS + + False + 0 + + + 10.4982 + 17.4091 + + + + + + + + + 0 + 0 + 0 + 1034 + 547 + True + + + True + View 3 + -0.541294 0.738323 0.402342 4749.47 0.834496 0.530356 0.14946 1161.22 -0.103035 0.416655 -0.903207 -41220.3 0 0 0 1 + 3800 -744.597 -10718 + True + 5 + 0.694118 0.772549 0.870588 + 10 + True + 0 + FULL_MESH + SURFACE + True + False + + + + True + + + + + + + True + + + + + True + + + + + True + True + True + True + True + False + ALL_TIMESTEPS + ALL_CELLS + + + + + ELEMENT + RATIO + + False + 0 + + + 8 + 4 + FIXED + NORMAL + LinearContinuous + AUTOMATIC_ALLTIMESTEPS + 1 + 0 + + + + + + + + True + + + + + + 10 + 30 + C:\Users\Rebecca Cox\Desktop\regression-tests\ModelData\DENSITY_TABLE.inp;C:\Users\Rebecca Cox\Desktop\regression-tests\ModelData\ELASTIC_TABLE.inp + + + + + + + True + True + 0.929412 0.929412 0.929412 + ALL_ON + 0.1 + True + 100 + + + + + + UNITS_METRIC + + + + + + + + + + + + + + + + + + + + + + + + + + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts\InputPropTest.m + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts\kaverage.m + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts\kslice.m + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts\LGRSOIL.m + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts\SatNum.m + + + C:\gitroot\ResInsight\OctavePlugin\OctaveScripts\SoilTimeDiff.m + + + + + + + + + + True + True + UTM_FILTER_OFF + 0 + 0 + 0 + 0 + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 0 + 0 + -1 + -1 + False + + + False + + + SELECTED + + + 0.1 + True + CELLS_ACTIVE + + + + 0 + 146000 + + + + + + + + + + + + True + + + + + + + + + + + -1-110000050;-1-1100000;-1-110001050;-1-1100010;-1-1100020;-1-11000;-1-110 + 1 0;0 0;2 0;2 0 + + + True + False + + + + + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + + + + + 2 + 2 + 2 + 8 + + + + + + + UNIFIED_FILE + ALL_WELLS + TRANSMISSIBILITIES + 0 + False + True + True + True + False + + + + +