- Timestamp:
- 2015-02-20T22:50:54Z (10 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- Location:
- tests
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/check.c
raf359b4 r5ebff60 8 8 #include "testsuite.h" 9 9 10 global_t global; 10 global_t global; /* Against global namespace pollution */ 11 11 12 12 gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2) 13 13 { 14 14 int sock[2]; 15 15 16 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNIX, sock) < 0) { 16 17 perror("socketpair"); … … 27 28 irc_t *irc; 28 29 GIOChannel *ch1, *ch2; 29 if (!g_io_channel_pair(&ch1, &ch2)) 30 31 if (!g_io_channel_pair(&ch1, &ch2)) { 30 32 return NULL; 33 } 31 34 irc = irc_new(g_io_channel_unix_get_fd(ch1)); 32 35 return irc; … … 37 40 struct timeval time[1]; 38 41 39 gettimeofday( time, 0);40 return( (double) time->tv_sec + (double) time->tv_usec / 1000000);42 gettimeofday(time, 0); 43 return((double) time->tv_sec + (double) time->tv_usec / 1000000); 41 44 } 42 45 … … 71 74 Suite *jabber_util_suite(void); 72 75 73 int main 76 int main(int argc, char **argv) 74 77 { 75 78 int nf; … … 79 82 gboolean verbose = FALSE; 80 83 GOptionEntry options[] = { 81 { "no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" },82 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },84 { "no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" }, 85 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, 83 86 { NULL } 84 87 }; … … 87 90 g_option_context_add_main_entries(pc, options, NULL); 88 91 89 if (!g_option_context_parse(pc, &argc, &argv, NULL))92 if (!g_option_context_parse(pc, &argc, &argv, NULL)) { 90 93 return 1; 94 } 91 95 92 96 g_option_context_free(pc); … … 97 101 98 102 if (verbose) { 99 log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE);103 log_link(LOGLVL_ERROR, LOGOUTPUT_CONSOLE); 100 104 #ifdef DEBUG 101 log_link( LOGLVL_DEBUG, LOGOUTPUT_CONSOLE);105 log_link(LOGLVL_DEBUG, LOGOUTPUT_CONSOLE); 102 106 #endif 103 log_link( LOGLVL_INFO, LOGOUTPUT_CONSOLE);104 log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE);107 log_link(LOGLVL_INFO, LOGOUTPUT_CONSOLE); 108 log_link(LOGLVL_WARNING, LOGOUTPUT_CONSOLE); 105 109 } 106 110 107 global.conf = conf_load( 111 global.conf = conf_load(0, NULL); 108 112 global.conf->runmode = RUNMODE_DAEMON; 109 113 … … 118 122 srunner_add_suite(sr, jabber_sasl_suite()); 119 123 srunner_add_suite(sr, jabber_util_suite()); 120 if (no_fork) 124 if (no_fork) { 121 125 srunner_set_fork_status(sr, CK_NOFORK); 122 srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL); 126 } 127 srunner_run_all(sr, verbose ? CK_VERBOSE : CK_NORMAL); 123 128 nf = srunner_ntests_failed(sr); 124 129 srunner_free(sr); -
tests/check_arc.c
raf359b4 r5ebff60 21 21 { 22 22 int i; 23 24 for( i = 0; clear_tests[i]; i++ ) 25 { 26 tcase_fn_start (clear_tests[i], __FILE__, __LINE__); 23 24 for (i = 0; clear_tests[i]; i++) { 25 tcase_fn_start(clear_tests[i], __FILE__, __LINE__); 27 26 unsigned char *crypted; 28 27 char *decrypted; 29 28 int len; 30 31 len = arc_encode( clear_tests[i], 0, &crypted, password, 12);32 len = arc_decode( crypted, len, &decrypted, password);33 34 fail_if( strcmp( clear_tests[i], decrypted) != 0,35 "%s didn't decrypt back properly", clear_tests[i]);36 37 g_free( crypted);38 g_free( decrypted);29 30 len = arc_encode(clear_tests[i], 0, &crypted, password, 12); 31 len = arc_decode(crypted, len, &decrypted, password); 32 33 fail_if(strcmp(clear_tests[i], decrypted) != 0, 34 "%s didn't decrypt back properly", clear_tests[i]); 35 36 g_free(crypted); 37 g_free(decrypted); 39 38 } 40 39 } 41 40 42 struct 43 { 41 struct { 44 42 unsigned char crypted[30]; 45 43 int len; … … 53 51 }, 18, "short pass" 54 52 }, 55 53 56 54 /* Two blocks with padding. */ 57 55 { … … 78 76 { 79 77 int i; 80 81 for( i = 0; decrypt_tests[i].len; i++ ) 82 { 83 tcase_fn_start (decrypt_tests[i].decrypted, __FILE__, __LINE__); 78 79 for (i = 0; decrypt_tests[i].len; i++) { 80 tcase_fn_start(decrypt_tests[i].decrypted, __FILE__, __LINE__); 84 81 char *decrypted; 85 82 int len; 86 87 len = arc_decode( 88 &decrypted, password);89 90 fail_if( len == -1,91 "`%s' didn't decrypt properly", decrypt_tests[i].decrypted);92 fail_if( strcmp( decrypt_tests[i].decrypted, decrypted) != 0,93 "`%s' didn't decrypt properly", decrypt_tests[i].decrypted);94 95 g_free( decrypted);83 84 len = arc_decode(decrypt_tests[i].crypted, decrypt_tests[i].len, 85 &decrypted, password); 86 87 fail_if(len == -1, 88 "`%s' didn't decrypt properly", decrypt_tests[i].decrypted); 89 fail_if(strcmp(decrypt_tests[i].decrypted, decrypted) != 0, 90 "`%s' didn't decrypt properly", decrypt_tests[i].decrypted); 91 92 g_free(decrypted); 96 93 } 97 94 } 98 95 99 Suite *arc_suite 96 Suite *arc_suite(void) 100 97 { 101 98 Suite *s = suite_create("ArcFour"); 102 99 TCase *tc_core = tcase_create("Core"); 103 suite_add_tcase (s, tc_core); 104 tcase_add_test (tc_core, check_codec); 105 tcase_add_test (tc_core, check_decod); 100 101 suite_add_tcase(s, tc_core); 102 tcase_add_test(tc_core, check_codec); 103 tcase_add_test(tc_core, check_decod); 106 104 return s; 107 105 } -
tests/check_help.c
raf359b4 r5ebff60 8 8 9 9 START_TEST(test_help_initfree) 10 help_t *h, *r;11 12 13 10 help_t * h, *r; 11 r = help_init(&h, "/dev/null"); 12 fail_if(r == NULL); 13 fail_if(r != h); 14 14 15 16 15 help_free(&h); 16 fail_if(h != NULL); 17 17 END_TEST 18 18 19 19 START_TEST(test_help_nonexistent) 20 help_t *h, *r;21 22 23 20 help_t * h, *r; 21 r = help_init(&h, "/dev/null"); 22 fail_unless(help_get(&h, "nonexistent") == NULL); 23 fail_if(r == NULL); 24 24 END_TEST 25 25 26 Suite *help_suite 26 Suite *help_suite(void) 27 27 { 28 28 Suite *s = suite_create("Help"); 29 29 TCase *tc_core = tcase_create("Core"); 30 suite_add_tcase (s, tc_core); 31 tcase_add_test (tc_core, test_help_initfree); 32 tcase_add_test (tc_core, test_help_nonexistent); 30 31 suite_add_tcase(s, tc_core); 32 tcase_add_test(tc_core, test_help_initfree); 33 tcase_add_test(tc_core, test_help_nonexistent); 33 34 return s; 34 35 } -
tests/check_irc.c
raf359b4 r5ebff60 9 9 10 10 START_TEST(test_connect) 11 GIOChannel *ch1, *ch2;12 13 14 11 GIOChannel * ch1, *ch2; 12 irc_t *irc; 13 char *raw; 14 fail_unless(g_io_channel_pair(&ch1, &ch2)); 15 15 16 16 irc = irc_new(g_io_channel_unix_get_fd(ch1)); 17 17 18 18 irc_free(irc); 19 19 20 fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); 21 22 fail_if(strcmp(raw, "") != 0); 20 fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); 23 21 24 g_free(raw); 22 fail_if(strcmp(raw, "") != 0); 23 24 g_free(raw); 25 25 END_TEST 26 26 27 27 START_TEST(test_login) 28 GIOChannel *ch1, *ch2;29 30 31 28 GIOChannel * ch1, *ch2; 29 irc_t *irc; 30 char *raw; 31 fail_unless(g_io_channel_pair(&ch1, &ch2)); 32 32 33 34 33 g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL); 34 g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL); 35 35 36 36 irc = irc_new(g_io_channel_unix_get_fd(ch1)); 37 37 38 39 40 38 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n" 39 "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL); 40 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL); 41 41 42 43 42 g_main_iteration(FALSE); 43 irc_free(irc); 44 44 45 fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); 46 47 fail_unless(strstr(raw, "001") != NULL); 48 fail_unless(strstr(raw, "002") != NULL); 49 fail_unless(strstr(raw, "003") != NULL); 50 fail_unless(strstr(raw, "004") != NULL); 51 fail_unless(strstr(raw, "005") != NULL); 45 fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL); 52 46 53 g_free(raw); 47 fail_unless(strstr(raw, "001") != NULL); 48 fail_unless(strstr(raw, "002") != NULL); 49 fail_unless(strstr(raw, "003") != NULL); 50 fail_unless(strstr(raw, "004") != NULL); 51 fail_unless(strstr(raw, "005") != NULL); 52 53 g_free(raw); 54 54 END_TEST 55 55 56 Suite *irc_suite 56 Suite *irc_suite(void) 57 57 { 58 58 Suite *s = suite_create("IRC"); 59 59 TCase *tc_core = tcase_create("Core"); 60 suite_add_tcase (s, tc_core); 61 tcase_add_test (tc_core, test_connect); 62 tcase_add_test (tc_core, test_login); 60 61 suite_add_tcase(s, tc_core); 62 tcase_add_test(tc_core, test_connect); 63 tcase_add_test(tc_core, test_login); 63 64 return s; 64 65 } -
tests/check_jabber_sasl.c
raf359b4 r5ebff60 6 6 #include <stdio.h> 7 7 8 char *sasl_get_part( char *data, char *field);8 char *sasl_get_part(char *data, char *field); 9 9 10 10 #define challenge1 "nonce=\"1669585310\",qop=\"auth\",charset=utf-8,algorithm=md5-sess," \ 11 11 "something=\"Not \\\"standardized\\\"\"" 12 12 #define challenge2 "realm=\"quadpoint.org\", nonce=\"NPotlQpQf9RNYodOwierkQ==\", " \ 13 13 "qop=\"auth, auth-int\", charset=utf-8, algorithm=md5-sess" 14 14 #define challenge3 ", realm=\"localhost\", nonce=\"LlBV2txnO8RbB5hgs3KgiQ==\", " \ 15 15 "qop=\"auth, auth-int, \", ,\n, charset=utf-8, algorithm=md5-sess," 16 16 17 struct 18 { 17 struct { 19 18 char *challenge; 20 19 char *key; … … 82 81 { 83 82 int i; 84 85 for( i = 0; get_part_tests[i].key; i++ ) 86 { 87 tcase_fn_start( get_part_tests[i].key, __FILE__, i ); 83 84 for (i = 0; get_part_tests[i].key; i++) { 85 tcase_fn_start(get_part_tests[i].key, __FILE__, i); 88 86 char *res; 89 90 res = sasl_get_part( get_part_tests[i].challenge, 91 get_part_tests[i].key ); 92 93 if( get_part_tests[i].value == NULL ) 94 fail_if( res != NULL, "Found key %s in %s while it shouldn't be there!", 95 get_part_tests[i].key, get_part_tests[i].challenge ); 96 else if( res ) 97 fail_unless( strcmp( res, get_part_tests[i].value ) == 0, 98 "Incorrect value for key %s in %s: %s", 99 get_part_tests[i].key, get_part_tests[i].challenge, res ); 100 else 101 fail( "Could not find key %s in %s", 102 get_part_tests[i].key, get_part_tests[i].challenge ); 103 104 g_free( res ); 87 88 res = sasl_get_part(get_part_tests[i].challenge, 89 get_part_tests[i].key); 90 91 if (get_part_tests[i].value == NULL) { 92 fail_if(res != NULL, "Found key %s in %s while it shouldn't be there!", 93 get_part_tests[i].key, get_part_tests[i].challenge); 94 } else if (res) { 95 fail_unless(strcmp(res, get_part_tests[i].value) == 0, 96 "Incorrect value for key %s in %s: %s", 97 get_part_tests[i].key, get_part_tests[i].challenge, res); 98 } else { 99 fail("Could not find key %s in %s", 100 get_part_tests[i].key, get_part_tests[i].challenge); 101 } 102 103 g_free(res); 105 104 } 106 105 } 107 106 108 Suite *jabber_sasl_suite 107 Suite *jabber_sasl_suite(void) 109 108 { 110 109 Suite *s = suite_create("jabber/sasl"); 111 110 TCase *tc_core = tcase_create("Core"); 112 suite_add_tcase (s, tc_core); 113 tcase_add_test (tc_core, check_get_part); 111 112 suite_add_tcase(s, tc_core); 113 tcase_add_test(tc_core, check_get_part); 114 114 return s; 115 115 } -
tests/check_jabber_util.c
raf359b4 r5ebff60 12 12 { 13 13 struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud; 14 15 budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee");16 budw1->last_msg = time( NULL) - 100;17 budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy");14 15 budw1 = jabber_buddy_add(ic, "wilmer@gaast.net/BitlBee"); 16 budw1->last_msg = time(NULL) - 100; 17 budw2 = jabber_buddy_add(ic, "WILMER@gaast.net/Telepathy"); 18 18 budw2->priority = 2; 19 budw2->last_msg = time( NULL);20 budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee");21 budw3->last_msg = time( NULL) - 200;19 budw2->last_msg = time(NULL); 20 budw3 = jabber_buddy_add(ic, "wilmer@GAAST.NET/bitlbee"); 21 budw3->last_msg = time(NULL) - 200; 22 22 budw3->priority = 4; 23 23 /* TODO(wilmer): Shouldn't this just return budw3? */ 24 fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ) != NULL);25 26 budn = jabber_buddy_add( ic, "nekkid@lamejab.net");24 fail_if(jabber_buddy_add(ic, "wilmer@gaast.net/Telepathy") != NULL); 25 26 budn = jabber_buddy_add(ic, "nekkid@lamejab.net"); 27 27 /* Shouldn't be allowed if there's already a bare JID. */ 28 fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ));29 28 fail_if(jabber_buddy_add(ic, "nekkid@lamejab.net/Illegal")); 29 30 30 /* Case sensitivity: Case only matters after the / */ 31 fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == 32 jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", 0 ) ); 33 fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/telepathy", 0 ) ); 34 35 fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 ); 36 fail_unless( jabber_buddy_by_jid( ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT ) == budw1 ); 37 fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT ) == budw1 ); 31 fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net/BitlBee", 0) == 32 jabber_buddy_by_jid(ic, "wilmer@gaast.net/bitlbee", 0)); 33 fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net/telepathy", 0)); 38 34 39 fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) ); 40 fail_unless( jabber_buddy_by_jid( ic, "WILMER@gaast.net", 0 ) == budw3 ); 35 fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net/BitlBee", 0) == budw1); 36 fail_unless(jabber_buddy_by_jid(ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT) == budw1); 37 fail_unless(jabber_buddy_by_jid(ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT) == budw1); 38 39 fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_EXACT)); 40 fail_unless(jabber_buddy_by_jid(ic, "WILMER@gaast.net", 0) == budw3); 41 41 42 42 /* Check O_FIRST and see if it's indeed the first item from the list. */ 43 fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) ) == budw1);44 fail_unless( bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL);45 43 fail_unless((bud = jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_FIRST)) == budw1); 44 fail_unless(bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL); 45 46 46 /* Change the resource_select setting, now we should get a different resource. */ 47 set_setstr( &ic->acc->set, "resource_select", "activity");48 fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET", 0 ) == budw2);49 47 set_setstr(&ic->acc->set, "resource_select", "activity"); 48 fail_unless(jabber_buddy_by_jid(ic, "wilmer@GAAST.NET", 0) == budw2); 49 50 50 /* Some testing of bare JID handling (which is horrible). */ 51 fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ));52 fail_if( jabber_buddy_by_jid( ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT ));53 fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn);54 fail_unless( jabber_buddy_by_jid( ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT ) == budn);55 fail_unless( jabber_buddy_by_jid( ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT ) == budn);56 51 fail_if(jabber_buddy_by_jid(ic, "nekkid@lamejab.net/Illegal", 0)); 52 fail_if(jabber_buddy_by_jid(ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT)); 53 fail_unless(jabber_buddy_by_jid(ic, "nekkid@lamejab.net", 0) == budn); 54 fail_unless(jabber_buddy_by_jid(ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT) == budn); 55 fail_unless(jabber_buddy_by_jid(ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT) == budn); 56 57 57 /* More case sensitivity testing, and see if remove works properly. */ 58 fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ));59 fail_if( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT ) == budw2);60 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/Telepathy" ));61 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ));62 58 fail_if(jabber_buddy_remove(ic, "wilmer@gaast.net/telepathy")); 59 fail_if(jabber_buddy_by_jid(ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT) == budw2); 60 fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/Telepathy")); 61 fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/telepathy")); 62 63 63 /* Test activity_timeout and GET_BUDDY_BARE_OK. */ 64 fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK ) == budw1);64 fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK) == budw1); 65 65 budw1->last_msg -= 50; 66 fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK ) ) != NULL);67 fail_unless( strcmp( bud->full_jid, "wilmer@gaast.net" ) == 0);68 69 fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ));70 fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1);71 72 fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ));73 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/bitlbee" ));74 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/BitlBee" ));75 fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK ));76 66 fail_unless((bud = jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK)) != NULL); 67 fail_unless(strcmp(bud->full_jid, "wilmer@gaast.net") == 0); 68 69 fail_if(jabber_buddy_remove(ic, "wilmer@gaast.net")); 70 fail_unless(jabber_buddy_by_jid(ic, "wilmer@gaast.net", 0) == budw1); 71 72 fail_if(jabber_buddy_remove(ic, "wilmer@gaast.net")); 73 fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/bitlbee")); 74 fail_unless(jabber_buddy_remove(ic, "wilmer@gaast.net/BitlBee")); 75 fail_if(jabber_buddy_by_jid(ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK)); 76 77 77 /* Check if remove_bare() indeed gets rid of all. */ 78 78 /* disable this one for now. … … 81 81 */ 82 82 83 fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ));84 fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ));85 fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ));86 83 fail_if(jabber_buddy_remove(ic, "nekkid@lamejab.net/Illegal")); 84 fail_unless(jabber_buddy_remove(ic, "nekkid@lamejab.net")); 85 fail_if(jabber_buddy_by_jid(ic, "nekkid@lamejab.net", 0)); 86 87 87 /* Fixing a bug in this branch that caused information to get lost when 88 88 removing the first full JID from a list. */ 89 jabber_buddy_add( ic, "bugtest@google.com/A");90 jabber_buddy_add( ic, "bugtest@google.com/B");91 jabber_buddy_add( ic, "bugtest@google.com/C");92 fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/A" ));93 fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/B" ));94 fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/C" ));89 jabber_buddy_add(ic, "bugtest@google.com/A"); 90 jabber_buddy_add(ic, "bugtest@google.com/B"); 91 jabber_buddy_add(ic, "bugtest@google.com/C"); 92 fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/A")); 93 fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/B")); 94 fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/C")); 95 95 } 96 96 97 97 static void check_compareJID(int l) 98 98 { 99 fail_unless( jabber_compare_jid( "bugtest@google.com/B", "bugtest@google.com/A" ));100 fail_if( jabber_compare_jid( "bugtest1@google.com/B", "bugtest@google.com/A" ));101 fail_if( jabber_compare_jid( "bugtest@google.com/B", "bugtest1@google.com/A" ));102 fail_if( jabber_compare_jid( "bugtest1@google.com/B", "bugtest2@google.com/A" ));103 fail_unless( jabber_compare_jid( "bugtest@google.com/A", "bugtest@google.com/A" ));104 fail_if( jabber_compare_jid( "", "bugtest@google.com/A" ));99 fail_unless(jabber_compare_jid("bugtest@google.com/B", "bugtest@google.com/A")); 100 fail_if(jabber_compare_jid("bugtest1@google.com/B", "bugtest@google.com/A")); 101 fail_if(jabber_compare_jid("bugtest@google.com/B", "bugtest1@google.com/A")); 102 fail_if(jabber_compare_jid("bugtest1@google.com/B", "bugtest2@google.com/A")); 103 fail_unless(jabber_compare_jid("bugtest@google.com/A", "bugtest@google.com/A")); 104 fail_if(jabber_compare_jid("", "bugtest@google.com/A")); 105 105 } 106 106 107 Suite *jabber_util_suite 107 Suite *jabber_util_suite(void) 108 108 { 109 109 Suite *s = suite_create("jabber/util"); 110 110 TCase *tc_core = tcase_create("Buddy"); 111 111 struct jabber_data *jd; 112 113 ic = g_new0( struct im_connection, 1);114 ic->acc = g_new0( account_t, 1);115 ic->proto_data = jd = g_new0( struct jabber_data, 1);116 jd->buddies = g_hash_table_new( g_str_hash, g_str_equal);117 set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc);118 set_add( &ic->acc->set, "activity_timeout", "120", NULL, ic->acc);119 120 suite_add_tcase 121 tcase_add_test 122 tcase_add_test 112 113 ic = g_new0(struct im_connection, 1); 114 ic->acc = g_new0(account_t, 1); 115 ic->proto_data = jd = g_new0(struct jabber_data, 1); 116 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); 117 set_add(&ic->acc->set, "resource_select", "priority", NULL, ic->acc); 118 set_add(&ic->acc->set, "activity_timeout", "120", NULL, ic->acc); 119 120 suite_add_tcase(s, tc_core); 121 tcase_add_test(tc_core, check_buddy_add); 122 tcase_add_test(tc_core, check_compareJID); 123 123 return s; 124 124 } -
tests/check_md5.c
raf359b4 r5ebff60 12 12 md5_byte_t expected[16]; 13 13 } tests[] = { 14 { "", 15 14 { "", 15 { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } }, 16 16 { "a", 17 18 { "abc", 19 20 { "message digest", 21 22 { "abcdefghijklmnopqrstuvwxyz", 23 17 { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } }, 18 { "abc", 19 { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } }, 20 { "message digest", 21 { 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 } }, 22 { "abcdefghijklmnopqrstuvwxyz", 23 { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b } }, 24 24 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 25 26 { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 27 25 { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f } }, 26 { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 27 { 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a } }, 28 28 29 29 { NULL }, … … 33 33 { 34 34 int i; 35 35 36 for (i = 0; tests[i].str; i++) { 36 37 md5_byte_t sum[16]; 37 tcase_fn_start(tests[i].str, __FILE__, __LINE__);38 tcase_fn_start(tests[i].str, __FILE__, __LINE__); 38 39 md5_state_t state; 39 40 40 41 md5_init(&state); 41 md5_append(&state, (const md5_byte_t *) tests[i].str, strlen(tests[i].str));42 md5_append(&state, (const md5_byte_t *) tests[i].str, strlen(tests[i].str)); 42 43 md5_finish(&state, sum); 43 44 … … 46 47 } 47 48 48 Suite *md5_suite 49 Suite *md5_suite(void) 49 50 { 50 51 Suite *s = suite_create("MD5"); 51 52 TCase *tc_core = tcase_create("Core"); 52 suite_add_tcase (s, tc_core); 53 tcase_add_test (tc_core, check_sums); 53 54 suite_add_tcase(s, tc_core); 55 tcase_add_test(tc_core, check_sums); 54 56 return s; 55 57 } -
tests/check_nick.c
raf359b4 r5ebff60 9 9 #include "bitlbee.h" 10 10 11 START_TEST(test_nick_strip) 12 { 11 START_TEST(test_nick_strip){ 13 12 int i; 14 const char *get[] = { "test:", "test", "test\n", 15 "thisisaveryveryveryverylongnick",16 "thisisave:ryveryveryverylongnick",17 "t::::est",18 "test123",19 "123test",20 "123",21 NULL };22 const char *expected[] = { "test", "test", "test", 23 "thisisaveryveryveryveryl",24 "thisisaveryveryveryveryl",25 "test",26 "test123",27 "_123test",28 "_123",29 NULL };13 const char *get[] = { "test:", "test", "test\n", 14 "thisisaveryveryveryverylongnick", 15 "thisisave:ryveryveryverylongnick", 16 "t::::est", 17 "test123", 18 "123test", 19 "123", 20 NULL }; 21 const char *expected[] = { "test", "test", "test", 22 "thisisaveryveryveryveryl", 23 "thisisaveryveryveryveryl", 24 "test", 25 "test123", 26 "_123test", 27 "_123", 28 NULL }; 30 29 31 30 for (i = 0; get[i]; i++) { … … 33 32 strcpy(copy, get[i]); 34 33 nick_strip(NULL, copy); 35 fail_unless (strcmp(copy, expected[i]) == 0,36 "(%d) nick_strip broken: %s -> %s (expected: %s)",37 34 fail_unless(strcmp(copy, expected[i]) == 0, 35 "(%d) nick_strip broken: %s -> %s (expected: %s)", 36 i, get[i], copy, expected[i]); 38 37 } 39 38 } … … 43 42 { 44 43 const char *nicks[] = { "foo", "bar123", "bla[", "blie]", "BreEZaH", 45 44 "\\od^~", "_123", "_123test", NULL }; 46 45 int i; 47 46 48 47 for (i = 0; nicks[i]; i++) { 49 fail_unless 50 48 fail_unless(nick_ok(NULL, nicks[i]) == 1, 49 "nick_ok() failed: %s", nicks[i]); 51 50 } 52 51 } … … 56 55 { 57 56 const char *nicks[] = { "thisisaveryveryveryveryveryveryverylongnick", 58 57 "\nillegalchar", "", "nick%", "123test", NULL }; 59 58 int i; 60 59 61 60 for (i = 0; nicks[i]; i++) { 62 fail_unless 63 61 fail_unless(nick_ok(NULL, nicks[i]) == 0, 62 "nick_ok() succeeded for invalid: %s", nicks[i]); 64 63 } 65 64 } 66 65 END_TEST 67 66 68 Suite *nick_suite 67 Suite *nick_suite(void) 69 68 { 70 69 Suite *s = suite_create("Nick"); 71 70 TCase *tc_core = tcase_create("Core"); 72 suite_add_tcase (s, tc_core); 73 tcase_add_test (tc_core, test_nick_ok_ok); 74 tcase_add_test (tc_core, test_nick_ok_notok); 75 tcase_add_test (tc_core, test_nick_strip); 71 72 suite_add_tcase(s, tc_core); 73 tcase_add_test(tc_core, test_nick_ok_ok); 74 tcase_add_test(tc_core, test_nick_ok_notok); 75 tcase_add_test(tc_core, test_nick_strip); 76 76 return s; 77 77 } -
tests/check_set.c
raf359b4 r5ebff60 8 8 9 9 START_TEST(test_set_add) 10 11 12 13 14 15 10 void *data = "data"; 11 set_t *s = NULL, *t; 12 t = set_add(&s, "name", "default", NULL, data); 13 fail_unless(s == t); 14 fail_unless(t->data == data); 15 fail_unless(strcmp(t->def, "default") == 0); 16 16 END_TEST 17 17 18 18 START_TEST(test_set_add_existing) 19 20 21 22 23 24 19 void *data = "data"; 20 set_t *s = NULL, *t; 21 t = set_add(&s, "name", "default", NULL, data); 22 t = set_add(&s, "name", "newdefault", NULL, data); 23 fail_unless(s == t); 24 fail_unless(strcmp(t->def, "newdefault") == 0); 25 25 END_TEST 26 26 27 27 START_TEST(test_set_find_unknown) 28 set_t *s = NULL;29 fail_unless(set_find(&s, "foo") == NULL);28 set_t * s = NULL; 29 fail_unless(set_find(&s, "foo") == NULL); 30 30 END_TEST 31 31 32 32 START_TEST(test_set_find) 33 34 35 36 37 33 void *data = "data"; 34 set_t *s = NULL, *t; 35 t = set_add(&s, "name", "default", NULL, data); 36 fail_unless(s == t); 37 fail_unless(set_find(&s, "name") == t); 38 38 END_TEST 39 39 40 40 START_TEST(test_set_get_str_default) 41 42 43 44 45 41 void *data = "data"; 42 set_t *s = NULL, *t; 43 t = set_add(&s, "name", "default", NULL, data); 44 fail_unless(s == t); 45 fail_unless(strcmp(set_getstr(&s, "name"), "default") == 0); 46 46 END_TEST 47 47 48 48 START_TEST(test_set_get_bool_default) 49 50 51 52 53 49 void *data = "data"; 50 set_t *s = NULL, *t; 51 t = set_add(&s, "name", "true", NULL, data); 52 fail_unless(s == t); 53 fail_unless(set_getbool(&s, "name")); 54 54 END_TEST 55 55 56 56 START_TEST(test_set_get_bool_integer) 57 58 59 60 61 57 void *data = "data"; 58 set_t *s = NULL, *t; 59 t = set_add(&s, "name", "3", NULL, data); 60 fail_unless(s == t); 61 fail_unless(set_getbool(&s, "name") == 3); 62 62 END_TEST 63 63 64 64 START_TEST(test_set_get_bool_unknown) 65 set_t *s = NULL;66 65 set_t * s = NULL; 66 fail_unless(set_getbool(&s, "name") == 0); 67 67 END_TEST 68 68 69 69 START_TEST(test_set_get_str_value) 70 71 72 73 74 70 void *data = "data"; 71 set_t *s = NULL; 72 set_add(&s, "name", "default", NULL, data); 73 set_setstr(&s, "name", "foo"); 74 fail_unless(strcmp(set_getstr(&s, "name"), "foo") == 0); 75 75 END_TEST 76 76 77 77 START_TEST(test_set_get_str_unknown) 78 set_t *s = NULL;79 78 set_t * s = NULL; 79 fail_unless(set_getstr(&s, "name") == NULL); 80 80 END_TEST 81 81 82 82 START_TEST(test_setint) 83 84 85 86 87 83 void *data = "data"; 84 set_t *s = NULL; 85 set_add(&s, "name", "10", NULL, data); 86 set_setint(&s, "name", 3); 87 fail_unless(set_getint(&s, "name") == 3); 88 88 END_TEST 89 89 90 90 START_TEST(test_setstr) 91 92 93 94 95 91 void *data = "data"; 92 set_t *s = NULL; 93 set_add(&s, "name", "foo", NULL, data); 94 set_setstr(&s, "name", "bloe"); 95 fail_unless(strcmp(set_getstr(&s, "name"), "bloe") == 0); 96 96 END_TEST 97 97 98 98 START_TEST(test_set_get_int_unknown) 99 set_t *s = NULL;100 99 set_t * s = NULL; 100 fail_unless(set_getint(&s, "foo") == 0); 101 101 END_TEST 102 102 103 Suite *set_suite 103 Suite *set_suite(void) 104 104 { 105 105 Suite *s = suite_create("Set"); 106 106 TCase *tc_core = tcase_create("Core"); 107 suite_add_tcase (s, tc_core); 108 tcase_add_test (tc_core, test_set_add); 109 tcase_add_test (tc_core, test_set_add_existing); 110 tcase_add_test (tc_core, test_set_find_unknown); 111 tcase_add_test (tc_core, test_set_find); 112 tcase_add_test (tc_core, test_set_get_str_default); 113 tcase_add_test (tc_core, test_set_get_str_value); 114 tcase_add_test (tc_core, test_set_get_str_unknown); 115 tcase_add_test (tc_core, test_set_get_bool_default); 116 tcase_add_test (tc_core, test_set_get_bool_integer); 117 tcase_add_test (tc_core, test_set_get_bool_unknown); 118 tcase_add_test (tc_core, test_set_get_int_unknown); 119 tcase_add_test (tc_core, test_setint); 120 tcase_add_test (tc_core, test_setstr); 107 108 suite_add_tcase(s, tc_core); 109 tcase_add_test(tc_core, test_set_add); 110 tcase_add_test(tc_core, test_set_add_existing); 111 tcase_add_test(tc_core, test_set_find_unknown); 112 tcase_add_test(tc_core, test_set_find); 113 tcase_add_test(tc_core, test_set_get_str_default); 114 tcase_add_test(tc_core, test_set_get_str_value); 115 tcase_add_test(tc_core, test_set_get_str_unknown); 116 tcase_add_test(tc_core, test_set_get_bool_default); 117 tcase_add_test(tc_core, test_set_get_bool_integer); 118 tcase_add_test(tc_core, test_set_get_bool_unknown); 119 tcase_add_test(tc_core, test_set_get_int_unknown); 120 tcase_add_test(tc_core, test_setint); 121 tcase_add_test(tc_core, test_setstr); 121 122 return s; 122 123 } -
tests/check_user.c
raf359b4 r5ebff60 9 9 #if 0 10 10 START_TEST(test_user_add) 11 irc_t *irc = torture_irc();12 13 14 15 16 11 irc_t * irc = torture_irc(); 12 user_t *user; 13 user = user_add(irc, "foo"); 14 fail_if(user == NULL); 15 fail_if(strcmp(user->nick, "foo") != 0); 16 fail_unless(user_find(irc, "foo") == user); 17 17 END_TEST 18 18 19 19 START_TEST(test_user_add_exists) 20 irc_t *irc = torture_irc();21 22 23 24 25 20 irc_t * irc = torture_irc(); 21 user_t *user; 22 user = user_add(irc, "foo"); 23 fail_if(user == NULL); 24 user = user_add(irc, "foo"); 25 fail_unless(user == NULL); 26 26 END_TEST 27 27 28 28 START_TEST(test_user_add_invalid) 29 irc_t *irc = torture_irc();30 31 32 29 irc_t * irc = torture_irc(); 30 user_t *user; 31 user = user_add(irc, ":foo"); 32 fail_unless(user == NULL); 33 33 END_TEST 34 34 35 35 START_TEST(test_user_del_invalid) 36 irc_t *irc = torture_irc();37 36 irc_t * irc = torture_irc(); 37 fail_unless(user_del(irc, ":foo") == 0); 38 38 END_TEST 39 39 40 40 START_TEST(test_user_del) 41 irc_t *irc = torture_irc();42 43 44 45 41 irc_t * irc = torture_irc(); 42 user_t *user; 43 user = user_add(irc, "foo"); 44 fail_unless(user_del(irc, "foo") == 1); 45 fail_unless(user_find(irc, "foo") == NULL); 46 46 END_TEST 47 47 48 48 START_TEST(test_user_del_nonexistant) 49 irc_t *irc = torture_irc();50 49 irc_t * irc = torture_irc(); 50 fail_unless(user_del(irc, "foo") == 0); 51 51 END_TEST 52 52 53 53 START_TEST(test_user_rename) 54 irc_t *irc = torture_irc();55 56 57 58 59 54 irc_t * irc = torture_irc(); 55 user_t *user; 56 user = user_add(irc, "foo"); 57 user_rename(irc, "foo", "bar"); 58 fail_unless(user_find(irc, "foo") == NULL); 59 fail_if(user_find(irc, "bar") == NULL); 60 60 END_TEST 61 61 #endif 62 Suite *user_suite 62 Suite *user_suite(void) 63 63 { 64 64 Suite *s = suite_create("User"); 65 65 TCase *tc_core = tcase_create("Core"); 66 suite_add_tcase (s, tc_core); 66 67 suite_add_tcase(s, tc_core); 67 68 #if 0 68 tcase_add_test 69 tcase_add_test 70 tcase_add_test 71 tcase_add_test 72 tcase_add_test 73 tcase_add_test 74 tcase_add_test 69 tcase_add_test(tc_core, test_user_add); 70 tcase_add_test(tc_core, test_user_add_invalid); 71 tcase_add_test(tc_core, test_user_add_exists); 72 tcase_add_test(tc_core, test_user_del_invalid); 73 tcase_add_test(tc_core, test_user_del_nonexistant); 74 tcase_add_test(tc_core, test_user_del); 75 tcase_add_test(tc_core, test_user_rename); 75 76 #endif 76 77 return s; -
tests/check_util.c
raf359b4 r5ebff60 9 9 #include "url.h" 10 10 11 START_TEST(test_strip_linefeed) 12 { 11 START_TEST(test_strip_linefeed){ 13 12 int i; 14 13 const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL }; … … 19 18 strcpy(copy, get[i]); 20 19 strip_linefeed(copy); 21 fail_unless (strcmp(copy, expected[i]) == 0,22 "(%d) strip_linefeed broken: %s -> %s (expected: %s)",23 20 fail_unless(strcmp(copy, expected[i]) == 0, 21 "(%d) strip_linefeed broken: %s -> %s (expected: %s)", 22 i, get[i], copy, expected[i]); 24 23 } 25 24 } … … 36 35 strcpy(copy, get[i]); 37 36 ret = strip_newlines(copy); 38 fail_unless (strcmp(copy, expected[i]) == 0,39 "(%d) strip_newlines broken: %s -> %s (expected: %s)",40 41 fail_unless (copy == ret, "Original string not returned");37 fail_unless(strcmp(copy, expected[i]) == 0, 38 "(%d) strip_newlines broken: %s -> %s (expected: %s)", 39 i, get[i], copy, expected[i]); 40 fail_unless(copy == ret, "Original string not returned"); 42 41 } 43 42 } … … 45 44 46 45 START_TEST(test_set_url_http) 47 48 49 fail_if(0 == url_set(&url, "http://host/"));50 fail_unless(!strcmp(url.host, "host"));51 fail_unless(!strcmp(url.file, "/"));52 fail_unless(!strcmp(url.user, ""));53 fail_unless(!strcmp(url.pass, ""));54 fail_unless(url.proto == PROTO_HTTP);55 fail_unless(url.port == 80);46 url_t url; 47 48 fail_if(0 == url_set(&url, "http://host/")); 49 fail_unless(!strcmp(url.host, "host")); 50 fail_unless(!strcmp(url.file, "/")); 51 fail_unless(!strcmp(url.user, "")); 52 fail_unless(!strcmp(url.pass, "")); 53 fail_unless(url.proto == PROTO_HTTP); 54 fail_unless(url.port == 80); 56 55 END_TEST 57 56 58 57 START_TEST(test_set_url_https) 59 60 61 fail_if(0 == url_set(&url, "https://ahost/AimeeMann"));62 fail_unless(!strcmp(url.host, "ahost"));63 fail_unless(!strcmp(url.file, "/AimeeMann"));64 fail_unless(!strcmp(url.user, ""));65 fail_unless(!strcmp(url.pass, ""));66 fail_unless(url.proto == PROTO_HTTPS);67 fail_unless(url.port == 443);58 url_t url; 59 60 fail_if(0 == url_set(&url, "https://ahost/AimeeMann")); 61 fail_unless(!strcmp(url.host, "ahost")); 62 fail_unless(!strcmp(url.file, "/AimeeMann")); 63 fail_unless(!strcmp(url.user, "")); 64 fail_unless(!strcmp(url.pass, "")); 65 fail_unless(url.proto == PROTO_HTTPS); 66 fail_unless(url.port == 443); 68 67 END_TEST 69 68 70 69 START_TEST(test_set_url_port) 71 72 73 fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space"));74 fail_unless(!strcmp(url.host, "ahost"));75 fail_unless(!strcmp(url.file, "/Lost/In/Space"));76 fail_unless(!strcmp(url.user, ""));77 fail_unless(!strcmp(url.pass, ""));78 fail_unless(url.proto == PROTO_HTTPS);79 fail_unless(url.port == 200);70 url_t url; 71 72 fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space")); 73 fail_unless(!strcmp(url.host, "ahost")); 74 fail_unless(!strcmp(url.file, "/Lost/In/Space")); 75 fail_unless(!strcmp(url.user, "")); 76 fail_unless(!strcmp(url.pass, "")); 77 fail_unless(url.proto == PROTO_HTTPS); 78 fail_unless(url.port == 200); 80 79 END_TEST 81 80 82 81 START_TEST(test_set_url_username) 83 84 85 fail_if(0 == url_set(&url, "socks4://user@ahost/Space"));86 fail_unless(!strcmp(url.host, "ahost"));87 fail_unless(!strcmp(url.file, "/Space"));88 fail_unless(!strcmp(url.user, "user"));89 fail_unless(!strcmp(url.pass, ""));90 fail_unless(url.proto == PROTO_SOCKS4);91 fail_unless(url.port == 1080);82 url_t url; 83 84 fail_if(0 == url_set(&url, "socks4://user@ahost/Space")); 85 fail_unless(!strcmp(url.host, "ahost")); 86 fail_unless(!strcmp(url.file, "/Space")); 87 fail_unless(!strcmp(url.user, "user")); 88 fail_unless(!strcmp(url.pass, "")); 89 fail_unless(url.proto == PROTO_SOCKS4); 90 fail_unless(url.port == 1080); 92 91 END_TEST 93 92 94 93 START_TEST(test_set_url_username_pwd) 95 url_t url; 96 97 fail_if (0 == url_set(&url, "socks5://user:pass@ahost/")); 98 fail_unless (!strcmp(url.host, "ahost")); 99 fail_unless (!strcmp(url.file, "/")); 100 fail_unless (!strcmp(url.user, "user")); 101 fail_unless (!strcmp(url.pass, "pass")); 102 fail_unless (url.proto == PROTO_SOCKS5); 103 fail_unless (url.port == 1080); 104 END_TEST 105 106 struct 107 { 94 url_t url; 95 96 fail_if(0 == url_set(&url, "socks5://user:pass@ahost/")); 97 fail_unless(!strcmp(url.host, "ahost")); 98 fail_unless(!strcmp(url.file, "/")); 99 fail_unless(!strcmp(url.user, "user")); 100 fail_unless(!strcmp(url.pass, "pass")); 101 fail_unless(url.proto == PROTO_SOCKS5); 102 fail_unless(url.port == 1080); 103 END_TEST 104 105 struct { 108 106 char *orig; 109 107 int line_len; … … 146 144 147 145 START_TEST(test_word_wrap) 148 int i; 149 150 for( i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i ++ ) 151 { 152 char *wrapped = word_wrap( word_wrap_tests[i].orig, word_wrap_tests[i].line_len ); 153 154 fail_unless( strcmp( word_wrap_tests[i].wrapped, wrapped ) == 0, 155 "%s (line_len = %d) should wrap to `%s', not to `%s'", 156 word_wrap_tests[i].orig, word_wrap_tests[i].line_len, 157 word_wrap_tests[i].wrapped, wrapped ); 158 159 g_free( wrapped ); 160 } 146 int i; 147 148 for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) { 149 char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len); 150 151 fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0, 152 "%s (line_len = %d) should wrap to `%s', not to `%s'", 153 word_wrap_tests[i].orig, word_wrap_tests[i].line_len, 154 word_wrap_tests[i].wrapped, wrapped); 155 156 g_free(wrapped); 157 } 161 158 END_TEST 162 159 163 160 START_TEST(test_http_encode) 164 165 166 strcpy( s, "ee\xc3""\xab""ee!!...");167 http_encode( s);168 fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0);161 char s[80]; 162 163 strcpy(s, "ee\xc3" "\xab" "ee!!..."); 164 http_encode(s); 165 fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0); 169 166 END_TEST 170 167 … … 172 169 int limit; 173 170 char *command; 174 char *expected[IRC_MAX_ARGS +1];171 char *expected[IRC_MAX_ARGS + 1]; 175 172 } split_tests[] = { 176 173 { 177 174 0, "account add etc \"user name with spaces\" 'pass\\ word'", 178 { "account", "add", "etc", "user name with spaces", "pass\\ word", NULL},175 { "account", "add", "etc", "user name with spaces", "pass\\ word", NULL }, 179 176 }, 180 177 { 181 178 0, "channel set group Close\\ friends", 182 { "channel", "set", "group", "Close friends", NULL},179 { "channel", "set", "group", "Close friends", NULL }, 183 180 }, 184 181 { 185 182 2, "reply wilmer \"testing in C is a PITA\", you said.", 186 { "reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL},183 { "reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL }, 187 184 }, 188 185 { 189 186 4, "one space two spaces limit limit", 190 { "one", "space", "two", "spaces", "limit limit", NULL},187 { "one", "space", "two", "spaces", "limit limit", NULL }, 191 188 }, 192 189 { 193 190 0, NULL, 194 { NULL}191 { NULL } 195 192 }, 196 193 }; 197 194 198 195 START_TEST(test_split_command_parts) 199 200 201 202 203 204 205 206 207 fail_unless(strcmp(split[j], expected[j]) == 0,208 209 210 211 212 213 END_TEST 214 215 Suite *util_suite 196 int i; 197 for (i = 0; split_tests[i].command; i++) { 198 char *cmd = g_strdup(split_tests[i].command); 199 char **split = split_command_parts(cmd, split_tests[i].limit); 200 char **expected = split_tests[i].expected; 201 202 int j; 203 for (j = 0; split[j] && expected[j]; j++) { 204 fail_unless(strcmp(split[j], expected[j]) == 0, 205 "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)", 206 i, split_tests[i].command, j, split[j], expected[j]); 207 } 208 g_free(cmd); 209 } 210 END_TEST 211 212 Suite *util_suite(void) 216 213 { 217 214 Suite *s = suite_create("Util"); 218 215 TCase *tc_core = tcase_create("Core"); 219 suite_add_tcase (s, tc_core); 220 tcase_add_test (tc_core, test_strip_linefeed); 221 tcase_add_test (tc_core, test_strip_newlines); 222 tcase_add_test (tc_core, test_set_url_http); 223 tcase_add_test (tc_core, test_set_url_https); 224 tcase_add_test (tc_core, test_set_url_port); 225 tcase_add_test (tc_core, test_set_url_username); 226 tcase_add_test (tc_core, test_set_url_username_pwd); 227 tcase_add_test (tc_core, test_word_wrap); 228 tcase_add_test (tc_core, test_http_encode); 229 tcase_add_test (tc_core, test_split_command_parts); 216 217 suite_add_tcase(s, tc_core); 218 tcase_add_test(tc_core, test_strip_linefeed); 219 tcase_add_test(tc_core, test_strip_newlines); 220 tcase_add_test(tc_core, test_set_url_http); 221 tcase_add_test(tc_core, test_set_url_https); 222 tcase_add_test(tc_core, test_set_url_port); 223 tcase_add_test(tc_core, test_set_url_username); 224 tcase_add_test(tc_core, test_set_url_username_pwd); 225 tcase_add_test(tc_core, test_word_wrap); 226 tcase_add_test(tc_core, test_http_encode); 227 tcase_add_test(tc_core, test_split_command_parts); 230 228 return s; 231 229 } -
tests/testsuite.h
raf359b4 r5ebff60 1 1 #ifndef __BITLBEE_CHECK_H__ 2 #define __BITLBEE_CHECK_H__ 2 #define __BITLBEE_CHECK_H__ 3 3 4 4 #include "irc.h"
Note: See TracChangeset
for help on using the changeset viewer.