Debian Codegraph @

tests/api/feat.c

raw symbols SCIP
1 /*
2 * ProFTPD - FTP server testsuite
3 * Copyright (c) 2008-2016 The ProFTPD Project team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, The ProFTPD Project team and other respective
20 * copyright holders give permission to link this program with OpenSSL, and
21 * distribute the resulting executable, without including the source code for
22 * OpenSSL in the source distribution.
23 */
24
25 /* Feat API tests */
26
27 #include "tests.h"
28
29 static pool *p = NULL;
30
31 /* Fixtures */
32
33 static void set_up(void) {
34 if (p == NULL) {
35 p = permanent_pool = make_sub_pool(NULL);
36 }
37 }
38
39 static void tear_down(void) {
40 if (p) {
41 destroy_pool(p);
42 p = NULL;
43 permanent_pool = NULL;
44 }
45 }
46
47 /* Tests */
48
49 START_TEST (feat_add_test) {
50 int res;
51 const char *key;
52
53 res = pr_feat_add(NULL);
54 ck_assert_msg(res == -1, "Failed to handle null feat");
55 ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL");
56
57 key = "foo";
58
59 res = pr_feat_add(key);
60 ck_assert_msg(res == 0, "Failed to add feat: %s", strerror(errno));
61
62 res = pr_feat_add(key);
63 ck_assert_msg(res == -1, "Failed to handle duplicate feat");
64 ck_assert_msg(errno == EEXIST, "Failed to set errno to EEXIST");
65 }
66 END_TEST
67
68 START_TEST (feat_get_test) {
69 int ok;
70 const char *res;
71
72 res = pr_feat_get();
73 ck_assert_msg(res == NULL, "Failed to handle empty feat");
74 ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM");
75
76 ok = pr_feat_add("foo");
77 ck_assert_msg(ok == 0, "Failed to add feat: %s", strerror(errno));
78
79 res = pr_feat_get();
80 ck_assert_msg(res != NULL, "Failed to get feat: %s", strerror(errno));
81 ck_assert_msg(strcmp(res, "foo") == 0, "Expected '%s', got '%s'", "foo", res);
82
83 res = pr_feat_get();
84 ck_assert_msg(res != NULL, "Failed to get feat: %s", strerror(errno));
85 ck_assert_msg(strcmp(res, "foo") == 0, "Expected '%s', got '%s'", "foo", res);
86 }
87 END_TEST
88
89 START_TEST (feat_get_next_test) {
90 int ok;
91 const char *res;
92
93 res = pr_feat_get_next();
94 ck_assert_msg(res == NULL, "Failed to handle empty feat");
95 ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM");
96
97 ok = pr_feat_add("foo");
98 ck_assert_msg(ok == 0, "Failed to add feat: %s", strerror(errno));
99
100 res = pr_feat_get_next();
101 ck_assert_msg(res != NULL, "Failed to get feat: %s", strerror(errno));
102 ck_assert_msg(strcmp(res, "foo") == 0, "Expected '%s', got '%s'", "foo", res);
103
104 res = pr_feat_get_next();
105 ck_assert_msg(res == NULL, "Expected null, got '%s'", res);
106 }
107 END_TEST
108
109 START_TEST (feat_remove_test) {
110 int res;
111 const char *feat;
112
113 res = pr_feat_remove(NULL);
114 ck_assert_msg(res == -1, "Failed to handle empty feat");
115 ck_assert_msg(errno == EPERM, "Failed to set errno to EPERM");
116
117 feat = "foo";
118 res = pr_feat_add(feat);
119 ck_assert_msg(res == 0, "Failed to add feat: %s", strerror(errno));
120
121 res = pr_feat_remove(NULL);
122 ck_assert_msg(res == -1, "Failed to handle null feat");
123 ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL");
124
125 res = pr_feat_remove(feat);
126 ck_assert_msg(res == 0, "Failed to remove feat: %s", strerror(errno));
127
128 res = pr_feat_remove(feat);
129 ck_assert_msg(res == -1, "Failed to detected removed feat");
130 ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT");
131 }
132 END_TEST
133
134 Suite *tests_get_feat_suite(void) {
135 Suite *suite;
136 TCase *testcase;
137
138 suite = suite_create("feat");
139
140 testcase = tcase_create("base");
141
142 tcase_add_checked_fixture(testcase, set_up, tear_down);
143
144 tcase_add_test(testcase, feat_add_test);
145 tcase_add_test(testcase, feat_get_test);
146 tcase_add_test(testcase, feat_get_next_test);
147 tcase_add_test(testcase, feat_remove_test);
148
149 suite_add_tcase(suite, testcase);
150
151 return suite;
152 }