efl

Форк
0
/
eldbus_cxx_test_eldbus_client.cc 
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_H
17
# include <config.h>
18
#endif
19

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

29
const char g_bus[] = "org.Enlightenment.TestCxx";
30
const char g_path[] = "/org/enlightenment";
31
const char g_interface[] = "org.enlightenment.FakeServer";
32

33
static void
34
on_name_request(std::error_code const& ec, efl::eldbus::const_message
35
                , efl::eldbus::pending, unsigned int reply)
36
{
37
  if(!ec)
38
    {
39
       if(reply != ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)
40
         {
41
           printf("error name already in use\n");
42
           return;
43
         }
44
     }
45
}
46

47
EFL_START_TEST(eldbus_cxx_client)
48
{
49
  namespace edb = efl::eldbus;
50

51
  efl::ecore::ecore_init ecore_init;
52
  edb::eldbus_init init;
53

54
  edb::connection c_(edb::session);
55

56
  namespace es = edb::service;
57

58
  bool expected_bool = true;
59
  char expected_byte = 0xAA;
60
  uint32_t expected_uint32 = 0xFFFFFFFF;
61
  int32_t expected_int32 = -1;
62
  int16_t expected_int16 = -1;
63
  double expected_double = 3.1415926;
64
  std::string expected_string = "expected string";
65

66
  edb::service_interface iface = edb::service_interface_register
67
    (c_, g_path, g_interface
68
     , es::method("SendBool"
69
                  , [expected_bool] (edb::const_message, edb::service_interface, bool b)
70
                  {
71
                    ck_assert(b == expected_bool);
72
                    return 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
                  {
80
                    ck_assert(c == expected_byte);
81
                    return 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
                  {
89
                    ck_assert(n == expected_uint32);
90
                    return 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
                  {
98
                    ck_assert(n == expected_int32);
99
                    return 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
                  {
107
                    ck_assert(n == expected_int16);
108
                    return 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
                  {
116
                    ck_assert(n == expected_double);
117
                    return 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
                  {
125
                    std::cout << "SendString " << n.size() << " " << n << std::endl;
126
                    ck_assert(n == expected_string);
127
                    return 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
                  {
135
                    ck_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_interface
141
                                                      , std::string const& n, bool b)
142
                  {
143
                    ck_assert(n == expected_string);
144
                    ck_assert(b == expected_bool);
145
                    return 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_interface
152
                                                      , std::string const& n, bool b
153
                                                      , bool* out)
154
                  {
155
                    std::cout << "Running SendStringAndBool" << std::endl;
156
                    ck_assert(n == expected_string);
157
                    ck_assert(b == expected_bool);
158
                    *out = b;
159
                    return 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_interface
166
                                                      , std::string const& s, bool b
167
                                                      , std::string* out_s, bool* out_b)
168
                  {
169
                    std::cout << "Running SendStringAndBool" << std::endl;
170
                    ck_assert(s == expected_string);
171
                    ck_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
    );
179
  static_cast<void>(iface);
180

181
  using namespace std::placeholders;
182
  edb::name_request<std::uint32_t>(c_, g_bus, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE
183
                                   , & ::on_name_request);
184

185
  std::cout << "registered" << std::endl;
186

187
  edb::object o = c_.get_object(g_bus, g_path);
188
  edb::proxy p = o.get_proxy(g_interface);
189

190
  using namespace std::placeholders;
191
  p.call<bool>
192
    ("SendBool"
193
     , -1
194
     , std::bind
195
     ([expected_bool] (std::error_code const& ec, edb::const_message const& /*msg*/, bool b)
196
      {
197
        if(!ec)
198
          {
199
            std::cout << "bool received " << b << std::endl;
200
            ck_assert(b == expected_bool);
201
          }
202
        else
203
          {
204
            std::cout << "error " << ec.message() << std::endl;
205
            const char *errname = "", *errmsg = "";
206
            // eldbus_message_error_get(msg, &errname, &errmsg);
207
            std::cout << "error " << errname << " " << errmsg << std::endl;
208
            std::abort();
209
          }
210
      }
211
      , _1, _2, _4)
212
     , expected_bool
213
     );
214

215
  p.call<char>
216
    ("SendByte"
217
     , -1
218
     , std::bind
219
     ([expected_byte] (std::error_code const& ec, edb::const_message const& msg, char c)
220
      {
221
        if(!ec)
222
          {
223
            std::cout << "char received " << c << std::endl;
224
            ck_assert(c == expected_byte);
225
          }
226
        else
227
          {
228
            std::cout << "error " << ec.message() << std::endl;
229
            const char *errname, *errmsg;
230
            std::tie(errname, errmsg) = msg.error_get();
231
            std::cout << "error " << errname << " " << errmsg << std::endl;
232
            std::abort();
233
          }
234
      }
235
      , _1, _2, _4)
236
     , expected_byte
237
     );
238

239
  p.call<uint32_t>
240
    ("SendUint32"
241
     , -1
242
     , std::bind
243
     ([expected_uint32] (std::error_code const& ec, edb::const_message const& msg, uint32_t i)
244
      {
245
        if(!ec)
246
          {
247
            std::cout << "uint32_t received " << i << std::endl;
248
            ck_assert(i == expected_uint32);
249
          }
250
        else
251
          {
252
            std::cout << "error " << ec.message() << std::endl;
253
            const char *errname, *errmsg;
254
            std::tie(errname, errmsg) = msg.error_get();
255
            std::cout << "error " << errname << " " << errmsg << std::endl;
256
            std::abort();
257
          }
258
      }
259
      , _1, _2, _4)
260
     , expected_uint32
261
     );
262

263
  p.call<int32_t>
264
    ("SendInt32"
265
     , -1
266
     , std::bind
267
     ([expected_int32] (std::error_code const& ec, edb::const_message const& msg, int32_t i)
268
      {
269
        if(!ec)
270
          {
271
            std::cout << "int32_t received " << i << std::endl;
272
            ck_assert(i == expected_int32);
273
          }
274
        else
275
          {
276
            std::cout << "error " << ec.message() << std::endl;
277
            const char *errname, *errmsg;
278
            std::tie(errname, errmsg) = msg.error_get();
279
            std::cout << "error " << errname << " " << errmsg << std::endl;
280
            std::abort();
281
          }
282
      }
283
      , _1, _2, _4)
284
     , expected_int32
285
     );
286

287
  p.call<int16_t>
288
    ("SendInt16"
289
     , -1
290
     , std::bind
291
     ([expected_int16] (std::error_code const& ec, edb::const_message const& msg, int16_t i)
292
      {
293
        if(!ec)
294
          {
295
            std::cout << "int16_t received " << i << std::endl;
296
            ck_assert(i == expected_int16);
297
          }
298
        else
299
          {
300
            std::cout << "error " << ec.message() << std::endl;
301
            const char *errname, *errmsg;
302
            std::tie(errname, errmsg) = msg.error_get();
303
            std::cout << "error " << errname << " " << errmsg << std::endl;
304
            std::abort();
305
          }
306
      }
307
      , _1, _2, _4)
308
     , expected_int16
309
     );
310

311
  p.call<double>
312
    ("SendDouble"
313
     , -1
314
     , std::bind
315
     ([expected_double] (std::error_code const& ec, edb::const_message const& msg, double i)
316
      {
317
        if(!ec)
318
          {
319
            std::cout << "double received " << i << std::endl;
320
            ck_assert(i == expected_double);
321
          }
322
        else
323
          {
324
            std::cout << "error " << ec.message() << std::endl;
325
            const char *errname, *errmsg;
326
            std::tie(errname, errmsg) = msg.error_get();
327
            std::cout << "error " << errname << " " << errmsg << std::endl;
328
            std::abort();
329
          }
330
      }
331
      , _1, _2, _4)
332
     , expected_double
333
     );
334

335
  p.call<std::string>
336
    ("SendString"
337
     , -1
338
     , std::bind
339
     ([expected_string] (std::error_code const& ec, edb::const_message const& msg, std::string i)
340
      {
341
        if(!ec)
342
          {
343
            std::cout << "string received " << i << std::endl;
344
            ck_assert(i == expected_string);
345
          }
346
        else
347
          {
348
            std::cout << "error " << ec.message() << std::endl;
349
            const char *errname, *errmsg;
350
            std::tie(errname, errmsg) = msg.error_get();
351
            std::cout << "error " << errname << " " << errmsg << std::endl;
352
            std::abort();
353
          }
354
      }
355
      , _1, _2, _4)
356
     , expected_string
357
     );
358

359
  p.call<void>
360
    ("GetVoid"
361
     , -1
362
     , std::bind
363
     ([] (std::error_code const& ec, edb::const_message const& msg)
364
      {
365
        if(!ec)
366
          {
367
            std::cout << "GetVoid returned succesfully" << std::endl;
368
          }
369
        else
370
          {
371
            std::cout << "error " << ec.message() << std::endl;
372
            const char *errname, *errmsg;
373
            std::tie(errname, errmsg) = msg.error_get();
374
            std::cout << "error " << errname << " " << errmsg << std::endl;
375
            std::abort();
376
          }
377
      }
378
      , _1, _2)
379
     , expected_bool
380
     );
381

382
  p.call<std::string>
383
    ("SendStringWithBool"
384
     , -1
385
     , std::bind
386
     ([expected_string] (std::error_code const& ec, edb::const_message const& msg, std::string i)
387
      {
388
        if(!ec)
389
          {
390
            std::cout << "string received " << i << std::endl;
391
            ck_assert(i == expected_string);
392
          }
393
        else
394
          {
395
            std::cout << "error " << ec.message() << std::endl;
396
            const char *errname, *errmsg;
397
            std::tie(errname, errmsg) = msg.error_get();
398
            std::cout << "error " << errname << " " << errmsg << std::endl;
399
            std::abort();
400
          }
401
      }
402
      , _1, _2, _4)
403
     , expected_string
404
     , expected_bool
405
     );
406

407
  p.call<std::tuple<std::string, bool> >
408
    ("SendStringAndBool"
409
     , -1
410
     , std::bind
411
     ([expected_string, expected_bool]
412
      (std::error_code const& ec, edb::const_message const& msg, std::string i, bool b)
413
      {
414
        if(!ec)
415
          {
416
            std::cout << "string received " << i << std::endl;
417
            ck_assert(i == expected_string);
418
            ck_assert(b == expected_bool);
419
          }
420
        else
421
          {
422
            std::cout << "error " << ec.message() << std::endl;
423
            const char *errname, *errmsg;
424
            std::tie(errname, errmsg) = msg.error_get();
425
            std::cout << "error " << errname << " " << errmsg << std::endl;
426
            std::abort();
427
          }
428
      }
429
      , _1, _2, _4, _5)
430
     , expected_string
431
     , expected_bool
432
     );
433

434
  p.call<std::tuple<std::string, bool> >
435
    ("SendStringAndBoolWithoutReturn"
436
     , -1
437
     , std::bind
438
     ([expected_string, expected_bool]
439
      (std::error_code const& ec, edb::const_message const& msg, std::string i, bool b)
440
      {
441
        if(!ec)
442
          {
443
            std::cout << "string received " << i << std::endl;
444
            ck_assert(i == expected_string);
445
            ck_assert(b == expected_bool);
446

447
            ::ecore_main_loop_quit();
448
          }
449
        else
450
          {
451
            std::cout << "error " << ec.message() << std::endl;
452
            const char *errname, *errmsg;
453
            std::tie(errname, errmsg) = msg.error_get();
454
            std::cout << "error " << errname << " " << errmsg << std::endl;
455
            std::abort();
456
          }
457
      }
458
      , _1, _2, _4, _5)
459
     , expected_string
460
     , expected_bool
461
     );
462

463
  // eldbus_name_owner_changed_callback_add(c.native_handle(), bus, on_name_owner_changed,
464
  //                                        c.native_handle(), EINA_TRUE);
465

466
  ecore_main_loop_begin();
467

468
  std::cout << "out of loop" << std::endl;
469
}
470
EFL_END_TEST
471

472
void
473
eldbus_test_client(TCase* tc)
474
{
475
  tcase_add_test(tc, eldbus_cxx_client);
476
}
477

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.