40b7a9365cf5a02c556b70689b46e01bf41b5e93
[platform/core/system/dlog.git] / src / tests / libdlog_base_neg.c
1 /*
2  * Copyright (c) 2018-2020, Samsung Electronics Co., Ltd. All rights reserved.
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
17 #include "libdlog_base_wrap.c"
18
19 int main()
20 {
21         fail_conf_read = true;
22         __configure();
23         assert(dlog_print(DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NOT_PERMITTED);
24         assert(write_to_log != wtl_android);
25         assert(write_to_log != wtl_pipe);
26         fail_conf_read = false;
27         __dlog_fini();
28
29         __configure();
30         assert(dlog_print(DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NOT_PERMITTED);
31         assert(write_to_log != wtl_android);
32         assert(write_to_log != wtl_pipe);
33         conf_read_called = false;
34         assert(dlog_print(DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NOT_PERMITTED);
35         assert(conf_read_called); // should retry reinitializing
36         __dlog_fini();
37
38         log_config_set(&CONFIG, "backend", "Hej, zamawiam Bentoye. Czekam do 11:15.");
39         __configure();
40         assert(dlog_print(DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NOT_PERMITTED);
41         assert(write_to_log != wtl_pipe);
42         assert(write_to_log != wtl_android);
43         __dlog_fini();
44
45         log_config_set(&CONFIG, "backend", "logger");
46         log_config_set(&CONFIG, "limiter", "1");
47         log_config_set(&CONFIG, "debugmode", "0");
48         use_dynamic_conf = true;
49         limiter_ret = (struct pass_log_result) { .decision = DECISION_ALLOWED };
50         __configure();
51         assert(write_to_log != wtl_pipe); // ceci n'est pas une pipe
52         assert(write_to_log == wtl_android);
53         assert(limiter_created);
54
55         assert(__dlog_print((log_id_t) -1, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_INVALID_PARAMETER);
56         assert(__dlog_print(LOG_ID_MAIN, DLOG_ERROR, NULL , "msg") == DLOG_ERROR_INVALID_PARAMETER);
57
58         assert(__dlog_sec_print((log_id_t) -1, DLOG_ERROR, "tag", "msg") == DLOG_ERROR_INVALID_PARAMETER);
59         assert(__dlog_sec_print(LOG_ID_MAIN, DLOG_ERROR, NULL , "msg") == DLOG_ERROR_INVALID_PARAMETER);
60
61         limiter_ret = (struct pass_log_result) { .decision = DECISION_ALLOWED };
62         __dlog_fini();
63
64         fail_snprintf = true;
65         __configure();
66         assert(__dlog_print(LOG_ID_SYSTEM, DLOG_ERROR, "tag", "msg") == 45835705);
67         fail_snprintf = false;
68         __dlog_fini();
69
70         return 0;
71 }