aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 21:37:49 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-09-21 21:37:49 +0200
commit4127daa65ed8962900b386e138577a83bbc6baa5 (patch)
treea923ad42e411d94ac31a20d149dacd86ae648c31
parenta0ff652261af4bebad0419aaf99ccea64c7ccf2e (diff)
downloaddns-4127daa65ed8962900b386e138577a83bbc6baa5.tar.gz
test: database
-rw-r--r--src/database.c3
-rw-r--r--tests/database.c21
2 files changed, 24 insertions, 0 deletions
diff --git a/src/database.c b/src/database.c
index 21174f7..491fae1 100644
--- a/src/database.c
+++ b/src/database.c
@@ -10,6 +10,9 @@ int database_init ( database_t* _database ) {
unsigned int i = 0;
size_t rr_size;
+ if ( !_database )
+ return 1;
+
/* Initialize 2D array of tree_node pointers, paranoia style */
if ( !( _database->zone = malloc( sizeof( tree_node_t** ) * DB_CLASS_LEN ) ) )
return 1;
diff --git a/tests/database.c b/tests/database.c
index 18c7ec4..c1bd9ed 100644
--- a/tests/database.c
+++ b/tests/database.c
@@ -8,6 +8,7 @@
#include "../src/database.h"
#include "../src/zonefile.h"
+#include <check.h>
START_TEST ( test_database_parse_zonefile ) {
int ret;
@@ -32,11 +33,31 @@ START_TEST ( test_database_parse_zonefile ) {
ck_assert_ptr_null( db.zone );
} END_TEST
+START_TEST (test_database_error_handling) {
+ database_t db;
+ database_rdata_t rdata;
+ database_init(&db);
+
+ ck_assert_int_ne(database_init(NULL), 0);
+ ck_assert_int_ne(database_destroy(NULL), 0);
+ ck_assert_int_ne(database_query(NULL, NULL, NULL, 0, 0, 0), 0);
+
+ /* Record not found */
+ ck_assert_int_ne(database_query(&rdata, &db, "aa", 3, 1, 1), 0);
+
+ /* Invalid record */
+ ck_assert_int_ne(database_query(&rdata, &db, "aa", 3, 1, 777), 0);
+ ck_assert_int_ne(database_query(&rdata, &db, "aa", 3, 777, 1), 0);
+
+ database_destroy(&db);
+} END_TEST
+
TCase* test_database(void) {
TCase *tc = tcase_create("Database");
tcase_add_test(tc, test_database_parse_zonefile);
+ tcase_add_test(tc, test_database_error_handling);
return tc;
}