summaryrefslogtreecommitdiff
path: root/src/tests/eina_cxx/eina_cxx_test_error.cc
blob: fb3a6aa7ae8a44bd3d156c61fb0f3f49eb8326f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

#include "Eina.hh"

#include <check.h>

Eina_Error my_error, my_error_2;

START_TEST(eina_cxx_get_error)
{
  efl::eina::eina_init eina_init;

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

  ::eina_error_set(0);
  
  efl::eina::error_code ec1 = efl::eina::get_error_code();
  ck_assert(!ec1);

  ::eina_error_set(my_error);

  efl::eina::error_code ec2 = efl::eina::get_error_code();
  ck_assert(!!ec2);
  
  ck_assert(ec2.message() == "Message 1");

  ::eina_error_set(EINA_ERROR_OUT_OF_MEMORY);

  efl::eina::error_code ec3 = efl::eina::get_error_code();
  ck_assert(!!ec3);
  
  ck_assert(ec3.message() == "Out of memory");
}
END_TEST

START_TEST(eina_cxx_throw_on_error)
{
  efl::eina::eina_init eina_init;

  ::eina_error_set(my_error_2);
  my_error_2 = ::eina_error_msg_static_register("Message 2");

  ::eina_error_set(0);
  try
    {
      efl::eina::throw_on_error();
    }
  catch(std::exception const&)
    {
      std::abort();
    }

  ::eina_error_set(my_error_2);
  try
    {
      efl::eina::throw_on_error();
      std::abort();
    }
  catch(efl::eina::system_error const& e)
    {
      ck_assert(e.code().value() == my_error_2);
      ck_assert(e.code().message() == "Message 2");
      ck_assert(!efl::eina::get_error_code());
    }
}
END_TEST

void
eina_test_error(TCase *tc)
{
  tcase_add_test(tc, eina_cxx_get_error);
  tcase_add_test(tc, eina_cxx_throw_on_error);
}