summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/install_progress_test.cc7
-rw-r--r--test/libapt/srvrecs_test.cc10
-rw-r--r--test/libapt/stringview_test.cc20
3 files changed, 26 insertions, 11 deletions
diff --git a/test/libapt/install_progress_test.cc b/test/libapt/install_progress_test.cc
index a70fc9261..b63b4716f 100644
--- a/test/libapt/install_progress_test.cc
+++ b/test/libapt/install_progress_test.cc
@@ -12,9 +12,14 @@ TEST(InstallProgressTest, FancyGetTextProgressStr)
EXPECT_EQ(60, p.GetTextProgressStr(0.5, 60).size());
EXPECT_EQ("[#.]", p.GetTextProgressStr(0.5, 4));
+ EXPECT_EQ("[..........]", p.GetTextProgressStr(0.0, 12));
EXPECT_EQ("[#.........]", p.GetTextProgressStr(0.1, 12));
+ EXPECT_EQ("[####......]", p.GetTextProgressStr(0.4999, 12));
+ EXPECT_EQ("[#####.....]", p.GetTextProgressStr(0.5001, 12));
EXPECT_EQ("[#########.]", p.GetTextProgressStr(0.9, 12));
+ EXPECT_EQ("[##########]", p.GetTextProgressStr(1.0, 12));
// deal with incorrect inputs gracefully (or should we die instead?)
- EXPECT_EQ("", p.GetTextProgressStr(-999, 12));
+ EXPECT_EQ("[..........]", p.GetTextProgressStr(-1.0, 12));
+ EXPECT_EQ("[##########]", p.GetTextProgressStr(2.0, 12));
}
diff --git a/test/libapt/srvrecs_test.cc b/test/libapt/srvrecs_test.cc
index b3fa8102d..5253b1c34 100644
--- a/test/libapt/srvrecs_test.cc
+++ b/test/libapt/srvrecs_test.cc
@@ -53,12 +53,19 @@ TEST(SrvRecTest,Randomness)
EXPECT_EQ(testLength*2, base2.size());
std::vector<SrvRec> first_pull;
+ auto const startingClock = clock();
for (unsigned int i = 0; i < testLength; ++i)
first_pull.push_back(PopFromSrvRecs(base1));
EXPECT_TRUE(base1.empty());
EXPECT_FALSE(first_pull.empty());
EXPECT_EQ(testLength, first_pull.size());
+ // busy-wait for a cpu-clock change as we use it as "random" value
+ if (startingClock != -1)
+ for (int i = 0; i < 100000; ++i)
+ if (startingClock != clock())
+ break;
+
std::vector<SrvRec> second_pull;
for (unsigned int i = 0; i < testLength; ++i)
second_pull.push_back(PopFromSrvRecs(base2));
@@ -69,7 +76,8 @@ TEST(SrvRecTest,Randomness)
EXPECT_EQ(first_pull.size(), second_pull.size());
EXPECT_TRUE(std::all_of(first_pull.begin(), first_pull.end(), [](SrvRec const &R) { return R.priority == 20; }));
EXPECT_TRUE(std::all_of(second_pull.begin(), second_pull.end(), [](SrvRec const &R) { return R.priority == 20; }));
- EXPECT_FALSE(std::equal(first_pull.begin(), first_pull.end(), second_pull.begin()));
+ if (startingClock != -1 && startingClock != clock())
+ EXPECT_FALSE(std::equal(first_pull.begin(), first_pull.end(), second_pull.begin()));
EXPECT_TRUE(std::all_of(base2.begin(), base2.end(), [](SrvRec const &R) { return R.priority == 30; }));
}
diff --git a/test/libapt/stringview_test.cc b/test/libapt/stringview_test.cc
index a4b7d77e3..f215287d9 100644
--- a/test/libapt/stringview_test.cc
+++ b/test/libapt/stringview_test.cc
@@ -34,26 +34,28 @@ TEST(StringViewTest,EmptyString)
TEST(StringViewTest,FooString)
{
- constexpr APT::StringView defString("foo", 3);
+ constexpr APT::StringView defString("fooGARBAGE", 3);
static_assert( 3 == defString.length(), "def right size");
- EXPECT_EQ(defString.to_string(), defString.data());
+ EXPECT_EQ(0, defString.to_string().compare(0, defString.length(), defString.data(), 3));
APT::StringView strString{std::string{"foo"}};
EXPECT_EQ(3, strString.length());
- EXPECT_EQ(strString.to_string(), strString.data());
+ EXPECT_EQ(0, strString.to_string().compare(0, strString.length(), strString.data(), 3));
- constexpr char const * const charp = "foo";
+ constexpr char const * const charp = "fooGARBAGE";
constexpr APT::StringView charpString{charp, 3};
- EXPECT_EQ( 3, charpString.length());
- EXPECT_EQ(charpString.to_string(), charpString.data());
+ EXPECT_EQ(3, charpString.length());
+ EXPECT_EQ(0, charpString.to_string().compare(0, charpString.length(), charpString.data(), 3));
- APT::StringView charp2String{charp};
+ char * charp2 = strdup("foo");
+ APT::StringView charp2String{charp2};
EXPECT_EQ(3, charp2String.length());
- EXPECT_EQ(charp2String.to_string(), charp2String.data());
+ EXPECT_EQ(0, charp2String.to_string().compare(0, charp2String.length(), charp2String.data(), 3));
+ free(charp2);
const APT::StringView charaString{"foo"};
EXPECT_EQ(3, charaString.length());
- EXPECT_EQ(charaString.to_string(), charaString.data());
+ EXPECT_EQ(0, charaString.to_string().compare(0, charaString.length(), charaString.data(), 3));
EXPECT_TRUE(APT::StringView("foo") == "foo");
EXPECT_FALSE(APT::StringView("foo") != "foo");