PageRenderTime 36ms CodeModel.GetById 18ms app.highlight 16ms RepoModel.GetById 1ms 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
  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
 30#include "../test/lltut.h"
 31
 32#include "../llviewerhelputil.h"
 33#include "../llweb.h"
 34#include "llcontrol.h"
 35
 36#include <iostream>
 37
 38// values for all of the supported substitutions parameters
 39static std::string gHelpURL;
 40static std::string gVersion;
 41static std::string gChannel;
 42static std::string gLanguage;
 43static std::string gGrid;
 44static std::string gOS;
 45
 46//----------------------------------------------------------------------------
 47// Mock objects for the dependencies of the code we're testing
 48
 49LLControlGroup::LLControlGroup(const std::string& name)
 50	: LLInstanceTracker<LLControlGroup, std::string>(name) {}
 51LLControlGroup::~LLControlGroup() {}
 52BOOL LLControlGroup::declareString(const std::string& name,
 53				   const std::string& initial_val,
 54				   const std::string& comment,
 55				   BOOL persist) {return TRUE;}
 56void LLControlGroup::setString(const std::string& name, const std::string& val){}
 57std::string LLControlGroup::getString(const std::string& name)
 58{
 59	if (name == "HelpURLFormat")
 60		return gHelpURL;
 61	return "";
 62}
 63LLControlGroup gSavedSettings("test");
 64
 65static void substitute_string(std::string &input, const std::string &search, const std::string &replace)
 66{
 67	size_t pos = input.find(search);
 68	while (pos != std::string::npos)
 69	{
 70		input = input.replace(pos, search.size(), replace);
 71		pos = input.find(search);
 72	}
 73}
 74
 75#include "../llagent.h"
 76LLAgent::LLAgent() : mAgentAccess(NULL) { }
 77LLAgent::~LLAgent() { }
 78bool LLAgent::isGodlike() const { return FALSE; }
 79
 80LLAgent gAgent;
 81
 82std::string LLWeb::expandURLSubstitutions(const std::string &url,
 83										  const LLSD &default_subs)
 84{
 85	(void)gAgent.isGodlike(); // ref symbol to stop compiler from stripping it
 86	std::string new_url = url;
 87	substitute_string(new_url, "[TOPIC]", default_subs["TOPIC"].asString());
 88	substitute_string(new_url, "[VERSION]", gVersion);
 89	substitute_string(new_url, "[CHANNEL]", gChannel);
 90	substitute_string(new_url, "[LANGUAGE]", gLanguage);
 91	substitute_string(new_url, "[GRID]", gGrid);
 92	substitute_string(new_url, "[OS]", gOS);
 93	return new_url;
 94}
 95
 96
 97//----------------------------------------------------------------------------
 98	
 99namespace tut
100{
101    struct viewerhelputil
102    {
103    };
104    
105	typedef test_group<viewerhelputil> viewerhelputil_t;
106	typedef viewerhelputil_t::object viewerhelputil_object_t;
107	tut::viewerhelputil_t tut_viewerhelputil("LLViewerHelpUtil");
108
109	template<> template<>
110	void viewerhelputil_object_t::test<1>()
111	{
112		std::string topic("test_topic");
113		std::string subresult;
114
115		gHelpURL = "fooformat";
116		subresult = LLViewerHelpUtil::buildHelpURL(topic);
117		ensure_equals("no substitution tags", subresult, "fooformat");
118
119		gHelpURL = "";
120		subresult = LLViewerHelpUtil::buildHelpURL(topic);
121		ensure_equals("blank substitution format", subresult, "");
122
123		gHelpURL = "[TOPIC]";
124		subresult = LLViewerHelpUtil::buildHelpURL(topic);
125		ensure_equals("topic name", subresult, "test_topic");
126
127		gHelpURL = "[LANGUAGE]";
128		gLanguage = "";
129		subresult = LLViewerHelpUtil::buildHelpURL(topic);
130		ensure_equals("simple substitution with blank", subresult, "");
131
132		gHelpURL = "[LANGUAGE]";
133		gLanguage = "Esperanto";
134		subresult = LLViewerHelpUtil::buildHelpURL(topic);
135		ensure_equals("simple substitution", subresult, "Esperanto");
136
137		gHelpURL = "http://secondlife.com/[LANGUAGE]";
138		gLanguage = "Gaelic";
139		subresult = LLViewerHelpUtil::buildHelpURL(topic);
140		ensure_equals("simple substitution with url", subresult, "http://secondlife.com/Gaelic");
141
142		gHelpURL = "[XXX]";
143		subresult = LLViewerHelpUtil::buildHelpURL(topic);
144		ensure_equals("unknown substitution", subresult, "[XXX]");
145
146		gHelpURL = "[LANGUAGE]/[LANGUAGE]";
147		gLanguage = "Esperanto";
148		subresult = LLViewerHelpUtil::buildHelpURL(topic);
149		ensure_equals("multiple substitution", subresult, "Esperanto/Esperanto");
150
151		gHelpURL = "http://[CHANNEL]/[VERSION]/[LANGUAGE]/[OS]/[GRID]/[XXX]";
152		gChannel = "Second Life Test";
153		gVersion = "2.0";
154		gLanguage = "gaelic";
155		gOS = "AmigaOS 2.1";
156		gGrid = "mysim";
157		subresult = LLViewerHelpUtil::buildHelpURL(topic);
158		ensure_equals("complex substitution", subresult, "http://Second Life Test/2.0/gaelic/AmigaOS 2.1/mysim/[XXX]");
159	}
160}