Replace () with (void) in function prototypes
[platform/core/system/dlog.git] / src / tests / limiter_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 "limiter_wrap.c"
18
19 int main(void)
20 {
21         __log_limiter_destroy(); // check whether it explodes if called before init
22
23         struct log_config conf = {NULL, NULL};
24         assert(!__log_limiter_create(&conf));
25
26         struct rule *r = NULL;
27         char buffer[10];
28         assert(!__log_limiter_dump_rule(&r, buffer, sizeof buffer));
29         assert(r == NULL);
30
31         log_config_set(&conf, "limiter|*|*"  , "allow");
32         log_config_set(&conf, "limiter|FOO|*", "deny");
33         log_config_set(&conf, "limiter|*|E"  , "deny");
34         log_config_set(&conf, "limiter|FOO|E", "7");
35         assert(__log_limiter_create(&conf));
36
37         fail_malloc = 1;
38         __log_limiter_update(&conf);
39         for (int i = 0; i < 100; ++i) {
40                 assert(__log_limiter_pass_log("FOO", 'F').decision == DECISION_ALLOWED);
41                 assert(__log_limiter_pass_log("BAR", 'F').decision == DECISION_ALLOWED);
42                 assert(__log_limiter_pass_log("BAR", 'E').decision == DECISION_ALLOWED);
43         }
44
45         fail_malloc = 2;
46         __log_limiter_update(&conf);
47         for (int i = 0; i < 100; ++i) {
48                 assert(__log_limiter_pass_log("FOO", 'F').decision == DECISION_ALLOWED);
49                 assert(__log_limiter_pass_log("BAR", 'F').decision == DECISION_ALLOWED);
50                 assert(__log_limiter_pass_log("BAR", 'E').decision == DECISION_ALLOWED);
51         }
52
53         fail_malloc = 0;
54         __log_limiter_destroy();
55         assert(__log_limiter_create(&conf));
56
57         fail_time = true;
58         assert(__log_limiter_pass_log("FOO", 'E').decision == DECISION_ALLOWED);
59         fail_time = false;
60
61         int rule_count = get_rulecount();
62         log_config_set(&conf, "irrelevant", "entry");
63         assert(rule_count == get_rulecount());
64         __log_limiter_update(&conf);
65
66         for (int i = 1; i <= 2; ++i) {
67                 struct rule *r = NULL;
68                 char buf[128];
69                 fail_snprintf = i;
70                 assert(__log_limiter_dump_rule(&r, buf, sizeof buf) == -1);
71         }
72         fail_snprintf = 0;
73
74         assert(0 == util_hash_key(NULL, 0));
75         assert(0 == util_hash_key("", 0));
76 }