PageRenderTime 59ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/tests/llurlmatch_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 313 lines | 197 code | 59 blank | 57 comment | 0 complexity | c3b94445c574eb4bf541d3272fefc279 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llurlmatch_test.cpp
  3. * @author Martin Reddy
  4. * @brief Unit tests for LLUrlMatch
  5. *
  6. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "../llurlmatch.h"
  29. #include "../lluiimage.h"
  30. #include "lltut.h"
  31. // link seams
  32. LLUIColor::LLUIColor()
  33. : mColorPtr(NULL)
  34. {}
  35. LLStyle::Params::Params()
  36. {
  37. }
  38. LLUIImage::LLUIImage(const std::string& name, LLPointer<LLTexture> image)
  39. {
  40. }
  41. LLUIImage::~LLUIImage()
  42. {
  43. }
  44. //virtual
  45. S32 LLUIImage::getWidth() const
  46. {
  47. return 0;
  48. }
  49. //virtual
  50. S32 LLUIImage::getHeight() const
  51. {
  52. return 0;
  53. }
  54. namespace LLInitParam
  55. {
  56. BlockDescriptor::BlockDescriptor() {}
  57. ParamDescriptor::ParamDescriptor(param_handle_t p,
  58. merge_func_t merge_func,
  59. deserialize_func_t deserialize_func,
  60. serialize_func_t serialize_func,
  61. validation_func_t validation_func,
  62. inspect_func_t inspect_func,
  63. S32 min_count,
  64. S32 max_count){}
  65. ParamDescriptor::~ParamDescriptor() {}
  66. void BaseBlock::addParam(BlockDescriptor& block_data, const ParamDescriptorPtr in_param, const char* char_name){}
  67. param_handle_t BaseBlock::getHandleFromParam(const Param* param) const {return 0;}
  68. void BaseBlock::addSynonym(Param& param, const std::string& synonym) {}
  69. void BaseBlock::init(BlockDescriptor& descriptor, BlockDescriptor& base_descriptor, size_t block_size)
  70. {
  71. descriptor.mCurrentBlockPtr = this;
  72. }
  73. Param::Param(BaseBlock* enclosing_block)
  74. : mIsProvided(false)
  75. {
  76. const U8* my_addr = reinterpret_cast<const U8*>(this);
  77. const U8* block_addr = reinterpret_cast<const U8*>(enclosing_block);
  78. mEnclosingBlockOffset = 0x7FFFffff & ((U32)(my_addr - block_addr));
  79. }
  80. bool BaseBlock::deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack, bool new_name){ return true; }
  81. void BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const LLInitParam::BaseBlock* diff_block) const {}
  82. bool BaseBlock::inspectBlock(Parser& parser, Parser::name_stack_t name_stack, S32 min_count, S32 max_count) const { return true; }
  83. bool BaseBlock::mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite) { return true; }
  84. bool BaseBlock::validateBlock(bool emit_errors) const { return true; }
  85. ParamValue<LLUIColor, TypeValues<LLUIColor> >::ParamValue(const LLUIColor& color)
  86. : super_t(color)
  87. {}
  88. void ParamValue<LLUIColor, TypeValues<LLUIColor> >::updateValueFromBlock()
  89. {}
  90. void ParamValue<LLUIColor, TypeValues<LLUIColor> >::updateBlockFromValue(bool)
  91. {}
  92. bool ParamCompare<const LLFontGL*, false>::equals(const LLFontGL* a, const LLFontGL* b)
  93. {
  94. return false;
  95. }
  96. ParamValue<const LLFontGL*, TypeValues<const LLFontGL*> >::ParamValue(const LLFontGL* fontp)
  97. : super_t(fontp)
  98. {}
  99. void ParamValue<const LLFontGL*, TypeValues<const LLFontGL*> >::updateValueFromBlock()
  100. {}
  101. void ParamValue<const LLFontGL*, TypeValues<const LLFontGL*> >::updateBlockFromValue(bool)
  102. {}
  103. void TypeValues<LLFontGL::HAlign>::declareValues()
  104. {}
  105. void TypeValues<LLFontGL::VAlign>::declareValues()
  106. {}
  107. void TypeValues<LLFontGL::ShadowType>::declareValues()
  108. {}
  109. void ParamValue<LLUIImage*, TypeValues<LLUIImage*> >::updateValueFromBlock()
  110. {}
  111. void ParamValue<LLUIImage*, TypeValues<LLUIImage*> >::updateBlockFromValue(bool)
  112. {}
  113. bool ParamCompare<LLUIImage*, false>::equals(
  114. LLUIImage* const &a,
  115. LLUIImage* const &b)
  116. {
  117. return false;
  118. }
  119. bool ParamCompare<LLUIColor, false>::equals(const LLUIColor &a, const LLUIColor &b)
  120. {
  121. return false;
  122. }
  123. }
  124. //static
  125. LLFontGL* LLFontGL::getFontDefault()
  126. {
  127. return NULL;
  128. }
  129. namespace tut
  130. {
  131. struct LLUrlMatchData
  132. {
  133. };
  134. typedef test_group<LLUrlMatchData> factory;
  135. typedef factory::object object;
  136. }
  137. namespace
  138. {
  139. tut::factory tf("LLUrlMatch");
  140. }
  141. namespace tut
  142. {
  143. template<> template<>
  144. void object::test<1>()
  145. {
  146. //
  147. // test the empty() method
  148. //
  149. LLUrlMatch match;
  150. ensure("empty()", match.empty());
  151. match.setValues(0, 1, "http://secondlife.com", "Second Life", "", "", LLStyle::Params(), "", "", LLUUID::null);
  152. ensure("! empty()", ! match.empty());
  153. }
  154. template<> template<>
  155. void object::test<2>()
  156. {
  157. //
  158. // test the getStart() method
  159. //
  160. LLUrlMatch match;
  161. ensure_equals("getStart() == 0", match.getStart(), 0);
  162. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  163. ensure_equals("getStart() == 10", match.getStart(), 10);
  164. }
  165. template<> template<>
  166. void object::test<3>()
  167. {
  168. //
  169. // test the getEnd() method
  170. //
  171. LLUrlMatch match;
  172. ensure_equals("getEnd() == 0", match.getEnd(), 0);
  173. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  174. ensure_equals("getEnd() == 20", match.getEnd(), 20);
  175. }
  176. template<> template<>
  177. void object::test<4>()
  178. {
  179. //
  180. // test the getUrl() method
  181. //
  182. LLUrlMatch match;
  183. ensure_equals("getUrl() == ''", match.getUrl(), "");
  184. match.setValues(10, 20, "http://slurl.com/", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  185. ensure_equals("getUrl() == 'http://slurl.com/'", match.getUrl(), "http://slurl.com/");
  186. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  187. ensure_equals("getUrl() == '' (2)", match.getUrl(), "");
  188. }
  189. template<> template<>
  190. void object::test<5>()
  191. {
  192. //
  193. // test the getLabel() method
  194. //
  195. LLUrlMatch match;
  196. ensure_equals("getLabel() == ''", match.getLabel(), "");
  197. match.setValues(10, 20, "", "Label", "", "", LLStyle::Params(), "", "", LLUUID::null);
  198. ensure_equals("getLabel() == 'Label'", match.getLabel(), "Label");
  199. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  200. ensure_equals("getLabel() == '' (2)", match.getLabel(), "");
  201. }
  202. template<> template<>
  203. void object::test<6>()
  204. {
  205. //
  206. // test the getTooltip() method
  207. //
  208. LLUrlMatch match;
  209. ensure_equals("getTooltip() == ''", match.getTooltip(), "");
  210. match.setValues(10, 20, "", "", "Info", "", LLStyle::Params(), "", "", LLUUID::null);
  211. ensure_equals("getTooltip() == 'Info'", match.getTooltip(), "Info");
  212. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  213. ensure_equals("getTooltip() == '' (2)", match.getTooltip(), "");
  214. }
  215. template<> template<>
  216. void object::test<7>()
  217. {
  218. //
  219. // test the getIcon() method
  220. //
  221. LLUrlMatch match;
  222. ensure_equals("getIcon() == ''", match.getIcon(), "");
  223. match.setValues(10, 20, "", "", "", "Icon", LLStyle::Params(), "", "", LLUUID::null);
  224. ensure_equals("getIcon() == 'Icon'", match.getIcon(), "Icon");
  225. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  226. ensure_equals("getIcon() == '' (2)", match.getIcon(), "");
  227. }
  228. template<> template<>
  229. void object::test<8>()
  230. {
  231. //
  232. // test the getMenuName() method
  233. //
  234. LLUrlMatch match;
  235. ensure("getMenuName() empty", match.getMenuName().empty());
  236. match.setValues(10, 20, "", "", "", "Icon", LLStyle::Params(), "xui_file.xml", "", LLUUID::null);
  237. ensure_equals("getMenuName() == \"xui_file.xml\"", match.getMenuName(), "xui_file.xml");
  238. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  239. ensure("getMenuName() empty (2)", match.getMenuName().empty());
  240. }
  241. template<> template<>
  242. void object::test<9>()
  243. {
  244. //
  245. // test the getLocation() method
  246. //
  247. LLUrlMatch match;
  248. ensure("getLocation() empty", match.getLocation().empty());
  249. match.setValues(10, 20, "", "", "", "Icon", LLStyle::Params(), "xui_file.xml", "Paris", LLUUID::null);
  250. ensure_equals("getLocation() == \"Paris\"", match.getLocation(), "Paris");
  251. match.setValues(10, 20, "", "", "", "", LLStyle::Params(), "", "", LLUUID::null);
  252. ensure("getLocation() empty (2)", match.getLocation().empty());
  253. }
  254. }