From 5dfdce0a0fb47faf06c01045b44b08d454d5b4da Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 17 Jun 2021 00:18:13 +0200 Subject: [PATCH] Tests: PityTest - add pEpidents to Perspective own/cpt AND change PTASSERT to take another param "reason" --- test/pitytest11/src/PityPerspective.hh | 8 ++++++-- test/pitytest11/src/PitySwarm.cc | 4 ++-- test/pitytest11/src/PityUnit.hh | 8 +++++--- test/pitytest11/test/test_processdirs.cc | 20 ++++++++++---------- test/pitytest11/test/test_swarm.cc | 4 ++-- test/test_template_swarm_multi.cc | 8 ++++---- test/test_template_swarm_single.cc | 6 +++--- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/test/pitytest11/src/PityPerspective.hh b/test/pitytest11/src/PityPerspective.hh index 2e4f445..2c155f4 100644 --- a/test/pitytest11/src/PityPerspective.hh +++ b/test/pitytest11/src/PityPerspective.hh @@ -5,6 +5,7 @@ #define PITYTEST_PITYPERSPECTIVE_HH #include "../../../src/pEpLog.hh" +#include "../../framework/utils.hh" #include "PityModel.hh" namespace pEp { @@ -18,10 +19,13 @@ namespace pEp { PityModel& model; // Perspective - std::string name; - std::string partner; + std::string own_name; + std::string cpt_name; std::vector peers; + Test::Utils::pEpIdent own_ident; + Test::Utils::pEpIdent cpt_ident; + //internal logging static bool debug_log_enabled; Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; diff --git a/test/pitytest11/src/PitySwarm.cc b/test/pitytest11/src/PitySwarm.cc index a9ee1e6..b2de3bf 100644 --- a/test/pitytest11/src/PitySwarm.cc +++ b/test/pitytest11/src/PitySwarm.cc @@ -16,11 +16,11 @@ namespace pEp { // The perspective currently is complete defined by specifying a node, since there is a 1-1 node/ident relationship currently void PitySwarm::_createPerspective(const PityModel& model, PityPerspective* psp, int node_nr) { - psp->name = model.nodeNr(node_nr)->getName(); + psp->own_name = model.nodeNr(node_nr)->getName(); // Default partner is next node, its a circle int partner_node_index = (node_nr + 1) % model.nodes().size(); - psp->partner = model.nodes().at(partner_node_index)->getName(); + psp->cpt_name = model.nodes().at(partner_node_index)->getName(); // Create peers, everyone but me auto nodes = model.nodes(); diff --git a/test/pitytest11/src/PityUnit.hh b/test/pitytest11/src/PityUnit.hh index bda4e28..50d880d 100644 --- a/test/pitytest11/src/PityUnit.hh +++ b/test/pitytest11/src/PityUnit.hh @@ -63,7 +63,8 @@ namespace pEp { // Util void recreateDirsRecursively(); - static std::string _normalizeName(std::string name); //TODO HACK in PityTransport this should be private + static std::string _normalizeName( + std::string name); //TODO HACK in PityTransport this should be private //Transport PityTransport* transport() const; @@ -132,11 +133,12 @@ namespace pEp { PityAssertException(const std::string& string) : runtime_error(string) {} }; + #ifndef PTASSERT - #define PTASSERT(condition) \ + #define PTASSERT(condition, msg) \ do { \ if (!(condition)) { \ - throw PityAssertException("AssertError"); \ + throw PityAssertException(msg); \ } \ } while (0) #endif diff --git a/test/pitytest11/test/test_processdirs.cc b/test/pitytest11/test/test_processdirs.cc index ad823d3..4815a7a 100644 --- a/test/pitytest11/test/test_processdirs.cc +++ b/test/pitytest11/test/test_processdirs.cc @@ -21,26 +21,26 @@ int main(int argc, char* argv[]) // 1 PityUnit<> test1 = PityUnit<>{ &root, "node 1", [](PityUnit<>& mynode, void* ctx) { PTASSERT( - mynode.processDir() == "./pitytest_data/test_processdirs/"); + mynode.processDir() == "./pitytest_data/test_processdirs/",""); } }; PityUnit<> test1_1 = PityUnit<>{ &test1, "node 1.1", [](PityUnit<>& mynode, void* ctx) { PTASSERT( mynode.processDir() == - "./pitytest_data/test_processdirs/"); + "./pitytest_data/test_processdirs/",""); } }; // 2 PityUnit<> test2 = PityUnit<>{ &root, "node 2", [](PityUnit<>& mynode, void* ctx) { PTASSERT( - mynode.processDir() == "./pitytest_data/test_processdirs/"); + mynode.processDir() == "./pitytest_data/test_processdirs/",""); } }; PityUnit<> test2_1 = PityUnit<>{ &test2, "node 2.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_2_1/"); + PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_2_1/",""); }, nullptr, pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) PityUnit<> test2_1_1 = PityUnit<>{ &test2_1, "node 2.1.1", [](PityUnit<> mynode, void* ctx) { PTASSERT( mynode.processDir() == - "./pitytest_data/test_processdirs/node_2_1/"); + "./pitytest_data/test_processdirs/node_2_1/",""); } }; @@ -59,7 +59,7 @@ int main(int argc, char* argv[]) &root, "node 3", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3/"); + PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3/",""); }, nullptr, PityUnit<>::ExecutionMode::PROCESS_PARALLEL @@ -68,20 +68,20 @@ int main(int argc, char* argv[]) PityUnit<> test3_1 = PityUnit<>{ &test3, "node 3.1", [](PityUnit<>& mynode, void* ctx) { PTASSERT( mynode.processDir() == - "./pitytest_data/test_processdirs/node_3/"); + "./pitytest_data/test_processdirs/node_3/",""); } }; PityUnit<> test3_1_1 = PityUnit<>{ &test3_1, "node 3.1.1", [](PityUnit<>& mynode, void* ctx) { PTASSERT( mynode.processDir() == - "./pitytest_data/test_processdirs/node_3/"); + "./pitytest_data/test_processdirs/node_3/",""); } }; PityUnit<> test3_1_1_1 = PityUnit<>{ &test3_1_1, "node 3.1.1", [](PityUnit<>& mynode, void* ctx) { - PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/"); + PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/",""); }, nullptr, PityUnit<>::ExecutionMode::PROCESS_PARALLEL @@ -91,7 +91,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/"); + PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3_1_1/",""); } }; diff --git a/test/pitytest11/test/test_swarm.cc b/test/pitytest11/test/test_swarm.cc index c3a075f..bce3510 100644 --- a/test/pitytest11/test/test_swarm.cc +++ b/test/pitytest11/test/test_swarm.cc @@ -10,8 +10,8 @@ using namespace pEp::PityTest11; void test_node1(PityUnit& unit, PityPerspective* ctx) { unit.log("ModelName:" + ctx->model.getName()); - unit.log("perspective name:" + ctx->name); - unit.log("perspective partner:" + ctx->partner); + unit.log("perspective name:" + ctx->own_name); + unit.log("perspective partner:" + ctx->cpt_name); unit.log("HOME: " + std::string(getenv("HOME"))); std::string msg = "Message from: " + unit.getPathShort(); diff --git a/test/test_template_swarm_multi.cc b/test/test_template_swarm_multi.cc index 4aec53a..8e0cddb 100644 --- a/test/test_template_swarm_multi.cc +++ b/test/test_template_swarm_multi.cc @@ -24,7 +24,7 @@ using namespace pEp::PityTest11; // This is the 1st test unit void test_func1(PityUnit &pity, PityPerspective *ctx) { - pity.log(ctx->name); + pity.log(ctx->own_name); pity.log("getName: " + pity.getName()); pity.log("getPath: " +pity.getPath()); pity.log("getPathShort: " +pity.getPathShort()); @@ -33,14 +33,14 @@ void test_func1(PityUnit &pity, PityPerspective *ctx) pity.log("getGlobalRootDir: " +pity.getGlobalRootDir()); pity.log("to_string: " +pity.to_string()); - PTASSERT(true); + PTASSERT(true,""); } // This is the 2nd test unit void test_func2(PityUnit &pity, PityPerspective *ctx) { - pity.log(ctx->name); - PTASSERT(false); + pity.log(ctx->own_name); + PTASSERT(false,""); } diff --git a/test/test_template_swarm_single.cc b/test/test_template_swarm_single.cc index f546be2..46a5a48 100644 --- a/test/test_template_swarm_single.cc +++ b/test/test_template_swarm_single.cc @@ -32,14 +32,14 @@ void test_func1(PityUnit &pity, PityPerspective *ctx) pity.log("processDir: " + pity.processDir()); pity.log("getGlobalRootDir: " + pity.getGlobalRootDir()); pity.log("to_string: " + pity.to_string(false)); - PTASSERT(true); + PTASSERT(true,""); } // This is the 2nd test unit void test_func2(PityUnit &pity, PityPerspective *ctx) { - pity.log(ctx->name); - PTASSERT(false); + pity.log(ctx->own_name); + PTASSERT(false,""); }