summaryrefslogtreecommitdiff
path: root/src/tests/eina_cxx/eina_cxx_test_log.cc
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-03-10 12:25:20 +0900
committerCedric BAIL <cedric.bail@samsung.com>2014-03-10 12:35:00 +0900
commit416376e03c8ac2f5fa990956fbebcada5704c666 (patch)
treec5cbe401523d90a95d734f672280c82b8cd9b3a5 /src/tests/eina_cxx/eina_cxx_test_log.cc
parent5942207b25d746585c2b9eb93393e1af9dcb0ad7 (diff)
eina-cxx: Added eina_log support for C++, using IOStreams syntax
Summary: Added eina_log support for C++ using the following macros: For logging into a domain: EINA_CXX_DOM_LOG EINA_CXX_DOM_LOG_CRIT EINA_CXX_DOM_LOG_ERR EINA_CXX_DOM_LOG_INFO EINA_CXX_DOM_LOG_DBG EINA_CXX_DOM_LOG_WARN And for logging into the default domain: EINA_CXX_LOG EINA_CXX_LOG_CRIT EINA_CXX_LOG_ERR EINA_CXX_LOG_INFO EINA_CXX_LOG_DBG EINA_CXX_LOG_WARN The usage is simple as can be seen in the tests: efl::eina::log_domain domain("error_domain_name"); domain.set_level(efl::eina::log_level::critical); EINA_CXX_DOM_LOG_CRIT(domain, "something went wrong with the following error: " << error); @feature Reviewers: cedric CC: raster, savio, cedric, sanjeev Differential Revision: https://phab.enlightenment.org/D605
Diffstat (limited to 'src/tests/eina_cxx/eina_cxx_test_log.cc')
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_log.cc102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/tests/eina_cxx/eina_cxx_test_log.cc b/src/tests/eina_cxx/eina_cxx_test_log.cc
new file mode 100644
index 0000000000..52c8ccdc61
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_log.cc
@@ -0,0 +1,102 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5
6#include <check.h>
7
8bool expensive_called = false;
9
10int expensive_call()
11{
12 expensive_called = true;
13 return 11;
14}
15
16START_TEST(eina_cxx_level_log)
17{
18 efl::eina::eina_init init;
19
20 efl::eina::log_domain domain("level_error_domain");
21
22 domain.set_level(efl::eina::log_level::critical);
23 ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_CRITICAL);
24 domain.set_level(efl::eina::log_level::warning);
25 ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_WARN);
26 domain.set_level(efl::eina::log_level::debug);
27 ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_DBG);
28 domain.set_level(efl::eina::log_level::info);
29 ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_INFO);
30 domain.set_level(efl::eina::log_level::error);
31 ck_assert(domain.get_level() == ::EINA_LOG_LEVEL_ERR);
32}
33END_TEST
34
35START_TEST(eina_cxx_expensive_log)
36{
37 efl::eina::eina_init init;
38
39 efl::eina::log_domain domain("expensive_call_error_domain");
40
41 domain.set_level(EINA_LOG_LEVEL_CRITICAL);
42
43 EINA_CXX_DOM_LOG_ERR(domain, "foo " << ::expensive_call());
44 ck_assert(!expensive_called);
45}
46END_TEST
47
48START_TEST(eina_cxx_domain_log)
49{
50 efl::eina::eina_init init;
51
52 efl::eina::log_domain domain("error_domain");
53
54 EINA_CXX_DOM_LOG_CRIT(domain, "foo 0x" << std::hex << 10);
55 EINA_CXX_DOM_LOG_ERR(domain, "foo " << 5);
56 EINA_CXX_DOM_LOG_INFO(domain, "foo " << 5);
57 EINA_CXX_DOM_LOG_DBG(domain, "foo " << 5);
58 EINA_CXX_DOM_LOG_WARN(domain, "foo " << 5);
59
60 EINA_CXX_LOG_CRIT("foo " << 5);
61 EINA_CXX_LOG_ERR("foo " << 5);
62 EINA_CXX_LOG_INFO("foo " << 5);
63 EINA_CXX_LOG_DBG("foo " << 5);
64 EINA_CXX_LOG_WARN("foo " << 5);
65}
66END_TEST
67
68START_TEST(eina_cxx_default_domain_log)
69{
70 efl::eina::eina_init init;
71
72 EINA_CXX_DOM_LOG_CRIT(efl::eina::default_domain, "foo " << 5);
73 EINA_CXX_DOM_LOG_ERR(efl::eina::default_domain, "foo " << 5);
74 EINA_CXX_DOM_LOG_INFO(efl::eina::default_domain, "foo " << 5);
75 EINA_CXX_DOM_LOG_DBG(efl::eina::default_domain, "foo " << 5);
76 EINA_CXX_DOM_LOG_WARN(efl::eina::default_domain, "foo " << 5);
77}
78END_TEST
79
80START_TEST(eina_cxx_global_domain_log)
81{
82 efl::eina::eina_init init;
83
84 efl::eina::log_domain domain("domain");
85
86 EINA_CXX_DOM_LOG_CRIT(efl::eina::global_domain, "foo " << 5);
87 EINA_CXX_DOM_LOG_ERR(efl::eina::global_domain, "foo " << 5);
88 EINA_CXX_DOM_LOG_INFO(efl::eina::global_domain, "foo " << 5);
89 EINA_CXX_DOM_LOG_DBG(efl::eina::global_domain, "foo " << 5);
90 EINA_CXX_DOM_LOG_WARN(efl::eina::global_domain, "foo " << 5);
91}
92END_TEST
93
94void
95eina_test_log(TCase* tc)
96{
97 tcase_add_test(tc, eina_cxx_domain_log);
98 tcase_add_test(tc, eina_cxx_default_domain_log);
99 tcase_add_test(tc, eina_cxx_global_domain_log);
100 tcase_add_test(tc, eina_cxx_expensive_log);
101 tcase_add_test(tc, eina_cxx_level_log);
102}