/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/tests/test_tools.h

00001 #ifndef TEST_TOOLS_H
00002 #define TEST_TOOLS_H
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  */
00021 
00022 #include <limits.h>             // Include before boost/test headers.
00023 
00024 #include <boost/test/test_tools.hpp>
00025 #include <boost/assign/list_of.hpp>
00026 #include <boost/regex.hpp>
00027 #include <boost/assign/list_of.hpp>
00028 #include <vector>
00029 #include <ostream>
00030 
00031 // Print a sequence
00032 template <class T> std::ostream& seqPrint(std::ostream& o, const T& seq) {
00033     std::copy(seq.begin(), seq.end(), std::ostream_iterator<typename T::value_type>(o, " "));
00034     return o;
00035 }
00036 
00037 // Compare sequences 
00038 template <class T, class U>
00039 bool seqEqual(const T& a, const U& b) {
00040     typename T::const_iterator i = a.begin();
00041     typename U::const_iterator j = b.begin();
00042     while (i != a.end() && j != b.end() && *i == *j) { ++i; ++j; }
00043     return (i == a.end()) && (j == b.end());
00044 }
00045 
00046 // ostream and == operators so we can compare vectors and boost::assign::list_of
00047 // with BOOST_CHECK_EQUALS
00048 namespace std {                 // In namespace std so boost can find them.
00049 
00050 template <class T>
00051 ostream& operator<<(ostream& o, const vector<T>& v) { return seqPrint(o, v); }
00052 
00053 template <class T>
00054 ostream& operator<<(ostream& o, const boost::assign_detail::generic_list<T>& l) { return seqPrint(o, l); }
00055 
00056 template <class T>
00057 bool operator == (const vector<T>& a, const boost::assign_detail::generic_list<T>& b) { return seqEqual(a, b); }
00058 
00059 template <class T>
00060 bool operator == (const boost::assign_detail::generic_list<T>& b, const vector<T>& a) { return seqEqual(a, b); }
00061 }
00062 
00066 inline bool regexPredicate(const std::string& re, const std::string& text) {
00067     return boost::regex_match(text, boost::regex(re));
00068 }
00069 
00071 #define BOOST_CHECK_REGEX(re, text) \
00072     BOOST_CHECK_PREDICATE(regexPredicate, (re)(text))
00073 
00075 #define BOOST_CHECK_TYPEID_EQUAL(a,b) BOOST_CHECK_EQUAL(typeid(a).name(),typeid(b).name())
00076 
00077 #endif  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7