PageRenderTime 48ms CodeModel.GetById 20ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/tests/llagentaccess_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 263 lines | 178 code | 46 blank | 39 comment | 2 complexity | 0555d2101f644673d0921855b34639b9 MD5 | raw file
  1/** 
  2 * @file llagentaccess_test.cpp
  3 * @brief LLAgentAccess tests
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28#include "../test/lltut.h"
 29
 30#include "../llagentaccess.h"
 31
 32#include "llcontrol.h"
 33#include "indra_constants.h"
 34
 35#include <iostream>
 36
 37//----------------------------------------------------------------------------
 38// Implementation of enough of LLControlGroup to support the tests:
 39
 40static U32 test_preferred_maturity = SIM_ACCESS_PG;
 41
 42LLControlGroup::LLControlGroup(const std::string& name)
 43	: LLInstanceTracker<LLControlGroup, std::string>(name)
 44{
 45}
 46
 47LLControlGroup::~LLControlGroup()
 48{
 49}
 50
 51// Implementation of just the LLControlGroup methods we requre
 52BOOL LLControlGroup::declareU32(const std::string& name, U32 initial_val, const std::string& comment, BOOL persist)
 53{
 54	test_preferred_maturity = initial_val;
 55	return true;
 56}
 57
 58void LLControlGroup::setU32(const std::string& name, U32 val)
 59{
 60	test_preferred_maturity = val;
 61}
 62
 63U32 LLControlGroup::getU32(const std::string& name)
 64{
 65	return test_preferred_maturity;
 66}
 67//----------------------------------------------------------------------------
 68	
 69namespace tut
 70{
 71    struct agentaccess
 72    {
 73    };
 74    
 75	typedef test_group<agentaccess> agentaccess_t;
 76	typedef agentaccess_t::object agentaccess_object_t;
 77	tut::agentaccess_t tut_agentaccess("LLAgentAccess");
 78
 79	template<> template<>
 80	void agentaccess_object_t::test<1>()
 81	{
 82		LLControlGroup cgr("test");
 83		cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", FALSE);
 84		LLAgentAccess aa(cgr);
 85		
 86		cgr.setU32("PreferredMaturity", SIM_ACCESS_PG);
 87		ensure("1 prefersPG",     aa.prefersPG());
 88		ensure("1 prefersMature", !aa.prefersMature());
 89		ensure("1 prefersAdult",  !aa.prefersAdult());
 90		
 91		cgr.setU32("PreferredMaturity", SIM_ACCESS_MATURE);
 92		ensure("2 prefersPG",     !aa.prefersPG());
 93		ensure("2 prefersMature", aa.prefersMature());
 94		ensure("2 prefersAdult",  !aa.prefersAdult());
 95		
 96		cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT);
 97		ensure("3 prefersPG",     !aa.prefersPG());
 98		ensure("3 prefersMature", aa.prefersMature());
 99		ensure("3 prefersAdult",  aa.prefersAdult());
100    }
101    
102	template<> template<>
103	void agentaccess_object_t::test<2>()
104	{
105		LLControlGroup cgr("test");
106		cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", FALSE);
107		LLAgentAccess aa(cgr);
108		
109		// make sure default is PG
110		ensure("1 isTeen",     aa.isTeen());
111		ensure("1 isMature",   !aa.isMature());
112		ensure("1 isAdult",    !aa.isAdult());
113		
114		// this is kinda bad -- setting this forces maturity to MATURE but !teen != Mature anymore
115		aa.setTeen(false);
116		ensure("2 isTeen",     !aa.isTeen());
117		ensure("2 isMature",   aa.isMature());
118		ensure("2 isAdult",    !aa.isAdult());
119
120		// have to flip it back and make sure it still works
121		aa.setTeen(true);
122		ensure("3 isTeen",     aa.isTeen());
123		ensure("3 isMature",   !aa.isMature());
124		ensure("3 isAdult",    !aa.isAdult());		
125
126		// check the conversion routine
127		ensure_equals("1 conversion", SIM_ACCESS_PG, aa.convertTextToMaturity('P'));
128		ensure_equals("2 conversion", SIM_ACCESS_MATURE, aa.convertTextToMaturity('M'));
129		ensure_equals("3 conversion", SIM_ACCESS_ADULT, aa.convertTextToMaturity('A'));
130		ensure_equals("4 conversion", SIM_ACCESS_MIN, aa.convertTextToMaturity('Q'));
131		
132		// now try the other method of setting it - PG
133		aa.setMaturity('P');
134		ensure("4 isTeen",     aa.isTeen());
135		ensure("4 isMature",   !aa.isMature());
136		ensure("4 isAdult",    !aa.isAdult());
137		
138		// Mature
139		aa.setMaturity('M');
140		ensure("5 isTeen",     !aa.isTeen());
141		ensure("5 isMature",   aa.isMature());
142		ensure("5 isAdult",    !aa.isAdult());
143		
144		// Adult
145		aa.setMaturity('A');
146		ensure("6 isTeen",     !aa.isTeen());
147		ensure("6 isMature",   aa.isMature());
148		ensure("6 isAdult",    aa.isAdult());
149		
150	}
151
152	template<> template<>
153	void agentaccess_object_t::test<3>()
154	{
155		LLControlGroup cgr("test");
156		cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", FALSE);
157		LLAgentAccess aa(cgr);
158		
159		ensure("starts normal", !aa.isGodlike());
160		aa.setGodLevel(GOD_NOT);
161		ensure("stays normal", !aa.isGodlike());
162		aa.setGodLevel(GOD_FULL);
163		ensure("sets full", aa.isGodlike());
164		aa.setGodLevel(GOD_NOT);
165		ensure("resets normal", !aa.isGodlike());
166		aa.setAdminOverride(true);
167		ensure("admin true", aa.getAdminOverride());
168		ensure("overrides 1", aa.isGodlike());
169		aa.setGodLevel(GOD_FULL);
170		ensure("overrides 2", aa.isGodlike());
171		aa.setAdminOverride(false);
172		ensure("admin false", !aa.getAdminOverride());
173		ensure("overrides 3", aa.isGodlike());
174    }
175    
176	template<> template<>
177	void agentaccess_object_t::test<4>()
178	{
179		LLControlGroup cgr("test");
180		cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", FALSE);
181		LLAgentAccess aa(cgr);
182		
183		ensure("1 pg to start", aa.wantsPGOnly());
184		ensure("2 pg to start", !aa.canAccessMature());
185		ensure("3 pg to start", !aa.canAccessAdult());
186		
187		aa.setGodLevel(GOD_FULL);
188		ensure("1 full god", !aa.wantsPGOnly());
189		ensure("2 full god", aa.canAccessMature());
190		ensure("3 full god", aa.canAccessAdult());
191				
192		aa.setGodLevel(GOD_NOT);
193		aa.setAdminOverride(true);
194		ensure("1 admin mode", !aa.wantsPGOnly());
195		ensure("2 admin mode", aa.canAccessMature());
196		ensure("3 admin mode", aa.canAccessAdult());
197
198		aa.setAdminOverride(false);
199		aa.setMaturity('M');
200		// preferred is still pg by default
201		ensure("1 mature pref pg", aa.wantsPGOnly());
202		ensure("2 mature pref pg", !aa.canAccessMature());
203		ensure("3 mature pref pg", !aa.canAccessAdult());
204		
205		cgr.setU32("PreferredMaturity", SIM_ACCESS_MATURE);
206		ensure("1 mature", !aa.wantsPGOnly());
207		ensure("2 mature", aa.canAccessMature());
208		ensure("3 mature", !aa.canAccessAdult());
209		
210		cgr.setU32("PreferredMaturity", SIM_ACCESS_PG);
211		ensure("1 mature pref pg", aa.wantsPGOnly());
212		ensure("2 mature pref pg", !aa.canAccessMature());
213		ensure("3 mature pref pg", !aa.canAccessAdult());
214		
215		aa.setMaturity('A');
216		ensure("1 adult pref pg", aa.wantsPGOnly());
217		ensure("2 adult pref pg", !aa.canAccessMature());
218		ensure("3 adult pref pg", !aa.canAccessAdult());
219
220		cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT);
221		ensure("1 adult", !aa.wantsPGOnly());
222		ensure("2 adult", aa.canAccessMature());
223		ensure("3 adult", aa.canAccessAdult());
224
225		// make sure that even if pref is high, if access is low we block access
226		// this shouldn't occur in real life but we want to be safe
227		cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT);
228		aa.setMaturity('P');
229		ensure("1 pref adult, actual pg", aa.wantsPGOnly());
230		ensure("2 pref adult, actual pg", !aa.canAccessMature());
231		ensure("3 pref adult, actual pg", !aa.canAccessAdult());
232		
233	}
234
235	template<> template<>
236	void agentaccess_object_t::test<5>()
237	{
238		LLControlGroup cgr("test");
239		cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", FALSE);
240		LLAgentAccess aa(cgr);
241		
242		ensure("1 transition starts false", !aa.isInTransition());
243		aa.setTransition();
244		ensure("2 transition now true", aa.isInTransition());
245	}
246
247	template<> template<>
248	void agentaccess_object_t::test<6>()
249	{
250		LLControlGroup cgr("test");
251		cgr.declareU32("PreferredMaturity", SIM_ACCESS_PG, "declared_for_test", FALSE);
252		LLAgentAccess aa(cgr);
253		
254		cgr.setU32("PreferredMaturity", SIM_ACCESS_ADULT);
255		aa.setMaturity('M');
256		ensure("1 preferred maturity pegged to M when maturity is M", cgr.getU32("PreferredMaturity") == SIM_ACCESS_MATURE);
257		
258		aa.setMaturity('P');
259		ensure("1 preferred maturity pegged to P when maturity is P", cgr.getU32("PreferredMaturity") == SIM_ACCESS_PG);
260	}
261}
262
263