4527: Don't make score test depend on specific timestamp r=heinrich5991 a=def-

Insert current timestamp instead

Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-12-25 01:25:31 +00:00 committed by GitHub
commit 5b981e4075
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 8 deletions

View file

@ -656,7 +656,7 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST)
)
if(MSVC)
foreach(target gtest)
foreach(target gtest gmock)
# `/w` disables all warnings. This is needed because `gtest` enables
# `/WX` (equivalent of `-Werror`) for some reason, breaking builds
# when MSVS adds new warnings.
@ -664,10 +664,10 @@ if(NOT(GTEST_FOUND) AND DOWNLOAD_GTEST)
endforeach()
endif()
set(GTEST_LIBRARIES gtest)
set(GTEST_LIBRARIES gtest gmock)
set(GTEST_INCLUDE_DIRS)
if(CMAKE_VERSION VERSION_LESS 2.8.11)
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include")
set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
endif()
endif()
endif()

View file

@ -42,6 +42,12 @@ int sqlstr::EscapeLike(char *pDst, const char *pSrc, int DstSize)
void sqlstr::AgoTimeToString(int AgoTime, char *pAgoString, int Size)
{
if(AgoTime <= 0)
{
str_copy(pAgoString, "moments", Size);
return;
}
char aBuf[20];
int aTimes[7] =
{

View file

@ -1,3 +1,4 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <base/detect.h>
@ -75,11 +76,13 @@ struct Score : public testing::TestWithParam<IDbConnection *>
void InsertMap()
{
char aTimestamp[32];
str_timestamp_format(aTimestamp, sizeof(aTimestamp), FORMAT_SPACE);
char aBuf[512];
str_format(aBuf, sizeof(aBuf),
"%s into %s_maps(Map, Server, Mapper, Points, Stars, Timestamp) "
"VALUES (\"Kobra 3\", \"Novice\", \"Zerodin\", 5, 5, \"2015-01-01 00:00:00\")",
m_pConn->InsertIgnore(), m_pConn->GetPrefix());
"VALUES (\"Kobra 3\", \"Novice\", \"Zerodin\", 5, 5, \"%s\")",
m_pConn->InsertIgnore(), m_pConn->GetPrefix(), aTimestamp);
ASSERT_FALSE(m_pConn->PrepareStatement(aBuf, m_aError, sizeof(m_aError))) << m_aError;
int NumInserted = 0;
ASSERT_FALSE(m_pConn->ExecuteUpdate(&NumInserted, m_aError, sizeof(m_aError))) << m_aError;
@ -253,7 +256,13 @@ TEST_P(MapInfo, ExactNoFinish)
{
str_copy(m_PlayerRequest.m_aName, "Kobra 3", sizeof(m_PlayerRequest.m_aName));
ASSERT_FALSE(CScoreWorker::MapInfo(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(pPlayerResult, {"\"Kobra 3\" by Zerodin on Novice, ★★★★★, 5 points, released 6 years and 11 months ago, 0 finishes by 0 tees"});
EXPECT_EQ(pPlayerResult->m_MessageKind, CScorePlayerResult::DIRECT);
EXPECT_THAT(pPlayerResult->m_Data.m_aaMessages[0], testing::MatchesRegex("\"Kobra 3\" by Zerodin on Novice, ★★★★★, 5 points, released .* ago, 0 finishes by 0 tees"));
for(int i = 1; i < CScorePlayerResult::MAX_MESSAGES; i++)
{
EXPECT_STREQ(pPlayerResult->m_Data.m_aaMessages[i], "");
}
}
TEST_P(MapInfo, ExactFinish)
@ -261,7 +270,13 @@ TEST_P(MapInfo, ExactFinish)
InsertRank();
str_copy(m_PlayerRequest.m_aName, "Kobra 3", sizeof(m_PlayerRequest.m_aName));
ASSERT_FALSE(CScoreWorker::MapInfo(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(pPlayerResult, {"\"Kobra 3\" by Zerodin on Novice, ★★★★★, 5 points, released 6 years and 11 months ago, 1 finish by 1 tee in 01:40 median"});
EXPECT_EQ(pPlayerResult->m_MessageKind, CScorePlayerResult::DIRECT);
EXPECT_THAT(pPlayerResult->m_Data.m_aaMessages[0], testing::MatchesRegex("\"Kobra 3\" by Zerodin on Novice, ★★★★★, 5 points, released .* ago, 1 finish by 1 tee in 01:40 median"));
for(int i = 1; i < CScorePlayerResult::MAX_MESSAGES; i++)
{
EXPECT_STREQ(pPlayerResult->m_Data.m_aaMessages[i], "");
}
}
TEST_P(MapInfo, Fuzzy)
@ -269,7 +284,13 @@ TEST_P(MapInfo, Fuzzy)
InsertRank();
str_copy(m_PlayerRequest.m_aName, "k3", sizeof(m_PlayerRequest.m_aName));
ASSERT_FALSE(CScoreWorker::MapInfo(m_pConn, &m_PlayerRequest, m_aError, sizeof(m_aError))) << m_aError;
ExpectLines(pPlayerResult, {"\"Kobra 3\" by Zerodin on Novice, ★★★★★, 5 points, released 6 years and 11 months ago, 1 finish by 1 tee in 01:40 median"});
EXPECT_EQ(pPlayerResult->m_MessageKind, CScorePlayerResult::DIRECT);
EXPECT_THAT(pPlayerResult->m_Data.m_aaMessages[0], testing::MatchesRegex("\"Kobra 3\" by Zerodin on Novice, ★★★★★, 5 points, released .* ago, 1 finish by 1 tee in 01:40 median"));
for(int i = 1; i < CScorePlayerResult::MAX_MESSAGES; i++)
{
EXPECT_STREQ(pPlayerResult->m_Data.m_aaMessages[i], "");
}
}
TEST_P(MapInfo, DoesntExit)