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