]>
git.saurik.com Git - apt.git/blob - test/libapt/acqprogress_test.cc
2 #include <apt-pkg/hashes.h>
3 #include <apt-pkg/acquire.h>
4 #include <apt-pkg/acquire-item.h>
5 #include <apt-pkg/configuration.h>
6 #include <apt-private/acqprogress.h>
9 #include <gtest/gtest.h>
11 class TestItem
: public pkgAcquire::Item
14 TestItem(pkgAcquire
* const Acq
) : pkgAcquire::Item(Acq
) {}
16 virtual std::string
DescURI() const APT_OVERRIDE
{ return ""; }
17 virtual HashStringList
GetExpectedHashes() const APT_OVERRIDE
{ return HashStringList(); }
21 TEST(AcqProgress
, IMSHit
)
23 std::ostringstream out
;
24 unsigned int width
= 80;
25 AcqTextStatus
Stat(out
, width
, 0);
28 pkgAcquire
Acq(&Stat
);
29 pkgAcquire::ItemDesc hit
;
30 hit
.URI
= "http://example.org/file";
31 hit
.Description
= "Example File from example.org";
32 hit
.ShortDesc
= "Example File";
36 EXPECT_EQ("", out
.str());
38 EXPECT_EQ("Hit:1 Example File from example.org\n", out
.str());
40 EXPECT_EQ("Hit:1 Example File from example.org\n"
41 "Hit:1 Example File from example.org\n", out
.str());
43 EXPECT_EQ("Hit:1 Example File from example.org\n"
44 "Hit:1 Example File from example.org\n", out
.str());
46 TEST(AcqProgress
, FetchNoFileSize
)
48 std::ostringstream out
;
49 unsigned int width
= 80;
50 AcqTextStatus
Stat(out
, width
, 0);
53 pkgAcquire
Acq(&Stat
);
54 pkgAcquire::ItemDesc fetch
;
55 fetch
.URI
= "http://example.org/file";
56 fetch
.Description
= "Example File from example.org";
57 fetch
.ShortDesc
= "Example File";
58 TestItem
fetchO(&Acq
);
59 fetch
.Owner
= &fetchO
;
61 EXPECT_EQ("", out
.str());
63 EXPECT_EQ("Get:1 Example File from example.org\n", out
.str());
65 EXPECT_EQ("Get:1 Example File from example.org\n"
66 "Get:1 Example File from example.org\n", out
.str());
68 EXPECT_EQ("Get:1 Example File from example.org\n"
69 "Get:1 Example File from example.org\n", out
.str());
71 TEST(AcqProgress
, FetchFileSize
)
73 std::ostringstream out
;
74 unsigned int width
= 80;
75 AcqTextStatus
Stat(out
, width
, 0);
78 pkgAcquire
Acq(&Stat
);
79 pkgAcquire::ItemDesc fetch
;
80 fetch
.URI
= "http://example.org/file";
81 fetch
.Description
= "Example File from example.org";
82 fetch
.ShortDesc
= "Example File";
83 TestItem
fetchO(&Acq
);
84 fetchO
.FileSize
= 100;
85 fetch
.Owner
= &fetchO
;
87 EXPECT_EQ("", out
.str());
89 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n", out
.str());
92 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
93 "Get:1 Example File from example.org [42 B]\n", out
.str());
95 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
96 "Get:1 Example File from example.org [42 B]\n", out
.str());
98 TEST(AcqProgress
, Fail
)
100 std::ostringstream out
;
101 unsigned int width
= 80;
102 AcqTextStatus
Stat(out
, width
, 0);
105 pkgAcquire
Acq(&Stat
);
106 pkgAcquire::ItemDesc fetch
;
107 fetch
.URI
= "http://example.org/file";
108 fetch
.Description
= "Example File from example.org";
109 fetch
.ShortDesc
= "Example File";
110 TestItem
fetchO(&Acq
);
111 fetchO
.FileSize
= 100;
112 fetchO
.Status
= pkgAcquire::Item::StatIdle
;
113 fetch
.Owner
= &fetchO
;
115 EXPECT_EQ("", out
.str());
117 EXPECT_EQ("Ign:1 Example File from example.org\n", out
.str());
118 fetchO
.Status
= pkgAcquire::Item::StatDone
;
120 EXPECT_EQ("Ign:1 Example File from example.org\n"
121 "Ign:1 Example File from example.org\n", out
.str());
122 fetchO
.Status
= pkgAcquire::Item::StatError
;
123 fetchO
.ErrorText
= "An error test!";
125 EXPECT_EQ("Ign:1 Example File from example.org\n"
126 "Ign:1 Example File from example.org\n"
127 "Err:1 Example File from example.org\n"
128 " An error test!\n", out
.str());
129 _config
->Set("Acquire::Progress::Ignore::ShowErrorText", true);
130 fetchO
.Status
= pkgAcquire::Item::StatDone
;
132 EXPECT_EQ("Ign:1 Example File from example.org\n"
133 "Ign:1 Example File from example.org\n"
134 "Err:1 Example File from example.org\n"
136 "Ign:1 Example File from example.org\n"
137 " An error test!\n", out
.str());
138 _config
->Set("Acquire::Progress::Ignore::ShowErrorText", true);
140 EXPECT_EQ("Ign:1 Example File from example.org\n"
141 "Ign:1 Example File from example.org\n"
142 "Err:1 Example File from example.org\n"
144 "Ign:1 Example File from example.org\n"
145 " An error test!\n", out
.str());
147 TEST(AcqProgress
, Pulse
)
149 std::ostringstream out
;
150 unsigned int width
= 80;
151 AcqTextStatus
Stat(out
, width
, 0);
152 _config
->Set("APT::Sandbox::User", ""); // ensure we aren't sandboxing
154 pkgAcquire
Acq(&Stat
);
155 pkgAcquire::ItemDesc fetch
;
156 fetch
.URI
= "http://example.org/file";
157 fetch
.Description
= "Example File from example.org";
158 fetch
.ShortDesc
= "Example File";
159 TestItem
fetchO(&Acq
);
160 fetchO
.FileSize
= 100;
161 fetchO
.Status
= pkgAcquire::Item::StatFetching
;
162 fetch
.Owner
= &fetchO
;
164 // make screen smaller and bigger again while running
165 EXPECT_TRUE(Stat
.Pulse(&Acq
));
166 EXPECT_EQ("\r0% [Working]", out
.str());
168 EXPECT_TRUE(Stat
.Pulse(&Acq
));
169 EXPECT_EQ("\r0% [Working]"
171 "\r0% [Work", out
.str());
173 EXPECT_TRUE(Stat
.Pulse(&Acq
));
174 EXPECT_EQ("\r0% [Working]"
177 "\r0% [Working]", out
.str());