Update libtest/fedora/lion fixes
[awesomized/libmemcached] / libtest / comparison.hpp
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * libtest
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #pragma once
23
24 #include <typeinfo>
25 #include <libtest/strerror.h>
26 #include <libmemcached/memcached.h>
27
28 namespace libtest {
29
30 template <class T_comparable, class T_hint>
31 bool _compare_true_hint(const char *file, int line, const char *func, T_comparable __expected, const char *assertation_label, T_hint __hint)
32 {
33 if (__expected == false)
34 {
35 libtest::stream::make_cerr(file, line, func) << "Assertation \"" << assertation_label << "\" failed, hint: " << __hint;
36 return false;
37 }
38
39 return true;
40 }
41
42 template <class T_comparable>
43 bool _compare(const char *file, int line, const char *func, T_comparable __expected, T_comparable __actual)
44 {
45 if (__expected != __actual)
46 {
47 if (typeid(__expected) == typeid(memcached_return_t))
48 {
49 libtest::stream::make_cerr(file, line, func) << "Expected \""
50 << memcached_strerror(NULL, memcached_return_t(__expected))
51 << "\" got \""
52 << memcached_strerror(NULL, memcached_return_t(__actual)) << "\"";
53 }
54 else if (typeid(__expected) == typeid(test_return_t))
55 {
56 libtest::stream::make_cerr(file, line, func) << "Expected \""
57 << test_strerror(test_return_t(__expected))
58 << "\" got \""
59 << test_strerror(test_return_t(__actual)) << "\"";
60 }
61 else
62 {
63 libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";
64 }
65 return false;
66 }
67
68 return true;
69 }
70
71 template <class T_comparable>
72 bool _compare_zero(const char *file, int line, const char *func, T_comparable __actual)
73 {
74 if (T_comparable(0) != __actual)
75 {
76 libtest::stream::make_cerr(file, line, func) << "Expected 0 got \"" << __actual << "\"";
77 return false;
78 }
79
80 return true;
81 }
82
83 template <class T_comparable, class T_hint>
84 bool _compare_hint(const char *file, int line, const char *func, T_comparable __expected, T_comparable __actual, T_hint __hint)
85 {
86 if (__expected != __actual)
87 {
88 libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\" Additionally: \"" << __hint << "\"";
89
90 return false;
91 }
92
93 return true;
94 }
95
96 } // namespace libtest