]>
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 { return ""; }
17 virtual HashStringList
GetExpectedHashes() const { return HashStringList(); }
21 TEST(AcqProgress
, IMSHit
)
23 std::ostringstream out
;
24 unsigned int width
= 80;
25 AcqTextStatus
Stat(out
, width
, 0);
28 pkgAcquire::ItemDesc hit
;
29 hit
.URI
= "http://example.org/file";
30 hit
.Description
= "Example File from example.org";
31 hit
.ShortDesc
= "Example File";
34 EXPECT_EQ("", out
.str());
36 EXPECT_EQ("Hit Example File from example.org\n", out
.str());
38 EXPECT_EQ("Hit Example File from example.org\n"
39 "Hit Example File from example.org\n", out
.str());
41 EXPECT_EQ("Hit Example File from example.org\n"
42 "Hit Example File from example.org\n", out
.str());
44 TEST(AcqProgress
, FetchNoFileSize
)
46 std::ostringstream out
;
47 unsigned int width
= 80;
48 AcqTextStatus
Stat(out
, width
, 0);
51 pkgAcquire
Acq(&Stat
);
52 pkgAcquire::ItemDesc fetch
;
53 fetch
.URI
= "http://example.org/file";
54 fetch
.Description
= "Example File from example.org";
55 fetch
.ShortDesc
= "Example File";
56 TestItem
fetchO(&Acq
);
57 fetch
.Owner
= &fetchO
;
59 EXPECT_EQ("", out
.str());
61 EXPECT_EQ("Get:1 Example File from example.org\n", out
.str());
63 EXPECT_EQ("Get:1 Example File from example.org\n"
64 "Get:2 Example File from example.org\n", out
.str());
66 EXPECT_EQ("Get:1 Example File from example.org\n"
67 "Get:2 Example File from example.org\n", out
.str());
69 TEST(AcqProgress
, FetchFileSize
)
71 std::ostringstream out
;
72 unsigned int width
= 80;
73 AcqTextStatus
Stat(out
, width
, 0);
76 pkgAcquire
Acq(&Stat
);
77 pkgAcquire::ItemDesc fetch
;
78 fetch
.URI
= "http://example.org/file";
79 fetch
.Description
= "Example File from example.org";
80 fetch
.ShortDesc
= "Example File";
81 TestItem
fetchO(&Acq
);
82 fetchO
.FileSize
= 100;
83 fetch
.Owner
= &fetchO
;
85 EXPECT_EQ("", out
.str());
87 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n", out
.str());
90 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
91 "Get:2 Example File from example.org [42 B]\n", out
.str());
93 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n"
94 "Get:2 Example File from example.org [42 B]\n", out
.str());
96 TEST(AcqProgress
, Fail
)
98 std::ostringstream out
;
99 unsigned int width
= 80;
100 AcqTextStatus
Stat(out
, width
, 0);
103 pkgAcquire
Acq(&Stat
);
104 pkgAcquire::ItemDesc fetch
;
105 fetch
.URI
= "http://example.org/file";
106 fetch
.Description
= "Example File from example.org";
107 fetch
.ShortDesc
= "Example File";
108 TestItem
fetchO(&Acq
);
109 fetchO
.FileSize
= 100;
110 fetchO
.Status
= pkgAcquire::Item::StatIdle
;
111 fetch
.Owner
= &fetchO
;
113 EXPECT_EQ("", out
.str());
115 EXPECT_EQ("", out
.str());
116 fetchO
.Status
= pkgAcquire::Item::StatDone
;
118 EXPECT_EQ("Ign Example File from example.org\n", out
.str());
119 fetchO
.Status
= pkgAcquire::Item::StatError
;
120 fetchO
.ErrorText
= "An error test!";
122 EXPECT_EQ("Ign Example File from example.org\n"
123 "Err Example File from example.org\n"
124 " An error test!\n", out
.str());
125 _config
->Set("Acquire::Progress::Ignore::ShowErrorText", true);
126 fetchO
.Status
= pkgAcquire::Item::StatDone
;
128 EXPECT_EQ("Ign Example File from example.org\n"
129 "Err Example File from example.org\n"
131 "Ign Example File from example.org\n"
132 " An error test!\n", out
.str());
133 _config
->Set("Acquire::Progress::Ignore::ShowErrorText", true);
135 EXPECT_EQ("Ign Example File from example.org\n"
136 "Err Example File from example.org\n"
138 "Ign Example File from example.org\n"
139 " An error test!\n", out
.str());
141 TEST(AcqProgress
, Pulse
)
143 std::ostringstream out
;
144 unsigned int width
= 80;
145 AcqTextStatus
Stat(out
, width
, 0);
146 _config
->Set("APT::Sandbox::User", ""); // ensure we aren't sandboxing
148 pkgAcquire
Acq(&Stat
);
149 pkgAcquire::ItemDesc fetch
;
150 fetch
.URI
= "http://example.org/file";
151 fetch
.Description
= "Example File from example.org";
152 fetch
.ShortDesc
= "Example File";
153 TestItem
fetchO(&Acq
);
154 fetchO
.FileSize
= 100;
155 fetchO
.Status
= pkgAcquire::Item::StatFetching
;
156 fetch
.Owner
= &fetchO
;
158 // make screen smaller and bigger again while running
159 EXPECT_TRUE(Stat
.Pulse(&Acq
));
160 EXPECT_EQ("\r0% [Working]", out
.str());
162 EXPECT_TRUE(Stat
.Pulse(&Acq
));
163 EXPECT_EQ("\r0% [Working]"
165 "\r0% [Work", out
.str());
167 EXPECT_TRUE(Stat
.Pulse(&Acq
));
168 EXPECT_EQ("\r0% [Working]"
171 "\r0% [Working]", out
.str());