From 4234d90d58b684824bf217d9226c50b7c9583346 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 5 Nov 2014 18:14:04 +0100 Subject: tests: silence clang on uninitilized variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The testcases have far worse problems if these ever end up being NULL and/or are not given a value by the method called, but clang is right to warn about it, just that we don't want to fix it in testcases… Git-Dch: Ignore --- test/libapt/cdrom_test.cc | 3 ++- test/libapt/sourcelist_test.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'test/libapt') diff --git a/test/libapt/cdrom_test.cc b/test/libapt/cdrom_test.cc index 5cf3b353c..7257eaf1b 100644 --- a/test/libapt/cdrom_test.cc +++ b/test/libapt/cdrom_test.cc @@ -109,6 +109,7 @@ TEST(CDROMTest, FindMountPointForDevice) EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1")); EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs")); - unlink(tempfile); + if (tempfile != NULL) + unlink(tempfile); free(tempfile); } diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc index eb2d76c43..747ab4957 100644 --- a/test/libapt/sourcelist_test.cc +++ b/test/libapt/sourcelist_test.cc @@ -20,7 +20,7 @@ class SourceList : public pkgSourceList { TEST(SourceListTest,ParseFileDeb822) { FileFd fd; - char * tempfile; + char * tempfile = NULL; createTemporaryFile("parsefiledeb822", fd, &tempfile, "Types: deb\n" "URIs: http://ftp.debian.org/debian\n" -- cgit v1.2.3 From ad5ffe1ffb203eb58e5e25fe6f4c0dabc53253c9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 5 Nov 2014 18:42:56 +0100 Subject: Division by result of sizeof(). memset() expects a size in bytes "did you intend to multiply instead?" is what cppcheck helpful says and it is absolutely right. Doesn't make a whole lot of a difference though as we are talking about 'char' in this testcase, but just to be sure. Reported-By: cppcheck Git-Dch: Ignore --- test/libapt/fileutl_test.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test/libapt') diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc index 8d47c5098..57d5bbdc2 100644 --- a/test/libapt/fileutl_test.cc +++ b/test/libapt/fileutl_test.cc @@ -53,11 +53,16 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission // ensure the memory is as predictably messed up #define APT_INIT_READBACK \ char readback[20]; \ - memset(readback, 'D', sizeof(readback)/sizeof(readback[0])); \ + memset(readback, 'D', sizeof(readback)*sizeof(readback[0])); \ readback[19] = '\0'; #define EXPECT_N_STR(expect, actual) \ EXPECT_EQ(0, strncmp(expect, actual, strlen(expect))); - + { + APT_INIT_READBACK + char const * const expect = "DDDDDDDDDDDDDDDDDDD"; + EXPECT_STREQ(expect,readback); + EXPECT_N_STR(expect, readback); + } { APT_INIT_READBACK char const * const expect = "This"; -- cgit v1.2.3 From 23fb7b2cbbda62c99a199d29ad62205b23d35af4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 5 Nov 2014 18:56:12 +0100 Subject: (style) Variable 'res' is assigned a value that is never used Checking the return value of this (and many other calls) in this testcase is a good idea, so we do it now. Reported-By: cppcheck Git-Dch: Ignore --- test/libapt/fileutl_test.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'test/libapt') diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc index 57d5bbdc2..a2c303768 100644 --- a/test/libapt/fileutl_test.cc +++ b/test/libapt/fileutl_test.cc @@ -252,37 +252,40 @@ TEST(FileUtlTest, Popen) // output something const char* Args[10] = {"/bin/echo", "meepmeep", NULL}; - bool res = Popen(Args, Fd, Child, FileFd::ReadOnly); - Fd.Read(buf, sizeof(buf)-1, &n); + EXPECT_TRUE(Popen(Args, Fd, Child, FileFd::ReadOnly)); + EXPECT_TRUE(Fd.Read(buf, sizeof(buf)-1, &n)); buf[n] = 0; EXPECT_NE(n, 0); - EXPECT_EQ(res, true); EXPECT_STREQ(buf, "meepmeep\n"); // wait for the child to exit and cleanup - ExecWait(Child, "PopenRead"); - Fd.Close(); + EXPECT_TRUE(ExecWait(Child, "PopenRead")); + EXPECT_TRUE(Fd.Close()); // ensure that after a close all is good again if(FileExists("/proc/self/fd")) EXPECT_EQ(Glob("/proc/self/fd/*").size(), OpenFds.size()); - // ReadWrite is not supported - res = Popen(Args, Fd, Child, FileFd::ReadWrite); - EXPECT_EQ(res, false); - _error->Discard(); + _error->PushToStack(); + EXPECT_FALSE(Popen(Args, Fd, Child, FileFd::ReadWrite)); + EXPECT_FALSE(Fd.IsOpen()); + EXPECT_FALSE(Fd.Failed()); + EXPECT_TRUE(_error->PendingError()); + _error->RevertToStack(); // write something Args[0] = "/bin/bash"; Args[1] = "-c"; Args[2] = "read"; Args[3] = NULL; - res = Popen(Args, Fd, Child, FileFd::WriteOnly); + EXPECT_TRUE(Popen(Args, Fd, Child, FileFd::WriteOnly)); s = "\n"; - Fd.Write(s.c_str(), s.size()); - Fd.Close(); - ExecWait(Child, "PopenWrite"); + EXPECT_TRUE(Fd.Write(s.c_str(), s.length())); + EXPECT_TRUE(Fd.Close()); + EXPECT_FALSE(Fd.IsOpen()); + EXPECT_FALSE(Fd.Failed()); + EXPECT_TRUE(ExecWait(Child, "PopenWrite")); } TEST(FileUtlTest, flAbsPath) { -- cgit v1.2.3 From b8eba208daebe3e3f235983e44da9c398d6f7a57 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 10 Mar 2015 14:11:54 +0100 Subject: reimplement the last uses of sprintf Working with strings c-style is complicated and error-prune, so by converting to c++ style we gain some simplicity and avoid buffer overflows by later extensions. Git-Dch: Ignore --- test/libapt/strutil_test.cc | 22 ++++++++++++++++++++++ test/libapt/uri_test.cc | 12 ++++++++++++ 2 files changed, 34 insertions(+) (limited to 'test/libapt') diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc index 9bc3c76fd..23dc08727 100644 --- a/test/libapt/strutil_test.cc +++ b/test/libapt/strutil_test.cc @@ -97,6 +97,28 @@ TEST(StrUtilTest,StartsWith) EXPECT_FALSE(Startswith("abcd", "x")); EXPECT_FALSE(Startswith("abcd", "abcndefg")); } +TEST(StrUtilTest,TimeToStr) +{ + EXPECT_EQ("0s", TimeToStr(0)); + EXPECT_EQ("42s", TimeToStr(42)); + EXPECT_EQ("9min 21s", TimeToStr((9*60) + 21)); + EXPECT_EQ("20min 42s", TimeToStr((20*60) + 42)); + EXPECT_EQ("10h 42min 21s", TimeToStr((10*3600) + (42*60) + 21)); + EXPECT_EQ("10h 42min 21s", TimeToStr((10*3600) + (42*60) + 21)); + EXPECT_EQ("1988d 3h 29min 7s", TimeToStr((1988*86400) + (3*3600) + (29*60) + 7)); + + EXPECT_EQ("59s", TimeToStr(59)); + EXPECT_EQ("60s", TimeToStr(60)); + EXPECT_EQ("1min 1s", TimeToStr(61)); + EXPECT_EQ("59min 59s", TimeToStr(3599)); + EXPECT_EQ("60min 0s", TimeToStr(3600)); + EXPECT_EQ("1h 0min 1s", TimeToStr(3601)); + EXPECT_EQ("1h 1min 0s", TimeToStr(3660)); + EXPECT_EQ("23h 59min 59s", TimeToStr(86399)); + EXPECT_EQ("24h 0min 0s", TimeToStr(86400)); + EXPECT_EQ("1d 0h 0min 1s", TimeToStr(86401)); + EXPECT_EQ("1d 0h 1min 0s", TimeToStr(86460)); +} TEST(StrUtilTest,SubstVar) { EXPECT_EQ("", SubstVar("", "fails", "passes")); diff --git a/test/libapt/uri_test.cc b/test/libapt/uri_test.cc index 1662f51f0..5d5ae9679 100644 --- a/test/libapt/uri_test.cc +++ b/test/libapt/uri_test.cc @@ -12,6 +12,7 @@ TEST(URITest, BasicHTTP) EXPECT_EQ(90, U.Port); EXPECT_EQ("www.debian.org", U.Host); EXPECT_EQ("/temp/test", U.Path); + EXPECT_EQ("http://www.debian.org:90/temp/test", (std::string)U); // Login data U = URI("http://jgg:foo@ualberta.ca/blah"); EXPECT_EQ("http", U.Access); @@ -20,6 +21,7 @@ TEST(URITest, BasicHTTP) EXPECT_EQ(0, U.Port); EXPECT_EQ("ualberta.ca", U.Host); EXPECT_EQ("/blah", U.Path); + EXPECT_EQ("http://jgg:foo@ualberta.ca/blah", (std::string)U); } TEST(URITest, SingeSlashFile) { @@ -30,6 +32,7 @@ TEST(URITest, SingeSlashFile) EXPECT_EQ(0, U.Port); EXPECT_EQ("", U.Host); EXPECT_EQ("/usr/bin/foo", U.Path); + EXPECT_EQ("file:/usr/bin/foo", (std::string)U); } TEST(URITest, BasicCDROM) { @@ -40,6 +43,7 @@ TEST(URITest, BasicCDROM) EXPECT_EQ(0, U.Port); EXPECT_EQ("Moo Cow Rom", U.Host); EXPECT_EQ("/debian", U.Path); + EXPECT_EQ("cdrom://Moo Cow Rom/debian", (std::string)U); } TEST(URITest, RelativeGzip) { @@ -50,6 +54,7 @@ TEST(URITest, RelativeGzip) EXPECT_EQ(0, U.Port); EXPECT_EQ(".", U.Host); EXPECT_EQ("/bar/cow", U.Path); + EXPECT_EQ("gzip://./bar/cow", (std::string)U); } TEST(URITest, NoSlashFTP) { @@ -60,6 +65,7 @@ TEST(URITest, NoSlashFTP) EXPECT_EQ(0, U.Port); EXPECT_EQ("ftp.fr.debian.org", U.Host); EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path); + EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", (std::string)U); } TEST(URITest, RFC2732) { @@ -70,6 +76,7 @@ TEST(URITest, RFC2732) EXPECT_EQ(0, U.Port); EXPECT_EQ("1080::8:800:200C:417A", U.Host); EXPECT_EQ("/foo", U.Path); + EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", (std::string)U); // with port U = URI("http://[::FFFF:129.144.52.38]:80/index.html"); EXPECT_EQ("http", U.Access); @@ -78,6 +85,7 @@ TEST(URITest, RFC2732) EXPECT_EQ(80, U.Port); EXPECT_EQ("::FFFF:129.144.52.38", U.Host); EXPECT_EQ("/index.html", U.Path); + EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", (std::string)U); // extra colon U = URI("http://[::FFFF:129.144.52.38:]:80/index.html"); EXPECT_EQ("http", U.Access); @@ -86,6 +94,7 @@ TEST(URITest, RFC2732) EXPECT_EQ(80, U.Port); EXPECT_EQ("::FFFF:129.144.52.38:", U.Host); EXPECT_EQ("/index.html", U.Path); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", (std::string)U); // extra colon port U = URI("http://[::FFFF:129.144.52.38:]/index.html"); EXPECT_EQ("http", U.Access); @@ -94,6 +103,7 @@ TEST(URITest, RFC2732) EXPECT_EQ(0, U.Port); EXPECT_EQ("::FFFF:129.144.52.38:", U.Host); EXPECT_EQ("/index.html", U.Path); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", (std::string)U); // My Evil Corruption of RFC 2732 to handle CDROM names! // Fun for the whole family! */ U = URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/"); @@ -103,6 +113,7 @@ TEST(URITest, RFC2732) EXPECT_EQ(0, U.Port); EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U.Host); EXPECT_EQ("/debian/", U.Path); + EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", (std::string)U); // no brackets U = URI("cdrom:Foo Bar Cow/debian/"); EXPECT_EQ("cdrom", U.Access); @@ -111,6 +122,7 @@ TEST(URITest, RFC2732) EXPECT_EQ(0, U.Port); EXPECT_EQ("Foo Bar Cow", U.Host); EXPECT_EQ("/debian/", U.Path); + EXPECT_EQ("cdrom://Foo Bar Cow/debian/", (std::string)U); // percent encoded U = URI("ftp://foo:b%40r@example.org"); EXPECT_EQ("foo", U.User); -- cgit v1.2.3 From dfad5beea77d75983f6ff8a1b8296b74dd48203e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 15 Mar 2015 22:34:54 +0100 Subject: 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 --- test/libapt/acqprogress_test.cc | 170 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 test/libapt/acqprogress_test.cc (limited to 'test/libapt') 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 +#include +#include +#include +#include +#include +#include +#include + +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()); +} -- cgit v1.2.3 From 42fab5fbc85e243b958beff95912c46fb81abcc0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 17 Mar 2015 16:51:29 +0100 Subject: demote missing gtest to a buildtime warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We just need it for unit tests and our debian/rules file actually skips calling them if nocheck is given… but this fails anyhow as we declared a hard-dependency on it. Demoting the error to a warning in configuration and adding a test in the 'make test' path with a friendly message allows nocheck to be useful again. (Running unit tests is fully encouraged of course, but bootstrappers and co do not need to be burdened with this stuff) --- test/libapt/makefile | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/libapt') diff --git a/test/libapt/makefile b/test/libapt/makefile index 7f23ace46..0f8df291f 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -8,6 +8,7 @@ APT_DOMAIN=none include ../../buildlib/defaults.mak .PHONY: test +ifeq (file-okay,$(shell $(CC) -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay')) test: $(BIN)/gtest$(BASENAME) MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME) @@ -71,3 +72,11 @@ $(LIB)/gtest.a: $(OBJ)/gtest-all.o echo Building static library $@ -rm -f $@ $(AR) $(ARFLAGS) $@ $^ + +else +test: + @echo "APT uses Googles C++ testing framework for its unit tests" + @echo "On Debian systems this is available in the 'libgtest-dev' package." + @echo "Please install it before attempting to run the unit tests." + exit 100 +endif -- cgit v1.2.3 From 9224ce3d4d1ea0428a70e75134998e08aa45b1e6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 30 Mar 2015 20:47:13 +0200 Subject: calculate only expected hashes in methods Methods get told which hashes are expected by the acquire system, which means we can use this list to restrict what we calculate in the methods as any extra we are calculating is wasted effort as we can't compare it with anything anyway. Adding support for a new hash algorithm is therefore 'free' now and if a algorithm is no longer provided in a repository for a file, we automatically stop calculating it. In practice this results in a speed-up in Debian as we don't have SHA512 here (so far), so we practically stop calculating it. --- test/libapt/hashsums_test.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/libapt') diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index a19a0befd..edcd8a11a 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -193,6 +193,30 @@ TEST(HashSumsTest, FileBased) EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } fd.Seek(0); + { + Hashes hashes(Hashes::MD5SUM | Hashes::SHA512SUM); + hashes.AddFD(fd); + HashStringList list = hashes.GetHashStringList(); + EXPECT_FALSE(list.empty()); + EXPECT_EQ(3, list.size()); + EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(NULL, list.find("SHA1")); + EXPECT_EQ(NULL, list.find("SHA256")); + EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); + fd.Seek(0); + Hashes hashes2(list); + hashes2.AddFD(fd); + list = hashes2.GetHashStringList(); + EXPECT_FALSE(list.empty()); + EXPECT_EQ(3, list.size()); + EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(NULL, list.find("SHA1")); + EXPECT_EQ(NULL, list.find("SHA256")); + EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); + } + fd.Seek(0); { MD5Summation MD5; MD5.AddFD(fd.Fd()); -- cgit v1.2.3 From f492283b4369ed0711f5f538b6d5fe61a8a75a0f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 28 Apr 2015 15:06:12 +0200 Subject: do not require installed libapt-pkg-dev for gtest Git-Dch: Ignore --- test/libapt/makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/libapt') diff --git a/test/libapt/makefile b/test/libapt/makefile index 0f8df291f..61a8aaf31 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -8,7 +8,7 @@ APT_DOMAIN=none include ../../buildlib/defaults.mak .PHONY: test -ifeq (file-okay,$(shell $(CC) -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay')) +ifeq (file-okay,$(shell $(CC) -I $(BASE)/build/include -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay')) test: $(BIN)/gtest$(BASENAME) MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME) @@ -78,5 +78,6 @@ test: @echo "APT uses Googles C++ testing framework for its unit tests" @echo "On Debian systems this is available in the 'libgtest-dev' package." @echo "Please install it before attempting to run the unit tests." + $(CC) -I $(BASE)/build/include -M gtest_runner.cc exit 100 endif -- cgit v1.2.3 From 8d058ea53b18348f81229049a27d14282bd8d8c1 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 10 May 2015 22:53:15 +0200 Subject: implement a more c++-style TFRewrite alternative TFRewrite is okay, but it has obscure limitations (256 Tags), even more obscure bugs (order for renames is defined by the old name) and the interface is very c-style encouraging bad usage like we do it in apt-ftparchive passing massive amounts of c_str() from std::string in. The old-style is marked as deprecated accordingly. The next commit will fix all places in the apt code to not use the old-style anymore. --- test/libapt/tagfile_test.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/libapt') diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc index df618ea16..d7030f41a 100644 --- a/test/libapt/tagfile_test.cc +++ b/test/libapt/tagfile_test.cc @@ -34,6 +34,12 @@ TEST(TagFileTest,SingleField) EXPECT_FALSE(section.Exists("FieldB-12345678")); // There is only one section in this tag file EXPECT_FALSE(tfile.Step(section)); + + // Now we scan an empty section to test reset + ASSERT_TRUE(section.Scan("\n\n", 2, true)); + EXPECT_EQ(0, section.Count()); + EXPECT_FALSE(section.Exists("FieldA-12345678")); + EXPECT_FALSE(section.Exists("FieldB-12345678")); } TEST(TagFileTest,MultipleSections) -- cgit v1.2.3 From 88593886a42025d51d76051da5929b044e42efee Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 11 May 2015 15:08:08 +0200 Subject: rewrite all TFRewrite instances to use the new pkgTagSection::Write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it is mostly busywork to rewrite all instances it actually fixes bugs as the data storage used by the new method is std::string rather than a char*, the later mostly created by c_str() from a std::string which the caller has to ensure keeps in scope – something apt-ftparchive actually didn't ensure and relied on copy-on-write behavior instead which c++11 forbids and hence the new default gcc abi doesn't use it. --- test/libapt/indexcopytosourcelist_test.cc | 2 +- test/libapt/tagsection_test.cc | 270 ++++++++++++++++++++++++++++++ 2 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 test/libapt/tagsection_test.cc (limited to 'test/libapt') diff --git a/test/libapt/indexcopytosourcelist_test.cc b/test/libapt/indexcopytosourcelist_test.cc index bec87601f..1b0427564 100644 --- a/test/libapt/indexcopytosourcelist_test.cc +++ b/test/libapt/indexcopytosourcelist_test.cc @@ -16,7 +16,7 @@ class NoCopy : public IndexCopy { return Path; } bool GetFile(std::string &/*Filename*/, unsigned long long &/*Size*/) { return false; } - bool RewriteEntry(FILE * /*Target*/, std::string /*File*/) { return false; } + bool RewriteEntry(FileFd & /*Target*/, std::string const &/*File*/) { return false; } const char *GetFileName() { return NULL; } const char *Type() { return NULL; } diff --git a/test/libapt/tagsection_test.cc b/test/libapt/tagsection_test.cc new file mode 100644 index 000000000..f250177af --- /dev/null +++ b/test/libapt/tagsection_test.cc @@ -0,0 +1,270 @@ +#include + +#include +#include + +#include +#include + +#include + +#include "file-helpers.h" + +std::string packageValue = "aaaa"; +std::string typoValue = "aa\n" + " .\n" + " cc"; +std::string typoRawValue = "\n " + typoValue; +std::string overrideValue = "1"; +/* + std::cerr << "FILECONTENT: »"; + char buffer[3000]; + while (fd.ReadLine(buffer, sizeof(buffer))) + std::cerr << buffer; + std::cerr << "«" << std::endl;; +*/ + +void setupTestcaseStart(FileFd &fd, pkgTagSection §ion, std::string &content) +{ + createTemporaryFile("writesection", fd, NULL, NULL); + content = "Package: " + packageValue + "\n" + "TypoA:\n " + typoValue + "\n" + "Override: " + overrideValue + "\n" + "Override-Backup: " + overrideValue + "\n" + "\n"; + EXPECT_TRUE(section.Scan(content.c_str(), content.length(), true)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoA")); + EXPECT_EQ(typoRawValue, section.FindRawS("TypoA")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteUnmodified) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + EXPECT_TRUE(section.Write(fd)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoA")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteUnmodifiedOrder) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + char const * const order[] = { "Package", "TypoA", "Override", NULL }; + EXPECT_TRUE(section.Write(fd, order)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoA")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteUnmodifiedOrderReversed) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + char const * const order[] = { "Override", "TypoA", "Package", NULL }; + EXPECT_TRUE(section.Write(fd, order)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoA")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteUnmodifiedOrderNotAll) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + char const * const order[] = { "Override", NULL }; + EXPECT_TRUE(section.Write(fd, order)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoA")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteNoOrderRename) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Rename("TypoA", "TypoB")); + EXPECT_TRUE(section.Write(fd, NULL, rewrite)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_FALSE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("TypoB")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoB")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteNoOrderRemove) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Remove("TypoA")); + rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", "")); + EXPECT_TRUE(section.Write(fd, NULL, rewrite)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_FALSE(section.Exists("TypoA")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_FALSE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(2, section.Count()); +} +TEST(TagSectionTest,WriteNoOrderRewrite) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", "42")); + EXPECT_TRUE(section.Write(fd, NULL, rewrite)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(42, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteOrderRename) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Rename("TypoA", "TypoB")); + char const * const order[] = { "Package", "TypoA", "Override", NULL }; + EXPECT_TRUE(section.Write(fd, order, rewrite)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_FALSE(section.Exists("TypoA")); + EXPECT_TRUE(section.Exists("TypoB")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(typoValue, section.FindS("TypoB")); + EXPECT_EQ(1, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} +TEST(TagSectionTest,WriteOrderRemove) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Remove("TypoA")); + rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", "")); + char const * const order[] = { "Package", "TypoA", "Override", NULL }; + EXPECT_TRUE(section.Write(fd, order, rewrite)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_FALSE(section.Exists("TypoA")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_FALSE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(2, section.Count()); +} +TEST(TagSectionTest,WriteOrderRewrite) +{ + FileFd fd; + pkgTagSection section; + std::string content; + setupTestcaseStart(fd, section, content); + std::vector rewrite; + rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", "42")); + char const * const order[] = { "Package", "TypoA", "Override", NULL }; + EXPECT_TRUE(section.Write(fd, order, rewrite)); + EXPECT_TRUE(fd.Seek(0)); + pkgTagFile tfile(&fd); + ASSERT_TRUE(tfile.Step(section)); + EXPECT_TRUE(section.Exists("Package")); + EXPECT_TRUE(section.Exists("TypoA")); + EXPECT_FALSE(section.Exists("TypoB")); + EXPECT_TRUE(section.Exists("Override")); + EXPECT_TRUE(section.Exists("Override-Backup")); + EXPECT_EQ(packageValue, section.FindS("Package")); + EXPECT_EQ(42, section.FindI("Override")); + EXPECT_EQ(1, section.FindI("Override-Backup")); + EXPECT_EQ(4, section.Count()); +} -- cgit v1.2.3 From 448c38bdcd72b52f11ec5f326f822cf57653f81c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 6 Jun 2015 12:28:00 +0200 Subject: rework hashsum verification in the acquire system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Having every item having its own code to verify the file(s) it handles is an errorprune process and easy to break, especially if items move through various stages (download, uncompress, patching, …). With a giant rework we centralize (most of) the verification to have a better enforcement rate and (hopefully) less chance for bugs, but it breaks the ABI bigtime in exchange – and as we break it anyway, it is broken even harder. It shouldn't effect most frontends as they don't deal with the acquire system at all or implement their own items, but some do and will need to be patched (might be an opportunity to use apt on-board material). The theory is simple: Items implement methods to decide if hashes need to be checked (in this stage) and to return the expected hashes for this item (in this stage). The verification itself is done in worker message passing which has the benefit that a hashsum error is now a proper error for the acquire system rather than a Done() which is later revised to a Failed(). --- test/libapt/acqprogress_test.cc | 6 ++++-- test/libapt/hashsums_test.cc | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'test/libapt') diff --git a/test/libapt/acqprogress_test.cc b/test/libapt/acqprogress_test.cc index 288e05aca..c634733d4 100644 --- a/test/libapt/acqprogress_test.cc +++ b/test/libapt/acqprogress_test.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -10,9 +11,10 @@ class TestItem: public pkgAcquire::Item { public: - TestItem(pkgAcquire * const Acq) : pkgAcquire::Item(Acq, "", NULL) {} + TestItem(pkgAcquire * const Acq) : pkgAcquire::Item(Acq) {} - virtual std::string DescURI() { return ""; } + virtual std::string DescURI() const { return ""; } + virtual HashStringList GetExpectedHashes() const { return HashStringList(); } }; diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index edcd8a11a..63c63ecd3 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -306,6 +306,7 @@ TEST(HashSumsTest, HashStringList) EXPECT_EQ(NULL, list.find(NULL)); EXPECT_EQ(NULL, list.find("")); EXPECT_EQ(NULL, list.find("MD5Sum")); + EXPECT_EQ(0, list.FileSize()); // empty lists aren't equal HashStringList list2; @@ -316,6 +317,8 @@ TEST(HashSumsTest, HashStringList) list.push_back(HashString("Checksum-FileSize", "29")); EXPECT_FALSE(list.empty()); EXPECT_FALSE(list.usable()); + EXPECT_EQ(1, list.size()); + EXPECT_EQ(29, list.FileSize()); Hashes hashes; hashes.Add("The quick brown fox jumps over the lazy dog"); -- cgit v1.2.3 From 1da3b7b8e15b642135b54684e70a0c271471f07a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 11 Jun 2015 10:56:31 +0200 Subject: show URI.Path in all acquire item descriptions It is a rather strange sight that index items use SiteOnly which strips the Path, while e.g. deb files are downloaded with NoUserPassword which does not. Important to note here is that for the file transport Path is pretty important as there is no Host which would be displayed by Site, which always resulted in "interesting" unspecific errors for "file:". Adding a 'middle' ground between the two which does show the Path but potentially modifies it (it strips a pending / at the end if existing) solves this "file:" issue, syncs the output and in the end helps to identify which file is meant exactly in progress output and co as a single site can have multiple repositories in different paths. --- test/libapt/uri_test.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/libapt') diff --git a/test/libapt/uri_test.cc b/test/libapt/uri_test.cc index 5d5ae9679..fe6015e65 100644 --- a/test/libapt/uri_test.cc +++ b/test/libapt/uri_test.cc @@ -13,6 +13,9 @@ TEST(URITest, BasicHTTP) EXPECT_EQ("www.debian.org", U.Host); EXPECT_EQ("/temp/test", U.Path); EXPECT_EQ("http://www.debian.org:90/temp/test", (std::string)U); + EXPECT_EQ("http://www.debian.org:90", URI::SiteOnly(U)); + EXPECT_EQ("http://www.debian.org:90/temp/test", URI::ArchiveOnly(U)); + EXPECT_EQ("http://www.debian.org:90/temp/test", URI::NoUserPassword(U)); // Login data U = URI("http://jgg:foo@ualberta.ca/blah"); EXPECT_EQ("http", U.Access); @@ -22,6 +25,9 @@ TEST(URITest, BasicHTTP) EXPECT_EQ("ualberta.ca", U.Host); EXPECT_EQ("/blah", U.Path); EXPECT_EQ("http://jgg:foo@ualberta.ca/blah", (std::string)U); + EXPECT_EQ("http://ualberta.ca", URI::SiteOnly(U)); + EXPECT_EQ("http://ualberta.ca/blah", URI::ArchiveOnly(U)); + EXPECT_EQ("http://ualberta.ca/blah", URI::NoUserPassword(U)); } TEST(URITest, SingeSlashFile) { @@ -33,6 +39,9 @@ TEST(URITest, SingeSlashFile) EXPECT_EQ("", U.Host); EXPECT_EQ("/usr/bin/foo", U.Path); EXPECT_EQ("file:/usr/bin/foo", (std::string)U); + EXPECT_EQ("file:", URI::SiteOnly(U)); + EXPECT_EQ("file:/usr/bin/foo", URI::ArchiveOnly(U)); + EXPECT_EQ("file:/usr/bin/foo", URI::NoUserPassword(U)); } TEST(URITest, BasicCDROM) { @@ -44,6 +53,9 @@ TEST(URITest, BasicCDROM) EXPECT_EQ("Moo Cow Rom", U.Host); EXPECT_EQ("/debian", U.Path); EXPECT_EQ("cdrom://Moo Cow Rom/debian", (std::string)U); + EXPECT_EQ("cdrom://Moo Cow Rom", URI::SiteOnly(U)); + EXPECT_EQ("cdrom://Moo Cow Rom/debian", URI::ArchiveOnly(U)); + EXPECT_EQ("cdrom://Moo Cow Rom/debian", URI::NoUserPassword(U)); } TEST(URITest, RelativeGzip) { @@ -55,6 +67,9 @@ TEST(URITest, RelativeGzip) EXPECT_EQ(".", U.Host); EXPECT_EQ("/bar/cow", U.Path); EXPECT_EQ("gzip://./bar/cow", (std::string)U); + EXPECT_EQ("gzip://.", URI::SiteOnly(U)); + EXPECT_EQ("gzip://./bar/cow", URI::ArchiveOnly(U)); + EXPECT_EQ("gzip://./bar/cow", URI::NoUserPassword(U)); } TEST(URITest, NoSlashFTP) { @@ -66,6 +81,9 @@ TEST(URITest, NoSlashFTP) EXPECT_EQ("ftp.fr.debian.org", U.Host); EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path); EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", (std::string)U); + EXPECT_EQ("ftp://ftp.fr.debian.org", URI::SiteOnly(U)); + EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", URI::ArchiveOnly(U)); + EXPECT_EQ("ftp://ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", URI::NoUserPassword(U)); } TEST(URITest, RFC2732) { @@ -77,6 +95,9 @@ TEST(URITest, RFC2732) EXPECT_EQ("1080::8:800:200C:417A", U.Host); EXPECT_EQ("/foo", U.Path); EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", (std::string)U); + EXPECT_EQ("http://[1080::8:800:200C:417A]", URI::SiteOnly(U)); + EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", URI::ArchiveOnly(U)); + EXPECT_EQ("http://[1080::8:800:200C:417A]/foo", URI::NoUserPassword(U)); // with port U = URI("http://[::FFFF:129.144.52.38]:80/index.html"); EXPECT_EQ("http", U.Access); @@ -86,6 +107,9 @@ TEST(URITest, RFC2732) EXPECT_EQ("::FFFF:129.144.52.38", U.Host); EXPECT_EQ("/index.html", U.Path); EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", (std::string)U); + EXPECT_EQ("http://[::FFFF:129.144.52.38]:80", URI::SiteOnly(U)); + EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", URI::ArchiveOnly(U)); + EXPECT_EQ("http://[::FFFF:129.144.52.38]:80/index.html", URI::NoUserPassword(U)); // extra colon U = URI("http://[::FFFF:129.144.52.38:]:80/index.html"); EXPECT_EQ("http", U.Access); @@ -95,6 +119,9 @@ TEST(URITest, RFC2732) EXPECT_EQ("::FFFF:129.144.52.38:", U.Host); EXPECT_EQ("/index.html", U.Path); EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", (std::string)U); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80", URI::SiteOnly(U)); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", URI::ArchiveOnly(U)); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]:80/index.html", URI::NoUserPassword(U)); // extra colon port U = URI("http://[::FFFF:129.144.52.38:]/index.html"); EXPECT_EQ("http", U.Access); @@ -104,6 +131,9 @@ TEST(URITest, RFC2732) EXPECT_EQ("::FFFF:129.144.52.38:", U.Host); EXPECT_EQ("/index.html", U.Path); EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", (std::string)U); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]", URI::SiteOnly(U)); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", URI::ArchiveOnly(U)); + EXPECT_EQ("http://[::FFFF:129.144.52.38:]/index.html", URI::NoUserPassword(U)); // My Evil Corruption of RFC 2732 to handle CDROM names! // Fun for the whole family! */ U = URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/"); @@ -114,6 +144,9 @@ TEST(URITest, RFC2732) EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U.Host); EXPECT_EQ("/debian/", U.Path); EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", (std::string)U); + EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]", URI::SiteOnly(U)); + EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian", URI::ArchiveOnly(U)); + EXPECT_EQ("cdrom://[The Debian 1.2 disk, 1/2 R1:6]/debian/", URI::NoUserPassword(U)); // no brackets U = URI("cdrom:Foo Bar Cow/debian/"); EXPECT_EQ("cdrom", U.Access); @@ -123,9 +156,15 @@ TEST(URITest, RFC2732) EXPECT_EQ("Foo Bar Cow", U.Host); EXPECT_EQ("/debian/", U.Path); EXPECT_EQ("cdrom://Foo Bar Cow/debian/", (std::string)U); + EXPECT_EQ("cdrom://Foo Bar Cow", URI::SiteOnly(U)); + EXPECT_EQ("cdrom://Foo Bar Cow/debian", URI::ArchiveOnly(U)); + EXPECT_EQ("cdrom://Foo Bar Cow/debian/", URI::NoUserPassword(U)); // percent encoded U = URI("ftp://foo:b%40r@example.org"); EXPECT_EQ("foo", U.User); EXPECT_EQ("b@r", U.Password); EXPECT_EQ("ftp://foo:b%40r@example.org/", (std::string) U); + EXPECT_EQ("ftp://example.org", URI::SiteOnly(U)); + EXPECT_EQ("ftp://example.org", URI::ArchiveOnly(U)); + EXPECT_EQ("ftp://example.org/", URI::NoUserPassword(U)); } -- cgit v1.2.3 From c8a4ce6cbed57ae108dc955d4a850f9b129a0693 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 16 Jun 2015 16:22:46 +0200 Subject: add d-pointer, virtual destructors and de-inline de/constructors To have a chance to keep the ABI for a while we need all three to team up. One of them missing and we might loose, so ensuring that they are available is a very tedious but needed task once in a while. Git-Dch: Ignore --- test/libapt/acqprogress_test.cc | 46 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'test/libapt') diff --git a/test/libapt/acqprogress_test.cc b/test/libapt/acqprogress_test.cc index c634733d4..dc31423fc 100644 --- a/test/libapt/acqprogress_test.cc +++ b/test/libapt/acqprogress_test.cc @@ -25,21 +25,23 @@ TEST(AcqProgress, IMSHit) 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"; - hit.Owner = NULL; + TestItem hitO(&Acq); + hit.Owner = &hitO; EXPECT_EQ("", out.str()); Stat.IMSHit(hit); - EXPECT_EQ("Hit Example File from example.org\n", out.str()); + EXPECT_EQ("Hit:1 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()); + 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 Example File from example.org\n" - "Hit Example File from example.org\n", out.str()); + EXPECT_EQ("Hit:1 Example File from example.org\n" + "Hit:1 Example File from example.org\n", out.str()); } TEST(AcqProgress, FetchNoFileSize) { @@ -61,10 +63,10 @@ TEST(AcqProgress, FetchNoFileSize) 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()); + "Get:1 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()); + "Get:1 Example File from example.org\n", out.str()); } TEST(AcqProgress, FetchFileSize) { @@ -88,10 +90,10 @@ TEST(AcqProgress, FetchFileSize) 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()); + "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:2 Example File from example.org [42 B]\n", out.str()); + "Get:1 Example File from example.org [42 B]\n", out.str()); } TEST(AcqProgress, Fail) { @@ -112,30 +114,34 @@ TEST(AcqProgress, Fail) EXPECT_EQ("", out.str()); Stat.Fail(fetch); - EXPECT_EQ("", out.str()); + EXPECT_EQ("Ign:1 Example File from example.org\n", out.str()); fetchO.Status = pkgAcquire::Item::StatDone; Stat.Fail(fetch); - EXPECT_EQ("Ign Example File from example.org\n", out.str()); + 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 Example File from example.org\n" - "Err Example File from example.org\n" + 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 Example File from example.org\n" - "Err Example File from example.org\n" + 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 Example File from example.org\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 Example File from example.org\n" - "Err Example File from example.org\n" + 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 Example File from example.org\n" + "Ign:1 Example File from example.org\n" " An error test!\n", out.str()); } TEST(AcqProgress, Pulse) -- cgit v1.2.3