utest: add log tests
[platform/core/uifw/libtbm.git] / utests / ut_tbm_log.cpp
1
2 /**************************************************************************
3  *
4  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5  *
6  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
7  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
8  * Contact: Roman Marchenko <r.marchenko@samsung.com>
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sub license, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice (including the
19  * next paragraph) shall be included in all copies or substantial portions
20  * of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  *
30 **************************************************************************/
31
32 #include "ut_tbm.h"
33
34 TEST(TBMLog, logPrintf)
35 {
36         tbm_log_enable_color(1);
37         tbm_log_enable_dlog(0);
38         tbm_log_set_debug_level(2);
39         tbm_log_set_path("/tmp/tbm.log");
40         tbm_log_print(TBM_LOG_LEVEL_ERR, "utest\n");
41         tbm_log_print(TBM_LOG_LEVEL_WRN, "utest\n");
42         tbm_log_print(TBM_LOG_LEVEL_INFO, "utest\n");
43         tbm_log_print(TBM_LOG_LEVEL_DBG, "utest\n");
44         tbm_log_set_path(NULL);
45 }
46
47 TEST(TBMLog, logSetPath)
48 {
49         tbm_log_enable_dlog(0);
50         tbm_log_set_path("/tmp/tbm.log");
51         tbm_log_print(TBM_LOG_LEVEL_ERR, "hello\n");
52         tbm_log_set_path(NULL);
53 }
54
55 TEST(TBMLog, logDlogNone)
56 {
57         tbm_log_enable_color(0);
58         tbm_log_enable_dlog(1);
59         tbm_log_set_debug_level(0);
60         tbm_log_print(TBM_LOG_LEVEL_ERR, "utest");
61         tbm_log_print(TBM_LOG_LEVEL_WRN, "utest");
62         tbm_log_print(TBM_LOG_LEVEL_INFO, "utest");
63         tbm_log_print(TBM_LOG_LEVEL_DBG, "utest");
64 }
65
66 TEST(TBMLog, logDlog)
67 {
68         tbm_log_enable_dlog(1);
69         tbm_log_print(TBM_LOG_LEVEL_ERR, "utest");
70         tbm_log_print(TBM_LOG_LEVEL_WRN, "utest");
71         tbm_log_print(TBM_LOG_LEVEL_INFO, "utest");
72         tbm_log_print(TBM_LOG_LEVEL_DBG, "utest");
73 }
74
75 TEST(TBMLog, logDlogNormal)
76 {
77         tbm_log_enable_dlog(1);
78         tbm_log_print(TBM_LOG_LEVEL_ERR, "utest");
79         tbm_log_print(TBM_LOG_LEVEL_WRN, "utest");
80         tbm_log_print(TBM_LOG_LEVEL_INFO, "utest");
81         tbm_log_print(TBM_LOG_LEVEL_DBG, "utest");
82 }
83
84 TEST(TBMLog, logDlogUnknownLevel)
85 {
86         tbm_log_enable_dlog(1);
87         tbm_log_print(UT_TBM_INVALID_VALUE, "utest");
88 }
89
90 TEST(TBMLog, logSetAssertLevel)
91 {
92         tbm_log_enable_dlog(1);
93         tbm_log_set_assert_level(TBM_LOG_LEVEL_ERR);
94         tbm_log_set_assert_level(TBM_LOG_LEVEL_WRN);
95         tbm_log_set_assert_level(TBM_LOG_LEVEL_INFO);
96         tbm_log_set_assert_level(TBM_LOG_LEVEL_DBG);
97 }
98
99 TEST(TBMLog, logPrintStdout)
100 {
101         tbm_log_print_stdout(TBM_LOG_LEVEL_ERR, "utest");
102         tbm_log_print_stdout(TBM_LOG_LEVEL_WRN, "utest");
103         tbm_log_print_stdout(TBM_LOG_LEVEL_INFO, "utest");
104         tbm_log_print_stdout(TBM_LOG_LEVEL_DBG, "utest");
105 }