diff options
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/fileutl_test.cc | 13 | ||||
-rw-r--r-- | test/libapt/globalerror_test.cc | 26 | ||||
-rw-r--r-- | test/libapt/hashsums_test.cc | 32 | ||||
-rw-r--r-- | test/libapt/makefile | 6 | ||||
-rw-r--r-- | test/libapt/parsedepends_test.cc | 2 | ||||
-rw-r--r-- | test/libapt/sourcelist_test.cc | 55 | ||||
-rw-r--r-- | test/libapt/strutil_test.cc | 45 |
7 files changed, 149 insertions, 30 deletions
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc index b6b8ac579..462bdefd9 100644 --- a/test/libapt/fileutl_test.cc +++ b/test/libapt/fileutl_test.cc @@ -38,5 +38,18 @@ int main(int argc,char *argv[]) return 1; } + // GetTempDir() + unsetenv("TMPDIR"); + equals(GetTempDir(), "/tmp"); + + setenv("TMPDIR", "", 1); + equals(GetTempDir(), "/tmp"); + + setenv("TMPDIR", "/not-there-no-really-not", 1); + equals(GetTempDir(), "/tmp"); + + setenv("TMPDIR", "/usr", 1); + equals(GetTempDir(), "/usr"); + return 0; } diff --git a/test/libapt/globalerror_test.cc b/test/libapt/globalerror_test.cc index 72044d493..b6939231d 100644 --- a/test/libapt/globalerror_test.cc +++ b/test/libapt/globalerror_test.cc @@ -15,17 +15,17 @@ int main(int argc,char *argv[]) equals(_error->empty(), true); equals(_error->empty(GlobalError::DEBUG), false); equals(_error->PendingError(), false); - equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false); equals(_error->PendingError(), true); std::string text; equals(_error->PopMessage(text), false); equals(_error->PendingError(), true); equals(text, "A Notice"); equals(_error->PopMessage(text), true); - equals(text, "Something horrible happend 2 times"); + equals(text, "Something horrible happened 2 times"); equals(_error->empty(GlobalError::DEBUG), true); equals(_error->PendingError(), false); - equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false); equals(_error->PendingError(), true); equals(_error->empty(GlobalError::FATAL), false); _error->Discard(); @@ -33,7 +33,7 @@ int main(int argc,char *argv[]) equals(_error->empty(), true); equals(_error->PendingError(), false); equals(_error->Notice("%s Notice", "A"), false); - equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false); equals(_error->PendingError(), true); equals(_error->empty(GlobalError::NOTICE), false); _error->PushToStack(); @@ -49,12 +49,12 @@ int main(int argc,char *argv[]) equals(_error->PendingError(), true); equals(text, "A Notice"); equals(_error->PopMessage(text), true); - equals(text, "Something horrible happend 2 times"); + equals(text, "Something horrible happened 2 times"); equals(_error->PendingError(), false); equals(_error->empty(), true); equals(_error->Notice("%s Notice", "A"), false); - equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false); equals(_error->PendingError(), true); equals(_error->empty(GlobalError::NOTICE), false); _error->PushToStack(); @@ -70,7 +70,7 @@ int main(int argc,char *argv[]) equals(_error->PendingError(), true); equals(text, "A Notice"); equals(_error->PopMessage(text), true); - equals(text, "Something horrible happend 2 times"); + equals(text, "Something horrible happened 2 times"); equals(_error->PendingError(), false); equals(_error->empty(), false); equals(_error->PopMessage(text), false); @@ -78,24 +78,24 @@ int main(int argc,char *argv[]) equals(_error->empty(), true); errno = 0; - equals(_error->Errno("errno", "%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->Errno("errno", "%s horrible %s %d times", "Something", "happened", 2), false); equals(_error->empty(), false); equals(_error->PendingError(), true); equals(_error->PopMessage(text), true); equals(_error->PendingError(), false); - equals(text, std::string("Something horrible happend 2 times - errno (0: ").append(textOfErrnoZero).append(")")); + equals(text, std::string("Something horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")")); equals(_error->empty(), true); std::string longText; for (size_t i = 0; i < 500; ++i) longText.append("a"); - equals(_error->Error("%s horrible %s %d times", longText.c_str(), "happend", 2), false); + equals(_error->Error("%s horrible %s %d times", longText.c_str(), "happened", 2), false); equals(_error->PopMessage(text), true); - equals(text, std::string(longText).append(" horrible happend 2 times")); + equals(text, std::string(longText).append(" horrible happened 2 times")); - equals(_error->Errno("errno", "%s horrible %s %d times", longText.c_str(), "happend", 2), false); + equals(_error->Errno("errno", "%s horrible %s %d times", longText.c_str(), "happened", 2), false); equals(_error->PopMessage(text), true); - equals(text, std::string(longText).append(" horrible happend 2 times - errno (0: ").append(textOfErrnoZero).append(")")); + equals(text, std::string(longText).append(" horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")")); equals(_error->Warning("Репозиторий не обновлён и будут %d %s", 4, "test"), false); equals(_error->PopMessage(text), false); diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index e2d0aec5b..3da89052b 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -3,6 +3,7 @@ #include <apt-pkg/sha2.h> #include <apt-pkg/strutl.h> #include <apt-pkg/hashes.h> +#include <apt-pkg/fileutl.h> #include <iostream> #include <stdio.h> @@ -108,55 +109,54 @@ int main(int argc, char** argv) Test<SHA512Summation>("The quick brown fox jumps over the lazy dog.", "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bb" "c6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed"); - FILE* fd = fopen(argv[1], "r"); - if (fd == NULL) { + FileFd fd(argv[1], FileFd::ReadOnly); + if (fd.IsOpen() == false) { std::cerr << "Can't open file for 1. testing: " << argv[1] << std::endl; return 1; } { Hashes hashes; - hashes.AddFD(fileno(fd)); + hashes.AddFD(fd.Fd()); equals(argv[2], hashes.MD5.Result().Value()); equals(argv[3], hashes.SHA1.Result().Value()); equals(argv[4], hashes.SHA256.Result().Value()); equals(argv[5], hashes.SHA512.Result().Value()); } - fseek(fd, 0L, SEEK_END); - unsigned long sz = ftell(fd); - fseek(fd, 0L, SEEK_SET); + unsigned long sz = fd.FileSize(); + fd.Seek(0); { Hashes hashes; - hashes.AddFD(fileno(fd), sz); + hashes.AddFD(fd.Fd(), sz); equals(argv[2], hashes.MD5.Result().Value()); equals(argv[3], hashes.SHA1.Result().Value()); equals(argv[4], hashes.SHA256.Result().Value()); equals(argv[5], hashes.SHA512.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { MD5Summation md5; - md5.AddFD(fileno(fd)); + md5.AddFD(fd.Fd()); equals(argv[2], md5.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { SHA1Summation sha1; - sha1.AddFD(fileno(fd)); + sha1.AddFD(fd.Fd()); equals(argv[3], sha1.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { SHA256Summation sha2; - sha2.AddFD(fileno(fd)); + sha2.AddFD(fd.Fd()); equals(argv[4], sha2.Result().Value()); } - fseek(fd, 0L, SEEK_SET); + fd.Seek(0); { SHA512Summation sha2; - sha2.AddFD(fileno(fd)); + sha2.AddFD(fd.Fd()); equals(argv[5], sha2.Result().Value()); } - fclose(fd); + fd.Close(); // test HashString code { diff --git a/test/libapt/makefile b/test/libapt/makefile index 73403b24c..a8e053d6e 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -111,3 +111,9 @@ SLIBS = -lapt-pkg SOURCE = tagfile_test.cc include $(PROGRAM_H) +# test sourcelist +PROGRAM = SourceList${BASENAME} +SLIBS = -lapt-pkg +SOURCE = sourcelist_test.cc +include $(PROGRAM_H) + diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc index 677b1c892..e95016240 100644 --- a/test/libapt/parsedepends_test.cc +++ b/test/libapt/parsedepends_test.cc @@ -176,7 +176,7 @@ test: equals("7.15.3~", Version); equals(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op); - Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); if (StripMultiArch == true) equals("overlord-dev", Package); else diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc new file mode 100644 index 000000000..0300ce929 --- /dev/null +++ b/test/libapt/sourcelist_test.cc @@ -0,0 +1,55 @@ +#include <apt-pkg/sourcelist.h> +#include <apt-pkg/tagfile.h> + +#include "assert.h" +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +char *tempfile = NULL; +int tempfile_fd = -1; + +void remove_tmpfile(void) +{ + if (tempfile_fd > 0) + close(tempfile_fd); + if (tempfile != NULL) { + unlink(tempfile); + free(tempfile); + } +} + +int main(int argc, char *argv[]) +{ + _config->Set("APT::Sources::Use-Deb822", true); + + const char contents[] = "" + "Types: deb\n" + "URIs: http://ftp.debian.org/debian\n" + "Suites: stable\n" + "Sections: main\n" + "Description: short\n" + " long description that can be very long\n" + "\n" + "Types: deb\n" + "URIs: http://ftp.debian.org/debian\n" + "Suites: unstable\n" + "Sections: main non-free\n" + ; + + FileFd fd; + atexit(remove_tmpfile); + tempfile = strdup("apt-test.XXXXXXXX"); + tempfile_fd = mkstemp(tempfile); + + /* (Re-)Open (as FileFd), write and seek to start of the temp file */ + equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true); + equals(fd.Write(contents, strlen(contents)), true); + equals(fd.Seek(0), true); + + pkgSourceList sources(tempfile); + equals(sources.size(), 2); + + /* clean up handled by atexit handler, so just return here */ + return 0; +} diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc index bfe0d7222..8215654d0 100644 --- a/test/libapt/strutil_test.cc +++ b/test/libapt/strutil_test.cc @@ -42,5 +42,50 @@ int main(int argc,char *argv[]) output = DeEscapeString(input); equals(output, expected); + // Split + input = "status: libnet1:amd64: unpacked"; + vector<std::string> result = StringSplit(input, ": "); + equals(result[0], "status"); + equals(result[1], "libnet1:amd64"); + equals(result[2], "unpacked"); + equals(result.size(), 3); + + input = "status: libnet1:amd64: unpacked"; + result = StringSplit(input, "xxx"); + equals(result[0], input); + equals(result.size(), 1); + + input = "status: libnet1:amd64: unpacked"; + result = StringSplit(input, ""); + equals(result.size(), 0); + + input = "x:y:z"; + result = StringSplit(input, ":", 2); + equals(result.size(), 2); + equals(result[0], "x"); + equals(result[1], "y:z"); + + input = "abc"; + result = StringSplit(input, ""); + equals(result.size(), 0); + + // endswith + bool b; + input = "abcd"; + b = APT::String::Endswith(input, "d"); + equals(b, true); + + b = APT::String::Endswith(input, "cd"); + equals(b, true); + + b = APT::String::Endswith(input, "abcd"); + equals(b, true); + + b = APT::String::Endswith(input, "x"); + equals(b, false); + + b = APT::String::Endswith(input, "abcndefg"); + equals(b, false); + return 0; } |