[AMBClient] - added time sync message
[profile/ivi/automotive-message-broker.git] / tests / testProtocolClient.cpp
1 #include "testProtocolCommon.h"
2
3 #include <debugout.h>
4 #include <jsonprotocol.h>
5
6 #include <QLocalSocket>
7 #include <QLocalServer>
8 #include <QCoreApplication>
9 #include <QObject>
10
11 #include <memory>
12
13 void runTest(amb::AmbRemoteClient *c)
14 {
15         DebugOut(0) << "calling client->list()" << endl;
16         c->list([](std::vector<amb::Object::ObjectPtr> supported)
17         {
18                 DebugOut(0) << "list call reply" << endl;
19                 g_assert(supported.size() == 2);
20         });
21
22         DebugOut(0) << "calling client->get()" << endl;
23         c->get("interface1", [&c](amb::Object::ObjectPtr obj)
24         {
25                 DebugOut(0) << "get call reply" << endl;
26                 g_assert(obj->size() == 2);
27
28                 obj->emplace("vehicleSpeed", amb::make_shared(new VehicleProperty::VehicleSpeedType(69)));
29
30                 c->set("interface1", obj, [](bool s)
31                 {
32                         DebugOut(0) << "set call reply status: " << (s ? "success!" : "fail") << endl;
33                         g_assert(s);
34                 });
35         });
36 }
37
38 int main(int argc, char** argv)
39 {
40         DebugOut::setDebugThreshhold(7);
41         DebugOut::setThrowErr(true);
42         DebugOut::setThrowWarn(false);
43
44         DebugOut(0) << "Testing AMB json server/client" << endl;
45
46         QCoreApplication app(argc, argv);
47
48         DomainSocket socket;
49
50         socket.open();
51
52         socket.getSocket()->waitForConnected();
53
54         DebugOut(0) << "We are connected!" << endl;
55
56         amb::AmbRemoteClient client(&socket);
57
58         runTest(&client);
59
60         app.exec();
61 }