]>
git.saurik.com Git - apt.git/blob - test/libapt/acqprogress_test.cc
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>
8 #include <gtest/gtest.h>
10 class TestItem
: public pkgAcquire::Item
13 TestItem(pkgAcquire
* const Acq
) : pkgAcquire::Item(Acq
, "", NULL
) {}
15 virtual std::string
DescURI() { return ""; }
19 TEST(AcqProgress
, IMSHit
)
21 std::ostringstream out
;
22 unsigned int width
= 80;
23 AcqTextStatus
Stat(out
, width
, 0);
26 pkgAcquire::ItemDesc hit
;
27 hit
.URI
= "http://example.org/file";
28 hit
.Description
= "Example File from example.org";
29 hit
.ShortDesc
= "Example File";
32 EXPECT_EQ("", out
.str());
34 EXPECT_EQ("Hit Example File from example.org\n", out
.str());
36 EXPECT_EQ("Hit Example File from example.org\n"
37 "Hit Example File from example.org\n", out
.str());
39 EXPECT_EQ("Hit Example File from example.org\n"
40 "Hit Example File from example.org\n", out
.str());
42 TEST(AcqProgress
, FetchNoFileSize
)
44 std::ostringstream out
;
45 unsigned int width
= 80;
46 AcqTextStatus
Stat(out
, width
, 0);
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
;
57 EXPECT_EQ("", out
.str());
59 EXPECT_EQ("Get:1 Example File from example.org\n", out
.str());
61 EXPECT_EQ("Get:1 Example File from example.org\n"
62 "Get:2 Example File from example.org\n", out
.str());
64 EXPECT_EQ("Get:1 Example File from example.org\n"
65 "Get:2 Example File from example.org\n", out
.str());
67 TEST(AcqProgress
, FetchFileSize
)
69 std::ostringstream out
;
70 unsigned int width
= 80;
71 AcqTextStatus
Stat(out
, width
, 0);
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
;
83 EXPECT_EQ("", out
.str());
85 EXPECT_EQ("Get:1 Example File from example.org [100 B]\n", out
.str());
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());
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());
94 TEST(AcqProgress
, Fail
)
96 std::ostringstream out
;
97 unsigned int width
= 80;
98 AcqTextStatus
Stat(out
, width
, 0);
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
;
111 EXPECT_EQ("", out
.str());
113 EXPECT_EQ("", out
.str());
114 fetchO
.Status
= pkgAcquire::Item::StatDone
;
116 EXPECT_EQ("Ign Example File from example.org\n", out
.str());
117 fetchO
.Status
= pkgAcquire::Item::StatError
;
118 fetchO
.ErrorText
= "An error test!";
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
;
126 EXPECT_EQ("Ign Example File from example.org\n"
127 "Err Example File from example.org\n"
129 "Ign Example File from example.org\n"
130 " An error test!\n", out
.str());
131 _config
->Set("Acquire::Progress::Ignore::ShowErrorText", true);
133 EXPECT_EQ("Ign Example File from example.org\n"
134 "Err Example File from example.org\n"
136 "Ign Example File from example.org\n"
137 " An error test!\n", out
.str());
139 TEST(AcqProgress
, Pulse
)
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
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
;
156 // make screen smaller and bigger again while running
157 EXPECT_TRUE(Stat
.Pulse(&Acq
));
158 EXPECT_EQ("\r0% [Working]", out
.str());
160 EXPECT_TRUE(Stat
.Pulse(&Acq
));
161 EXPECT_EQ("\r0% [Working]"
163 "\r0% [Work", out
.str());
165 EXPECT_TRUE(Stat
.Pulse(&Acq
));
166 EXPECT_EQ("\r0% [Working]"
169 "\r0% [Working]", out
.str());