PageRenderTime 39ms CodeModel.GetById 12ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/test/message_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 148 lines | 112 code | 7 blank | 29 comment | 1 complexity | c29b80962b1c09a37884ca1743134d3f MD5 | raw file
  1/**
  2 * @file lldatapacker_tut.cpp
  3 * @date 2007-04
  4 * @brief LLDataPacker test cases.
  5 *
  6 * $LicenseInfo:firstyear=2007&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 <tut/tut.hpp>
 29#include "linden_common.h"
 30#include "lltut.h"
 31
 32#include "llapr.h"
 33#include "llmessageconfig.h"
 34#include "llsdserialize.h"
 35#include "llversionserver.h"
 36#include "message.h"
 37#include "message_prehash.h"
 38
 39namespace
 40{
 41	struct Response : public LLHTTPNode::Response
 42	{
 43		virtual void result(const LLSD&) {}
 44		virtual void status(S32 code, const std::string& message) 
 45		{
 46			mStatus = code;
 47		}
 48		virtual void extendedResult(S32 code, const std::string& message, const LLSD& headers) { }
 49		S32 mStatus;
 50	};
 51}
 52
 53namespace tut
 54{	
 55	struct LLMessageSystemTestData 
 56	{
 57		std::string mTestConfigDir;
 58		std::string mSep;
 59
 60		LLMessageSystemTestData()
 61		{
 62			static bool init = false;
 63			if(!init)
 64			{
 65				ll_init_apr();
 66				//init_prehash_data();
 67				init = true;
 68			}
 69			const F32 circuit_heartbeat_interval=5;
 70			const F32 circuit_timeout=100;
 71
 72
 73			// currently test disconnected message system
 74			start_messaging_system("notafile", 13035,
 75								   LL_VERSION_MAJOR,
 76								   LL_VERSION_MINOR,        
 77								   LL_VERSION_PATCH,        
 78								   FALSE,        
 79								   "notasharedsecret",
 80								   NULL,
 81								   false,
 82								   circuit_heartbeat_interval,
 83								   circuit_timeout
 84								   );
 85			// generate temp dir
 86			std::ostringstream ostr;
 87#if LL_WINDOWS
 88			mSep = "\\";
 89			ostr << "C:" << mSep;
 90#else
 91			mSep = "/";
 92			ostr << mSep << "tmp" << mSep;
 93#endif
 94			LLUUID random;
 95			random.generate();
 96			ostr << "message-test-" << random;
 97			mTestConfigDir = ostr.str();
 98			LLFile::mkdir(mTestConfigDir);
 99			writeConfigFile(LLSD());
100			LLMessageConfig::initClass("simulator", ostr.str());
101		}
102
103		~LLMessageSystemTestData()
104		{
105			// not end_messaging_system()
106			delete gMessageSystem;
107			gMessageSystem = NULL;
108
109			// rm contents of temp dir
110			std::ostringstream ostr;
111			ostr << mTestConfigDir << mSep << "message.xml";
112			int rmfile = LLFile::remove(ostr.str());
113			ensure_equals("rmfile value", rmfile, 0);
114
115			// rm temp dir
116			int rmdir = LLFile::rmdir(mTestConfigDir);
117			ensure_equals("rmdir value", rmdir, 0);
118		}
119
120		void writeConfigFile(const LLSD& config)
121		{
122			std::ostringstream ostr;
123			ostr << mTestConfigDir << mSep << "message.xml";
124			llofstream file(ostr.str());
125			if (file.is_open())
126			{
127				LLSDSerialize::toPrettyXML(config, file);
128			}
129			file.close();
130		}
131	};
132	
133	typedef test_group<LLMessageSystemTestData>	LLMessageSystemTestGroup;
134	typedef LLMessageSystemTestGroup::object		LLMessageSystemTestObject;
135	LLMessageSystemTestGroup messageTestGroup("LLMessageSystem");
136	
137	template<> template<>
138	void LLMessageSystemTestObject::test<1>()
139		// dispatch unknown message
140	{
141		const char* name = "notamessasge";
142		const LLSD message;
143		const LLPointer<Response> response = new Response();
144		gMessageSystem->dispatch(name, message, response);
145		ensure_equals(response->mStatus, 404);
146	}
147}
148