summaryrefslogtreecommitdiff
path: root/test/libapt/strutil_test.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-03-10 14:11:54 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2015-04-10 20:18:17 +0200
commitb8eba208daebe3e3f235983e44da9c398d6f7a57 (patch)
tree5bbd9a87c1a9a5b41f7484f775c30e756e6ab29f /test/libapt/strutil_test.cc
parent249aec3b7397662a678ea0014f94392085477b09 (diff)
reimplement the last uses of sprintf
Working with strings c-style is complicated and error-prune, so by converting to c++ style we gain some simplicity and avoid buffer overflows by later extensions. Git-Dch: Ignore
Diffstat (limited to 'test/libapt/strutil_test.cc')
-rw-r--r--test/libapt/strutil_test.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc
index 9bc3c76fd..23dc08727 100644
--- a/test/libapt/strutil_test.cc
+++ b/test/libapt/strutil_test.cc
@@ -97,6 +97,28 @@ TEST(StrUtilTest,StartsWith)
EXPECT_FALSE(Startswith("abcd", "x"));
EXPECT_FALSE(Startswith("abcd", "abcndefg"));
}
+TEST(StrUtilTest,TimeToStr)
+{
+ EXPECT_EQ("0s", TimeToStr(0));
+ EXPECT_EQ("42s", TimeToStr(42));
+ EXPECT_EQ("9min 21s", TimeToStr((9*60) + 21));
+ EXPECT_EQ("20min 42s", TimeToStr((20*60) + 42));
+ EXPECT_EQ("10h 42min 21s", TimeToStr((10*3600) + (42*60) + 21));
+ EXPECT_EQ("10h 42min 21s", TimeToStr((10*3600) + (42*60) + 21));
+ EXPECT_EQ("1988d 3h 29min 7s", TimeToStr((1988*86400) + (3*3600) + (29*60) + 7));
+
+ EXPECT_EQ("59s", TimeToStr(59));
+ EXPECT_EQ("60s", TimeToStr(60));
+ EXPECT_EQ("1min 1s", TimeToStr(61));
+ EXPECT_EQ("59min 59s", TimeToStr(3599));
+ EXPECT_EQ("60min 0s", TimeToStr(3600));
+ EXPECT_EQ("1h 0min 1s", TimeToStr(3601));
+ EXPECT_EQ("1h 1min 0s", TimeToStr(3660));
+ EXPECT_EQ("23h 59min 59s", TimeToStr(86399));
+ EXPECT_EQ("24h 0min 0s", TimeToStr(86400));
+ EXPECT_EQ("1d 0h 0min 1s", TimeToStr(86401));
+ EXPECT_EQ("1d 0h 1min 0s", TimeToStr(86460));
+}
TEST(StrUtilTest,SubstVar)
{
EXPECT_EQ("", SubstVar("", "fails", "passes"));