Browse Source

Test: PityTest - PityPerspective group and peer handling

LIB-11
heck 3 months ago
parent
commit
f65cd2a996
2 changed files with 55 additions and 5 deletions
  1. +36
    -1
      test/pitytest11/src/PityPerspective.cc
  2. +19
    -4
      test/pitytest11/src/PityPerspective.hh

+ 36
- 1
test/pitytest11/src/PityPerspective.cc View File

@ -5,9 +5,44 @@ namespace pEp {
namespace PityTest11 {
bool PityPerspective::debug_log_enabled = false;
PityPerspective::PityPerspective(const PityModel& model) : model{ model }
PityPerspective::PityPerspective(const PityModel& model) : model{ model }, peerNrAsCpt{ 0 }
{
pEpLogClass("called");
}
TestIdent* PityPerspective::getPeer(const std::string& addr)
{
for (int i = 0; i < peers.size(); i++) {
if (peers.at(i).addr == addr) {
return &peers.at(i);
}
}
throw std::invalid_argument("getPeer(+" + addr + ") - not found");
}
void PityPerspective::setPeerNrAsCpt(int nr)
{
if (nr < peers.size()) {
peerNrAsCpt = nr;
} else {
throw std::invalid_argument("setPeerNrAsCpt(" + std::to_string(nr) + ") - out of range");
}
}
TestIdent& PityPerspective::getCpt()
{
return peers.at(peerNrAsCpt);
}
Group* PityPerspective::getGroup(const std::string& addr)
{
for (int i = 0; i < groups.size(); i++) {
if (groups.at(i).addr == addr) {
return &groups.at(i);
}
}
throw std::invalid_argument("getGroup(" + addr + ") - not found");
}
} // namespace PityTest11
} // namespace pEp

+ 19
- 4
test/pitytest11/src/PityPerspective.hh View File

@ -7,9 +7,19 @@
#include "../../../src/pEpLog.hh"
#include "../../framework/utils.hh"
#include "PityModel.hh"
#include <map>
namespace pEp {
namespace PityTest11 {
// Group
struct Group {
std::string addr;
std::string moderator;
std::vector<TestIdent> members;
};
class PityPerspective {
public:
// Constructors
@ -18,16 +28,20 @@ namespace pEp {
// Lets grant access to the whole model too
const PityModel& model;
TestIdent* getPeer(const std::string& addr);
// Perspective
std::string own_name;
std::string cpt_name;
std::vector<std::string> peers;
// TestIdent* cpt = nullptr;
void setPeerNrAsCpt(int nr);
TestIdent& getCpt();
std::vector<TestIdent> peers;
Test::Utils::pEpIdent own_ident;
Test::Utils::pEpIdent cpt_ident;
// Test::Utils::pEpIdent cpt_ident;
// Groups
std::vector<Test::Utils::Group> own_groups;
Group* getGroup(const std::string& addr);
std::vector<Group> groups;
//Callbacks
//internal logging
@ -35,6 +49,7 @@ namespace pEp {
Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled };
private:
int peerNrAsCpt;
//internal logging
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug;
};


Loading…
Cancel
Save