summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-07-28 09:19:45 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-07-28 09:19:45 +0200
commit0b7d641cf12761c3dcc5edb4031adfc9709963e4 (patch)
tree5d12281c5f482e6f85636f57ef86a2dc92e8713c /test/libapt
parent7d79339f811aeebacb3f841bac6075fdfbadd03f (diff)
parented6ba81db1b2832089ea443cf0030ab3f15fda97 (diff)
* merged latest fixes from debian-sid
* apt-pkg/contrib/sha1.cc: - fix illegally casts of on-stack buffer to a type requiring more alignment than it has resulting in segfaults on sparc (Closes: #634696) * apt-pkg/contrib/cdromutl.cc: - fix escape problem when looking for the mounted devices * apt-pkg/contrib/strutl.{h,cc}, test/libapt/strutil_test.cc: - add new DeEscapeString() similar to DeQuoteString but unescape character escapes like \0XX and \xXX (plus added test) * refresh po/* * cmdline/apt-get.cc: - fix missing download progress in apt-get download - do not require unused partial dirs in 'source' (Closes: #633510) - buildconflicts effect all architectures - implement MultiarchCross for build-dep and source (Closes: #632221) * cmdline/apt-key: - use a tmpfile instead of /etc/apt/secring.gpg (Closes: #632596) * debian/apt.postinst: - remove /etc/apt/secring.gpg if it is an empty file * doc/apt-cache.8.xml: - apply madison typofix from John Feuerstein, thanks! (Closes: #633455) * apt-pkg/policy.cc: - emit an error on unknown APT::Default-Release value (Closes: #407511) * apt-pkg/aptconfiguration.cc: - ensure that native architecture is if not specified otherwise the first architecture in the Architectures vector * apt-pkg/deb/deblistparser.cc: - Strip only :any and :native if MultiArch should be stripped as it is save to ignore them in non-MultiArch contexts but if the dependency is a specific architecture (and not the native) do not strip
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/assert.h42
-rw-r--r--test/libapt/getarchitectures_test.cc6
-rw-r--r--test/libapt/getlanguages_test.cc4
-rw-r--r--test/libapt/makefile6
-rw-r--r--test/libapt/strutil_test.cc46
5 files changed, 98 insertions, 6 deletions
diff --git a/test/libapt/assert.h b/test/libapt/assert.h
index 5da76ae0a..92b662dfa 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,45 @@ 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);
+}
+
diff --git a/test/libapt/getarchitectures_test.cc b/test/libapt/getarchitectures_test.cc
index 1500caeed..e3ca7bbc2 100644
--- a/test/libapt/getarchitectures_test.cc
+++ b/test/libapt/getarchitectures_test.cc
@@ -39,6 +39,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..3d63e0e74 100644
--- a/test/libapt/getlanguages_test.cc
+++ b/test/libapt/getlanguages_test.cc
@@ -138,8 +138,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/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;
+}