Browse Source

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

LIB-11
heck 11 months ago
parent
commit
5dfdce0a0f
7 changed files with 32 additions and 26 deletions
  1. +6
    -2
      test/pitytest11/src/PityPerspective.hh
  2. +2
    -2
      test/pitytest11/src/PitySwarm.cc
  3. +5
    -3
      test/pitytest11/src/PityUnit.hh
  4. +10
    -10
      test/pitytest11/test/test_processdirs.cc
  5. +2
    -2
      test/pitytest11/test/test_swarm.cc
  6. +4
    -4
      test/test_template_swarm_multi.cc
  7. +3
    -3
      test/test_template_swarm_single.cc

+ 6
- 2
test/pitytest11/src/PityPerspective.hh View File

@ -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<std::string> 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 };


+ 2
- 2
test/pitytest11/src/PitySwarm.cc View File

@ -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();


+ 5
- 3
test/pitytest11/src/PityUnit.hh View File

@ -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


+ 10
- 10
test/pitytest11/test/test_processdirs.cc View File

@ -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/","");
}
};


+ 2
- 2
test/pitytest11/test/test_swarm.cc View File

@ -10,8 +10,8 @@ using namespace pEp::PityTest11;
void test_node1(PityUnit<PityPerspective>& 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();


+ 4
- 4
test/test_template_swarm_multi.cc View File

@ -24,7 +24,7 @@ using namespace pEp::PityTest11;
// This is the 1st test unit
void test_func1(PityUnit<PityPerspective> &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<PityPerspective> &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<PityPerspective> &pity, PityPerspective *ctx)
{
pity.log(ctx->name);
PTASSERT(false);
pity.log(ctx->own_name);
PTASSERT(false,"");
}


+ 3
- 3
test/test_template_swarm_single.cc View File

@ -32,14 +32,14 @@ void test_func1(PityUnit<PityPerspective> &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<PityPerspective> &pity, PityPerspective *ctx)
{
pity.log(ctx->name);
PTASSERT(false);
pity.log(ctx->own_name);
PTASSERT(false,"");
}


Loading…
Cancel
Save