From a385c79cfe37abd947cd5b5555ebcca86da87cc0 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 17 Aug 2013 23:02:36 +0200 Subject: [PATCH 1/3] Use ck_assert_msg --- auto_tests/messenger_test.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 374bc5a6..67156db4 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -87,13 +87,13 @@ START_TEST(test_m_set_userstatus) uint16_t good_length = strlen(status); uint16_t bad_length = REALLY_BIG_NUMBER; - if (m_set_statusmessage(m, (uint8_t *)status, bad_length) != -1) - ck_abort_msg("m_set_userstatus did NOT catch the following length: %d\n", - REALLY_BIG_NUMBER); + ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1), + "m_set_userstatus did NOT catch the following length: %d\n", + REALLY_BIG_NUMBER); - if ((m_set_statusmessage(m, (uint8_t *)status, good_length)) != 0) - ck_abort_msg("m_set_userstatus did NOT return 0 on the following length: %d\n" - "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); + ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0), + "m_set_userstatus did NOT return 0 on the following length: %d\n" + "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); } END_TEST @@ -156,12 +156,11 @@ START_TEST(test_setname) int good_length = strlen(good_name); int bad_length = REALLY_BIG_NUMBER; - if (setname(m, (uint8_t *)good_name, bad_length) != -1) - ck_abort_msg("setname() did NOT error on %d as a length argument!\n", - bad_length); + ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1), + "setname() did NOT error on %d as a length argument!\n", bad_length); - if (setname(m, (uint8_t *)good_name, good_length) != 0) - ck_abort_msg("setname() did NOT return 0 on good arguments!\n"); + ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0), + "setname() did NOT return 0 on good arguments!\n"); } END_TEST From 5c0c182ee1644f7f93f0fdb16815616132bb3ac9 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 17 Aug 2013 23:03:26 +0200 Subject: [PATCH 2/3] Remove unused script for running tests "make test" should be used to run the tests --- auto_tests/run_tests | 5 ----- 1 file changed, 5 deletions(-) delete mode 100755 auto_tests/run_tests diff --git a/auto_tests/run_tests b/auto_tests/run_tests deleted file mode 100755 index 1899f354..00000000 --- a/auto_tests/run_tests +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# run_tests - run the current tests for tox core -set -e - -./messenger_test && ./friends_test && ./crypto_test From 2e90691f4cf9bfdcc4ec9317ffdbbb389f5e8ddc Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sat, 17 Aug 2013 23:23:54 +0200 Subject: [PATCH 3/3] Add test for getname --- auto_tests/messenger_test.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 67156db4..3ca89152 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -196,24 +196,20 @@ START_TEST(test_m_copy_userstatus) END_TEST */ -/* this test is excluded for now, due to lack of a way - * to set a friend's nickname for now. - * ideas: - * if we have access to the friends list, we could - * just add a name manually ourselves. */ -/* START_TEST(test_getname) { uint8_t name_buf[MAX_NAME_LENGTH]; + uint8_t test_name[] = {'f', 'o', 'o'}; - assert(getname(-1, name_buf) == -1); - assert(getname(REALLY_BIG_NUMBER, name_buf) == -1); + ck_assert(getname(m, -1, name_buf) == -1); + ck_assert(getname(m, REALLY_BIG_NUMBER, name_buf) == -1); - getname(friend_id_num, name_buf); - assert(name_buf[MAX_NAME_LENGTH] == '\0'); // something like this + memcpy(m->friendlist[0].name, &test_name[0], 3); + getname(m, 0, &name_buf[0]); + + ck_assert(strcmp((char *)&name_buf[0], "foo") == 0); } END_TEST -*/ Suite *messenger_suite(void) { @@ -227,6 +223,7 @@ Suite *messenger_suite(void) TCase *delfriend = tcase_create("delfriend"); //TCase *addfriend = tcase_create("addfriend"); TCase *setname = tcase_create("setname"); + TCase *getname = tcase_create("getname"); tcase_add_test(userstatus_size, test_m_get_userstatus_size); tcase_add_test(set_userstatus, test_m_set_userstatus); @@ -235,6 +232,7 @@ Suite *messenger_suite(void) tcase_add_test(send_message, test_m_sendmesage); tcase_add_test(delfriend, test_m_delfriend); //tcase_add_test(addfriend, test_m_addfriend); + tcase_add_test(setname, test_getname); tcase_add_test(setname, test_setname); suite_add_tcase(s, userstatus_size); @@ -244,6 +242,7 @@ Suite *messenger_suite(void) suite_add_tcase(s, getself_name); suite_add_tcase(s, delfriend); //suite_add_tcase(s, addfriend); + suite_add_tcase(s, getname); suite_add_tcase(s, setname); return s;