efl
476 строк · 14.8 Кб
1/*
2* Copyright 2019 by its authors. See AUTHORS.
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16#ifdef HAVE_CONFIG_H17# include <config.h>18#endif19
20#include <algorithm>21#include <iostream>22
23#include <Ecore.hh>24#include <Eldbus.hh>25#include <eldbus_freedesktop.hh>26
27#include "eldbus_cxx_suite.h"28
29const char g_bus[] = "org.Enlightenment.TestCxx";30const char g_path[] = "/org/enlightenment";31const char g_interface[] = "org.enlightenment.FakeServer";32
33static void34on_name_request(std::error_code const& ec, efl::eldbus::const_message35, efl::eldbus::pending, unsigned int reply)36{
37if(!ec)38{39if(reply != ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)40{41printf("error name already in use\n");42return;43}44}45}
46
47EFL_START_TEST(eldbus_cxx_client)48{
49namespace edb = efl::eldbus;50
51efl::ecore::ecore_init ecore_init;52edb::eldbus_init init;53
54edb::connection c_(edb::session);55
56namespace es = edb::service;57
58bool expected_bool = true;59char expected_byte = 0xAA;60uint32_t expected_uint32 = 0xFFFFFFFF;61int32_t expected_int32 = -1;62int16_t expected_int16 = -1;63double expected_double = 3.1415926;64std::string expected_string = "expected string";65
66edb::service_interface iface = edb::service_interface_register67(c_, g_path, g_interface68, es::method("SendBool"69, [expected_bool] (edb::const_message, edb::service_interface, bool b)70{71ck_assert(b == expected_bool);72return b;73}74, es::ins<bool>("bool")75, es::outs<bool>("bool")76)77, es::method("SendByte"78, [expected_byte] (edb::const_message, edb::service_interface, char c)79{80ck_assert(c == expected_byte);81return c;82}83, es::ins<char>("byte")84, es::outs<char>("byte")85)86, es::method("SendUint32"87, [expected_uint32] (edb::const_message, edb::service_interface, uint32_t n)88{89ck_assert(n == expected_uint32);90return n;91}92, es::ins<uint32_t>("uint32")93, es::outs<uint32_t>("uint32")94)95, es::method("SendInt32"96, [expected_int32] (edb::const_message, edb::service_interface, int32_t n)97{98ck_assert(n == expected_int32);99return n;100}101, es::ins<int32_t>("int32")102, es::outs<int32_t>("int32")103)104, es::method("SendInt16"105, [expected_int16] (edb::const_message, edb::service_interface, int16_t n)106{107ck_assert(n == expected_int16);108return n;109}110, es::ins<int16_t>("int16")111, es::outs<int16_t>("int16")112)113, es::method("SendDouble"114, [expected_double] (edb::const_message, edb::service_interface, double n)115{116ck_assert(n == expected_double);117return n;118}119, es::ins<double>("double")120, es::outs<double>("double")121)122, es::method("SendString"123, [expected_string] (edb::const_message, edb::service_interface, std::string const& n)124{125std::cout << "SendString " << n.size() << " " << n << std::endl;126ck_assert(n == expected_string);127return n;128}129, es::ins<std::string>("string")130, es::outs<std::string>("string")131)132, es::method("GetVoid"133, [expected_bool] (edb::const_message, edb::service_interface, bool b)134{135ck_assert(b == expected_bool);136}137, es::ins<bool>("string")138)139, es::method("SendStringWithBool"140, [expected_string, expected_bool] (edb::const_message, edb::service_interface141, std::string const& n, bool b)142{143ck_assert(n == expected_string);144ck_assert(b == expected_bool);145return n;146}147, es::ins<std::string, bool>("string", "bool")148, es::outs<std::string>("string")149)150, es::method("SendStringAndBool"151, [expected_string, expected_bool] (edb::const_message, edb::service_interface152, std::string const& n, bool b153, bool* out)154{155std::cout << "Running SendStringAndBool" << std::endl;156ck_assert(n == expected_string);157ck_assert(b == expected_bool);158*out = b;159return n;160}161, es::ins<std::string, bool>("string", "bool")162, es::outs<std::string, bool>("string", "bool")163)164, es::method("SendStringAndBoolWithoutReturn"165, [expected_string, expected_bool] (edb::const_message, edb::service_interface166, std::string const& s, bool b167, std::string* out_s, bool* out_b)168{169std::cout << "Running SendStringAndBool" << std::endl;170ck_assert(s == expected_string);171ck_assert(b == expected_bool);172*out_s = s;173*out_b = b;174}175, es::ins<std::string, bool>("string", "bool")176, es::outs<std::string, bool>("string", "bool")177)178);179static_cast<void>(iface);180
181using namespace std::placeholders;182edb::name_request<std::uint32_t>(c_, g_bus, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE183, & ::on_name_request);184
185std::cout << "registered" << std::endl;186
187edb::object o = c_.get_object(g_bus, g_path);188edb::proxy p = o.get_proxy(g_interface);189
190using namespace std::placeholders;191p.call<bool>192("SendBool"193, -1194, std::bind195([expected_bool] (std::error_code const& ec, edb::const_message const& /*msg*/, bool b)196{197if(!ec)198{199std::cout << "bool received " << b << std::endl;200ck_assert(b == expected_bool);201}202else203{204std::cout << "error " << ec.message() << std::endl;205const char *errname = "", *errmsg = "";206// eldbus_message_error_get(msg, &errname, &errmsg);207std::cout << "error " << errname << " " << errmsg << std::endl;208std::abort();209}210}211, _1, _2, _4)212, expected_bool213);214
215p.call<char>216("SendByte"217, -1218, std::bind219([expected_byte] (std::error_code const& ec, edb::const_message const& msg, char c)220{221if(!ec)222{223std::cout << "char received " << c << std::endl;224ck_assert(c == expected_byte);225}226else227{228std::cout << "error " << ec.message() << std::endl;229const char *errname, *errmsg;230std::tie(errname, errmsg) = msg.error_get();231std::cout << "error " << errname << " " << errmsg << std::endl;232std::abort();233}234}235, _1, _2, _4)236, expected_byte237);238
239p.call<uint32_t>240("SendUint32"241, -1242, std::bind243([expected_uint32] (std::error_code const& ec, edb::const_message const& msg, uint32_t i)244{245if(!ec)246{247std::cout << "uint32_t received " << i << std::endl;248ck_assert(i == expected_uint32);249}250else251{252std::cout << "error " << ec.message() << std::endl;253const char *errname, *errmsg;254std::tie(errname, errmsg) = msg.error_get();255std::cout << "error " << errname << " " << errmsg << std::endl;256std::abort();257}258}259, _1, _2, _4)260, expected_uint32261);262
263p.call<int32_t>264("SendInt32"265, -1266, std::bind267([expected_int32] (std::error_code const& ec, edb::const_message const& msg, int32_t i)268{269if(!ec)270{271std::cout << "int32_t received " << i << std::endl;272ck_assert(i == expected_int32);273}274else275{276std::cout << "error " << ec.message() << std::endl;277const char *errname, *errmsg;278std::tie(errname, errmsg) = msg.error_get();279std::cout << "error " << errname << " " << errmsg << std::endl;280std::abort();281}282}283, _1, _2, _4)284, expected_int32285);286
287p.call<int16_t>288("SendInt16"289, -1290, std::bind291([expected_int16] (std::error_code const& ec, edb::const_message const& msg, int16_t i)292{293if(!ec)294{295std::cout << "int16_t received " << i << std::endl;296ck_assert(i == expected_int16);297}298else299{300std::cout << "error " << ec.message() << std::endl;301const char *errname, *errmsg;302std::tie(errname, errmsg) = msg.error_get();303std::cout << "error " << errname << " " << errmsg << std::endl;304std::abort();305}306}307, _1, _2, _4)308, expected_int16309);310
311p.call<double>312("SendDouble"313, -1314, std::bind315([expected_double] (std::error_code const& ec, edb::const_message const& msg, double i)316{317if(!ec)318{319std::cout << "double received " << i << std::endl;320ck_assert(i == expected_double);321}322else323{324std::cout << "error " << ec.message() << std::endl;325const char *errname, *errmsg;326std::tie(errname, errmsg) = msg.error_get();327std::cout << "error " << errname << " " << errmsg << std::endl;328std::abort();329}330}331, _1, _2, _4)332, expected_double333);334
335p.call<std::string>336("SendString"337, -1338, std::bind339([expected_string] (std::error_code const& ec, edb::const_message const& msg, std::string i)340{341if(!ec)342{343std::cout << "string received " << i << std::endl;344ck_assert(i == expected_string);345}346else347{348std::cout << "error " << ec.message() << std::endl;349const char *errname, *errmsg;350std::tie(errname, errmsg) = msg.error_get();351std::cout << "error " << errname << " " << errmsg << std::endl;352std::abort();353}354}355, _1, _2, _4)356, expected_string357);358
359p.call<void>360("GetVoid"361, -1362, std::bind363([] (std::error_code const& ec, edb::const_message const& msg)364{365if(!ec)366{367std::cout << "GetVoid returned succesfully" << std::endl;368}369else370{371std::cout << "error " << ec.message() << std::endl;372const char *errname, *errmsg;373std::tie(errname, errmsg) = msg.error_get();374std::cout << "error " << errname << " " << errmsg << std::endl;375std::abort();376}377}378, _1, _2)379, expected_bool380);381
382p.call<std::string>383("SendStringWithBool"384, -1385, std::bind386([expected_string] (std::error_code const& ec, edb::const_message const& msg, std::string i)387{388if(!ec)389{390std::cout << "string received " << i << std::endl;391ck_assert(i == expected_string);392}393else394{395std::cout << "error " << ec.message() << std::endl;396const char *errname, *errmsg;397std::tie(errname, errmsg) = msg.error_get();398std::cout << "error " << errname << " " << errmsg << std::endl;399std::abort();400}401}402, _1, _2, _4)403, expected_string404, expected_bool405);406
407p.call<std::tuple<std::string, bool> >408("SendStringAndBool"409, -1410, std::bind411([expected_string, expected_bool]412(std::error_code const& ec, edb::const_message const& msg, std::string i, bool b)413{414if(!ec)415{416std::cout << "string received " << i << std::endl;417ck_assert(i == expected_string);418ck_assert(b == expected_bool);419}420else421{422std::cout << "error " << ec.message() << std::endl;423const char *errname, *errmsg;424std::tie(errname, errmsg) = msg.error_get();425std::cout << "error " << errname << " " << errmsg << std::endl;426std::abort();427}428}429, _1, _2, _4, _5)430, expected_string431, expected_bool432);433
434p.call<std::tuple<std::string, bool> >435("SendStringAndBoolWithoutReturn"436, -1437, std::bind438([expected_string, expected_bool]439(std::error_code const& ec, edb::const_message const& msg, std::string i, bool b)440{441if(!ec)442{443std::cout << "string received " << i << std::endl;444ck_assert(i == expected_string);445ck_assert(b == expected_bool);446
447::ecore_main_loop_quit();448}449else450{451std::cout << "error " << ec.message() << std::endl;452const char *errname, *errmsg;453std::tie(errname, errmsg) = msg.error_get();454std::cout << "error " << errname << " " << errmsg << std::endl;455std::abort();456}457}458, _1, _2, _4, _5)459, expected_string460, expected_bool461);462
463// eldbus_name_owner_changed_callback_add(c.native_handle(), bus, on_name_owner_changed,464// c.native_handle(), EINA_TRUE);465
466ecore_main_loop_begin();467
468std::cout << "out of loop" << std::endl;469}
470EFL_END_TEST
471
472void
473eldbus_test_client(TCase* tc)474{
475tcase_add_test(tc, eldbus_cxx_client);476}
477