// 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
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;
}
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;
}
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 \
--- /dev/null
+/* 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;
+}
#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
}
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;
}
{
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;
}
}
} // 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;
+}
#pragma once
+#include <vector>
+#include <iostream>
+
namespace libtest {
/**
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);
+
%{_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
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));