lltut.h

Go to the documentation of this file.
00001 
00034 #ifndef LL_LLTUT_H
00035 #define LL_LLTUT_H
00036 
00037 #include <tut/tut.h>
00038 
00039 #include "lldate.h"
00040 #include "lluri.h"
00041 #include "llmath.h"
00042 
00043 class LLSD;
00044 
00045 namespace tut
00046 {
00047         inline void ensure_approximately_equals(const char* msg, F64 actual, F64 expected, U32 frac_bits)
00048         {
00049                 if(!is_approx_equal_fraction(actual, expected, frac_bits))
00050                 {
00051                         std::stringstream ss;
00052                         ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
00053                         throw tut::failure(ss.str().c_str());
00054                 }
00055         }
00056 
00057         inline void ensure_approximately_equals(const char* msg, F32 actual, F32 expected, U32 frac_bits)
00058         {
00059                 if(!is_approx_equal_fraction(actual, expected, frac_bits))
00060                 {
00061                         std::stringstream ss;
00062                         ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
00063                         throw tut::failure(ss.str().c_str());
00064                 }
00065         }
00066 
00067         inline void ensure_approximately_equals(F32 actual, F32 expected, U32 frac_bits)
00068         {
00069                 ensure_approximately_equals(NULL, actual, expected, frac_bits);
00070         }
00071 
00072         inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len)
00073         {
00074                 if((expected_len != actual_len) || 
00075                         (memcmp(actual, expected, actual_len) != 0))
00076                 {
00077                         std::stringstream ss;
00078                         ss << (msg?msg:"") << (msg?": ":"") << "not equal";
00079                         throw tut::failure(ss.str().c_str());
00080                 }
00081         }
00082 
00083         inline void ensure_memory_matches(const void* actual, U32 actual_len, const void* expected,U32 expected_len)
00084         {
00085                 ensure_memory_matches(NULL, actual, actual_len, expected, expected_len);
00086         }
00087 
00088         template <class T,class Q>
00089         void ensure_not_equals(const char* msg,const Q& actual,const T& expected)
00090         {
00091                 if( expected == actual )
00092                 {
00093                         std::stringstream ss;
00094                         ss << (msg?msg:"") << (msg?": ":"") << "both equal " << expected;
00095                         throw tut::failure(ss.str().c_str());
00096                 }
00097         }
00098 
00099         template <class T,class Q>
00100         void ensure_not_equals(const Q& actual,const T& expected)
00101         {
00102                 ensure_not_equals(NULL, actual, expected);
00103         }
00104         
00105         
00106         template <class T,class Q>
00107         void ensure_equals(const std::string& msg,
00108                 const Q& actual,const T& expected)
00109                 { ensure_equals(msg.c_str(), actual, expected); }
00110 
00111         template<>
00112         void ensure_equals(const char* msg,
00113                 const LLDate& actual, const LLDate& expected);
00114 
00115         template<>
00116         void ensure_equals(const char* msg,
00117                 const LLURI& actual, const LLURI& expected);
00118                 
00119         template<>
00120         void ensure_equals(const char* msg,
00121                 const std::vector<U8>& actual, const std::vector<U8>& expected);
00122 
00123         template<>
00124         void ensure_equals(const char* msg,
00125                 const LLSD& actual, const LLSD& expected);
00126         
00127         void ensure_starts_with(const std::string& msg,
00128                 const std::string& actual, const std::string& expectedStart);
00129 
00130         void ensure_ends_with(const std::string& msg,
00131                 const std::string& actual, const std::string& expectedEnd);
00132 
00133         void ensure_contains(const std::string& msg,
00134                 const std::string& actual, const std::string& expectedSubString);
00135 
00136         void ensure_does_not_contain(const std::string& msg,
00137                 const std::string& actual, const std::string& expectedSubString);
00138 }
00139 
00140 
00141 #endif // LL_LLTUT_H

Generated on Fri May 16 08:34:31 2008 for SecondLife by  doxygen 1.5.5