mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-10-28 02:20:24 -05:00
* [Client] Improve card database update visibility Addresses Cockatrice/Cockatrice#7431. Cockatrice previously offered no in-client feedback while the card database updater ran: the only progress UI lived in the first-run wizard, stderr/stdout were not parsed in interactive runs, and starting a second update with Oracle already open or with a hidden background run active just showed a confusing 'already running' guard - even though Oracle is launched as a separate process with no lifecycle tracking. - Add a status-bar widget (CardDatabaseUpdateStatusBar) that appears while an update runs and shows the Downloading/Parsing/Importing stages with percent progress; it is also used in the quit-confirm prompt so users see an unfinished update before cancelling it. - Parse the updater's PROGRESS lines (new CardUpdateProgressParser, unit-tested) in both foreground and background runs and log stage changes to the new card_database.update category, throttled to at most one line per second; forward Oracle stderr to the logs. - Show a tray balloon when a background update starts and on finish or failure instead of staying silent. - Request a running Oracle instance to raise itself (QLocalServer CockatriceOracleRaise-<user>) when the user starts another update, and demote the 'already running' guard to an informative message only when no running instance can be found. - Emit download/scan/import progress unconditionally from Oracle so interactive and background runs behave the same. - Document the new log category in the troubleshooting guide. * [Client] Address card database update review feedback * [Client] Add setting to control card database update tray notifications * [Client] Address remaining card database update review nits - Rename card_update_progress_parser.{h,cpp} to card_update_progress.{h,cpp} - Store the CardUpdateProgress struct in the status bar widget * Lint. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
93 lines
3.1 KiB
C++
93 lines
3.1 KiB
C++
#include "interface/card_database_update/card_update_progress.h"
|
|
|
|
#include <QByteArray>
|
|
#include <QString>
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace
|
|
{
|
|
std::optional<CardUpdateProgress> parseLine(const QByteArray &line)
|
|
{
|
|
return CardUpdateProgress::fromProtocolLine(line);
|
|
}
|
|
} // namespace
|
|
|
|
TEST(CardUpdateProgressTest, ParsesAValidDownloadLine)
|
|
{
|
|
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS download 42 100");
|
|
ASSERT_TRUE(progress.has_value());
|
|
EXPECT_EQ(CardUpdateStage::Download, progress->stage);
|
|
EXPECT_EQ(42, progress->done);
|
|
EXPECT_EQ(100, progress->total);
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, ParsesTrailingNewline)
|
|
{
|
|
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS scan 7 99\n");
|
|
ASSERT_TRUE(progress.has_value());
|
|
EXPECT_EQ(CardUpdateStage::Scan, progress->stage);
|
|
EXPECT_EQ(7, progress->done);
|
|
EXPECT_EQ(99, progress->total);
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, ParsesWithSurroundingWhitespace)
|
|
{
|
|
const std::optional<CardUpdateProgress> progress = parseLine(QByteArray(" PROGRESS import 3 10 "));
|
|
ASSERT_TRUE(progress.has_value());
|
|
EXPECT_EQ(CardUpdateStage::Import, progress->stage);
|
|
EXPECT_EQ(3, progress->done);
|
|
EXPECT_EQ(10, progress->total);
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, AcceptsZeroProgress)
|
|
{
|
|
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS download 0 0");
|
|
ASSERT_TRUE(progress.has_value());
|
|
EXPECT_EQ(0, progress->done);
|
|
EXPECT_EQ(0, progress->total);
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, RejectsLinesWithoutProgressPrefix)
|
|
{
|
|
EXPECT_FALSE(parseLine("download 42 100").has_value());
|
|
EXPECT_FALSE(parseLine("PROGRESSdownload 42 100").has_value());
|
|
EXPECT_FALSE(parseLine("").has_value());
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, RejectsMalformedLines)
|
|
{
|
|
EXPECT_FALSE(parseLine("PROGRESS").has_value());
|
|
EXPECT_FALSE(parseLine("PROGRESS download").has_value());
|
|
EXPECT_FALSE(parseLine("PROGRESS download 42 100 extra").has_value());
|
|
EXPECT_FALSE(parseLine("PROGRESS download 42").has_value());
|
|
EXPECT_FALSE(parseLine("PROGRESS download notANumber 100").has_value());
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, RejectsNegativeValues)
|
|
{
|
|
EXPECT_FALSE(parseLine("PROGRESS download -1 100").has_value());
|
|
EXPECT_FALSE(parseLine("PROGRESS download 42 -100").has_value());
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, AcceptsUnknownStagesSchemalessly)
|
|
{
|
|
const std::optional<CardUpdateProgress> progress = parseLine("PROGRESS spoilers 1 2");
|
|
ASSERT_TRUE(progress.has_value());
|
|
EXPECT_EQ(CardUpdateStage::Unknown, progress->stage);
|
|
EXPECT_EQ(1, progress->done);
|
|
EXPECT_EQ(2, progress->total);
|
|
}
|
|
|
|
TEST(CardUpdateProgressTest, StageTokensRoundTrip)
|
|
{
|
|
EXPECT_EQ("download", CardUpdateProgress{CardUpdateStage::Download}.stageToken());
|
|
EXPECT_EQ("scan", CardUpdateProgress{CardUpdateStage::Scan}.stageToken());
|
|
EXPECT_EQ("import", CardUpdateProgress{CardUpdateStage::Import}.stageToken());
|
|
EXPECT_EQ("unknown", CardUpdateProgress{CardUpdateStage::Unknown}.stageToken());
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
} |