From a513ace2d2e3b71d607257990893199c6105b072 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jul 2011 10:49:28 +0200 Subject: * apt-pkg/contrib/strutl.{h,cc}, test/libapt/strutil_test.cc: - add new DeEscapeString() similar to DeQuoteQuotedWord but unescape charackter escapes like \0XXX and \xXX (plus add test) --- test/libapt/makefile | 6 ++++++ test/libapt/strutil_test.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/libapt/strutil_test.cc (limited to 'test/libapt') 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..8d81a0c6c --- /dev/null +++ b/test/libapt/strutil_test.cc @@ -0,0 +1,40 @@ +#include + +#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); + + return 0; +} -- cgit v1.2.3 From b9dc47069ab90a79ca3b9eae3cc85d38062d57ee Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jul 2011 11:10:47 +0200 Subject: add another escape test case, fixup octal one (its \0XX instead of \0XXX) --- test/libapt/strutil_test.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/libapt') diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc index 8d81a0c6c..af6eb2cc6 100644 --- a/test/libapt/strutil_test.cc +++ b/test/libapt/strutil_test.cc @@ -36,5 +36,11 @@ int main(int argc,char *argv[]) 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; } -- cgit v1.2.3