]> git.saurik.com Git - apt.git/blob - test/libapt/srvrecs_test.cc
Ensure that no by-hash file for "Release/InRelease is written"
[apt.git] / test / libapt / srvrecs_test.cc
1 #include <config.h>
2
3 #include <apt-pkg/srvrec.h>
4
5 #include <string>
6 #include <iostream>
7
8 #include <gtest/gtest.h>
9
10 TEST(SrvRecTest, PopFromSrvRecs)
11 {
12 // the PopFromSrvRecs() is using a random number so we must
13 // run it a bunch of times to ensure we are not fooled by randomness
14 std::set<std::string> selected;
15 for(size_t i = 0; i < 100; ++i)
16 {
17 std::vector<SrvRec> Meep;
18 Meep.emplace_back("foo", 20, 0, 80);
19 Meep.emplace_back("bar", 20, 0, 80);
20 Meep.emplace_back("baz", 30, 0, 80);
21
22 EXPECT_EQ(Meep.size(), 3);
23 SrvRec const result = PopFromSrvRecs(Meep);
24 selected.insert(result.target);
25 // ensure that pop removed one element
26 EXPECT_EQ(Meep.size(), 2);
27 EXPECT_NE(result.target, "baz");
28
29 SrvRec const result2 = PopFromSrvRecs(Meep);
30 EXPECT_NE(result.target, result2.target);
31 EXPECT_NE(result2.target, "baz");
32 EXPECT_EQ(Meep.size(), 1);
33
34 SrvRec const result3 = PopFromSrvRecs(Meep);
35 EXPECT_EQ(result3.target, "baz");
36 EXPECT_TRUE(Meep.empty());
37 }
38
39 // ensure that after enough runs we end up with both selected
40 EXPECT_EQ(selected.size(), 2);
41 }