PageRenderTime 32ms CodeModel.GetById 2ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/test/llmessageconfig_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 236 lines | 181 code | 17 blank | 38 comment | 1 complexity | 03ceaa9bebca87719bf3cbeebe75a514 MD5 | raw file
  1/** 
  2 * @file llmessageconfig_tut.cpp
  3 * @date   March 2007
  4 * @brief LLMessageConfig unit tests
  5 *
  6 * $LicenseInfo:firstyear=2006&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
 28#include "linden_common.h"
 29#include "llmessageconfig.h"
 30#include "lltut.h"
 31#include "llsdserialize.h"
 32#include "llfile.h"
 33#include "lltimer.h"
 34#include "llframetimer.h"
 35#include "llsdutil.h"
 36
 37namespace tut
 38{
 39	struct LLMessageConfigTestData {
 40		std::string mTestConfigDir;
 41
 42		LLMessageConfigTestData()
 43		{
 44			LLUUID random;
 45			random.generate();
 46			// generate temp dir
 47			std::ostringstream oStr;
 48#if LL_WINDOWS 
 49			oStr << "llmessage-config-test-" << random;
 50#else
 51			oStr << "/tmp/llmessage-config-test-" << random;
 52#endif
 53			mTestConfigDir = oStr.str();
 54			LLFile::mkdir(mTestConfigDir);
 55			writeConfigFile(LLSD());
 56			LLMessageConfig::initClass("simulator", mTestConfigDir);
 57		}
 58
 59		~LLMessageConfigTestData()
 60		{
 61			// rm contents of temp dir
 62			int rmfile = LLFile::remove((mTestConfigDir + "/message.xml"));
 63			ensure_equals("rmfile value", rmfile, 0);
 64			// rm temp dir
 65			int rmdir = LLFile::rmdir(mTestConfigDir);
 66			ensure_equals("rmdir value", rmdir, 0);
 67		}
 68
 69		void writeConfigFile(const LLSD& config)
 70		{
 71			llofstream file((mTestConfigDir + "/message.xml"));
 72			if (file.is_open())
 73			{
 74				LLSDSerialize::toPrettyXML(config, file);
 75			}
 76			file.close();
 77		}
 78	};
 79	
 80	typedef test_group<LLMessageConfigTestData> LLMessageConfigTestGroup;
 81	typedef LLMessageConfigTestGroup::object LLMessageConfigTestObject;
 82	LLMessageConfigTestGroup llMessageConfigTestGroup("LLMessageConfig");
 83	
 84	template<> template<>
 85	void LLMessageConfigTestObject::test<1>()
 86		// tests server defaults
 87	{
 88		LLSD config;
 89		config["serverDefaults"]["simulator"] = "template";
 90		LLMessageConfig::useConfig(config);
 91		ensure_equals("Ensure server default is not template",
 92					  LLMessageConfig::getServerDefaultFlavor(),
 93					  LLMessageConfig::TEMPLATE_FLAVOR);
 94	}
 95
 96	template<> template<>
 97	void LLMessageConfigTestObject::test<2>()
 98		// tests message flavors
 99	{
100		LLSD config;
101		config["serverDefaults"]["simulator"] = "template";
102		config["messages"]["msg1"]["flavor"] = "template";
103		config["messages"]["msg2"]["flavor"] = "llsd";
104		LLMessageConfig::useConfig(config);
105		ensure_equals("Ensure msg template flavor",
106					  LLMessageConfig::getMessageFlavor("msg1"),
107					  LLMessageConfig::TEMPLATE_FLAVOR);
108		ensure_equals("Ensure msg llsd flavor",
109					  LLMessageConfig::getMessageFlavor("msg2"),
110					  LLMessageConfig::LLSD_FLAVOR);
111	}
112
113	template<> template<>
114	void LLMessageConfigTestObject::test<4>()
115		// tests message flavor defaults
116	{
117		LLSD config;
118		config["serverDefaults"]["simulator"] = "llsd";
119		config["messages"]["msg1"]["trusted-sender"] = true;
120		LLMessageConfig::useConfig(config);
121		ensure_equals("Ensure missing message gives no flavor",
122					  LLMessageConfig::getMessageFlavor("Test"),
123					  LLMessageConfig::NO_FLAVOR);
124		ensure_equals("Ensure missing flavor is NO_FLAVOR even with sender trustedness set",
125					  LLMessageConfig::getMessageFlavor("msg1"),
126					  LLMessageConfig::NO_FLAVOR);
127		ensure_equals("Ensure server default is llsd",
128					  LLMessageConfig::getServerDefaultFlavor(),
129					  LLMessageConfig::LLSD_FLAVOR);
130	}
131
132	template<> template<>
133	void LLMessageConfigTestObject::test<3>()
134		// tests trusted/untrusted senders
135	{
136		LLSD config;
137		config["serverDefaults"]["simulator"] = "template";
138		config["messages"]["msg1"]["flavor"] = "llsd";
139		config["messages"]["msg1"]["trusted-sender"] = false;
140		config["messages"]["msg2"]["flavor"] = "llsd";
141		config["messages"]["msg2"]["trusted-sender"] = true;
142		LLMessageConfig::useConfig(config);
143		ensure_equals("Ensure untrusted is untrusted",
144					  LLMessageConfig::getSenderTrustedness("msg1"),
145					  LLMessageConfig::UNTRUSTED);
146		ensure_equals("Ensure trusted is trusted",
147					  LLMessageConfig::getSenderTrustedness("msg2"),
148					  LLMessageConfig::TRUSTED);
149		ensure_equals("Ensure missing trustedness is NOT_SET",
150					  LLMessageConfig::getSenderTrustedness("msg3"),
151					  LLMessageConfig::NOT_SET);
152	}
153	
154	template<> template<>
155	void LLMessageConfigTestObject::test<5>()
156		// tests trusted/untrusted without flag, only flavor
157	{
158		LLSD config;
159		config["serverDefaults"]["simulator"] = "template";
160		config["messages"]["msg1"]["flavor"] = "llsd";
161		LLMessageConfig::useConfig(config);
162		ensure_equals("Ensure msg1 exists, has llsd flavor",
163					  LLMessageConfig::getMessageFlavor("msg1"),
164					  LLMessageConfig::LLSD_FLAVOR);
165		ensure_equals("Ensure missing trusted is not set",
166					  LLMessageConfig::getSenderTrustedness("msg1"),
167					  LLMessageConfig::NOT_SET);
168	}
169
170	template<> template<>
171	void LLMessageConfigTestObject::test<6>()
172	{
173		LLSD config;
174		config["capBans"]["MapLayer"] = true;
175		config["capBans"]["MapLayerGod"] = false;
176		LLMessageConfig::useConfig(config);
177		ensure_equals("Ensure cap ban true MapLayer",
178					  LLMessageConfig::isCapBanned("MapLayer"),
179					  true);
180		ensure_equals("Ensure cap ban false",
181					  LLMessageConfig::isCapBanned("MapLayerGod"),
182					  false);
183	}
184
185	template<> template<>
186	void LLMessageConfigTestObject::test<7>()
187		// tests that config changes are picked up/refreshed periodically
188	{
189		LLSD config;
190		config["serverDefaults"]["simulator"] = "llsd";
191		writeConfigFile(config);
192
193		// wait for it to reload after N seconds
194		ms_sleep(6*1000);
195		LLFrameTimer::updateFrameTime();
196		ensure_equals("Ensure reload after 6 seconds",
197					  LLMessageConfig::getServerDefaultFlavor(),
198					  LLMessageConfig::LLSD_FLAVOR);
199	}
200
201	template<> template<>
202	void LLMessageConfigTestObject::test<8>()
203		// tests that config changes are picked up/refreshed periodically
204	{
205		LLSD config;
206		config["serverDefaults"]["simulator"] = "template";
207		config["messages"]["msg1"]["flavor"] = "llsd";
208		config["messages"]["msg1"]["only-send-latest"] = true;
209		config["messages"]["msg2"]["flavor"] = "llsd";
210		config["messages"]["msg2"]["only-send-latest"] = false;
211		LLMessageConfig::useConfig(config);
212		ensure_equals("Ensure msg1 exists, sent latest-only",
213					  LLMessageConfig::onlySendLatest("msg1"),
214					  true);
215		ensure_equals("Ensure msg2 exists, sent latest-only",
216					  LLMessageConfig::onlySendLatest("msg2"),
217					  false);
218	}
219
220	template<> template<>
221	void LLMessageConfigTestObject::test<9>()
222		 // tests that event queue max is reloaded
223	{
224		LLSD config;
225		config["maxQueuedEvents"] = 200;
226		LLMessageConfig::useConfig(config);
227		ensure_equals("Ensure setting maxQueuedEvents",
228					  LLMessageConfig::getMaxQueuedEvents(),
229					  200);
230
231		LLMessageConfig::useConfig(LLSD());
232		ensure_equals("Ensure default of event queue max 100",
233					  LLMessageConfig::getMaxQueuedEvents(),
234					  100);
235	}	 
236}