mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
Merge 2916fa45af into 7a7c535158
This commit is contained in:
commit
28706b5b8d
10 changed files with 937 additions and 2 deletions
|
|
@ -475,6 +475,15 @@ cockatrice_add_test(
|
|||
libcockatrice_deck_list
|
||||
libcockatrice_utility
|
||||
)
|
||||
cockatrice_add_test(
|
||||
NAME
|
||||
deck_content_hash_test
|
||||
SOURCES
|
||||
deck_content_hash_test.cpp
|
||||
LIBS
|
||||
libcockatrice_deck_list
|
||||
libcockatrice_utility
|
||||
)
|
||||
cockatrice_add_test(
|
||||
NAME
|
||||
deck_sync_profile_test
|
||||
|
|
|
|||
51
tests/deck_content_hash_test.cpp
Normal file
51
tests/deck_content_hash_test.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include <QString>
|
||||
#include <libcockatrice/deck_list/deck_list.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
QString deckWithName(const QString &name)
|
||||
{
|
||||
return QStringLiteral(R"(<?xml version="1.0"?><cockatrice_deck version="1">)"
|
||||
R"(<deckname>%1</deckname><comments></comments>)"
|
||||
R"(<zone name="main"><card number="4" name="Lightning Bolt"/></zone>)"
|
||||
R"(<zone name="side"><card number="2" name="Pyroblast"/></zone>)"
|
||||
R"(</cockatrice_deck>)")
|
||||
.arg(name);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(DeckContentHashTest, MatchesNativeSerialisation)
|
||||
{
|
||||
DeckList deck;
|
||||
ASSERT_TRUE(deck.loadFromString_Native(deckWithName(QStringLiteral("Burn"))));
|
||||
EXPECT_EQ(deck.getContentHash(), DeckList::contentHash(deck.writeToString_Native()));
|
||||
}
|
||||
|
||||
TEST(DeckContentHashTest, IsStableAcrossLoads)
|
||||
{
|
||||
DeckList first;
|
||||
DeckList second;
|
||||
ASSERT_TRUE(first.loadFromString_Native(deckWithName(QStringLiteral("Burn"))));
|
||||
ASSERT_TRUE(second.loadFromString_Native(deckWithName(QStringLiteral("Burn"))));
|
||||
EXPECT_EQ(first.getContentHash(), second.getContentHash());
|
||||
}
|
||||
|
||||
TEST(DeckContentHashTest, CoversDeckName)
|
||||
{
|
||||
DeckList burn;
|
||||
DeckList renamed;
|
||||
ASSERT_TRUE(burn.loadFromString_Native(deckWithName(QStringLiteral("Burn"))));
|
||||
ASSERT_TRUE(renamed.loadFromString_Native(deckWithName(QStringLiteral("Burn v2"))));
|
||||
|
||||
// The card hash only looks at card names and counts, so it cannot tell the
|
||||
// two decks apart; the content hash must.
|
||||
EXPECT_EQ(burn.getDeckHash(), renamed.getDeckHash());
|
||||
EXPECT_NE(burn.getContentHash(), renamed.getContentHash());
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue