Merge branch 'development' into TIF/Runtime
This commit is contained in:
@@ -2010,6 +2010,28 @@ TEST_F(SerializeBasicTest, BasicTypeTest_Succeed)
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This test will dynamic cast (azrtti_cast) between incompatible types, which should always result in nullptr.
|
||||
If this test fails, the RTTI declaration for the relevant type is incorrect.
|
||||
*/
|
||||
TEST_F(Serialization, AttributeRTTI)
|
||||
{
|
||||
{
|
||||
AttributeInvocable<AZStd::function<AZStd::string(AZStd::string)>> fn([](AZStd::string x) { return x + x; });
|
||||
Attribute* fnDownCast = &fn;
|
||||
auto fnUpCast = azrtti_cast<AttributeInvocable<AZStd::function<int(int)>>*>(fnDownCast);
|
||||
EXPECT_EQ(fnUpCast, nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
AttributeFunction<AZStd::string(AZStd::string)> fn([](AZStd::string x) { return x + x; });
|
||||
Attribute* fnDownCast = &fn;
|
||||
auto fnUpCast = azrtti_cast<AttributeFunction<int(int)>*>(fnDownCast);
|
||||
EXPECT_EQ(fnUpCast, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Deprecation
|
||||
*/
|
||||
|
||||
@@ -95,6 +95,20 @@ namespace JsonSerializationTests
|
||||
}
|
||||
};
|
||||
|
||||
class SerializerWithOneDuplicatedTypeWithOverride
|
||||
: public JsonSerializerTemplatedMock<SerializerWithOneDuplicatedTypeWithOverride>
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(SerializerWithOneDuplicatedTypeWithOverride, "{4218D591-E578-499B-B578-ACA70C9944AB}", BaseJsonSerializer);
|
||||
~SerializerWithOneDuplicatedTypeWithOverride() override = default;
|
||||
|
||||
static void Reflect(AZ::JsonRegistrationContext* context)
|
||||
{
|
||||
context->Serializer<SerializerWithOneDuplicatedTypeWithOverride>()
|
||||
->HandlesType<bool>(true);
|
||||
}
|
||||
};
|
||||
|
||||
// Attempts to register the same type twice
|
||||
class SerializerWithTwoSameTypes
|
||||
: public JsonSerializerTemplatedMock<SerializerWithTwoSameTypes>
|
||||
@@ -271,13 +285,29 @@ namespace JsonSerializationTests
|
||||
|
||||
EXPECT_EQ(1, m_jsonRegistrationContext->GetRegisteredSerializers().size());
|
||||
AZ::BaseJsonSerializer* mockSerializer = m_jsonRegistrationContext->GetSerializerForType(azrtti_typeid<bool>());
|
||||
EXPECT_NE(mockSerializer, nullptr);
|
||||
ASSERT_NE(mockSerializer, nullptr);
|
||||
EXPECT_EQ(AZ::AzTypeInfo<SerializerWithOneType>::Uuid(), mockSerializer->RTTI_GetType());
|
||||
|
||||
SerializerWithOneType::Unreflect(m_jsonRegistrationContext.get());
|
||||
SerializerWithOneDuplicatedType::Unreflect(m_jsonRegistrationContext.get());
|
||||
}
|
||||
|
||||
TEST_F(JsonRegistrationContextTests, OverwriteRegisterSameUuidWithMultipleSerializers_Succeeds)
|
||||
{
|
||||
EXPECT_NE(AZ::AzTypeInfo<SerializerWithOneDuplicatedTypeWithOverride>::Uuid(), AZ::AzTypeInfo<SerializerWithOneType>::Uuid());
|
||||
|
||||
SerializerWithOneType::Reflect(m_jsonRegistrationContext.get());
|
||||
SerializerWithOneDuplicatedTypeWithOverride::Reflect(m_jsonRegistrationContext.get());
|
||||
|
||||
EXPECT_EQ(1, m_jsonRegistrationContext->GetRegisteredSerializers().size());
|
||||
AZ::BaseJsonSerializer* mockSerializer = m_jsonRegistrationContext->GetSerializerForType(azrtti_typeid<bool>());
|
||||
ASSERT_NE(mockSerializer, nullptr);
|
||||
EXPECT_EQ(AZ::AzTypeInfo<SerializerWithOneDuplicatedTypeWithOverride>::Uuid(), mockSerializer->RTTI_GetType());
|
||||
|
||||
SerializerWithOneType::Unreflect(m_jsonRegistrationContext.get());
|
||||
SerializerWithOneDuplicatedTypeWithOverride::Unreflect(m_jsonRegistrationContext.get());
|
||||
}
|
||||
|
||||
TEST_F(JsonRegistrationContextTests, RegisterSameUuidWithSameSerializers_Fails)
|
||||
{
|
||||
AZ_TEST_START_ASSERTTEST;
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Serialization/Json/UnsupportedTypesSerializer.h>
|
||||
#include <AzCore/std/any.h>
|
||||
#include <AzCore/std/optional.h>
|
||||
#include <AzCore/std/containers/variant.h>
|
||||
#include <Tests/Serialization/Json/BaseJsonSerializerFixture.h>
|
||||
|
||||
namespace JsonSerializationTests
|
||||
{
|
||||
struct AnyInfo
|
||||
{
|
||||
using Type = AZStd::any;
|
||||
using Serializer = AZ::JsonAnySerializer;
|
||||
};
|
||||
|
||||
struct VariantInfo
|
||||
{
|
||||
using Type = AZStd::variant<AZStd::monostate, int, double>;
|
||||
using Serializer = AZ::JsonVariantSerializer;
|
||||
};
|
||||
|
||||
struct OptionalInfo
|
||||
{
|
||||
using Type = AZStd::optional<int>;
|
||||
using Serializer = AZ::JsonVariantSerializer;
|
||||
};
|
||||
|
||||
template<typename Info>
|
||||
class JsonUnsupportedTypesSerializerTests : public BaseJsonSerializerFixture
|
||||
{
|
||||
public:
|
||||
using Type = typename Info::Type;
|
||||
using Serializer = typename Info::Serializer;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
BaseJsonSerializerFixture::SetUp();
|
||||
this->m_serializer = AZStd::make_unique<Serializer>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
this->m_serializer.reset();
|
||||
BaseJsonSerializerFixture::TearDown();
|
||||
}
|
||||
|
||||
protected:
|
||||
AZStd::unique_ptr<Serializer> m_serializer;
|
||||
Type m_instance{};
|
||||
};
|
||||
|
||||
using UnsupportedTypesTestTypes = ::testing::Types<AnyInfo, VariantInfo, OptionalInfo>;
|
||||
TYPED_TEST_CASE(JsonUnsupportedTypesSerializerTests, UnsupportedTypesTestTypes);
|
||||
|
||||
TYPED_TEST(JsonUnsupportedTypesSerializerTests, Load_CallDirectly_ReportsIssueAndHalts)
|
||||
{
|
||||
namespace JSR = AZ::JsonSerializationResult;
|
||||
|
||||
bool hasMessage = false;
|
||||
auto callback = [&hasMessage](AZStd::string_view message, JSR::ResultCode result, AZStd::string_view) -> JSR::ResultCode
|
||||
{
|
||||
hasMessage = !message.empty();
|
||||
return result;
|
||||
};
|
||||
this->m_jsonDeserializationContext->PushReporter(AZStd::move(callback));
|
||||
|
||||
JSR::Result result = this->m_serializer->Load(
|
||||
&this->m_instance, azrtti_typeid(this->m_instance), *this->m_jsonDocument, *this->m_jsonDeserializationContext);
|
||||
this->m_jsonDeserializationContext->PopReporter();
|
||||
|
||||
EXPECT_EQ(JSR::Processing::Halted, result.GetResultCode().GetProcessing());
|
||||
EXPECT_TRUE(hasMessage);
|
||||
}
|
||||
|
||||
TYPED_TEST(JsonUnsupportedTypesSerializerTests, Load_CallThroughFrontEnd_ReportsIssueAndHalts)
|
||||
{
|
||||
namespace JSR = AZ::JsonSerializationResult;
|
||||
|
||||
bool hasMessage = false;
|
||||
auto callback = [&hasMessage](AZStd::string_view message, JSR::ResultCode result, AZStd::string_view) -> JSR::ResultCode
|
||||
{
|
||||
hasMessage = !message.empty();
|
||||
return result;
|
||||
};
|
||||
this->m_deserializationSettings->m_reporting = AZStd::move(callback);
|
||||
|
||||
JSR::ResultCode result = AZ::JsonSerialization::Load(this->m_instance, *this->m_jsonDocument, *this->m_deserializationSettings);
|
||||
|
||||
EXPECT_EQ(JSR::Processing::Halted, result.GetProcessing());
|
||||
EXPECT_TRUE(hasMessage);
|
||||
}
|
||||
|
||||
TYPED_TEST(JsonUnsupportedTypesSerializerTests, Save_CallDirectly_ReportsIssueAndHalts)
|
||||
{
|
||||
namespace JSR = AZ::JsonSerializationResult;
|
||||
|
||||
bool hasMessage = false;
|
||||
auto callback = [&hasMessage](AZStd::string_view message, JSR::ResultCode result, AZStd::string_view) -> JSR::ResultCode
|
||||
{
|
||||
hasMessage = !message.empty();
|
||||
return result;
|
||||
};
|
||||
this->m_jsonSerializationContext->PushReporter(AZStd::move(callback));
|
||||
|
||||
JSR::Result result = this->m_serializer->Store(
|
||||
*this->m_jsonDocument, &this->m_instance, nullptr, azrtti_typeid(this->m_instance), *this->m_jsonSerializationContext);
|
||||
this->m_jsonSerializationContext->PopReporter();
|
||||
|
||||
EXPECT_EQ(JSR::Processing::Halted, result.GetResultCode().GetProcessing());
|
||||
EXPECT_TRUE(hasMessage);
|
||||
}
|
||||
|
||||
TYPED_TEST(JsonUnsupportedTypesSerializerTests, Save_CallThroughFrontEnd_ReportsIssueAndHalts)
|
||||
{
|
||||
namespace JSR = AZ::JsonSerializationResult;
|
||||
|
||||
bool hasMessage = false;
|
||||
auto callback = [&hasMessage](AZStd::string_view message, JSR::ResultCode result, AZStd::string_view) -> JSR::ResultCode
|
||||
{
|
||||
hasMessage = !message.empty();
|
||||
return result;
|
||||
};
|
||||
this->m_serializationSettings->m_reporting = AZStd::move(callback);
|
||||
|
||||
JSR::ResultCode result = AZ::JsonSerialization::Store(
|
||||
*this->m_jsonDocument, this->m_jsonDocument->GetAllocator(), this->m_instance, *this->m_serializationSettings);
|
||||
|
||||
EXPECT_EQ(JSR::Processing::Halted, result.GetProcessing());
|
||||
EXPECT_TRUE(hasMessage);
|
||||
}
|
||||
} // namespace JsonSerializationTests
|
||||
@@ -128,6 +128,7 @@ set(FILES
|
||||
Serialization/Json/TransformSerializerTests.cpp
|
||||
Serialization/Json/TupleSerializerTests.cpp
|
||||
Serialization/Json/UnorderedSetSerializerTests.cpp
|
||||
Serialization/Json/UnsupportedTypesSerializerTests.cpp
|
||||
Serialization/Json/UuidSerializerTests.cpp
|
||||
Math/AabbTests.cpp
|
||||
Math/ColorTests.cpp
|
||||
|
||||
Reference in New Issue
Block a user