]> git.saurik.com Git - apt.git/blame - test/libapt/srvrecs_test.cc
use a less generic special trigger filename for stdin
[apt.git] / test / libapt / srvrecs_test.cc
CommitLineData
c29dbdff
MV
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
10TEST(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;
76abe9a5 15 for(size_t i = 0; i < 100; ++i)
c29dbdff
MV
16 {
17 std::vector<SrvRec> Meep;
76abe9a5
DK
18 Meep.emplace_back("foo", 20, 0, 80);
19 Meep.emplace_back("bar", 20, 0, 80);
20 Meep.emplace_back("baz", 30, 0, 80);
c29dbdff 21
76abe9a5
DK
22 EXPECT_EQ(Meep.size(), 3);
23 SrvRec const result = PopFromSrvRecs(Meep);
c29dbdff
MV
24 selected.insert(result.target);
25 // ensure that pop removed one element
76abe9a5
DK
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");
c29dbdff 32 EXPECT_EQ(Meep.size(), 1);
76abe9a5
DK
33
34 SrvRec const result3 = PopFromSrvRecs(Meep);
35 EXPECT_EQ(result3.target, "baz");
36 EXPECT_TRUE(Meep.empty());
c29dbdff
MV
37 }
38
39 // ensure that after enough runs we end up with both selected
40 EXPECT_EQ(selected.size(), 2);
41}