Browse Source

Test: update all tests to return int

LIB-11
heck 4 years ago
parent
commit
1a46228b42
  1. 5
      test/pitytest11/src/PitySwarm.cc
  2. 2
      test/pitytest11/src/PitySwarm.hh
  3. 6
      test/pitytest11/test/test_linear.cc
  4. 37
      test/pitytest11/test/test_processdirs.cc
  5. 2
      test/pitytest11/test/test_swarm.cc
  6. 6
      test/test_template_swarm_multi.cc
  7. 6
      test/test_template_swarm_single.cc
  8. 22
      test/test_tofu.cc

5
test/pitytest11/src/PitySwarm.cc

@ -41,11 +41,12 @@ namespace pEp {
}
}
void PitySwarm::_init_process(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
int PitySwarm::_init_process(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
{
std::cout << "PROC INIT" << std::endl;
std::cout << "Node init, setting $HOME" << std::endl;
std::string home = unit.processDir();
setenv("HOME", home.c_str(), true);
return 0;
}
PitySwarm::PitySwarm(PityModel& model) : _model{ model }

2
test/pitytest11/src/PitySwarm.hh

@ -34,7 +34,7 @@ namespace pEp {
private:
// methods
void _createPerspective(const PityModel& model, PityPerspective* psp, int node_nr);
void _init_process(PityUnit<PityPerspective>& unit, PityPerspective* ctx);
int _init_process(PityUnit<PityPerspective>& unit, PityPerspective* ctx);
// fields
PityModel& _model;

6
test/pitytest11/test/test_linear.cc

@ -35,16 +35,18 @@ public:
Car car;
};
void test_setGear(PityUnit<CarTestModel>& node, CarTestModel* ctx)
int test_setGear(PityUnit<CarTestModel>& node, CarTestModel* ctx)
{
int gear = 1;
node.log("Setting gear to: " + to_string(gear));
ctx->car.setGear(gear);
return 0;
}
void test_drive(PityUnit<CarTestModel>& node, CarTestModel* ctx)
int test_drive(PityUnit<CarTestModel>& node, CarTestModel* ctx)
{
ctx->car.drive();
return 0;
}
int main(int argc, char* argv[])

37
test/pitytest11/test/test_processdirs.cc

@ -21,26 +21,32 @@ 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/",
"");
return 0;
} };
PityUnit<> test1_1 = PityUnit<>{ &test1, "node 1.1", [](PityUnit<>& mynode, void* ctx) {
PTASSERT(
mynode.processDir() ==
"./pitytest_data/test_processdirs/","");
mynode.processDir() == "./pitytest_data/test_processdirs/",
"");
return 0;
} };
// 2
PityUnit<> test2 = PityUnit<>{ &root, "node 2", [](PityUnit<>& mynode, void* ctx) {
PTASSERT(
mynode.processDir() == "./pitytest_data/test_processdirs/","");
mynode.processDir() == "./pitytest_data/test_processdirs/",
"");
return 0;
} };
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/", "");
return 0;
},
nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL
@ -50,7 +56,9 @@ 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/",
"");
return 0;
} };
@ -59,7 +67,8 @@ 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/", "");
return 0;
},
nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL
@ -68,20 +77,25 @@ 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/",
"");
return 0;
} };
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/",
"");
return 0;
} };
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/", "");
return 0;
},
nullptr,
PityUnit<>::ExecutionMode::PROCESS_PARALLEL
@ -91,7 +105,8 @@ 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/", "");
return 0;
}
};

2
test/pitytest11/test/test_swarm.cc

@ -7,7 +7,7 @@ using namespace pEp;
using namespace pEp::Adapter;
using namespace pEp::PityTest11;
void test_node1(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
int test_node1(PityUnit<PityPerspective>& unit, PityPerspective* ctx)
{
unit.log("ModelName:" + ctx->model.getName());
unit.log("perspective name:" + ctx->own_name);

6
test/test_template_swarm_multi.cc

@ -22,7 +22,7 @@ using namespace pEp::PityTest11;
// Test template for 3 nodes (processes) running the same 2 tests each in their own environment in parallel
// This is the 1st test unit
void test_func1(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
int test_func1(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{
pity.log(ctx->own_name);
pity.log("getName: " + pity.getName());
@ -34,13 +34,15 @@ void test_func1(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
pity.log("to_string: " +pity.to_string());
PTASSERT(true,"");
return 0;
}
// This is the 2nd test unit
void test_func2(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
int test_func2(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{
pity.log(ctx->own_name);
PTASSERT(false,"");
return 0;
}

6
test/test_template_swarm_single.cc

@ -22,7 +22,7 @@ using namespace pEp::PityTest11;
// Test template for a single process with 2 test units that run in sequence
// This is the 1st test unit
void test_func1(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
int test_func1(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{
// here some example values from the PityUnit
pity.log("getName: " + pity.getName());
@ -33,13 +33,15 @@ void test_func1(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
pity.log("getGlobalRootDir: " + pity.getGlobalRootDir());
pity.log("to_string: " + pity.to_string(false));
PTASSERT(true,"");
return 0;
}
// This is the 2nd test unit
void test_func2(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
int test_func2(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{
pity.log(ctx->own_name);
PTASSERT(false,"");
return 0;
}

22
test/test_tofu.cc

@ -80,6 +80,13 @@ void reply(PityUnit<PityPerspective> &pity, PityPerspective *ctx, MinMsgRx msg_o
// Encrypt
pity.log("TX message - BEFORE encrypt: \n" + Utils::to_string(msg.get()));
// pEpIdent tmp_ident = createRawIdent(addr_orig);
// tmp_ident.get()->user_id = strdup("23");
// PEP_STATUS status = ::update_identity(Adapter::session(),tmp_ident.get());
// throw_status(status);
// pity.log("IDENTZZZ:" + Utils::to_string(tmp_ident.get()));
EncryptResult eres = encryptMessage(msg);
pEpMessage msg_encrypted = std::get<0>(eres);
did_tx_encrypted = std::get<2>(eres);
@ -93,7 +100,7 @@ void reply(PityUnit<PityPerspective> &pity, PityPerspective *ctx, MinMsgRx msg_o
pity.transport()->sendMsg(addr_orig, mime_data_tx);
}
void tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
int tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
{
pity.log("Model : " + ctx->model.getName());
pity.log("myself : " + ctx->own_name);
@ -111,15 +118,16 @@ void tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
send(pity, ctx);
}
MinMsgRx rx_msg = receive(pity,ctx);
reply(pity,ctx, rx_msg);
MinMsgRx rx_msg = receive(pity, ctx);
reply(pity, ctx, rx_msg);
if(!init) {
receive(pity,ctx);
if (!init) {
receive(pity, ctx);
}
PTASSERT(did_tx_encrypted, "could never send encrypted");
PTASSERT(did_rx_encrypted, "no encrypted msg received");
return 0;
}
@ -132,10 +140,10 @@ int main(int argc, char *argv[])
PitySwarm swarm{ model };
swarm.addTestUnit(0, "tofu1", [](PityUnit<PityPerspective> &unit, PityPerspective *ctx) {
tofu(unit, ctx, true);
return tofu(unit, ctx, true);
});
swarm.addTestUnit(1, "tofu2", [](PityUnit<PityPerspective> &unit, PityPerspective *ctx) {
tofu(unit, ctx, false);
return tofu(unit, ctx, false);
});
swarm.run();

Loading…
Cancel
Save