Streamline how we are handling the printing of error types.
authorBrian Aker <brian@tangent.org>
Tue, 11 Oct 2011 20:04:15 +0000 (13:04 -0700)
committerBrian Aker <brian@tangent.org>
Tue, 11 Oct 2011 20:04:15 +0000 (13:04 -0700)
libmemcached-1.0/memcached.hpp
libmemcachedutil-1.0/include.am
libmemcachedutil-1.0/ostream.hpp [new file with mode: 0644]
libtest/comparison.hpp
libtest/strerror.cc
libtest/strerror.h
support/libmemcached.spec.in
tests/plus.cpp

index 66d62524eeb0cc9455a398cc50c1ef6489ba9c5a..33dcdc1fb171527adc4cabcfb5a9eefdf67ed3f8 100644 (file)
@@ -215,7 +215,7 @@ public:
 
       // Actual value, null terminated
       ret_val.reserve(memcached_result_length(result) +1);
-      ret_val.assign(memcached_result_value(result), 
+      ret_val.assign(memcached_result_value(result),
                      memcached_result_value(result) +memcached_result_length(result));
 
       // Misc
@@ -255,7 +255,7 @@ public:
     if (value != NULL && ret_val.empty())
     {
       ret_val.reserve(value_length);
-      ret_val.assign(value, value + value_length);
+      ret_val.assign(value, value +value_length);
       free(value);
       return true;
     }
@@ -290,7 +290,7 @@ public:
     if (value)
     {
       ret_val.reserve(value_length);
-      ret_val.assign(value, value + value_length);
+      ret_val.assign(value, value +value_length);
       free(value);
       return true;
     }
index c5576058e4fc4522f8325d1a6e0940dc8b916184..39a159377dea1658e447468abc9d4b726cb5fdf6 100644 (file)
@@ -5,6 +5,7 @@
 
 nobase_include_HEADERS+= \
                         libmemcachedutil-1.0/flush.h \
+                        libmemcachedutil-1.0/ostream.hpp \
                         libmemcachedutil-1.0/pid.h \
                         libmemcachedutil-1.0/ping.h \
                         libmemcachedutil-1.0/pool.h \
diff --git a/libmemcachedutil-1.0/ostream.hpp b/libmemcachedutil-1.0/ostream.hpp
new file mode 100644 (file)
index 0000000..4113414
--- /dev/null
@@ -0,0 +1,43 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ *  Libmemcached library
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+static inline std::ostream& operator<<(std::ostream& output, const enum memcached_return_t &arg)
+{
+  output << memcached_strerror(NULL, arg);
+  return output;
+}
index eb240d47f9195a16e0a88383a3e87416130f96de..33cfa5a5b095a77ea43f969b6ceedbd87ba51240 100644 (file)
@@ -24,7 +24,8 @@
 #include <typeinfo>
 
 #if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
-#include <libmemcached/memcached.h>
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcachedutil-1.0/ostream.hpp>
 #endif
 
 #if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
@@ -46,43 +47,11 @@ bool _compare_truth_hint(const char *file, int line, const char *func, T_compara
 }
 
 template <class T1_comparable, class T2_comparable>
-bool _compare(const char *file, int line, const char *func, const T1_comparable __expected, const T2_comparable __actual)
+bool _compare(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual)
 {
   if (__expected != __actual)
   {
-    if (typeid(__expected) == typeid(test_return_t))
-    {
-      const char *expected_str= test_strerror(test_return_t(__expected));
-      const char *got_str= test_strerror(test_return_t(__actual));
-
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << expected_str
-        << "\" got \"" 
-        << got_str
-        << "\"";
-    }
-#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
-    else if (typeid(__expected) == typeid(memcached_return_t))
-    {
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << memcached_strerror(NULL, memcached_return_t(__expected)) 
-        << "\" got \"" 
-        << memcached_strerror(NULL, memcached_return_t(__actual)) << "\"";
-    }
-#endif
-#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
-    else if (typeid(__expected) == typeid(gearman_return_t))
-    {
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << gearman_strerror(gearman_return_t(__expected)) 
-        << "\" got \"" 
-        << gearman_strerror(gearman_return_t(__actual)) << "\"";
-    }
-#endif
-    else
-    {
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";
-    }
+    libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";
     return false;
   }
 
@@ -118,43 +87,8 @@ bool _compare_hint(const char *file, int line, const char *func, T1_comparable _
 {
   if (__expected != __actual)
   {
-    if (typeid(__expected) == typeid(test_return_t))
-    {
-      const char *expected_str= test_strerror(test_return_t(__expected));
-      const char *got_str= test_strerror(test_return_t(__actual));
-
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << expected_str
-        << "\" got \"" 
-        << got_str
-        << "\""
-        << " Additionally: \"" << __hint << "\"";
-    }
-#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
-    else if (typeid(__expected) == typeid(memcached_return_t))
-    {
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << memcached_strerror(NULL, memcached_return_t(__expected)) 
-        << "\" got \"" 
-        << memcached_strerror(NULL, memcached_return_t(__actual)) << "\""
-        << " Additionally: \"" << __hint << "\"";
-    }
-#endif
-#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
-    else if (typeid(__expected) == typeid(gearman_return_t))
-    {
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << gearman_strerror(gearman_return_t(__expected)) 
-        << "\" got \"" 
-        << gearman_strerror(gearman_return_t(__actual)) << "\""
-        << " Additionally: \"" << __hint << "\"";
-    }
-#endif
-    else
-    {
-      libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\""
-        << " Additionally: \"" << __hint << "\"";
-    }
+    libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"" << " Additionally: \"" << __hint << "\"";
+
     return false;
   }
 
index 74440f51ef3765307b65b6283a1e259d7756bb1d..e4f0cf5089bc6e6af3f860b1dd5a14586c61a002 100644 (file)
@@ -46,3 +46,16 @@ const char *test_strerror(test_return_t code)
 }
 
 } // namespace libtest
+
+
+std::ostream& operator<<(std::ostream& output, const enum test_return_t &arg)
+{
+  output << libtest::test_strerror(arg);
+  return output;
+}
+
+std::ostream& operator<<(std::ostream& output, const std::vector<char> &arg)
+{
+  output << "std::vector<char>:" << arg.size(); 
+  return output;
+}
index 861c84b60c9e22b608cab7526233da2bad1a2a24..7dc3cf5ecc97e755b0db9ba52a459797778dd92d 100644 (file)
@@ -21,6 +21,9 @@
 
 #pragma once
 
+#include <vector>
+#include <iostream>
+
 namespace libtest {
 
 /**
@@ -30,3 +33,7 @@ LIBTEST_API
 const char *test_strerror(test_return_t code);
 
 } // namespace libtest
+
+std::ostream& operator<<(std::ostream& output, const enum test_return_t &arg);
+std::ostream& operator<<(std::ostream& output, const std::vector<char> &arg);
+
index 449ee0b30732a1f0f571be2bd96a5606c80cff9e..e610adaa1d1a4e7c901ba78ffef5c4a7a04b9e4b 100644 (file)
@@ -134,6 +134,7 @@ you will need to install %{name}-devel.
 %{_includedir}/libmemcachedutil-1.0/flush.h
 %{_includedir}/libmemcachedutil-1.0/pid.h
 %{_includedir}/libmemcachedutil-1.0/ping.h
+%{_includedir}/libmemcachedutil-1.0/ostream.hpp
 %{_includedir}/libmemcachedutil-1.0/pool.h
 %{_includedir}/libmemcachedutil-1.0/version.h
 
index e020cdd988e2bdddf71c6d6ba52cbc67319af265..7de8164f7db8868df15b8a6a04361db52a2dc84f 100644 (file)
@@ -86,6 +86,7 @@ static test_return_t basic_test(memcached_st *memc)
   test_true(foo.set("mine", value, 0, 0));
   test_true(foo.get("mine", test_value));
 
+  test_compare(test_value.size(), value.size());
   test_memcmp(&test_value[0], &value[0], test_value.size());
   test_false(foo.set("", value, 0, 0));