apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject svn commit: r765799 - in /apr/apr/trunk/test: Makefile.in abts_tests.h testbase64.c testutil.h
Date Thu, 16 Apr 2009 23:22:10 GMT
Author: jerenkrantz
Date: Thu Apr 16 23:22:09 2009
New Revision: 765799

URL: http://svn.apache.org/viewvc?rev=765799&view=rev
Log:
Add quick base64 sanity checker to test suite.

* test/testbase64.c: Add simple test cases.
* test/Makefile.in: Add testbase64.lo
* test/abts_tests.h, test/testutil.h: Declare testbase64.

Added:
    apr/apr/trunk/test/testbase64.c   (with props)
Modified:
    apr/apr/trunk/test/Makefile.in
    apr/apr/trunk/test/abts_tests.h
    apr/apr/trunk/test/testutil.h

Modified: apr/apr/trunk/test/Makefile.in
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/Makefile.in?rev=765799&r1=765798&r2=765799&view=diff
==============================================================================
--- apr/apr/trunk/test/Makefile.in (original)
+++ apr/apr/trunk/test/Makefile.in Thu Apr 16 23:22:09 2009
@@ -34,7 +34,7 @@
 	testxlate.lo testdbd.lo testrmm.lo testldap.lo testmd4.lo	\
 	teststrmatch.lo testpass.lo testcrypto.lo testqueue.lo		\
 	testbuckets.lo testxml.lo testdbm.lo testuuid.lo testmd5.lo	\
-	testreslist.lo
+	testreslist.lo testbase64.lo
 
 OTHER_PROGRAMS = \
 	sendfile@EXEEXT@ \

Modified: apr/apr/trunk/test/abts_tests.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/abts_tests.h?rev=765799&r1=765798&r2=765799&view=diff
==============================================================================
--- apr/apr/trunk/test/abts_tests.h (original)
+++ apr/apr/trunk/test/abts_tests.h Thu Apr 16 23:22:09 2009
@@ -72,6 +72,7 @@
     {testuuid},
     {testbuckets},
     {testpass},
+    {testbase64},
     {testmd4},
     {testmd5},
     {testcrypto},

Added: apr/apr/trunk/test/testbase64.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testbase64.c?rev=765799&view=auto
==============================================================================
--- apr/apr/trunk/test/testbase64.c (added)
+++ apr/apr/trunk/test/testbase64.c Thu Apr 16 23:22:09 2009
@@ -0,0 +1,80 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "apr_base64.h"
+
+#include "abts.h"
+#include "testutil.h"
+
+static struct {
+   const char *orig;
+   const char *enc;
+} base64_tbl[] =
+{
+    {"", ""},
+    {"H", "SA=="},
+    {"He", "SGU="},
+    {"Hel", "SGVs"},
+    {"Hell", "SGVsbA=="},
+    {"Hello", "SGVsbG8="},
+    {"Hello World", "SGVsbG8gV29ybGQ="},
+    {"\xff\xff\xff\xff", "/////w=="},
+    {"A\u00ea\u00f1\u00fcC", "QcOqw7HDvEM="},
+};
+static int num_base64 = sizeof(base64_tbl) / sizeof(base64_tbl[0]);
+
+static void test_base64(abts_case *tc, void *data)
+{
+    apr_pool_t *pool;
+    int i;
+
+    apr_pool_create(&pool, NULL);
+
+    for (i = 0; i < num_base64; i++) {
+        char *enc;
+        int orig_len, enc_len, b64_len, b64_enc_len;
+
+        apr_pool_clear(pool);
+
+        orig_len = strlen(base64_tbl[i].orig);
+        enc_len = strlen(base64_tbl[i].enc);
+
+        /* includes + 1 for term null */
+        b64_enc_len = apr_base64_encode_len(orig_len);
+        ABTS_ASSERT(tc, "base 64 exp. length", (enc_len == (b64_enc_len - 1)));
+
+        enc = apr_palloc(pool, b64_enc_len);
+
+        b64_len = apr_base64_encode(enc, base64_tbl[i].orig, orig_len);
+
+        ABTS_ASSERT(tc, "base 64 encoded length", (b64_enc_len == b64_len));
+        ABTS_ASSERT(tc, "base 64 encoded matches expected output",
+                    (memcmp(enc, base64_tbl[i].enc, b64_enc_len) == 0));
+    }
+}
+
+abts_suite *testbase64(abts_suite *suite)
+{
+    suite = ADD_SUITE(suite);
+
+    abts_run_test(suite, test_base64, NULL);
+
+    return suite;
+}

Propchange: apr/apr/trunk/test/testbase64.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: apr/apr/trunk/test/testutil.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testutil.h?rev=765799&r1=765798&r2=765799&view=diff
==============================================================================
--- apr/apr/trunk/test/testutil.h (original)
+++ apr/apr/trunk/test/testutil.h Thu Apr 16 23:22:09 2009
@@ -108,6 +108,7 @@
 abts_suite *testuuid(abts_suite *suite);
 abts_suite *testbuckets(abts_suite *suite);
 abts_suite *testpass(abts_suite *suite);
+abts_suite *testbase64(abts_suite *suite);
 abts_suite *testmd4(abts_suite *suite);
 abts_suite *testmd5(abts_suite *suite);
 abts_suite *testcrypto(abts_suite *suite);



Mime
View raw message