rbb 2002/11/23 22:14:00
Modified: test Makefile.in test_apr.h testall.c testdup.c
Log:
Migrate testdup to the new test suite.
Revision Changes Path
1.111 +3 -3 apr/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr/test/Makefile.in,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- Makefile.in 24 Nov 2002 04:49:45 -0000 1.110
+++ Makefile.in 24 Nov 2002 06:13:59 -0000 1.111
@@ -153,12 +153,12 @@
testall: testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
- testdso.lo testoc.lo CuTest.lo mod_test.la libmod_test.la \
- [EMAIL PROTECTED]@ $(LOCAL_LIBS)
+ testdso.lo testoc.lo testdup.lo CuTest.lo mod_test.la \
+ libmod_test.la [EMAIL PROTECTED]@ $(LOCAL_LIBS)
$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo \
testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
- testdso.lo testoc.lo CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
+ testdso.lo testoc.lo testdup.lo CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
# DO NOT REMOVE
1.25 +1 -0 apr/test/test_apr.h
Index: test_apr.h
===================================================================
RCS file: /home/cvs/apr/test/test_apr.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- test_apr.h 24 Nov 2002 04:49:45 -0000 1.24
+++ test_apr.h 24 Nov 2002 06:13:59 -0000 1.25
@@ -82,6 +82,7 @@
CuSuite *testrand(void);
CuSuite *testdso(void);
CuSuite *testoc(void);
+CuSuite *testdup(void);
1.23 +2 -1 apr/test/testall.c
Index: testall.c
===================================================================
RCS file: /home/cvs/apr/test/testall.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- testall.c 24 Nov 2002 04:49:45 -0000 1.22
+++ testall.c 24 Nov 2002 06:13:59 -0000 1.23
@@ -75,8 +75,9 @@
{"testpool", testpool},
{"testfmt", testfmt},
{"testfile", testfile},
- {"testdir", testdir},
{"testfileinfo", testfileinfo},
+ {"testdup", testdup},
+ {"testdir", testdir},
{"testrand", testrand},
{"testdso", testdso},
{"testoc", testoc},
1.6 +118 -47 apr/test/testdup.c
Index: testdup.c
===================================================================
RCS file: /home/cvs/apr/test/testdup.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- testdup.c 13 Mar 2002 20:39:27 -0000 1.5
+++ testdup.c 24 Nov 2002 06:13:59 -0000 1.6
@@ -57,83 +57,154 @@
#include "apr_pools.h"
#include "apr_errno.h"
#include "apr_file_io.h"
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#if APR_HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#include "test_apr.h"
#define TEST "Testing\n"
#define TEST2 "Testing again\n"
+#define FILENAME "data/testdup.file"
-int main (int argc, char ** argv)
+static void test_file_dup(CuTest *tc)
{
apr_file_t *file1 = NULL;
- apr_file_t *file2 = NULL;
apr_file_t *file3 = NULL;
+ apr_status_t rv;
+ apr_finfo_t finfo;
+
+ /* First, create a new file, empty... */
+ rv = apr_file_open(&file1, FILENAME, APR_READ | APR_WRITE | APR_CREATE|
+ APR_DELONCLOSE, APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file1);
+
+ rv = apr_file_dup(&file3, file1, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file3);
+
+ rv = apr_file_close(file1);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ /* cleanup after ourselves */
+ rv = apr_file_close(file3);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_stat(&finfo, FILENAME, APR_FINFO_NORM, p);
+ CuAssertIntEquals(tc, APR_ENOENT, rv);
+}
- apr_pool_t *p;
+static void test_file_readwrite(CuTest *tc)
+{
+ apr_file_t *file1 = NULL;
+ apr_file_t *file3 = NULL;
+ apr_status_t rv;
+ apr_finfo_t finfo;
apr_size_t txtlen = sizeof(TEST);
char buff[50];
apr_off_t fpos;
- apr_initialize();
- atexit(apr_terminate);
-
- fprintf(stdout, "APR File Duplication
Test\n=========================\n\n");
- STD_TEST_NEQ("Creating a pool", apr_pool_create(&p, NULL))
-
- printf("\nTesting apr_file_dup\n");
/* First, create a new file, empty... */
- STD_TEST_NEQ(" Open a new, empty file (#1)", apr_file_open(&file1,
"./testdup.file",
- APR_READ | APR_WRITE |
APR_CREATE,
- APR_OS_DEFAULT, p))
-
- STD_TEST_NEQ(" Simple dup", apr_file_dup(&file3, file1, p))
-
- STD_TEST_NEQ(" Write to dup'd file (#3)", apr_file_write(file3, TEST,
&txtlen))
+ rv = apr_file_open(&file1, FILENAME, APR_READ | APR_WRITE | APR_CREATE|
+ APR_DELONCLOSE, APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file1);
+
+ rv = apr_file_dup(&file3, file1, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file3);
+
+ rv = apr_file_write(file3, TEST, &txtlen);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, sizeof(TEST), txtlen);
fpos = 0;
- STD_TEST_NEQ(" Rewind file #1 to start", apr_file_seek(file1,
APR_SET, &fpos))
+ rv = apr_file_seek(file1, APR_SET, &fpos);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, 0, fpos);
txtlen = 50;
- STD_TEST_NEQ(" Read from file #1",
- apr_file_read(file1, buff, &txtlen))
+ rv = apr_file_read(file1, buff, &txtlen);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, TEST, buff);
+
+ /* cleanup after ourselves */
+ rv = apr_file_close(file1);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_file_close(file3);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ rv = apr_stat(&finfo, FILENAME, APR_FINFO_NORM, p);
+ CuAssertIntEquals(tc, APR_ENOENT, rv);
+}
- TEST_NEQ(" Checking what we read from #1", strcmp(buff, TEST), 0,
"OK", "Failed")
+static void test_dup2(CuTest *tc)
+{
+ apr_file_t *file2 = NULL;
+ apr_file_t *file3 = NULL;
+ apr_status_t rv;
+ rv = apr_file_open(&file2, FILENAME, APR_READ | APR_WRITE | APR_CREATE |
+ APR_DELONCLOSE, APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file2);
- printf("\nTesting apr_file_dup2\n");
- STD_TEST_NEQ(" Open another new, empty file (#2)",
- apr_file_open(&file2, "./testdup2.file",
- APR_READ | APR_WRITE | APR_CREATE,
- APR_OS_DEFAULT, p))
+ rv = apr_file_open_stderr(&file3, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
- STD_TEST_NEQ(" Dup2 test", apr_file_dup2(file3, file2, p))
+ rv = apr_file_dup2(file3, file2, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file3);
+
+ apr_file_close(file2);
+ apr_file_close(file3);
+}
+
+static void test_dup2_readwrite(CuTest *tc)
+{
+ apr_file_t *file3 = NULL;
+ apr_file_t *file2 = NULL;
+ apr_status_t rv;
+ apr_size_t txtlen = sizeof(TEST);
+ char buff[50];
+ apr_off_t fpos;
+
+ rv = apr_file_open(&file2, FILENAME, APR_READ | APR_WRITE | APR_CREATE |
+ APR_DELONCLOSE, APR_OS_DEFAULT, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file2);
+
+ rv = apr_file_open_stderr(&file3, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_file_dup2(file3, file2, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertPtrNotNull(tc, file3);
txtlen = sizeof(TEST2);
- STD_TEST_NEQ(" Write to dup'd file #3", apr_file_write(file3, TEST2,
&txtlen))
+ rv = apr_file_write(file3, TEST2, &txtlen);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, sizeof(TEST2), txtlen);
- STD_TEST_NEQ(" Rewind file #2 to start", apr_file_seek(file2,
APR_SET, &fpos))
+ fpos = 0;
+ rv = apr_file_seek(file2, APR_SET, &fpos);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, 0, fpos);
txtlen = 50;
- STD_TEST_NEQ(" Read from file #2",
- apr_file_read(file2, buff, &txtlen))
-
- TEST_NEQ(" Checking what we read from #2", strcmp(buff, TEST2), 0,
"OK", "Failed")
+ rv = apr_file_read(file2, buff, &txtlen);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertStrEquals(tc, TEST2, buff);
- printf("\nCleaning up\n");
- STD_TEST_NEQ(" Closing file #3", apr_file_close(file3))
- STD_TEST_NEQ(" Closing file #2", apr_file_close(file2))
- STD_TEST_NEQ(" Closing file #1", apr_file_close(file1))
+ apr_file_close(file2);
+ apr_file_close(file3);
+}
- STD_TEST_NEQ(" Removing first test file",
apr_file_remove("./testdup.file", p))
- STD_TEST_NEQ(" Removing first test file",
apr_file_remove("./testdup2.file", p))
+CuSuite *testdup(void)
+{
+ CuSuite *suite = CuSuiteNew("File duplication");
- printf("\nAll Tests completed - OK!\n");
+ SUITE_ADD_TEST(suite, test_file_dup);
+ SUITE_ADD_TEST(suite, test_file_readwrite);
+ SUITE_ADD_TEST(suite, test_dup2);
+ SUITE_ADD_TEST(suite, test_dup2_readwrite);
- return (0);
+ return suite;
}