diff options
Diffstat (limited to 'indra')
| -rw-r--r-- | indra/cmake/GoogleMock.cmake | 27 | ||||
| -rw-r--r-- | indra/cmake/LLAddBuildTest.cmake | 11 | ||||
| -rw-r--r-- | indra/llmessage/lliohttpserver.cpp | 14 | ||||
| -rw-r--r-- | indra/llmessage/llxfermanager.cpp | 36 | ||||
| -rw-r--r-- | indra/llmessage/tests/llmockhttpclient.h | 61 | ||||
| -rw-r--r-- | indra/llprimitive/llprimitive.cpp | 78 | ||||
| -rw-r--r-- | indra/llprimitive/llprimitive.h | 25 | ||||
| -rw-r--r-- | indra/llprimitive/llprimtexturelist.cpp | 5 | ||||
| -rw-r--r-- | indra/lscript/lscript_compile/lscript_tree.cpp | 17 | ||||
| -rw-r--r-- | indra/test/CMakeLists.txt | 17 | ||||
| -rw-r--r-- | indra/test/test.cpp | 6 | 
11 files changed, 257 insertions, 40 deletions
| diff --git a/indra/cmake/GoogleMock.cmake b/indra/cmake/GoogleMock.cmake new file mode 100644 index 0000000000..ca5a8034ba --- /dev/null +++ b/indra/cmake/GoogleMock.cmake @@ -0,0 +1,27 @@ +# -*- cmake -*- +include(Prebuilt) +include(Linking) + +use_prebuilt_binary(googlemock) + +set(GOOGLEMOCK_INCLUDE_DIRS  +    ${LIBS_PREBUILT_DIR}/include) + +if (LINUX) +    set(GOOGLEMOCK_LIBRARIES  +        gmock   +        gtest) +elseif(WINDOWS) +    set(GOOGLEMOCK_LIBRARIES  +        gmock) +    set(GOOGLEMOCK_INCLUDE_DIRS  +        ${LIBS_PREBUILT_DIR}/include +        ${LIBS_PREBUILT_DIR}/include/gmock +        ${LIBS_PREBUILT_DIR}/include/gmock/boost/tr1/tr1) +elseif(DARWIN) +    set(GOOGLEMOCK_LIBRARIES +        gmock +        gtest) +endif(LINUX) + + diff --git a/indra/cmake/LLAddBuildTest.cmake b/indra/cmake/LLAddBuildTest.cmake index 4a61725e09..4da0824120 100644 --- a/indra/cmake/LLAddBuildTest.cmake +++ b/indra/cmake/LLAddBuildTest.cmake @@ -13,6 +13,8 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources)    #    # WARNING: do NOT modify this code without working with poppy or daveh -    # there is another branch that will conflict heavily with any changes here. +INCLUDE(GoogleMock) +    IF(LL_TEST_VERBOSE)      MESSAGE("LL_ADD_PROJECT_UNIT_TESTS UNITTEST_PROJECT_${project} sources: ${sources}") @@ -32,8 +34,10 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources)      ${LLMATH_INCLUDE_DIRS}      ${LLCOMMON_INCLUDE_DIRS}      ${LIBS_OPEN_DIR}/test +    ${GOOGLEMOCK_INCLUDE_DIRS}      )    SET(alltest_LIBRARIES +    ${GOOGLEMOCK_LIBRARIES}      ${PTHREAD_LIBRARY}      ${WINDOWS_LIBRARIES}      ) @@ -42,6 +46,11 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources)      ${CMAKE_SOURCE_DIR}/test/test.h      ) +  # Use the default flags +  if (LINUX) +    SET(CMAKE_EXE_LINKER_FLAGS "") +  endif (LINUX) +    # start the source test executable definitions    SET(${project}_TEST_OUTPUT "")    FOREACH (source ${sources}) @@ -84,9 +93,9 @@ MACRO(LL_ADD_PROJECT_UNIT_TESTS project sources)        MESSAGE("LL_ADD_PROJECT_UNIT_TESTS ${name}_test_additional_INCLUDE_DIRS ${${name}_test_additional_INCLUDE_DIRS}")      ENDIF(LL_TEST_VERBOSE) +      # Setup target      ADD_EXECUTABLE(PROJECT_${project}_TEST_${name} ${${name}_test_SOURCE_FILES}) -      #      # Per-codefile additional / external project dep and lib dep property extraction      # diff --git a/indra/llmessage/lliohttpserver.cpp b/indra/llmessage/lliohttpserver.cpp index 83dfa94f00..ce815cc85b 100644 --- a/indra/llmessage/lliohttpserver.cpp +++ b/indra/llmessage/lliohttpserver.cpp @@ -520,7 +520,7 @@ protected:  	 * seek orfor string assignment.  	 * @returns Returns true if a line was found.  	 */ -	bool readLine( +	bool readHeaderLine(  		const LLChannelDescriptors& channels,  		buffer_ptr_t buffer,  		U8* dest, @@ -591,7 +591,7 @@ LLHTTPResponder::~LLHTTPResponder()  	//lldebugs << "destroying LLHTTPResponder" << llendl;  } -bool LLHTTPResponder::readLine( +bool LLHTTPResponder::readHeaderLine(  	const LLChannelDescriptors& channels,  	buffer_ptr_t buffer,  	U8* dest, @@ -669,7 +669,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(  #endif  		PUMP_DEBUG; -		if(readLine(channels, buffer, (U8*)buf, len)) +		if(readHeaderLine(channels, buffer, (U8*)buf, len))  		{  			bool read_next_line = false;  			bool parse_all = true; @@ -733,7 +733,13 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(  					if(read_next_line)  					{  						len = HEADER_BUFFER_SIZE;	 -						readLine(channels, buffer, (U8*)buf, len); +						if (!readHeaderLine(channels, buffer, (U8*)buf, len)) +						{ +							// Failed to read the header line, probably too long. +							// readHeaderLine already marked the channel/buffer as bad. +							keep_parsing = false; +							break; +						}  					}  					if(0 == len)  					{ diff --git a/indra/llmessage/llxfermanager.cpp b/indra/llmessage/llxfermanager.cpp index 08c9192c9f..209bdb2249 100644 --- a/indra/llmessage/llxfermanager.cpp +++ b/indra/llmessage/llxfermanager.cpp @@ -760,30 +760,36 @@ static bool remove_prefix(std::string& filename, const std::string& prefix)  static bool verify_cache_filename(const std::string& filename)  {  	//NOTE: This routine is only used to check file names that our own -	// code places in the cache directory.  As such, it can be limited -	// to this very restrictive file name pattern.  It does not need to -	// handle other characters. - +	// code places in the cache directory.	As such, it can be limited +	// to this very restrictive file name pattern.	It does not need to +	// handle other characters. The only known uses of this are (with examples): +	//	sim to sim object pass:			fc0b72d8-9456-63d9-a802-a557ef847313.tmp +	//	sim to viewer mute list:		mute_b78eacd0-1244-448e-93ca-28ede242f647.tmp +	//	sim to viewer task inventory:	inventory_d8ab59d2-baf0-0e79-c4c2-a3f99b9fcf45.tmp +	 +	//IMPORTANT: Do not broaden the filenames accepted by this routine +	// without careful analysis. Anything allowed by this function can +	// be downloaded by the viewer. +	  	size_t len = filename.size(); -	//const boost::regex expr("[a-zA-Z0-9][-_.a-zA-Z0-9]<0,49>"); -	if (len < 1 || len > 50) -	{ +	//const boost::regex expr("[0-9a-zA-Z_-]<1,46>\.tmp"); +	if (len < 5 || len > 50) +	{	  		return false;  	} -	for(unsigned i=0; i<len; ++i) -	{ +	for(size_t i=0; i<(len-4); ++i) +	{	  		char c = filename[i]; -		bool ok = isalnum(c); -		if (!ok && i > 0) -		{ -			ok = '_'==c || '-'==c || '.'==c; -		} +		bool ok = isalnum(c) || '_'==c || '-'==c;  		if (!ok)  		{  			return false;  		}  	} -	return true; +	return filename[len-4] == '.' +		&& filename[len-3] == 't' +		&& filename[len-2] == 'm' +		&& filename[len-1] == 'p';  }  void LLXferManager::processFileRequest (LLMessageSystem *mesgsys, void ** /*user_data*/) diff --git a/indra/llmessage/tests/llmockhttpclient.h b/indra/llmessage/tests/llmockhttpclient.h new file mode 100644 index 0000000000..2f55e97fcc --- /dev/null +++ b/indra/llmessage/tests/llmockhttpclient.h @@ -0,0 +1,61 @@ +/**  + * @file  + * @brief  + * + * $LicenseInfo:firstyear=2008&license=viewergpl$ + *  + * Copyright (c) 2008, Linden Research, Inc. + *  + * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of + * this source code is governed by the Linden Lab Source Code Disclosure + * Agreement ("Agreement") previously entered between you and Linden + * Lab. By accessing, using, copying, modifying or distributing this + * software, you acknowledge that you have been informed of your + * obligations under the Agreement and agree to abide by those obligations. + *  + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. + * $/LicenseInfo$ + */ + +/* Macro Definitions */ +#ifndef LL_LLMOCKHTTPCLIENT_H +#define LL_LLMOCKHTTPCLIENT_H + +#include "linden_common.h" +#include "llhttpclientinterface.h" + +#include <gmock/gmock.h> + +class LLMockHTTPClient : public LLHTTPClientInterface +{ +public: +  MOCK_METHOD2(get, void(const std::string& url, LLCurl::ResponderPtr responder)); +  MOCK_METHOD3(get, void(const std::string& url, LLCurl::ResponderPtr responder, const LLSD& headers)); +  MOCK_METHOD3(put, void(const std::string& url, const LLSD& body, LLCurl::ResponderPtr responder)); +}; + +// A helper to match responder types +template<typename T> +struct ResponderType +{ +	bool operator()(LLCurl::ResponderPtr ptr) const +	{ +		T* p = dynamic_cast<T*>(ptr.get()); +		return p != NULL; +	} +}; + +inline bool operator==(const LLSD& l, const LLSD& r) +{ +	std::ostringstream ls, rs; +	ls << l; +	rs << r; +	return ls.str() == rs.str(); + +} + + +#endif //LL_LLMOCKHTTPCLIENT_H + diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp index 13facc0d58..58aaf97a76 100644 --- a/indra/llprimitive/llprimitive.cpp +++ b/indra/llprimitive/llprimitive.cpp @@ -1314,6 +1314,8 @@ BOOL LLNetworkData::isValid(U16 param_type, U32 size)  		return (size == 16);  	case PARAMS_SCULPT:  		return (size == 17); +	case PARAMS_LIGHT_IMAGE: +		return (size == 28);  	}  	return FALSE; @@ -1646,3 +1648,79 @@ bool LLSculptParams::fromLLSD(LLSD& sd)  	return false;  } +//============================================================================ + +LLLightImageParams::LLLightImageParams() +{ +	mType = PARAMS_LIGHT_IMAGE; +	mParams.setVec(F_PI*0.5f, 0.f, 0.f); +} + +BOOL LLLightImageParams::pack(LLDataPacker &dp) const +{ +	dp.packUUID(mLightTexture, "texture"); +	dp.packVector3(mParams, "params"); + +	return TRUE; +} + +BOOL LLLightImageParams::unpack(LLDataPacker &dp) +{ +	dp.unpackUUID(mLightTexture, "texture"); +	dp.unpackVector3(mParams, "params"); +	 +	return TRUE; +} + +bool LLLightImageParams::operator==(const LLNetworkData& data) const +{ +	if (data.mType != PARAMS_LIGHT_IMAGE) +	{ +		return false; +	} +	 +	const LLLightImageParams *param = (const LLLightImageParams*)&data; +	if ( (param->mLightTexture != mLightTexture) ) +	{ +		return false; +	} + +	if ( (param->mParams != mParams ) ) +	{ +		return false; +	} +	 +	return true; +} + +void LLLightImageParams::copy(const LLNetworkData& data) +{ +	const LLLightImageParams *param = (LLLightImageParams*)&data; +	mLightTexture = param->mLightTexture; +	mParams = param->mParams; +} + + + +LLSD LLLightImageParams::asLLSD() const +{ +	LLSD sd; +	 +	sd["texture"] = mLightTexture; +	sd["params"] = mParams.getValue(); +		 +	return sd; +} + +bool LLLightImageParams::fromLLSD(LLSD& sd) +{ +	if (sd.has("texture")) +	{ +		setLightTexture( sd["texture"] ); +		setParams( sd["params"] ); +		return true; +	}  +	 +	return false; +} + diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h index c25df0a40f..01389a0e04 100644 --- a/indra/llprimitive/llprimitive.h +++ b/indra/llprimitive/llprimitive.h @@ -107,7 +107,8 @@ public:  	{  		PARAMS_FLEXIBLE = 0x10,  		PARAMS_LIGHT    = 0x20, -		PARAMS_SCULPT   = 0x30 +		PARAMS_SCULPT   = 0x30, +		PARAMS_LIGHT_IMAGE = 0x40,  	};  public: @@ -267,6 +268,28 @@ public:  	U8 getSculptType()                      { return mSculptType; }  }; +class LLLightImageParams : public LLNetworkData +{ +protected: +	LLUUID mLightTexture; +	LLVector3 mParams; +	 +public: +	LLLightImageParams(); +	/*virtual*/ BOOL pack(LLDataPacker &dp) const; +	/*virtual*/ BOOL unpack(LLDataPacker &dp); +	/*virtual*/ bool operator==(const LLNetworkData& data) const; +	/*virtual*/ void copy(const LLNetworkData& data); +	LLSD asLLSD() const; +	operator LLSD() const { return asLLSD(); } +	bool fromLLSD(LLSD& sd); + +	void setLightTexture(const LLUUID& id) { mLightTexture = id; } +	LLUUID getLightTexture() const         { return mLightTexture; } +	void setParams(const LLVector3& params) { mParams = params; } +	LLVector3 getParams() const			   { return mParams; } +	 +};  class LLPrimitive : public LLXform diff --git a/indra/llprimitive/llprimtexturelist.cpp b/indra/llprimitive/llprimtexturelist.cpp index c1dde32993..b02d4c50bd 100644 --- a/indra/llprimitive/llprimtexturelist.cpp +++ b/indra/llprimitive/llprimtexturelist.cpp @@ -134,13 +134,12 @@ S32 LLPrimTextureList::copyTexture(const U8 index, const LLTextureEntry& te)  {  	if (S32(index) >= mEntryList.size())  	{ -		// TODO -- assert here  		S32 current_size = mEntryList.size(); -		llerrs << "index = " << S32(index) << "  current_size = " << current_size << llendl; +		llwarns << "ignore copy of index = " << S32(index) << " into texture entry list of size = " << current_size << llendl;  		return TEM_CHANGE_NONE;  	} -	// we're changing an existing entry +		// we're changing an existing entry  	llassert(mEntryList[index]);  	delete (mEntryList[index]);  	if  (&te) diff --git a/indra/lscript/lscript_compile/lscript_tree.cpp b/indra/lscript/lscript_compile/lscript_tree.cpp index a15f1fee11..7fa115bb20 100644 --- a/indra/lscript/lscript_compile/lscript_tree.cpp +++ b/indra/lscript/lscript_compile/lscript_tree.cpp @@ -8799,8 +8799,7 @@ void LLScriptIf::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass p  		}  		break;  	case LSCP_PRUNE: -		prunearg = TRUE; -		mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); +		prunearg = FALSE;  		break;  	case LSCP_TYPE:  		mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); @@ -8986,8 +8985,7 @@ void LLScriptFor::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass  		}  		break;  	case LSCP_PRUNE: -		prunearg = TRUE; -		mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); +		prunearg = FALSE;  		break;  	case LSCP_TYPE:  		if(mSequence) @@ -9091,8 +9089,7 @@ void LLScriptDoWhile::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompileP  		}  		break;  	case LSCP_PRUNE: -		prunearg = TRUE; -		mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); +		prunearg = FALSE;  		break;  	case LSCP_TYPE:  		mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); @@ -9168,8 +9165,7 @@ void LLScriptWhile::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePas  		}  		break;  	case LSCP_PRUNE: -		prunearg = TRUE; -		mStatement->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); +		prunearg = FALSE;  		break;  	case LSCP_TYPE:  		mExpression->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL); @@ -10137,10 +10133,7 @@ void LLScriptGlobalFunctions::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPT  			mStatements->recurse(fp, tabs, tabsize, pass, LSPRUNE_GLOBAL_NON_VOIDS, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);  			if (!prunearg)  			{ -				if (!gErrorToText.getErrors()) // Hide this error when a state change has been made in a global function -				{ -					gErrorToText.writeError(fp, this, LSERROR_NO_RETURN); -				} +				gErrorToText.writeError(fp, this, LSERROR_NO_RETURN);  			}  		}  		else diff --git a/indra/test/CMakeLists.txt b/indra/test/CMakeLists.txt index 49a0a8f361..53109ca196 100644 --- a/indra/test/CMakeLists.txt +++ b/indra/test/CMakeLists.txt @@ -14,6 +14,7 @@ include(LScript)  include(Linking)  include(Tut)  include(Boost) +include(GoogleMock)  include_directories(      ${LLCOMMON_INCLUDE_DIRS} @@ -24,6 +25,7 @@ include_directories(      ${LLVFS_INCLUDE_DIRS}      ${LLXML_INCLUDE_DIRS}      ${LSCRIPT_INCLUDE_DIRS} +    ${GOOGLEMOCK_INCLUDE_DIRS}      )  set(test_SOURCE_FILES @@ -121,6 +123,7 @@ target_link_libraries(test      ${LLXML_LIBRARIES}      ${LSCRIPT_LIBRARIES}      ${LLCOMMON_LIBRARIES} +    ${GOOGLEMOCK_LIBRARIES}      ${APRICONV_LIBRARIES}      ${PTHREAD_LIBRARY}      ${WINDOWS_LIBRARIES} @@ -137,12 +140,18 @@ endif (WINDOWS)  get_target_property(TEST_EXE test LOCATION) +SET(TEST_CMD ${TEST_EXE} --touch=${TEST_OUTPUT} --sourcedir=${CMAKE_CURRENT_SOURCE_DIR}) + +SET(TEST_LD_CMD  +  ${CMAKE_COMMAND}  +  -DLD_LIBRARY_PATH=${ARCH_PREBUILT_DIRS}:/usr/lib +  -DTEST_CMD:STRING="${TEST_CMD}"  +  -P ${CMAKE_SOURCE_DIR}/cmake/RunBuildTest.cmake +  ) +  add_custom_command(    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpp_tests_ok.txt -  COMMAND ${TEST_EXE} -  ARGS -    --output=${CMAKE_CURRENT_BINARY_DIR}/cpp_test_results.txt -    --touch=${CMAKE_CURRENT_BINARY_DIR}/cpp_tests_ok.txt +  COMMAND ${TEST_LD_CMD}    DEPENDS test    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}    COMMENT "C++ unit tests" diff --git a/indra/test/test.cpp b/indra/test/test.cpp index ba81c6e49e..c9e985c914 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -54,6 +54,9 @@  #	include "ctype_workaround.h"  #endif +#include <gmock/gmock.h> +#include <gtest/gtest.h> +  namespace tut  {  	std::string sSourceDir; @@ -238,6 +241,9 @@ void wouldHaveCrashed(const std::string& message)  int main(int argc, char **argv)  { +	// The following line must be executed to initialize Google Mock +	// (and Google Test) before running the tests. +	::testing::InitGoogleMock(&argc, argv);  	LLError::initForApplication(".");  	LLError::setFatalFunction(wouldHaveCrashed);  	LLError::setDefaultLevel(LLError::LEVEL_ERROR); | 
