]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests: added parameter checks for zonecut
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 26 Apr 2015 21:37:57 +0000 (23:37 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 26 Apr 2015 21:37:57 +0000 (23:37 +0200)
.gitignore
lib/zonecut.c
tests/test_zonecut.c [new file with mode: 0644]
tests/unit.mk

index 8b39b6193b8d42369fb7fdd023d078afaf8bf5e9..4d2c98a6be4ad7b910ff983f4396e6c2b14bf740 100644 (file)
@@ -15,6 +15,7 @@
 *.6
 *.log
 *.inc
+*.mdb
 .dirstamp
 .libs
 .deps
@@ -46,3 +47,4 @@ tmp*
 /tests/test_pack
 /tests/test_set
 /tests/test_utils
+/tests/test_zonecut
index fdfebed3e4c91eb370d228544099902b6d4f73a7..69f56870d6ea5e13e7d0a37b31a613ec296b1639 100644 (file)
@@ -65,7 +65,7 @@ static void update_cut_name(struct kr_zonecut *cut, const knot_dname_t *name)
 
 int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, mm_ctx_t *pool)
 {
-       if (cut == NULL) {
+       if (cut == NULL || name == NULL) {
                return kr_error(EINVAL);
        }
 
@@ -98,7 +98,7 @@ void kr_zonecut_deinit(struct kr_zonecut *cut)
 
 void kr_zonecut_set(struct kr_zonecut *cut, const knot_dname_t *name)
 {
-       if (cut == NULL) {
+       if (cut == NULL || name == NULL) {
                return;
        }
        kr_zonecut_deinit(cut);
diff --git a/tests/test_zonecut.c b/tests/test_zonecut.c
new file mode 100644 (file)
index 0000000..d2e0eb6
--- /dev/null
@@ -0,0 +1,43 @@
+/*  Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tests/test.h"
+#include "lib/zonecut.h"
+
+static void test_zonecut_params(void **state)
+{
+       /* NULL args */
+       struct kr_zonecut cut;
+       assert_int_not_equal(kr_zonecut_init(NULL, NULL, NULL), 0);
+       assert_int_not_equal(kr_zonecut_init(&cut, NULL, NULL), 0);
+       kr_zonecut_deinit(NULL);
+       kr_zonecut_set(NULL, NULL);
+       kr_zonecut_set(&cut, NULL);
+       assert_int_not_equal(kr_zonecut_add(NULL, NULL, NULL), 0);
+       assert_null(kr_zonecut_find(NULL, NULL));
+       assert_null(kr_zonecut_find(&cut, NULL));
+       assert_int_not_equal(kr_zonecut_set_sbelt(NULL), 0);
+       assert_int_not_equal(kr_zonecut_find_cached(NULL, NULL, 0), 0);
+}
+
+int main(void)
+{
+       const UnitTest tests[] = {
+               unit_test(test_zonecut_params)
+       };
+
+       return run_tests(tests);
+}
index d8ac592e79ef0095b506df2c1d4e16c12efdcefe..d2f2f59ead6c6d02ca74874e0f2651410b5b5444 100644 (file)
@@ -9,8 +9,9 @@ tests_BIN := \
        test_pack \
        test_utils \
        test_module \
-       test_rplan \
        test_cache \
+       test_zonecut \
+       test_rplan \
        test_resolve
 
 mock_cmodule_SOURCES := tests/mock_cmodule.c