From d3f2e1b27996b74c6f29db1706099b531216fb6b Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 10 Mar 2022 01:30:58 +0100 Subject: [PATCH] Test: add test_identity.cc --- test/test_identity.cc | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/test_identity.cc diff --git a/test/test_identity.cc b/test/test_identity.cc new file mode 100644 index 0000000..713e67b --- /dev/null +++ b/test/test_identity.cc @@ -0,0 +1,75 @@ +#include "../src/prototype.hh" +#include +#include +#include +#include +#include + + +//--------------------------------------------------------------------------------------------- +namespace pEp { + class Identity : public PODStruct<::pEp_identity> { + public: + Identity(bool is_owner, ::pEp_identity** ident_p = nullptr) : + PODStruct<::pEp_identity>(is_owner, ident_p) + { + } + + Identity( + bool is_owner, + const std::string& address = "", + const std::string& username = "", + const std::string& user_id = "", + const std::string& fpr = "") : + PODStruct<::pEp_identity>(is_owner, nullptr) + { + pEpLogClass("called"); + this->address = address; + this->username = username; + this->user_id = user_id; + this->fpr = fpr; + } + + pEp::String address{ is_owner(), &(*data())->address }; + pEp::String fpr{ is_owner(), &(*data())->fpr }; + pEp::String user_id{ is_owner(), &(*data())->user_id }; + pEp::String username{ is_owner(), &(*data())->username }; + pEp::POD<::PEP_comm_type> comm_type{ &(*data())->comm_type }; + //char[3] lang + pEp::POD me{ &(*data())->me }; + pEp::POD major_ver{ &(*data())->major_ver }; + pEp::POD minor_ver{ &(*data())->minor_ver }; + pEp::POD<::PEP_enc_format> enc_format{ &(*data())->enc_format }; + pEp::POD<::identity_flags_t> flags{ &(*data())->flags }; + }; + + template<> + bool PODStruct<::pEp_identity>::log_enabled{ false }; + +} // namespace pEp + +int main() +{ + pEp::Adapter::pEpLog::set_enabled(true); + ::PEP_SESSION session; + setenv("HOME", ".", 1); + ::init(&session, nullptr, nullptr, nullptr); + + // create identity + pEp::Identity id1{ true, "wrong@entry.lol", "wrong", "23", "INVA_FPR" }; + + pEpLog(id1); + id1.username = "alice"; + id1.address = "alice@peptest.org"; + + pEpLog(id1.address); + pEpLog(id1.username); + ::myself(session, id1); + pEpLog(id1); + + pEp::Identity id2{ true, "bob" }; + ::update_identity(session, id2); + pEpLog(id2); + + return 0; +} \ No newline at end of file