PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/tests/llviewerhelputil_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 160 lines | 105 code | 24 blank | 31 comment | 4 complexity | ae164bfb27fbbdcd2e67302a3a937c49 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerhelputil_test.cpp
  3. * @brief LLViewerHelpUtil tests
  4. * @author Tofu Linden
  5. *
  6. * $LicenseInfo:firstyear=2001&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. // Precompiled header
  28. #include "../llviewerprecompiledheaders.h"
  29. #include "../test/lltut.h"
  30. #include "../llviewerhelputil.h"
  31. #include "../llweb.h"
  32. #include "llcontrol.h"
  33. #include <iostream>
  34. // values for all of the supported substitutions parameters
  35. static std::string gHelpURL;
  36. static std::string gVersion;
  37. static std::string gChannel;
  38. static std::string gLanguage;
  39. static std::string gGrid;
  40. static std::string gOS;
  41. //----------------------------------------------------------------------------
  42. // Mock objects for the dependencies of the code we're testing
  43. LLControlGroup::LLControlGroup(const std::string& name)
  44. : LLInstanceTracker<LLControlGroup, std::string>(name) {}
  45. LLControlGroup::~LLControlGroup() {}
  46. BOOL LLControlGroup::declareString(const std::string& name,
  47. const std::string& initial_val,
  48. const std::string& comment,
  49. BOOL persist) {return TRUE;}
  50. void LLControlGroup::setString(const std::string& name, const std::string& val){}
  51. std::string LLControlGroup::getString(const std::string& name)
  52. {
  53. if (name == "HelpURLFormat")
  54. return gHelpURL;
  55. return "";
  56. }
  57. LLControlGroup gSavedSettings("test");
  58. static void substitute_string(std::string &input, const std::string &search, const std::string &replace)
  59. {
  60. size_t pos = input.find(search);
  61. while (pos != std::string::npos)
  62. {
  63. input = input.replace(pos, search.size(), replace);
  64. pos = input.find(search);
  65. }
  66. }
  67. #include "../llagent.h"
  68. LLAgent::LLAgent() : mAgentAccess(NULL) { }
  69. LLAgent::~LLAgent() { }
  70. bool LLAgent::isGodlike() const { return FALSE; }
  71. LLAgent gAgent;
  72. std::string LLWeb::expandURLSubstitutions(const std::string &url,
  73. const LLSD &default_subs)
  74. {
  75. (void)gAgent.isGodlike(); // ref symbol to stop compiler from stripping it
  76. std::string new_url = url;
  77. substitute_string(new_url, "[TOPIC]", default_subs["TOPIC"].asString());
  78. substitute_string(new_url, "[VERSION]", gVersion);
  79. substitute_string(new_url, "[CHANNEL]", gChannel);
  80. substitute_string(new_url, "[LANGUAGE]", gLanguage);
  81. substitute_string(new_url, "[GRID]", gGrid);
  82. substitute_string(new_url, "[OS]", gOS);
  83. return new_url;
  84. }
  85. //----------------------------------------------------------------------------
  86. namespace tut
  87. {
  88. struct viewerhelputil
  89. {
  90. };
  91. typedef test_group<viewerhelputil> viewerhelputil_t;
  92. typedef viewerhelputil_t::object viewerhelputil_object_t;
  93. tut::viewerhelputil_t tut_viewerhelputil("LLViewerHelpUtil");
  94. template<> template<>
  95. void viewerhelputil_object_t::test<1>()
  96. {
  97. std::string topic("test_topic");
  98. std::string subresult;
  99. gHelpURL = "fooformat";
  100. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  101. ensure_equals("no substitution tags", subresult, "fooformat");
  102. gHelpURL = "";
  103. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  104. ensure_equals("blank substitution format", subresult, "");
  105. gHelpURL = "[TOPIC]";
  106. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  107. ensure_equals("topic name", subresult, "test_topic");
  108. gHelpURL = "[LANGUAGE]";
  109. gLanguage = "";
  110. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  111. ensure_equals("simple substitution with blank", subresult, "");
  112. gHelpURL = "[LANGUAGE]";
  113. gLanguage = "Esperanto";
  114. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  115. ensure_equals("simple substitution", subresult, "Esperanto");
  116. gHelpURL = "http://secondlife.com/[LANGUAGE]";
  117. gLanguage = "Gaelic";
  118. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  119. ensure_equals("simple substitution with url", subresult, "http://secondlife.com/Gaelic");
  120. gHelpURL = "[XXX]";
  121. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  122. ensure_equals("unknown substitution", subresult, "[XXX]");
  123. gHelpURL = "[LANGUAGE]/[LANGUAGE]";
  124. gLanguage = "Esperanto";
  125. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  126. ensure_equals("multiple substitution", subresult, "Esperanto/Esperanto");
  127. gHelpURL = "http://[CHANNEL]/[VERSION]/[LANGUAGE]/[OS]/[GRID]/[XXX]";
  128. gChannel = "Second Life Test";
  129. gVersion = "2.0";
  130. gLanguage = "gaelic";
  131. gOS = "AmigaOS 2.1";
  132. gGrid = "mysim";
  133. subresult = LLViewerHelpUtil::buildHelpURL(topic);
  134. ensure_equals("complex substitution", subresult, "http://Second Life Test/2.0/gaelic/AmigaOS 2.1/mysim/[XXX]");
  135. }
  136. }