You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2013/11/23 02:19:14 UTC

svn commit: r1544729 - /subversion/trunk/subversion/tests/libsvn_subr/io-test.c

Author: stefan2
Date: Sat Nov 23 01:19:14 2013
New Revision: 1544729

URL: http://svn.apache.org/r1544729
Log:
Make I/O tests use separate working sets.

Instead of tracking current state to globally shared test descriptions,
we use them only as a template and provide each test with a separate copy.
Also, store files in test-specific folders.

* subversion/tests/libsvn_subr/io-test.c
  (TEST_DIR): rename to ...
  (TEST_DIR_PREFIX): ... this
  (test_file_definitions): rename to ...
  (test_file_definitions_template): ... this
  (create_test_file): write to a test-specific folder
  (create_comparison_candidates): provide a copy of the test data and
                                  create files in test-specific folders
  (test_two_file_size_comparison,
   test_two_file_content_comparison,
   test_three_file_size_comparison, 
   test_three_file_content_comparison): update callers

Modified:
    subversion/trunk/subversion/tests/libsvn_subr/io-test.c

Modified: subversion/trunk/subversion/tests/libsvn_subr/io-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/io-test.c?rev=1544729&r1=1544728&r2=1544729&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/io-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/io-test.c Sat Nov 23 01:19:14 2013
@@ -39,7 +39,7 @@
 
 /* Helpers to create the test data directory. */
 
-#define TEST_DIR "io-test-temp"
+#define TEST_DIR_PREFIX "io-test-temp"
 
 /* The definition for the test data files. */
 struct test_file_definition_t
@@ -66,7 +66,7 @@ struct test_file_definition_t
     char* created_path;
   };
 
