diff options
author | David Kalnischkies <david@kalnischkies.de> | 2015-03-15 22:34:54 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2015-04-10 22:29:08 +0200 |
commit | dfad5beea77d75983f6ff8a1b8296b74dd48203e (patch) | |
tree | 405a6e037cd162ec45b9757b826619a9d5f9f597 /test/libapt | |
parent | b8eba208daebe3e3f235983e44da9c398d6f7a57 (diff) |
add a simple unit test for acquire progress
This isn't testing much of the 'complex' parts,
but its better than nothing for now.
Git-Dch: Ignore
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/acqprogress_test.cc | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/test/libapt/acqprogress_test.cc b/test/libapt/acqprogress_test.cc new file mode 100644 index 000000000..288e05aca --- /dev/null +++ b/test/libapt/acqprogress_test.cc @@ -0,0 +1,170 @@ +#include <config.h> +#include <apt-pkg/acquire.h> +#include <apt-pkg/acquire-item.h> +#include <apt-pkg/configuration.h> +#include <apt-private/acqprogress.h> +#include <string> +#include <sstream> +#include <gtest/gtest.h> + +class TestItem: public pkgAcquire::Item +{ +public: + TestItem(pkgAcquire * const Acq) : pkgAcquire::Item(Acq, "", NULL) {} + + virtual std::string DescURI() { return ""; } + +}; + +TEST(AcqProgress, IMSHit) +{ + std::ostringstream out; + unsigned int width = 80; + AcqTextStatus Stat(out, width, 0); + Stat.Start(); + + pkgAcquire::ItemDesc hit; + hit.URI = "http://example.org/file"; + hit.Description = "Example File from example.org"; + hit.ShortDesc = "Example File"; + hit.Owner = NULL; + + EXPECT_EQ("", out.str()); + Stat.IMSHit(hit); + EXPECT_EQ("Hit Example File from example.org\n", out.str()); + Stat.IMSHit(hit); + EXPECT_EQ("Hit Example File from example.org\n" + "Hit Example File from example.org\n", out.str()); + Stat.Stop(); + EXPECT_EQ("Hit Example File from example.org\n" + "Hit 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:2 Example File from example.org\n", out.str()); + Stat.Stop(); + EXPECT_EQ("Get:1 Example File from example.org\n" + "Get:2 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:2 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:2 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("", out.str()); + fetchO.Status = pkgAcquire::Item::StatDone; + Stat.Fail(fetch); + EXPECT_EQ("Ign Example File from example.org\n", out.str()); + fetchO.Status = pkgAcquire::Item::StatError; + fetchO.ErrorText = "An error test!"; + Stat.Fail(fetch); + EXPECT_EQ("Ign Example File from example.org\n" + "Err 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 Example File from example.org\n" + "Err Example File from example.org\n" + " An error test!\n" + "Ign Example File from example.org\n" + " An error test!\n", out.str()); + _config->Set("Acquire::Progress::Ignore::ShowErrorText", true); + Stat.Stop(); + EXPECT_EQ("Ign Example File from example.org\n" + "Err Example File from example.org\n" + " An error test!\n" + "Ign 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()); +} |