diff options
Diffstat (limited to 'indra/test')
42 files changed, 3758 insertions, 927 deletions
diff --git a/indra/test/CMakeLists.txt b/indra/test/CMakeLists.txt index 32579e4fe2..66c78a86c4 100644 --- a/indra/test/CMakeLists.txt +++ b/indra/test/CMakeLists.txt @@ -10,7 +10,12 @@ include(LLMath) include(LLMessage) include(LLVFS) include(LLXML) +include(LScript) include(Linking) +include(Tut) +include(LLAddBuildTest) + +include(GoogleMock) include_directories( ${LLCOMMON_INCLUDE_DIRS} @@ -20,63 +25,45 @@ include_directories( ${LLINVENTORY_INCLUDE_DIRS} ${LLVFS_INCLUDE_DIRS} ${LLXML_INCLUDE_DIRS} + ${LSCRIPT_INCLUDE_DIRS} + ${GOOGLEMOCK_INCLUDE_DIRS} ) set(test_SOURCE_FILES - common.cpp - inventory.cpp io.cpp - llapp_tut.cpp - llbase64_tut.cpp +# llapp_tut.cpp # Temporarily removed until thread issues can be solved llblowfish_tut.cpp llbuffer_tut.cpp - lldatabase_tut.cpp - lldate_tut.cpp - llerror_tut.cpp - llhost_tut.cpp + lldoubledispatch_tut.cpp + llevents_tut.cpp llhttpdate_tut.cpp llhttpclient_tut.cpp llhttpnode_tut.cpp - llinventoryparcel_tut.cpp lliohttpserver_tut.cpp - lljoint_tut.cpp - llmime_tut.cpp llmessageconfig_tut.cpp - llnamevalue_tut.cpp llpermissions_tut.cpp llpipeutil.cpp - llquaternion_tut.cpp - llrandom_tut.cpp llsaleinfo_tut.cpp + llscriptresource_tut.cpp llsdmessagebuilder_tut.cpp llsdmessagereader_tut.cpp llsd_new_tut.cpp - llsdserialize_tut.cpp llsdutil_tut.cpp llservicebuilder_tut.cpp llstreamtools_tut.cpp lltemplatemessagebuilder_tut.cpp - lltiming_tut.cpp + lltimestampcache_tut.cpp + lltranscode_tut.cpp lltut.cpp - lluri_tut.cpp lluuidhashmap_tut.cpp - llxfer_tut.cpp - math.cpp message_tut.cpp - reflection_tut.cpp test.cpp - v2math_tut.cpp - v3color_tut.cpp - v3dmath_tut.cpp - v3math_tut.cpp - v4color_tut.cpp - v4coloru_tut.cpp - v4math_tut.cpp ) set(test_HEADER_FILES CMakeLists.txt + debug.h llpipeutil.h llsdtraits.h lltut.h @@ -88,10 +75,16 @@ if (NOT WINDOWS) ) endif (NOT WINDOWS) +if (NOT DARWIN) + list(APPEND test_SOURCE_FILES + lldatabase_tut.cpp + ) +endif (NOT DARWIN) + set_source_files_properties(${test_HEADER_FILES} PROPERTIES HEADER_FILE_ONLY TRUE) -list(APPEND test_SOURC_FILES ${test_HEADER_FILES}) +list(APPEND test_SOURCE_FILES ${test_HEADER_FILES}) add_executable(test ${test_SOURCE_FILES}) @@ -102,31 +95,39 @@ target_link_libraries(test ${LLMATH_LIBRARIES} ${LLVFS_LIBRARIES} ${LLXML_LIBRARIES} + ${LSCRIPT_LIBRARIES} ${LLCOMMON_LIBRARIES} + ${EXPAT_LIBRARIES} + ${GOOGLEMOCK_LIBRARIES} + ${APRICONV_LIBRARIES} ${PTHREAD_LIBRARY} ${WINDOWS_LIBRARIES} + ${BOOST_PROGRAM_OPTIONS_LIBRARY} + ${BOOST_REGEX_LIBRARY} + ${DL_LIBRARY} + ${GOOGLE_PERFTOOLS_LIBRARIES} ) if (WINDOWS) set_target_properties(test PROPERTIES - LINK_FLAGS "/NODEFAULTLIB:MSVCRT" - LINK_FLAGS_DEBUG "/NODEFAULTLIB:LIBCMT" + LINK_FLAGS "/NODEFAULTLIB:LIBCMT" + LINK_FLAGS_DEBUG "/NODEFAULTLIB:\"LIBCMT;LIBCMTD;MSVCRT\"" ) endif (WINDOWS) get_target_property(TEST_EXE test LOCATION) -add_custom_command( +SET_TEST_PATH(LD_LIBRARY_PATH) +LL_TEST_COMMAND(command "${LD_LIBRARY_PATH}" + "${TEST_EXE}" "--output=${CMAKE_CURRENT_BINARY_DIR}/cpp_test_results.txt" "--touch=${CMAKE_CURRENT_BINARY_DIR}/cpp_tests_ok.txt") +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 ${command} DEPENDS test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "C++ unit tests" - ) + ) set(test_results ${CMAKE_CURRENT_BINARY_DIR}/cpp_tests_ok.txt) @@ -139,8 +140,10 @@ if (EXISTS /etc/debian_version_FAIL) COMMAND ${PYTHON_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/test.py + --mode=static --output=${CMAKE_CURRENT_BINARY_DIR}/py_test_results.txt --touch=${CMAKE_CURRENT_BINARY_DIR}/py_tests_ok.txt + --mode=static DEPENDS test.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Python unit tests" diff --git a/indra/test/debug.h b/indra/test/debug.h new file mode 100644 index 0000000000..d61eba651b --- /dev/null +++ b/indra/test/debug.h @@ -0,0 +1,85 @@ +/** + * @file debug.h + * @author Nat Goodspeed + * @date 2009-05-28 + * @brief Debug output for unit test code + * + * $LicenseInfo:firstyear=2009&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#if ! defined(LL_DEBUG_H) +#define LL_DEBUG_H + +#include <iostream> + +/***************************************************************************** +* Debugging stuff +*****************************************************************************/ +// This class is intended to illuminate entry to a given block, exit from the +// same block and checkpoints along the way. It also provides a convenient +// place to turn std::cout output on and off. +class Debug +{ +public: + Debug(const std::string& block): + mBlock(block) + { + (*this)("entry"); + } + + ~Debug() + { + (*this)("exit"); + } + + void operator()(const std::string& status) + { +#if defined(DEBUG_ON) + std::cout << mBlock << ' ' << status << std::endl; +#endif + } + +private: + const std::string mBlock; +}; + +// It's often convenient to use the name of the enclosing function as the name +// of the Debug block. +#define DEBUG Debug debug(__FUNCTION__) + +// These BEGIN/END macros are specifically for debugging output -- please +// don't assume you must use such for coroutines in general! They only help to +// make control flow (as well as exception exits) explicit. +#define BEGIN \ +{ \ + DEBUG; \ + try + +#define END \ + catch (...) \ + { \ + debug("*** exceptional "); \ + throw; \ + } \ +} + +#endif /* ! defined(LL_DEBUG_H) */ diff --git a/indra/test/io.cpp b/indra/test/io.cpp index 3bb8f62ffb..c06c1b153b 100644 --- a/indra/test/io.cpp +++ b/indra/test/io.cpp @@ -4,30 +4,25 @@ * @date 2005-10-02 * @brief Tests for io classes and helpers * - * $LicenseInfo:firstyear=2005&license=viewergpl$ - * - * Copyright (c) 2005-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/test/llassetuploadqueue_tut.cpp b/indra/test/llassetuploadqueue_tut.cpp new file mode 100644 index 0000000000..ec952e0058 --- /dev/null +++ b/indra/test/llassetuploadqueue_tut.cpp @@ -0,0 +1,195 @@ +/** + * @file asset_upload_queue_tut.cpp + * @brief Tests for newview/llassetuploadqueue.cpp + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "lltut.h" + +#include "mock_http_client.h" +#include "../newview/llassetuploadqueue.cpp" + +// Mock implementation. +LLAssetUploadResponder::LLAssetUploadResponder(const LLSD& post_data, + const LLUUID& vfile_id, + LLAssetType::EType asset_type) +{ +} + +LLAssetUploadResponder::LLAssetUploadResponder(const LLSD& post_data, const std::string& file_name) +{ +} + +LLAssetUploadResponder::~LLAssetUploadResponder() +{ +} + +void LLAssetUploadResponder::error(U32 statusNum, const std::string& reason) +{ +} + +void LLAssetUploadResponder::result(const LLSD& content) +{ +} + +void LLAssetUploadResponder::uploadUpload(const LLSD& content) +{ +} + +void LLAssetUploadResponder::uploadComplete(const LLSD& content) +{ +} + +void LLAssetUploadResponder::uploadFailure(const LLSD& content) +{ +} + +LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data, + const LLUUID& vfile_id, + LLAssetType::EType asset_type) : + LLAssetUploadResponder(post_data, vfile_id, asset_type) +{ +} + +LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data, + const std::string& file_name) : + LLAssetUploadResponder(post_data, file_name) +{ +} + +LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data, + const std::string& file_name, + const LLUUID& queue_id) : + LLAssetUploadResponder(post_data, file_name) +{ +} + +void LLUpdateTaskInventoryResponder::uploadComplete(const LLSD& content) +{ +} + +namespace tut +{ + class asset_upload_queue_test_data : public MockHttpClient {}; + typedef test_group<asset_upload_queue_test_data> asset_upload_queue_test; + typedef asset_upload_queue_test::object asset_upload_queue_object; + tut::asset_upload_queue_test asset_upload_queue("asset_upload_queue"); + + void queue(LLAssetUploadQueue& q, const std::string& filename) + { + LLUUID task_id; + LLUUID item_id; + BOOL is_running = FALSE; + BOOL is_target_mono = TRUE; + LLUUID queue_id; + q.queue(filename, task_id, item_id, is_running, is_target_mono, queue_id); + } + + class LLTestSupplier : public LLAssetUploadQueueSupplier + { + public: + + void set(LLAssetUploadQueue* queue) {mQueue = queue;} + + virtual LLAssetUploadQueue* get() const + { + return mQueue; + } + + private: + LLAssetUploadQueue* mQueue; + }; + + template<> template<> + void asset_upload_queue_object::test<1>() + { + setupTheServer(); + reset(); + LLTestSupplier* supplier = new LLTestSupplier(); + LLAssetUploadQueue q("http://localhost:8888/test/success", supplier); + supplier->set(&q); + queue(q, "foo.bar"); + ensure("upload queue not empty before request", q.isEmpty()); + runThePump(10); + ensure("upload queue not empty after request", q.isEmpty()); + } + + template<> template<> + void asset_upload_queue_object::test<2>() + { + reset(); + LLTestSupplier* supplier = new LLTestSupplier(); + LLAssetUploadQueue q("http://localhost:8888/test/error", supplier); + supplier->set(&q); + queue(q, "foo.bar"); + ensure("upload queue not empty before request", q.isEmpty()); + runThePump(10); + ensure("upload queue not empty after request", q.isEmpty()); + } + + template<> template<> + void asset_upload_queue_object::test<3>() + { + reset(); + LLTestSupplier* supplier = new LLTestSupplier(); + LLAssetUploadQueue q("http://localhost:8888/test/timeout", supplier); + supplier->set(&q); + queue(q, "foo.bar"); + ensure("upload queue not empty before request", q.isEmpty()); + runThePump(10); + ensure("upload queue not empty after request", q.isEmpty()); + } + + template<> template<> + void asset_upload_queue_object::test<4>() + { + reset(); + LLTestSupplier* supplier = new LLTestSupplier(); + LLAssetUploadQueue q("http://localhost:8888/test/success", supplier); + supplier->set(&q); + queue(q, "foo.bar"); + queue(q, "baz.bar"); + ensure("upload queue empty before request", !q.isEmpty()); + runThePump(10); + ensure("upload queue not empty before request", q.isEmpty()); + runThePump(10); + ensure("upload queue not empty after request", q.isEmpty()); + } + + template<> template<> + void asset_upload_queue_object::test<5>() + { + reset(); + LLTestSupplier* supplier = new LLTestSupplier(); + LLAssetUploadQueue q("http://localhost:8888/test/success", supplier); + supplier->set(&q); + queue(q, "foo.bar"); + runThePump(10); + ensure("upload queue not empty before request", q.isEmpty()); + queue(q, "baz.bar"); + ensure("upload queue not empty after request", q.isEmpty()); + runThePump(10); + killServer(); + } +} diff --git a/indra/test/llblowfish_tut.cpp b/indra/test/llblowfish_tut.cpp index 3081ac3855..2573cab81f 100644 --- a/indra/test/llblowfish_tut.cpp +++ b/indra/test/llblowfish_tut.cpp @@ -7,30 +7,25 @@ * openssl enc -bf-cbc -in blowfish.digits.txt -out blowfish.1.bin -K 00000000000000000000000000000000 -iv 0000000000000000 -p * openssl enc -bf-cbc -in blowfish.digits.txt -out blowfish.2.bin -K 526a1e07a19dbaed84c4ff08a488d15e -iv 0000000000000000 -p * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -57,8 +52,8 @@ namespace tut mInputSize = 36; } - bool matchFile(const char* filename, - const std::string& data) + bool matchFile(const std::string& filename, + const std::string& data) { LLFILE* fp = LLFile::fopen(filename, "rb"); if (!fp) @@ -66,7 +61,7 @@ namespace tut // sometimes test is run inside the indra directory std::string path = "test/"; path += filename; - fp = LLFile::fopen(path.c_str(), "rb"); + fp = LLFile::fopen(path, "rb"); } if (!fp) { @@ -93,9 +88,6 @@ namespace tut template<> template<> void blowfish_object::test<1>() { -#if !LL_LINUX - skip_fail("Blowfish only supported on Linux."); -#else LLUUID blank; LLBlowfishCipher cipher(&blank.mData[0], UUID_BYTES); @@ -108,15 +100,11 @@ namespace tut dst_len = cipher.requiredEncryptionSpace(8); ensure("encryption space 8", (dst_len == 16) ); -#endif // !LL_LINUX } template<> template<> void blowfish_object::test<2>() { -#if !LL_LINUX - skip_fail("Blowfish only supported on Linux."); -#else LLUUID blank; LLBlowfishCipher cipher(&blank.mData[0], UUID_BYTES); @@ -130,15 +118,11 @@ namespace tut result.resize(count); ensure("encrypt null key", matchFile("blowfish.1.bin", result)); -#endif // !LL_LINUX } template<> template<> void blowfish_object::test<3>() { -#if !LL_LINUX - skip_fail("Blowfish only supported on Linux."); -#else // same as base64 test id LLUUID id("526a1e07-a19d-baed-84c4-ff08a488d15e"); LLBlowfishCipher cipher(&id.mData[0], UUID_BYTES); @@ -153,6 +137,5 @@ namespace tut result.resize(count); ensure("encrypt real key", matchFile("blowfish.2.bin", result)); -#endif // !LL_LINUX } } diff --git a/indra/test/llbuffer_tut.cpp b/indra/test/llbuffer_tut.cpp index cd659ce9b8..dc1a5cdd3d 100644 --- a/indra/test/llbuffer_tut.cpp +++ b/indra/test/llbuffer_tut.cpp @@ -4,34 +4,29 @@ * @date 2007-03 * @brief llbuffer test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" #include "llbuffer.h" diff --git a/indra/test/lldatapacker_tut.cpp b/indra/test/lldatapacker_tut.cpp index 2b2085e0ae..cf2b7870ef 100644 --- a/indra/test/lldatapacker_tut.cpp +++ b/indra/test/lldatapacker_tut.cpp @@ -4,34 +4,29 @@ * @date 2007-02 * @brief LLDataPacker test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "lltut.h" #include "linden_common.h" #include "lldatapacker.h" diff --git a/indra/test/lldoubledispatch_tut.cpp b/indra/test/lldoubledispatch_tut.cpp new file mode 100644 index 0000000000..ad8f6454d4 --- /dev/null +++ b/indra/test/lldoubledispatch_tut.cpp @@ -0,0 +1,239 @@ +/** + * @file lldoubledispatch_tut.cpp + * @author Nat Goodspeed + * @date 2008-11-13 + * @brief Test for lldoubledispatch.h + * + * This program tests the DoubleDispatch class, using a variation on the example + * from Scott Meyers' "More Effective C++", Item 31. + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// Precompiled header +#include "linden_common.h" +// associated header +#include "lldoubledispatch.h" +// STL headers +// std headers +#include <string> +#include <iostream> +#include <typeinfo> +// external library headers +// other Linden headers +#include "lltut.h" + + +/*---------------------------- Class hierarchy -----------------------------*/ +// All objects are GameObjects. +class GameObject +{ +public: + GameObject(const std::string& name): mName(name) {} + virtual ~GameObject() {} + virtual std::string stringize() { return std::string(typeid(*this).name()) + " " + mName; } + +protected: + std::string mName; +}; + +// SpaceStation, Asteroid and SpaceShip are peer GameObjects. +struct SpaceStation: public GameObject +{ + SpaceStation(const std::string& name): GameObject(name) {} + // Only a dummy SpaceStation is constructed without a name + SpaceStation(): GameObject("dummy") {} +}; + +struct Asteroid: public GameObject +{ + Asteroid(const std::string& name): GameObject(name) {} + Asteroid(): GameObject("dummy") {} +}; + +struct SpaceShip: public GameObject +{ + SpaceShip(const std::string& name): GameObject(name) {} + SpaceShip(): GameObject("dummy") {} +}; + +// SpaceShip is specialized further into CommercialShip and MilitaryShip. +struct CommercialShip: public SpaceShip +{ + CommercialShip(const std::string& name): SpaceShip(name) {} + CommercialShip(): SpaceShip("dummy") {} +}; + +struct MilitaryShip: public SpaceShip +{ + MilitaryShip(const std::string& name): SpaceShip(name) {} + MilitaryShip(): SpaceShip("dummy") {} +}; + +/*-------------------------- Collision functions ---------------------------*/ +// This mechanism permits us to overcome a limitation of Meyers' approach: we +// can declare the parameter types exactly as we want, rather than having to +// make them all GameObject& parameters. +std::string shipAsteroid(SpaceShip& ship, Asteroid& rock) +{ +// std::cout << rock.stringize() << " has pulverized " << ship.stringize() << std::endl; + return "shipAsteroid"; +} + +std::string militaryShipAsteroid(MilitaryShip& ship, Asteroid& rock) +{ +// std::cout << rock.stringize() << " has severely damaged " << ship.stringize() << std::endl; + return "militaryShipAsteroid"; +} + +std::string shipStation(SpaceShip& ship, SpaceStation& dock) +{ +// std::cout << ship.stringize() << " has docked at " << dock.stringize() << std::endl; + return "shipStation"; +} + +std::string asteroidStation(Asteroid& rock, SpaceStation& dock) +{ +// std::cout << rock.stringize() << " has damaged " << dock.stringize() << std::endl; + return "asteroidStation"; +} + +/*------------------------------- Test code --------------------------------*/ +namespace tut +{ + struct dispatch_data + { + dispatch_data(): + home(new SpaceStation("Terra Station")), + obstacle(new Asteroid("Ganymede")), + tug(new CommercialShip("Pilotfish")), + patrol(new MilitaryShip("Enterprise")) + {} + + // Instantiate and populate the DoubleDispatch object. + typedef LLDoubleDispatch<std::string, GameObject> DD; + DD dispatcher; + + // Instantiate a few GameObjects. Make sure we refer to them + // polymorphically, and don't let them leak. + std::auto_ptr<GameObject> home; + std::auto_ptr<GameObject> obstacle; + std::auto_ptr<GameObject> tug; + std::auto_ptr<GameObject> patrol; + + // prototype objects + Asteroid dummyAsteroid; + SpaceShip dummyShip; + MilitaryShip dummyMilitary; + CommercialShip dummyCommercial; + SpaceStation dummyStation; + }; + typedef test_group<dispatch_data> dispatch_group; + typedef dispatch_group::object dispatch_object; + tut::dispatch_group ddgr("double dispatch"); + + template<> template<> + void dispatch_object::test<1>() + { + // Describe param types using explicit DD::Type objects + // (order-sensitive add() variant) + dispatcher.add(DD::Type<SpaceShip>(), DD::Type<Asteroid>(), shipAsteroid, true); + // naive adding, won't work + dispatcher.add(DD::Type<MilitaryShip>(), DD::Type<Asteroid>(), militaryShipAsteroid, true); + dispatcher.add(DD::Type<SpaceShip>(), DD::Type<SpaceStation>(), shipStation, true); + dispatcher.add(DD::Type<Asteroid>(), DD::Type<SpaceStation>(), asteroidStation, true); + + // Try colliding them. + ensure_equals(dispatcher(*home, *tug), // reverse params, SpaceShip subclass + "shipStation"); + ensure_equals(dispatcher(*patrol, *home), // forward params, SpaceShip subclass + "shipStation"); + ensure_equals(dispatcher(*obstacle, *home), // forward params + "asteroidStation"); + ensure_equals(dispatcher(*home, *obstacle), // reverse params + "asteroidStation"); + ensure_equals(dispatcher(*tug, *obstacle), // forward params, SpaceShip subclass + "shipAsteroid"); + ensure_equals(dispatcher(*obstacle, *patrol), // reverse params, SpaceShip subclass + // won't use militaryShipAsteroid() because it was added + // in wrong order + "shipAsteroid"); + } + + template<> template<> + void dispatch_object::test<2>() + { + // Describe param types using explicit DD::Type objects + // (order-sensitive add() variant) + // adding in correct order + dispatcher.add(DD::Type<MilitaryShip>(), DD::Type<Asteroid>(), militaryShipAsteroid, true); + dispatcher.add(DD::Type<SpaceShip>(), DD::Type<Asteroid>(), shipAsteroid, true); + dispatcher.add(DD::Type<SpaceShip>(), DD::Type<SpaceStation>(), shipStation, true); + dispatcher.add(DD::Type<Asteroid>(), DD::Type<SpaceStation>(), asteroidStation, true); + + ensure_equals(dispatcher(*patrol, *obstacle), "militaryShipAsteroid"); + ensure_equals(dispatcher(*tug, *obstacle), "shipAsteroid"); + } + + template<> template<> + void dispatch_object::test<3>() + { + // Describe param types with actual prototype instances + // (order-insensitive add() variant) + dispatcher.add(dummyMilitary, dummyAsteroid, militaryShipAsteroid); + dispatcher.add(dummyShip, dummyAsteroid, shipAsteroid); + dispatcher.add(dummyShip, dummyStation, shipStation); + dispatcher.add(dummyAsteroid, dummyStation, asteroidStation); + + ensure_equals(dispatcher(*patrol, *obstacle), "militaryShipAsteroid"); + ensure_equals(dispatcher(*tug, *obstacle), "shipAsteroid"); + ensure_equals(dispatcher(*obstacle, *patrol), ""); + } + + template<> template<> + void dispatch_object::test<4>() + { + // Describe param types with actual prototype instances + // (order-insensitive add() variant) + dispatcher.add(dummyShip, dummyAsteroid, shipAsteroid); + // Even if we add the militaryShipAsteroid in the wrong order, it + // should still work. + dispatcher.add(dummyMilitary, dummyAsteroid, militaryShipAsteroid); + dispatcher.add(dummyShip, dummyStation, shipStation); + dispatcher.add(dummyAsteroid, dummyStation, asteroidStation); + + ensure_equals(dispatcher(*patrol, *obstacle), "militaryShipAsteroid"); + ensure_equals(dispatcher(*tug, *obstacle), "shipAsteroid"); + } + + template<> template<> + void dispatch_object::test<5>() + { + dispatcher.add<SpaceShip, Asteroid>(shipAsteroid); + dispatcher.add<MilitaryShip, Asteroid>(militaryShipAsteroid); + dispatcher.add<SpaceShip, SpaceStation>(shipStation); + dispatcher.add<Asteroid, SpaceStation>(asteroidStation); + + ensure_equals(dispatcher(*patrol, *obstacle), "militaryShipAsteroid"); + ensure_equals(dispatcher(*tug, *obstacle), "shipAsteroid"); + } +} // namespace tut diff --git a/indra/test/llevents_tut.cpp b/indra/test/llevents_tut.cpp new file mode 100644 index 0000000000..57e22bbb56 --- /dev/null +++ b/indra/test/llevents_tut.cpp @@ -0,0 +1,739 @@ +/** + * @file llevents_tut.cpp + * @author Nat Goodspeed + * @date 2008-09-12 + * @brief Test of llevents.h + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#if LL_WINDOWS +#pragma warning (disable : 4675) // "resolved by ADL" -- just as I want! +#endif + +// Precompiled header +#include "linden_common.h" +// associated header +// UGLY HACK! We want to verify state internal to the classes without +// providing public accessors. +#define testable public +#include "llevents.h" +#undef testable +#include "lllistenerwrapper.h" +// STL headers +// std headers +#include <iostream> +#include <typeinfo> +// external library headers +#include <boost/bind.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/assign/list_of.hpp> +// other Linden headers +#include "lltut.h" +#include "stringize.h" +#include "tests/listener.h" + +using boost::assign::list_of; + +template<typename T> +T make(const T& value) { return value; } + +/***************************************************************************** +* tut test group +*****************************************************************************/ +namespace tut +{ + struct events_data + { + events_data(): + pumps(LLEventPumps::instance()), + listener0("first"), + listener1("second") + {} + LLEventPumps& pumps; + Listener listener0; + Listener listener1; + + void check_listener(const std::string& desc, const Listener& listener, LLSD::Integer got) + { + ensure_equals(STRINGIZE(listener << ' ' << desc), + listener.getLastEvent().asInteger(), got); + } + }; + typedef test_group<events_data> events_group; + typedef events_group::object events_object; + tut::events_group evgr("events"); + + template<> template<> + void events_object::test<1>() + { + set_test_name("basic operations"); + // Now there's a static constructor in llevents.cpp that registers on + // the "mainloop" pump to call LLEventPumps::flush(). + // Actually -- having to modify this to track the statically- + // constructed pumps in other TUT modules in this giant monolithic test + // executable isn't such a hot idea. +// ensure_equals("initial pump", pumps.mPumpMap.size(), 1); + size_t initial_pumps(pumps.mPumpMap.size()); + LLEventPump& per_frame(pumps.obtain("per-frame")); + ensure_equals("first explicit pump", pumps.mPumpMap.size(), initial_pumps+1); + // Verify that per_frame was instantiated as an LLEventStream. + ensure("LLEventStream leaf class", dynamic_cast<LLEventStream*>(&per_frame)); + ensure("enabled", per_frame.enabled()); + // Trivial test, but posting an event to an EventPump with no + // listeners should not blow up. The test is relevant because defining + // a boost::signal with a non-void return signature, using the default + // combiner, blows up if there are no listeners. This is because the + // default combiner is defined to return the value returned by the + // last listener, which is meaningless if there were no listeners. + per_frame.post(0); + LLBoundListener connection = listener0.listenTo(per_frame); + ensure("connected", connection.connected()); + ensure("not blocked", ! connection.blocked()); + per_frame.post(1); + check_listener("received", listener0, 1); + { // block the connection + LLEventPump::Blocker block(connection); + ensure("blocked", connection.blocked()); + per_frame.post(2); + check_listener("not updated", listener0, 1); + } // unblock + ensure("unblocked", ! connection.blocked()); + per_frame.post(3); + check_listener("unblocked", listener0, 3); + LLBoundListener sameConnection = per_frame.getListener(listener0.getName()); + ensure("still connected", sameConnection.connected()); + ensure("still not blocked", ! sameConnection.blocked()); + { // block it again + LLEventPump::Blocker block(sameConnection); + ensure("re-blocked", sameConnection.blocked()); + per_frame.post(4); + check_listener("re-blocked", listener0, 3); + } // unblock + bool threw = false; + try + { + // NOTE: boost::bind() saves its arguments by VALUE! If you pass + // an object instance rather than a pointer, you'll end up binding + // to an internal copy of that instance! Use boost::ref() to + // capture a reference instead. + per_frame.listen(listener0.getName(), // note bug, dup name + boost::bind(&Listener::call, boost::ref(listener1), _1)); + } + catch (const LLEventPump::DupListenerName& e) + { + threw = true; + ensure_equals(e.what(), + std::string("DupListenerName: " + "Attempt to register duplicate listener name '") + + listener0.getName() + + "' on " + typeid(per_frame).name() + " '" + per_frame.getName() + "'"); + } + ensure("threw DupListenerName", threw); + // do it right this time + listener1.listenTo(per_frame); + per_frame.post(5); + check_listener("got", listener0, 5); + check_listener("got", listener1, 5); + per_frame.enable(false); + per_frame.post(6); + check_listener("didn't get", listener0, 5); + check_listener("didn't get", listener1, 5); + per_frame.enable(); + per_frame.post(7); + check_listener("got", listener0, 7); + check_listener("got", listener1, 7); + per_frame.stopListening(listener0.getName()); + ensure("disconnected 0", ! connection.connected()); + ensure("disconnected 1", ! sameConnection.connected()); + per_frame.post(8); + check_listener("disconnected", listener0, 7); + check_listener("still connected", listener1, 8); + per_frame.stopListening(listener1.getName()); + per_frame.post(9); + check_listener("disconnected", listener1, 8); + } + + template<> template<> + void events_object::test<2>() + { + set_test_name("callstop() returning true"); + LLEventPump& per_frame(pumps.obtain("per-frame")); + listener0.reset(0); + listener1.reset(0); + LLBoundListener bound0 = listener0.listenTo(per_frame, &Listener::callstop); + LLBoundListener bound1 = listener1.listenTo(per_frame, &Listener::call, + // after listener0 + make<LLEventPump::NameList>(list_of(listener0.getName()))); + ensure("enabled", per_frame.enabled()); + ensure("connected 0", bound0.connected()); + ensure("unblocked 0", ! bound0.blocked()); + ensure("connected 1", bound1.connected()); + ensure("unblocked 1", ! bound1.blocked()); + per_frame.post(1); + check_listener("got", listener0, 1); + // Because listener0.callstop() returns true, control never reaches listener1.call(). + check_listener("got", listener1, 0); + } + + bool chainEvents(Listener& someListener, const LLSD& event) + { + // Make this call so we can watch for side effects for test purposes. + someListener.call(event); + // This function represents a recursive event chain -- or some other + // scenario in which an event handler raises additional events. + int value = event.asInteger(); + if (value) + { + LLEventPumps::instance().obtain("login").post(value - 1); + } + return false; + } + + template<> template<> + void events_object::test<3>() + { + set_test_name("LLEventQueue delayed action"); + // This access is NOT legal usage: we can do it only because we're + // hacking private for test purposes. Normally we'd either compile in + // a particular name, or (later) edit a config file. + pumps.mQueueNames.insert("login"); + LLEventPump& login(pumps.obtain("login")); + // The "mainloop" pump is special: posting on that implicitly calls + // LLEventPumps::flush(), which in turn should flush our "login" + // LLEventQueue. + LLEventPump& mainloop(pumps.obtain("mainloop")); + ensure("LLEventQueue leaf class", dynamic_cast<LLEventQueue*>(&login)); + listener0.listenTo(login); + listener0.reset(0); + login.post(1); + check_listener("waiting for queued event", listener0, 0); + mainloop.post(LLSD()); + check_listener("got queued event", listener0, 1); + login.stopListening(listener0.getName()); + // Verify that when an event handler posts a new event on the same + // LLEventQueue, it doesn't get processed in the same flush() call -- + // it waits until the next flush() call. + listener0.reset(17); + login.listen("chainEvents", boost::bind(chainEvents, boost::ref(listener0), _1)); + login.post(1); + check_listener("chainEvents(1) not yet called", listener0, 17); + mainloop.post(LLSD()); + check_listener("chainEvents(1) called", listener0, 1); + mainloop.post(LLSD()); + check_listener("chainEvents(0) called", listener0, 0); + mainloop.post(LLSD()); + check_listener("chainEvents(-1) not called", listener0, 0); + login.stopListening("chainEvents"); + } + + template<> template<> + void events_object::test<4>() + { + set_test_name("explicitly-instantiated LLEventStream"); + // Explicitly instantiate an LLEventStream, and verify that it + // self-registers with LLEventPumps + size_t registered = pumps.mPumpMap.size(); + size_t owned = pumps.mOurPumps.size(); + LLEventPump* localInstance; + { + LLEventStream myEventStream("stream"); + localInstance = &myEventStream; + LLEventPump& stream(pumps.obtain("stream")); + ensure("found named LLEventStream instance", &stream == localInstance); + ensure_equals("registered new instance", pumps.mPumpMap.size(), registered + 1); + ensure_equals("explicit instance not owned", pumps.mOurPumps.size(), owned); + } // destroy myEventStream -- should unregister + ensure_equals("destroyed instance unregistered", pumps.mPumpMap.size(), registered); + ensure_equals("destroyed instance not owned", pumps.mOurPumps.size(), owned); + LLEventPump& stream(pumps.obtain("stream")); + ensure("new LLEventStream instance", &stream != localInstance); + ensure_equals("obtain()ed instance registered", pumps.mPumpMap.size(), registered + 1); + ensure_equals("obtain()ed instance owned", pumps.mOurPumps.size(), owned + 1); + } + + template<> template<> + void events_object::test<5>() + { + set_test_name("stopListening()"); + LLEventPump& login(pumps.obtain("login")); + listener0.listenTo(login); + login.stopListening(listener0.getName()); + // should not throw because stopListening() should have removed name + listener0.listenTo(login, &Listener::callstop); + LLBoundListener wrong = login.getListener("bogus"); + ensure("bogus connection disconnected", ! wrong.connected()); + ensure("bogus connection blocked", wrong.blocked()); + } + + template<> template<> + void events_object::test<6>() + { + set_test_name("chaining LLEventPump instances"); + LLEventPump& upstream(pumps.obtain("upstream")); + // One potentially-useful construct is to chain LLEventPumps together. + // Among other things, this allows you to turn subsets of listeners on + // and off in groups. + LLEventPump& filter0(pumps.obtain("filter0")); + LLEventPump& filter1(pumps.obtain("filter1")); + upstream.listen(filter0.getName(), + boost::bind(&LLEventPump::post, boost::ref(filter0), _1)); + upstream.listen(filter1.getName(), + boost::bind(&LLEventPump::post, boost::ref(filter1), _1)); + listener0.listenTo(filter0); + listener1.listenTo(filter1); + listener0.reset(0); + listener1.reset(0); + upstream.post(1); + check_listener("got unfiltered", listener0, 1); + check_listener("got unfiltered", listener1, 1); + filter0.enable(false); + upstream.post(2); + check_listener("didn't get filtered", listener0, 1); + check_listener("got filtered", listener1, 2); + } + + template<> template<> + void events_object::test<7>() + { + set_test_name("listener dependency order"); + typedef LLEventPump::NameList NameList; + typedef Collect::StringList StringList; + LLEventPump& button(pumps.obtain("button")); + Collect collector; + button.listen("Mary", + boost::bind(&Collect::add, boost::ref(collector), "Mary", _1), + // state that "Mary" must come after "checked" + make<NameList>(list_of("checked"))); + button.listen("checked", + boost::bind(&Collect::add, boost::ref(collector), "checked", _1), + // "checked" must come after "spot" + make<NameList>(list_of("spot"))); + button.listen("spot", + boost::bind(&Collect::add, boost::ref(collector), "spot", _1)); + button.post(1); + ensure_equals(collector.result, make<StringList>(list_of("spot")("checked")("Mary"))); + collector.clear(); + button.stopListening("Mary"); + button.listen("Mary", + boost::bind(&Collect::add, boost::ref(collector), "Mary", _1), + LLEventPump::empty, // no after dependencies + // now "Mary" must come before "spot" + make<NameList>(list_of("spot"))); + button.post(2); + ensure_equals(collector.result, make<StringList>(list_of("Mary")("spot")("checked"))); + collector.clear(); + button.stopListening("spot"); + std::string threw; + try + { + button.listen("spot", + boost::bind(&Collect::add, boost::ref(collector), "spot", _1), + // after "Mary" and "checked" -- whoops! + make<NameList>(list_of("Mary")("checked"))); + } + catch (const LLEventPump::Cycle& e) + { + threw = e.what(); +// std::cout << "Caught: " << e.what() << '\n'; + } + // Obviously the specific wording of the exception text can + // change; go ahead and change the test to match. + // Establish that it contains: + // - the name and runtime type of the LLEventPump + ensure_contains("LLEventPump type", threw, typeid(button).name()); + ensure_contains("LLEventPump name", threw, "'button'"); + // - the name of the new listener that caused the problem + ensure_contains("new listener name", threw, "'spot'"); + // - a synopsis of the problematic dependencies. + ensure_contains("cyclic dependencies", threw, + "\"Mary\" -> before (\"spot\")"); + ensure_contains("cyclic dependencies", threw, + "after (\"spot\") -> \"checked\""); + ensure_contains("cyclic dependencies", threw, + "after (\"Mary\", \"checked\") -> \"spot\""); + button.listen("yellow", + boost::bind(&Collect::add, boost::ref(collector), "yellow", _1), + make<NameList>(list_of("checked"))); + button.listen("shoelaces", + boost::bind(&Collect::add, boost::ref(collector), "shoelaces", _1), + make<NameList>(list_of("checked"))); + button.post(3); + ensure_equals(collector.result, make<StringList>(list_of("Mary")("checked")("yellow")("shoelaces"))); + collector.clear(); + threw.clear(); + try + { + button.listen("of", + boost::bind(&Collect::add, boost::ref(collector), "of", _1), + make<NameList>(list_of("shoelaces")), + make<NameList>(list_of("yellow"))); + } + catch (const LLEventPump::OrderChange& e) + { + threw = e.what(); +// std::cout << "Caught: " << e.what() << '\n'; + } + // Same remarks about the specific wording of the exception. Just + // ensure that it contains enough information to clarify the + // problem and what must be done to resolve it. + ensure_contains("LLEventPump type", threw, typeid(button).name()); + ensure_contains("LLEventPump name", threw, "'button'"); + ensure_contains("new listener name", threw, "'of'"); + ensure_contains("prev listener name", threw, "'yellow'"); + ensure_contains("old order", threw, "was: Mary, checked, yellow, shoelaces"); + ensure_contains("new order", threw, "now: Mary, checked, shoelaces, of, yellow"); + button.post(4); + ensure_equals(collector.result, make<StringList>(list_of("Mary")("checked")("yellow")("shoelaces"))); + } + + template<> template<> + void events_object::test<8>() + { + set_test_name("tweaked and untweaked LLEventPump instance names"); + { // nested scope + // Hand-instantiate an LLEventStream... + LLEventStream bob("bob"); + bool threw = false; + try + { + // then another with a duplicate name. + LLEventStream bob2("bob"); + } + catch (const LLEventPump::DupPumpName& /*e*/) + { + threw = true; +// std::cout << "Caught: " << e.what() << '\n'; + } + ensure("Caught DupPumpName", threw); + } // delete first 'bob' + LLEventStream bob("bob"); // should work, previous one unregistered + LLEventStream bob1("bob", true); // allowed to tweak name + ensure_equals("tweaked LLEventStream name", bob1.getName(), "bob1"); + std::vector< boost::shared_ptr<LLEventStream> > streams; + for (int i = 2; i <= 10; ++i) + { + streams.push_back(boost::shared_ptr<LLEventStream>(new LLEventStream("bob", true))); + } + ensure_equals("last tweaked LLEventStream name", streams.back()->getName(), "bob10"); + } + + // Define a function that accepts an LLListenerOrPumpName + void eventSource(const LLListenerOrPumpName& listener) + { + // Pretend that some time has elapsed. Call listener immediately. + listener(17); + } + + template<> template<> + void events_object::test<9>() + { + set_test_name("LLListenerOrPumpName"); + // Passing a boost::bind() expression to LLListenerOrPumpName + listener0.reset(0); + eventSource(boost::bind(&Listener::call, boost::ref(listener0), _1)); + check_listener("got by listener", listener0, 17); + // Passing a string LLEventPump name to LLListenerOrPumpName + listener0.reset(0); + LLEventStream random("random"); + listener0.listenTo(random); + eventSource("random"); + check_listener("got by pump name", listener0, 17); + bool threw = false; + try + { + LLListenerOrPumpName empty; + empty(17); + } + catch (const LLListenerOrPumpName::Empty&) + { + threw = true; + } + ensure("threw Empty", threw); + } + + class TempListener: public Listener + { + public: + TempListener(const std::string& name, bool& liveFlag): + Listener(name), + mLiveFlag(liveFlag) + { + mLiveFlag = true; + } + + virtual ~TempListener() + { + mLiveFlag = false; + } + + private: + bool& mLiveFlag; + }; + + template<> template<> + void events_object::test<10>() + { + set_test_name("listen(boost::bind(...TempListener...))"); + // listen() can't do anything about a plain TempListener instance: + // it's not managed with shared_ptr, nor is it an LLEventTrackable subclass + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + { + TempListener tempListener("temp", live); + ensure("TempListener constructed", live); + connection = heaptest.listen(tempListener.getName(), + boost::bind(&Listener::call, + boost::ref(tempListener), + _1)); + heaptest.post(1); + check_listener("received", tempListener, 1); + } // presumably this will make newListener go away? + // verify that + ensure("TempListener destroyed", ! live); + // This is the case against which we can't defend. Don't even try to + // post to heaptest -- that would engage Undefined Behavior. + // Cautiously inspect connection... + ensure("misleadingly connected", connection.connected()); + // then disconnect by hand. + heaptest.stopListening("temp"); + } + + template<> template<> + void events_object::test<11>() + { + set_test_name("listen(boost::bind(...weak_ptr...))"); + // listen() detecting weak_ptr<TempListener> in boost::bind() object + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + ensure("default state", ! connection.connected()); + { + boost::shared_ptr<TempListener> newListener(new TempListener("heap", live)); + newListener->reset(); + ensure("TempListener constructed", live); + connection = heaptest.listen(newListener->getName(), + boost::bind(&Listener::call, weaken(newListener), _1)); + ensure("new connection", connection.connected()); + heaptest.post(1); + check_listener("received", *newListener, 1); + } // presumably this will make newListener go away? + // verify that + ensure("TempListener destroyed", ! live); + ensure("implicit disconnect", ! connection.connected()); + // now just make sure we don't blow up trying to access a freed object! + heaptest.post(2); + } + + template<> template<> + void events_object::test<12>() + { + set_test_name("listen(boost::bind(...shared_ptr...))"); +/*==========================================================================*| + // DISABLED because I've made this case produce a compile error. + // Following the error leads the disappointed dev to a comment + // instructing her to use the weaken() function to bind a weak_ptr<T> + // instead of binding a shared_ptr<T>, and explaining why. I know of + // no way to use TUT to code a repeatable test in which the expected + // outcome is a compile error. The interested reader is invited to + // uncomment this block and build to see for herself. + + // listen() detecting shared_ptr<TempListener> in boost::bind() object + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + std::string listenerName("heap"); + ensure("default state", ! connection.connected()); + { + boost::shared_ptr<TempListener> newListener(new TempListener(listenerName, live)); + ensure_equals("use_count", newListener.use_count(), 1); + newListener->reset(); + ensure("TempListener constructed", live); + connection = heaptest.listen(newListener->getName(), + boost::bind(&Listener::call, newListener, _1)); + ensure("new connection", connection.connected()); + ensure_equals("use_count", newListener.use_count(), 2); + heaptest.post(1); + check_listener("received", *newListener, 1); + } // this should make newListener go away... + // Unfortunately, the fact that we've bound a shared_ptr by value into + // our LLEventPump means that copy will keep the referenced object alive. + ensure("TempListener still alive", live); + ensure("still connected", connection.connected()); + // disconnecting explicitly should delete the TempListener... + heaptest.stopListening(listenerName); +#if 0 // however, in my experience, it does not. I don't know why not. + // Ah: on 2009-02-19, Frank Mori Hess, author of the Boost.Signals2 + // library, stated on the boost-users mailing list: + // http://www.nabble.com/Re%3A--signals2--review--The-review-of-the-signals2-library-(formerly-thread_safe_signals)-begins-today%2C-Nov-1st-p22102367.html + // "It will get destroyed eventually. The signal cleans up its slot + // list little by little during connect/invoke. It doesn't immediately + // remove disconnected slots from the slot list since other threads + // might be using the same slot list concurrently. It might be + // possible to make it immediately reset the shared_ptr owning the + // slot though, leaving an empty shared_ptr in the slot list, since + // that wouldn't invalidate any iterators." + ensure("TempListener destroyed", ! live); + ensure("implicit disconnect", ! connection.connected()); +#endif // 0 + // now just make sure we don't blow up trying to access a freed object! + heaptest.post(2); +|*==========================================================================*/ + } + + class TempTrackableListener: public TempListener, public LLEventTrackable + { + public: + TempTrackableListener(const std::string& name, bool& liveFlag): + TempListener(name, liveFlag) + {} + }; + + template<> template<> + void events_object::test<13>() + { + set_test_name("listen(boost::bind(...TempTrackableListener ref...))"); + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + { + TempTrackableListener tempListener("temp", live); + ensure("TempTrackableListener constructed", live); + connection = heaptest.listen(tempListener.getName(), + boost::bind(&TempTrackableListener::call, + boost::ref(tempListener), _1)); + heaptest.post(1); + check_listener("received", tempListener, 1); + } // presumably this will make tempListener go away? + // verify that + ensure("TempTrackableListener destroyed", ! live); + ensure("implicit disconnect", ! connection.connected()); + // now just make sure we don't blow up trying to access a freed object! + heaptest.post(2); + } + + template<> template<> + void events_object::test<14>() + { + set_test_name("listen(boost::bind(...TempTrackableListener pointer...))"); + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + { + TempTrackableListener* newListener(new TempTrackableListener("temp", live)); + ensure("TempTrackableListener constructed", live); + connection = heaptest.listen(newListener->getName(), + boost::bind(&TempTrackableListener::call, + newListener, _1)); + heaptest.post(1); + check_listener("received", *newListener, 1); + // explicitly destroy newListener + delete newListener; + } + // verify that + ensure("TempTrackableListener destroyed", ! live); + ensure("implicit disconnect", ! connection.connected()); + // now just make sure we don't blow up trying to access a freed object! + heaptest.post(2); + } + + template<> template<> + void events_object::test<15>() + { + // This test ensures that using an LLListenerWrapper subclass doesn't + // block Boost.Signals2 from recognizing a bound LLEventTrackable + // subclass. + set_test_name("listen(llwrap<LLLogListener>(boost::bind(...TempTrackableListener ref...)))"); + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + { + TempTrackableListener tempListener("temp", live); + ensure("TempTrackableListener constructed", live); + connection = heaptest.listen(tempListener.getName(), + llwrap<LLLogListener>( + boost::bind(&TempTrackableListener::call, + boost::ref(tempListener), _1))); + heaptest.post(1); + check_listener("received", tempListener, 1); + } // presumably this will make tempListener go away? + // verify that + ensure("TempTrackableListener destroyed", ! live); + ensure("implicit disconnect", ! connection.connected()); + // now just make sure we don't blow up trying to access a freed object! + heaptest.post(2); + } + + class TempSharedListener: public TempListener, + public boost::enable_shared_from_this<TempSharedListener> + { + public: + TempSharedListener(const std::string& name, bool& liveFlag): + TempListener(name, liveFlag) + {} + }; + + template<> template<> + void events_object::test<16>() + { + set_test_name("listen(boost::bind(...TempSharedListener ref...))"); +#if 0 + bool live = false; + LLEventPump& heaptest(pumps.obtain("heaptest")); + LLBoundListener connection; + { + // We MUST have at least one shared_ptr to an + // enable_shared_from_this subclass object before + // shared_from_this() can work. + boost::shared_ptr<TempSharedListener> + tempListener(new TempSharedListener("temp", live)); + ensure("TempSharedListener constructed", live); + // However, we're not passing either the shared_ptr or its + // corresponding weak_ptr -- instead, we're passing a reference to + // the TempSharedListener. +/*==========================================================================*| + std::cout << "Capturing const ref" << std::endl; + const boost::enable_shared_from_this<TempSharedListener>& cref(*tempListener); + std::cout << "Capturing const ptr" << std::endl; + const boost::enable_shared_from_this<TempSharedListener>* cp(&cref); + std::cout << "Capturing non-const ptr" << std::endl; + boost::enable_shared_from_this<TempSharedListener>* p(const_cast<boost::enable_shared_from_this<TempSharedListener>*>(cp)); + std::cout << "Capturing shared_from_this()" << std::endl; + boost::shared_ptr<TempSharedListener> sp(p->shared_from_this()); + std::cout << "Capturing weak_ptr" << std::endl; + boost::weak_ptr<TempSharedListener> wp(weaken(sp)); + std::cout << "Binding weak_ptr" << std::endl; +|*==========================================================================*/ + connection = heaptest.listen(tempListener->getName(), + boost::bind(&TempSharedListener::call, *tempListener, _1)); + heaptest.post(1); + check_listener("received", *tempListener, 1); + } // presumably this will make tempListener go away? + // verify that + ensure("TempSharedListener destroyed", ! live); + ensure("implicit disconnect", ! connection.connected()); + // now just make sure we don't blow up trying to access a freed object! + heaptest.post(2); +#endif // 0 + } +} // namespace tut diff --git a/indra/test/llhttpclient_tut.cpp b/indra/test/llhttpclient_tut.cpp index a177d5f2ea..03759001ae 100644 --- a/indra/test/llhttpclient_tut.cpp +++ b/indra/test/llhttpclient_tut.cpp @@ -2,30 +2,25 @@ * @file llhttpclient_tut.cpp * @brief Testing the HTTP client classes. * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -35,7 +30,7 @@ * */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" // These are too slow on Windows to actually include in the build. JC @@ -58,8 +53,8 @@ namespace tut class LLSDStorageNode : public LLHTTPNode { public: - LLSD get() const { return storage; } - LLSD put(const LLSD& value) const { storage = value; return LLSD(); } + LLSD simpleGet() const { return storage; } + LLSD simplePut(const LLSD& value) const { storage = value; return LLSD(); } }; class ErrorNode : public LLHTTPNode @@ -259,7 +254,7 @@ namespace tut template<> template<> void HTTPClientTestObject::test<1>() { - LLHTTPClient::get("http://www.secondlife.com/", newResult()); + LLHTTPClient::get("http://www.google.com/", newResult()); runThePump(); ensureStatusOK(); ensure("result object wasn't destroyed", mResultDeleted); @@ -268,6 +263,7 @@ namespace tut template<> template<> void HTTPClientTestObject::test<2>() { + skip("error test depends on dev's local ISP not supplying \"helpful\" search page"); LLHTTPClient::get("http://www.invalid", newResult()); runThePump(); ensureStatusError(); @@ -345,7 +341,7 @@ namespace tut // won't ever let it run. Instead get from a known LLSD // source and compare results with the non-blocking get which // is tested against the mini server earlier. - skip_fail("secondlife.com is not reliable enough for unit tests."); + skip("secondlife.com is not reliable enough for unit tests."); LLSD expected; @@ -365,7 +361,7 @@ namespace tut { // This is testing for the presence of the Header in the returned results // from an HTTP::get call. - LLHTTPClient::get("http://www.secondlife.com/", newResult()); + LLHTTPClient::get("http://www.google.com/", newResult()); runThePump(); ensureStatusOK(); LLSD header = getHeader(); @@ -374,7 +370,7 @@ namespace tut template<> template<> void HTTPClientTestObject::test<9>() { - LLHTTPClient::head("http://www.secondlife.com/", newResult()); + LLHTTPClient::head("http://www.google.com/", newResult()); runThePump(); ensureStatusOK(); ensure("result object wasn't destroyed", mResultDeleted); diff --git a/indra/test/llhttpdate_tut.cpp b/indra/test/llhttpdate_tut.cpp index c630e9caf0..46684bb9dc 100644 --- a/indra/test/llhttpdate_tut.cpp +++ b/indra/test/llhttpdate_tut.cpp @@ -3,30 +3,25 @@ * @author Kartic Krishnamurthy * @date Wednesday, 18 Jul 2007 17:00:00 GMT :) * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -36,6 +31,9 @@ #include "lldate.h" #include "llframetimer.h" +#include <time.h> +#include <locale.h> + namespace tut { struct httpdate_data @@ -49,6 +47,7 @@ namespace tut template<> template<> void httpdate_object::test<1>() { + static std::string epoch_expected = "Thursday, 01 Jan 1970 00:00:00 GMT" ; ensure("Check Epoch in RFC 1123", ( epoch_expected == some_date.asRFC1123())); } @@ -56,6 +55,7 @@ namespace tut template<> template<> void httpdate_object::test<2>() { + static std::string expected = "Wednesday, 18 Jul 2007 22:17:24 GMT" ; some_date = LLDate(1184797044.037586); ensure("Check some timestamp in RFC 1123", ( expected == some_date.asRFC1123())); @@ -65,6 +65,7 @@ namespace tut template<> template<> void httpdate_object::test<3>() { + //F64 sometime = LLFrameTimer::getTotalSeconds(); time_t sometime; time(&sometime); @@ -90,4 +91,70 @@ namespace tut // probably not a good idea to use strcmp but this is just a unit test ensure("Current time in RFC 1123", (strcmp(expected, actual.c_str()) == 0)); } + + void test_date_string(const std::string &locale, struct tm *t, + const std::string &fmt, const std::string &expected) + { + std::string result = LLDate::toHTTPDateString(t, fmt); + LLStringUtil::toLower(result); + std::string label = std::string("toHTTPDateString - ") + locale; + ensure_equals(label.c_str(), result, expected); + } + + template<> template<> + void httpdate_object::test<4>() + { + // test localization of http dates +#if LL_WINDOWS + const char *en_locale = "english"; + const char *fr_locale = "french"; +#else + const char *en_locale = "en_GB.UTF-8"; + const char *fr_locale = "fr_FR.UTF-8"; +#endif + + std::string prev_locale = LLStringUtil::getLocale(); + std::string prev_clocale = std::string(setlocale(LC_TIME, NULL)); + time_t test_time = 1252374030; // 8 Sep 2009 01:40:01 + struct tm *t = gmtime(&test_time); + + setlocale(LC_TIME, en_locale); + if (strcmp(setlocale(LC_TIME, NULL), en_locale) != 0) + { + setlocale(LC_TIME, prev_clocale.c_str()); + skip("Cannot set English locale"); + } + + LLStringUtil::setLocale(en_locale); + test_date_string(en_locale, t, "%d %B %Y - %H:%M", "08 september 2009 - 01:40"); + test_date_string(en_locale, t, "%H", "01"); + test_date_string(en_locale, t, "%M", "40"); + test_date_string(en_locale, t, "%I", "01"); + test_date_string(en_locale, t, "%d", "08"); + test_date_string(en_locale, t, "%Y", "2009"); + test_date_string(en_locale, t, "%p", "am"); + test_date_string(en_locale, t, "%A", "tuesday"); + test_date_string(en_locale, t, "%B", "september"); + + setlocale(LC_TIME, fr_locale); + if (strcmp(setlocale(LC_TIME, NULL), fr_locale) != 0) + { + LLStringUtil::setLocale(prev_locale); + setlocale(LC_TIME, prev_clocale.c_str()); + skip("Cannot set French locale"); + } + + LLStringUtil::setLocale(fr_locale); + test_date_string(fr_locale, t, "%d %B %Y - %H:%M", "08 septembre 2009 - 01:40"); + test_date_string(fr_locale, t, "%H", "01"); + test_date_string(fr_locale, t, "%M", "40"); + test_date_string(fr_locale, t, "%I", "01"); + test_date_string(fr_locale, t, "%d", "08"); + test_date_string(fr_locale, t, "%Y", "2009"); + test_date_string(fr_locale, t, "%A", "mardi"); + test_date_string(fr_locale, t, "%B", "septembre"); + + LLStringUtil::setLocale(prev_locale); + setlocale(LC_TIME, prev_clocale.c_str()); + } } diff --git a/indra/test/llhttpnode_tut.cpp b/indra/test/llhttpnode_tut.cpp index 245ea17667..216c59d766 100644 --- a/indra/test/llhttpnode_tut.cpp +++ b/indra/test/llhttpnode_tut.cpp @@ -3,30 +3,25 @@ * @date May 2006 * @brief HTTP server unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -85,7 +80,8 @@ namespace tut void result(const LLSD& result) { mResult = result; } void status(S32 code, const std::string& message) { } - + void extendedResult(S32 code, const std::string& message, const LLSD& headers) { } + private: Response() {;} // Must be accessed through LLPointer. }; diff --git a/indra/test/lliohttpserver_tut.cpp b/indra/test/lliohttpserver_tut.cpp index 5401d1a8ae..2fdc455f45 100644 --- a/indra/test/lliohttpserver_tut.cpp +++ b/indra/test/lliohttpserver_tut.cpp @@ -3,30 +3,25 @@ * @date May 2006 * @brief HTTP server unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -191,7 +186,7 @@ namespace tut "HTTP/1.0 200 OK\r\n"); ensure_contains("web/hello content type", result, - "Content-Type: application/xml\r\n"); + "Content-Type: application/llsd+xml\r\n"); ensure_contains("web/hello content length", result, "Content-Length: 36\r\n"); @@ -232,7 +227,7 @@ namespace tut "HTTP/1.0 200 OK\r\n"); ensure_contains("web/echo content type", result, - "Content-Type: application/xml\r\n"); + "Content-Type: application/llsd+xml\r\n"); ensure_contains("web/echo content length", result, "Content-Length: 35\r\n"); @@ -327,6 +322,23 @@ namespace tut ensure_starts_with("large echo status", result, "HTTP/1.0 200 OK\r\n"); } + template<> template<> + void HTTPServiceTestObject::test<8>() + { + // test the OPTIONS http method -- the default implementation + // should return the X-Documentation-URL + std::ostringstream http_request; + http_request << "OPTIONS / HTTP/1.0\r\nHost: localhost\r\n\r\n"; + bool timeout = false; + std::string result = makeRequest("/", http_request.str(), timeout); + ensure_starts_with("OPTIONS verb ok", result, "HTTP/1.0 200 OK\r\n"); + ensure_contains( + "Doc url header exists", + result, + "X-Documentation-URL: http://localhost"); + } + + /* TO DO: test generation of not found and method not allowed errors */ diff --git a/indra/test/llmessageconfig_tut.cpp b/indra/test/llmessageconfig_tut.cpp index c2329220e5..8088ce8558 100644 --- a/indra/test/llmessageconfig_tut.cpp +++ b/indra/test/llmessageconfig_tut.cpp @@ -3,30 +3,25 @@ * @date March 2007 * @brief LLMessageConfig unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -56,7 +51,7 @@ namespace tut oStr << "/tmp/llmessage-config-test-" << random; #endif mTestConfigDir = oStr.str(); - LLFile::mkdir(mTestConfigDir.c_str()); + LLFile::mkdir(mTestConfigDir); writeConfigFile(LLSD()); LLMessageConfig::initClass("simulator", mTestConfigDir); } @@ -64,16 +59,16 @@ namespace tut ~LLMessageConfigTestData() { // rm contents of temp dir - int rmfile = LLFile::remove((mTestConfigDir + "/message.xml").c_str()); + int rmfile = LLFile::remove((mTestConfigDir + "/message.xml")); ensure_equals("rmfile value", rmfile, 0); // rm temp dir - int rmdir = LLFile::rmdir(mTestConfigDir.c_str()); + int rmdir = LLFile::rmdir(mTestConfigDir); ensure_equals("rmdir value", rmdir, 0); } void writeConfigFile(const LLSD& config) { - llofstream file((mTestConfigDir + "/message.xml").c_str()); + llofstream file((mTestConfigDir + "/message.xml")); if (file.is_open()) { LLSDSerialize::toPrettyXML(config, file); diff --git a/indra/test/llmessagetemplateparser_tut.cpp b/indra/test/llmessagetemplateparser_tut.cpp index 690cc26bcf..da6d229fb5 100644 --- a/indra/test/llmessagetemplateparser_tut.cpp +++ b/indra/test/llmessagetemplateparser_tut.cpp @@ -3,30 +3,25 @@ * @date April 2007 * @brief LLMessageTemplateParser unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/test/llpermissions_tut.cpp b/indra/test/llpermissions_tut.cpp index 69f832049c..bf6766424c 100644 --- a/indra/test/llpermissions_tut.cpp +++ b/indra/test/llpermissions_tut.cpp @@ -4,34 +4,29 @@ * @date March 2007 * @brief llpermissions test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" #include "message.h" @@ -60,7 +55,7 @@ namespace tut uuid2 == LLUUID::null && uuid3 == LLUUID::null)); ensure("LLPermission Get Functions failed", (permissions.getMaskBase() == PERM_ALL && permissions.getMaskOwner() == PERM_ALL && permissions.getMaskGroup() == PERM_ALL && permissions.getMaskEveryone() == PERM_ALL && permissions.getMaskNextOwner() == PERM_ALL)); - ensure("Ownership functions failed", (permissions.isGroupOwned() == FALSE && permissions.isOwned() == FALSE)); + ensure("Ownership functions failed", ((! permissions.isGroupOwned()) && (! permissions.isOwned()))); } template<> template<> @@ -203,7 +198,7 @@ namespace tut LLPermissions perm1; LLUUID uuid; BOOL is_group_owned = FALSE; - ensure("1:getOwnership:failed ", (FALSE == perm1.getOwnership(uuid,is_group_owned))); + ensure("1:getOwnership:failed ", ! perm1.getOwnership(uuid,is_group_owned)); LLPermissions perm; LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); @@ -212,11 +207,11 @@ namespace tut LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); perm.init(creator,owner,lastOwner,group); perm.getOwnership(uuid,is_group_owned); - ensure("2:getOwnership:failed ", ((uuid == owner) && (FALSE == is_group_owned))); + ensure("2:getOwnership:failed ", ((uuid == owner) && (! is_group_owned))); perm.init(creator,LLUUID::null,lastOwner,group); perm.getOwnership(uuid,is_group_owned); - ensure("3:getOwnership:failed ", ((uuid == group) && (TRUE == is_group_owned))); + ensure("3:getOwnership:failed ", ((uuid == group) && is_group_owned)); } template<> template<> @@ -239,17 +234,17 @@ namespace tut LLUUID agent("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); - bool is_atomic = TRUE; - ensure("setOwnerAndGroup():failed ", (TRUE == perm.setOwnerAndGroup(agent,owner,group,is_atomic))); + bool is_atomic = true; + ensure("setOwnerAndGroup():failed ", perm.setOwnerAndGroup(agent,owner,group,is_atomic)); LLUUID owner2("68edcf47-ccd7-45b8-9f90-1649d7f12807"); LLUUID group2("9c8eca51-53d5-42a7-bb58-cef070395db9"); // cant change - agent need to be current owner - ensure("setOwnerAndGroup():failed ", (FALSE == perm.setOwnerAndGroup(agent,owner2,group2,is_atomic))); + ensure("setOwnerAndGroup():failed ", ! perm.setOwnerAndGroup(agent,owner2,group2,is_atomic)); // should be able to change - agent and owner same as current owner - ensure("setOwnerAndGroup():failed ", (TRUE == perm.setOwnerAndGroup(owner,owner,group2,is_atomic))); + ensure("setOwnerAndGroup():failed ", perm.setOwnerAndGroup(owner,owner,group2,is_atomic)); } template<> template<> @@ -258,7 +253,7 @@ namespace tut LLPermissions perm; LLUUID agent; LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); - ensure("deedToGroup():failed ", (TRUE == perm.deedToGroup(agent,group))); + ensure("deedToGroup():failed ", perm.deedToGroup(agent,group)); } template<> template<> void permission_object_t::test<11>() @@ -267,12 +262,12 @@ namespace tut LLUUID agent; BOOL set = 1; U32 bits = PERM_TRANSFER | PERM_MODIFY; - ensure("setBaseBits():failed ", (TRUE == perm.setBaseBits(agent, set, bits))); - ensure("setOwnerBits():failed ", (TRUE == perm.setOwnerBits(agent, set, bits))); + ensure("setBaseBits():failed ", perm.setBaseBits(agent, set, bits)); + ensure("setOwnerBits():failed ", perm.setOwnerBits(agent, set, bits)); LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); - ensure("setBaseBits():failed ", (FALSE == perm.setBaseBits(agent1, set, bits))); - ensure("setOwnerBits():failed ", (FALSE == perm.setOwnerBits(agent1, set, bits))); + ensure("setBaseBits():failed ", ! perm.setBaseBits(agent1, set, bits)); + ensure("setOwnerBits():failed ", ! perm.setOwnerBits(agent1, set, bits)); } template<> template<> @@ -283,14 +278,14 @@ namespace tut LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); BOOL set = 1; U32 bits = 10; - ensure("setGroupBits():failed ", (TRUE == perm.setGroupBits(agent,group, set, bits))); - ensure("setEveryoneBits():failed ", (TRUE == perm.setEveryoneBits(agent,group, set, bits))); - ensure("setNextOwnerBits():failed ", (TRUE == perm.setNextOwnerBits(agent,group, set, bits))); - - LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); - ensure("setGroupBits():failed ", (FALSE == perm.setGroupBits(agent1,group, set, bits))); - ensure("setEveryoneBits():failed ", (FALSE == perm.setEveryoneBits(agent1,group, set, bits))); - ensure("setNextOwnerBits():failed ", (FALSE == perm.setNextOwnerBits(agent1,group, set, bits))); + ensure("setGroupBits():failed ", perm.setGroupBits(agent,group, set, bits)); + ensure("setEveryoneBits():failed ", perm.setEveryoneBits(agent,group, set, bits)); + ensure("setNextOwnerBits():failed ", perm.setNextOwnerBits(agent,group, set, bits)); + + LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); + ensure("setGroupBits():failed ", ! perm.setGroupBits(agent1,group, set, bits)); + ensure("setEveryoneBits():failed ", ! perm.setEveryoneBits(agent1,group, set, bits)); + ensure("setNextOwnerBits():failed ", ! perm.setNextOwnerBits(agent1,group, set, bits)); } template<> template<> @@ -300,14 +295,14 @@ namespace tut LLUUID agent; LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); U32 bits = 10; - ensure("allowOperationBy():failed ", (TRUE == perm.allowOperationBy(bits,agent,group))); + ensure("allowOperationBy():failed ", perm.allowOperationBy(bits,agent,group)); LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); perm.init(creator,owner,lastOwner,group); - ensure("allowOperationBy():failed ", (TRUE == perm.allowOperationBy(bits,agent1,group))); + ensure("allowOperationBy():failed ", perm.allowOperationBy(bits,agent1,group)); } template<> template<> @@ -320,15 +315,12 @@ namespace tut LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); perm.init(creator,owner,lastOwner,group); LLUUID agent; - ensure("1:allowModifyBy():failed ", (TRUE == perm.allowModifyBy(agent))); - ensure("2:allowModifyBy():failed ", (TRUE == perm.allowModifyBy(agent,group))); + ensure("1:allowModifyBy():failed ", perm.allowModifyBy(agent)); + ensure("2:allowModifyBy():failed ", perm.allowModifyBy(agent,group)); - U32 val1 = 0x7FFFFFFF; - S32 sVal = 1 << 14; - sVal = val1 & sVal; LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); - ensure("3:allowModifyBy():failed ", (sVal == perm.allowModifyBy(agent1))); - ensure("4:allowModifyBy():failed ", (sVal == perm.allowModifyBy(agent1,group))); + ensure("3:allowModifyBy():failed ", perm.allowModifyBy(agent1)); + ensure("4:allowModifyBy():failed ", perm.allowModifyBy(agent1,group)); } template<> template<> @@ -341,15 +333,12 @@ namespace tut LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); perm.init(creator,owner,lastOwner,group); LLUUID agent; - ensure("1:allowCopyBy():failed ", (TRUE == perm.allowModifyBy(agent))); - ensure("2:allowCopyBy():failed ", (TRUE == perm.allowModifyBy(agent,group))); + ensure("1:allowCopyBy():failed ", perm.allowModifyBy(agent)); + ensure("2:allowCopyBy():failed ", perm.allowModifyBy(agent,group)); - U32 val1 = 0x7FFFFFFF; - S32 sVal = 1 << 15; - sVal = val1 & sVal; LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); - ensure("3:allowCopyBy():failed ", (sVal == perm.allowCopyBy(agent1))); - ensure("4:allowCopyBy():failed ", (sVal == perm.allowCopyBy(agent1,group))); + ensure("3:allowCopyBy():failed ", perm.allowCopyBy(agent1)); + ensure("4:allowCopyBy():failed ", perm.allowCopyBy(agent1,group)); } template<> template<> @@ -362,15 +351,12 @@ namespace tut LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); perm.init(creator,owner,lastOwner,group); LLUUID agent; - ensure("1:allowMoveBy():failed ", (TRUE == perm.allowMoveBy(agent))); - ensure("2:allowMoveBy():failed ", (TRUE == perm.allowMoveBy(agent,group))); + ensure("1:allowMoveBy():failed ", perm.allowMoveBy(agent)); + ensure("2:allowMoveBy():failed ", perm.allowMoveBy(agent,group)); - U32 val1 = 0x7FFFFFFF; - S32 sVal = 1 << 19; - sVal = val1 & sVal; LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); - ensure("3:allowMoveBy():failed ", (sVal == perm.allowMoveBy(agent1))); - ensure("4:allowMoveBy():failed ", (sVal == perm.allowMoveBy(agent1,group))); + ensure("3:allowMoveBy():failed ", perm.allowMoveBy(agent1)); + ensure("4:allowMoveBy():failed ", perm.allowMoveBy(agent1,group)); } template<> template<> @@ -382,20 +368,17 @@ namespace tut LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); LLUUID agent; - ensure("1:allowMoveBy():failed ", (TRUE == perm.allowTransferTo(agent))); + ensure("1:allowMoveBy():failed ", perm.allowTransferTo(agent)); perm.init(creator,owner,lastOwner,group); - U32 val1 = 0x7FFFFFFF; - S32 sVal = 1 << 13; - sVal = val1 & sVal; - ensure("2:allowMoveBy():failed ", (sVal == perm.allowTransferTo(agent))); + ensure("2:allowMoveBy():failed ", perm.allowTransferTo(agent)); } template<> template<> void permission_object_t::test<18>() { LLPermissions perm,perm1; - ensure("1:Operator==:failed ", perm == perm1); + ensure_equals("1:Operator==:failed ", perm, perm1); LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); @@ -403,7 +386,7 @@ namespace tut LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); perm.init(creator,owner,lastOwner,group); perm = perm1; - ensure("2:Operator==:failed ", perm == perm1); + ensure_equals("2:Operator==:failed ", perm, perm1); } template<> template<> @@ -415,7 +398,7 @@ namespace tut LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); perm.init(creator,owner,lastOwner,group); - ensure("2:Operator==:failed ", perm != perm1); + ensure_not_equals("2:Operator==:failed ", perm, perm1); } template<> template<> @@ -452,7 +435,7 @@ namespace tut } perm1.importFile(fp); fclose(fp); - ensure("exportFile()/importFile():failed to export and import the data ", perm1 == perm); + ensure_equals("exportFile()/importFile():failed to export and import the data ", perm1, perm); } template<> template<> @@ -478,21 +461,14 @@ namespace tut std::istringstream istream(ostream.str()); perm1.importLegacyStream(istream); - ensure("exportLegacyStream()/importLegacyStream():failed to export and import the data ", perm1 == perm); + ensure_equals("exportLegacyStream()/importLegacyStream():failed to export and import the data ", perm1, perm); } template<> template<> void permission_object_t::test<22>() { - LLPermissions perm,perm1; - LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); - LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); - LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); - LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); - perm.init(creator,owner,lastOwner,group); - LLXMLNode* xml_node = perm.exportFileXML(); - perm1.importXML(xml_node); - ensure("exportFileXML()/importXML():failed to export and import the data ", perm1 == perm); + // Deleted LLPermissions::exportFileXML() and LLPermissions::importXML() + // because I can't find any non-test code references to it. 2009-05-04 JC } template<> template<> @@ -508,7 +484,7 @@ namespace tut stream1 << perm; perm1.init(creator,owner,lastOwner,group); stream2 << perm1; - ensure("1:operator << failed",(stream1.str() == stream2.str())); + ensure_equals("1:operator << failed", stream1.str(), stream2.str()); } template<> template<> @@ -539,19 +515,19 @@ namespace tut { LLAggregatePermissions AggrPermission; LLAggregatePermissions AggrPermission1; - ensure("getU8() function failed", (AggrPermission.getU8() == 0)); - ensure("isEmpty() function failed", (AggrPermission.isEmpty() == TRUE)); + ensure_equals("getU8() function failed", AggrPermission.getU8(), 0); + ensure("isEmpty() function failed", AggrPermission.isEmpty()); AggrPermission.getValue(PERM_TRANSFER); ensure_equals("getValue() function failed", AggrPermission.getValue(PERM_TRANSFER), 0x00); AggrPermission.aggregate(PERM_ITEM_UNRESTRICTED); - ensure("aggregate() function failed", (AggrPermission.isEmpty() == FALSE)); + ensure("aggregate() function failed", ! AggrPermission.isEmpty()); AggrPermission1.aggregate(AggrPermission); - ensure("aggregate() function failed", (AggrPermission1.isEmpty() == FALSE)); + ensure("aggregate() function failed", ! AggrPermission1.isEmpty()); std::ostringstream stream1; stream1 << AggrPermission; - ensure("operator<< failed", (stream1.str() == "{PI_COPY=All, PI_MODIFY=All, PI_TRANSFER=All}")); + ensure_equals("operator<< failed", stream1.str(), "{PI_COPY=All, PI_MODIFY=All, PI_TRANSFER=All}"); } } diff --git a/indra/test/llpipeutil.cpp b/indra/test/llpipeutil.cpp index c9c1eeb8b4..db76a370e0 100644 --- a/indra/test/llpipeutil.cpp +++ b/indra/test/llpipeutil.cpp @@ -3,30 +3,25 @@ * @date 2006-05-18 * @brief Utility pipe fittings for injecting and extracting strings * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/test/llpipeutil.h b/indra/test/llpipeutil.h index a52f141d55..5deb26764f 100644 --- a/indra/test/llpipeutil.h +++ b/indra/test/llpipeutil.h @@ -3,30 +3,25 @@ * @date 2006-05-18 * @brief Utility pipe fittings for injecting and extracting strings * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/test/llsaleinfo_tut.cpp b/indra/test/llsaleinfo_tut.cpp index 0d0c52a2dd..09fca2abba 100644 --- a/indra/test/llsaleinfo_tut.cpp +++ b/indra/test/llsaleinfo_tut.cpp @@ -4,34 +4,29 @@ * @date 2007-03 * @brief Test cases of llsaleinfo.h * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" #include "llsaleinfo.h" @@ -53,7 +48,7 @@ namespace tut S32 sale_price = 10000; LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price); - char* sale= "copy"; + const char* sale= "copy"; LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1); @@ -166,19 +161,8 @@ namespace tut template<> template<> void llsaleinfo_test_t::test<4>() { -// LLXMLNode is teh suck. -#if 0 - S32 sale_price = 23445; - LLSaleInfo saleinfo(LLSaleInfo::FS_CONTENTS, sale_price); - - LLXMLNode* x_node = saleinfo.exportFileXML(); - - LLSaleInfo saleinfo1(LLSaleInfo::FS_NOT, 0); - - saleinfo1.importXML(x_node); - ensure_equals("1.importXML() fn failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice()); - ensure_equals("2.importXML() fn failed", saleinfo.getSaleType(), saleinfo1.getSaleType()); -#endif + // Deleted LLSaleInfo::exportFileXML() and LLSaleInfo::importXML() + // because I can't find any non-test code references to it. 2009-05-04 JC } template<> template<> diff --git a/indra/test/llscriptresource_tut.cpp b/indra/test/llscriptresource_tut.cpp new file mode 100644 index 0000000000..7a3b824e6d --- /dev/null +++ b/indra/test/llscriptresource_tut.cpp @@ -0,0 +1,198 @@ +/** + * @file llscriptresource_tut.cpp + * @brief Test LLScriptResource + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +//#include <tut/tut.h> +#include "linden_common.h" + +#include "lltut.h" + +#include "llscriptresource.h" +#include "llscriptresourceconsumer.h" +#include "llscriptresourcepool.h" + +class TestConsumer : public LLScriptResourceConsumer +{ +public: + TestConsumer() + : mUsedURLs(0) + { } + + // LLScriptResourceConsumer interface: + S32 getUsedPublicURLs() const + { + return mUsedURLs; + } + + // Test details: + S32 mUsedURLs; +}; + + +namespace tut +{ + class LLScriptResourceTestData + { + }; + + typedef test_group<LLScriptResourceTestData> LLScriptResourceTestGroup; + typedef LLScriptResourceTestGroup::object LLScriptResourceTestObject; + LLScriptResourceTestGroup scriptResourceTestGroup("scriptResource"); + + template<> template<> + void LLScriptResourceTestObject::test<1>() + { + LLScriptResource resource; + U32 total = 42; + + resource.setTotal(total); + ensure_equals("Verify set/get total", resource.getTotal(), total); + ensure_equals("Verify all resources are initially available",resource.getAvailable(),total); + + // Requesting too many, releasing non-allocated + ensure("Request total + 1 resources should fail",!resource.request(total + 1)); + ensure_equals("Verify all resources available after failed request",resource.getAvailable(),total); + + ensure("Releasing resources when none allocated should fail",!resource.release()); + ensure_equals("All resources should be available after failed release",resource.getAvailable(),total); + + ensure("Request one resource", resource.request()); + ensure_equals("Verify available resources after successful request",resource.getAvailable(),total - 1); + + // Is this right? Or should we release all used resources if we try to release more than are currently used? + ensure("Release more resources than allocated",!resource.release(2)); + ensure_equals("Verify resource availability after failed release",resource.getAvailable(),total - 1); + + ensure("Release a resource",resource.release()); + ensure_equals("Verify all resources available after successful release",resource.getAvailable(),total); + } + + + template<> template<> + void LLScriptResourceTestObject::test<2>() + { + LLScriptResource resource; + U32 total = 42; + + resource.setTotal(total); + + S32 resources_to_request = 30; + ensure("Get multiple resources resources",resource.request(resources_to_request)); + ensure_equals("Verify available resources is correct after request of multiple resources",resource.getAvailable(), total - resources_to_request); + + S32 resources_to_release = (resources_to_request / 2); + ensure("Release some resources",resource.release(resources_to_release)); + + S32 expected_available = (total - resources_to_request + resources_to_release); + ensure_equals("Verify available resources after release of some resources",resource.getAvailable(), expected_available); + + resources_to_release = (resources_to_request - resources_to_release); + ensure("Release remaining resources",resource.release(resources_to_release)); + + ensure_equals("Verify available resources after release of remaining resources",resource.getAvailable(), total); + } + + template<> template<> + void LLScriptResourceTestObject::test<3>() + { + LLScriptResource resource; + + U32 total = 42; + resource.setTotal(total); + + ensure("Request all resources",resource.request(total)); + + U32 low_total = 10; + ensure("Release all resources",resource.release(total)); + ensure_equals("Verify all resources available after releasing",resource.getAvailable(),total); + + resource.setTotal(low_total); + ensure_equals("Verify low total resources are available after set",resource.getAvailable(),low_total); + } + + + template<> template<> + void LLScriptResourceTestObject::test<4>() + { + S32 big_resource_total = 100; + S32 small_resource_total = 10; + LLScriptResourcePool big_pool; + big_pool.getPublicURLResource().setTotal(big_resource_total); + LLScriptResourcePool small_pool; + small_pool.getPublicURLResource().setTotal(small_resource_total); + + TestConsumer consumer; + LLScriptResourcePool& initial_pool = consumer.getScriptResourcePool(); + ensure("Initial resource pool is 'null'.", (&initial_pool == &LLScriptResourcePool::null)); + + consumer.switchScriptResourcePools(big_pool); + LLScriptResourcePool& get_pool = consumer.getScriptResourcePool(); + ensure("Get resource that was set.", (&big_pool == &get_pool)); + + ensure_equals("No public urls in use yet.", consumer.getUsedPublicURLs(),0); + + S32 request_urls = 5; + consumer.mUsedURLs = request_urls; + consumer.getScriptResourcePool().getPublicURLResource().request(request_urls); + + ensure_equals("Available urls on big_pool is 5 less than total.", + big_pool.getPublicURLResource().getAvailable(), big_resource_total - request_urls); + + ensure("Switching from big pool to small pool", + consumer.switchScriptResourcePools(small_pool)); + + ensure_equals("All resources available to big pool again", + big_pool.getPublicURLResource().getAvailable(), big_resource_total); + + ensure_equals("Available urls on small pool is 5 less than total.", + small_pool.getPublicURLResource().getAvailable(), small_resource_total - request_urls); + + ensure("Switching from small pool to big pool", + consumer.switchScriptResourcePools(big_pool)); + + consumer.getScriptResourcePool().getPublicURLResource().release(request_urls); + + request_urls = 50; // Too many for the small_pool + + consumer.mUsedURLs = request_urls; + consumer.getScriptResourcePool().getPublicURLResource().request(request_urls); + + // Verify big pool has them + ensure_equals("Available urls on big pool is 50 less than total.", + big_pool.getPublicURLResource().getAvailable(), big_resource_total - request_urls); + + // Verify can't switch to small_pool + ensure("Switching to small pool with too many resources", + !consumer.switchScriptResourcePools(small_pool)); + + // Verify big pool still accounting for used resources + ensure_equals("Available urls on big_pool is still 50 less than total.", + big_pool.getPublicURLResource().getAvailable(), big_resource_total - request_urls); + + // Verify small pool still has all resources available. + ensure_equals("All resources in small pool are still available.", + small_pool.getPublicURLResource().getAvailable(), small_resource_total); + } +} diff --git a/indra/test/llsd_new_tut.cpp b/indra/test/llsd_new_tut.cpp index b40d4fa348..dd93b36f04 100644 --- a/indra/test/llsd_new_tut.cpp +++ b/indra/test/llsd_new_tut.cpp @@ -3,34 +3,29 @@ * @date February 2006 * @brief LLSD unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" @@ -108,7 +103,7 @@ namespace tut SDCleanupCheck check; LLSD v; - + v = true; ensureTypeAndValue("set true", v, true); v = false; ensureTypeAndValue("set false", v, false); v = true; ensureTypeAndValue("set true again", v, true); @@ -132,13 +127,11 @@ namespace tut v = newUUID; ensureTypeAndValue("set to new UUID", v, newUUID); v = nullUUID; ensureTypeAndValue("set to null again", v, nullUUID); - // strings must be tested with three (!) types of string objects + // strings must be tested with two types of string objects std::string s = "now is the time"; - LLString ls = "for all good zorks"; - const char* cs = "to come to the air of their planet"; + const char* cs = "for all good zorks"; v = s; ensureTypeAndValue("set to std::string", v, s); - v = ls; ensureTypeAndValue("set to LLString", v, ls); v = cs; ensureTypeAndValue("set to const char*", v, cs); LLDate epoch; @@ -186,10 +179,10 @@ namespace tut ensureTypeAndValue("construct std::string", ss1, "abc"); LLSD ss2 = std::string("abc"); ensureTypeAndValue("initialize std::string",ss2, "abc"); - LLSD sl1(LLString("def")); - ensureTypeAndValue("construct LLString", sl1, "def"); - LLSD sl2 = LLString("def"); - ensureTypeAndValue("initialize LLString", sl2, "def"); + LLSD sl1(std::string("def")); + ensureTypeAndValue("construct std::string", sl1, "def"); + LLSD sl2 = std::string("def"); + ensureTypeAndValue("initialize std::string", sl2, "def"); LLSD sc1("ghi"); ensureTypeAndValue("construct const char*", sc1, "ghi"); LLSD sc2 = "ghi"; @@ -432,10 +425,6 @@ namespace tut // SAD s = v; ensure_equals("assign to string", s, " 42.375"); s = (std::string)v; ensure_equals("cast to string", s, " 42.375"); - LLString t = "yo"; -// SAD t = v; ensure_equals("assign to LLString", t, " 42.375"); - t = (LLString)v; ensure_equals("cast to LLString", t, " 42.375"); - std::string uuidStr = "b1e50c2b-b627-4d23-8a86-a65d97b6319b"; v = uuidStr; LLUUID u; @@ -486,10 +475,10 @@ namespace tut ensure_equals("contruct string", s1, " 42.375"); ensure_equals("initialize string", s2, " 42.375"); - LLString t1(v); - LLString t2 = v.asString(); // SAD - ensure_equals("contruct LLString", t1, " 42.375"); - ensure_equals("initialize LLString", t2, " 42.375"); + std::string t1(v); + std::string t2 = v.asString(); // SAD + ensure_equals("contruct std::string", t1, " 42.375"); + ensure_equals("initialize std::string", t2, " 42.375"); std::string uuidStr = "b1e50c2b-b627-4d23-8a86-a65d97b6319b"; v = uuidStr; @@ -755,6 +744,15 @@ namespace tut } } + template<> template<> + void SDTestObject::test<14>() + // make sure that assignment of char* NULL in a string does not crash. + { + LLSD v; + v = (const char*)NULL; + ensure("type is a string", v.isString()); + } + /* TO DO: conversion of undefined to UUID, Date, URI and Binary conversion of undefined to map and array diff --git a/indra/test/llsdmessagebuilder_tut.cpp b/indra/test/llsdmessagebuilder_tut.cpp index 96b37cc262..cc6f78decd 100755..100644 --- a/indra/test/llsdmessagebuilder_tut.cpp +++ b/indra/test/llsdmessagebuilder_tut.cpp @@ -3,37 +3,33 @@ * @date February 2006 * @brief LLSDMessageBuilder unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" +#include "llmessagetemplate.h" #include "llsdmessagebuilder.h" #include "llsdmessagereader.h" #include "llsdtraits.h" @@ -42,10 +38,26 @@ #include "v3dmath.h" #include "v3math.h" #include "v4math.h" +#include "llsdutil.h" +//#include "llsdutil.cpp" +#include "llsdutil_math.cpp" +#include "lltemplatemessagebuilder.h" namespace tut { + static LLTemplateMessageBuilder::message_template_name_map_t templateNameMap; + + LLMsgData* messageData = NULL; + LLMsgBlkData* messageBlockData = NULL; + struct LLSDMessageBuilderTestData { + + LLSDMessageBuilderTestData() + { + messageData = new LLMsgData("testMessage"); + messageBlockData = new LLMsgBlkData("testBlock", 0); + } + static LLSDMessageBuilder defaultBuilder() { LLSDMessageBuilder builder; @@ -60,6 +72,43 @@ namespace tut reader.setMessage("name", builder.getMessage()); return reader; } + + static void addValue(LLMsgBlkData* mbd, char* name, void* v, EMsgVariableType type, int size, int data_size = -1) + { + LLMsgVarData tmp(name, type); + tmp.addData(v, size, type, data_size); + mbd->mMemberVarData[name] = tmp; + } + + + static LLMessageBlock* defaultTemplateBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) + { + return createTemplateBlock(_PREHASH_Test0, type, size, block); + } + + static LLMessageBlock* createTemplateBlock(char* name, const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) + { + LLMessageBlock* result = new LLMessageBlock(name, block); + if(type != MVT_NULL) + { + result->addVariable(_PREHASH_Test0, type, size); + } + return result; + } + + static LLTemplateMessageBuilder* defaultTemplateBuilder(LLMessageTemplate& messageTemplate, char* name = _PREHASH_Test0) + { + templateNameMap[_PREHASH_TestMessage] = &messageTemplate; + LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(templateNameMap); + builder->newMessage(_PREHASH_TestMessage); + builder->nextBlock(name); + return builder; + } + + static LLMessageTemplate defaultTemplate() + { + return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH); + } }; typedef test_group<LLSDMessageBuilderTestData> LLSDMessageBuilderTestGroup; @@ -279,5 +328,509 @@ namespace tut outValue = buffer; ensure_equals("Ensure String", inValue, outValue); } + + template<> template<> + void LLSDMessageBuilderTestObject::test<19>() + { + LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0); + LLMsgData* md = new LLMsgData("testMessage"); + md->addBlock(mbd); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*md); + LLSD output = builder.getMessage(); + + ensure("Ensure message block created when copied from legacy message to llsd", output["testBlock"].isDefined()); + } + + // MVT_FIXED + template<> template<> + void LLSDMessageBuilderTestObject::test<20>() + { + char binData[] = "abcdefghijklmnop"; + + addValue(messageBlockData, (char *)"testBinData", &binData, MVT_FIXED, sizeof(binData)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure fixed binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData), binData, sizeof(binData)); + } + + // MVT_VARIABLE data_size 1 (U8's) + template<> template<> + void LLSDMessageBuilderTestObject::test<21>() + { + /* U8 binData[] = "abcdefghijklmnop"; + + addValue(messageBlockData, "testBinData", &binData, MVT_VARIABLE, sizeof(binData), 1); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_VARIABLE U8 binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData), binData, sizeof(binData));*/ + } + + // MVT_VARIABLE data_size 2 (U16's) + template<> template<> + void LLSDMessageBuilderTestObject::test<22>() + { + U16 binData[] = {1,2,3,4,5,6,7,8,9}; //9 shorts + + addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 1, 2); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_VARIABLE U16 binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData) >> 1, binData, sizeof(binData) >> 1); + } + + // MVT_VARIABLE data_size 4 (S32's) + template<> template<> + void LLSDMessageBuilderTestObject::test<23>() + { + U32 binData[] = {9,8,7,6,5,4,3,2,1}; + + addValue(messageBlockData, (char *)"testBinData", &binData, MVT_VARIABLE, sizeof(binData) >> 2, 4); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_VARIABLE S32 binary data works in a message copied from legacy to llsd", + &v[0], sizeof(binData) >> 2, binData, sizeof(binData) >> 2); + } + + // MVT_U8 + template<> template<> + void LLSDMessageBuilderTestObject::test<24>() + { + U8 data = 0xa5; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U8, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U8 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_U16 + template<> template<> + void LLSDMessageBuilderTestObject::test<25>() + { + U16 data = 0xa55a; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U16 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_U32 + template<> template<> + void LLSDMessageBuilderTestObject::test<26>() + { + U32 data = 0xa55a7117; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U32, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U32 data works in a message copied from legacy to llsd", + ll_U32_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_U64 - crush into an s32: LLSD does not support 64 bit values + template<> template<> + void LLSDMessageBuilderTestObject::test<27>() + { + U64 data = U64L(0xa55a711711223344); + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U64, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_U64 data works in a message copied from legacy to llsd", + ll_U64_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_S8 + template<> template<> + void LLSDMessageBuilderTestObject::test<28>() + { + S8 data = -31; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S8, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S8 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_S16 + template<> template<> + void LLSDMessageBuilderTestObject::test<29>() + { + S16 data = -31; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S16 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_S32 + template<> template<> + void LLSDMessageBuilderTestObject::test<30>() + { + S32 data = -3100; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S32, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S32 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_S64 - crush into an s32: LLSD does not support 64 bit values + template<> template<> + void LLSDMessageBuilderTestObject::test<31>() + { + S64 data = -31003100; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S64, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_S64 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), (S32)data); + } + + // MVT_F32 + template<> template<> + void LLSDMessageBuilderTestObject::test<32>() + { + F32 data = 1234.1234f; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_F32, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_F32 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asReal(), data); + } + + // MVT_F64 + template<> template<> + void LLSDMessageBuilderTestObject::test<33>() + { + F64 data = 1234.1234; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_F64, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_F64 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asReal(), data); + } + + // MVT_LLVector3 + template<> template<> + void LLSDMessageBuilderTestObject::test<34>() + { + LLVector3 data(1,2,3); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd", + ll_vector3_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_LLVector3d + template<> template<> + void LLSDMessageBuilderTestObject::test<35>() + { + LLVector3d data(1,2,3); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector3d, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLVector3 data works in a message copied from legacy to llsd", + ll_vector3d_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_LLVector4 + template<> template<> + void LLSDMessageBuilderTestObject::test<36>() + { + LLVector4 data(1,2,3,4); + LLSD v = ll_sd_from_vector4(data); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLVector4, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLVector4 data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"], v); + } + + // MVT_LLQuaternion + template<> template<> + void LLSDMessageBuilderTestObject::test<37>() + { + LLQuaternion data(1,2,3,0); + + //we send a quaternion packed into a vec3 (w is infered) - so sizeof(vec) == 12 bytes not 16. + LLVector3 vec = data.packToVector3(); + + addValue(messageBlockData, (char *)"testBinData", &vec, MVT_LLQuaternion, sizeof(vec)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_LLQuaternion data works in a message copied from legacy to llsd", + ll_quaternion_from_sd(output["testBlock"][0]["testBinData"]), data); + } + + // MVT_LLUUID + template<> template<> + void LLSDMessageBuilderTestObject::test<38>() + { + LLUUID data("01234567-0123-0123-0123-234567abcdef"); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_LLUUID, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::string v = output["testBlock"][0]["testBinData"].asUUID().asString(); + + ensure_equals("Ensure MVT_LLUUID data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asUUID(), data); + } + + // MVT_BOOL + template<> template<> + void LLSDMessageBuilderTestObject::test<39>() + { + BOOL valueTrue = true; + BOOL valueFalse = false; + + LLMsgData* md = new LLMsgData("testMessage"); + LLMsgBlkData* mbd = new LLMsgBlkData("testBlock", 0); + addValue(mbd, (char *)"testBoolFalse", &valueFalse, MVT_BOOL, sizeof(BOOL)); + addValue(mbd, (char *)"testBoolTrue", &valueTrue, MVT_BOOL, sizeof(BOOL)); + md->addBlock(mbd); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*md); + LLSD output = builder.getMessage(); + + ensure("Ensure bools work in a message copied from legacy to llsd", + output["testBlock"][0]["testBoolTrue"].asBoolean() && !output["testBlock"][0]["testBoolFalse"].asBoolean()); + } + + // MVT_IP_ADDR + template<> template<> + void LLSDMessageBuilderTestObject::test<40>() + { + U32 data(0xff887766); + LLSD v = ll_sd_from_ipaddr(data); + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_ADDR, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_IP_ADDR data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"], v); + } + + // MVT_IP_PORT + template<> template<> + void LLSDMessageBuilderTestObject::test<41>() + { + U16 data = 0xff88; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_IP_PORT, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + ensure_equals("Ensure MVT_IP_PORT data works in a message copied from legacy to llsd", + output["testBlock"][0]["testBinData"].asInteger(), data); + } + + // MVT_U16Vec3 + template<> template<> + void LLSDMessageBuilderTestObject::test<42>() + { + U16 data[3] = {0,1,2}; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Vec3, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_U16Vec3 data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_U16Vec3 data works in a message copied from legacy to llsd", + (U16*)&v[0], 6, data, 6); + } + + // MVT_U16Quat + template<> template<> + void LLSDMessageBuilderTestObject::test<43>() + { + U16 data[4] = {0,1,2,4}; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_U16Quat, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_U16Quat data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_U16Quat data works in a message copied from legacy to llsd", + (U16*)&v[0], 8, data, 8); + } + + // MVT_S16Array + template<> template<> + void LLSDMessageBuilderTestObject::test<44>() + { + S16 data[19] = {0,-1,2,-4,5,-6,7,-8,9,-10,11,-12,13,-14,15,16,17,18}; + + addValue(messageBlockData, (char *)"testBinData", &data, MVT_S16Array, sizeof(data)); + messageData->addBlock(messageBlockData); + LLSDMessageBuilder builder = defaultBuilder(); + + builder.copyFromMessageData(*messageData); + LLSD output = builder.getMessage(); + + std::vector<U8> v = output["testBlock"][0]["testBinData"].asBinary(); + ensure("Ensure MVT_S16Array data copied from legacy to llsd give a valid vector", v.size() > 0); + + ensure_memory_matches("Ensure MVT_S16Array data works in a message copied from legacy to llsd", + (U16*)&v[0], 19, data, 19); + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<45>() + { + LLMessageTemplate messageTemplate = defaultTemplate(); + messageTemplate.addBlock(defaultTemplateBlock(MVT_U8, 1)); + U8 inValue = 2; + LLTemplateMessageBuilder* template_builder = defaultTemplateBuilder(messageTemplate); + template_builder->addU8(_PREHASH_Test0, inValue); + + LLSDMessageBuilder builder; + builder.copyFromMessageData(*template_builder->getCurrentMessage()); + LLSD output = builder.getMessage(); + + ensure_equals(output["Test0"][0]["Test0"].asInteger(), 2); + + } + + template<> template<> + void LLSDMessageBuilderTestObject::test<46>() + { + LLMessageTemplate messageTemplate = defaultTemplate(); + messageTemplate.addBlock(defaultTemplateBlock(MVT_VARIABLE, 1)); + std::string inValue = "testing"; + LLTemplateMessageBuilder* builder = defaultTemplateBuilder(messageTemplate); + builder->addString(_PREHASH_Test0, inValue.c_str()); + + LLSDMessageBuilder sd_builder; + sd_builder.copyFromMessageData(*builder->getCurrentMessage()); + LLSD output = sd_builder.getMessage(); + + ensure_equals(output["Test0"][0]["Test0"].asString(), std::string("testing")); + } + } diff --git a/indra/test/llsdmessagereader_tut.cpp b/indra/test/llsdmessagereader_tut.cpp index bee6f8a185..6dc5cf593e 100755..100644 --- a/indra/test/llsdmessagereader_tut.cpp +++ b/indra/test/llsdmessagereader_tut.cpp @@ -3,34 +3,29 @@ * @date February 2006 * @brief LLSDMessageReader unit tests * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" #include "v3dmath.h" @@ -41,6 +36,7 @@ #include "message.h" #include "llsdmessagereader.h" #include "llsdutil.h" +#include "llsdutil_math.h" namespace tut { diff --git a/indra/test/llsdtraits.h b/indra/test/llsdtraits.h index 97eece6ff0..8144aaee94 100644 --- a/indra/test/llsdtraits.h +++ b/indra/test/llsdtraits.h @@ -2,30 +2,25 @@ * @file llsdtraits.h * @brief Unit test helpers * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -84,10 +79,6 @@ LLSDTraits<LLSD::String>::LLSDTraits() { } template<> -class LLSDTraits<LLString> : public LLSDTraits<LLSD::String> -{ }; - -template<> class LLSDTraits<const char*> : public LLSDTraits<LLSD::String> { }; diff --git a/indra/test/llsdutil_tut.cpp b/indra/test/llsdutil_tut.cpp index e9a7c379bb..140f4b832b 100644 --- a/indra/test/llsdutil_tut.cpp +++ b/indra/test/llsdutil_tut.cpp @@ -4,30 +4,25 @@ * @date 2007-02 * @brief LLSD conversion routines test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -43,12 +38,42 @@ #include "v4math.h" #include "llquaternion.h" #include "llsdutil.h" - +#include "llsdutil_math.h" +#include "stringize.h" +#include <set> +#include <boost/range.hpp> namespace tut { struct llsdutil_data { + void test_matches(const std::string& proto_key, const LLSD& possibles, + const char** begin, const char** end) + { + std::set<std::string> succeed(begin, end); + LLSD prototype(possibles[proto_key]); + for (LLSD::map_const_iterator pi(possibles.beginMap()), pend(possibles.endMap()); + pi != pend; ++pi) + { + std::string match(llsd_matches(prototype, pi->second)); + std::set<std::string>::const_iterator found = succeed.find(pi->first); + if (found != succeed.end()) + { + // This test is supposed to succeed. Comparing to the + // empty string ensures that if the test fails, it will + // display the string received so we can tell what failed. + ensure_equals("match", match, ""); + } + else + { + // This test is supposed to fail. If we get a false match, + // the string 'match' will be empty, which doesn't tell us + // much about which case went awry. So construct a more + // detailed description string. + ensure(proto_key + " shouldn't match " + pi->first, ! match.empty()); + } + } + } }; typedef test_group<llsdutil_data> llsdutil_test;; typedef llsdutil_test::object llsdutil_object; @@ -158,4 +183,207 @@ namespace tut LLSD sd1 = ll_sd_from_color4(c1); ensure_equals("sd -> LLColor4 -> sd", sd, sd1); } + + template<> template<> + void llsdutil_object::test<9>() + { + set_test_name("llsd_matches"); + + // for this test, construct a map of all possible LLSD types + LLSD map; + map.insert("empty", LLSD()); + map.insert("Boolean", LLSD::Boolean()); + map.insert("Integer", LLSD::Integer(0)); + map.insert("Real", LLSD::Real(0.0)); + map.insert("String", LLSD::String("bah")); + map.insert("NumString", LLSD::String("1")); + map.insert("UUID", LLSD::UUID()); + map.insert("Date", LLSD::Date()); + map.insert("URI", LLSD::URI()); + map.insert("Binary", LLSD::Binary()); + map.insert("Map", LLSD().with("foo", LLSD())); + // Only an empty array can be constructed on the fly + LLSD array; + array.append(LLSD()); + map.insert("Array", array); + + // These iterators are declared outside our various for loops to avoid + // fatal MSVC warning: "I used to be broken, but I'm all better now!" + LLSD::map_const_iterator mi, mend(map.endMap()); + + /*-------------------------- llsd_matches --------------------------*/ + + // empty prototype matches anything + for (mi = map.beginMap(); mi != mend; ++mi) + { + ensure_equals(std::string("empty matches ") + mi->first, llsd_matches(LLSD(), mi->second), ""); + } + + LLSD proto_array, data_array; + for (int i = 0; i < 3; ++i) + { + proto_array.append(LLSD()); + data_array.append(LLSD()); + } + + // prototype array matches only array + for (mi = map.beginMap(); mi != mend; ++mi) + { + ensure(std::string("array doesn't match ") + mi->first, + ! llsd_matches(proto_array, mi->second).empty()); + } + + // data array must be at least as long as prototype array + proto_array.append(LLSD()); + ensure_equals("data array too short", llsd_matches(proto_array, data_array), + "Array size 4 required instead of Array size 3"); + data_array.append(LLSD()); + ensure_equals("data array just right", llsd_matches(proto_array, data_array), ""); + data_array.append(LLSD()); + ensure_equals("data array longer", llsd_matches(proto_array, data_array), ""); + + // array element matching + data_array[0] = LLSD::String(); + ensure_equals("undefined prototype array entry", llsd_matches(proto_array, data_array), ""); + proto_array[0] = LLSD::Binary(); + ensure_equals("scalar prototype array entry", llsd_matches(proto_array, data_array), + "[0]: Binary required instead of String"); + data_array[0] = LLSD::Binary(); + ensure_equals("matching prototype array entry", llsd_matches(proto_array, data_array), ""); + + // build a coupla maps + LLSD proto_map, data_map; + data_map["got"] = LLSD(); + data_map["found"] = LLSD(); + for (LLSD::map_const_iterator dmi(data_map.beginMap()), dmend(data_map.endMap()); + dmi != dmend; ++dmi) + { + proto_map[dmi->first] = dmi->second; + } + proto_map["foo"] = LLSD(); + proto_map["bar"] = LLSD(); + + // prototype map matches only map + for (mi = map.beginMap(); mi != mend; ++mi) + { + ensure(std::string("map doesn't match ") + mi->first, + ! llsd_matches(proto_map, mi->second).empty()); + } + + // data map must contain all keys in prototype map + std::string error(llsd_matches(proto_map, data_map)); + ensure_contains("missing keys", error, "missing keys"); + ensure_contains("missing foo", error, "foo"); + ensure_contains("missing bar", error, "bar"); + ensure_does_not_contain("found found", error, "found"); + ensure_does_not_contain("got got", error, "got"); + data_map["bar"] = LLSD(); + error = llsd_matches(proto_map, data_map); + ensure_contains("missing foo", error, "foo"); + ensure_does_not_contain("got bar", error, "bar"); + data_map["foo"] = LLSD(); + ensure_equals("data map just right", llsd_matches(proto_map, data_map), ""); + data_map["extra"] = LLSD(); + ensure_equals("data map with extra", llsd_matches(proto_map, data_map), ""); + + // map element matching + data_map["foo"] = LLSD::String(); + ensure_equals("undefined prototype map entry", llsd_matches(proto_map, data_map), ""); + proto_map["foo"] = LLSD::Binary(); + ensure_equals("scalar prototype map entry", llsd_matches(proto_map, data_map), + "['foo']: Binary required instead of String"); + data_map["foo"] = LLSD::Binary(); + ensure_equals("matching prototype map entry", llsd_matches(proto_map, data_map), ""); + + // String + { + static const char* matches[] = { "String", "NumString", "Boolean", "Integer", + "Real", "UUID", "Date", "URI" }; + test_matches("String", map, boost::begin(matches), boost::end(matches)); + } + + // Boolean, Integer, Real + static const char* numerics[] = { "Boolean", "Integer", "Real" }; + for (const char **ni = boost::begin(numerics), **nend = boost::end(numerics); + ni != nend; ++ni) + { + static const char* matches[] = { "Boolean", "Integer", "Real", "String", "NumString" }; + test_matches(*ni, map, boost::begin(matches), boost::end(matches)); + } + + // UUID + { + static const char* matches[] = { "UUID", "String", "NumString" }; + test_matches("UUID", map, boost::begin(matches), boost::end(matches)); + } + + // Date + { + static const char* matches[] = { "Date", "String", "NumString" }; + test_matches("Date", map, boost::begin(matches), boost::end(matches)); + } + + // URI + { + static const char* matches[] = { "URI", "String", "NumString" }; + test_matches("URI", map, boost::begin(matches), boost::end(matches)); + } + + // Binary + { + static const char* matches[] = { "Binary" }; + test_matches("Binary", map, boost::begin(matches), boost::end(matches)); + } + + /*-------------------------- llsd_equals ---------------------------*/ + + // Cross-product of each LLSD type with every other + for (LLSD::map_const_iterator lmi(map.beginMap()), lmend(map.endMap()); + lmi != lmend; ++lmi) + { + for (LLSD::map_const_iterator rmi(map.beginMap()), rmend(map.endMap()); + rmi != rmend; ++rmi) + { + // Name this test based on the map keys naming the types of + // interest, e.g "String::Integer". + // We expect the values (xmi->second) to be equal if and only + // if the type names (xmi->first) are equal. + ensure(STRINGIZE(lmi->first << "::" << rmi->first), + bool(lmi->first == rmi->first) == + bool(llsd_equals(lmi->second, rmi->second))); + } + } + + // Array cases + LLSD rarray; + rarray.append(1.0); + rarray.append(2); + rarray.append("3"); + LLSD larray(rarray); + ensure("llsd_equals(equal arrays)", llsd_equals(larray, rarray)); + rarray[2] = "4"; + ensure("llsd_equals(different [2])", ! llsd_equals(larray, rarray)); + rarray = larray; + rarray.append(LLSD::Date()); + ensure("llsd_equals(longer right array)", ! llsd_equals(larray, rarray)); + rarray = larray; + rarray.erase(2); + ensure("llsd_equals(shorter right array)", ! llsd_equals(larray, rarray)); + + // Map cases + LLSD rmap; + rmap["San Francisco"] = 65; + rmap["Phoenix"] = 92; + rmap["Boston"] = 77; + LLSD lmap(rmap); + ensure("llsd_equals(equal maps)", llsd_equals(lmap, rmap)); + rmap["Boston"] = 80; + ensure("llsd_equals(different [\"Boston\"])", ! llsd_equals(lmap, rmap)); + rmap = lmap; + rmap["Atlanta"] = 95; + ensure("llsd_equals(superset right map)", ! llsd_equals(lmap, rmap)); + rmap = lmap; + lmap["Seattle"] = 72; + ensure("llsd_equals(superset left map)", ! llsd_equals(lmap, rmap)); + } } diff --git a/indra/test/llservicebuilder_tut.cpp b/indra/test/llservicebuilder_tut.cpp index 14f3774f7c..8f5be3011c 100644 --- a/indra/test/llservicebuilder_tut.cpp +++ b/indra/test/llservicebuilder_tut.cpp @@ -3,34 +3,29 @@ * @brief LLServiceBuilder unit tests * @date March 2007 * -* $LicenseInfo:firstyear=2006&license=viewergpl$ -* -* Copyright (c) 2006-2007, Linden Research, Inc. -* +* $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code -* The source code in this file ("Source Code") is provided by Linden Lab -* to you under the terms of the GNU General Public License, version 2.0 -* ("GPL"), unless you have obtained a separate licensing agreement -* ("Other License"), formally executed by you and Linden Lab. Terms of -* the GPL can be found in doc/GPL-license.txt in this distribution, or -* online at http://secondlife.com/developers/opensource/gplv2 +* Copyright (C) 2010, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. * -* There are special exceptions to the terms and conditions of the GPL as -* it is applied to this Source Code. View the full text of the exception -* in the file doc/FLOSS-exception.txt in this software distribution, or -* online at http://secondlife.com/developers/opensource/flossexception +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. * -* By copying, modifying or distributing this software, you acknowledge -* that you have read and understood your obligations described above, -* and agree to abide by those obligations. +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * -* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO -* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, -* COMPLETENESS OR PERFORMANCE. +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" diff --git a/indra/test/llstreamtools_tut.cpp b/indra/test/llstreamtools_tut.cpp index d1466e923e..a93f2e8f65 100644 --- a/indra/test/llstreamtools_tut.cpp +++ b/indra/test/llstreamtools_tut.cpp @@ -4,34 +4,29 @@ * @date February 2007 * @brief llstreamtools test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "llstreamtools.h" diff --git a/indra/test/lltemplatemessagebuilder_tut.cpp b/indra/test/lltemplatemessagebuilder_tut.cpp index 52d1436761..09beb53869 100644 --- a/indra/test/lltemplatemessagebuilder_tut.cpp +++ b/indra/test/lltemplatemessagebuilder_tut.cpp @@ -3,34 +3,29 @@ * @date 2007-04 * @brief Tests for building messages. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" @@ -59,6 +54,9 @@ namespace tut if(! init) { ll_init_apr(); + const F32 circuit_heartbeat_interval=5; + const F32 circuit_timeout=100; + start_messaging_system("notafile", 13035, LL_VERSION_MAJOR, LL_VERSION_MINOR, @@ -66,7 +64,9 @@ namespace tut FALSE, "notasharedsecret", NULL, - false); + false, + circuit_heartbeat_interval, + circuit_timeout); //init_prehash_data(); init = true; } diff --git a/indra/test/lltimestampcache_tut.cpp b/indra/test/lltimestampcache_tut.cpp new file mode 100644 index 0000000000..857a17a6d5 --- /dev/null +++ b/indra/test/lltimestampcache_tut.cpp @@ -0,0 +1,124 @@ +/** + * @file lltimestampcache_tut.cpp + * @author James Tess + * @date 2008-12-03 + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include <tut/tut.hpp> + +#include "linden_common.h" +#include "../mapserver/lltimestampcache.h" +#include "lltut.h" + + +namespace tut +{ + struct LLTimestampCacheTestData + { + }; + + typedef test_group<LLTimestampCacheTestData> LLTimestampCacheTestGroup; + typedef LLTimestampCacheTestGroup::object LLTimestampCacheTestObject; + + LLTimestampCacheTestGroup timestampCacheTestGroup("LLTimestampCache"); + + // Most common usage + template<> template<> + void LLTimestampCacheTestObject::test<1>() + { + LLTimestampCache<std::string, std::string> cache; + // put in some data + cache.insert("key1", "val1", 1); + cache.insert("key2", "val2", 2); + cache.insert("key3", "val3", 3); + ensure_equals("size is 3", cache.size(), 3); + // check some items + ensure("has key1", cache.has("key1")); + ensure("no invalid key", !cache.has("invalid key")); + // get some items + ensure_equals("get key1", cache.get("key1", 4), "val1"); + ensure_equals("get invalid key", + cache.get("invalid key", 4), std::string() ); + // timestamps + ensure_equals("key1 timestamp updated", cache.getTimestamp("key1"), 4); + ensure_equals("invalid key timestamp", + cache.getTimestamp("invalid key"), 0); + } + + // New empty cache shouldn't have any entries + template<> template<> + void LLTimestampCacheTestObject::test<2>() + { + LLTimestampCache<std::string, std::string> cache; + ensure_equals("starts empty", cache.size(), 0); + ensure_equals("has nothing", cache.has("foo"), false); + ensure_equals("gets nothing", cache.get("foo", 0), std::string() ); + U32 max_time = 0xFFFFFFFF; + ensure_equals("erases nothing", cache.eraseBefore(max_time), 0); + } + + // Non empty cache + template<> template<> + void LLTimestampCacheTestObject::test<3>() + { + LLTimestampCache<std::string, std::string> cache; + cache.insert("foo", "bar", 123); + ensure_equals("size one", cache.size(), 1); + ensure_equals("has it", cache.has("foo"), true); + ensure_equals("timestamp correct", cache.getTimestamp("foo"), 123); + std::string value = cache.get("foo", 456); + ensure_equals("get value", value, "bar"); + ensure_equals("timestamp updated", cache.getTimestamp("foo"), 456); + ensure_equals("erase nothing", cache.eraseBefore(0), 0); + ensure_equals("erase one", cache.eraseBefore(789), 1); + ensure_equals("empty after erase", cache.size(), 0); + } + + // Recache of item should update timestamp + template<> template<> + void LLTimestampCacheTestObject::test<4>() + { + LLTimestampCache<std::string, std::string> cache; + cache.insert("foo", "bar", 123); + cache.insert("foo", "bar", 456); + ensure_equals("duplicate suppressed", cache.size(), 1); + ensure_equals("timestamp replaced", cache.getTimestamp("foo"), 456); + } + + // Erasing some items + template<> template<> + void LLTimestampCacheTestObject::test<5>() + { + LLTimestampCache<std::string, std::string> cache; + cache.insert("key1", "val1", 1); + cache.insert("key2", "val2", 2); + cache.insert("key3", "val3", 3); + cache.insert("key4", "val4", 4); + size_t erased = cache.eraseBefore(3); + ensure_equals("erase range", erased, 2); + ensure_equals("cache post erase", cache.size(), 2); + ensure_equals("has key3", cache.has("key3"), true); + ensure_equals("not has key2", cache.has("key2"), false); + } +} diff --git a/indra/test/lltranscode_tut.cpp b/indra/test/lltranscode_tut.cpp new file mode 100644 index 0000000000..2431afad27 --- /dev/null +++ b/indra/test/lltranscode_tut.cpp @@ -0,0 +1,89 @@ +/** + * @file llscriptresource_tut.cpp + * @brief Test LLScriptResource + * + * $LicenseInfo:firstyear=2008&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +//#include <tut/tut.h> +#include "linden_common.h" + +#include "lltut.h" + +#include "../newsim/lltranscode.cpp" // include TU to pull in newsim implementation. + +static const char test_utf8[] = "Edelwei\xc3\x9f"; +static const char test_utf7[] = "Edelwei+AN8-"; +static const char test_latin1[] = "Edelwei\xdf"; +static const char test_latin2[] = "Edelwei\xdf"; + +namespace tut +{ + class LLTranscodeTestData + { + }; + + typedef test_group<LLTranscodeTestData> LLTranscodeTestGroup; + typedef LLTranscodeTestGroup::object LLTranscodeTestObject; + LLTranscodeTestGroup transcodeTestGroup("transcode"); + + template<> template<> + void LLTranscodeTestObject::test<1>() + { +#if LL_WINDOWS + skip("Windows APR libs can't transcode."); +#endif + // Test utf8 + std::stringstream input; + std::stringstream output; + + input.str(test_utf7); + output.clear(); + LLTranscode::transcode("charset=UTF-7", input, output); + ensure_equals("UTF-7 to UTF-8 transcoding", output.str(), + std::string(test_utf8)); + + input.str(test_latin1); + output.clear(); + LLTranscode::transcode("", input, output); + ensure_equals("Default (latin_1) to UTF8 transcoding", output.str(), + std::string(test_utf8)); + + input.str(test_latin1); + output.clear(); + LLTranscode::transcode("charset=iso-8859-1", input, output); + ensure_equals("latin_1 (ISO-8859-1) to UTF8 transcoding", output.str(), + std::string(test_utf8)); + + input.str(test_latin2); + output.clear(); + LLTranscode::transcode("charset=iso-8859-2", input, output); + ensure_equals("latin_2 (ISO-8859-2) to UTF8 transcoding", output.str(), + std::string(test_utf8)); + + input.str(test_utf8); + output.clear(); + LLTranscode::transcode("charset=utf-8", input, output); + ensure_equals("UTF8 to UTF8 transcoding", output.str(), + std::string(test_utf8)); + } +} diff --git a/indra/test/lltut.cpp b/indra/test/lltut.cpp index 03a70c714d..da7031b52a 100644 --- a/indra/test/lltut.cpp +++ b/indra/test/lltut.cpp @@ -4,42 +4,39 @@ * @date 5/16/06 * @brief MacTester * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ #include "linden_common.h" + #include "lltut.h" +#include "lldate.h" #include "llformat.h" #include "llsd.h" +#include "lluri.h" namespace tut { - template<> void ensure_equals(const char* msg, const LLDate& actual, const LLDate& expected) { @@ -47,7 +44,6 @@ namespace tut actual.secondsSinceEpoch(), expected.secondsSinceEpoch()); } - template<> void ensure_equals(const char* msg, const LLURI& actual, const LLURI& expected) { @@ -55,7 +51,6 @@ namespace tut actual.asString(), expected.asString()); } - template<> void ensure_equals(const char* msg, const std::vector<U8>& actual, const std::vector<U8>& expected) { @@ -73,12 +68,15 @@ namespace tut } } - template<> void ensure_equals(const char* m, const LLSD& actual, const LLSD& expected) + { + ensure_equals(std::string(m), actual, expected); + } + + void ensure_equals(const std::string& msg, const LLSD& actual, + const LLSD& expected) { - const std::string& msg = m; - ensure_equals(msg + " type", actual.type(), expected.type()); switch (actual.type()) { @@ -199,3 +197,4 @@ namespace tut } } } + diff --git a/indra/test/lltut.h b/indra/test/lltut.h index 375d558182..55d84bcaca 100644 --- a/indra/test/lltut.h +++ b/indra/test/lltut.h @@ -4,43 +4,39 @@ * @date 2005-09-26 * @brief helper tut methods * - * $LicenseInfo:firstyear=2005&license=viewergpl$ - * - * Copyright (c) 2005-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ #ifndef LL_LLTUT_H #define LL_LLTUT_H -#include <tut/tut.h> +#include "is_approx_equal_fraction.h" // instead of llmath.h -#include "lldate.h" -#include "lluri.h" -#include "llmath.h" +#include <tut/tut.hpp> +#include <cstring> +class LLDate; class LLSD; +class LLURI; namespace tut { @@ -72,7 +68,7 @@ namespace tut inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len) { if((expected_len != actual_len) || - (memcmp(actual, expected, actual_len) != 0)) + (std::memcmp(actual, expected, actual_len) != 0)) { std::stringstream ss; ss << (msg?msg:"") << (msg?": ":"") << "not equal"; @@ -108,21 +104,20 @@ namespace tut const Q& actual,const T& expected) { ensure_equals(msg.c_str(), actual, expected); } - template<> void ensure_equals(const char* msg, const LLDate& actual, const LLDate& expected); - template<> void ensure_equals(const char* msg, const LLURI& actual, const LLURI& expected); - template<> void ensure_equals(const char* msg, const std::vector<U8>& actual, const std::vector<U8>& expected); - template<> void ensure_equals(const char* msg, const LLSD& actual, const LLSD& expected); + + void ensure_equals(const std::string& msg, + const LLSD& actual, const LLSD& expected); void ensure_starts_with(const std::string& msg, const std::string& actual, const std::string& expectedStart); diff --git a/indra/test/lluserrelations_tut.cpp b/indra/test/lluserrelations_tut.cpp index 4d07ba947e..afbcf6e5a8 100644 --- a/indra/test/lluserrelations_tut.cpp +++ b/indra/test/lluserrelations_tut.cpp @@ -4,34 +4,29 @@ * @date 2006-10-12 * @brief Unit tests for the LLRelationship class. * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lluserrelations.h" diff --git a/indra/test/lluuidhashmap_tut.cpp b/indra/test/lluuidhashmap_tut.cpp index 129d17aaa4..0544e832ce 100644 --- a/indra/test/lluuidhashmap_tut.cpp +++ b/indra/test/lluuidhashmap_tut.cpp @@ -4,34 +4,29 @@ * @date 2007-02 * @brief Test cases for LLUUIDHashMap * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lluuidhashmap.h" #include "llsdserialize.h" diff --git a/indra/test/llxorcipher_tut.cpp b/indra/test/llxorcipher_tut.cpp index a2a9b5101e..55b3faaa61 100644 --- a/indra/test/llxorcipher_tut.cpp +++ b/indra/test/llxorcipher_tut.cpp @@ -4,30 +4,25 @@ * @date 2007-03 * @brief llxorcipher, llnullcipher test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ diff --git a/indra/test/message_tut.cpp b/indra/test/message_tut.cpp index 57db6dd97a..d971b33475 100644 --- a/indra/test/message_tut.cpp +++ b/indra/test/message_tut.cpp @@ -3,34 +3,29 @@ * @date 2007-04 * @brief LLDataPacker test cases. * - * $LicenseInfo:firstyear=2007&license=viewergpl$ - * - * Copyright (c) 2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -#include <tut/tut.h> +#include <tut/tut.hpp> #include "linden_common.h" #include "lltut.h" @@ -50,6 +45,7 @@ namespace { mStatus = code; } + virtual void extendedResult(S32 code, const std::string& message, const LLSD& headers) { } S32 mStatus; }; } @@ -70,6 +66,9 @@ namespace tut //init_prehash_data(); init = true; } + const F32 circuit_heartbeat_interval=5; + const F32 circuit_timeout=100; + // currently test disconnected message system start_messaging_system("notafile", 13035, @@ -79,7 +78,10 @@ namespace tut FALSE, "notasharedsecret", NULL, - false); + false, + circuit_heartbeat_interval, + circuit_timeout + ); // generate temp dir std::ostringstream ostr; #if LL_WINDOWS @@ -93,7 +95,7 @@ namespace tut random.generate(); ostr << "message-test-" << random; mTestConfigDir = ostr.str(); - LLFile::mkdir(mTestConfigDir.c_str()); + LLFile::mkdir(mTestConfigDir); writeConfigFile(LLSD()); LLMessageConfig::initClass("simulator", ostr.str()); } @@ -107,11 +109,11 @@ namespace tut // rm contents of temp dir std::ostringstream ostr; ostr << mTestConfigDir << mSep << "message.xml"; - int rmfile = LLFile::remove(ostr.str().c_str()); + int rmfile = LLFile::remove(ostr.str()); ensure_equals("rmfile value", rmfile, 0); // rm temp dir - int rmdir = LLFile::rmdir(mTestConfigDir.c_str()); + int rmdir = LLFile::rmdir(mTestConfigDir); ensure_equals("rmdir value", rmdir, 0); } @@ -119,7 +121,7 @@ namespace tut { std::ostringstream ostr; ostr << mTestConfigDir << mSep << "message.xml"; - llofstream file(ostr.str().c_str()); + llofstream file(ostr.str()); if (file.is_open()) { LLSDSerialize::toPrettyXML(config, file); diff --git a/indra/test/mock_http_client.cpp b/indra/test/mock_http_client.cpp new file mode 100644 index 0000000000..d7ef407d52 --- /dev/null +++ b/indra/test/mock_http_client.cpp @@ -0,0 +1,83 @@ +/** + * @file mock_http_client.cpp + * @brief Framework for testing HTTP requests + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "llsdhttpserver.h" +#include "lliohttpserver.h" + +namespace tut +{ + class SuccessNode : public LLHTTPNode + { + public: + void get(ResponsePtr r, const LLSD& context) const + { + LLSD result; + result["state"] = "complete"; + result["test"] = "test"; + r->result(result); + } + void post(ResponsePtr r, const LLSD& context, const LLSD& input) const + { + LLSD result; + result["state"] = "complete"; + result["test"] = "test"; + r->result(result); + } + }; + + class ErrorNode : public LLHTTPNode + { + public: + void get(ResponsePtr r, const LLSD& context) const + { r->status(599, "Intentional error"); } + void post(ResponsePtr r, const LLSD& context, const LLSD& input) const + { r->status(input["status"], input["reason"]); } + }; + + class TimeOutNode : public LLHTTPNode + { + public: + void get(ResponsePtr r, const LLSD& context) const + { + /* do nothing, the request will eventually time out */ + } + }; + + LLSD storage; + + class LLSDStorageNode : public LLHTTPNode + { + public: + LLSD get() const{ return storage; } + LLSD put(const LLSD& value) const{ storage = value; return LLSD(); } + }; + + LLHTTPRegistration<LLSDStorageNode> gStorageNode("/test/storage"); + LLHTTPRegistration<SuccessNode> gSuccessNode("/test/success"); + LLHTTPRegistration<ErrorNode> gErrorNode("/test/error"); + LLHTTPRegistration<TimeOutNode> gTimeOutNode("/test/timeout"); +} diff --git a/indra/test/mock_http_client.h b/indra/test/mock_http_client.h new file mode 100644 index 0000000000..7668a43fdf --- /dev/null +++ b/indra/test/mock_http_client.h @@ -0,0 +1,191 @@ +/** + * @file mock_http_client.cpp + * @brief Framework for testing HTTP requests + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llsdhttpserver.h" +#include "lliohttpserver.h" +#include "llhttpclient.h" +#include "llformat.h" +#include "llpipeutil.h" +#include "llpumpio.h" + +namespace tut +{ + struct MockHttpClient + { + public: + MockHttpClient() + { + apr_pool_create(&mPool, NULL); + mServerPump = new LLPumpIO(mPool); + mClientPump = new LLPumpIO(mPool); + + LLHTTPClient::setPump(*mClientPump); + } + + ~MockHttpClient() + { + delete mServerPump; + delete mClientPump; + apr_pool_destroy(mPool); + } + + void setupTheServer() + { + LLHTTPNode& root = LLIOHTTPServer::create(mPool, *mServerPump, 8888); + + LLHTTPStandardServices::useServices(); + LLHTTPRegistrar::buildAllServices(root); + } + + void runThePump(float timeout = 100.0f) + { + LLTimer timer; + timer.setTimerExpirySec(timeout); + + while(!mSawCompleted && !timer.hasExpired()) + { + if (mServerPump) + { + mServerPump->pump(); + mServerPump->callback(); + } + if (mClientPump) + { + mClientPump->pump(); + mClientPump->callback(); + } + } + } + + void killServer() + { + delete mServerPump; + mServerPump = NULL; + } + + private: + apr_pool_t* mPool; + LLPumpIO* mServerPump; + LLPumpIO* mClientPump; + + + protected: + void ensureStatusOK() + { + if (mSawError) + { + std::string msg = + llformat("error() called when not expected, status %d", + mStatus); + fail(msg); + } + } + + void ensureStatusError() + { + if (!mSawError) + { + fail("error() wasn't called"); + } + } + + LLSD getResult() + { + return mResult; + } + + protected: + bool mSawError; + U32 mStatus; + std::string mReason; + bool mSawCompleted; + LLSD mResult; + bool mResultDeleted; + + class Result : public LLHTTPClient::Responder + { + protected: + Result(MockHttpClient& client) + : mClient(client) + { + } + + public: + static boost::intrusive_ptr<Result> build(MockHttpClient& client) + { + return boost::intrusive_ptr<Result>(new Result(client)); + } + + ~Result() + { + mClient.mResultDeleted = true; + } + + virtual void error(U32 status, const std::string& reason) + { + mClient.mSawError = true; + mClient.mStatus = status; + mClient.mReason = reason; + } + + virtual void result(const LLSD& content) + { + mClient.mResult = content; + } + + virtual void completed( + U32 status, const std::string& reason, + const LLSD& content) + { + LLHTTPClient::Responder::completed(status, reason, content); + + mClient.mSawCompleted = true; + } + + private: + MockHttpClient& mClient; + }; + + friend class Result; + + protected: + + void reset() + { + mSawError = false; + mStatus = 0; + mSawCompleted = false; + mResult.clear(); + mResultDeleted = false; + } + + LLHTTPClient::ResponderPtr newResult() + { + reset(); + return Result::build(*this); + } + }; +} diff --git a/indra/test/prim_linkability_tut.cpp b/indra/test/prim_linkability_tut.cpp index d2236a5cff..a70912e535 100644 --- a/indra/test/prim_linkability_tut.cpp +++ b/indra/test/prim_linkability_tut.cpp @@ -4,8 +4,26 @@ * @date 2007-04-23 * @brief Tests for the LLPrimLinkInfo template which computes the linkability of prims * - * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. - * $License$ + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ */ #include "linden_common.h" diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 4a9b2825f2..ffdb0cb976 100644 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -4,30 +4,25 @@ * @date 2005-09-26 * @brief Entry point for the test app. * - * $LicenseInfo:firstyear=2005&license=viewergpl$ - * - * Copyright (c) 2005-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -53,9 +48,15 @@ # include "ctype_workaround.h" #endif +#ifndef LL_WINDOWS +#include <gmock/gmock.h> +#include <gtest/gtest.h> +#endif namespace tut { + std::string sSourceDir; + test_runner_singleton runner; } @@ -63,59 +64,66 @@ class LLTestCallback : public tut::callback { public: LLTestCallback(bool verbose_mode, std::ostream *stream) : - mVerboseMode(verbose_mode), - mTotalTests(0), - mPassedTests(0), - mFailedTests(0), - mSkippedTests(0), - mSkippedFailTests(0), - mStream(stream) + mVerboseMode(verbose_mode), + mTotalTests(0), + mPassedTests(0), + mFailedTests(0), + mSkippedTests(0), + mStream(stream) { } - void run_started() + ~LLTestCallback() + { + } + + virtual void run_started() { //std::cout << "run_started" << std::endl; } - void test_completed(const tut::test_result& tr) + virtual void group_started(const std::string& name) { + std::cout << "Unit test group_started name=" << name << std::endl; + } + + virtual void group_completed(const std::string& name) { + std::cout << "Unit test group_completed name=" << name << std::endl; + } + + virtual void test_completed(const tut::test_result& tr) { ++mTotalTests; std::ostringstream out; out << "[" << tr.group << ", " << tr.test << "] "; switch(tr.result) { - case tut::test_result::ok: - ++mPassedTests; - out << "ok"; - break; - case tut::test_result::fail: - ++mFailedTests; - out << "fail"; - break; - case tut::test_result::ex: - ++mFailedTests; - out << "exception"; - break; - case tut::test_result::warn: - ++mFailedTests; - out << "test destructor throw"; - break; - case tut::test_result::term: - ++mFailedTests; - out << "abnormal termination"; - break; - case tut::test_result::skip: - ++mSkippedTests; - out << "skipped"; - break; - case tut::test_result::skip_fail: - ++mSkippedFailTests; - out << "skipped known failure"; - break; - default: - ++mFailedTests; - out << "unknown"; + case tut::test_result::ok: + ++mPassedTests; + out << "ok"; + break; + case tut::test_result::fail: + ++mFailedTests; + out << "fail"; + break; + case tut::test_result::ex: + ++mFailedTests; + out << "exception"; + break; + case tut::test_result::warn: + ++mFailedTests; + out << "test destructor throw"; + break; + case tut::test_result::term: + ++mFailedTests; + out << "abnormal termination"; + break; + case tut::test_result::skip: + ++mSkippedTests; + out << "skipped known failure"; + break; + default: + ++mFailedTests; + out << "unknown"; } if(mVerboseMode || (tr.result != tut::test_result::ok)) { @@ -132,46 +140,37 @@ public: } } - void run_completed() + virtual void run_completed() { if (mStream) { run_completed_(*mStream); } run_completed_(std::cout); + } + + virtual int getFailedTests() const { return mFailedTests; } - if (mFailedTests > 0) + virtual void run_completed_(std::ostream &stream) + { + stream << "\tTotal Tests:\t" << mTotalTests << std::endl; + stream << "\tPassed Tests:\t" << mPassedTests; + if (mPassedTests == mTotalTests) { - exit(1); + stream << "\tYAY!! \\o/"; } - } - -private: - void run_completed_(std::ostream &stream) - { stream << std::endl; - stream << "Total Tests: " << mTotalTests << std::endl; - stream << "Passed Tests: " << mPassedTests << std::endl; - stream << std::endl; - stream << "Total Tests: " << mTotalTests << std::endl; - stream << "Passed Tests: " << mPassedTests << std::endl; - if (mSkippedTests > 0) { - stream << "Skipped Tests: " << mSkippedTests << std::endl; - } - - if (mSkippedFailTests > 0) - { - stream << "Skipped known failures: " << mSkippedFailTests - << std::endl; + stream << "\tSkipped known failures:\t" << mSkippedTests + << std::endl; } if(mFailedTests > 0) { stream << "*********************************" << std::endl; - stream << "Failed Tests: " << mFailedTests << std::endl; + stream << "Failed Tests:\t" << mFailedTests << std::endl; stream << "Please report or fix the problem." << std::endl; stream << "*********************************" << std::endl; } @@ -183,10 +182,97 @@ protected: int mPassedTests; int mFailedTests; int mSkippedTests; - int mSkippedFailTests; std::ostream *mStream; }; +// TeamCity specific class which emits service messages +// http://confluence.jetbrains.net/display/TCD3/Build+Script+Interaction+with+TeamCity;#BuildScriptInteractionwithTeamCity-testReporting + +class LLTCTestCallback : public LLTestCallback +{ +public: + LLTCTestCallback(bool verbose_mode, std::ostream *stream) : + LLTestCallback(verbose_mode, stream), + mTCStream() + { + } + + ~LLTCTestCallback() + { + } + + virtual void group_started(const std::string& name) { + LLTestCallback::group_started(name); + mTCStream << "\n##teamcity[testSuiteStarted name='" << name << "']" << std::endl; + } + + virtual void group_completed(const std::string& name) { + LLTestCallback::group_completed(name); + mTCStream << "##teamcity[testSuiteFinished name='" << name << "']" << std::endl; + } + + virtual void test_completed(const tut::test_result& tr) + { + LLTestCallback::test_completed(tr); + + switch(tr.result) + { + case tut::test_result::ok: + mTCStream << "##teamcity[testStarted name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testFinished name='" << tr.group << "." << tr.test << "']" << std::endl; + break; + case tut::test_result::fail: + mTCStream << "##teamcity[testStarted name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testFailed name='" << tr.group << "." << tr.test << "' message='" << tr.message << "']" << std::endl; + mTCStream << "##teamcity[testFinished name='" << tr.group << "." << tr.test << "']" << std::endl; + break; + case tut::test_result::ex: + mTCStream << "##teamcity[testStarted name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testFailed name='" << tr.group << "." << tr.test << "' message='" << tr.message << "']" << std::endl; + mTCStream << "##teamcity[testFinished name='" << tr.group << "." << tr.test << "']" << std::endl; + break; + case tut::test_result::warn: + mTCStream << "##teamcity[testStarted name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testFailed name='" << tr.group << "." << tr.test << "' message='" << tr.message << "']" << std::endl; + mTCStream << "##teamcity[testFinished name='" << tr.group << "." << tr.test << "']" << std::endl; + break; + case tut::test_result::term: + mTCStream << "##teamcity[testStarted name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testFailed name='" << tr.group << "." << tr.test << "' message='" << tr.message << "']" << std::endl; + mTCStream << "##teamcity[testFinished name='" << tr.group << "." << tr.test << "']" << std::endl; + break; + case tut::test_result::skip: + mTCStream << "##teamcity[testStarted name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testIgnored name='" << tr.group << "." << tr.test << "']" << std::endl; + mTCStream << "##teamcity[testFinished name='" << tr.group << "." << tr.test << "']" << std::endl; + break; + default: + break; + } + + } + + virtual void run_completed() + { + LLTestCallback::run_completed(); + + // dump the TC reporting results to cout + tc_run_completed_(std::cout); + } + + virtual void tc_run_completed_(std::ostream &stream) + { + + // dump the TC reporting results to cout + stream << mTCStream.str() << std::endl; + } + +protected: + std::ostringstream mTCStream; + +}; + + static const apr_getopt_option_t TEST_CL_OPTIONS[] = { {"help", 'h', 0, "Print the help message."}, @@ -194,17 +280,18 @@ static const apr_getopt_option_t TEST_CL_OPTIONS[] = {"verbose", 'v', 0, "Verbose output."}, {"group", 'g', 1, "Run test group specified by option argument."}, {"output", 'o', 1, "Write output to the named file."}, - {"skip", 's', 1, "Skip test number specified by option argument. Only works when a specific group is being tested"}, + {"sourcedir", 's', 1, "Project source file directory from CMake."}, {"touch", 't', 1, "Touch the given file if all tests succeed"}, {"wait", 'w', 0, "Wait for input before exit."}, {"debug", 'd', 0, "Emit full debug logs."}, + {"suitename", 'x', 1, "Run tests using this suitename"}, {0, 0, 0, 0} }; void stream_usage(std::ostream& s, const char* app) { s << "Usage: " << app << " [OPTIONS]" << std::endl - << std::endl; + << std::endl; s << "This application runs the unit tests." << std::endl << std::endl; @@ -214,7 +301,7 @@ void stream_usage(std::ostream& s, const char* app) { s << " "; s << " -" << (char)option->optch << ", --" << option->name - << std::endl; + << std::endl; s << "\t" << option->description << std::endl << std::endl; ++option; } @@ -226,8 +313,6 @@ void stream_usage(std::ostream& s, const char* app) s << "\tList all available test groups." << std::endl; s << " " << app << " --group=uuid" << std::endl; s << "\tRun the test group 'uuid'." << std::endl; - s << " " << app << " --skip=2" << std::endl; - s << "\tSkip test case 2." << std::endl; } void stream_groups(std::ostream& s, const char* app) @@ -249,12 +334,17 @@ 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. +#ifndef LL_WINDOWS + ::testing::InitGoogleMock(&argc, argv); +#endif LLError::initForApplication("."); LLError::setFatalFunction(wouldHaveCrashed); LLError::setDefaultLevel(LLError::LEVEL_ERROR); - //< *TODO: should come from error config file. Note that we - // have a command line option that sets this to debug. - + //< *TODO: should come from error config file. Note that we + // have a command line option that sets this to debug. + #ifdef CTYPE_WORKAROUND ctype_workaround(); #endif @@ -276,8 +366,8 @@ int main(int argc, char **argv) // values used for controlling application bool verbose_mode = false; bool wait_at_exit = false; - int skip_test_id = 0; std::string test_group; + std::string suite_name; // values use for options parsing apr_status_t apr_err; @@ -285,7 +375,7 @@ int main(int argc, char **argv) int opt_id = 0; std::ofstream *output = NULL; const char *touch = NULL; - + while(true) { apr_err = apr_getopt_long(os, TEST_CL_OPTIONS, &opt_id, &opt_arg); @@ -294,82 +384,103 @@ int main(int argc, char **argv) { char buf[255]; /* Flawfinder: ignore */ std::cerr << "Error parsing options: " - << apr_strerror(apr_err, buf, 255) << std::endl; + << apr_strerror(apr_err, buf, 255) << std::endl; return 1; } switch (opt_id) { - case 'g': - test_group.assign(opt_arg); - break; - case 's': - skip_test_id = atoi(opt_arg); - break; - case 'h': - stream_usage(std::cout, argv[0]); - return 0; - break; - case 'l': - stream_groups(std::cout, argv[0]); - return 0; - case 'v': - verbose_mode = true; - break; - case 'o': - output = new std::ofstream; - output->open(opt_arg); - break; - case 't': - touch = opt_arg; - break; - case 'w': - wait_at_exit = true; - break; - case 'd': - // *TODO: should come from error config file. We set it to - // ERROR by default, so this allows full debug levels. - LLError::setDefaultLevel(LLError::LEVEL_DEBUG); - break; - default: - stream_usage(std::cerr, argv[0]); - return 1; - break; + case 'g': + test_group.assign(opt_arg); + break; + case 'h': + stream_usage(std::cout, argv[0]); + return 0; + break; + case 'l': + stream_groups(std::cout, argv[0]); + return 0; + case 'v': + verbose_mode = true; + break; + case 'o': + output = new std::ofstream; + output->open(opt_arg); + break; + case 's': // --sourcedir + tut::sSourceDir = opt_arg; + // For convenience, so you can use tut::sSourceDir + "myfile" + tut::sSourceDir += '/'; + break; + case 't': + touch = opt_arg; + break; + case 'w': + wait_at_exit = true; + break; + case 'd': + // *TODO: should come from error config file. We set it to + // ERROR by default, so this allows full debug levels. + LLError::setDefaultLevel(LLError::LEVEL_DEBUG); + break; + case 'x': + suite_name.assign(opt_arg); + break; + default: + stream_usage(std::cerr, argv[0]); + return 1; + break; } } // run the tests - LLTestCallback callback(verbose_mode, output); - tut::runner.get().set_callback(&callback); - + + LLTestCallback* mycallback; + if (getenv("TEAMCITY_PROJECT_NAME")) + { + mycallback = new LLTCTestCallback(verbose_mode, output); + } + else + { + mycallback = new LLTestCallback(verbose_mode, output); + } + + tut::runner.get().set_callback(mycallback); + if(test_group.empty()) { tut::runner.get().run_tests(); } else { - tut::runner.get().run_tests(test_group, skip_test_id); + tut::runner.get().run_tests(test_group); } + bool success = (mycallback->getFailedTests() == 0); + if (wait_at_exit) { - std::cerr << "Waiting for input before exiting..." << std::endl; + std::cerr << "Press return to exit..." << std::endl; std::cin.get(); } - + if (output) { output->close(); delete output; } - if (touch) + if (touch && success) { std::ofstream s; s.open(touch); s << "ok" << std::endl; s.close(); } - + apr_terminate(); - return 0; + + int retval = (success ? 0 : 1); + return retval; + + //delete mycallback; } diff --git a/indra/test/test.h b/indra/test/test.h new file mode 100644 index 0000000000..40c94283ec --- /dev/null +++ b/indra/test/test.h @@ -0,0 +1,44 @@ +/** + * @file test.h + * @author James + * @date 2009-01-12 + * + * $LicenseInfo:firstyear=2009&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ +#ifndef TEST_H +#define TEST_H + +#include <string> + +namespace tut +{ + // Source code directory from CMake, used for loading test data and + // configuration. For example: + // + // loadMyConfig( sSourceDir + "config.dat" ); + // + // Use sparingly, as hitting the file system slows down test execution + // and hence every compile. JC + extern std::string sSourceDir; +} + +#endif diff --git a/indra/test/test_llmanifest.py b/indra/test/test_llmanifest.py index dfe79e20d9..89c36f95dd 100644 --- a/indra/test/test_llmanifest.py +++ b/indra/test/test_llmanifest.py @@ -4,30 +4,25 @@ @author Ryan Williams @brief Test cases for LLManifest library. -$LicenseInfo:firstyear=2006&license=viewergpl$ +$LicenseInfo:firstyear=2006&license=viewerlgpl$ +Second Life Viewer Source Code +Copyright (C) 2010, Linden Research, Inc. -Copyright (c) 2006-2007, Linden Research, Inc. +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; +version 2.1 of the License only. -Second Life Viewer Source Code -The source code in this file ("Source Code") is provided by Linden Lab -to you under the terms of the GNU General Public License, version 2.0 -("GPL"), unless you have obtained a separate licensing agreement -("Other License"), formally executed by you and Linden Lab. Terms of -the GPL can be found in doc/GPL-license.txt in this distribution, or -online at http://secondlife.com/developers/opensource/gplv2 - -There are special exceptions to the terms and conditions of the GPL as -it is applied to this Source Code. View the full text of the exception -in the file doc/FLOSS-exception.txt in this software distribution, or -online at http://secondlife.com/developers/opensource/flossexception - -By copying, modifying or distributing this software, you acknowledge -that you have read and understood your obligations described above, -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. +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA $/LicenseInfo$ """ @@ -56,7 +51,8 @@ class Demo_ArchManifest(llmanifest.LLManifest): class TestLLManifest(unittest.TestCase): mode='static' def setUp(self): - self.m = llmanifest.LLManifest("src", "dst", {'grid':'default', 'platform':'darwin', 'version':(1,2,3,4)}) + self.m = llmanifest.LLManifest({'source':'src', 'dest':'dst', 'grid':'default', 'platform':'darwin', 'version':(1,2,3,4), + 'artwork':'art', 'build':'build'}) def testproperwindowspath(self): self.assertEqual(llmanifest.proper_windows_path("C:\Program Files", "cygwin"),"/cygdrive/c/Program Files") |