-struct test_file_definition_t test_file_definitions[] =
+struct test_file_definition_t test_file_definitions_template[] =
   {
     {"empty",                 "",      0},
     {"single_a",              "a",     1},
@@ -121,6 +121,7 @@ struct test_file_definition_t test_file_
 
 static svn_error_t *
 create_test_file(struct test_file_definition_t* definition,
+                 const char *testname,
                  apr_pool_t *pool,
                  apr_pool_t *scratch_pool)
 {
@@ -129,6 +130,7 @@ create_test_file(struct test_file_defini
   apr_off_t midpos = definition->size / 2;
   svn_error_t *err = NULL;
   int i;
+  const char *test_dir = apr_pstrcat(pool, TEST_DIR_PREFIX, testname, NULL);
 
   if (definition->size < 5)
     SVN_ERR_ASSERT(strlen(definition->data) >= (apr_size_t)definition->size);
@@ -136,9 +138,9 @@ create_test_file(struct test_file_defini
     SVN_ERR_ASSERT(strlen(definition->data) >= 5);
 
 
-  definition->created_path = svn_dirent_join(TEST_DIR,
-                                  definition->name,
-                                  pool);
+  definition->created_path = svn_dirent_join(test_dir,
+                                             definition->name,
+                                             pool);
 
   SVN_ERR(svn_io_file_open(&file_h,
                            definition->created_path,
@@ -176,37 +178,47 @@ create_test_file(struct test_file_defini
 
 /* Function to prepare the whole set of on-disk files to be compared. */
 static svn_error_t *
-create_comparison_candidates(apr_pool_t *scratch_pool)
+create_comparison_candidates(struct test_file_definition_t **definitions,
+                             const char *testname,
+                             apr_pool_t *pool)
 {
   svn_node_kind_t kind;
-  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  apr_pool_t *iterpool = svn_pool_create(pool);
   struct test_file_definition_t *candidate;
   svn_error_t *err = SVN_NO_ERROR;
+  apr_size_t count = 0;
+  const char *test_dir = apr_pstrcat(pool, TEST_DIR_PREFIX,
+                                     testname, NULL);
 
   /* If there's already a directory named io-test-temp, delete it.
      Doing things this way means that repositories stick around after
      a failure for postmortem analysis, but also that tests can be
      re-run without cleaning out the repositories created by prior
      runs.  */
-  SVN_ERR(svn_io_check_path(TEST_DIR, &kind, scratch_pool));
+  SVN_ERR(svn_io_check_path(test_dir, &kind, pool));
 
   if (kind == svn_node_dir)
-    SVN_ERR(svn_io_remove_dir2(TEST_DIR, TRUE, NULL, NULL, scratch_pool));
+    SVN_ERR(svn_io_remove_dir2(test_dir, TRUE, NULL, NULL, pool));
   else if (kind != svn_node_none)
     return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
                              "There is already a file named '%s'",
-                             TEST_DIR);
+                             test_dir);
 
-  SVN_ERR(svn_io_dir_make(TEST_DIR, APR_OS_DEFAULT, scratch_pool));
+  SVN_ERR(svn_io_dir_make(test_dir, APR_OS_DEFAULT, pool));
 
-  svn_test_add_dir_cleanup(TEST_DIR);
+  svn_test_add_dir_cleanup(test_dir);
 
-  for (candidate = test_file_definitions;
+  for (candidate = test_file_definitions_template;
        candidate->name != NULL;
        candidate += 1)
+    count++;
+
+  *definitions = apr_pmemdup(pool, test_file_definitions_template,
+                             (count + 1) * sizeof(**definitions));
+  for (candidate = *definitions; candidate->name != NULL; candidate += 1)
     {
       svn_pool_clear(iterpool);
-      err = create_test_file(candidate, scratch_pool, iterpool);
+      err = create_test_file(candidate, testname, pool, iterpool);
       if (err)
         break;
     }
@@ -229,8 +241,11 @@ test_two_file_size_comparison(apr_pool_t
   svn_error_t *err = SVN_NO_ERROR;
   svn_error_t *cmp_err;
   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  struct test_file_definition_t *test_file_definitions;
 
-  SVN_ERR(create_comparison_candidates(scratch_pool));
+  SVN_ERR(create_comparison_candidates(&test_file_definitions,
+                                       "test_two_file_size_comparison",
+                                       scratch_pool));
 
   for (outer = test_file_definitions; outer->name != NULL; outer += 1)
     {
@@ -280,8 +295,11 @@ test_two_file_content_comparison(apr_poo
   svn_error_t *err = SVN_NO_ERROR;
   svn_error_t *cmp_err;
   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  struct test_file_definition_t *test_file_definitions;
 
-  SVN_ERR(create_comparison_candidates(scratch_pool));
+  SVN_ERR(create_comparison_candidates(&test_file_definitions,
+                                       "test_two_file_content_comparison",
+                                       scratch_pool));
 
   for (outer = test_file_definitions; outer->name != NULL; outer += 1)
     {
@@ -333,8 +351,11 @@ test_three_file_size_comparison(apr_pool
   svn_error_t *err = SVN_NO_ERROR;
   svn_error_t *cmp_err;
   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  struct test_file_definition_t *test_file_definitions;
 
-  SVN_ERR(create_comparison_candidates(scratch_pool));
+  SVN_ERR(create_comparison_candidates(&test_file_definitions,
+                                       "test_three_file_size_comparison",
+                                       scratch_pool));
 
   for (outer = test_file_definitions; outer->name != NULL; outer += 1)
     {
@@ -413,8 +434,11 @@ test_three_file_content_comparison(apr_p
   svn_error_t *err = SVN_NO_ERROR;
   svn_error_t *cmp_err;
   apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  struct test_file_definition_t *test_file_definitions;
 
-  SVN_ERR(create_comparison_candidates(scratch_pool));
+  SVN_ERR(create_comparison_candidates(&test_file_definitions,
+                                       "test_three_file_content_comparison",
+                                       scratch_pool));
 
   for (outer = test_file_definitions; outer->name != NULL; outer += 1)
     {