From f093895fe1297f4f6876d42ea287d07a75b9a796 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 7 Jul 2021 15:10:30 +0200 Subject: [PATCH] Tests: PityTest - Add main header PityTest.hh Also rename PTASSERT to PITYASSERT --- src/AbstractPityUnit.hh | 21 --------------------- src/PityTest.hh | 33 +++++++++++++++++++++++++++++++++ test/test_execmodes.cc | 6 ++---- test/test_linear.cc | 2 +- test/test_processdirs.cc | 22 +++++++++++----------- test/test_swarm.cc | 6 ++---- 6 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 src/PityTest.hh diff --git a/src/AbstractPityUnit.hh b/src/AbstractPityUnit.hh index cc52c45..e2b8729 100644 --- a/src/AbstractPityUnit.hh +++ b/src/AbstractPityUnit.hh @@ -115,27 +115,6 @@ namespace pEp { public: PityAssertException(const std::string& string) : runtime_error(string) {} }; - -#ifndef PTASSERT - #define PTASSERT(condition, msg) \ - do { \ - if (!(condition)) { \ - throw PityAssertException(msg); \ - } \ - } while (0) -#endif - -#ifndef PTASSERT_EXCEPT - #define PTASSERT_EXCEPT(func) \ - do { \ - try { \ - (func); \ - PTASSERT(false); \ - } catch (const exception& e) { \ - } \ - } while (0) -#endif - }; // namespace PityTest11 }; // namespace pEp diff --git a/src/PityTest.hh b/src/PityTest.hh new file mode 100644 index 0000000..17dee59 --- /dev/null +++ b/src/PityTest.hh @@ -0,0 +1,33 @@ +// This file is under GNU General Public License 3.0 +// see LICENSE.txt + +#ifndef PITYTEST_PITYTEST_HH +#define PITYTEST_PITYTEST_HH + +#include "PityUnit.hh" +#include "PityModel.hh" +#include "PitySwarm.hh" +#include "PityPerspective.hh" + +#ifndef PITYASSERT + #define PITYASSERT(condition, msg) \ + do { \ + if (!(condition)) { \ + throw PityAssertException(msg); \ + } \ + } while (0) +#endif + +#ifndef PITYASSERT_THROWS + #define PITYASSERT_THROWS(func, msg) \ + do { \ + try { \ + (func); \ + PITYASSERT(false, msg); \ + } catch (const std::exception& e) { \ + } catch (...) { \ + } \ + } while (0) +#endif + +#endif \ No newline at end of file diff --git a/test/test_execmodes.cc b/test/test_execmodes.cc index 11eff90..37c59a1 100644 --- a/test/test_execmodes.cc +++ b/test/test_execmodes.cc @@ -1,6 +1,4 @@ -#include "../src/PityUnit.hh" -#include "../src/PityModel.hh" -#include "../src/PityPerspective.hh" +#include "../src/PityTest.hh" #include "../../../src/utils.hh" #include @@ -34,7 +32,7 @@ int main(int argc, char* argv[]) TestUnit::debug_log_enabled = false; CTXExecmodes ctxe; ctxe.sleepmilis = 100; - ctxe.rep_count = 3; + ctxe.rep_count = 100; // Utils::readKey(); // The RootNode is the diff --git a/test/test_linear.cc b/test/test_linear.cc index e5ac530..51820ff 100644 --- a/test/test_linear.cc +++ b/test/test_linear.cc @@ -1,4 +1,4 @@ -#include "../src/PityUnit.hh" +#include "../src/PityTest.hh" #include #include diff --git a/test/test_processdirs.cc b/test/test_processdirs.cc index 77aa821..ee91a96 100644 --- a/test/test_processdirs.cc +++ b/test/test_processdirs.cc @@ -1,4 +1,4 @@ -#include "../src/PityUnit.hh" +#include "../src/PityTest.hh" #include #include @@ -20,14 +20,14 @@ int main(int argc, char* argv[]) // 1 PityUnit<> test1 = PityUnit<>{ root, "node 1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT( + PITYASSERT( mynode.processDir() == "./pitytest_data/test_processdirs/", ""); return 0; } }; PityUnit<> test1_1 = PityUnit<>{ test1, "node 1.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT( + PITYASSERT( mynode.processDir() == "./pitytest_data/test_processdirs/", ""); return 0; @@ -35,7 +35,7 @@ int main(int argc, char* argv[]) // 2 PityUnit<> test2 = PityUnit<>{ root, "node 2", [](PityUnit<>& mynode, void* ctx) { - PTASSERT( + PITYASSERT( mynode.processDir() == "./pitytest_data/test_processdirs/", ""); return 0; @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) test2, "node 2.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_2_1/", ""); + PITYASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_2_1/", ""); return 0; }, nullptr, @@ -53,7 +53,7 @@ int main(int argc, char* argv[]) PityUnit<> test2_1_1 = PityUnit<>{ test2_1, "node 2.1.1", [](PityUnit<> mynode, void* ctx) { - PTASSERT( + PITYASSERT( mynode.processDir() == "./pitytest_data/test_processdirs/node_2_1/", ""); @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) root, "node 3", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); + PITYASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); return 0; }, nullptr, @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) }; PityUnit<> test3_1 = PityUnit<>{ test3, "node 3.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT( + PITYASSERT( mynode.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); @@ -82,7 +82,7 @@ int main(int argc, char* argv[]) } }; PityUnit<> test3_1_1 = PityUnit<>{ test3_1, "node 3.1.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT( + PITYASSERT( mynode.processDir() == "./pitytest_data/test_processdirs/node_3/", ""); @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) test3_1_1, "node 3.1.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", ""); + PITYASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", ""); return 0; }, nullptr, @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) test3_1_1_1, "node 3.1.1.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", ""); + PITYASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/", ""); return 0; } }; diff --git a/test/test_swarm.cc b/test/test_swarm.cc index 9d35bc2..61102ad 100644 --- a/test/test_swarm.cc +++ b/test/test_swarm.cc @@ -1,7 +1,4 @@ -#include "../src/PityUnit.hh" -#include "../src/PityModel.hh" -#include "../src/PitySwarm.hh" -#include "../src/PityPerspective.hh" +#include "../src/PityTest.hh" using namespace pEp; using namespace pEp::Adapter; @@ -26,6 +23,7 @@ int test_node1(PityUnit& unit, PityPerspective* ctx) unit.log("MSG RX:" + unit.transport()->receiveMsg()); } } + return 0; } int main(int argc, char* argv[])