Debian Codegraph @

check/internal-tests/ceh_t.c

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "ceh_t.h"
21
22 #include <fcml_ceh.h>
23
24 fcml_bool fcml_tf_ceh_suite_init(void) {
25 return FCML_TRUE;
26 }
27
28 fcml_bool fcml_tf_ceh_suite_cleanup(void) {
29 return FCML_TRUE;
30 }
31
32 void fcml_tf_ceh_test_remove_errors_by_level(void) {
33
34 fcml_st_ceh_error_container conteiner = { NULL };
35
36 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 1.", 1, FCML_EN_CEH_EL_ERROR ) );
37 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 2.", 2, FCML_EN_CEH_EL_ERROR ) );
38 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 3.", 3, FCML_EN_CEH_EL_WARN ) );
39 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 4.", 4, FCML_EN_CEH_EL_WARN ) );
40
41 fcml_st_ceh_error_info *error = conteiner.errors;
42 STF_ASSERT_EQUAL( error->code, 1 );
43 error = error->next_error;
44 STF_ASSERT_EQUAL( error->code, 2 );
45 error = error->next_error;
46 STF_ASSERT_EQUAL( error->code, 3 );
47 error = error->next_error;
48 STF_ASSERT_EQUAL( error->code, 4 );
49 error = error->next_error;
50 STF_ASSERT_PTR_NULL( error );
51
52 fcml_fn_ceh_free_errors_only_with_level( &conteiner, FCML_EN_CEH_EL_ERROR );
53
54 error = conteiner.errors;
55 STF_ASSERT_EQUAL( error->code, 3 );
56 error = error->next_error;
57 STF_ASSERT_EQUAL( error->code, 4 );
58 error = error->next_error;
59 STF_ASSERT_PTR_NULL( error );
60
61 fcml_fn_ceh_free_errors_only_with_level( &conteiner, FCML_EN_CEH_EL_WARN );
62
63 STF_ASSERT_PTR_NULL( conteiner.errors );
64 STF_ASSERT_PTR_NULL( conteiner.last_error );
65
66 }
67
68 void fcml_tf_ceh_test_remove_errors(void) {
69
70 fcml_st_ceh_error_container conteiner = { NULL };
71
72 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 1.", 1, FCML_EN_CEH_EL_ERROR ) );
73 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 2.", 2, FCML_EN_CEH_EL_ERROR ) );
74 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 3.", 3, FCML_EN_CEH_EL_WARN ) );
75 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 4.", 4, FCML_EN_CEH_EL_WARN ) );
76
77 fcml_st_ceh_error_info *error = conteiner.errors;
78 STF_ASSERT_EQUAL( error->code, 1 );
79 error = error->next_error;
80 STF_ASSERT_EQUAL( error->code, 2 );
81 error = error->next_error;
82 STF_ASSERT_EQUAL( error->code, 3 );
83 error = error->next_error;
84 STF_ASSERT_EQUAL( error->code, 4 );
85 error = error->next_error;
86 STF_ASSERT_PTR_NULL( error );
87
88 fcml_fn_ceh_free_errors_only( &conteiner );
89
90 STF_ASSERT_PTR_NULL( conteiner.errors );
91 STF_ASSERT_PTR_NULL( conteiner.last_error );
92
93 }
94
95 void fcml_tf_ceh_test_move(void) {
96
97 fcml_st_ceh_error_container conteiner = { NULL };
98 fcml_st_ceh_error_container conteiner_next = { NULL };
99
100 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 1.", 1, FCML_EN_CEH_EL_ERROR ) );
101 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 2.", 2, FCML_EN_CEH_EL_ERROR ) );
102 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 3.", 3, FCML_EN_CEH_EL_WARN ) );
103 STF_ASSERT_PTR_NOT_NULL( fcml_fn_ceh_add_error( &conteiner, "Message 4.", 4, FCML_EN_CEH_EL_WARN ) );
104
105 fcml_st_ceh_error_info *error = conteiner.errors;
106 STF_ASSERT_EQUAL( error->code, 1 );
107 error = error->next_error;
108 STF_ASSERT_EQUAL( error->code, 2 );
109 error = error->next_error;
110 STF_ASSERT_EQUAL( error->code, 3 );
111 error = error->next_error;
112 STF_ASSERT_EQUAL( error->code, 4 );
113 error = error->next_error;
114 STF_ASSERT_PTR_NULL( error );
115
116 fcml_fn_ceh_move_errors( &conteiner_next, &conteiner );
117
118 STF_ASSERT_PTR_NULL( conteiner.errors );
119 STF_ASSERT_PTR_NULL( conteiner.last_error );
120
121 error = conteiner_next.errors;
122 STF_ASSERT_EQUAL( error->code, 1 );
123 error = error->next_error;
124 STF_ASSERT_EQUAL( error->code, 2 );
125 error = error->next_error;
126 STF_ASSERT_EQUAL( error->code, 3 );
127 error = error->next_error;
128 STF_ASSERT_EQUAL( error->code, 4 );
129 error = error->next_error;
130 STF_ASSERT_PTR_NULL( error );
131
132 fcml_fn_ceh_free_errors_only( &conteiner_next );
133
134 }
135
136 fcml_stf_test_case fcml_ti_ceh[] = {
137 { "fcml_tf_ceh_test_remove_errors_by_level", fcml_tf_ceh_test_remove_errors_by_level },
138 { "fcml_tf_ceh_test_remove_errors", fcml_tf_ceh_test_remove_errors },
139 { "fcml_tf_ceh_test_move", fcml_tf_ceh_test_move },
140 FCML_STF_NULL_TEST
141 };
142
143 fcml_stf_test_suite fcml_si_ceh = {
144 "suite-fcml-ceh", fcml_tf_ceh_suite_init, fcml_tf_ceh_suite_cleanup, fcml_ti_ceh
145 };