Files
o3de/Gems/AudioEngineWwise/Code/Tests/AudioEngineWwiseTest.cpp
T
lumberyard-employee-dm f648cb1fd8 Update the FileIO Aliases (#4186)
* Update the FileIOAlias naming to make the cache, project root and engine
root paths more clear

The alias of `@root@`, `@assets@`, and `@projectplatformcache@` has been
collapsed to `@projectproductassets@`

The alias of `@devroot@` and `@engroot@` has been collapsed to
`@engroot@`

The alias of `@devassets@` and `@projectroot@` has been collapsed to
`@projectroot@`

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated use of devassets and devroot properties in python

Those properties now use projectroot and engroot

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updating the alias @engroot@ alias path comment in each platform specific LocalFileIO_*.cpp file

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed hardcoded size of 9 for the product asset alias.

The ResolvePath function now just appends the @projectproductassets@
alias with the input path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Remove duplicate @projectproductassets@ check in ProcessFileTreeRequest

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fix for typos in Hydra python test

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated LocalFileIO::Copy call on Windows to use the Unicode aware CopyFileW API

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the AWSMetreicsGemAllocatorFixture to properly suppress asset
cache write errors for Test file creation.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed unneeded call to set the @projectproductasstes@ alias at the bottom of the AssetSeedManagerTest SetUp

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Added a deprecated alias map to the FileIO System

When a deprecated alias is accessed, the FileIO System logs an AZ_Error and indicates the alias that should be used

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated python test scripts to use the projectroot binding

Retrieving the AutomatedTesting project path based on "<devroot>/AutomatedTesting" has been removed.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated references to devroot and devgame within the codebase

The GetAbsoluteDevGameFolderPath functions has been replaced with direct call to AZ::Utils::GetProjectPath
The GetAbsoluteDevRootFolderPath functions has been replaced with direct calls to AZ::Utils::GetEnginePath

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated <engroot>/AutomatedTesting references to projectroot


Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replaced references that assumes the project path is <engroot>/AutomatedTesting with <projectroot> in the AutomatedTesting python test

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Correct casing in emfxworkspace file


Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed newly added AppendPathParts function
Removed the Path constructors which accepts a PathIterable instance

The PathIterable isn't safe to return to a user of the Path class as it might be referencing temporary paths supplied via PathView arguments

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed unused parameter warning

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Undid change to the LexicallyProximate function to set the path result to the base path.

It needs to return the *this path if the pathResult is empty

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Moved the LocalFileIO ConvertToAbsolutePath implementations to AZ::Utils

Fixed the ConvertToAbsolutePath implementation for Unix platforms to use a buffer that is size PATH_MAX(4096 on all our supported Unix platforms).
Because the buffer before was AZ::IO::MaxPathLength which as a size of 1024, this was resulting in the Unix `realpath` function smashing the stack when it converts a path to an absolute path that is longer than 1024 characters

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the EditorCore.Tests to attach the AZ Environment to the EditorCore shared library that is statically loaded on launch.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed for DeprecatedAlaisesKeyVisitor Visit function causing the non string_view overloads being hidden causing a hidden base class function warning

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Changed the AWSMetricsGemMock to use a temporary for writing test assets

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the LocalFileIO::ResolvePath function to use HasRootPath to determine if a path starts with a root path such as "D:", "D:/" or "/"

IsAbsolute was not the corect check as the path of "D:" is a relative
path.
To be absolute according to the Windows the path must have a root
directory. i.e "D:/" or "D:\"

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed absolute path comment from LocalFile_UnixLike.cpp and LocalFile_Android.cpp FindFiles implementations
Updated the ConvertToAlias to supply an AZ::IO::FixedMaxPath

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replaced usage of the @projectproductassets@ alias with @engroot@ when referring to the LmbrCentral source folder in the CopyDependencyBuilderTest and the SeedBuilderTests

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the ScriptCanvas Upgrade Tool to output backed up files to the
Project User Path instead of the engine root

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed whitespacing issues in Application.cpp

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Remove unnecessary creation of a FixedMaxPath in the UpgradeTool.cpp

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Modified testSeedFolder variable in the SeedBuilderTests to use the
@engroot@ alias instead of @projectproductassets@/.. alias when
referring to the LmbrCentral Gem source path

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated references to the Project Asset Cache in the PythonTests.

Those tests no longer use the logic `azlmbr.paths.projectroot / "Cache" / "pc"` to retrieve a path to the cache root but instead the `azlmbr.paths.projectproductassets` constant

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed the FileIO Deprecated Alias test on Windows

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removing @projectsourceassets@ alias, as it is only used once.

Updated the PhysX EditorSystemComponent.cpp to query the ProjectPath
form the SettingsRegistry.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Replaced @projectproductassets@ alias with @products@

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Rollback changes to the PhysX EditorSystemComponent.cpp

The changes to use the ProjectPath from the SettingsRegistry has been implemented in PR #4497

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2021-10-05 15:12:53 -05:00

340 lines
12 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/PlatformIncl.h>
#include <AzTest/AzTest.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/StringFunc/StringFunc.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
#include <AzFramework/IO/LocalFileIO.h>
#include <AzFramework/Application/Application.h>
#include <AudioSystemImpl_wwise.h>
#include <AudioEngineWwise_Traits_Platform.h>
#include <Config_wwise.h>
#include <AK/SoundEngine/Common/AkSoundEngine.h>
#include <AK/SoundEngine/Common/AkMemoryMgr.h>
#include <AK/SoundEngine/Common/AkModule.h>
#include <platform.h>
#include <Mocks/IConsoleMock.h>
#include <Mocks/ISystemMock.h>
using namespace Audio;
using ::testing::NiceMock;
namespace UnitTest
{
class WwiseTestEnvironment
: public AZ::Test::ITestEnvironment
{
public:
AZ_TEST_CLASS_ALLOCATOR(WwiseTestEnvironment)
WwiseTestEnvironment() = default;
~WwiseTestEnvironment() override = default;
protected:
struct MockHolder
{
AZ_TEST_CLASS_ALLOCATOR(MockHolder)
NiceMock<ConsoleMock> m_console;
NiceMock<SystemMock> m_system;
};
void SetupEnvironment() override
{
// Create AZ::SystemAllocator
if (!AZ::AllocatorInstance<AZ::SystemAllocator>::IsReady())
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Create();
}
// Setup Mocks on a stub environment
m_mocks = new MockHolder();
m_stubEnv.pConsole = &m_mocks->m_console;
m_stubEnv.pSystem = &m_mocks->m_system;
gEnv = &m_stubEnv;
// Create AudioImplAllocator (used by Wwise)
if (!AZ::AllocatorInstance<AudioImplAllocator>::IsReady())
{
AudioImplAllocator::Descriptor allocDesc;
allocDesc.m_allocationRecords = false;
allocDesc.m_heap.m_numFixedMemoryBlocks = 1;
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0] = 8 << 20;
allocDesc.m_heap.m_fixedMemoryBlocks[0] = AZ::AllocatorInstance<AZ::OSAllocator>::Get().Allocate(allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0], allocDesc.m_heap.m_memoryBlockAlignment);
AZ::AllocatorInstance<AudioImplAllocator>::Create(allocDesc);
}
}
void TeardownEnvironment() override
{
if (AZ::AllocatorInstance<AudioImplAllocator>::IsReady())
{
AZ::AllocatorInstance<AudioImplAllocator>::Destroy();
}
delete m_mocks;
m_mocks = nullptr;
if (AZ::AllocatorInstance<AZ::SystemAllocator>::IsReady())
{
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
}
}
private:
SSystemGlobalEnvironment m_stubEnv;
MockHolder* m_mocks = nullptr;
};
class AudioSystemImplWwiseTests
: public ::testing::Test
{
public:
AZ_TEST_CLASS_ALLOCATOR(AudioSystemImplWwiseTests)
protected:
AudioSystemImplWwiseTests()
: m_wwiseImpl("")
{}
void SetUp() override
{
#if !AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
// Init Wwise
AkMemSettings memSettings;
AK::MemoryMgr::GetDefaultSettings(memSettings);
AK::MemoryMgr::Init(&memSettings);
AkStreamMgrSettings strmSettings;
AK::StreamMgr::GetDefaultSettings(strmSettings);
AK::StreamMgr::Create(strmSettings);
AkInitSettings initSettings;
AK::SoundEngine::GetDefaultInitSettings(initSettings);
AkPlatformInitSettings platSettings;
AK::SoundEngine::GetDefaultPlatformInitSettings(platSettings);
AK::SoundEngine::Init(&initSettings, &platSettings);
#endif // !AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
}
void TearDown() override
{
#if !AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
// Term Wwise
AK::SoundEngine::Term();
AK::IAkStreamMgr::Get()->Destroy();
AK::MemoryMgr::Term();
#endif // !AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
}
CAudioSystemImpl_wwise m_wwiseImpl;
};
#if AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
TEST_F(AudioSystemImplWwiseTests, DISABLED_WwiseSanityTest)
#else
TEST_F(AudioSystemImplWwiseTests, WwiseSanityTest)
#endif // AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
{
// Tests that Setup/TearDown work as expected
}
#if AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
TEST_F(AudioSystemImplWwiseTests, DISABLED_WwiseMultiPosition_GoodData)
#else
TEST_F(AudioSystemImplWwiseTests, WwiseMultiPosition_GoodData)
#endif // AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
{
SATLAudioObjectData_wwise wwiseObject(1, true);
MultiPositionParams params;
params.m_positions.push_back(AZ::Vector3(1.f, 2.f, 3.f));
params.m_type = MultiPositionBehaviorType::Blended;
auto result = m_wwiseImpl.SetMultiplePositions(&wwiseObject, params);
EXPECT_EQ(result, eARS_SUCCESS);
}
#if AZ_TRAIT_AUDIOENGINEWWISE_DISABLE_MULTIPOSITION_TESTS
TEST_F(AudioSystemImplWwiseTests, DISABLED_WwiseMultiPosition_BadObject)
#else
TEST_F(AudioSystemImplWwiseTests, WwiseMultiPosition_BadObject)
#endif
{
MultiPositionParams params;
params.m_positions.push_back(AZ::Vector3(1.f, 2.f, 3.f));
params.m_type = MultiPositionBehaviorType::Separate;
auto result = m_wwiseImpl.SetMultiplePositions(nullptr, params);
EXPECT_EQ(result, eARS_FAILURE);
}
#if AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
TEST_F(AudioSystemImplWwiseTests, DISABLED_WwiseMultiPosition_ZeroPositions)
#else
TEST_F(AudioSystemImplWwiseTests, WwiseMultiPosition_ZeroPositions)
#endif // AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
{
SATLAudioObjectData_wwise wwiseObject(1, true);
MultiPositionParams params;
auto result = m_wwiseImpl.SetMultiplePositions(&wwiseObject, params);
EXPECT_EQ(result, eARS_SUCCESS);
}
class AudioSystemImpl_wwise_Test
: public CAudioSystemImpl_wwise
{
public:
AZ_TEST_CLASS_ALLOCATOR(AudioSystemImpl_wwise_Test)
explicit AudioSystemImpl_wwise_Test(const char* assetPlatform)
: CAudioSystemImpl_wwise(assetPlatform)
{}
#if AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
friend class GTEST_TEST_CLASS_NAME_(AudioSystemImplWwiseConfigTests, DISABLED_WwiseSetBankPaths_NonDefaultPath_PathMatches);
friend class GTEST_TEST_CLASS_NAME_(AudioSystemImplWwiseConfigTests, DISABLED_WwiseSetBankPaths_NoInitBnk_DefaultPath);
#else
friend class GTEST_TEST_CLASS_NAME_(AudioSystemImplWwiseConfigTests, WwiseSetBankPaths_NonDefaultPath_PathMatches);
friend class GTEST_TEST_CLASS_NAME_(AudioSystemImplWwiseConfigTests, WwiseSetBankPaths_NoInitBnk_DefaultPath);
#endif // AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
};
class AudioSystemImplWwiseConfigTests
: public ::testing::Test
{
public:
AZ_TEST_CLASS_ALLOCATOR(AudioSystemImplWwiseConfigTests)
protected:
AudioSystemImplWwiseConfigTests()
: m_wwiseImpl("")
{
}
void SetUp() override
{
m_app.Start(AZ::ComponentApplication::Descriptor());
// Without this, the user settings component would attempt to save on finalize/shutdown. Since the file is
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
// shared across the whole engine, if multiple tests are run in parallel, the saving could cause a crash
// in the unit tests.
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequests::DisableSaveOnFinalize);
// Store and remove the existing fileIO...
m_prevFileIO = AZ::IO::FileIOBase::GetInstance();
if (m_prevFileIO)
{
AZ::IO::FileIOBase::SetInstance(nullptr);
}
// Replace with a new LocalFileIO...
m_fileIO = AZStd::make_unique<AZ::IO::LocalFileIO>();
AZ::IO::FileIOBase::SetInstance(m_fileIO.get());
// Reflect the wwise config settings...
AZ::SerializeContext* serializeContext = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationBus::Events::GetSerializeContext);
AZ_TEST_ASSERT(serializeContext != nullptr);
Audio::Wwise::ConfigurationSettings::Reflect(serializeContext);
// Set the @products@ alias to the path where *this* cpp file lives.
AZStd::string rootFolder(AZ::Test::GetCurrentExecutablePath());
AZ::StringFunc::Path::Join(rootFolder.c_str(), "Test.Assets/Gems/AudioEngineWwise", rootFolder);
m_fileIO->SetAlias("@products@", rootFolder.c_str());
// So we don't have to compute it in each test...
AZStd::string defaultBanksPath(Audio::Wwise::DefaultBanksPath);
m_configFilePath = AZStd::string::format("%s/%s%s", rootFolder.c_str(), defaultBanksPath.c_str(), Audio::Wwise::ConfigFile);
}
void TearDown() override
{
// Destroy our LocalFileIO...
m_fileIO.reset();
// Replace the old fileIO (set instance to null first)...
AZ::IO::FileIOBase::SetInstance(nullptr);
if (m_prevFileIO)
{
AZ::IO::FileIOBase::SetInstance(m_prevFileIO);
m_prevFileIO = nullptr;
}
m_app.Stop();
}
AZStd::unique_ptr<AZ::IO::LocalFileIO> m_fileIO;
AZStd::string m_configFilePath;
Audio::Wwise::ConfigurationSettings::PlatformMapping m_mapEntry;
AudioSystemImpl_wwise_Test m_wwiseImpl;
private:
AzFramework::Application m_app;
AZ::IO::FileIOBase* m_prevFileIO { nullptr };
};
#if AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
TEST_F(AudioSystemImplWwiseConfigTests, DISABLED_WwiseSetBankPaths_NonDefaultPath_PathMatches)
#else
TEST_F(AudioSystemImplWwiseConfigTests, WwiseSetBankPaths_NonDefaultPath_PathMatches)
#endif // AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
{
// The mapping here points to a custom directory that exists (and contains an init.bnk).
// The custom bank path should be set.
Audio::Wwise::ConfigurationSettings config;
m_mapEntry.m_enginePlatform = AZ_TRAIT_OS_PLATFORM_NAME;
m_mapEntry.m_bankSubPath = "soundbanks";
config.m_platformMappings.push_back(m_mapEntry);
config.Save(m_configFilePath);
m_wwiseImpl.SetBankPaths();
m_fileIO->Remove(m_configFilePath.c_str());
EXPECT_STREQ(m_wwiseImpl.m_soundbankFolder.c_str(), "sounds/wwise/soundbanks/");
}
#if AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
TEST_F(AudioSystemImplWwiseConfigTests, DISABLED_WwiseSetBankPaths_NoInitBnk_DefaultPath)
#else
TEST_F(AudioSystemImplWwiseConfigTests, WwiseSetBankPaths_NoInitBnk_DefaultPath)
#endif // AZ_TRAIT_DISABLE_FAILED_AUDIO_WWISE_TESTS
{
// The mapping here points to a directory that does not exist (and doesn't contain init.bnk).
// The default bank path should be set.
Audio::Wwise::ConfigurationSettings config;
m_mapEntry.m_enginePlatform = AZ_TRAIT_OS_PLATFORM_NAME;
m_mapEntry.m_bankSubPath = "no_soundbanks";
config.m_platformMappings.push_back(m_mapEntry);
config.Save(m_configFilePath);
m_wwiseImpl.SetBankPaths();
m_fileIO->Remove(m_configFilePath.c_str());
EXPECT_STREQ(m_wwiseImpl.m_soundbankFolder.c_str(), Audio::Wwise::DefaultBanksPath);
}
} // namespace UnitTest
AZ_UNIT_TEST_HOOK(new UnitTest::WwiseTestEnvironment);