From e0fd8c32bdbf3e94067488920c17bfc600fba980 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" --- src/PityPerspective.hh | 8 ++++++-- src/PitySwarm.cc | 4 ++-- src/PityUnit.hh | 8 +++++--- test/test_processdirs.cc | 20 ++++++++++---------- test/test_swarm.cc | 4 ++-- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/PityPerspective.hh b/src/PityPerspective.hh index 2e4f445..2c155f4 100644 --- a/src/PityPerspective.hh +++ b/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/src/PitySwarm.cc b/src/PitySwarm.cc index a9ee1e6..b2de3bf 100644 --- a/src/PitySwarm.cc +++ b/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/src/PityUnit.hh b/src/PityUnit.hh index bda4e28..50d880d 100644 --- a/src/PityUnit.hh +++ b/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/test_processdirs.cc b/test/test_processdirs.cc index ad823d3..4815a7a 100644 --- a/test/test_processdirs.cc +++ b/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/test_swarm.cc b/test/test_swarm.cc index c3a075f..bce3510 100644 --- a/test/test_swarm.cc +++ b/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();