From 182dd4271c96305c69e0a950a4cdada38d39eac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 7 Apr 2023 20:23:58 +0200 Subject: Test: direct messages to peer --- src/main.cpp | 26 ++++++++++++++++++++++++++ test/message.test | 29 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/message.test diff --git a/src/main.cpp b/src/main.cpp index edf68d7..aa70c48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -270,6 +271,22 @@ void startServer(const vector &) conts->onResponse(bind(confirmPairing, "contact-response", _1, _2, _3)); services.push_back(move(conts)); + auto dms = make_unique(); + dms->onUpdate([](const DirectMessageThread & thread, ssize_t, ssize_t) { + ostringstream ss; + + string name = ""; + if (auto opt = thread.peer().name()) + name = *opt; + + ss << "dm-received" + << " from " << name + << " text " << thread.at(0).text() + ; + printLine(ss.str()); + }); + services.push_back(move(dms)); + services.push_back(make_unique()); server.emplace(*h, move(services)); @@ -498,6 +515,14 @@ void contactSetName(const vector & args) printLine("contact-set-name-done"); } +void dmSendPeer(const vector & args) +{ + server->svc().send( + server->identity().finalOwner(), + getPeer(args.at(0)).peer, + args.at(1)); +} + vector commands = { { "store", store }, { "stored-generation", storedGeneration }, @@ -521,6 +546,7 @@ vector commands = { { "contact-reject", contactReject }, { "contact-list", contactList }, { "contact-set-name", contactSetName }, + { "dm-send-peer", dmSendPeer }, }; } diff --git a/test/message.test b/test/message.test new file mode 100644 index 0000000..9567611 --- /dev/null +++ b/test/message.test @@ -0,0 +1,29 @@ +test DirectMessage: + spawn as p1 + spawn as p2 + send "create-identity Device1 Owner1" to p1 + send "create-identity Device2 Owner2" to p2 + send "start-server" to p1 + send "start-server" to p2 + + expect from p1: + /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2 + /peer $peer1_2 id Device2 Owner2/ + + expect from p2: + /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1 + /peer $peer2_1 id Device1 Owner1/ + + for i in [1..2]: + send "dm-send-peer $peer1_2 hello$i" to p1 + expect /dm-received from Owner1 text hello$i/ from p2 + + for i in [1..2]: + send "dm-send-peer $peer1_2 hello$i" to p2 + expect /dm-received from Owner2 text hello$i/ from p1 + + for i in [3..4]: + send "dm-send-peer $peer1_2 hello$i" to p1 + expect /dm-received from Owner1 text hello$i/ from p2 + send "dm-send-peer $peer1_2 hello$i" to p2 + expect /dm-received from Owner2 text hello$i/ from p1 -- cgit v1.2.3