// Copyright Epic Games, Inc. All Rights Reserved. #include "MetasoundOutput.h" #include "MetasoundPrimitives.h" #include "MetasoundTime.h" #include "Misc/AutomationTest.h" #if WITH_DEV_AUTOMATION_TESTS namespace Metasound::Test::GeneratorOutput { IMPLEMENT_SIMPLE_AUTOMATION_TEST( FMetasoundOutputIsTypeTest, "Audio.Metasound.Output.IsType", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter) bool FMetasoundOutputIsTypeTest::RunTest(const FString&) { FMetaSoundOutput Output; Output.Init(float{ 0.0f }); UTEST_TRUE("float is float", Output.IsType()); UTEST_FALSE("float is not int32", Output.IsType()); UTEST_FALSE("float is not bool", Output.IsType()); UTEST_FALSE("float is not FString", Output.IsType()); UTEST_FALSE("float is not FTime", Output.IsType()); Output.Init(int32{ 0 }); UTEST_FALSE("int32 is not float", Output.IsType()); UTEST_TRUE("int32 is int32", Output.IsType()); UTEST_FALSE("int32 is not bool", Output.IsType()); UTEST_FALSE("int32 is not FString", Output.IsType()); UTEST_FALSE("int32 is not FTime", Output.IsType()); Output.Init(bool{ false }); UTEST_FALSE("bool is not float", Output.IsType()); UTEST_FALSE("bool is not int32", Output.IsType()); UTEST_TRUE("bool is bool", Output.IsType()); UTEST_FALSE("bool is not FString", Output.IsType()); UTEST_FALSE("bool is not FTime", Output.IsType()); Output.Init(FString{ "hi!" }); UTEST_FALSE("FString is not float", Output.IsType()); UTEST_FALSE("FString is not int32", Output.IsType()); UTEST_FALSE("FString is not bool", Output.IsType()); UTEST_TRUE("FString is FString", Output.IsType()); UTEST_FALSE("FString is not FTime", Output.IsType()); constexpr float TimeSeconds = 123.456f; Output.Init(FTime::FromSeconds(TimeSeconds)); UTEST_FALSE("FTime is not float", Output.IsType()); UTEST_FALSE("FTime is not int32", Output.IsType()); UTEST_FALSE("FTime is not bool", Output.IsType()); UTEST_FALSE("FTime is not FString", Output.IsType()); UTEST_TRUE("FTime is FTime", Output.IsType()); return true; } template bool RunOutputGetSetTest(FAutomationTestBase& Test, const DataType& InitialValue, const DataType& ExpectedValue) { FMetaSoundOutput Output; Output.Init(InitialValue); DataType Value; if (!Test.TestTrue("Got value", Output.Get(Value))) { return false; } if (!Test.TestEqual("Value equals initial", Value, InitialValue)) { return false; } if (!Test.TestTrue("Set value", Output.Set(ExpectedValue))) { return false; } if (!Test.TestTrue("Got value", Output.Get(Value))) { return false; } return Test.TestEqual("Value equals expected", Value, ExpectedValue); } IMPLEMENT_SIMPLE_AUTOMATION_TEST( FMetasoundOutputGetSetFloatTest, "Audio.Metasound.Output.GetSet.Float", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter) bool FMetasoundOutputGetSetFloatTest::RunTest(const FString&) { using DataType = float; constexpr DataType InitialValue = 321.654f; constexpr DataType ExpectedValue = 123.456f; return RunOutputGetSetTest(*this, InitialValue, ExpectedValue); } IMPLEMENT_SIMPLE_AUTOMATION_TEST( FMetasoundOutputGetSetInt32Test, "Audio.Metasound.Output.GetSet.Int32", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter) bool FMetasoundOutputGetSetInt32Test::RunTest(const FString&) { using DataType = int32; constexpr DataType InitialValue = 321654; constexpr DataType ExpectedValue = 123456; return RunOutputGetSetTest(*this, InitialValue, ExpectedValue); } IMPLEMENT_SIMPLE_AUTOMATION_TEST( FMetasoundOutputGetSetBoolTest, "Audio.Metasound.Output.GetSet.Bool", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter) bool FMetasoundOutputGetSetBoolTest::RunTest(const FString&) { using DataType = bool; constexpr DataType InitialValue = false; constexpr DataType ExpectedValue = true; return RunOutputGetSetTest(*this, InitialValue, ExpectedValue); } IMPLEMENT_SIMPLE_AUTOMATION_TEST( FMetasoundOutputGetSetStringTest, "Audio.Metasound.Output.GetSet.String", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter) bool FMetasoundOutputGetSetStringTest::RunTest(const FString&) { using FDataType = FString; const FDataType InitialValue{ "hello" }; const FDataType ExpectedValue{ "goodbye" }; return RunOutputGetSetTest(*this, InitialValue, ExpectedValue); } IMPLEMENT_SIMPLE_AUTOMATION_TEST( FMetasoundOutputGetSetFTimeTest, "Audio.Metasound.Output.GetSet.FTime", EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter) bool FMetasoundOutputGetSetFTimeTest::RunTest(const FString&) { using FDataType = FTime; const FDataType InitialValue{ FTime::FromSeconds(123.456f) }; const FDataType ExpectedValue{ FTime::FromSeconds(654.321f) }; return RunOutputGetSetTest(*this, InitialValue, ExpectedValue); } } #endif