do not save a const reference to the user data in the info dialog (#6974)

* do not save a const reference to the user data in the info dialog

* cmake format

(cherry picked from commit 6be9cec6e2)
This commit is contained in:
ebbit1q 2026-06-10 08:35:00 +02:00 committed by RickyRister
parent 547d9ab88d
commit 00ce2cef8a
5 changed files with 29 additions and 34 deletions

View file

@ -59,7 +59,9 @@ endif()
include_directories(${GTEST_INCLUDE_DIRS})
target_link_libraries(dummy_test Threads::Threads ${GTEST_BOTH_LIBRARIES})
target_link_libraries(expression_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
target_link_libraries(test_age_formatting Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
target_link_libraries(
test_age_formatting libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
)
target_link_libraries(
password_hash_test libcockatrice_utility Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES}
)

View file

@ -1,6 +1,5 @@
#include "../cockatrice/src/interface/widgets/server/user/user_info_box.h"
#include "gtest/gtest.h"
#include <libcockatrice/utility/days_years_between.h>
namespace
{
@ -8,31 +7,31 @@ using dayyear = QPair<int, int>;
TEST(AgeFormatting, Zero)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2000, 1, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2000, 1, 1));
ASSERT_EQ(got, dayyear(0, 0)) << "these are the same day";
}
TEST(AgeFormatting, LeapDay)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2000, 3, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2000, 3, 1));
ASSERT_EQ(got, dayyear(2, 0)) << "there is a leap day in between these days";
}
TEST(AgeFormatting, LeapYear)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2001, 1, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 1, 1), QDate(2001, 1, 1));
ASSERT_EQ(got, dayyear(0, 1)) << "there is a leap day in between these dates, but that's fine";
}
TEST(AgeFormatting, LeapDayWithYear)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2001, 3, 1));
auto got = getDaysAndYearsBetween(QDate(2000, 2, 28), QDate(2001, 3, 1));
ASSERT_EQ(got, dayyear(1, 1)) << "there is a leap day in between these days but not in the last year";
}
TEST(AgeFormatting, LeapDayThisYear)
{
auto got = UserInfoBox::getDaysAndYearsBetween(QDate(2003, 2, 28), QDate(2004, 3, 1));
auto got = getDaysAndYearsBetween(QDate(2003, 2, 28), QDate(2004, 3, 1));
ASSERT_EQ(got, dayyear(2, 1)) << "there is a leap day in between these days this year";
}
} // namespace