diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp index c82fca403..12165e8f3 100644 --- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp +++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_local.cpp @@ -101,7 +101,7 @@ QImage CardPictureLoaderLocal::tryLoadCardImageFromDisk(const QString &setName, for (const QString &path : candidatePaths) { QFileInfo fileInfo(path); QDir dir = fileInfo.dir(); - QString baseName = fileInfo.fileName(); + QString baseName = fileInfo.completeBaseName(); if (!dir.exists()) { continue; diff --git a/tests/loader_local_matching_test.cpp b/tests/loader_local_matching_test.cpp index 7ffa7157d..6ce684fdd 100644 --- a/tests/loader_local_matching_test.cpp +++ b/tests/loader_local_matching_test.cpp @@ -68,6 +68,18 @@ protected: loader = nullptr; } + /** + * @brief Destroys and rebuilds the loader so the CUSTOM index is re-scanned. + * + * The CUSTOM-folder index is snapshotted at construction; rebuild it after + * writing files so freshly placed images are discoverable. + */ + void rebuildLoader() + { + delete loader; + loader = new CardPictureLoaderLocal(nullptr); + } + /** * @brief Writes a valid 1x1 PNG under the sandboxed pics path. */ @@ -162,6 +174,28 @@ TEST_F(LocalMatcherTest, SetFolderCandidateTakesPrecedenceOverRootFallback) EXPECT_EQ(image.pixelColor(0, 0), QColor(Qt::red)) << "The set-folder candidate must be preferred"; } +TEST_F(LocalMatcherTest, CustomSubfolderResolvesExactFile) +{ + // Images in the CUSTOM folder are indexed by their full file path (extension included), + // unlike the extension-less candidate paths built from the naming schemes. + writePngUnderPics("CUSTOM/poker/TestCard.png"); + rebuildLoader(); + + const QImage image = loader->tryLoad(cardFor("TestCard", "", "")); + + EXPECT_FALSE(image.isNull()) << "A CUSTOM-folder image in a subdirectory must resolve"; +} + +TEST_F(LocalMatcherTest, CustomSubfolderIgnoresSuffixedFiles) +{ + writePngUnderPics("CUSTOM/poker/TestCard (1).png"); + rebuildLoader(); + + const QImage image = loader->tryLoad(cardFor("TestCard", "", "")); + + EXPECT_TRUE(image.isNull()) << "A suffixed CUSTOM-folder file must not satisfy an exact name lookup"; +} + } // namespace int main(int argc, char **argv)