check_array.c | check_array.c | |||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
* GNU Lesser General Public License for more details. | * GNU Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public License | * You should have received a copy of the GNU Lesser General Public License | |||
* along with libqb. If not, see <http://www.gnu.org/licenses/>. | * along with libqb. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | */ | |||
#include "os_base.h" | #include "os_base.h" | |||
#include <check.h> | #include <check.h> | |||
#include <qb/qbdefs.h> | #include <qb/qbdefs.h> | |||
#include <qb/qbutil.h> | #include <qb/qblog.h> | |||
#include <qb/qbarray.h> | #include <qb/qbarray.h> | |||
struct test_my_st { | struct test_my_st { | |||
int32_t a; | int32_t a; | |||
int32_t b; | int32_t b; | |||
int32_t c; | int32_t c; | |||
int32_t d; | int32_t d; | |||
}; | }; | |||
START_TEST(test_array_limits) | START_TEST(test_array_limits) | |||
skipping to change at line 57 | skipping to change at line 57 | |||
fail_unless(a == NULL); | fail_unless(a == NULL); | |||
a = qb_array_create(67, 0); | a = qb_array_create(67, 0); | |||
fail_unless(a == NULL); | fail_unless(a == NULL); | |||
/* working array */ | /* working array */ | |||
a = qb_array_create(10, sizeof(struct test_my_st)); | a = qb_array_create(10, sizeof(struct test_my_st)); | |||
fail_if(a == NULL); | fail_if(a == NULL); | |||
/* out-of-bounds */ | /* out-of-bounds */ | |||
res = qb_array_index(a, 10, (void**)&st); | res = qb_array_index(a, 10, (void**)&st); | |||
ck_assert_int_eq(res, -EINVAL); | ck_assert_int_eq(res, -ERANGE); | |||
res = qb_array_index(a, -10, (void**)&st); | res = qb_array_index(a, -10, (void**)&st); | |||
ck_assert_int_eq(res, -EINVAL); | ck_assert_int_eq(res, -ERANGE); | |||
res = qb_array_index(NULL, 1, (void**)&st); | res = qb_array_index(NULL, 1, (void**)&st); | |||
ck_assert_int_eq(res, -EINVAL); | ck_assert_int_eq(res, -EINVAL); | |||
res = qb_array_index(a, -10, NULL); | res = qb_array_index(a, -10, NULL); | |||
ck_assert_int_eq(res, -EINVAL); | ck_assert_int_eq(res, -EINVAL); | |||
qb_array_free(a); | qb_array_free(a); | |||
} | } | |||
END_TEST | END_TEST | |||
START_TEST(test_array_alloc_free) | ||||
{ | ||||
qb_array_t *a; | ||||
a = qb_array_create(65536, sizeof(struct test_my_st)); | ||||
qb_array_free(a); | ||||
} | ||||
END_TEST | ||||
START_TEST(test_array_correct_retrieval) | START_TEST(test_array_correct_retrieval) | |||
{ | { | |||
qb_array_t *a; | qb_array_t *a; | |||
int32_t i; | int32_t i; | |||
int32_t res; | int32_t res; | |||
struct test_my_st *st; | struct test_my_st *st; | |||
a = qb_array_create(112, sizeof(struct test_my_st)); | a = qb_array_create(112, sizeof(struct test_my_st)); | |||
for (i = 0; i < 112; i++) { | for (i = 0; i < 112; i++) { | |||
skipping to change at line 136 | skipping to change at line 144 | |||
static Suite *array_suite(void) | static Suite *array_suite(void) | |||
{ | { | |||
TCase *tc; | TCase *tc; | |||
Suite *s = suite_create("qb_array"); | Suite *s = suite_create("qb_array"); | |||
tc = tcase_create("limits"); | tc = tcase_create("limits"); | |||
tcase_add_test(tc, test_array_limits); | tcase_add_test(tc, test_array_limits); | |||
suite_add_tcase(s, tc); | suite_add_tcase(s, tc); | |||
tc = tcase_create("alloc_free"); | ||||
tcase_add_test(tc, test_array_alloc_free); | ||||
suite_add_tcase(s, tc); | ||||
tc = tcase_create("correct_retrieval"); | tc = tcase_create("correct_retrieval"); | |||
tcase_add_test(tc, test_array_correct_retrieval); | tcase_add_test(tc, test_array_correct_retrieval); | |||
suite_add_tcase(s, tc); | suite_add_tcase(s, tc); | |||
tc = tcase_create("static_memory"); | tc = tcase_create("static_memory"); | |||
tcase_add_test(tc, test_array_static_memory); | tcase_add_test(tc, test_array_static_memory); | |||
suite_add_tcase(s, tc); | suite_add_tcase(s, tc); | |||
return s; | return s; | |||
} | } | |||
static void libqb_log_fn(const char *file_name, | ||||
int32_t file_line, int32_t severity, const char *ms | ||||
g) | ||||
{ | ||||
printf("libqb: %s:%d %s\n", file_name, file_line, msg); | ||||
} | ||||
int32_t main(void) | int32_t main(void) | |||
{ | { | |||
int32_t number_failed; | int32_t number_failed; | |||
Suite *s = array_suite(); | Suite *s = array_suite(); | |||
SRunner *sr = srunner_create(s); | SRunner *sr = srunner_create(s); | |||
qb_util_set_log_function(libqb_log_fn); | qb_log_init("check", LOG_USER, LOG_EMERG); | |||
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); | ||||
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD, | ||||
QB_LOG_FILTER_FILE, "*", LOG_INFO); | ||||
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); | ||||
srunner_run_all(sr, CK_VERBOSE); | srunner_run_all(sr, CK_VERBOSE); | |||
number_failed = srunner_ntests_failed(sr); | number_failed = srunner_ntests_failed(sr); | |||
srunner_free(sr); | srunner_free(sr); | |||
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | |||
} | } | |||
End of changes. 7 change blocks. | ||||
11 lines changed or deleted | 20 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |