13#include <gtest/gtest.h>
17using namespace std::chrono_literals;
20TEST(TestParseRsyncProgress, Invalid) {
21 EXPECT_FALSE(ParseRsyncProgress(
""));
22 EXPECT_FALSE(ParseRsyncProgress(
"a"));
23 EXPECT_FALSE(ParseRsyncProgress(
"120"));
24 EXPECT_FALSE(ParseRsyncProgress(
"120 1 z :::"));
25 EXPECT_FALSE(ParseRsyncProgress(
"a b c d"));
26 EXPECT_FALSE(ParseRsyncProgress(
" 0 0% 0.00aB/s 0:00:00"))
27 <<
"aB/s should not be accepted";
28 EXPECT_FALSE(ParseRsyncProgress(
" 0 0% 0.00aaaaa 0:00:00"))
29 <<
"bad unit should not be accepted";
30 EXPECT_FALSE(ParseRsyncProgress(
" 0 0% 0,00kB/s 0:00:00"))
31 <<
"Comma separated speed should not be accepted";
32 EXPECT_FALSE(ParseRsyncProgress(
" 0 0% 0,00kB/s 0;00;00"))
33 <<
"Semi-colon separated time should not be accepted";
34 EXPECT_FALSE(ParseRsyncProgress(
" 0 0% 0,00kB/s 0.00.00"))
35 <<
"Period separated time should not be accepted";
38TEST(TestParseRsyncProgress, Initial) {
39 auto p = ParseRsyncProgress(
" 0 0% 0.00kB/s 0:00:00");
41 EXPECT_NEAR(p->progress, 0.f, 0.01);
42 EXPECT_NEAR(p->speed, 0.f, 0.01);
46TEST(TestParseRsyncProgress, Mid1) {
47 auto p = ParseRsyncProgress(
" 361234432 33% 344.50MB/s 0:00:02");
49 EXPECT_NEAR(p->progress, 0.33f, 0.01);
50 EXPECT_NEAR(p->speed, 344.5 * 1024 * 1024, 0.01);
54TEST(TestParseRsyncProgress, Mid2) {
55 auto p = ParseRsyncProgress(
"6881280 0% 200.09kB/s 1:28:51");
57 EXPECT_NEAR(p->progress, 0.0f, 0.01);
58 EXPECT_NEAR(p->speed, 200.09 * 1024, 0.01);
59 EXPECT_EQ(p->remaining, 1h + 28min + 51s);
62TEST(TestParseRsyncProgress, Final) {
63 auto p = ParseRsyncProgress(
" 200000 100% 344.50MB/s 0:00:00 (xfr#1 to-chk=0/1)");
65 EXPECT_NEAR(p->progress, 1.f, 0.01);
66 EXPECT_NEAR(p->speed, 344.5 * 1024.0f * 1024.0f, 0.01);
TEST(TestParseRsyncProgress, Invalid)
std::optional< RsyncProgress > ParseRsyncProgress(std::string const &line) noexcept
Parse progress update from rsync.
daq::RsyncAsyncProcess and related class declarations.
EXPECT_EQ(meta.rr_uri, "zpb.rr://meta")