Tide 0.1.0

test_utils.h

Go to the documentation of this file.
00001 /* Tide
00002  *
00003  * Test utilities header file.
00004  *
00005  * Copyright 2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
00006  *     RT-Synthesis Research Group
00007  *     Intelligent Systems Research Institute,
00008  *     National Institute of Advanced Industrial Science and Technology (AIST),
00009  *     Japan
00010  *     All rights reserved.
00011  *
00012  * This file is part of Tide.
00013  *
00014  * Tide is free software; you can redistribute it and/or modify it under
00015  * the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation; either version 2.1 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * Tide is distributed in the hope that it will be useful, but WITHOUT
00020  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00021  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00022  * License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with Tide. If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #if !defined(TIDE_TEST_UTILS_H_)
00029 #define TIDE_TEST_UTILS_H_
00030 
00031 #include <boost/shared_ptr.hpp>
00032 #include <functional>
00033 #include <gtest/gtest.h>
00034 #include <stdint.h>
00035 #include <string>
00036 #include <tide/element.h>
00037 #include <tide/prim_element.h>
00038 #include <vector>
00039 
00040 
00041 namespace test_utils
00042 {
00043 
00044 typedef boost::shared_ptr<tide::Element> ElPtr;
00045 
00046 // Adds the total size of an element to a value
00047 struct TotalSizeOp
00048     : public std::binary_function<uint64_t, ElPtr, uint64_t>
00049 {
00050     uint64_t operator()(uint64_t total, ElPtr el)
00051     {
00052         return total + el->size();
00053     }
00054 };
00055 
00056 
00057 // Tests if two std::basic_string<uint8_t> byte buffers are equal.
00058 ::testing::AssertionResult std_buffers_eq(char const* b1_expr,
00059         char const* b2_expr,
00060         std::basic_string<uint8_t> const& b1,
00061         std::basic_string<uint8_t> const& b2);
00062 
00063 // Tests if two std::string buffers are equal.
00064 ::testing::AssertionResult std_buffers_eq(char const* b1_expr,
00065         char const* b2_expr, std::string const& b1, std::string const& b2);
00066 
00067 // Tests if two std::vector<char> buffers are equal.
00068 ::testing::AssertionResult std_vectors_eq(char const* b1_expr,
00069         char const* b2_expr, std::vector<char> const& b1,
00070         std::vector<char> const& b2);
00071 
00072 // Tests if two std::pair values are equal because gtest can't figure it out
00073 // for itself nor print the result.
00074 template<typename T1, typename T2>
00075 ::testing::AssertionResult pairs_eq(char const* p1_expr,
00076         char const* p2_expr, typename std::pair<uint64_t, T1> const& p1,
00077         typename std::pair<uint64_t, T2> const& p2)
00078 {
00079     if (p1.first != p2.first || p1.second != p2.second)
00080     {
00081         return ::testing::AssertionFailure() << p1_expr << " (" << p1.first <<
00082             ", " << p1.second << ") != " << p2_expr << " (" << p2.first <<
00083             ", " << p2.second << ")";
00084     }
00085     return ::testing::AssertionSuccess();
00086 }
00087 
00088 // Returns a blob of binary data, with a length that increases by 5 bytes
00089 // each time this function is called.
00090 boost::shared_ptr<std::vector<char> > make_blob(size_t size);
00091 
00092 }; // test_utils
00093 
00094 #endif // TIDE_TEST_UTILS_H_
00095 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines