]> git.saurik.com Git - apt.git/blame - test/libapt/acqprogress_test.cc
allow spaces in fingerprints for 'apt-key del'
[apt.git] / test / libapt / acqprogress_test.cc
CommitLineData
dfad5bee 1#include <config.h>
448c38bd 2#include <apt-pkg/hashes.h>
dfad5bee
DK
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
11class TestItem: public pkgAcquire::Item
12{
13public:
258b9e51 14 explicit TestItem(pkgAcquire * const Acq) : pkgAcquire::Item(Acq) {}
dfad5bee 15
3b302846
DK
16 virtual std::string DescURI() const APT_OVERRIDE { return ""; }
17 virtual HashStringList GetExpectedHashes() const APT_OVERRIDE { return HashStringList(); }
dfad5bee
DK
18
19};
20
21TEST(AcqProgress, IMSHit)
22{
23 std::ostringstream out;
24 unsigned int width = 80;
25 AcqTextStatus Stat(out, width, 0);
26 Stat.Start();
27
c8a4ce6c 28 pkgAcquire Acq(&Stat);
dfad5bee
DK
29 pkgAcquire::ItemDesc hit;
30 hit.URI = "http://example.org/file";
31 hit.Description = "Example File from example.org";
32 hit.ShortDesc = "Example File";
c8a4ce6c
DK
33 TestItem hitO(&Acq);
34 hit.Owner = &hitO;
dfad5bee
DK
35
36 EXPECT_EQ("", out.str());
37 Stat.IMSHit(hit);
c8a4ce6c 38 EXPECT_EQ("Hit:1 Example File from example.org\n", out.str());
dfad5bee 39 Stat.IMSHit(hit);
c8a4ce6c
DK
40 EXPECT_EQ("Hit:1 Example File from example.org\n"
41 "Hit:1 Example File from example.org\n", out.str());
dfad5bee 42 Stat.Stop();
c8a4ce6c
DK
43 EXPECT_EQ("Hit:1 Example File from example.org\n"
44 "Hit:1 Example File from example.org\n", out.str());
dfad5bee
DK
45}
46TEST(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"
c8a4ce6c 66 "Get:1 Example File from example.org\n", out.str());
dfad5bee
DK
67 Stat.Stop();
68 EXPECT_EQ("Get:1 Example File from example.org\n"
c8a4ce6c 69 "Get:1 Example File from example.org\n", out.str());
dfad5bee
DK
70}
71TEST(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"
c8a4ce6c 93 "Get:1 Example File from example.org [42 B]\n", out.str());
dfad5bee
DK
94 Stat.Stop();
95 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
c8a4ce6c 96 "Get:1 Example File from example.org [42 B]\n", out.str());
dfad5bee
DK
97}
98TEST(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);
c8a4ce6c 117 EXPECT_EQ("Ign:1 Example File from example.org\n", out.str());
dfad5bee
DK
118 fetchO.Status = pkgAcquire::Item::StatDone;
119 Stat.Fail(fetch);
c8a4ce6c
DK
120 EXPECT_EQ("Ign:1 Example File from example.org\n"
121 "Ign:1 Example File from example.org\n", out.str());
dfad5bee
DK
122 fetchO.Status = pkgAcquire::Item::StatError;
123 fetchO.ErrorText = "An error test!";
124 Stat.Fail(fetch);
c8a4ce6c
DK
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"
dfad5bee
DK
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);
c8a4ce6c
DK
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"
dfad5bee 135 " An error test!\n"
c8a4ce6c 136 "Ign:1 Example File from example.org\n"
dfad5bee
DK
137 " An error test!\n", out.str());
138 _config->Set("Acquire::Progress::Ignore::ShowErrorText", true);
139 Stat.Stop();
c8a4ce6c
DK
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"
dfad5bee 143 " An error test!\n"
c8a4ce6c 144 "Ign:1 Example File from example.org\n"
dfad5bee
DK
145 " An error test!\n", out.str());
146}
147TEST(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}