PageRenderTime 70ms CodeModel.GetById 33ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/test/lltut.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 136 lines | 85 code | 24 blank | 27 comment | 8 complexity | 042f79ab9b53a687ab83d950db228dbc MD5 | raw file
  1/** 
  2 * @file lltut.h
  3 * @author Phoenix
  4 * @date 2005-09-26
  5 * @brief helper tut methods
  6 *
  7 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#ifndef LL_LLTUT_H
 30#define LL_LLTUT_H
 31
 32#include "is_approx_equal_fraction.h" // instead of llmath.h
 33
 34#include <tut/tut.hpp>
 35#include <cstring>
 36
 37class LLDate;
 38class LLSD;
 39class LLURI;
 40
 41namespace tut
 42{
 43	inline void ensure_approximately_equals(const char* msg, F64 actual, F64 expected, U32 frac_bits)
 44	{
 45		if(!is_approx_equal_fraction(actual, expected, frac_bits))
 46		{
 47			std::stringstream ss;
 48			ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
 49			throw tut::failure(ss.str().c_str());
 50		}
 51	}
 52
 53	inline void ensure_approximately_equals(const char* msg, F32 actual, F32 expected, U32 frac_bits)
 54	{
 55		if(!is_approx_equal_fraction(actual, expected, frac_bits))
 56		{
 57			std::stringstream ss;
 58			ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
 59			throw tut::failure(ss.str().c_str());
 60		}
 61	}
 62
 63	inline void ensure_approximately_equals(F32 actual, F32 expected, U32 frac_bits)
 64	{
 65		ensure_approximately_equals(NULL, actual, expected, frac_bits);
 66	}
 67
 68	inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len)
 69	{
 70		if((expected_len != actual_len) || 
 71			(std::memcmp(actual, expected, actual_len) != 0))
 72		{
 73			std::stringstream ss;
 74			ss << (msg?msg:"") << (msg?": ":"") << "not equal";
 75			throw tut::failure(ss.str().c_str());
 76		}
 77	}
 78
 79	inline void ensure_memory_matches(const void* actual, U32 actual_len, const void* expected,U32 expected_len)
 80	{
 81		ensure_memory_matches(NULL, actual, actual_len, expected, expected_len);
 82	}
 83
 84	template <class T,class Q>
 85	void ensure_not_equals(const char* msg,const Q& actual,const T& expected)
 86	{
 87		if( expected == actual )
 88		{
 89			std::stringstream ss;
 90			ss << (msg?msg:"") << (msg?": ":"") << "both equal " << expected;
 91			throw tut::failure(ss.str().c_str());
 92		}
 93	}
 94
 95	template <class T,class Q>
 96	void ensure_not_equals(const Q& actual,const T& expected)
 97	{
 98		ensure_not_equals(NULL, actual, expected);
 99	}
100	
101	
102	template <class T,class Q>
103	void ensure_equals(const std::string& msg,
104		const Q& actual,const T& expected)
105		{ ensure_equals(msg.c_str(), actual, expected); }
106
107	void ensure_equals(const char* msg,
108		const LLDate& actual, const LLDate& expected);
109
110	void ensure_equals(const char* msg,
111		const LLURI& actual, const LLURI& expected);
112		
113	void ensure_equals(const char* msg,
114		const std::vector<U8>& actual, const std::vector<U8>& expected);
115
116	void ensure_equals(const char* msg,
117		const LLSD& actual, const LLSD& expected);
118
119	void ensure_equals(const std::string& msg,
120		const LLSD& actual, const LLSD& expected);
121	
122	void ensure_starts_with(const std::string& msg,
123		const std::string& actual, const std::string& expectedStart);
124
125	void ensure_ends_with(const std::string& msg,
126		const std::string& actual, const std::string& expectedEnd);
127
128	void ensure_contains(const std::string& msg,
129		const std::string& actual, const std::string& expectedSubString);
130
131	void ensure_does_not_contain(const std::string& msg,
132		const std::string& actual, const std::string& expectedSubString);
133}
134
135
136#endif // LL_LLTUT_H