summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/assert.h50
-rw-r--r--test/libapt/getarchitectures_test.cc13
-rw-r--r--test/libapt/getlanguages_test.cc11
-rw-r--r--test/libapt/getlistoffilesindir_test.cc7
-rw-r--r--test/libapt/hashsums_test.cc15
-rw-r--r--test/libapt/makefile6
-rw-r--r--test/libapt/strutil_test.cc46
7 files changed, 121 insertions, 27 deletions
diff --git a/test/libapt/assert.h b/test/libapt/assert.h
index 5da76ae0a..fae9b6c64 100644
--- a/test/libapt/assert.h
+++ b/test/libapt/assert.h
@@ -1,9 +1,9 @@
#include <iostream>
-#define equals(x,y) assertEquals(x, y, __LINE__)
+#define equals(x,y) assertEquals(y, x, __LINE__)
template < typename X, typename Y >
-void OutputAssert(X expect, char const* compare, Y get, unsigned long const &line) {
+void OutputAssertEqual(X expect, char const* compare, Y get, unsigned long const &line) {
std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl;
}
@@ -11,11 +11,53 @@ template < typename X, typename Y >
void assertEquals(X expect, Y get, unsigned long const &line) {
if (expect == get)
return;
- OutputAssert(expect, "==", get, line);
+ OutputAssertEqual(expect, "==", get, line);
}
void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) {
if (get < 0)
- OutputAssert(expect, "==", get, line);
+ OutputAssertEqual(expect, "==", get, line);
assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
}
+
+void assertEquals(int const &expect, unsigned int const &get, unsigned long const &line) {
+ if (expect < 0)
+ OutputAssertEqual(expect, "==", get, line);
+ assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
+}
+
+
+#define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
+
+template < typename X, typename Y >
+void OutputAssertEqualOr2(X expect1, X expect2, char const* compare, Y get, unsigned long const &line) {
+ std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« " << compare << " »" << get << "« at line " << line << std::endl;
+}
+
+template < typename X, typename Y >
+void assertEqualsOr2(X expect1, X expect2, Y get, unsigned long const &line) {
+ if (expect1 == get || expect2 == get)
+ return;
+ OutputAssertEqualOr2(expect1, expect2, "==", get, line);
+}
+
+void assertEqualsOr2(unsigned int const &expect1, unsigned int const &expect2, int const &get, unsigned long const &line) {
+ if (get < 0)
+ OutputAssertEqualOr2(expect1, expect2, "==", get, line);
+ assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line);
+}
+
+void assertEqualsOr2(int const &expect1, int const &expect2, unsigned int const &get, unsigned long const &line) {
+ if (expect1 < 0 && expect2 < 0)
+ OutputAssertEqualOr2(expect1, expect2, "==", get, line);
+ assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line);
+}
+
+
+// simple helper to quickly output a vectors
+template < typename X >
+void dumpVector(X vec) {
+ for (typename X::const_iterator v = vec.begin();
+ v != vec.end(); ++v)
+ std::cout << *v << std::endl;
+}
diff --git a/test/libapt/getarchitectures_test.cc b/test/libapt/getarchitectures_test.cc
index 1500caeed..807469263 100644
--- a/test/libapt/getarchitectures_test.cc
+++ b/test/libapt/getarchitectures_test.cc
@@ -7,13 +7,6 @@
#include <iostream>
-// simple helper to quickly output a vector of strings
-void dumpVector(std::vector<std::string> vec) {
- for (std::vector<std::string>::const_iterator v = vec.begin();
- v != vec.end(); v++)
- std::cout << *v << std::endl;
-}
-
int main(int argc,char *argv[])
{
std::vector<std::string> vec;
@@ -39,6 +32,12 @@ int main(int argc,char *argv[])
_config->Set("APT::Architecture", "armel");
vec = APT::Configuration::getArchitectures(false);
equals(vec.size(), 2);
+ equals(vec[0], "armel");
+ equals(vec[1], "i386");
+
+ _config->Set("APT::Architectures::2", "armel");
+ vec = APT::Configuration::getArchitectures(false);
+ equals(vec.size(), 2);
equals(vec[0], "i386");
equals(vec[1], "armel");
diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc
index 707142aef..f6aa7a697 100644
--- a/test/libapt/getlanguages_test.cc
+++ b/test/libapt/getlanguages_test.cc
@@ -7,13 +7,6 @@
#include <iostream>
-// simple helper to quickly output a vector of strings
-void dumpVector(std::vector<std::string> vec) {
- for (std::vector<std::string>::const_iterator v = vec.begin();
- v != vec.end(); v++)
- std::cout << *v << std::endl;
-}
-
int main(int argc,char *argv[])
{
if (argc != 2) {
@@ -138,8 +131,8 @@ int main(int argc,char *argv[])
equals(vec[1], "de");
equals(vec[2], "en");
equals(vec[3], "none");
- equals(vec[4], "pt");
- equals(vec[5], "tr");
+ equalsOr2(vec[4], "pt", "tr");
+ equalsOr2(vec[5], "tr", "pt");
_config->Set("Dir::State::lists", "/non-existing-dir");
_config->Set("Acquire::Languages::1", "none");
diff --git a/test/libapt/getlistoffilesindir_test.cc b/test/libapt/getlistoffilesindir_test.cc
index ed8d2dad6..5ee014cca 100644
--- a/test/libapt/getlistoffilesindir_test.cc
+++ b/test/libapt/getlistoffilesindir_test.cc
@@ -7,13 +7,6 @@
#include <stdio.h>
#include <iostream>
-// simple helper to quickly output a vector of strings
-void dumpVector(std::vector<std::string> vec) {
- for (std::vector<std::string>::const_iterator v = vec.begin();
- v != vec.end(); v++)
- std::cout << *v << std::endl;
-}
-
#define P(x) string(argv[1]).append("/").append(x)
int main(int argc,char *argv[])
diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc
index ff1536718..2cb71cc38 100644
--- a/test/libapt/hashsums_test.cc
+++ b/test/libapt/hashsums_test.cc
@@ -135,6 +135,21 @@ int main(int argc, char** argv)
equals(argv[5], sha2.Result().Value());
}
fclose(fd);
+
+ // test HashString code
+ {
+ HashString sha2("SHA256", argv[4]);
+ equals(sha2.VerifyFile(argv[1]), true);
+ }
+ {
+ HashString sha2("SHA512", argv[5]);
+ equals(sha2.VerifyFile(argv[1]), true);
+ }
+ {
+ HashString sha2("SHA256:"+string(argv[4]));
+ equals(sha2.VerifyFile(argv[1]), true);
+ }
+
return 0;
}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 1d36f0c7c..a8acabd8e 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -52,3 +52,9 @@ PROGRAM = HashSums${BASENAME}
SLIBS = -lapt-pkg
SOURCE = hashsums_test.cc
include $(PROGRAM_H)
+
+# test the strutils stuff
+PROGRAM = StrUtil${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = strutil_test.cc
+include $(PROGRAM_H)
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc
new file mode 100644
index 000000000..af6eb2cc6
--- /dev/null
+++ b/test/libapt/strutil_test.cc
@@ -0,0 +1,46 @@
+#include <apt-pkg/strutl.h>
+
+#include "assert.h"
+
+int main(int argc,char *argv[])
+{
+ string input, output, expected;
+
+ // no input
+ input = "foobar";
+ expected = "foobar";
+ output = DeEscapeString(input);
+ equals(output, expected);
+
+ // hex and octal
+ input = "foo\\040bar\\x0abaz";
+ expected = "foo bar\nbaz";
+ output = DeEscapeString(input);
+ equals(output, expected);
+
+ // at the end
+ input = "foo\\040";
+ expected = "foo ";
+ output = DeEscapeString(input);
+ equals(output, expected);
+
+ // double escape
+ input = "foo\\\\ x";
+ expected = "foo\\ x";
+ output = DeEscapeString(input);
+ equals(output, expected);
+
+ // double escape at the end
+ input = "\\\\foo\\\\";
+ expected = "\\foo\\";
+ output = DeEscapeString(input);
+ equals(output, expected);
+
+ // the string that we actually need it for
+ input = "/media/Ubuntu\\04011.04\\040amd64";
+ expected = "/media/Ubuntu 11.04 amd64";
+ output = DeEscapeString(input);
+ equals(output, expected);
+
+ return 0;
+}