Simplify testing by using gmoick matchers

This commit is contained in:
2026-08-30 14:26:57 +02:00
parent 41a0758679
commit 7bf80949e8
6 changed files with 22 additions and 28 deletions
+3 -5
View File
@@ -10,6 +10,7 @@
#include <AssetsForTesting/Asset/AssetB.hpp>
#include <AssetsForTesting/Asset/AssetC.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace Bigfoot
@@ -114,10 +115,7 @@ TEST_F(AssetFixture, GetHardReferences_ShouldReturnTheHardReferencesOfTheAsset)
{
const eastl::vector<UUID> hardReferences = m_assetC.GetHardReferences(m_assetC.Pack());
EXPECT_EQ(hardReferences.size(), 2);
EXPECT_TRUE(std::find(hardReferences.begin(), hardReferences.end(), m_assetA.GetHeader().uuid) !=
hardReferences.end());
EXPECT_TRUE(std::find(hardReferences.begin(), hardReferences.end(), m_assetB.GetHeader().uuid) !=
hardReferences.end());
EXPECT_THAT(hardReferences,
::testing::UnorderedElementsAre(m_assetA.GetHeader().uuid, m_assetB.GetHeader().uuid));
}
} // namespace Bigfoot
+3 -5
View File
@@ -15,6 +15,7 @@
#include <AssetsForTesting/Asset/AssetC.hpp>
#include <EASTL/array.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <chrono>
@@ -207,9 +208,7 @@ TEST_F(BigFileFixture, GetAssetHardReference_ShouldGetTheAssetHardReferences)
const eastl::vector<UUID> hardReferences = m_bigFile.GetAssetHardReferences(asset.GetHeader().uuid);
ASSERT_EQ(hardReferences.size(), 1);
EXPECT_TRUE(std::find(hardReferences.begin(), hardReferences.end(), referencedAssetX.GetHeader().uuid) !=
hardReferences.end());
EXPECT_THAT(hardReferences, ::testing::ElementsAre(referencedAssetX.GetHeader().uuid));
}
/****************************************************************************************/
@@ -265,8 +264,7 @@ TEST_F(BigFileFixture, GetAssetHardReferences_ShouldDuplicateResultsForADuplicat
ASSERT_EQ(hardReferences.size(), 2);
for (const eastl::vector<UUID>& entry: hardReferences)
{
ASSERT_EQ(entry.size(), 1);
EXPECT_TRUE(std::find(entry.begin(), entry.end(), referencedAssetX.GetHeader().uuid) != entry.end());
EXPECT_THAT(entry, ::testing::ElementsAre(referencedAssetX.GetHeader().uuid));
}
}
+3 -5
View File
@@ -13,6 +13,7 @@
#include <AssetsForTesting/Asset/AssetA.hpp>
#include <AssetsForTesting/Asset/AssetB.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace Bigfoot
@@ -110,9 +111,7 @@ TEST_F(SasquatchFixture, GetAssetHardReference_ShouldGetTheAssetHardReferences)
{
const eastl::vector<UUID> hardReferences = m_sasquatch->GetAssetHardReferences(m_assetB.GetHeader().uuid);
ASSERT_EQ(hardReferences.size(), 1);
EXPECT_TRUE(std::find(hardReferences.begin(), hardReferences.end(), m_assetA.GetHeader().uuid) !=
hardReferences.end());
EXPECT_THAT(hardReferences, ::testing::ElementsAre(m_assetA.GetHeader().uuid));
}
/****************************************************************************************/
@@ -140,8 +139,7 @@ TEST_F(SasquatchFixture, GetAssetHardReferences_ShouldDuplicateResultsForADuplic
ASSERT_EQ(hardReferences.size(), 2);
for (const eastl::vector<UUID>& entry: hardReferences)
{
ASSERT_EQ(entry.size(), 1);
EXPECT_TRUE(std::find(entry.begin(), entry.end(), m_assetA.GetHeader().uuid) != entry.end());
EXPECT_THAT(entry, ::testing::ElementsAre(m_assetA.GetHeader().uuid));
}
}
+2 -4
View File
@@ -9,6 +9,7 @@
#include <System/UUID/UUID_generated.hpp>
#include <ankerl/unordered_dense.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace Bigfoot
@@ -175,10 +176,7 @@ TEST_F(UUIDFixture, ToBytes_ShouldGiveBackTheRawDataOfTheID)
std::span<const std::byte, UUID::UUID_BYTE_SIZE> d = m_d.ToBytes();
std::span<const std::byte, UUID::UUID_BYTE_SIZE> raw = m_raw;
for (std::uint32_t i = 0; i < UUID::UUID_BYTE_SIZE; ++i)
{
EXPECT_EQ(d[i], raw[i]);
}
EXPECT_THAT(d, ::testing::ElementsAreArray(raw));
}
/****************************************************************************************/
+4 -3
View File
@@ -15,6 +15,7 @@
#include <EASTL/string_view.h>
#include <EASTL/vector.h>
#include <fmt/format.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
@@ -104,7 +105,7 @@ TEST_F(EASTLFormattersLogFixture, LogsEastlStringArgument)
{
const eastl::string value = "Hello EASTL string";
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value);
EXPECT_NE(ReadFileSinkContent().find("Hello EASTL string"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello EASTL string"));
}
/****************************************************************************************/
@@ -113,7 +114,7 @@ TEST_F(EASTLFormattersLogFixture, LogsEmptyVectorArgument)
{
const eastl::vector<int> value;
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value);
EXPECT_NE(ReadFileSinkContent().find("[]"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("[]"));
}
/****************************************************************************************/
@@ -122,7 +123,7 @@ TEST_F(EASTLFormattersLogFixture, LogsVectorArgumentWithCommaSeparators)
{
const eastl::vector<eastl::string> value {"a", "b", "c"};
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "{}", value);
EXPECT_NE(ReadFileSinkContent().find("[a, b, c]"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("[a, b, c]"));
}
#endif
} // namespace Bigfoot
+7 -6
View File
@@ -13,6 +13,7 @@
#if defined BIGFOOT_NOT_OPTIMIZED
#include <EASTL/string.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <fstream>
@@ -39,7 +40,7 @@ class LogMacrosFixture: public ::testing::Test
TEST_F(LogMacrosFixture, LogDebug)
{
BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello Debug");
EXPECT_NE(ReadFileSinkContent().find("Hello Debug"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Debug"));
}
/****************************************************************************************/
@@ -47,7 +48,7 @@ TEST_F(LogMacrosFixture, LogDebug)
TEST_F(LogMacrosFixture, LogTrace)
{
BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello Trace");
EXPECT_NE(ReadFileSinkContent().find("Hello Trace"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Trace"));
}
/****************************************************************************************/
@@ -55,7 +56,7 @@ TEST_F(LogMacrosFixture, LogTrace)
TEST_F(LogMacrosFixture, LogInfo)
{
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello Info");
EXPECT_NE(ReadFileSinkContent().find("Hello Info"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Info"));
}
/****************************************************************************************/
@@ -63,7 +64,7 @@ TEST_F(LogMacrosFixture, LogInfo)
TEST_F(LogMacrosFixture, LogWarn)
{
BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello Warn");
EXPECT_NE(ReadFileSinkContent().find("Hello Warn"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Warn"));
}
/****************************************************************************************/
@@ -71,7 +72,7 @@ TEST_F(LogMacrosFixture, LogWarn)
TEST_F(LogMacrosFixture, LogError)
{
BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello Error");
EXPECT_NE(ReadFileSinkContent().find("Hello Error"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Error"));
}
/****************************************************************************************/
@@ -79,7 +80,7 @@ TEST_F(LogMacrosFixture, LogError)
TEST_F(LogMacrosFixture, LogFatal)
{
BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello Fatal");
EXPECT_NE(ReadFileSinkContent().find("Hello Fatal"), eastl::string::npos);
EXPECT_THAT(std::string {ReadFileSinkContent().c_str()}, ::testing::HasSubstr("Hello Fatal"));
}
} // namespace Bigfoot
#endif