summaryrefslogtreecommitdiff
path: root/src/tests/eina_cxx/eina_cxx_test_log.cc
blob: 4d32d41f2c91f34bd0ee8d53a73368f69abe0f8d (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

#include "Eina.hh"

#include <algorithm>

#include <check.h>

bool expensive_called = false;

int expensive_call()
{
  expensive_called = true;
  return 11;
}

START_TEST(eina_cxx_level_log)
{
  efl::eina::eina_init init;

  efl::eina::log_domain domain("level_error_domain");

  domain.set_level(efl::eina::log_level::critical);
  ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_CRITICAL);
  domain.set_level(efl::eina::log_level::warning);
  ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_WARN);
  domain.set_level(efl::eina::log_level::debug);
  ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_DBG);
  domain.set_level(efl::eina::log_level::info);
  ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_INFO);
  domain.set_level(efl::eina::log_level::error);
  ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_ERR);
}
END_TEST

START_TEST(eina_cxx_expensive_log)
{
  efl::eina::eina_init init;

  efl::eina::log_domain domain("expensive_call_error_domain");

  domain.set_level(EINA_LOG_LEVEL_CRITICAL);

  EINA_CXX_DOM_LOG_ERR(domain) << "foo " << ::expensive_call();
  ck_assert(!expensive_called);
}
END_TEST

START_TEST(eina_cxx_domain_log)
{
  efl::eina::eina_init init;

  efl::eina::log_domain domain("error_domain");

  EINA_CXX_DOM_LOG_CRIT(domain) << "foo 0x" << std::hex << 10;
  EINA_CXX_DOM_LOG_ERR(domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_INFO(domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_DBG(domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_WARN(domain) << "foo " << 5;

  EINA_CXX_LOG_CRIT() << "foo " << 5;
  EINA_CXX_LOG_ERR() << "foo " << 5;
  EINA_CXX_LOG_INFO() << "foo " << 5;
  EINA_CXX_LOG_DBG() << "foo " << 5;
  EINA_CXX_LOG_WARN() << "foo " << 5;
}
END_TEST

START_TEST(eina_cxx_default_domain_log)
{
  efl::eina::eina_init init;

  EINA_CXX_DOM_LOG_CRIT(efl::eina::default_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_ERR(efl::eina::default_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_INFO(efl::eina::default_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_DBG(efl::eina::default_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_WARN(efl::eina::default_domain) << "foo " << 5;
}
END_TEST

START_TEST(eina_cxx_global_domain_log)
{
  efl::eina::eina_init init;

  efl::eina::log_domain domain("domain");

  EINA_CXX_DOM_LOG_CRIT(efl::eina::global_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_ERR(efl::eina::global_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_INFO(efl::eina::global_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_DBG(efl::eina::global_domain) << "foo " << 5;
  EINA_CXX_DOM_LOG_WARN(efl::eina::global_domain) << "foo " << 5;
}
END_TEST

void
eina_test_log(TCase* tc)
{
  tcase_add_test(tc, eina_cxx_domain_log);
  tcase_add_test(tc, eina_cxx_default_domain_log);
  tcase_add_test(tc, eina_cxx_global_domain_log);
  tcase_add_test(tc, eina_cxx_expensive_log);
  tcase_add_test(tc, eina_cxx_level_log);
}