Browse Source

Tests: PityTest - update tests

LIB-11
heck 4 years ago
parent
commit
85de5e8111
  1. 2
      test/pitytest11/src/PityUnit.hh
  2. 46
      test/pitytest11/test/test_execmodes.cc
  3. 8
      test/pitytest11/test/test_linear.cc
  4. 81
      test/pitytest11/test/test_processdirs.cc
  5. 2
      test/pitytest11/test/test_swarm.cc
  6. 33
      test/test_group.cc

2
test/pitytest11/src/PityUnit.hh

@ -19,7 +19,7 @@
namespace pEp { namespace pEp {
namespace PityTest11 { namespace PityTest11 {
template<class TestContext> template<class TestContext = void>
class PityUnit { class PityUnit {
public: public:
using TestFunction = const std::function<void(PityUnit<TestContext>&, TestContext*)>; using TestFunction = const std::function<void(PityUnit<TestContext>&, TestContext*)>;

46
test/pitytest11/test/test_execmodes.cc

@ -29,46 +29,36 @@ int main(int argc, char* argv[])
// Subprocess 1 // Subprocess 1
PityUnit<> test1 = PityUnit<>{ &root, PityUnit<> test1 = PityUnit<>{ &root,
"node1", "node1",
[](PityUnit<>& unit, [](PityUnit<>& unit, void* ctx) {
PityModel* model, do_some_work(unit, 200, 10);
PityPerspective* psp) { do_some_work(unit, 200, 10); }, },
nullptr,
nullptr, nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL }; pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test1_1 = PityUnit<>{ &test1, PityUnit<> test1_1 = PityUnit<>{ &test1, "test1.1", [](PityUnit<>& unit, void* ctx) {
"test1.1", do_some_work(unit, 200, 10);
[](PityUnit<>& unit, } };
PityModel* model,
PityPerspective* psp) { do_some_work(unit, 200, 10); } };
PityUnit<> test1_2 = PityUnit<>{ &test1, PityUnit<> test1_2 = PityUnit<>{ &test1, "test1.2", [](PityUnit<>& unit, void* ctx) {
"test1.2", do_some_work(unit, 200, 10);
[](PityUnit<>& unit, } };
PityModel* model,
PityPerspective* psp) { do_some_work(unit, 200, 10); } };
// Subprocess 2 // Subprocess 2
PityUnit<> test2 = PityUnit<>{ &root, PityUnit<> test2 = PityUnit<>{ &root,
"node2", "node2",
[](PityUnit<>& unit, [](PityUnit<>& unit, void* ctx) {
PityModel* model, do_some_work(unit, 200, 10);
PityPerspective* psp) { do_some_work(unit, 200, 10); }, },
nullptr,
nullptr, nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL }; pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test2_1 = PityUnit<>{ &test2, PityUnit<> test2_1 = PityUnit<>{ &test2, "test2.1", [](PityUnit<>& unit, void* ctx) {
"test2.1", do_some_work(unit, 200, 10);
[](PityUnit<>& unit, } };
PityModel* model,
PityPerspective* psp) { do_some_work(unit, 200, 10); } };
PityUnit<> test2_2 = PityUnit<>{ &test2, PityUnit<> test2_2 = PityUnit<>{ &test2, "test2.2", [](PityUnit<>& unit, void* ctx) {
"test2.2", do_some_work(unit, 200, 10);
[](PityUnit<>& unit, } };
PityModel* model,
PityPerspective* psp) { do_some_work(unit, 200, 10); } };
root.run(); root.run();
} }

8
test/pitytest11/test/test_linear.cc

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

81
test/pitytest11/test/test_processdirs.cc

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

@ -29,7 +29,7 @@ void test_node1(PityUnit<PityPerspective>& unit, PityPerspective* psp)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int nodesCount = 3; int nodesCount = 23;
PityModel model{ "test_swarm", nodesCount }; PityModel model{ "test_swarm", nodesCount };
PitySwarm swarm{model}; PitySwarm swarm{model};

33
test/test_group.cc

@ -8,6 +8,7 @@
#include "../src/Adapter.hh" #include "../src/Adapter.hh"
#include "../src/utils.hh" #include "../src/utils.hh"
#include "../src/std_utils.hh"
#include "../src/grp_manager_interface.hh" #include "../src/grp_manager_interface.hh"
#include "../src/grp_driver_engine.hh" #include "../src/grp_driver_engine.hh"
@ -59,7 +60,8 @@ GroupQueryInterface* gq = nullptr;
log("called"); log("called");
log("me: " + pEp::Utils::to_string(_me, false)); log("me: " + pEp::Utils::to_string(_me, false));
log("partner: " + pEp::Utils::to_string(_partner, false)); log("partner: " + pEp::Utils::to_string(_partner, false));
log("Signal: " + string{ ::sync_handshake_signal_to_string(signal) }); log("Signal: " + to_string(signal));
// log("Signal: " + string{ ::sync_handshake_signal_to_string(signal) });
return PEP_STATUS_OK; return PEP_STATUS_OK;
} }
@ -87,8 +89,9 @@ void test_create_bob_partner()
logH2("test_create_bob_partner"); logH2("test_create_bob_partner");
bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob"); bob = ::new_identity("bob@peptest.ch", NULL, PEP_OWN_USERID, "Bob");
assert(bob); assert(bob);
bob->lang[0] = 'c'; // bob->lang[0] = 'c';
bob->lang[1] = 'r'; // bob->lang[1] = 'r';
// status = ::myself(Adapter::session(), bob);
status = ::update_identity(Adapter::session(), bob); status = ::update_identity(Adapter::session(), bob);
log("STATUS: " + status_to_string(status)); log("STATUS: " + status_to_string(status));
assert(!status); assert(!status);
@ -103,6 +106,7 @@ void test_create_carol_partner()
carol->lang[0] = 'f'; carol->lang[0] = 'f';
carol->lang[1] = 'n'; carol->lang[1] = 'n';
status = ::update_identity(Adapter::session(), carol); status = ::update_identity(Adapter::session(), carol);
// status = ::myself(Adapter::session(), carol);
log("STATUS: " + status_to_string(status)); log("STATUS: " + status_to_string(status));
assert(!status); assert(!status);
log("Carol:" + pEp::Utils::to_string(carol, debug_info_full)); log("Carol:" + pEp::Utils::to_string(carol, debug_info_full));
@ -126,8 +130,13 @@ void test_group_create()
assert(grp_ident); assert(grp_ident);
log("grp_ident:" + pEp::Utils::to_string(grp_ident, debug_info_full)); log("grp_ident:" + pEp::Utils::to_string(grp_ident, debug_info_full));
// PEP_STATUS stat = ::myself(Adapter::session(), grp_ident);
// log("STATUS: " + status_to_string(status));
// assert(stat == PEP_STATUS_OK);
// log("grp_ident:" + pEp::Utils::to_string(grp_ident, debug_info_full));
log("adapter_group_create()"); log("adapter_group_create()");
status = gu->adapter_group_create(Adapter::session(), grp_ident, alice, initial_memberlist); status = gu->adapter_group_create(Adapter::session(), grp_ident, alice, nullptr);
log("STATUS: " + status_to_string(status)); log("STATUS: " + status_to_string(status));
assert(!status); assert(!status);
} }
@ -203,14 +212,14 @@ int main(int argc, char** argv)
GroupDriverReplicator gdr{}; GroupDriverReplicator gdr{};
// gu = &gde; gu = &gde;
// gq = nullptr; gq = nullptr;
// gu = &gdd; // gu = &gdd;
// gq = &gdd; // gq = &gdd;
gu = &gdr; // gu = &gdr;
gq = &gdr; // gq = &gdr;
// Setup Test Context // Setup Test Context
@ -224,9 +233,9 @@ int main(int argc, char** argv)
test_group_create(); test_group_create();
logH1("2. Add Bob"); logH1("2. Add Bob");
// test_group_invite_member(*bob); // Fails test_group_invite_member(*bob); // Fails
logH1("3. Add Carol"); logH1("3. Add Carol");
// test_group_invite_member(*carol); test_group_invite_member(*carol);
logH1("4. Remove Carol"); logH1("4. Remove Carol");
test_group_remove_member(*carol); test_group_remove_member(*carol);

Loading…
Cancel
Save