You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2011/08/03 17:00:48 UTC

svn commit: r1153527 - in /subversion/trunk/subversion/tests: libsvn_wc/op-depth-test.c svn_test.h svn_test_fs.c svn_test_fs.h

Author: julianfoad
Date: Wed Aug  3 15:00:47 2011
New Revision: 1153527

URL: http://svn.apache.org/viewvc?rev=1153527&view=rev
Log:
Make the 'greek tree' structure available throughout the C test suite as a
simple data structure, to encourage writing functions in a style that can be
re-used on other tree structures. Re-write some existing functions that way.

* subversion/tests/svn_test_fs.c
  (svn_test__greek_tree_nodes): New array.
  (svn_test__check_greek_tree): Rework to use that array.
  (svn_test__create_greek_tree_at): Rework to use that array. Remove the doc
    string here, moving the useful parts of it into its public doc string in
    the header file.

* subversion/tests/svn_test_fs.h
  (svn_test__create_greek_tree_at): Adjust doc string as mentioned above.
  (svn_test__tree_entry_t, svn_test__create_repos): Move from here ...

* subversion/tests/svn_test.h
  (svn_test__tree_entry_t, svn_test__create_repos): ... to here.
  (svn_test__greek_tree_nodes): New array.

* subversion/tests/libsvn_wc/op-depth-test.c
  (add_and_commit_greek_tree): Re-work to use the 'greek tree' data.

Modified:
    subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c
    subversion/trunk/subversion/tests/svn_test.h
    subversion/trunk/subversion/tests/svn_test_fs.c
    subversion/trunk/subversion/tests/svn_test_fs.h

