Merge in sasl update
[m6w6/libmemcached] / libtest / comparison.hpp
index 8656e49935447ba2a5e20d120a1ebe6a5eb286fe..5c687fc3a6500b5d153b00802b73ca51934f7cbc 100644 (file)
 
 #include <typeinfo>
 #include <libtest/strerror.h>
+
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
 #include <libmemcached/memcached.h>
+#endif
+
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+#include <libgearman/gearman.h>
+#endif
 
 namespace libtest {
 
@@ -40,24 +47,39 @@ bool _compare_true_hint(const char *file, int line, const char *func, T_comparab
 }
 
 template <class T_comparable>
-bool _compare(const char *file, int line, const char *func, T_comparable __expected, T_comparable __actual)
+bool _compare(const char *file, int line, const char *func, const T_comparable __expected, const T_comparable __actual)
 {
   if (__expected != __actual)
   {
-    if (typeid(__expected) == typeid(memcached_return_t))
+    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)) << "\"";
     }
-    else if (typeid(__expected) == typeid(test_return_t))
+#endif
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+    else if (typeid(__expected) == typeid(gearman_return_t))
     {
       libtest::stream::make_cerr(file, line, func) << "Expected \"" 
-        << test_strerror(test_return_t(__expected)) 
+        << gearman_strerror(gearman_return_t(__expected)) 
         << "\" got \"" 
-        << test_strerror(test_return_t(__actual)) << "\"";
+        << gearman_strerror(gearman_return_t(__actual)) << "\"";
     }
+#endif
     else
     {
       libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";