apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1541666 - /apr/apr/trunk/test/testmmap.c
Date Wed, 13 Nov 2013 19:25:13 GMT
Author: trawick
Date: Wed Nov 13 19:25:12 2013
New Revision: 1541666

URL: http://svn.apache.org/r1541666
Log:
Read the contents of the test datafile instead of
hard-coding it in the source and relying on the line
ending in the datafile to be the same as APR_EOL_STR.
(Or, allow building and testing on Windows and Unix
using the same release tarball.)

Modified:
    apr/apr/trunk/test/testmmap.c

Modified: apr/apr/trunk/test/testmmap.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testmmap.c?rev=1541666&r1=1541665&r2=1541666&view=diff
==============================================================================
--- apr/apr/trunk/test/testmmap.c (original)
+++ apr/apr/trunk/test/testmmap.c Wed Nov 13 19:25:12 2013
@@ -26,7 +26,6 @@
  * length on a platform?
  */
 #define PATH_LEN 255
-#define TEST_STRING "This is the MMAP data file."APR_EOL_STR
 
 #if !APR_HAS_MMAP
 static void not_implemented(abts_case *tc, void *data)
@@ -36,6 +35,7 @@ static void not_implemented(abts_case *t
 
 #else
 
+static char test_string[256]; /* read from the datafile */
 static apr_mmap_t *themmap = NULL;
 static apr_file_t *thefile = NULL;
 static char *file1;
@@ -69,6 +69,17 @@ static void test_file_close(abts_case *t
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 }
    
+static void read_expected_contents(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_size_t nbytes = sizeof(test_string) - 1;
+
+    rv = apr_file_read(thefile, test_string, &nbytes);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+    test_string[nbytes] = '\0';
+    thisfsize = strlen(test_string);
+}
+
 static void test_file_open(abts_case *tc, void *data)
 {
     apr_status_t rv;
@@ -105,7 +116,7 @@ static void test_mmap_contents(abts_case
     ABTS_SIZE_EQUAL(tc, thisfsize, themmap->size);
 
     /* Must use nEquals since the string is not guaranteed to be NULL terminated */
-    ABTS_STR_NEQUAL(tc, themmap->mm, TEST_STRING, thisfsize);
+    ABTS_STR_NEQUAL(tc, themmap->mm, test_string, thisfsize);
 }
 
 static void test_mmap_delete(abts_case *tc, void *data)
@@ -127,7 +138,7 @@ static void test_mmap_offset(abts_case *
 
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     /* Must use nEquals since the string is not guaranteed to be NULL terminated */
-    ABTS_STR_NEQUAL(tc, addr, TEST_STRING + 5, thisfsize-5);
+    ABTS_STR_NEQUAL(tc, addr, test_string + 5, thisfsize-5);
 }
 #endif
 
@@ -136,10 +147,9 @@ abts_suite *testmmap(abts_suite *suite)
     suite = ADD_SUITE(suite)
 
 #if APR_HAS_MMAP    
-    thisfsize = strlen(TEST_STRING);
-
     abts_run_test(suite, create_filename, NULL);
     abts_run_test(suite, test_file_open, NULL);
+    abts_run_test(suite, read_expected_contents, NULL);
     abts_run_test(suite, test_get_filesize, NULL);
     abts_run_test(suite, test_mmap_create, NULL);
     abts_run_test(suite, test_mmap_contents, NULL);



Mime
View raw message