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, F32 actual, F32 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(F32 actual, F32 expected, U32 frac_bits)
00058         {
00059                 ensure_approximately_equals(NULL, actual, expected, frac_bits);
00060         }
00061 
00062         inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len)
00063         {
00064                 if((expected_len != actual_len) || 
00065                         (memcmp(actual, expected, actual_len) != 0))
00066                 {
00067                         std::stringstream ss;
00068                         ss << (msg?msg:"") << (msg?": ":"") << "not equal";
00069                         throw tut::failure(ss.str().c_str());
00070                 }
00071         }
00072 
00073         inline void ensure_memory_matches(const void* actual, U32 actual_len, const void* expected,U32 expected_len)
00074         {
00075                 ensure_memory_matches(NULL, actual, actual_len, expected, expected_len);
00076         }
00077 
00078         template <class T,class Q>
00079         void ensure_not_equals(const char* msg,const Q& actual,const T& expected)
00080         {
00081                 if( expected == actual )
00082                 {
00083                         std::stringstream ss;
00084                         ss << (msg?msg:"") << (msg?": ":"") << "both equal " << expected;
00085                         throw tut::failure(ss.str().c_str());
00086                 }
00087         }
00088 
00089         template <class T,class Q>
00090         void ensure_not_equals(const Q& actual,const T& expected)
00091         {
00092                 ensure_not_equals(NULL, actual, expected);
00093         }
00094         
00095         
00096         template <class T,class Q>
00097         void ensure_equals(const std::string& msg,
00098                 const Q& actual,const T& expected)
00099                 { ensure_equals(msg.c_str(), actual, expected); }
00100 
00101         template<>
00102         void ensure_equals(const char* msg,
00103                 const LLDate& actual, const LLDate& expected);
00104 
00105         template<>
00106         void ensure_equals(const char* msg,
00107                 const LLURI& actual, const LLURI& expected);
00108                 
00109         template<>
00110         void ensure_equals(const char* msg,
00111                 const std::vector<U8>& actual, const std::vector<U8>& expected);
00112 
00113         template<>
00114         void ensure_equals(const char* msg,
00115                 const LLSD& actual, const LLSD& expected);
00116         
00117         void ensure_starts_with(const std::string& msg,
00118                 const std::string& actual, const std::string& expectedStart);
00119 
00120         void ensure_ends_with(const std::string& msg,
00121                 const std::string& actual, const std::string& expectedEnd);
00122 
00123         void ensure_contains(const std::string& msg,
00124                 const std::string& actual, const std::string& expectedSubString);
00125 
00126         void ensure_does_not_contain(const std::string& msg,
00127                 const std::string& actual, const std::string& expectedSubString);
00128 }
00129 
00130 
00131 #endif // LL_LLTUT_H

Generated on Thu Jul 1 06:09:23 2010 for Second Life Viewer by  doxygen 1.4.7