Modified: subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c?rev=1153527&r1=1153526&r2=1153527&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c Wed Aug  3 15:00:47 2011
@@ -268,41 +268,19 @@ wc_move(svn_test__sandbox_t *b, const ch
 static svn_error_t *
 add_and_commit_greek_tree(svn_test__sandbox_t *b)
 {
-  const char *greek_tree_dirs[8] =
-  {
-    "A",
-    "A/B",
-    "A/B/E",
-    "A/B/F",
-    "A/C",
-    "A/D",
-    "A/D/G",
-    "A/D/H"
-  };
-  const char *greek_tree_files[12][2] =
-  {
-    { "iota",         "This is the file 'iota'.\n" },
-    { "A/mu",         "This is the file 'mu'.\n" },
-    { "A/B/lambda",   "This is the file 'lambda'.\n" },
-    { "A/B/E/alpha",  "This is the file 'alpha'.\n" },
-    { "A/B/E/beta",   "This is the file 'beta'.\n" },
-    { "A/D/gamma",    "This is the file 'gamma'.\n" },
-    { "A/D/G/pi",     "This is the file 'pi'.\n" },
-    { "A/D/G/rho",    "This is the file 'rho'.\n" },
-    { "A/D/G/tau",    "This is the file 'tau'.\n" },
-    { "A/D/H/chi",    "This is the file 'chi'.\n" },
-    { "A/D/H/psi",    "This is the file 'psi'.\n" },
-    { "A/D/H/omega",  "This is the file 'omega'.\n" }
-  };
-  int i;
-
-  for (i = 0; i < 8; i++)
-    SVN_ERR(wc_mkdir(b, greek_tree_dirs[i]));
+  const struct svn_test__tree_entry_t *node;
 
-  for (i = 0; i < 12; i++)
+  for (node = svn_test__greek_tree_nodes; node->path; node++)
     {
-      file_write(b, greek_tree_files[i][0], greek_tree_files[i][1]);
-      SVN_ERR(wc_add(b, greek_tree_files[i][0]));
+      if (node->contents)
+        {
+          file_write(b, node->path, node->contents);
+          SVN_ERR(wc_add(b, node->path));
+        }
+      else
+        {
+          SVN_ERR(wc_mkdir(b, node->path));
+        }
     }
 
   SVN_ERR(wc_commit(b, ""));

Modified: subversion/trunk/subversion/tests/svn_test.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test.h?rev=1153527&r1=1153526&r2=1153527&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/svn_test.h (original)
+++ subversion/trunk/subversion/tests/svn_test.h Wed Aug  3 15:00:47 2011
@@ -177,6 +177,27 @@ apr_uint32_t svn_test_rand(apr_uint32_t 
 void svn_test_add_dir_cleanup(const char *path);
 
 
+/* A simple representation for a tree node. */
+typedef struct svn_test__tree_entry_t
+{
+  const char *path;     /* relpath of this node */
+  const char *contents; /* text contents, or NULL for a directory */
+}
+svn_test__tree_entry_t;
+
+/* Wrapper for an array of svn_test__tree_entry_t's. */
+typedef struct svn_test__tree_t
+{
+  svn_test__tree_entry_t *entries;
+  int num_entries;
+}
+svn_test__tree_t;
+
+
+/* The standard Greek tree, terminated by a node with path=NULL. */
+const svn_test__tree_entry_t svn_test__greek_tree_nodes[21];
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: subversion/trunk/subversion/tests/svn_test_fs.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test_fs.c?rev=1153527&r1=1153526&r2=1153527&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/svn_test_fs.c (original)
+++ subversion/trunk/subversion/tests/svn_test_fs.c Wed Aug  3 15:00:47 2011
@@ -572,6 +572,30 @@ svn_test__txn_script_exec(svn_fs_root_t 
 }
 
 
+const struct svn_test__tree_entry_t svn_test__greek_tree_nodes[21] = {
+  { "iota",         "This is the file 'iota'.\n" },
+  { "A",            NULL },
+  { "A/mu",         "This is the file 'mu'.\n" },
+  { "A/B",          NULL },
+  { "A/B/lambda",   "This is the file 'lambda'.\n" },
+  { "A/B/E",        NULL },
+  { "A/B/E/alpha",  "This is the file 'alpha'.\n" },
+  { "A/B/E/beta",   "This is the file 'beta'.\n" },
+  { "A/B/F",        NULL },
+  { "A/C",          NULL },
+  { "A/D",          NULL },
+  { "A/D/gamma",    "This is the file 'gamma'.\n" },
+  { "A/D/G",        NULL },
+  { "A/D/G/pi",     "This is the file 'pi'.\n" },
+  { "A/D/G/rho",    "This is the file 'rho'.\n" },
+  { "A/D/G/tau",    "This is the file 'tau'.\n" },
+  { "A/D/H",        NULL },
+  { "A/D/H/chi",    "This is the file 'chi'.\n" },
+  { "A/D/H/psi",    "This is the file 'psi'.\n" },
+  { "A/D/H/omega",  "This is the file 'omega'.\n" },
+  { NULL,           NULL },
+};
+
 svn_error_t *
 svn_test__check_greek_tree(svn_fs_root_t *root,
                            apr_pool_t *pool)
@@ -579,115 +603,47 @@ svn_test__check_greek_tree(svn_fs_root_t
   svn_stream_t *rstream;
   svn_stringbuf_t *rstring;
   svn_stringbuf_t *content;
-  int i;
-
-  const char *file_contents[12][2] =
-  {
-    { "iota", "This is the file 'iota'.\n" },
-    { "A/mu", "This is the file 'mu'.\n" },
-    { "A/B/lambda", "This is the file 'lambda'.\n" },
-    { "A/B/E/alpha", "This is the file 'alpha'.\n" },
-    { "A/B/E/beta", "This is the file 'beta'.\n" },
-    { "A/D/gamma", "This is the file 'gamma'.\n" },
-    { "A/D/G/pi", "This is the file 'pi'.\n" },
-    { "A/D/G/rho", "This is the file 'rho'.\n" },
-    { "A/D/G/tau", "This is the file 'tau'.\n" },
-    { "A/D/H/chi", "This is the file 'chi'.\n" },
-    { "A/D/H/psi", "This is the file 'psi'.\n" },
-    { "A/D/H/omega", "This is the file 'omega'.\n" }
-  };
+  const struct svn_test__tree_entry_t *node;
 
   /* Loop through the list of files, checking for matching content. */
-  for (i = 0; i < 12; i++)
+  for (node = svn_test__greek_tree_nodes; node->path; node++)
     {
-      SVN_ERR(svn_fs_file_contents(&rstream, root,
-                                   file_contents[i][0], pool));
-      SVN_ERR(svn_test__stream_to_string(&rstring, rstream, pool));
-      content = svn_stringbuf_create(file_contents[i][1], pool);
-      if (! svn_stringbuf_compare(rstring, content))
-        return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,
-                                 "data read != data written in file '%s'.",
-                                 file_contents[i][0]);
+      if (node->contents)
+        {
+          SVN_ERR(svn_fs_file_contents(&rstream, root, node->path, pool));
+          SVN_ERR(svn_test__stream_to_string(&rstring, rstream, pool));
+          content = svn_stringbuf_create(node->contents, pool);
+          if (! svn_stringbuf_compare(rstring, content))
+            return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,
+                                     "data read != data written in file '%s'.",
+                                     node->path);
+        }
     }
   return SVN_NO_ERROR;
 }
 
-/**
- * Loads the greek tree in a directory at ROOT_DIR under transaction TXN_ROOT.
- * ROOT_DIR should be created by the caller.
- *
- * Note: this function will not commit the transaction.
- */
 svn_error_t *
 svn_test__create_greek_tree_at(svn_fs_root_t *txn_root,
                                const char *root_dir,
                                apr_pool_t *pool)
 {
-  char *iota =     svn_relpath_join(root_dir, "iota", pool);
-  char *A =        svn_relpath_join(root_dir, "A", pool);
-  char *Amu =      svn_relpath_join(root_dir, "A/mu", pool);
-  char *AB =       svn_relpath_join(root_dir, "A/B", pool);
-  char *ABlambda = svn_relpath_join(root_dir, "A/B/lambda", pool);
-  char *ABE =      svn_relpath_join(root_dir, "A/B/E", pool);
-  char *ABEalpha = svn_relpath_join(root_dir, "A/B/E/alpha", pool);
-  char *ABEbeta =  svn_relpath_join(root_dir, "A/B/E/beta", pool);
-  char *ABF =      svn_relpath_join(root_dir, "A/B/F", pool);
-  char *AC =       svn_relpath_join(root_dir, "A/C", pool);
-  char *AD =       svn_relpath_join(root_dir, "A/D", pool);
-  char *ADgamma =  svn_relpath_join(root_dir, "A/D/gamma", pool);
-  char *ADG =      svn_relpath_join(root_dir, "A/D/G", pool);
-  char *ADGpi =    svn_relpath_join(root_dir, "A/D/G/pi", pool);
-  char *ADGrho =   svn_relpath_join(root_dir, "A/D/G/rho", pool);
-  char *ADGtau =   svn_relpath_join(root_dir, "A/D/G/tau", pool);
-  char *ADH =      svn_relpath_join(root_dir, "A/D/H", pool);
-  char *ADHchi =   svn_relpath_join(root_dir, "A/D/H/chi", pool);
-  char *ADHpsi =   svn_relpath_join(root_dir, "A/D/H/psi", pool);
-  char *ADHomega = svn_relpath_join(root_dir, "A/D/H/omega", pool);
-
-  SVN_ERR(svn_fs_make_file(txn_root, iota, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, iota, "This is the file 'iota'.\n", pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, A, pool));
-  SVN_ERR(svn_fs_make_file(txn_root, Amu, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, Amu, "This is the file 'mu'.\n", pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, AB, pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ABlambda, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ABlambda, "This is the file 'lambda'.\n", pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, ABE, pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ABEalpha, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ABEalpha, "This is the file 'alpha'.\n", pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ABEbeta, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ABEbeta, "This is the file 'beta'.\n", pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, ABF, pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, AC, pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, AD, pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADgamma, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADgamma, "This is the file 'gamma'.\n", pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, ADG, pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADGpi, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADGpi, "This is the file 'pi'.\n", pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADGrho, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADGrho, "This is the file 'rho'.\n", pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADGtau, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADGtau, "This is the file 'tau'.\n", pool));
-  SVN_ERR(svn_fs_make_dir  (txn_root, ADH, pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADHchi, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADHchi, "This is the file 'chi'.\n", pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADHpsi, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADHpsi, "This is the file 'psi'.\n", pool));
-  SVN_ERR(svn_fs_make_file(txn_root, ADHomega, pool));
-  SVN_ERR(svn_test__set_file_contents
-          (txn_root, ADHomega, "This is the file 'omega'.\n", pool));
+  const struct svn_test__tree_entry_t *node;
+
+  for (node = svn_test__greek_tree_nodes; node->path; node++)
+    {
+      const char *path = svn_relpath_join(root_dir, node->path, pool);
+
+      if (node->contents)
+        {
+          SVN_ERR(svn_fs_make_file(txn_root, path, pool));
+          SVN_ERR(svn_test__set_file_contents(txn_root, path, node->contents,
+                                              pool));
+        }
+      else
+        {
+          SVN_ERR(svn_fs_make_dir(txn_root, path, pool));
+        }
+    }
   return SVN_NO_ERROR;
 }
 

Modified: subversion/trunk/subversion/tests/svn_test_fs.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/svn_test_fs.h?rev=1153527&r1=1153526&r2=1153527&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/svn_test_fs.h (original)
+++ subversion/trunk/subversion/tests/svn_test_fs.h Wed Aug  3 15:00:47 2011
@@ -102,25 +102,6 @@ svn_test__get_file_contents(svn_fs_root_
 
 /* The Helper Functions to End All Helper Functions */
 
-/* Structure used for testing integrity of the filesystem's revision
-   using validate_tree(). */
-typedef struct svn_test__tree_entry_t
-{
-  const char *path;     /* full path of this node */
-  const char *contents; /* text contents (NULL for directories) */
-}
-svn_test__tree_entry_t;
-
-
-/* Wrapper for an array of the above svn_test__tree_entry_t's.  */
-typedef struct svn_test__tree_t
-{
-  svn_test__tree_entry_t *entries;
-  int num_entries;
-}
-svn_test__tree_t;
-
-
 /* Given a transaction or revision root (ROOT), check to see if the
    tree that grows from that root has all the path entries, and only
    those entries, passed in the array ENTRIES (which is an array of
@@ -168,7 +149,10 @@ svn_error_t *
 svn_test__create_greek_tree(svn_fs_root_t *txn_root,
                             apr_pool_t *pool);
 
-/* Create the Greek Tree under TXN_ROOT at dir ROOT_DIR.  */
+/* Create the Greek Tree under TXN_ROOT at dir ROOT_DIR.
+ * ROOT_DIR should be created by the caller.
+ *
+ * Note: this function will not commit the transaction.  */
 svn_error_t *
 svn_test__create_greek_tree_at(svn_fs_root_t *txn_root,
                                const char *root_dir,