summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2015-06-23 12:17:35 +0100
committerMichael Vogt <mvo@debian.org>2015-06-23 12:17:35 +0100
commit245dde96193702f7f51389d3583dee547f8ba366 (patch)
tree6cf8c191641c760bcc6a6c08fb0ff65d27e0cffd /test/libapt
parent5530255b5f3ad7de2e23dfcb39ce325001126501 (diff)
parentc8a4ce6cbed57ae108dc955d4a850f9b129a0693 (diff)
Merge remote-tracking branch 'donkult/debian/experimental' into debian/experimental
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/acqprogress_test.cc178
-rw-r--r--test/libapt/cdrom_test.cc3
-rw-r--r--test/libapt/fileutl_test.cc38
-rw-r--r--test/libapt/hashsums_test.cc27
-rw-r--r--test/libapt/indexcopytosourcelist_test.cc2
-rw-r--r--test/libapt/makefile10
-rw-r--r--test/libapt/sourcelist_test.cc2
-rw-r--r--test/libapt/strutil_test.cc22
-rw-r--r--test/libapt/tagfile_test.cc6
-rw-r--r--test/libapt/tagsection_test.cc270
-rw-r--r--test/libapt/uri_test.cc51
11 files changed, 591 insertions, 18 deletions
diff --git a/test/libapt/acqprogress_test.cc b/test/libapt/acqprogress_test.cc
new file mode 100644
index 000000000..dc31423fc
--- /dev/null
+++ b/test/libapt/acqprogress_test.cc
@@ -0,0 +1,178 @@
+#include <config.h>
+#include <apt-pkg/hashes.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) {}
+
+ virtual std::string DescURI() const { return ""; }
+ virtual HashStringList GetExpectedHashes() const { return HashStringList(); }
+
+};
+
+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());
+}
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/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 8d47c5098..a2c303768 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";
@@ -247,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)
{
diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc
index a19a0befd..63c63ecd3 100644
--- a/test/libapt/hashsums_test.cc
+++ b/test/libapt/hashsums_test.cc
@@ -194,6 +194,30 @@ TEST(HashSumsTest, FileBased)
}
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());
EXPECT_EQ(md5.Value(), MD5.Result().Value());
@@ -282,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;
@@ -292,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");
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/makefile b/test/libapt/makefile
index 7f23ace46..61a8aaf31 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) -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)
@@ -71,3 +72,12 @@ $(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."
+ $(CC) -I $(BASE)/build/include -M gtest_runner.cc
+ exit 100
+endif
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"
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/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)
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 <config.h>
+
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/tagfile.h>
+
+#include <string>
+#include <sstream>
+
+#include <gtest/gtest.h>
+
+#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 &section, 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<pkgTagSection::Tag> 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<pkgTagSection::Tag> 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<pkgTagSection::Tag> 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<pkgTagSection::Tag> 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<pkgTagSection::Tag> 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<pkgTagSection::Tag> 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());
+}
diff --git a/test/libapt/uri_test.cc b/test/libapt/uri_test.cc
index 1662f51f0..fe6015e65 100644
--- a/test/libapt/uri_test.cc
+++ b/test/libapt/uri_test.cc
@@ -12,6 +12,10 @@ 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);
+ 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);
@@ -20,6 +24,10 @@ 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);
+ 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)
{
@@ -30,6 +38,10 @@ 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);
+ 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)
{
@@ -40,6 +52,10 @@ 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);
+ 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)
{
@@ -50,6 +66,10 @@ 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);
+ 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)
{
@@ -60,6 +80,10 @@ 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);
+ 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)
{
@@ -70,6 +94,10 @@ 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);
+ 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);
@@ -78,6 +106,10 @@ 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);
+ 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);
@@ -86,6 +118,10 @@ 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);
+ 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);
@@ -94,6 +130,10 @@ 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);
+ 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/");
@@ -103,6 +143,10 @@ 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);
+ 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);
@@ -111,9 +155,16 @@ 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);
+ 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));
}