efl

Форк
0
/
eina_cxx_test_error.cc 
90 строк · 2.0 Кб
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 <Eina.hh>
21

22
#include "eina_cxx_suite.h"
23

24
Eina_Error my_error, my_error_2;
25

26
EFL_START_TEST(eina_cxx_get_error)
27
{
28
  efl::eina::eina_init eina_init;
29

30
  my_error = ::eina_error_msg_static_register("Message 1");
31

32
  ::eina_error_set(0);
33

34
  efl::eina::error_code ec1 = efl::eina::get_error_code();
35
  ck_assert(!ec1);
36

37
  ::eina_error_set(my_error);
38

39
  efl::eina::error_code ec2 = efl::eina::get_error_code();
40
  ck_assert(!!ec2);
41

42
  ck_assert(ec2.message() == "Message 1");
43

44
  ::eina_error_set(ENOMEM);
45

46
  efl::eina::error_code ec3 = efl::eina::get_error_code();
47
  ck_assert(!!ec3);
48

49
  ck_assert(ec3.message() == strerror(ENOMEM));
50
}
51
EFL_END_TEST
52

53
EFL_START_TEST(eina_cxx_throw_on_error)
54
{
55
  efl::eina::eina_init eina_init;
56

57
  ::eina_error_set(my_error_2);
58
  my_error_2 = ::eina_error_msg_static_register("Message 2");
59

60
  ::eina_error_set(0);
61
  try
62
    {
63
      efl::eina::throw_on_error();
64
    }
65
  catch(std::exception const&)
66
    {
67
      std::abort();
68
    }
69

70
  ::eina_error_set(my_error_2);
71
  try
72
    {
73
      efl::eina::throw_on_error();
74
      std::abort();
75
    }
76
  catch(efl::eina::system_error const& e)
77
    {
78
      ck_assert(e.code().value() == my_error_2);
79
      ck_assert(e.code().message() == "Message 2");
80
      ck_assert(!efl::eina::get_error_code());
81
    }
82
}
83
EFL_END_TEST
84

85
void
86
eina_test_error(TCase *tc)
87
{
88
  tcase_add_test(tc, eina_cxx_get_error);
89
  tcase_add_test(tc, eina_cxx_throw_on_error);
90
}
91

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

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

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

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