summaryrefslogtreecommitdiff
path: root/connect/test/test_ncbi_connutil_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'connect/test/test_ncbi_connutil_misc.c')
-rw-r--r--connect/test/test_ncbi_connutil_misc.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/connect/test/test_ncbi_connutil_misc.c b/connect/test/test_ncbi_connutil_misc.c
index a26809f6..732ceee0 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.14 2004/04/01 14:14:02 lavr Exp $
+/* $Id: test_ncbi_connutil_misc.c,v 6.18 2005/04/20 18:23:26 lavr Exp $
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
@@ -32,6 +32,7 @@
#include <connect/ncbi_connutil.h>
#include <connect/ncbi_util.h>
+#include <stdlib.h>
#include <string.h>
/* This header must go last */
#include "test_assert.h"
@@ -141,6 +142,51 @@ 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, '=', 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);
+ assert(len == read);
+ assert (written < sizeof(buf2));
+ assert(buf2[written] == '\0');
+
+ buf2[written] = '=';
+ BASE64_Decode(buf2, written, &read, buf3, sizeof(buf3), &written);
+ assert(len == written);
+ assert(memcmp(buf1, buf3, len) == 0);
+ }
+}
+
/***********************************************************************
* TEST: Miscellaneous
@@ -291,6 +337,7 @@ int main(void)
CORE_SetLOGFILE(stderr, 0/*false*/);
TEST_URL_Encoding();
+ TEST_BASE64_Encoding();
TEST_MIME();
TEST_ConnNetInfo();
@@ -302,6 +349,18 @@ int main(void)
/*
* ---------------------------------------------------------------------------
* $Log: test_ncbi_connutil_misc.c,v $
+ * 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"
*