From e272bd0cb0766183375f253b705813d4124a95b1 Mon Sep 17 00:00:00 2001
From: peters <peters@irmb.tu-bs.de>
Date: Thu, 24 Jun 2021 11:32:40 +0200
Subject: [PATCH] Add ParameterTest to test the input file.

---
 src/gpu/VirtualFluids_GPU/LBM/LB.h            |  3 +-
 .../VirtualFluids_GPU/Parameter/Parameter.cpp |  9 +--
 .../Parameter/ParameterTest.cpp               | 61 +++++++++++++++++++
 .../Parameter/parameterTest.cfg               | 16 +++++
 .../Parameter/parameterTest_emptyfile.cfg     |  0
 5 files changed, 84 insertions(+), 5 deletions(-)
 create mode 100644 src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp
 create mode 100644 src/gpu/VirtualFluids_GPU/Parameter/parameterTest.cfg
 create mode 100644 src/gpu/VirtualFluids_GPU/Parameter/parameterTest_emptyfile.cfg

diff --git a/src/gpu/VirtualFluids_GPU/LBM/LB.h b/src/gpu/VirtualFluids_GPU/LBM/LB.h
index bea4a1683..dd443b469 100644
--- a/src/gpu/VirtualFluids_GPU/LBM/LB.h
+++ b/src/gpu/VirtualFluids_GPU/LBM/LB.h
@@ -112,7 +112,8 @@ struct InitCondition
    bool printFiles {false};
    bool doRestart {false};
    bool doCheckPoint {false};
-   bool readGeo, isGeo, isProp, isCp;
+   bool readGeo {false};
+   bool isGeo, isProp, isCp;
    bool GeometryValues {false};
    bool is2ndOrderMoments {false};
    bool is3rdOrderMoments {false};
diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp
index 8c3a4c510..61b5daf68 100644
--- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp
+++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp
@@ -65,6 +65,7 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData)
         this->setOutputPath(configData.getValue<std::string>("Path"));
     else
         throw std::runtime_error("<Path> need to be defined in config file!");
+
     //////////////////////////////////////////////////////////////////////////
     if (configData.contains("Prefix"))
         this->setOutputPrefix(configData.getValue<std::string>("Prefix"));
@@ -136,16 +137,16 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData)
         this->setTimeCalcMedEnd(configData.getValue<int>("TimeEndCalcMedian"));
     //////////////////////////////////////////////////////////////////////////
     if (configData.contains("PressInID"))
-        this->setTOut(configData.getValue<int>("PressInID"));
+        this->setPressInID(configData.getValue<int>("PressInID"));
     //////////////////////////////////////////////////////////////////////////
     if (configData.contains("PressOutID"))
-        this->setTStartOut(configData.getValue<int>("PressOutID"));
+        this->setPressOutID(configData.getValue<int>("PressOutID"));
     //////////////////////////////////////////////////////////////////////////
     if (configData.contains("PressInZ"))
-        this->setTimeCalcMedStart(configData.getValue<int>("PressInZ"));
+        this->setPressInZ(configData.getValue<int>("PressInZ"));
     //////////////////////////////////////////////////////////////////////////
     if (configData.contains("PressOutZ"))
-        this->setTimeCalcMedEnd(configData.getValue<int>("PressOutZ"));
+        this->setPressOutZ(configData.getValue<int>("PressOutZ"));
 
     //////////////////////////////////////////////////////////////////////////
     //second component
diff --git a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp
new file mode 100644
index 000000000..2f7740174
--- /dev/null
+++ b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp
@@ -0,0 +1,61 @@
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include "Parameter.h"
+#include <basics/config/ConfigurationFile.h>
+
+
+auto RealEq = [](auto value) { 
+#ifdef VF_DOUBLE_ACCURACY
+    return testing::DoubleEq(value); 
+#else 
+    return testing::FloatEq(value);
+#endif
+};
+
+
+TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldThrow)
+{
+    vf::basics::ConfigurationFile config;
+    std::string targetPath = __FILE__;
+    targetPath = targetPath.substr(0, targetPath.find_last_of('/') + 1);
+    targetPath += "parameterTest_emptyfile.cfg";
+
+    config.load(targetPath);
+
+    EXPECT_THROW(Parameter para(config, 1, 0), std::runtime_error);
+}
+
+TEST(ParameterTest, check_outputPath)
+{
+    vf::basics::ConfigurationFile config;
+    std::string targetPath = __FILE__;
+    targetPath = targetPath.substr(0, targetPath.find_last_of('/') + 1);
+    targetPath += "parameterTest.cfg";
+
+    config.load(targetPath);
+
+    Parameter para(config, 1, 0);
+
+    // this two parameters need to be defined in each config file
+    EXPECT_THAT(para.getOutputPath(), testing::Eq("/output/path"));
+    EXPECT_THAT(para.getgeoVec(), testing::Eq("/path/to/grid/geoVec.dat"));
+    // ... all grid files could be tested as well
+
+    // test optional parameter
+    EXPECT_THAT(para.getMaxDev(), testing::Eq(2));
+    EXPECT_THAT(para.getDevices(), testing::ElementsAreArray({2,3}));
+    EXPECT_THAT(para.getOutputPrefix(), testing::Eq("MyPrefix"));
+    EXPECT_THAT(para.getPrintFiles(), testing::Eq(true));
+    EXPECT_THAT(para.getIsGeometryValues(), testing::Eq(true));
+    EXPECT_THAT(para.getCalc2ndOrderMoments(), testing::Eq(true));
+    EXPECT_THAT(para.getCalc3rdOrderMoments(), testing::Eq(true));
+    EXPECT_THAT(para.getCalcHighOrderMoments(), testing::Eq(true));
+    EXPECT_THAT(para.getCalcMedian(), testing::Eq(true));
+    EXPECT_THAT(para.getCalcCp(), testing::Eq(true));
+    EXPECT_THAT(para.getCalcDragLift(), testing::Eq(true));
+}
+
+
+
diff --git a/src/gpu/VirtualFluids_GPU/Parameter/parameterTest.cfg b/src/gpu/VirtualFluids_GPU/Parameter/parameterTest.cfg
new file mode 100644
index 000000000..38d63cc29
--- /dev/null
+++ b/src/gpu/VirtualFluids_GPU/Parameter/parameterTest.cfg
@@ -0,0 +1,16 @@
+# this two parameters need to be defined in each config file
+Path = /output/path
+GridPath = /path/to/grid
+
+# optional parameter
+NumberOfDevices = 2
+Devices = 2 3
+Prefix = MyPrefix
+WriteGrid = true
+GeometryValues = true
+calc2ndOrderMoments = true
+calc3rdOrderMoments = true
+calcHigherOrderMoments = true
+calcMedian = true
+calcCp = true
+calcDrafLift = true
\ No newline at end of file
diff --git a/src/gpu/VirtualFluids_GPU/Parameter/parameterTest_emptyfile.cfg b/src/gpu/VirtualFluids_GPU/Parameter/parameterTest_emptyfile.cfg
new file mode 100644
index 000000000..e69de29bb
-- 
GitLab