Added tests for getdns_dict_get_int()

This commit is contained in:
Craig E. Despeaux 2014-01-07 14:49:04 -05:00
parent 7807d1ade0
commit d5f1a3fe4b
2 changed files with 167 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "check_getdns_dict_get_dict.h"
#include "check_getdns_dict_get_list.h"
#include "check_getdns_dict_get_bindata.h"
#include "check_getdns_dict_get_int.h"
int
main (void)
@ -41,6 +42,7 @@ main (void)
Suite *getdns_dict_get_dict_suite(void);
Suite *getdns_dict_get_list_suite(void);
Suite *getdns_dict_get_bindata_suite(void);
Suite *getdns_dict_get_int_suite(void);
sr = srunner_create(getdns_general_suite());
srunner_add_suite(sr, getdns_general_sync_suite());
@ -55,6 +57,7 @@ main (void)
srunner_add_suite(sr, getdns_dict_get_dict_suite());
srunner_add_suite(sr, getdns_dict_get_list_suite());
srunner_add_suite(sr, getdns_dict_get_bindata_suite());
srunner_add_suite(sr, getdns_dict_get_int_suite());
srunner_set_log(sr, "check_getdns.log");
srunner_run_all(sr, CK_NORMAL);

View File

@ -0,0 +1,164 @@
#ifndef _check_getdns_dict_get_int_h_
#define _check_getdns_dict_get_int_h_
/*
**************************************************************************
* *
* T E S T S F O R G E T D N S _ D I C T _ G E T _ I N T *
* *
**************************************************************************
*/
START_TEST (getdns_dict_get_int_1)
{
/*
* this_dict = NULL
* expect: GETDNS_RETURN_NO_SUCH_DICT_NAME
*/
struct getdns_dict *this_dict = NULL;
uint32_t answer;
ASSERT_RC(getdns_dict_get_int(this_dict, "key", &answer),
GETDNS_RETURN_NO_SUCH_DICT_NAME, "Return code from getdns_dict_get_int()");
}
END_TEST
START_TEST (getdns_dict_get_int_2)
{
/*
* name = NULL
* expect: GETDNS_RETURN_NO_SUCH_DICT_NAME
*/
struct getdns_dict *this_dict = NULL;
uint32_t answer;
DICT_CREATE(this_dict);
ASSERT_RC(getdns_dict_set_int(this_dict, "int", 10),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_get_int(this_dict, NULL, &answer),
GETDNS_RETURN_NO_SUCH_DICT_NAME, "Return code from getdns_dict_get_int()");
DICT_DESTROY(this_dict);
}
END_TEST
START_TEST (getdns_dict_get_int_3)
{
/*
* name does not exist in dict
* Create a dict with one int (name = "ten", value = 10)
* Call getdns_dict_get_int() against the dict with name = "nine"
* expect: GETDNS_RETURN_NO_SUCH_DICT_NAME
*/
struct getdns_dict *this_dict = NULL;
uint32_t answer;
DICT_CREATE(this_dict);
ASSERT_RC(getdns_dict_set_int(this_dict, "ten", 10),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_get_int(this_dict, "nine", &answer),
GETDNS_RETURN_NO_SUCH_DICT_NAME, "Return code from getdns_dict_get_int()");
DICT_DESTROY(this_dict);
}
END_TEST
START_TEST (getdns_dict_get_int_4)
{
/*
* data type at name is not int
* Create a dict
* Create some bindata containing "bindata" and add it to the dict with name = "bindata"
* Call getdns_dict_get_int() with name = "bindata"
* expect: GETDNS_RETURN_WRONG_TYPE_REQUESTED
*/
struct getdns_dict *this_dict = NULL;
struct getdns_bindata bindata = { 8, (void *)"bindata" };
uint32_t answer;
DICT_CREATE(this_dict);
ASSERT_RC(getdns_dict_set_bindata(this_dict, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
ASSERT_RC(getdns_dict_get_int(this_dict, "bindata", &answer),
GETDNS_RETURN_WRONG_TYPE_REQUESTED, "Return code from getdns_dict_get_int()");
DICT_DESTROY(this_dict);
}
END_TEST
START_TEST (getdns_dict_get_int_5)
{
/*
* answer = NULL
* expect: GETDNS_RETURN_NO_SUCH_DICT_NAME
*/
struct getdns_dict *this_dict = NULL;
DICT_CREATE(this_dict);
ASSERT_RC(getdns_dict_set_int(this_dict, "int", 10),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_get_int(this_dict, "int", NULL),
GETDNS_RETURN_NO_SUCH_DICT_NAME, "Return code from getdns_dict_get_int()");
DICT_DESTROY(this_dict);
}
END_TEST
START_TEST (getdns_dict_get_int_6)
{
/*
* successful get int
* Create a dict with one int (name = "ten", value = 10)
* Call getdns_dict_get_int() against the dict with name = "ten"
* expect: GETDNS_RETURN_GOOD
* int retrievedshould == 10
*
*/
struct getdns_dict *this_dict = NULL;
uint32_t answer;
DICT_CREATE(this_dict);
ASSERT_RC(getdns_dict_set_int(this_dict, "ten", 10),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_get_int(this_dict, "ten", &answer),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_get_int()");
ck_assert_msg(answer == 10, "Expected retrieve int == 10, got: %d",
answer);
DICT_DESTROY(this_dict);
}
END_TEST
Suite *
getdns_dict_get_int_suite (void)
{
Suite *s = suite_create ("getdns_dict_get_int()");
/* Negative test caseis */
TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_dict_get_int_1);
tcase_add_test(tc_neg, getdns_dict_get_int_2);
tcase_add_test(tc_neg, getdns_dict_get_int_3);
tcase_add_test(tc_neg, getdns_dict_get_int_4);
tcase_add_test(tc_neg, getdns_dict_get_int_5);
suite_add_tcase(s, tc_neg);
/* Positive test cases */
TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_dict_get_int_6);
suite_add_tcase(s, tc_pos);
return s;
}
#endif