Browse Source

Tests: PityTest - add pEpidents to Perspective own/cpt AND change PTASSERT to take another param "reason"

master
heck 4 years ago
parent
commit
e0fd8c32bd
  1. 8
      src/PityPerspective.hh
  2. 4
      src/PitySwarm.cc
  3. 8
      src/PityUnit.hh
  4. 20
      test/test_processdirs.cc
  5. 4
      test/test_swarm.cc

8
src/PityPerspective.hh

@ -5,6 +5,7 @@
#define PITYTEST_PITYPERSPECTIVE_HH #define PITYTEST_PITYPERSPECTIVE_HH
#include "../../../src/pEpLog.hh" #include "../../../src/pEpLog.hh"
#include "../../framework/utils.hh"
#include "PityModel.hh" #include "PityModel.hh"
namespace pEp { namespace pEp {
@ -18,10 +19,13 @@ namespace pEp {
PityModel& model; PityModel& model;
// Perspective // Perspective
std::string name; std::string own_name;
std::string partner; std::string cpt_name;
std::vector<std::string> peers; std::vector<std::string> peers;
Test::Utils::pEpIdent own_ident;
Test::Utils::pEpIdent cpt_ident;
//internal logging //internal logging
static bool debug_log_enabled; static bool debug_log_enabled;
Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled };

4
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 // 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) 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 // Default partner is next node, its a circle
int partner_node_index = (node_nr + 1) % model.nodes().size(); 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 // Create peers, everyone but me
auto nodes = model.nodes(); auto nodes = model.nodes();

8
src/PityUnit.hh

@ -63,7 +63,8 @@ namespace pEp {
// Util // Util
void recreateDirsRecursively(); 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 //Transport
PityTransport* transport() const; PityTransport* transport() const;
@ -132,11 +133,12 @@ namespace pEp {
PityAssertException(const std::string& string) : runtime_error(string) {} PityAssertException(const std::string& string) : runtime_error(string) {}
}; };
#ifndef PTASSERT #ifndef PTASSERT
#define PTASSERT(condition) \ #define PTASSERT(condition, msg) \
do { \ do { \
if (!(condition)) { \ if (!(condition)) { \
throw PityAssertException("AssertError"); \ throw PityAssertException(msg); \
} \ } \
} while (0) } while (0)
#endif #endif

20
test/test_processdirs.cc

@ -21,26 +21,26 @@ int main(int argc, char* argv[])
// 1 // 1
PityUnit<> test1 = PityUnit<>{ &root, "node 1", [](PityUnit<>& mynode, void* ctx) { PityUnit<> test1 = PityUnit<>{ &root, "node 1", [](PityUnit<>& mynode, void* ctx) {
PTASSERT( 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) { PityUnit<> test1_1 = PityUnit<>{ &test1, "node 1.1", [](PityUnit<>& mynode, void* ctx) {
PTASSERT( PTASSERT(
mynode.processDir() == mynode.processDir() ==
"./pitytest_data/test_processdirs/"); "./pitytest_data/test_processdirs/","");
} }; } };
// 2 // 2
PityUnit<> test2 = PityUnit<>{ &root, "node 2", [](PityUnit<>& mynode, void* ctx) { PityUnit<> test2 = PityUnit<>{ &root, "node 2", [](PityUnit<>& mynode, void* ctx) {
PTASSERT( PTASSERT(
mynode.processDir() == "./pitytest_data/test_processdirs/"); mynode.processDir() == "./pitytest_data/test_processdirs/","");
} }; } };
PityUnit<> test2_1 = PityUnit<>{ PityUnit<> test2_1 = PityUnit<>{
&test2, &test2,
"node 2.1", "node 2.1",
[](PityUnit<>& mynode, void* ctx) { [](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, nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL 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) { PityUnit<> test2_1_1 = PityUnit<>{ &test2_1, "node 2.1.1", [](PityUnit<> mynode, void* ctx) {
PTASSERT( PTASSERT(
mynode.processDir() == 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, &root,
"node 3", "node 3",
[](PityUnit<>& mynode, void* ctx) { [](PityUnit<>& mynode, void* ctx) {
PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3/"); PTASSERT(mynode.processDir() == "./pitytest_data/test_processdirs/node_3/","");
}, },
nullptr, nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL 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) { PityUnit<> test3_1 = PityUnit<>{ &test3, "node 3.1", [](PityUnit<>& mynode, void* ctx) {
PTASSERT( PTASSERT(
mynode.processDir() == 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) { PityUnit<> test3_1_1 = PityUnit<>{ &test3_1, "node 3.1.1", [](PityUnit<>& mynode, void* ctx) {
PTASSERT( PTASSERT(
mynode.processDir() == mynode.processDir() ==
"./pitytest_data/test_processdirs/node_3/"); "./pitytest_data/test_processdirs/node_3/","");
} }; } };
PityUnit<> test3_1_1_1 = PityUnit<>{ PityUnit<> test3_1_1_1 = PityUnit<>{
&test3_1_1, &test3_1_1,
"node 3.1.1", "node 3.1.1",
[](PityUnit<>& mynode, void* ctx) { [](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, nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL PityUnit<>::ExecutionMode::PROCESS_PARALLEL
@ -91,7 +91,7 @@ int main(int argc, char* argv[])
&test3_1_1_1, &test3_1_1_1,
"node 3.1.1.1", "node 3.1.1.1",
[](PityUnit<>& mynode, void* ctx) { [](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/","");
} }
}; };

4
test/test_swarm.cc

@ -10,8 +10,8 @@ using namespace pEp::PityTest11;
void test_node1(PityUnit<PityPerspective>& unit, PityPerspective* ctx) void test_node1(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
{ {
unit.log("ModelName:" + ctx->model.getName()); unit.log("ModelName:" + ctx->model.getName());
unit.log("perspective name:" + ctx->name); unit.log("perspective name:" + ctx->own_name);
unit.log("perspective partner:" + ctx->partner); unit.log("perspective partner:" + ctx->cpt_name);
unit.log("HOME: " + std::string(getenv("HOME"))); unit.log("HOME: " + std::string(getenv("HOME")));
std::string msg = "Message from: " + unit.getPathShort(); std::string msg = "Message from: " + unit.getPathShort();

Loading…
Cancel
Save