summaryrefslogtreecommitdiff
path: root/indra/llprimitive
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llprimitive')
-rw-r--r--indra/llprimitive/CMakeLists.txt1
-rw-r--r--indra/llprimitive/llmaterialtable.cpp3
-rw-r--r--indra/llprimitive/llmaterialtable.h83
-rw-r--r--indra/llprimitive/llmediaentry.cpp9
-rw-r--r--indra/llprimitive/llprimitive.cpp212
-rw-r--r--indra/llprimitive/llprimitive.h1
-rw-r--r--indra/llprimitive/llprimtexturelist.cpp19
-rw-r--r--indra/llprimitive/lltextureentry.cpp8
-rw-r--r--indra/llprimitive/lltextureentry.h4
-rw-r--r--indra/llprimitive/material_codes.cpp46
-rw-r--r--indra/llprimitive/material_codes.h19
-rw-r--r--indra/llprimitive/tests/llmediaentry_test.cpp231
12 files changed, 460 insertions, 176 deletions
diff --git a/indra/llprimitive/CMakeLists.txt b/indra/llprimitive/CMakeLists.txt
index f9392a2b75..af78ed7936 100644
--- a/indra/llprimitive/CMakeLists.txt
+++ b/indra/llprimitive/CMakeLists.txt
@@ -28,6 +28,7 @@ set(llprimitive_SOURCE_FILES
lltreeparams.cpp
llvolumemessage.cpp
llvolumexml.cpp
+ material_codes.cpp
)
set(llprimitive_HEADER_FILES
diff --git a/indra/llprimitive/llmaterialtable.cpp b/indra/llprimitive/llmaterialtable.cpp
index 18787c47c5..774a58c8ac 100644
--- a/indra/llprimitive/llmaterialtable.cpp
+++ b/indra/llprimitive/llmaterialtable.cpp
@@ -92,6 +92,9 @@ F32 const LLMaterialTable::DEFAULT_FRICTION = 0.5f;
F32 const LLMaterialTable::DEFAULT_RESTITUTION = 0.4f;
LLMaterialTable::LLMaterialTable()
+ : mCollisionSoundMatrix(NULL),
+ mSlidingSoundMatrix(NULL),
+ mRollingSoundMatrix(NULL)
{
}
diff --git a/indra/llprimitive/llmaterialtable.h b/indra/llprimitive/llmaterialtable.h
index 2c0b046fa7..77f29a8e06 100644
--- a/indra/llprimitive/llmaterialtable.h
+++ b/indra/llprimitive/llmaterialtable.h
@@ -38,6 +38,8 @@
#include <list>
+class LLMaterialInfo;
+
const U32 LLMATERIAL_INFO_NAME_LENGTH = 256;
// We've moved toward more reasonable mass values for the Havok4 engine.
@@ -64,45 +66,6 @@ const F32 LEGACY_DEFAULT_OBJECT_DENSITY = 10.0f;
const F32 DEFAULT_AVATAR_DENSITY = 445.3f; // was 444.24f;
-class LLMaterialInfo
-{
-public:
- U8 mMCode;
- std::string mName;
- LLUUID mDefaultTextureID;
- LLUUID mShatterSoundID;
- F32 mDensity; // kg/m^3
- F32 mFriction;
- F32 mRestitution;
-
- // damage and energy constants
- F32 mHPModifier; // modifier on mass based HP total
- F32 mDamageModifier; // modifier on KE based damage
- F32 mEPModifier; // modifier on mass based EP total
-
- LLMaterialInfo(U8 mcode, const std::string& name, const LLUUID &uuid)
- {
- init(mcode,name,uuid);
- };
-
- void init(U8 mcode, const std::string& name, const LLUUID &uuid)
- {
- mDensity = 1000.f; // default to 1000.0 (water)
- mHPModifier = 1.f;
- mDamageModifier = 1.f;
- mEPModifier = 1.f;
-
- mMCode = mcode;
- mName = name;
- mDefaultTextureID = uuid;
- };
-
- ~LLMaterialInfo()
- {
- };
-
-};
-
class LLMaterialTable
{
public:
@@ -185,5 +148,47 @@ public:
static LLMaterialTable basic;
};
+
+class LLMaterialInfo
+{
+public:
+ U8 mMCode;
+ std::string mName;
+ LLUUID mDefaultTextureID;
+ LLUUID mShatterSoundID;
+ F32 mDensity; // kg/m^3
+ F32 mFriction;
+ F32 mRestitution;
+
+ // damage and energy constants
+ F32 mHPModifier; // modifier on mass based HP total
+ F32 mDamageModifier; // modifier on KE based damage
+ F32 mEPModifier; // modifier on mass based EP total
+
+ LLMaterialInfo(U8 mcode, const std::string& name, const LLUUID &uuid)
+ {
+ init(mcode,name,uuid);
+ };
+
+ void init(U8 mcode, const std::string& name, const LLUUID &uuid)
+ {
+ mDensity = 1000.f; // default to 1000.0 (water)
+ mFriction = LLMaterialTable::DEFAULT_FRICTION;
+ mRestitution = LLMaterialTable::DEFAULT_RESTITUTION;
+ mHPModifier = 1.f;
+ mDamageModifier = 1.f;
+ mEPModifier = 1.f;
+
+ mMCode = mcode;
+ mName = name;
+ mDefaultTextureID = uuid;
+ };
+
+ ~LLMaterialInfo()
+ {
+ };
+
+};
+
#endif
diff --git a/indra/llprimitive/llmediaentry.cpp b/indra/llprimitive/llmediaentry.cpp
index fa04bf80e7..2fc1e5e60c 100644
--- a/indra/llprimitive/llmediaentry.cpp
+++ b/indra/llprimitive/llmediaentry.cpp
@@ -164,6 +164,7 @@ void LLMediaEntry::asLLSD(LLSD& sd) const
// "security" fields
sd[WHITELIST_ENABLE_KEY] = mWhiteListEnable;
+ sd.erase(WHITELIST_KEY);
for (U32 i=0; i<mWhiteList.size(); i++)
{
sd[WHITELIST_KEY].append(mWhiteList[i]);
@@ -388,8 +389,12 @@ U32 LLMediaEntry::setWhiteList( const std::vector<std::string> &whitelist )
U32 LLMediaEntry::setWhiteList( const LLSD &whitelist )
{
- // If whitelist is undef, this is a no-op.
- if (whitelist.isUndefined()) return LSL_STATUS_OK;
+ // If whitelist is undef, the whitelist is cleared
+ if (whitelist.isUndefined())
+ {
+ mWhiteList.clear();
+ return LSL_STATUS_OK;
+ }
// However, if the whitelist is an empty array, erase it.
if (whitelist.isArray())
diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index 2675a27c08..732f5a698b 100644
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -43,7 +43,7 @@
#include "llvolumemgr.h"
#include "llstring.h"
#include "lldatapacker.h"
-#include "llsdutil.h"
+#include "llsdutil_math.h"
#include "llprimtexturelist.h"
/**
@@ -154,6 +154,7 @@ bool LLPrimitive::cleanupVolumeManager()
//===============================================================
LLPrimitive::LLPrimitive()
: mTextureList(),
+ mNumTEs(0),
mMiscFlags(0)
{
mPrimitiveCode = 0;
@@ -743,12 +744,215 @@ BOOL LLPrimitive::setVolume(const LLVolumeParams &volume_params, const S32 detai
setNumTEs(mVolumep->getNumFaces());
return TRUE;
}
+
+#if 0
+ // #if 0'd out by davep
+ // this is a lot of cruft to set texture entry values that just stay the same for LOD switch
+ // or immediately get overridden by an object update message, also crashes occasionally
+ U32 old_face_mask = mVolumep->mFaceMask;
+
+ S32 face_bit = 0;
+ S32 cur_mask = 0;
+
+ // Grab copies of the old faces from the original shape, ordered by type.
+ // We will use these to figure out what old texture info gets mapped to new
+ // faces in the new shape.
+ std::vector<LLProfile::Face> old_faces;
+ for (S32 face = 0; face < mVolumep->getNumFaces(); face++)
+ {
+ old_faces.push_back(mVolumep->getProfile().mFaces[face]);
+ }
+
+ // Copy the old texture info off to the side, but not in the order in which
+ // they live in the mTextureList, rather in order of ther "face id" which
+ // is the corresponding value of LLVolueParams::LLProfile::mFaces::mIndex.
+ //
+ // Hence, some elements of old_tes::mEntryList will be invalid. It is
+ // initialized to a size of 9 (max number of possible faces on a volume?)
+ // and only the ones with valid types are filled in.
+ LLPrimTextureList old_tes;
+ old_tes.setSize(9);
+ for (face_bit = 0; face_bit < 9; face_bit++)
+ {
+ cur_mask = 0x1 << face_bit;
+ if (old_face_mask & cur_mask)
+ {
+ S32 te_index = face_index_from_id(cur_mask, old_faces);
+ old_tes.copyTexture(face_bit, *(getTE(te_index)));
+ //llinfos << face_bit << ":" << te_index << ":" << old_tes[face_bit].getID() << llendl;
+ }
+ }
+
// build the new object
sVolumeManager->unrefVolume(mVolumep);
mVolumep = volumep;
+
+ U32 new_face_mask = mVolumep->mFaceMask;
+ S32 i;
+
+ if (old_face_mask == new_face_mask)
+ {
+ // nothing to do
+ return TRUE;
+ }
+
+ if (mVolumep->getNumFaces() == 0 && new_face_mask != 0)
+ {
+ llwarns << "Object with 0 faces found...INCORRECT!" << llendl;
+ setNumTEs(mVolumep->getNumFaces());
+ return TRUE;
+ }
+
+ // initialize face_mapping
+ S32 face_mapping[9];
+ for (face_bit = 0; face_bit < 9; face_bit++)
+ {
+ face_mapping[face_bit] = face_bit;
+ }
+
+ // The new shape may have more faces than the original, but we can't just
+ // add them to the end -- the ordering matters and it may be that we must
+ // insert the new faces in the middle of the list. When we add a face it
+ // will pick up the texture/color info of one of the old faces an so we
+ // now figure out which old face info gets mapped to each new face, and
+ // store in the face_mapping lookup table.
+ for (face_bit = 0; face_bit < 9; face_bit++)
+ {
+ cur_mask = 0x1 << face_bit;
+ if (!(new_face_mask & cur_mask))
+ {
+ // Face doesn't exist in new map.
+ face_mapping[face_bit] = -1;
+ continue;
+ }
+ else if (old_face_mask & cur_mask)
+ {
+ // Face exists in new and old map.
+ face_mapping[face_bit] = face_bit;
+ continue;
+ }
+
+ // OK, how we've got a mismatch, where we have to fill a new face with one from
+ // the old face.
+ if (cur_mask & (LL_FACE_PATH_BEGIN | LL_FACE_PATH_END | LL_FACE_INNER_SIDE))
+ {
+ // It's a top/bottom/hollow interior face.
+ if (old_face_mask & LL_FACE_PATH_END)
+ {
+ face_mapping[face_bit] = 1;
+ continue;
+ }
+ else
+ {
+ S32 cur_outer_mask = LL_FACE_OUTER_SIDE_0;
+ for (i = 0; i < 4; i++)
+ {
+ if (old_face_mask & cur_outer_mask)
+ {
+ face_mapping[face_bit] = 5 + i;
+ break;
+ }
+ cur_outer_mask <<= 1;
+ }
+ if (i == 4)
+ {
+ llwarns << "No path end or outer face in volume!" << llendl;
+ }
+ continue;
+ }
+ }
+
+ if (cur_mask & (LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END))
+ {
+ // A cut slice. Use the hollow interior if we have it.
+ if (old_face_mask & LL_FACE_INNER_SIDE)
+ {
+ face_mapping[face_bit] = 2;
+ continue;
+ }
+
+ // No interior, use the bottom face.
+ // Could figure out which of the outer faces was nearest, but that would be harder.
+ if (old_face_mask & LL_FACE_PATH_END)
+ {
+ face_mapping[face_bit] = 1;
+ continue;
+ }
+ else
+ {
+ S32 cur_outer_mask = LL_FACE_OUTER_SIDE_0;
+ for (i = 0; i < 4; i++)
+ {
+ if (old_face_mask & cur_outer_mask)
+ {
+ face_mapping[face_bit] = 5 + i;
+ break;
+ }
+ cur_outer_mask <<= 1;
+ }
+ if (i == 4)
+ {
+ llwarns << "No path end or outer face in volume!" << llendl;
+ }
+ continue;
+ }
+ }
+
+ // OK, the face that's missing is an outer face...
+ // Pull from the nearest adjacent outer face (there's always guaranteed to be one...
+ S32 cur_outer = face_bit - 5;
+ S32 min_dist = 5;
+ S32 min_outer_bit = -1;
+ S32 i;
+ for (i = 0; i < 4; i++)
+ {
+ if (old_face_mask & (LL_FACE_OUTER_SIDE_0 << i))
+ {
+ S32 dist = abs(i - cur_outer);
+ if (dist < min_dist)
+ {
+ min_dist = dist;
+ min_outer_bit = i + 5;
+ }
+ }
+ }
+ if (-1 == min_outer_bit)
+ {
+ llinfos << (LLVolume *)mVolumep << llendl;
+ llwarns << "Bad! No outer faces, impossible!" << llendl;
+ }
+ face_mapping[face_bit] = min_outer_bit;
+ }
+
+
setNumTEs(mVolumep->getNumFaces());
-
+ for (face_bit = 0; face_bit < 9; face_bit++)
+ {
+ // For each possible face type on the new shape we check to see if that
+ // face exists and if it does we create a texture entry that is a copy
+ // of one of the originals. Since the originals might not have a
+ // matching face, we use the face_mapping lookup table to figure out
+ // which face information to copy.
+ cur_mask = 0x1 << face_bit;
+ if (new_face_mask & cur_mask)
+ {
+ if (-1 == face_mapping[face_bit])
+ {
+ llwarns << "No mapping from old face to new face!" << llendl;
+ }
+
+ S32 te_num = face_index_from_id(cur_mask, mVolumep->getProfile().mFaces);
+ setTE(te_num, *(old_tes.getTexture(face_mapping[face_bit])));
+ }
+ }
+#else
+ // build the new object
+ sVolumeManager->unrefVolume(mVolumep);
+ mVolumep = volumep;
+
+ setNumTEs(mVolumep->getNumFaces());
+#endif
return TRUE;
}
@@ -1708,10 +1912,10 @@ LLSD LLLightImageParams::asLLSD() const
bool LLLightImageParams::fromLLSD(LLSD& sd)
{
- if (sd.has("texture") && sd.has("params") && sd["params"].size() == 3)
+ if (sd.has("texture"))
{
setLightTexture( sd["texture"] );
- setParams( LLVector3(sd["params"][0].asReal(), sd["params"][1].asReal(), sd["params"][2].asReal()) );
+ setParams( LLVector3( sd["params"] ) );
return true;
}
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index 4db7aa7261..a44b9a6c1f 100644
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -286,6 +286,7 @@ public:
void setLightTexture(const LLUUID& id) { mLightTexture = id; }
LLUUID getLightTexture() const { return mLightTexture; }
+ bool isLightSpotlight() const { return mLightTexture.notNull(); }
void setParams(const LLVector3& params) { mParams = params; }
LLVector3 getParams() const { return mParams; }
diff --git a/indra/llprimitive/llprimtexturelist.cpp b/indra/llprimitive/llprimtexturelist.cpp
index d03150fc78..1c7de95975 100644
--- a/indra/llprimitive/llprimtexturelist.cpp
+++ b/indra/llprimitive/llprimtexturelist.cpp
@@ -135,13 +135,12 @@ S32 LLPrimTextureList::copyTexture(const U8 index, const LLTextureEntry& te)
{
if (S32(index) >= mEntryList.size())
{
- // TODO -- assert here
S32 current_size = mEntryList.size();
- llerrs << "index = " << S32(index) << " current_size = " << current_size << llendl;
+ llwarns << "ignore copy of index = " << S32(index) << " into texture entry list of size = " << current_size << llendl;
return TEM_CHANGE_NONE;
}
- // we're changing an existing entry
+ // we're changing an existing entry
llassert(mEntryList[index]);
delete (mEntryList[index]);
if (&te)
@@ -387,8 +386,18 @@ void LLPrimTextureList::setSize(S32 new_size)
mEntryList.resize(new_size);
for (S32 index = current_size; index < new_size; ++index)
{
- LLTextureEntry* new_entry = LLPrimTextureList::newTextureEntry();
- mEntryList[index] = new_entry;
+ if (current_size > 0
+ && mEntryList[current_size - 1])
+ {
+ // copy the last valid entry for the new one
+ mEntryList[index] = mEntryList[current_size - 1]->newCopy();
+ }
+ else
+ {
+ // no valid enries to copy, so we new one up
+ LLTextureEntry* new_entry = LLPrimTextureList::newTextureEntry();
+ mEntryList[index] = new_entry;
+ }
}
}
else if (new_size < current_size)
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index b534939dfc..f75f1d9b8c 100644
--- a/indra/llprimitive/lltextureentry.cpp
+++ b/indra/llprimitive/lltextureentry.cpp
@@ -35,7 +35,7 @@
#include "lluuid.h"
#include "llmediaentry.h"
#include "lltextureentry.h"
-#include "llsdutil.h"
+#include "llsdutil_math.h"
#include "v4color.h"
const U8 DEFAULT_BUMP_CODE = 0; // no bump or shininess
@@ -646,3 +646,9 @@ LLUUID LLTextureEntry::getAgentIDFromMediaVersionString(const std::string &versi
}
return id;
}
+
+//static
+bool LLTextureEntry::isMediaVersionString(const std::string &version_string)
+{
+ return std::string::npos != version_string.find(MEDIA_VERSION_STRING_PREFIX);
+}
diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h
index 8d2834f78c..d6366b9bb2 100644
--- a/indra/llprimitive/lltextureentry.h
+++ b/indra/llprimitive/lltextureentry.h
@@ -171,7 +171,9 @@ public:
static U32 getVersionFromMediaVersionString(const std::string &version_string);
// Given a media version string, return the UUID of the agent
static LLUUID getAgentIDFromMediaVersionString(const std::string &version_string);
-
+ // Return whether or not the given string is actually a media version
+ static bool isMediaVersionString(const std::string &version_string);
+
// Media flags
enum { MF_NONE = 0x0, MF_HAS_MEDIA = 0x1 };
diff --git a/indra/llprimitive/material_codes.cpp b/indra/llprimitive/material_codes.cpp
new file mode 100644
index 0000000000..ce146dad8a
--- /dev/null
+++ b/indra/llprimitive/material_codes.cpp
@@ -0,0 +1,46 @@
+/**
+ * @file material_codes.cpp
+ * @brief Material_codes definitions
+ *
+ * $LicenseInfo:firstyear=2000&license=viewergpl$
+ *
+ * Copyright (c) 2000-2009, Linden Research, Inc.
+ *
+ * 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://secondlifegrid.net/programs/open_source/licensing/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://secondlifegrid.net/programs/open_source/licensing/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.
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+
+#include "material_codes.h"
+
+#include "lluuid.h"
+
+const LLUUID LL_DEFAULT_STONE_UUID("87c5765b-aa26-43eb-b8c6-c09a1ca6208e");
+const LLUUID LL_DEFAULT_METAL_UUID("6f3c53e9-ba60-4010-8f3e-30f51a762476");
+const LLUUID LL_DEFAULT_GLASS_UUID("b4ba225c-373f-446d-9f7e-6cb7b5cf9b3d");
+const LLUUID LL_DEFAULT_WOOD_UUID("89556747-24cb-43ed-920b-47caed15465f");
+const LLUUID LL_DEFAULT_FLESH_UUID("80736669-e4b9-450e-8890-d5169f988a50");
+const LLUUID LL_DEFAULT_PLASTIC_UUID("304fcb4e-7d33-4339-ba80-76d3d22dc11a");
+const LLUUID LL_DEFAULT_RUBBER_UUID("9fae0bc5-666d-477e-9f70-84e8556ec867");
+const LLUUID LL_DEFAULT_LIGHT_UUID("00000000-0000-0000-0000-000000000000");
diff --git a/indra/llprimitive/material_codes.h b/indra/llprimitive/material_codes.h
index e5a59a2789..ba3faba39f 100644
--- a/indra/llprimitive/material_codes.h
+++ b/indra/llprimitive/material_codes.h
@@ -33,7 +33,7 @@
#ifndef LL_MATERIAL_CODES_H
#define LL_MATERIAL_CODES_H
-#include "lluuid.h"
+class LLUUID;
// material types
const U8 LL_MCODE_STONE = 0;
@@ -47,13 +47,14 @@ const U8 LL_MCODE_LIGHT = 7;
const U8 LL_MCODE_END = 8;
const U8 LL_MCODE_MASK = 0x0F;
-const LLUUID LL_DEFAULT_STONE_UUID("87c5765b-aa26-43eb-b8c6-c09a1ca6208e");
-const LLUUID LL_DEFAULT_METAL_UUID("6f3c53e9-ba60-4010-8f3e-30f51a762476");
-const LLUUID LL_DEFAULT_GLASS_UUID("b4ba225c-373f-446d-9f7e-6cb7b5cf9b3d");
-const LLUUID LL_DEFAULT_WOOD_UUID("89556747-24cb-43ed-920b-47caed15465f");
-const LLUUID LL_DEFAULT_FLESH_UUID("80736669-e4b9-450e-8890-d5169f988a50");
-const LLUUID LL_DEFAULT_PLASTIC_UUID("304fcb4e-7d33-4339-ba80-76d3d22dc11a");
-const LLUUID LL_DEFAULT_RUBBER_UUID("9fae0bc5-666d-477e-9f70-84e8556ec867");
-const LLUUID LL_DEFAULT_LIGHT_UUID("00000000-0000-0000-0000-000000000000");
+// *NOTE: Define these in .cpp file to reduce duplicate instances
+extern const LLUUID LL_DEFAULT_STONE_UUID;
+extern const LLUUID LL_DEFAULT_METAL_UUID;
+extern const LLUUID LL_DEFAULT_GLASS_UUID;
+extern const LLUUID LL_DEFAULT_WOOD_UUID;
+extern const LLUUID LL_DEFAULT_FLESH_UUID;
+extern const LLUUID LL_DEFAULT_PLASTIC_UUID;
+extern const LLUUID LL_DEFAULT_RUBBER_UUID;
+extern const LLUUID LL_DEFAULT_LIGHT_UUID;
#endif
diff --git a/indra/llprimitive/tests/llmediaentry_test.cpp b/indra/llprimitive/tests/llmediaentry_test.cpp
index 72478d0459..88cd96ebe4 100644
--- a/indra/llprimitive/tests/llmediaentry_test.cpp
+++ b/indra/llprimitive/tests/llmediaentry_test.cpp
@@ -9,7 +9,14 @@
#include "linden_common.h"
#include "lltut.h"
-#include "boost/lexical_cast.hpp"
+#if LL_WINDOWS
+#pragma warning (push)
+#pragma warning (disable : 4702) // boost::lexical_cast generates this warning
+#endif
+#include <boost/lexical_cast.hpp>
+#if LL_WINDOWS
+#pragma warning (pop)
+#endif
#include "llstring.h"
#include "llsdutil.h"
#include "llsdserialize.h"
@@ -150,14 +157,9 @@ namespace
namespace tut
{
- bool llsd_equals(const LLSD& a, const LLSD& b) {
- // cheesy, brute force, but it works
- return std::string(ll_pretty_print_sd(a)) == std::string(ll_pretty_print_sd(b));
- }
-
void ensure_llsd_equals(const std::string& msg, const LLSD& expected, const LLSD& actual)
{
- if (! llsd_equals(expected, actual))
+ if (!llsd_equals(expected, actual))
{
std::string message = msg;
message += ": actual: ";
@@ -190,9 +192,9 @@ namespace tut
entry.setWhiteList(tokens);
}
- void whitelist_test(bool enable, const char *whitelist, const char *candidate_url, bool expected_pass)
+ void whitelist_test(int num, bool enable, const char *whitelist, const char *candidate_url, bool expected_pass)
{
- std::string message = "Whitelist test";
+ std::string message = "Whitelist test " + boost::lexical_cast<std::string>(num);
LLMediaEntry entry;
entry.setWhiteListEnable(enable);
set_whitelist(entry, whitelist);
@@ -209,13 +211,13 @@ namespace tut
ensure(message, expected_pass == passed_whitelist);
}
- void whitelist_test(const char *whitelist, const char *candidate_url, bool expected_pass)
+ void whitelist_test(int num, const char *whitelist, const char *candidate_url, bool expected_pass)
{
- whitelist_test(true, whitelist, candidate_url, expected_pass);
+ whitelist_test(num, true, whitelist, candidate_url, expected_pass);
}
- void whitelist_test(const char *whitelist, const char *candidate_url)
+ void whitelist_test(int num, const char *whitelist, const char *candidate_url)
{
- whitelist_test(true, whitelist, candidate_url, true);
+ whitelist_test(num, true, whitelist, candidate_url, true);
}
template<> template<>
@@ -223,8 +225,7 @@ namespace tut
{
set_test_name("Test LLMediaEntry Instantiation");
LLMediaEntry entry;
- ensure_llsd_equals(get_test_name(), defaultMediaEntryLLSD, entry.asLLSD());
-
+ ensure_llsd_equals(get_test_name() + " failed", defaultMediaEntryLLSD, entry.asLLSD());
}
template<> template<>
@@ -251,12 +252,45 @@ namespace tut
ensure_llsd_equals(get_test_name() + " failed", golden, entry.asLLSD());
}
+ template<> template<>
+ void object::test<4>()
+ {
+ set_test_name("Test LLMediaEntry::asLLSD()");
+ LLMediaEntry entry;
+ LLSD sd;
+ // Put some cruft in the LLSD
+ sd[LLMediaEntry::CURRENT_URL_KEY] = "http://www.example.com";
+ LLSD whitelist;
+ whitelist.append("*.example.com");
+ sd[LLMediaEntry::WHITELIST_KEY] = whitelist;
+ entry.asLLSD(sd);
+ ensure_llsd_equals(get_test_name() + " failed", defaultMediaEntryLLSD, sd);
+ }
+
+
+ template<> template<>
+ void object::test<5>()
+ {
+ set_test_name("Test LLMediaEntry::asLLSD() -> LLMediaEntry::fromLLSD()");
+ LLMediaEntry entry1, entry2;
+ // Add a whitelist to entry2
+ std::vector<std::string> whitelist;
+ whitelist.push_back("*.example.com");
+ entry2.setWhiteList(whitelist);
+ // Render entry1 (which has no whitelist) as an LLSD
+ LLSD sd;
+ entry1.asLLSD(sd);
+ // "read" that LLSD into entry 2
+ entry2.fromLLSD(sd);
+ ensure_llsd_equals(get_test_name() + " failed", defaultMediaEntryLLSD, entry2.asLLSD());
+ }
+
// limit tests
const char *URL_OK = "http://www.example.com";
const char *URL_TOO_BIG = "http://www.example.com.qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq";
template<> template<>
- void object::test<4>()
+ void object::test<6>()
{
set_test_name("Test Limits on setting current URL");
LLMediaEntry entry;
@@ -267,7 +301,7 @@ namespace tut
}
template<> template<>
- void object::test<5>()
+ void object::test<7>()
{
set_test_name("Test Limits on setting home URL");
LLMediaEntry entry;
@@ -278,7 +312,7 @@ namespace tut
}
template<> template<>
- void object::test<6>()
+ void object::test<8>()
{
set_test_name("Test Limits on setting whitelist");
@@ -292,7 +326,7 @@ namespace tut
}
template<> template<>
- void object::test<7>()
+ void object::test<9>()
{
set_test_name("Test Limits on setting whitelist too big");
@@ -307,7 +341,7 @@ namespace tut
}
template<> template<>
- void object::test<8>()
+ void object::test<10>()
{
set_test_name("Test Limits on setting whitelist too many");
@@ -323,7 +357,7 @@ namespace tut
}
template<> template<>
- void object::test<9>()
+ void object::test<11>()
{
set_test_name("Test to make sure both setWhiteList() functions behave the same");
@@ -341,7 +375,7 @@ namespace tut
}
template<> template<>
- void object::test<10>()
+ void object::test<12>()
{
set_test_name("Test to make sure both setWhiteList() functions behave the same");
@@ -362,7 +396,7 @@ namespace tut
}
template<> template<>
- void object::test<11>()
+ void object::test<13>()
{
set_test_name("Test to make sure both setWhiteList() functions behave the same");
@@ -382,103 +416,70 @@ namespace tut
empty == entry2.getWhiteList());
}
- // Whitelist check tests
-
- // Check the "empty whitelist" case
template<> template<>
- void object::test<12>() { whitelist_test("", "http://www.example.com", true); }
+ void object::test<14>()
+ {
+ // Whitelist check tests
+ int n=0;
+
+ // Check the "empty whitelist" case
+ whitelist_test(++n, "", "http://www.example.com", true);
- // Check the "missing scheme" case
- template<> template<>
- void object::test<13>() { whitelist_test("www.example.com", "http://www.example.com", true); }
+ // Check the "missing scheme" case
+ whitelist_test(++n, "www.example.com", "http://www.example.com", true);
- // Check the "exactly the same" case
- template<> template<>
- void object::test<14>() { whitelist_test("http://example.com", "http://example.com", true); }
+ // Check the "exactly the same" case
+ whitelist_test(++n, "http://example.com", "http://example.com", true);
- // Check the enable flag
- template<> template<>
- void object::test<15>() { whitelist_test(false, "www.example.com", "http://www.secondlife.com", true); }
- template<> template<>
- void object::test<16>() { whitelist_test(true, "www.example.com", "http://www.secondlife.com", false); }
+ // Check the enable flag
+ whitelist_test(++n, false, "www.example.com", "http://www.secondlife.com", true);
+ whitelist_test(++n, true, "www.example.com", "http://www.secondlife.com", false);
- // Check permutations of trailing slash:
- template<> template<>
- void object::test<17>() { whitelist_test("http://www.example.com", "http://www.example.com/", true); }
- template<> template<>
- void object::test<18>() { whitelist_test("http://www.example.com/", "http://www.example.com/", true); }
- template<> template<>
- void object::test<19>() { whitelist_test("http://www.example.com/", "http://www.example.com", false); }
- template<> template<>
- void object::test<20>() { whitelist_test("http://www.example.com", "http://www.example.com/foobar", true); }
- template<> template<>
- void object::test<21>() { whitelist_test("http://www.example.com/", "http://www.example.com/foobar", false); }
+ // Check permutations of trailing slash:
+ whitelist_test(++n, "http://www.example.com", "http://www.example.com/", true);
+ whitelist_test(++n, "http://www.example.com/", "http://www.example.com/", true);
+ whitelist_test(++n, "http://www.example.com/", "http://www.example.com", false);
+ whitelist_test(++n, "http://www.example.com", "http://www.example.com/foobar", true);
+ whitelist_test(++n, "http://www.example.com/", "http://www.example.com/foobar", false);
- // More cases...
- template<> template<>
- void object::test<22>() { whitelist_test("http://example.com", "http://example.com/wiki", true); }
- template<> template<>
- void object::test<23>() { whitelist_test("www.example.com", "http://www.example.com/help", true); }
- template<> template<>
- void object::test<24>() { whitelist_test("http://www.example.com", "http://wwwexample.com", false); }
- template<> template<>
- void object::test<25>() { whitelist_test("http://www.example.com", "http://www.example.com/wiki", true); }
- template<> template<>
- void object::test<26>() { whitelist_test("example.com", "http://wwwexample.com", false); }
- template<> template<>
- void object::test<27>() { whitelist_test("http://www.example.com/", "http://www.amazon.com/wiki", false); }
- template<> template<>
- void object::test<28>() { whitelist_test("www.example.com", "http://www.amazon.com", false); }
-
- // regexp cases
- template<> template<>
- void object::test<29>() { whitelist_test("*.example.com", "http://www.example.com", true); }
- template<> template<>
- void object::test<30>() { whitelist_test("*.example.com", "http://www.amazon.com", false); }
- template<> template<>
- void object::test<31>() { whitelist_test("*.example.com", "http://www.example.com/foo/bar", true); }
- template<> template<>
- void object::test<32>() { whitelist_test("*.example.com", "http:/example.com/foo/bar", false); }
- template<> template<>
- void object::test<33>() { whitelist_test("*example.com", "http://example.com/foo/bar", true); }
- template<> template<>
- void object::test<34>() { whitelist_test("*example.com", "http://my.virus.com/foo/bar?example.com", false); }
- template<> template<>
- void object::test<35>() { whitelist_test("example.com", "http://my.virus.com/foo/bar?example.com", false); }
- template<> template<>
- void object::test<36>() { whitelist_test("*example.com", "http://my.virus.com/foo/bar?*example.com", false); }
- template<> template<>
- void object::test<37>() { whitelist_test("http://*example.com", "http://www.example.com", true); }
- template<> template<>
- void object::test<38>() { whitelist_test("http://*.example.com", "http://www.example.com", true); }
- template<> template<>
- void object::test<39>() { whitelist_test("http://*.e$?^.com", "http://www.e$?^.com", true); }
- template<> template<>
- void object::test<40>() { whitelist_test("*.example.com/foo/bar", "http://www.example.com/", false); }
- template<> template<>
- void object::test<41>() { whitelist_test("*.example.com/foo/bar", "http://example.com/foo/bar", false); }
- template<> template<>
- void object::test<42>() { whitelist_test("http://*.example.com/foo/bar", "http://www.example.com", false); }
- template<> template<>
- void object::test<43>() { whitelist_test("http://*.example.com", "https://www.example.com", false); }
- template<> template<>
- void object::test<44>() { whitelist_test("http*://*.example.com", "rtsp://www.example.com", false); }
- template<> template<>
- void object::test<45>() { whitelist_test("http*://*.example.com", "https://www.example.com", true); }
- template<> template<>
- void object::test<46>() { whitelist_test("example.com", "http://www.example.com", false); }
- template<> template<>
- void object::test<47>() { whitelist_test("www.example.com", "http://www.example.com:80", false); }
- template<> template<>
- void object::test<48>() { whitelist_test("www.example.com", "http://www.example.com", true); }
- template<> template<>
- void object::test<49>() { whitelist_test("www.example.com/", "http://www.example.com", false); }
- template<> template<>
- void object::test<50>() { whitelist_test("www.example.com/foo/bar/*", "http://www.example.com/foo/bar/baz", true); }
- // Path only
- template<> template<>
- void object::test<51>() { whitelist_test("/foo/*/baz", "http://www.example.com/foo/bar/baz", true); }
- template<> template<>
- void object::test<52>() { whitelist_test("/foo/*/baz", "http://www.example.com/foo/bar/", false); }
+ // More cases...
+ whitelist_test(++n, "http://example.com", "http://example.com/wiki", true);
+ whitelist_test(++n, "www.example.com", "http://www.example.com/help", true);
+ whitelist_test(++n, "http://www.example.com", "http://wwwexample.com", false);
+ whitelist_test(++n, "http://www.example.com", "http://www.example.com/wiki", true);
+ whitelist_test(++n, "example.com", "http://wwwexample.com", false);
+ whitelist_test(++n, "http://www.example.com/", "http://www.amazon.com/wiki", false);
+ whitelist_test(++n, "www.example.com", "http://www.amazon.com", false);
+
+ // regexp cases
+ whitelist_test(++n, "*.example.com", "http://www.example.com", true);
+ whitelist_test(++n, "*.example.com", "http://www.amazon.com", false);
+ whitelist_test(++n, "*.example.com", "http://www.example.com/foo/bar", true);
+ whitelist_test(++n, "*.example.com", "http:/example.com/foo/bar", false);
+ whitelist_test(++n, "*example.com", "http://example.com/foo/bar", true);
+ whitelist_test(++n, "*example.com", "http://my.virus.com/foo/bar?example.com", false);
+ whitelist_test(++n, "example.com", "http://my.virus.com/foo/bar?example.com", false);
+ whitelist_test(++n, "*example.com", "http://my.virus.com/foo/bar?*example.com", false);
+ whitelist_test(++n, "http://*example.com", "http://www.example.com", true);
+ whitelist_test(++n, "http://*.example.com", "http://www.example.com", true);
+ whitelist_test(++n, "http://*.e$?^.com", "http://www.e$?^.com", true);
+ whitelist_test(++n, "*.example.com/foo/bar", "http://www.example.com/", false);
+ whitelist_test(++n, "*.example.com/foo/bar", "http://example.com/foo/bar", false);
+ whitelist_test(++n, "http://*.example.com/foo/bar", "http://www.example.com", false);
+ whitelist_test(++n, "http://*.example.com", "https://www.example.com", false);
+ whitelist_test(++n, "http*://*.example.com", "rtsp://www.example.com", false);
+ whitelist_test(++n, "http*://*.example.com", "https://www.example.com", true);
+ whitelist_test(++n, "example.com", "http://www.example.com", false);
+ whitelist_test(++n, "www.example.com", "http://www.example.com:80", false);
+ whitelist_test(++n, "www.example.com", "http://www.example.com", true);
+ whitelist_test(++n, "www.example.com/", "http://www.example.com", false);
+ whitelist_test(++n, "www.example.com/foo/bar/*", "http://www.example.com/foo/bar/baz", true);
+
+ // Path only
+ whitelist_test(++n, "/foo/*/baz", "http://www.example.com/foo/bar/baz", true);
+ whitelist_test(++n, "/foo/*/baz", "http://www.example.com/foo/bar/", false);
+ }
+
}
+