PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLTUT_H
  29. #define LL_LLTUT_H
  30. #include "is_approx_equal_fraction.h" // instead of llmath.h
  31. #include <tut/tut.hpp>
  32. #include <cstring>
  33. class LLDate;
  34. class LLSD;
  35. class LLURI;
  36. namespace tut
  37. {
  38. inline void ensure_approximately_equals(const char* msg, F64 actual, F64 expected, U32 frac_bits)
  39. {
  40. if(!is_approx_equal_fraction(actual, expected, frac_bits))
  41. {
  42. std::stringstream ss;
  43. ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
  44. throw tut::failure(ss.str().c_str());
  45. }
  46. }
  47. inline void ensure_approximately_equals(const char* msg, F32 actual, F32 expected, U32 frac_bits)
  48. {
  49. if(!is_approx_equal_fraction(actual, expected, frac_bits))
  50. {
  51. std::stringstream ss;
  52. ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
  53. throw tut::failure(ss.str().c_str());
  54. }
  55. }
  56. inline void ensure_approximately_equals(F32 actual, F32 expected, U32 frac_bits)
  57. {
  58. ensure_approximately_equals(NULL, actual, expected, frac_bits);
  59. }
  60. inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len)
  61. {
  62. if((expected_len != actual_len) ||
  63. (std::memcmp(actual, expected, actual_len) != 0))
  64. {
  65. std::stringstream ss;
  66. ss << (msg?msg:"") << (msg?": ":"") << "not equal";
  67. throw tut::failure(ss.str().c_str());
  68. }
  69. }
  70. inline void ensure_memory_matches(const void* actual, U32 actual_len, const void* expected,U32 expected_len)
  71. {
  72. ensure_memory_matches(NULL, actual, actual_len, expected, expected_len);
  73. }
  74. template <class T,class Q>
  75. void ensure_not_equals(const char* msg,const Q& actual,const T& expected)
  76. {
  77. if( expected == actual )
  78. {
  79. std::stringstream ss;
  80. ss << (msg?msg:"") << (msg?": ":"") << "both equal " << expected;
  81. throw tut::failure(ss.str().c_str());
  82. }
  83. }
  84. template <class T,class Q>
  85. void ensure_not_equals(const Q& actual,const T& expected)
  86. {
  87. ensure_not_equals(NULL, actual, expected);
  88. }
  89. template <class T,class Q>
  90. void ensure_equals(const std::string& msg,
  91. const Q& actual,const T& expected)
  92. { ensure_equals(msg.c_str(), actual, expected); }
  93. void ensure_equals(const char* msg,
  94. const LLDate& actual, const LLDate& expected);
  95. void ensure_equals(const char* msg,
  96. const LLURI& actual, const LLURI& expected);
  97. void ensure_equals(const char* msg,
  98. const std::vector<U8>& actual, const std::vector<U8>& expected);
  99. void ensure_equals(const char* msg,
  100. const LLSD& actual, const LLSD& expected);
  101. void ensure_equals(const std::string& msg,
  102. const LLSD& actual, const LLSD& expected);
  103. void ensure_starts_with(const std::string& msg,
  104. const std::string& actual, const std::string& expectedStart);
  105. void ensure_ends_with(const std::string& msg,
  106. const std::string& actual, const std::string& expectedEnd);
  107. void ensure_contains(const std::string& msg,
  108. const std::string& actual, const std::string& expectedSubString);
  109. void ensure_does_not_contain(const std::string& msg,
  110. const std::string& actual, const std::string& expectedSubString);
  111. }
  112. #endif // LL_LLTUT_H