diff options
Diffstat (limited to 'connect/test')
-rw-r--r-- | connect/test/test_ncbi_connutil_misc.c | 139 | ||||
-rw-r--r-- | connect/test/test_ncbi_core.c | 44 | ||||
-rw-r--r-- | connect/test/test_ncbi_http_get.c | 72 | ||||
-rw-r--r-- | connect/test/test_ncbi_socket.c | 112 |
4 files changed, 122 insertions, 245 deletions
diff --git a/connect/test/test_ncbi_connutil_misc.c b/connect/test/test_ncbi_connutil_misc.c index 0269fe32..e0a1c4a4 100644 --- a/connect/test/test_ncbi_connutil_misc.c +++ b/connect/test/test_ncbi_connutil_misc.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_connutil_misc.c,v 6.25 2006/06/15 03:02:52 lavr Exp $ +/* $Id: test_ncbi_connutil_misc.c,v 6.26 2007/12/05 19:26:19 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -147,60 +147,6 @@ static void TEST_URL_Encoding(void) /*********************************************************************** - * TEST: BASE64_Encode(), BAS64_Decode() - */ - -static void TEST_BASE64_Encoding(void) -{ - const char test_string[] = "Quick brown fox jumps over the lazy dog"; - char buf1[1024], buf2[1024], buf3[1024]; - size_t read, written, len = 16, i, j; - - BASE64_Encode(test_string, strlen(test_string) + 1, &read, - buf1, sizeof(buf1), &written, &len); - assert(read == strlen(test_string) + 1); - assert(written < sizeof(buf1)); - assert(buf1[written] == '\0'); - - assert(BASE64_Decode(buf1, written, &read, - buf2, sizeof(buf2), &written)); - assert(strlen(buf1) == read); - assert(written == strlen(test_string) + 1); - assert(buf2[written - 1] == '\0'); - assert(strcmp(buf2, test_string) == 0); - - for (i = 0; i < 100; i++) { - len = rand() % 250; - memset(buf1, '\0', sizeof(buf1)); - memset(buf2, '\0', sizeof(buf2)); - memset(buf3, '\0', sizeof(buf3)); - for (j = 0; j < len; j++) { - buf1[j] = rand() & 0xFF; - } - - j = rand() % 100; - BASE64_Encode(buf1, len, &read, buf2, sizeof(buf2), &written, &j); - if (len != read) - fprintf(stderr, "len = %d, read = %d\n", (int)len, (int)read); - assert(len == read); - assert (written < sizeof(buf2)); - assert(buf2[written] == '\0'); - - if (rand() & 1) { - buf2[written] = '='; - } - j = written; - BASE64_Decode(buf2, j, &read, buf3, sizeof(buf3), &written); - if (j != read) - fprintf(stderr, "j = %d, read = %d\n", (int)j, (int)read); - assert(j == read); - assert(len == written); - assert(memcmp(buf1, buf3, len) == 0); - } -} - - -/*********************************************************************** * TEST: Miscellaneous */ @@ -382,92 +328,9 @@ int main(void) CORE_SetLOGFILE(stderr, 0/*false*/); TEST_URL_Encoding(); - TEST_BASE64_Encoding(); TEST_MIME(); TEST_ConnNetInfo(); CORE_SetLOG(0); return 0; } - - -/* - * --------------------------------------------------------------------------- - * $Log: test_ncbi_connutil_misc.c,v $ - * Revision 6.25 2006/06/15 03:02:52 lavr - * GetUsername test moved from here to test_ncbi_core.c - * - * Revision 6.24 2006/04/19 02:22:57 lavr - * Modify test for Pre/Post overrides of SConnNetInfo::args - * - * Revision 6.23 2006/04/19 01:39:16 lavr - * ConnNetInfo_*Arg tests added - * - * Revision 6.22 2006/01/31 17:12:07 lavr - * CONNUTIL_GetUsername() test added - * - * Revision 6.21 2005/08/18 19:00:48 lavr - * More thorough BASE64_{En|De}code() tests - * - * Revision 6.20 2005/07/11 18:24:28 lavr - * Spell ADDEND - * - * Revision 6.19 2005/05/02 16:12:16 lavr - * Use global random seed - * - * Revision 6.18 2005/04/20 18:23:26 lavr - * +<stdlib.h> - * - * Revision 6.17 2005/03/21 17:04:51 lavr - * BASE64_{En|De}code tests extended - * - * Revision 6.16 2005/03/19 02:17:08 lavr - * Fix change log entry - * - * Revision 6.15 2005/03/19 02:14:10 lavr - * +Test for BASE64_{En|De}code - * - * Revision 6.14 2004/04/01 14:14:02 lavr - * Spell "occurred", "occurrence", and "occurring" - * - * Revision 6.13 2004/01/14 18:53:09 lavr - * Use "application/xml+soap" in the test case - * - * Revision 6.12 2004/01/07 19:24:03 lavr - * Added test for MIME content-type "application/xml" - * - * Revision 6.11 2002/12/13 21:20:55 lavr - * Move log to end - * - * Revision 6.10 2002/11/22 15:09:40 lavr - * Replace all occurrences of "ray" with "yar" - * - * Revision 6.9 2002/10/11 19:57:17 lavr - * Add tests for ConnNetInfo_*UserHeader() routines - * - * Revision 6.8 2002/03/22 19:46:51 lavr - * Test_assert.h made last among the include files - * - * Revision 6.7 2002/02/20 19:12:39 lavr - * Swapped eENCOD_Url and eENCOD_None; eENCOD_Unknown introduced; test cleaned - * - * Revision 6.6 2002/02/05 21:45:55 lavr - * Included header files rearranged - * - * Revision 6.5 2002/01/16 21:23:15 vakatov - * Utilize header "test_assert.h" to switch on ASSERTs in the Release mode too - * - * Revision 6.4 2000/11/07 23:24:43 vakatov - * [MIME] In-sync with the C Toolkit "connutil.c:R6.15" - * - * Revision 6.3 2000/04/12 15:22:07 vakatov - * Always #undef NDEBUG - * - * Revision 6.2 2000/03/29 17:21:48 vakatov - * + CORE_SetLOG(0) at the program end. - * - * Revision 6.1 2000/03/24 22:53:38 vakatov - * Initial revision - * - * =========================================================================== - */ diff --git a/connect/test/test_ncbi_core.c b/connect/test/test_ncbi_core.c index 36bdd195..3e58f85c 100644 --- a/connect/test/test_ncbi_core.c +++ b/connect/test/test_ncbi_core.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_core.c,v 6.13 2007/06/25 16:55:29 kazimird Exp $ +/* $Id: test_ncbi_core.c,v 6.15 2008/02/28 20:25:52 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -258,10 +258,10 @@ static void TEST_CORE_Log(void) verify(LOG_Delete(x_log) == x_log); assert(TEST_CORE_LogUserData == 1); - LOG_WRITE(0, eLOG_Trace, 0); - LOG_Write(0, eLOG_Trace, 0, 0, 0, 0); - LOG_WRITE(x_log, eLOG_Trace, 0); - LOG_Write(x_log, eLOG_Trace, 0, 0, 0, 0); + LOG_WRITE(0, 0, 0, eLOG_Trace, 0); + LOG_Write(0, 0, 0, eLOG_Trace, 0, 0, 0, 0); + LOG_WRITE(x_log, 0, 0, eLOG_Trace, 0); + LOG_Write(x_log, 0, 0, eLOG_Trace, 0, 0, 0, 0); verify(LOG_Delete(x_log) == x_log); assert(TEST_CORE_LogUserData == 1); @@ -273,16 +273,16 @@ static void TEST_CORE_Log(void) TEST_CORE_LogUserData = 2; /* do the test logging */ - LOG_WRITE(x_log, eLOG_Trace, 0); - LOG_Write(x_log, eLOG_Trace, 0, 0, 0, 0); - LOG_WRITE(x_log, eLOG_Warning, ""); + LOG_WRITE(x_log, 0, 0, eLOG_Trace, 0); + LOG_Write(x_log, 0, 0, eLOG_Trace, 0, 0, 0, 0); + LOG_WRITE(x_log, 0, 0, eLOG_Warning, ""); /* LOG_WRITE(x_log, eLOG_Fatal, "Something fatal"); */ #undef THIS_MODULE #define THIS_MODULE "FooModuleName" - LOG_WRITE(x_log, eLOG_Error, "With changed module name"); + LOG_WRITE(x_log, 0, 0, eLOG_Error, "With changed module name"); #undef THIS_FILE #define THIS_FILE "BarFileName" - LOG_WRITE(x_log, eLOG_Critical, "With changed module and file name"); + LOG_WRITE(x_log, 0, 0, eLOG_Critical, "With changed module and file name"); #undef THIS_FILE #define THIS_FILE __FILE__ #undef THIS_MODULE @@ -316,16 +316,16 @@ static void TEST_UTIL_Log(void) LOG_ToFILE(x_log, stdout, 0/*false*/); /* simple logging */ - LOG_WRITE(x_log, eLOG_Trace, 0); - LOG_Write(x_log, eLOG_Trace, 0, 0, 0, 0); - LOG_WRITE(x_log, eLOG_Warning, ""); + LOG_WRITE(x_log, 0, 0, eLOG_Trace, 0); + LOG_Write(x_log, 0, 0, eLOG_Trace, 0, 0, 0, 0); + LOG_WRITE(x_log, 0, 0, eLOG_Warning, ""); /* LOG_WRITE(x_log, eLOG_Fatal, "Something fatal"); */ #undef THIS_MODULE #define THIS_MODULE "FooModuleName" - LOG_WRITE(x_log, eLOG_Error, "With changed module name"); + LOG_WRITE(x_log, 0, 0, eLOG_Error, "With changed module name"); #undef THIS_FILE #define THIS_FILE "BarFileName" - LOG_WRITE(x_log, eLOG_Critical, "With changed module and file name"); + LOG_WRITE(x_log, 0, 0, eLOG_Critical, "With changed module and file name"); #undef THIS_FILE #define THIS_FILE __FILE__ #undef THIS_MODULE @@ -338,20 +338,20 @@ static void TEST_UTIL_Log(void) for (i = 0; i < sizeof(data); i++) { data[i] = (unsigned char) (i % 256); } - LOG_DATA(x_log, data, sizeof(data), "Data logging test"); + LOG_DATA(x_log, 0, 0, eLOG_Note, data, sizeof(data), "Data logging test"); }} /* logging with errno */ errno = 0; - LOG_WRITE_ERRNO(x_log, eLOG_Warning, 0); - LOG_WRITE_ERRNO(x_log, eLOG_Error, ""); - LOG_WRITE_ERRNO(x_log, eLOG_Critical, "OKAY"); + LOG_WRITE_ERRNO(x_log, 0, 0, eLOG_Warning, 0); + LOG_WRITE_ERRNO(x_log, 0, 0, eLOG_Error, ""); + LOG_WRITE_ERRNO(x_log, 0, 0, eLOG_Critical, "OKAY"); #undef THIS_FILE #define THIS_FILE 0 - (void)strtod("1e-999999", 0); LOG_WRITE_ERRNO(x_log, eLOG_Warning, 0); - (void)strtod("1e-999999", 0); LOG_WRITE_ERRNO(x_log, eLOG_Error, ""); - (void)strtod("1e-999999", 0); LOG_WRITE_ERRNO(x_log, eLOG_Critical, "FAIL"); + (void)strtod("1e-999999", 0); LOG_WRITE_ERRNO(x_log, 0, 0, eLOG_Warning, 0); + (void)strtod("1e-999999", 0); LOG_WRITE_ERRNO(x_log, 0, 0, eLOG_Error, ""); + (void)strtod("1e-999999", 0); LOG_WRITE_ERRNO(x_log, 0, 0, eLOG_Critical, "FAIL"); /* delete */ verify(LOG_Delete(x_log) == 0); diff --git a/connect/test/test_ncbi_http_get.c b/connect/test/test_ncbi_http_get.c index 7876f201..d5df86be 100644 --- a/connect/test/test_ncbi_http_get.c +++ b/connect/test/test_ncbi_http_get.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_http_get.c,v 6.14 2005/04/20 15:51:19 lavr Exp $ +/* $Id: test_ncbi_http_get.c,v 6.15 2007/09/26 14:55:37 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -115,7 +115,7 @@ int main(int argc, char* argv[]) fclose(fp); t = time(0); - for (;;) { + do { status = CONN_Wait(conn, eIO_Read, net_info->timeout); if (status != eIO_Success) { if (status == eIO_Closed) @@ -124,21 +124,20 @@ int main(int argc, char* argv[]) CORE_LOG(eLOG_Fatal, "Timed out"); #ifdef NCBI_OS_UNIX usleep(500); -#endif +#endif /*NCBI_OS_UNIX*/ continue; } - status = CONN_Read(conn, blk, sizeof(blk), &n, eIO_ReadPlain); - if (status != eIO_Success && status != eIO_Closed) + status = CONN_ReadLine(conn, blk, sizeof(blk), &n); + if (status != eIO_Success && status != eIO_Closed) CORE_LOGF(eLOG_Fatal, ("Read error: %s", IO_StatusStr(status))); - if (n) { + if (n == sizeof(blk)) + CORE_LOGF(eLOG_Warning, ("Line too long, continuing...")); + if (n) fwrite(blk, 1, n, stdout); - fflush(stdout); - } else if (status == eIO_Closed) { - break; - } else - CORE_LOG(eLOG_Fatal, "Empty read"); - } + fputc('\n', stdout); + fflush(stdout); + } while (status == eIO_Success); ConnNetInfo_Destroy(net_info); CORE_LOG(eLOG_Note, "Closing connection"); @@ -148,52 +147,3 @@ int main(int argc, char* argv[]) CORE_SetLOG(0); return 0; } - - -/* - * -------------------------------------------------------------------------- - * $Log: test_ncbi_http_get.c,v $ - * Revision 6.14 2005/04/20 15:51:19 lavr - * Allow addtl file argument to attach as a body ('-' for stdin) - * - * Revision 6.13 2005/04/19 16:37:52 lavr - * Allow HTTP method to be overridden from the environment - * - * Revision 6.12 2003/09/30 20:59:39 lavr - * Fix typo in previous log message - * - * Revision 6.11 2003/09/30 20:57:15 lavr - * Allow to set zero timeout via environment - * - * Revision 6.10 2003/05/20 23:52:01 lavr - * Explicit cast "time_t"->"unsigned" to avoid GCC warning - * - * Revision 6.9 2003/05/19 16:58:37 lavr - * Modified to use {0,0} timeouts in CONN_Wait() and use app timeout handling - * - * Revision 6.8 2003/05/14 03:58:43 lavr - * Match changes in respective APIs of the tests - * - * Revision 6.7 2002/10/28 15:47:06 lavr - * Use "ncbi_ansi_ext.h" privately - * - * Revision 6.6 2002/08/14 14:42:46 lavr - * Use fwrite() instead of printf() when printing out the data fetched - * - * Revision 6.5 2002/08/07 16:38:08 lavr - * EIO_ReadMethod enums changed accordingly; log moved to end - * - * Revision 6.4 2002/03/22 19:47:23 lavr - * Test_assert.h made last among the include files - * - * Revision 6.3 2002/02/05 21:45:55 lavr - * Included header files rearranged - * - * Revision 6.2 2002/01/16 21:23:15 vakatov - * Utilize header "test_assert.h" to switch on ASSERTs in the Release mode too - * - * Revision 6.1 2001/12/30 19:42:06 lavr - * Initial revision - * - * ========================================================================== - */ diff --git a/connect/test/test_ncbi_socket.c b/connect/test/test_ncbi_socket.c index fbb0dc28..197a1cfe 100644 --- a/connect/test/test_ncbi_socket.c +++ b/connect/test/test_ncbi_socket.c @@ -1,4 +1,4 @@ -/* $Id: test_ncbi_socket.c,v 6.25 2007/07/06 16:55:28 kazimird Exp $ +/* $Id: test_ncbi_socket.c,v 6.26 2007/10/19 11:25:50 kazimird Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE @@ -736,7 +736,7 @@ static const char* s_ntoa(unsigned int host) } -static int/*bool*/ TEST_gethostbyname(const char* name) +static unsigned int TEST_gethostbyname(const char* name) { char buf[256]; unsigned int host; @@ -745,23 +745,21 @@ static int/*bool*/ TEST_gethostbyname(const char* name) host = SOCK_gethostbyname(name); fprintf(log_fp, "SOCK_gethostbyname(\"%s\"): 0x%08X [%s]\n", - name, (unsigned int) host, s_ntoa(host)); - if ( !host ) { - return 0/*false*/; - } - - name = SOCK_gethostbyaddr(host, buf, sizeof(buf)); - if ( name ) { - assert(name == buf); - assert(0 < strlen(buf) && strlen(buf) < sizeof(buf)); - fprintf(log_fp, "SOCK_gethostbyaddr(0x%08X [%s]): \"%s\"\n", - (unsigned int) host, s_ntoa(host), name); - } else { - fprintf(log_fp, "SOCK_gethostbyaddr(0x%08X [%s]): <not found>\n", - (unsigned int) host, s_ntoa(host)); + name, (unsigned int) SOCK_NetToHostLong(host), s_ntoa(host)); + if ( host ) { + name = SOCK_gethostbyaddr(host, buf, sizeof(buf)); + if ( name ) { + assert(name == buf); + assert(0 < strlen(buf) && strlen(buf) < sizeof(buf)); + fprintf(log_fp, "SOCK_gethostbyaddr(0x%08X [%s]): \"%s\"\n", + (unsigned int) SOCK_NetToHostLong(host), s_ntoa(host), + name); + } else { + fprintf(log_fp, "SOCK_gethostbyaddr(0x%08X [%s]): <not found>\n", + (unsigned int) SOCK_NetToHostLong(host), s_ntoa(host)); + } } - - return 1/*true*/; + return host; } @@ -770,23 +768,23 @@ static int/*bool*/ TEST_gethostbyaddr(unsigned int host) const char* name; char buf[1024]; - fprintf(log_fp, "- - - - - - -\n"); + fprintf(log_fp, "------------\n"); name = SOCK_gethostbyaddr(host, buf, sizeof(buf)); if ( name ) { assert(name == buf); assert(0 < strlen(buf) && strlen(buf) < sizeof(buf)); fprintf(log_fp, "SOCK_gethostbyaddr(0x%08X [%s]): \"%s\"\n", - (unsigned int) host, s_ntoa(host), name); + (unsigned int) SOCK_NetToHostLong(host), s_ntoa(host), name); } else { fprintf(log_fp, "SOCK_gethostbyaddr(0x%08X [%s]): <not found>\n", - (unsigned int) host, s_ntoa(host)); + (unsigned int) SOCK_NetToHostLong(host), s_ntoa(host)); return 0/*false*/; } host = SOCK_gethostbyname(name); fprintf(log_fp, "SOCK_gethostbyname(\"%s\"): 0x%08X [%s]\n", - name, (unsigned int) host, s_ntoa(host)); + name, (unsigned int) SOCK_NetToHostLong(host), s_ntoa(host)); return 1/*true*/; } @@ -805,8 +803,6 @@ static void TEST_gethostby(void) assert( !TEST_gethostbyname("a1....b1") ); assert( !TEST_gethostbyname("boo.foo.bar.doo") ); - fprintf(log_fp, "\n++++++++++++++++++++++\n"); - (void) TEST_gethostbyname("localhost"); (void) TEST_gethostbyname("ncbi.nlm.nih.gov"); @@ -823,6 +819,72 @@ static void TEST_gethostby(void) } +static int/*bool*/ TEST_isip(const char* ip) +{ + int retval = SOCK_isip(ip); + + fprintf(log_fp, "------------\n"); + + fprintf(log_fp, "SOCK_isip(\"%s\"): %s\n", ip, retval ? "True" : "False"); + + return retval; +} + + + +/* Try SOCK_isip() + */ +static void TEST_SOCK_isip(void) +{ + fprintf(log_fp, "\n===============================\n"); + + assert(TEST_isip("0") && TEST_isip("0.0.0.0")); + assert(TEST_gethostbyname("0") == 0); + assert(TEST_isip("1")); + assert(TEST_gethostbyname("1") == SOCK_HostToNetLong(1)); + assert(TEST_isip("0x7F000002")); + assert(TEST_gethostbyname("0x7F000002") == + TEST_gethostbyname("127.0.0.2")); + + assert(TEST_isip("127.234")); + assert(TEST_gethostbyname("127.234") == + TEST_gethostbyname("127.0.0.234")); + assert(TEST_isip("127.16777215")); + assert(TEST_gethostbyname("127.16777215") == + TEST_gethostbyname("127.255.255.255")); + + assert(TEST_isip("127.234.0x345")); + assert(TEST_gethostbyname("127.234.3.69") == + TEST_gethostbyname("127.234.3.69")); + assert(TEST_isip("127.234.0xFFFF")); + assert(TEST_gethostbyname("127.234.0xFFFF") == + TEST_gethostbyname("127.234.255.255")); + + assert(TEST_isip("127.012344321")); + assert(TEST_gethostbyname("127.012344321") == + TEST_gethostbyname("127.41.200.209")); + assert(TEST_isip("127.077777777")); + assert(TEST_gethostbyname("127.077777777") == + TEST_gethostbyname("127.255.255.255")); + + assert(TEST_isip("0.0321.0xAB.123")); + assert(TEST_isip("255.255.255.255")); + + assert(!TEST_isip("a")); + assert(!TEST_isip("-1")); + assert(!TEST_isip("1.2.3a")); + assert(!TEST_isip("1.0xDEATH")); + assert(!TEST_isip("1.2.3.256")); + assert(!TEST_isip("1.2.0200000")); + assert(!TEST_isip("1.1.1.1.")); + assert(!TEST_isip("1.1.-1.1")); + assert(!TEST_isip("1.0x100.1.1")); + assert(!TEST_isip("1.0100000000")); + assert(!TEST_isip("0x100000000")); + + fprintf(log_fp, "\n===============================\n"); +} + /* Main function * Parse command-line options, initialize and cleanup API internals; @@ -920,6 +982,8 @@ extern int main(int argc, char** argv) TEST_gethostby(); + TEST_SOCK_isip(); + TEST__client(server_host, (unsigned short)server_port, timeout); assert(SOCK_ShutdownAPI() == eIO_Success); CORE_SetLOG(0); |