summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-12-07 02:59:20 +0000
committerrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2002-12-07 02:59:20 +0000
commit0d34e0e714616529ab80068062b6fa11530e0e5a (patch)
treee44be2b373e02a423bfd8bc8fdca6d902241cb10
parent568b227141fb5fd3859ef27cd0eaa147de4ebba5 (diff)
downloadlibapr-0d34e0e714616529ab80068062b6fa11530e0e5a.tar.gz
Migrate testnames to the new test suite.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64128 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--test/Makefile.in6
-rw-r--r--test/test_apr.h1
-rw-r--r--test/testall.c1
-rw-r--r--test/testnames.c223
4 files changed, 156 insertions, 75 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index 322be7ec0..87f5122cd 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -10,7 +10,6 @@ PROGRAMS = \
client@EXEEXT@ \
sendfile@EXEEXT@ \
server@EXEEXT@ \
- testnames@EXEEXT@ \
testflock@EXEEXT@ \
testsock@EXEEXT@ \
testlockperf@EXEEXT@ \
@@ -46,9 +45,6 @@ check: $(PROGRAMS) $(NONPORTABLE)
fi \
done
-testnames@EXEEXT@: testnames.lo $(LOCAL_LIBS)
- $(LINK) testnames.lo $(LOCAL_LIBS) $(ALL_LIBS)
-
testflock@EXEEXT@: testflock.lo $(LOCAL_LIBS)
$(LINK) testflock.lo $(LOCAL_LIBS) $(ALL_LIBS)
@@ -112,7 +108,7 @@ TESTS = testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
- testhash.lo testargs.lo
+ testhash.lo testargs.lo testnames.lo
testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS)
diff --git a/test/test_apr.h b/test/test_apr.h
index 3466775dc..d59b6d9fe 100644
--- a/test/test_apr.h
+++ b/test/test_apr.h
@@ -92,6 +92,7 @@ CuSuite *testsockopt(void);
CuSuite *testpipe(void);
CuSuite *testthread(void);
CuSuite *testgetopt(void);
+CuSuite *testnames(void);
/* Assert that RV is an APR_SUCCESS value; else fail giving strerror
* for RV and CONTEXT message. */
diff --git a/test/testall.c b/test/testall.c
index 2a3c261f1..8d0554b56 100644
--- a/test/testall.c
+++ b/test/testall.c
@@ -100,6 +100,7 @@ static const struct testlist {
{"testlock", testlock},
{"testthread", testthread},
{"testargs", testgetopt},
+ {"testnames", testnames},
{"LastTest", NULL}
};
diff --git a/test/testnames.c b/test/testnames.c
index 23f8ef929..6ee9b80d0 100644
--- a/test/testnames.c
+++ b/test/testnames.c
@@ -52,9 +52,7 @@
* <http://www.apache.org/>.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "test_apr.h"
#include "apr_file_io.h"
#include "apr_file_info.h"
#include "apr_errno.h"
@@ -62,87 +60,172 @@
#include "apr_pools.h"
#include "apr_lib.h"
-apr_pool_t *context;
+static void merge_aboveroot(CuTest *tc)
+{
+ apr_status_t rv;
+ char *dstpath = NULL;
+ char errmsg[256];
+
+ rv = apr_filepath_merge(&dstpath, "/foo", "/bar", APR_FILEPATH_NOTABOVEROOT,
+ p);
+ apr_strerror(rv, errmsg, sizeof(errmsg));
+ CuAssertPtrEquals(tc, NULL, dstpath);
+ CuAssertIntEquals(tc, 1, APR_STATUS_IS_EABOVEROOT(rv));
+ CuAssertStrEquals(tc, "The given path was above the root path", errmsg);
+}
-static void closeapr(void)
+static void merge_belowroot(CuTest *tc)
{
- apr_pool_destroy(context);
- apr_terminate();
+ apr_status_t rv;
+ char *dstpath = NULL;
+
+ rv = apr_filepath_merge(&dstpath, "/foo", "/foo/bar",
+ APR_FILEPATH_NOTABOVEROOT, p);
+ CuAssertPtrNotNull(tc, dstpath);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "/foo/bar", dstpath);
}
-static void root_result(const char *path)
+static void merge_noflag(CuTest *tc)
{
- apr_status_t status;
+ apr_status_t rv;
+ char *dstpath = NULL;
+
+ rv = apr_filepath_merge(&dstpath, "/foo", "/foo/bar", 0, p);
+ CuAssertPtrNotNull(tc, dstpath);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "/foo/bar", dstpath);
+}
+
+static void merge_dotdot(CuTest *tc)
+{
+ apr_status_t rv;
+ char *dstpath = NULL;
+
+ rv = apr_filepath_merge(&dstpath, "/foo/bar", "../baz", 0, p);
+ CuAssertPtrNotNull(tc, dstpath);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "/foo/baz", dstpath);
+}
+
+static void merge_secure(CuTest *tc)
+{
+ apr_status_t rv;
+ char *dstpath = NULL;
+
+ rv = apr_filepath_merge(&dstpath, "/foo/bar", "../bar/baz", 0, p);
+ CuAssertPtrNotNull(tc, dstpath);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "/foo/bar/baz", dstpath);
+}
+
+static void merge_notrel(CuTest *tc)
+{
+ apr_status_t rv;
+ char *dstpath = NULL;
+
+ rv = apr_filepath_merge(&dstpath, "/foo/bar", "../baz",
+ APR_FILEPATH_NOTRELATIVE, p);
+ CuAssertPtrNotNull(tc, dstpath);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "/foo/baz", dstpath);
+}
+
+static void merge_notrelfail(CuTest *tc)
+{
+ apr_status_t rv;
+ char *dstpath = NULL;
char errmsg[256];
- const char *root = NULL;
- status = apr_filepath_root(&root, &path, APR_FILEPATH_NATIVE, context);
- apr_strerror(status, errmsg, sizeof(errmsg));
- if (root)
- fprintf(stderr, "\tRoot \"%s\" Path \"%s\" (%s)\n",
- root, path, errmsg);
- else
- fprintf(stderr, "\tPath \"%s\" Error (%s)\n",
- path, errmsg);
+ rv = apr_filepath_merge(&dstpath, "foo/bar", "../baz",
+ APR_FILEPATH_NOTRELATIVE, p);
+ apr_strerror(rv, errmsg, sizeof(errmsg));
+
+ CuAssertPtrEquals(tc, NULL, dstpath);
+ CuAssertIntEquals(tc, 1, APR_STATUS_IS_ERELATIVE(rv));
+ CuAssertStrEquals(tc, "The given path is relative", errmsg);
}
-static void mergeresult(char *rootpath, char *addpath, apr_int32_t mergetype, char *tdesc)
+static void merge_notabsfail(CuTest *tc)
{
+ apr_status_t rv;
+ char *dstpath = NULL;
char errmsg[256];
+
+ rv = apr_filepath_merge(&dstpath, "/foo/bar", "../baz",
+ APR_FILEPATH_NOTABSOLUTE, p);
+ apr_strerror(rv, errmsg, sizeof(errmsg));
+
+ CuAssertPtrEquals(tc, NULL, dstpath);
+ CuAssertIntEquals(tc, 1, APR_STATUS_IS_EABSOLUTE(rv));
+ CuAssertStrEquals(tc, "The given path is absolute", errmsg);
+}
+
+static void merge_notabs(CuTest *tc)
+{
+ apr_status_t rv;
char *dstpath = NULL;
- apr_status_t status = apr_filepath_merge(&dstpath,
- strcmp(rootpath, "NULL") ? rootpath : NULL,
- strcmp(addpath, "NULL") ? addpath : NULL,
- mergetype, context);
- apr_strerror(status, errmsg, sizeof(errmsg));
- if (dstpath) {
- fprintf(stderr, "%s result for %s\n\tResult Path \"%s\"\n", errmsg, tdesc, dstpath);
- }
- else {
- fprintf(stderr, "%s result for %s\n", errmsg, tdesc);
- }
+
+ rv = apr_filepath_merge(&dstpath, "foo/bar", "../baz",
+ APR_FILEPATH_NOTABSOLUTE, p);
+
+ CuAssertPtrNotNull(tc, dstpath);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "foo/baz", dstpath);
+}
+
+static void root_absolute(CuTest *tc)
+{
+ apr_status_t rv;
+ const char *root = NULL;
+ const char *path = "/foo/bar";
+
+ rv = apr_filepath_root(&root, &path, 0, p);
+
+ CuAssertPtrNotNull(tc, root);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, "/", root);
+}
+
+static void root_relative(CuTest *tc)
+{
+ apr_status_t rv;
+ const char *root = NULL;
+ const char *path = "foo/bar";
+ char errmsg[256];
+
+ rv = apr_filepath_root(&root, &path, 0, p);
+ apr_strerror(rv, errmsg, sizeof(errmsg));
+
+ CuAssertPtrEquals(tc, NULL, root);
+ CuAssertIntEquals(tc, 1, APR_STATUS_IS_ERELATIVE(rv));
+ CuAssertStrEquals(tc, "The given path is relative", errmsg);
}
-#define merge_result(r, a, t) mergeresult(r, a, t, #t)
-int main(void)
+#if 0
+ root_result(rootpath);
+ root_result(addpath);
+}
+#endif
+
+CuSuite *testnames(void)
{
- char rootpath[256];
- char addpath[256];
- char *eos;
-
- if (apr_initialize() != APR_SUCCESS) {
- fprintf(stderr, "Couldn't initialize.");
- exit(-1);
- }
- atexit(closeapr);
- if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
- fprintf(stderr, "Couldn't allocate context.");
- exit(-1);
- }
-
- fprintf(stdout, "Testing file truepath.\n");
-
- while (1) {
- fprintf(stdout, "\nEnter a root path$ ");
- if (!fgets(rootpath, 256, stdin))
- exit(0);
- for (eos = strchr(rootpath, '\0'); --eos >= rootpath; )
- if (apr_isspace(*eos))
- *eos = '\0';
- fprintf(stdout, "Enter an add path$ ");
- if (!fgets(addpath, 256, stdin))
- exit(0);
- for (eos = strchr(addpath, '\0'); --eos >= addpath; )
- if (apr_isspace(*eos))
- *eos = '\0';
- merge_result(rootpath, addpath, 0);
- merge_result(rootpath, addpath, APR_FILEPATH_NOTABOVEROOT);
- merge_result(rootpath, addpath, APR_FILEPATH_SECUREROOT);
- merge_result(rootpath, addpath, APR_FILEPATH_NOTABSOLUTE);
- merge_result(rootpath, addpath, APR_FILEPATH_NOTRELATIVE);
- root_result(rootpath);
- root_result(addpath);
- }
- return (0);
+ CuSuite *suite = CuSuiteNew("Path names");
+
+ SUITE_ADD_TEST(suite, merge_aboveroot);
+ SUITE_ADD_TEST(suite, merge_belowroot);
+ SUITE_ADD_TEST(suite, merge_noflag);
+ SUITE_ADD_TEST(suite, merge_dotdot);
+ SUITE_ADD_TEST(suite, merge_secure);
+ SUITE_ADD_TEST(suite, merge_notrel);
+ SUITE_ADD_TEST(suite, merge_notrelfail);
+ SUITE_ADD_TEST(suite, merge_notabs);
+ SUITE_ADD_TEST(suite, merge_notabsfail);
+
+ SUITE_ADD_TEST(suite, root_absolute);
+ SUITE_ADD_TEST(suite, root_relative);
+
+ return suite;
}
+