From: Marek VavruĊĦa Date: Sun, 26 Apr 2015 21:37:57 +0000 (+0200) Subject: tests: added parameter checks for zonecut X-Git-Tag: v1.0.0-beta1~228^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc35e304aad75d3758267159efa96e0d12a86e96;p=thirdparty%2Fknot-resolver.git tests: added parameter checks for zonecut --- diff --git a/.gitignore b/.gitignore index 8b39b6193..4d2c98a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/lib/zonecut.c b/lib/zonecut.c index fdfebed3e..69f56870d 100644 --- a/lib/zonecut.c +++ b/lib/zonecut.c @@ -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 index 000000000..d2e0eb6c1 --- /dev/null +++ b/tests/test_zonecut.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2014 CZ.NIC, z.s.p.o. + + 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 . + */ + +#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); +} diff --git a/tests/unit.mk b/tests/unit.mk index d8ac592e7..d2f2f59ea 100644 --- a/tests/unit.mk +++ b/tests/unit.mk @@ -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