diff options
Diffstat (limited to 'indra/llprimitive/tests')
-rw-r--r-- | indra/llprimitive/tests/llgltfmaterial_test.cpp | 92 | ||||
-rw-r--r-- | indra/llprimitive/tests/llprimitive_test.cpp | 16 |
2 files changed, 90 insertions, 18 deletions
diff --git a/indra/llprimitive/tests/llgltfmaterial_test.cpp b/indra/llprimitive/tests/llgltfmaterial_test.cpp index b56c9ab4f5..4f2de82386 100644 --- a/indra/llprimitive/tests/llgltfmaterial_test.cpp +++ b/indra/llprimitive/tests/llgltfmaterial_test.cpp @@ -1,31 +1,33 @@ -/** +/** * @file llgltfmaterial_test.cpp * - * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, 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$ + * $/LicenseInfo$ */ #include "linden_common.h" #include "lltut.h" +#include <set> + #include "../llgltfmaterial.h" #include "lluuid.cpp" @@ -108,9 +110,9 @@ namespace tut material.setAlphaCutoff(test_fraction); // Because this is the default value, it should append to the extras field to mark it as an override - material.setAlphaMode(LLGLTFMaterial::ALPHA_MODE_OPAQUE); + material.setAlphaMode(LLGLTFMaterial::ALPHA_MODE_OPAQUE, true); // Because this is the default value, it should append to the extras field to mark it as an override - material.setDoubleSided(false); + material.setDoubleSided(false, true); return material; } @@ -143,7 +145,7 @@ namespace tut #if LL_WINDOWS // If any fields are added/changed, these tests should be updated (consider also updating ASSET_VERSION in LLGLTFMaterial) // This test result will vary between compilers, so only test a single platform - ensure_equals("fields supported for GLTF (sizeof check)", sizeof(LLGLTFMaterial), 224); + ensure_equals("fields supported for GLTF (sizeof check)", sizeof(LLGLTFMaterial), 232); #endif #endif ensure_equals("LLGLTFMaterial texture info count", (U32)LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT, 4); @@ -366,4 +368,74 @@ namespace tut ensure_equals("LLGLTFMaterial: double sided override flag unset", material.mOverrideDoubleSided, false); } } + + template<typename T> + void ensure_material_hash_pre(LLGLTFMaterial& material, T& material_field, const T new_value, const std::string& field_name) + { + ensure("LLGLTFMaterial: Hash: Test field " + field_name + " is part of the test material object", ( + size_t(&material_field) >= size_t(&material) && + (size_t(&material_field) + sizeof(material_field)) <= (size_t(&material) + sizeof(material)) + )); + ensure("LLGLTFMaterial: Hash: " + field_name + " differs and will cause a perturbation worth hashing", material_field != new_value); + } + + template<typename T> + void ensure_material_hash_not_changed(LLGLTFMaterial& material, T& material_field, const T new_value, const std::string& field_name) + { + ensure_material_hash_pre(material, material_field, new_value, field_name); + + const LLGLTFMaterial old_material = material; + material_field = new_value; + // If this test fails, consult LLGLTFMaterial::getHash, and optionally consult http://www.catb.org/esr/structure-packing/ for guidance on optimal memory packing (effectiveness is platform-dependent) + ensure_equals(("LLGLTFMaterial: Hash: Perturbing " + field_name + " to new value does NOT change the hash").c_str(), material.getHash(), old_material.getHash()); + } + + template<typename T> + void ensure_material_hash_changed(LLGLTFMaterial& material, T& material_field, const T new_value, const std::string& field_name) + { + ensure_material_hash_pre(material, material_field, new_value, field_name); + + const LLGLTFMaterial old_material = material; + material_field = new_value; + // If this test fails, consult LLGLTFMaterial::getHash, and optionally consult http://www.catb.org/esr/structure-packing/ for guidance on optimal memory packing (effectiveness is platform-dependent) + ensure_not_equals(("LLGLTFMaterial: Hash: Perturbing " + field_name + " to new value changes the hash").c_str(), material.getHash(), old_material.getHash()); + } + +#define ENSURE_HASH_NOT_CHANGED(HASH_MAT, SOURCE_MAT, FIELD) ensure_material_hash_not_changed(HASH_MAT, HASH_MAT.FIELD, SOURCE_MAT.FIELD, #FIELD) +#define ENSURE_HASH_CHANGED(HASH_MAT, SOURCE_MAT, FIELD) ensure_material_hash_changed(HASH_MAT, HASH_MAT.FIELD, SOURCE_MAT.FIELD, #FIELD) + + // Test LLGLTFMaterial::getHash, which is very sensitive to the ordering of fields + template<> template<> + void llgltfmaterial_object_t::test<12>() + { + // *NOTE: Due to direct manipulation of the fields of materials + // throughout this test, the resulting modified materials may not be + // compliant or properly serializable. + + // Ensure all fields of source_mat are set to values that differ from + // LLGLTFMaterial::sDefault, even if that would result in an invalid + // material object. + LLGLTFMaterial source_mat = create_test_material(); + source_mat.mTrackingIdToLocalTexture[LLUUID::generateNewID()] = LLUUID::generateNewID(); + source_mat.mLocalTexDataDigest = 1; + source_mat.mAlphaMode = LLGLTFMaterial::ALPHA_MODE_MASK; + source_mat.mDoubleSided = true; + + LLGLTFMaterial hash_mat; + + ENSURE_HASH_NOT_CHANGED(hash_mat, source_mat, mTrackingIdToLocalTexture); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mLocalTexDataDigest); + + ENSURE_HASH_CHANGED(hash_mat, source_mat, mTextureId); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mTextureTransform); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mBaseColor); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mEmissiveColor); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mMetallicFactor); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mRoughnessFactor); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mAlphaCutoff); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mAlphaMode); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mDoubleSided); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mOverrideDoubleSided); + ENSURE_HASH_CHANGED(hash_mat, source_mat, mOverrideAlphaMode); + } } diff --git a/indra/llprimitive/tests/llprimitive_test.cpp b/indra/llprimitive/tests/llprimitive_test.cpp index 1b47182c28..0213a3e8b6 100644 --- a/indra/llprimitive/tests/llprimitive_test.cpp +++ b/indra/llprimitive/tests/llprimitive_test.cpp @@ -46,7 +46,7 @@ public: if (mVolumeTest.isNull() || volume_params != mCurrParamsTest || detail != mCurrDetailTest) { F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail); - mVolumeTest = new LLVolume(volume_params, volume_detail, FALSE, FALSE); + mVolumeTest = new LLVolume(volume_params, volume_detail, false, false); mCurrParamsTest = volume_params; mCurrDetailTest = detail; return mVolumeTest; @@ -109,7 +109,7 @@ void LLPrimTextureList::take(LLPrimTextureList &other_list) { } void LLPrimTextureList::setSize(S32 new_size) { mEntryList.resize(new_size); } void LLPrimTextureList::setAllIDs(const LLUUID &id) { } LLTextureEntry * LLPrimTextureList::getTexture(const U8 index) const { return nullptr; } -S32 LLPrimTextureList::size() const { return mEntryList.size(); } +S32 LLPrimTextureList::size() const { return static_cast<S32>(mEntryList.size()); } class PRIMITIVE_TEST_SETUP { @@ -193,7 +193,7 @@ namespace tut ensure(!primitive.isChanged(LLXform::GEOMETRY)); // Make sure setVolume returns true - ensure(primitive.setVolume(params, 0, true) == TRUE); + ensure(primitive.setVolume(params, 0, true) == true); LLVolume* new_volume = primitive.getVolume(); // make sure new volume was actually created @@ -210,12 +210,12 @@ namespace tut ensure(primitive.isChanged(LLXform::GEOMETRY)); // Run it twice to make sure it doesn't create a different one if params are the same - ensure(primitive.setVolume(params, 0, true) == FALSE); + ensure(primitive.setVolume(params, 0, true) == false); ensure(new_volume == primitive.getVolume()); // Change the param definition and try setting it again. params.setRevolutions(4); - ensure(primitive.setVolume(params, 0, true) == TRUE); + ensure(primitive.setVolume(params, 0, true) == true); // Ensure that we now have a different volume ensure(new_volume != primitive.getVolume()); @@ -238,7 +238,7 @@ namespace tut ensure(!primitive.isChanged(LLXform::GEOMETRY)); // Make sure setVolume returns true - ensure(primitive.setVolume(params, 0, false) == TRUE); + ensure(primitive.setVolume(params, 0, false) == true); LLVolume* new_volume = primitive.getVolume(); @@ -256,12 +256,12 @@ namespace tut ensure(primitive.isChanged(LLXform::GEOMETRY)); // Run it twice to make sure it doesn't create a different one if params are the same - ensure(primitive.setVolume(params, 0, false) == FALSE); + ensure(primitive.setVolume(params, 0, false) == false); ensure(new_volume == primitive.getVolume()); // Change the param definition and try setting it again. params.setRevolutions(4); - ensure(primitive.setVolume(params, 0, false) == TRUE); + ensure(primitive.setVolume(params, 0, false) == true); // Ensure that we now have a different volume ensure(new_volume != primitive.getVolume()); |