]>
Commit | Line | Data |
---|---|---|
1 | #include <config.h> | |
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> | |
7 | #include <string> | |
8 | #include <sstream> | |
9 | #include <gtest/gtest.h> | |
10 | ||
11 | class TestItem: public pkgAcquire::Item | |
12 | { | |
13 | public: | |
14 | explicit TestItem(pkgAcquire * const Acq) : pkgAcquire::Item(Acq) {} | |
15 | ||
16 | virtual std::string DescURI() const APT_OVERRIDE { return ""; } | |
17 | virtual HashStringList GetExpectedHashes() const APT_OVERRIDE { return HashStringList(); } | |
18 | ||
19 | }; | |
20 | ||
21 | TEST(AcqProgress, IMSHit) | |
22 | { | |
23 | std::ostringstream out; | |
24 | unsigned int width = 80; | |
25 | AcqTextStatus Stat(out, width, 0); | |
26 | Stat.Start(); | |
27 | ||
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"; | |
33 | TestItem hitO(&Acq); | |
34 | hit.Owner = &hitO; | |
35 | ||
36 | EXPECT_EQ("", out.str()); | |
37 | Stat.IMSHit(hit); | |
38 | EXPECT_EQ("Hit:1 Example File from example.org\n", out.str()); | |
39 | Stat.IMSHit(hit); | |
40 | EXPECT_EQ("Hit:1 Example File from example.org\n" | |
41 | "Hit:1 Example File from example.org\n", out.str()); | |
42 | Stat.Stop(); | |
43 | EXPECT_EQ("Hit:1 Example File from example.org\n" | |
44 | "Hit:1 Example File from example.org\n", out.str()); | |
45 | } | |
46 | TEST(AcqProgress, FetchNoFileSize) | |
47 | { | |
48 | std::ostringstream out; | |
49 | unsigned int width = 80; | |
50 | AcqTextStatus Stat(out, width, 0); | |
51 | Stat.Start(); | |
52 | ||
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; | |
60 | ||
61 | EXPECT_EQ("", out.str()); | |
62 | Stat.Fetch(fetch); | |
63 | EXPECT_EQ("Get:1 Example File from example.org\n", out.str()); | |
64 | Stat.Fetch(fetch); | |
65 | EXPECT_EQ("Get:1 Example File from example.org\n" | |
66 | "Get:1 Example File from example.org\n", out.str()); | |
67 | Stat.Stop(); | |
68 | EXPECT_EQ("Get:1 Example File from example.org\n" | |
69 | "Get:1 Example File from example.org\n", out.str()); | |
70 | } | |
71 | TEST(AcqProgress, FetchFileSize) | |
72 | { | |
73 | std::ostringstream out; | |
74 | unsigned int width = 80; | |
75 | AcqTextStatus Stat(out, width, 0); | |
76 | Stat.Start(); | |
77 | ||
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; | |
86 | ||
87 | EXPECT_EQ("", out.str()); | |
88 | Stat.Fetch(fetch); | |
89 | EXPECT_EQ("Get:1 Example File from example.org [100 B]\n", out.str()); | |
90 | fetchO.FileSize = 42; | |
91 | Stat.Fetch(fetch); | |
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()); | |
94 | Stat.Stop(); | |
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()); | |
97 | } | |
98 | TEST(AcqProgress, Fail) | |
99 | { | |
100 | std::ostringstream out; | |
101 | unsigned int width = 80; | |
102 | AcqTextStatus Stat(out, width, 0); | |
103 | Stat.Start(); | |
104 | ||
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; | |
114 | ||
115 | EXPECT_EQ("", out.str()); | |
116 | Stat.Fail(fetch); | |
117 | EXPECT_EQ("Ign:1 Example File from example.org\n", out.str()); | |
118 | fetchO.Status = pkgAcquire::Item::StatDone; | |
119 | Stat.Fail(fetch); | |
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!"; | |
124 | Stat.Fail(fetch); | |
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; | |
131 | Stat.Fail(fetch); | |
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" | |
135 | " An error test!\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); | |
139 | Stat.Stop(); | |
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" | |
143 | " An error test!\n" | |
144 | "Ign:1 Example File from example.org\n" | |
145 | " An error test!\n", out.str()); | |
146 | } | |
147 | TEST(AcqProgress, Pulse) | |
148 | { | |
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 | |
153 | ||
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; | |
163 | ||
164 | // make screen smaller and bigger again while running | |
165 | EXPECT_TRUE(Stat.Pulse(&Acq)); | |
166 | EXPECT_EQ("\r0% [Working]", out.str()); | |
167 | width = 8; | |
168 | EXPECT_TRUE(Stat.Pulse(&Acq)); | |
169 | EXPECT_EQ("\r0% [Working]" | |
170 | "\r " | |
171 | "\r0% [Work", out.str()); | |
172 | width = 80; | |
173 | EXPECT_TRUE(Stat.Pulse(&Acq)); | |
174 | EXPECT_EQ("\r0% [Working]" | |
175 | "\r " | |
176 | "\r0% [Work" | |
177 | "\r0% [Working]", out.str()); | |
178 | } |