summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-07-26 12:02:40 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2011-07-26 12:02:40 +0200
commit5af23ac14695d7f09dcd5fa55d1c822de4a05718 (patch)
tree69fad33da1d4f16a78fe89b4f679ee647ce1aa59 /test
parent38c19831778f9bedb8538a65ac5bafed29e1941c (diff)
parentcca2efe60edfae106380a55ee4fb561aa570f2c9 (diff)
merged from lp:~mvo/apt/mvo
Diffstat (limited to 'test')
-rw-r--r--test/libapt/makefile6
-rw-r--r--test/libapt/strutil_test.cc46
2 files changed, 52 insertions, 0 deletions
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 50058262e..fec928ad2 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -46,3 +46,9 @@ PROGRAM = GlobalError${BASENAME}
SLIBS = -lapt-pkg
SOURCE = globalerror_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;
+}