You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/07/29 14:33:33 UTC

svn commit: r1508018 - in /subversion/trunk/subversion/bindings/cxxhl: src/aprwrap/hash.hpp tests/test_aprwrap.cpp

Author: brane
Date: Mon Jul 29 12:33:33 2013
New Revision: 1508018

URL: http://svn.apache.org/r1508018
Log:
In C++HL, add a size() method to the APR hash wrappers, and convert the
hash tests to Gmock.

* subversion/bindings/cxxhl/src/aprwrap/hash.hpp (Hash::size): New method.

* subversion/bindings/cxxhl/tests/test_aprwrap.cpp (hashtest): Removed.
  (StringHash, FixedStringHash, Delete, Iterate): New test cases.

Modified:
    subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp
    subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp

Modified: subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp?rev=1508018&r1=1508017&r2=1508018&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp (original)
+++ subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp Mon Jul 29 12:33:33 2013
@@ -103,6 +103,7 @@ public:
 public:
   typedef Key::key_type key_type;
   typedef void* value_type;
+  typedef unsigned int size_type;
 
   /**
    * Create and proxy a new APR hash table in @a pool.
@@ -129,7 +130,18 @@ public:
   /**
    * Return the wrapped APR hash table.
    */
-  apr_hash_t* hash() const throw() { return m_hash; }
+  apr_hash_t* hash() const throw()
+    {
+      return m_hash;
+    }
+
+  /**
+   * Return the number of key-value pairs in the wrapped hash table.
+   */
+  size_type size() const throw()
+    {
+      return apr_hash_count(m_hash);
+    }
 
   /**
    * Set @a key = @a value in the wrapped hash table.
@@ -277,7 +289,18 @@ public:
   /**
    * @return The wrapped APR hash table.
    */
-  apr_hash_t* hash() const throw() { return inherited::hash(); }
+  apr_hash_t* hash() const throw()
+    {
+      return inherited::hash();
+    }
+
+  /**
+   * Return the number of key-value pairs in the wrapped hash table.
+   */
+  size_type size() const throw()
+    {
+      return inherited::size();
+    }
 
   /**
    * Set @a key = @a value in the wrapped hash table.

Modified: subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp?rev=1508018&r1=1508017&r2=1508018&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp (original)
+++ subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp Mon Jul 29 12:33:33 2013
@@ -358,58 +358,78 @@ TEST(ConstArrays, Iteration)
 // Hash tables
 //
 
-// TODO: Convert to gmock
+TEST(Hashes, StringHash)
+{
+  typedef APR::Hash<char, const char> H;
+
+  APR::Pool pool;
+  H hash(pool);
+  hash.set("aa", "a");
+  hash.set("bbb", "b");
+  hash.set("cccc", "c");
+
+  EXPECT_EQ(3, hash.size());
+  EXPECT_EQ("a", hash.get("aa"));
+  EXPECT_EQ("b", hash.get("bbb"));
+  EXPECT_EQ("c", hash.get("cccc"));
+}
 
-#include "../src/aprwrap.hpp"
-static void hashtest()
+TEST(Hashes, FixedStringHash)
 {
+  // The point of this test is to verify that the key-length parameter
+  // of the template actually limits the lenght of the keys.
   typedef APR::Hash<char, const char, 2> H;
-  typedef APR::Array<H::key_type> A;
-  typedef APR::ConstArray<A::value_type> CA;
 
   APR::Pool pool;
-  struct CB : public H::Iteration
-  {
-    A m_keys;
-
-    CB(const APR::Pool& array_pool)
-      : m_keys(array_pool)
-      {}
+  H hash(pool);
+  hash.set("aa&qux", "a");
+  hash.set("bb#foo", "b");
+  hash.set("cc@bar", "c");
+
+  EXPECT_EQ(3, hash.size());
+  EXPECT_EQ("a", hash.get("aa%foo"));
+  EXPECT_EQ("b", hash.get("bb*bar"));
+  EXPECT_EQ("c", hash.get("cc$qux"));
+}
 
-    bool operator() (const H::Key& key, H::value_type value)
-      {
-        m_keys.push(key.get());
-        return true;
-      }
-  } hash_callback(pool);
+TEST(Hashes, Delete)
+{
+  typedef APR::Hash<char, const char> H;
 
+  APR::Pool pool;
   H hash(pool);
+  hash.set("aa", "a");
+  hash.set("bbb", "b");
+  hash.set("cccc", "c");
+
+  hash.del("bbb");
+
+  EXPECT_EQ(2, hash.size());
+  EXPECT_EQ("a", hash.get("aa"));
+  EXPECT_EQ("c", hash.get("cccc"));
+}
 
-  hash.set("a", "aaa");
-  hash.set("c", "ccc");
-  hash.set("x", "bbb");
+TEST(Hashes, Iterate)
+{
+  typedef APR::Hash<char, const char> H;
 
-  hash.iterate(hash_callback, pool);
+  APR::Pool pool;
+  H hash(pool);
+  hash.set("aa", "a");
+  hash.set("bbb", "b");
+  hash.set("cccc", "c");
 
-  struct AB : public A::ConstIteration
+  struct C : public H::Iteration
   {
-    const H& m_hash;
+    H& m_hash;
+    explicit C(H& hashref) : m_hash(hashref) {}
 
-    AB(const H& hash_reference)
-      : m_hash(hash_reference)
-      {}
-
-    bool operator() (const A::value_type& value)
+    bool operator()(const H::Key& key, H::value_type value)
       {
-        std::cerr << value << " = " << m_hash.get(value) <<  std::endl;
+        EXPECT_EQ(value, m_hash.get(key));
         return true;
       }
-  } array_callback(hash);
-
-  CA keys(hash_callback.m_keys);
-  keys.iterate(array_callback);
+  } callback(hash);
 
-  std::cerr << keys[0] << " maps to " << hash_callback.m_keys[0] << std::endl;
-  std::cerr << keys.at(1) << " maps to " << hash_callback.m_keys.at(1) << std::endl;
-  std::cerr << keys[2] << " maps to " << hash_callback.m_keys[2] << std::endl;
+  hash.iterate(callback, pool);
 }