diff options
author | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2002-12-15 19:01:16 +0000 |
---|---|---|
committer | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2002-12-15 19:01:16 +0000 |
commit | ffc328d2ccf1f9275aa74c255d335cb8634281da (patch) | |
tree | dc0fea47c055186706c00af74a8dbb428ff6c63f /test/testfile.c | |
parent | 11ee8b026be7fc1ec9743fddbc3f480a0ec3123a (diff) | |
download | libapr-ffc328d2ccf1f9275aa74c255d335cb8634281da.tar.gz |
We were leaking file descriptors from the testfile program. That
interfered with testpoll on some platforms. All tests need to clean up
after themselves. testfile now finishes without any leaks.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64176 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testfile.c')
-rw-r--r-- | test/testfile.c | 84 |
1 files changed, 81 insertions, 3 deletions
diff --git a/test/testfile.c b/test/testfile.c index 2f1bdeb15..5e85d5a43 100644 --- a/test/testfile.c +++ b/test/testfile.c @@ -68,7 +68,6 @@ #define APR_BUFFERSIZE 4096 /* This should match APR's buffer size. */ -static apr_file_t *filetest = NULL; static void test_open_noreadwrite(CuTest *tc) { @@ -87,6 +86,7 @@ static void test_open_noreadwrite(CuTest *tc) */ CuAssertPtrEquals(tc, NULL, thefile); #endif + apr_file_close(thefile); } static void test_open_excl(CuTest *tc) @@ -106,17 +106,20 @@ static void test_open_excl(CuTest *tc) */ CuAssertPtrEquals(tc, NULL, thefile); #endif + apr_file_close(thefile); } static void test_open_read(CuTest *tc) { apr_status_t rv; + apr_file_t *filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ, APR_UREAD | APR_UWRITE | APR_GREAD, p); CuAssertIntEquals(tc, rv, APR_SUCCESS); CuAssertPtrNotNull(tc, filetest); + apr_file_close(filetest); } static void test_read(CuTest *tc) @@ -124,21 +127,35 @@ static void test_read(CuTest *tc) apr_status_t rv; apr_size_t nbytes = 256; char *str = apr_pcalloc(p, nbytes + 1); + apr_file_t *filetest = NULL; + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + rv = apr_file_read(filetest, str, &nbytes); CuAssertIntEquals(tc, APR_SUCCESS, rv); CuAssertIntEquals(tc, strlen(TESTSTR), nbytes); CuAssertStrEquals(tc, TESTSTR, str); + + apr_file_close(filetest); } static void test_filename(CuTest *tc) { const char *str; apr_status_t rv; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); rv = apr_file_name_get(&str, filetest); CuAssertIntEquals(tc, rv, APR_SUCCESS); CuAssertStrEquals(tc, FILENAME, str); + + apr_file_close(filetest); } static void test_fileclose(CuTest *tc) @@ -146,6 +163,12 @@ static void test_fileclose(CuTest *tc) char str; apr_status_t rv; apr_size_t one = 1; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + rv = apr_file_close(filetest); CuAssertIntEquals(tc, rv, APR_SUCCESS); @@ -157,6 +180,7 @@ static void test_fileclose(CuTest *tc) static void test_file_remove(CuTest *tc) { apr_status_t rv; + apr_file_t *filetest = NULL; rv = apr_file_remove(FILENAME, p); CuAssertIntEquals(tc, APR_SUCCESS, rv); @@ -169,45 +193,60 @@ static void test_file_remove(CuTest *tc) static void test_open_write(CuTest *tc) { apr_status_t rv; + apr_file_t *filetest = NULL; filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv)); + apr_file_close(filetest); } static void test_open_writecreate(CuTest *tc) { apr_status_t rv; + apr_file_t *filetest = NULL; filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_WRITE | APR_CREATE, APR_UREAD | APR_UWRITE | APR_GREAD, p); CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_close(filetest); } static void test_write(CuTest *tc) { apr_status_t rv; apr_size_t bytes = strlen(TESTSTR); + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE | APR_CREATE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); rv = apr_file_write(filetest, TESTSTR, &bytes); CuAssertIntEquals(tc, APR_SUCCESS, rv); + + apr_file_close(filetest); } static void test_open_readwrite(CuTest *tc) { apr_status_t rv; + apr_file_t *filetest = NULL; - apr_file_close(filetest); filetest = NULL; rv = apr_file_open(&filetest, FILENAME, APR_READ | APR_WRITE, APR_UREAD | APR_UWRITE | APR_GREAD, p); CuAssertIntEquals(tc, rv, APR_SUCCESS); CuAssertPtrNotNull(tc, filetest); + + apr_file_close(filetest); } static void test_seek(CuTest *tc) @@ -216,6 +255,18 @@ static void test_seek(CuTest *tc) apr_off_t offset = 5; apr_size_t nbytes = 256; char *str = apr_pcalloc(p, nbytes + 1); + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_READ, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + + rv = apr_file_read(filetest, str, &nbytes); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + CuAssertIntEquals(tc, strlen(TESTSTR), nbytes); + CuAssertStrEquals(tc, TESTSTR, str); + + memset(str, 0, nbytes + 1); rv = apr_file_seek(filetest, SEEK_SET, &offset); CuAssertIntEquals(tc, APR_SUCCESS, rv); @@ -224,36 +275,63 @@ static void test_seek(CuTest *tc) CuAssertIntEquals(tc, APR_SUCCESS, rv); CuAssertIntEquals(tc, strlen(TESTSTR) - 5, nbytes); CuAssertStrEquals(tc, TESTSTR + 5, str); -} + apr_file_close(filetest); +} static void test_userdata_set(CuTest *tc) { apr_status_t rv; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); rv = apr_file_data_set(filetest, "This is a test", "test", apr_pool_cleanup_null); CuAssertIntEquals(tc, APR_SUCCESS, rv); + apr_file_close(filetest); } static void test_userdata_get(CuTest *tc) { apr_status_t rv; char *teststr; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); + + rv = apr_file_data_set(filetest, "This is a test", + "test", apr_pool_cleanup_null); + CuAssertIntEquals(tc, APR_SUCCESS, rv); rv = apr_file_data_get((void **)&teststr, "test", filetest); CuAssertIntEquals(tc, APR_SUCCESS, rv); CuAssertStrEquals(tc, "This is a test", teststr); + + apr_file_close(filetest); } static void test_userdata_getnokey(CuTest *tc) { apr_status_t rv; char *teststr; + apr_file_t *filetest = NULL; + + rv = apr_file_open(&filetest, FILENAME, + APR_WRITE, + APR_UREAD | APR_UWRITE | APR_GREAD, p); + CuAssertIntEquals(tc, APR_SUCCESS, rv); rv = apr_file_data_get((void **)&teststr, "nokey", filetest); CuAssertIntEquals(tc, APR_SUCCESS, rv); CuAssertPtrEquals(tc, NULL, teststr); + apr_file_close(filetest); } static void test_getc(CuTest *tc) |