Line data Source code
1 : /*
2 : test_error.c
3 : Created by Danny Goossen, Gioxa Ltd on 26/3/17.
4 :
5 : MIT License
6 :
7 : Copyright (c) 2017 deployctl, Gioxa Ltd.
8 :
9 : Permission is hereby granted, free of charge, to any person obtaining a copy
10 : of this software and associated documentation files (the "Software"), to deal
11 : in the Software without restriction, including without limitation the rights
12 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 : copies of the Software, and to permit persons to whom the Software is
14 : furnished to do so, subject to the following conditions:
15 :
16 : The above copyright notice and this permission notice shall be included in all
17 : copies or substantial portions of the Software.
18 :
19 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 : SOFTWARE.
26 :
27 : */
28 :
29 : #include <check.h>
30 : #include "../src/deployd.h"
31 :
32 :
33 1 : START_TEST(check_normal)
34 : {
35 1 : ck_assert_int_eq(getsyslog(),0);
36 2 : ck_assert_int_eq(getdebug(),0);
37 2 : ck_assert_int_eq(getverbose(),0);
38 1 : info("test1");
39 1 : debug("test2");
40 1 : alert("test3");
41 1 : error("test4");
42 1 : sock_error("test4");
43 1 : sock_error_no("test5",1);
44 1 : setsyslog();
45 2 : ck_assert_int_eq(getsyslog(),1);
46 1 : info("test1");
47 1 : debug("test2");
48 1 : alert("test3");
49 1 : error("test4");
50 1 : sock_error("test4");
51 1 : sock_error_no("test5",1);
52 1 : clrsyslog();
53 : }
54 1 : END_TEST
55 1 : START_TEST(check_verbose)
56 : {
57 1 : setverbose();
58 1 : ck_assert_int_eq(getverbose(),1);
59 1 : info("test1");
60 1 : debug("test2");
61 1 : alert("test3");
62 1 : error("test4");
63 1 : sock_error("test4");
64 1 : sock_error_no("test5",1);
65 1 : setsyslog();
66 1 : info("test1");
67 1 : debug("test2");
68 1 : alert("test3");
69 1 : error("test4");
70 1 : sock_error("test4");
71 1 : sock_error_no("test5",1);
72 1 : clrsyslog();
73 1 : clrverbose();
74 2 : ck_assert_int_eq(getverbose(),0);
75 : }
76 1 : END_TEST
77 :
78 1 : START_TEST(check_debug)
79 : {
80 1 : setdebug();
81 1 : ck_assert_int_eq(getdebug(),1);
82 1 : info("test1");
83 1 : debug("test2");
84 1 : alert("test3");
85 1 : error("test4");
86 1 : sock_error("test4");
87 1 : sock_error_no("test5",1);
88 1 : setsyslog();
89 1 : info("test1");
90 1 : debug("test2");
91 1 : alert("test3");
92 1 : error("test4");
93 1 : sock_error("test4");
94 1 : sock_error_no("test5",1);
95 1 : clrsyslog();
96 1 : clrdebug();
97 2 : ck_assert_int_eq(getdebug(),0);
98 : }
99 1 : END_TEST
100 :
101 4 : Suite * socket_suite(void)
102 : {
103 : Suite *s;
104 : TCase *tc_core;
105 : //TCase *tc_progress;
106 4 : s = suite_create("test_error");
107 : /* Core test case */
108 4 : tc_core = tcase_create("Core");
109 : //tcase_add_checked_fixture(tc_core, setup, teardown);
110 4 : tcase_add_unchecked_fixture(tc_core, NULL,NULL);
111 4 : tcase_set_timeout(tc_core,15);
112 4 : tcase_add_test(tc_core, check_normal);
113 4 : tcase_add_test(tc_core, check_verbose);
114 4 : tcase_add_test(tc_core, check_debug);
115 4 : suite_add_tcase(s, tc_core);
116 4 : return s;
117 : }
118 :
119 :
120 4 : int main(void)
121 : {
122 : int number_failed;
123 : Suite *s;
124 : SRunner *sr;
125 :
126 4 : s = socket_suite();
127 4 : sr = srunner_create(s);
128 4 : srunner_run_all(sr, CK_NORMAL);
129 1 : number_failed = srunner_ntests_failed(sr);
130 1 : srunner_free(sr);
131 1 : return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
132 : }
|