]> git.saurik.com Git - apt.git/blame - test/libapt/acqprogress_test.cc
don't try other compressions on hashsum mismatch
[apt.git] / test / libapt / acqprogress_test.cc
CommitLineData
dfad5bee
DK
1#include <config.h>
2#include <apt-pkg/acquire.h>
3#include <apt-pkg/acquire-item.h>
4#include <apt-pkg/configuration.h>
5#include <apt-private/acqprogress.h>
6#include <string>
7#include <sstream>
8#include <gtest/gtest.h>
9
10class TestItem: public pkgAcquire::Item
11{
12public:
13 TestItem(pkgAcquire * const Acq) : pkgAcquire::Item(Acq, "", NULL) {}
14
15 virtual std::string DescURI() { return ""; }
16
17};
18
19TEST(AcqProgress, IMSHit)
20{
21 std::ostringstream out;
22 unsigned int width = 80;
23 AcqTextStatus Stat(out, width, 0);
24 Stat.Start();
25
26 pkgAcquire::ItemDesc hit;
27 hit.URI = "http://example.org/file";
28 hit.Description = "Example File from example.org";
29 hit.ShortDesc = "Example File";
30 hit.Owner = NULL;
31
32 EXPECT_EQ("", out.str());
33 Stat.IMSHit(hit);
34 EXPECT_EQ("Hit Example File from example.org\n", out.str());
35 Stat.IMSHit(hit);
36 EXPECT_EQ("Hit Example File from example.org\n"
37 "Hit Example File from example.org\n", out.str());
38 Stat.Stop();
39 EXPECT_EQ("Hit Example File from example.org\n"
40 "Hit Example File from example.org\n", out.str());
41}
42TEST(AcqProgress, FetchNoFileSize)
43{
44 std::ostringstream out;
45 unsigned int width = 80;
46 AcqTextStatus Stat(out, width, 0);
47 Stat.Start();
48
49 pkgAcquire Acq(&Stat);
50 pkgAcquire::ItemDesc fetch;
51 fetch.URI = "http://example.org/file";
52 fetch.Description = "Example File from example.org";
53 fetch.ShortDesc = "Example File";
54 TestItem fetchO(&Acq);
55 fetch.Owner = &fetchO;
56
57 EXPECT_EQ("", out.str());
58 Stat.Fetch(fetch);
59 EXPECT_EQ("Get:1 Example File from example.org\n", out.str());
60 Stat.Fetch(fetch);
61 EXPECT_EQ("Get:1 Example File from example.org\n"
62 "Get:2 Example File from example.org\n", out.str());
63 Stat.Stop();
64 EXPECT_EQ("Get:1 Example File from example.org\n"
65 "Get:2 Example File from example.org\n", out.str());
66}
67TEST(AcqProgress, FetchFileSize)
68{
69 std::ostringstream out;
70 unsigned int width = 80;
71 AcqTextStatus Stat(out, width, 0);
72 Stat.Start();
73
74 pkgAcquire Acq(&Stat);
75 pkgAcquire::ItemDesc fetch;
76 fetch.URI = "http://example.org/file";
77 fetch.Description = "Example File from example.org";
78 fetch.ShortDesc = "Example File";
79 TestItem fetchO(&Acq);
80 fetchO.FileSize = 100;
81 fetch.Owner = &fetchO;
82
83 EXPECT_EQ("", out.str());
84 Stat.Fetch(fetch);
85 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n", out.str());
86 fetchO.FileSize = 42;
87 Stat.Fetch(fetch);
88 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
89 "Get:2 Example File from example.org [42 B]\n", out.str());
90 Stat.Stop();
91 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
92 "Get:2 Example File from example.org [42 B]\n", out.str());
93}
94TEST(AcqProgress, Fail)
95{
96 std::ostringstream out;
97 unsigned int width = 80;
98 AcqTextStatus Stat(out, width, 0);
99 Stat.Start();
100
101 pkgAcquire Acq(&Stat);
102 pkgAcquire::ItemDesc fetch;
103 fetch.URI = "http://example.org/file";
104 fetch.Description = "Example File from example.org";
105 fetch.ShortDesc = "Example File";
106 TestItem fetchO(&Acq);
107 fetchO.FileSize = 100;
108 fetchO.Status = pkgAcquire::Item::StatIdle;
109 fetch.Owner = &fetchO;
110
111 EXPECT_EQ("", out.str());
112 Stat.Fail(fetch);
113 EXPECT_EQ("", out.str());
114 fetchO.Status = pkgAcquire::Item::StatDone;
115 Stat.Fail(fetch);
116 EXPECT_EQ("Ign Example File from example.org\n", out.str());
117 fetchO.Status = pkgAcquire::Item::StatError;
118 fetchO.ErrorText = "An error test!";
119 Stat.Fail(fetch);
120 EXPECT_EQ("Ign Example File from example.org\n"
121 "Err Example File from example.org\n"
122 " An error test!\n", out.str());
123 _config->Set("Acquire::Progress::Ignore::ShowErrorText", true);
124 fetchO.Status = pkgAcquire::Item::StatDone;
125 Stat.Fail(fetch);
126 EXPECT_EQ("Ign Example File from example.org\n"
127 "Err Example File from example.org\n"
128 " An error test!\n"
129 "Ign Example File from example.org\n"
130 " An error test!\n", out.str());
131 _config->Set("Acquire::Progress::Ignore::ShowErrorText", true);
132 Stat.Stop();
133 EXPECT_EQ("Ign Example File from example.org\n"
134 "Err Example File from example.org\n"
135 " An error test!\n"
136 "Ign Example File from example.org\n"
137 " An error test!\n", out.str());
138}
139TEST(AcqProgress, Pulse)
140{
141 std::ostringstream out;
142 unsigned int width = 80;
143 AcqTextStatus Stat(out, width, 0);
144 _config->Set("APT::Sandbox::User", ""); // ensure we aren't sandboxing
145
146 pkgAcquire Acq(&Stat);
147 pkgAcquire::ItemDesc fetch;
148 fetch.URI = "http://example.org/file";
149 fetch.Description = "Example File from example.org";
150 fetch.ShortDesc = "Example File";
151 TestItem fetchO(&Acq);
152 fetchO.FileSize = 100;
153 fetchO.Status = pkgAcquire::Item::StatFetching;
154 fetch.Owner = &fetchO;
155
156 // make screen smaller and bigger again while running
157 EXPECT_TRUE(Stat.Pulse(&Acq));
158 EXPECT_EQ("\r0% [Working]", out.str());
159 width = 8;
160 EXPECT_TRUE(Stat.Pulse(&Acq));
161 EXPECT_EQ("\r0% [Working]"
162 "\r "
163 "\r0% [Work", out.str());
164 width = 80;
165 EXPECT_TRUE(Stat.Pulse(&Acq));
166 EXPECT_EQ("\r0% [Working]"
167 "\r "
168 "\r0% [Work"
169 "\r0% [Working]", out.str());
170}