summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2013-04-23 08:08:54 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2013-04-23 08:08:54 +0200
commit3444603f5ff2b4c4816e45e686e06e01df31cdc4 (patch)
treeb0e63e9bc86ca6d39f6987381ca7bfa64e186048 /test/libapt
parent52d5690b47bd4efe425fa23d9f6559bb44324cd1 (diff)
parent3278fe66567d149ea92c1afa78941f2bc3c71c85 (diff)
merged debian-sid branch and resolved conflicts
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/assert.h2
-rw-r--r--test/libapt/makefile9
-rwxr-xr-xtest/libapt/run-tests9
-rw-r--r--test/libapt/tagfile_test.cc58
4 files changed, 76 insertions, 2 deletions
diff --git a/test/libapt/assert.h b/test/libapt/assert.h
index fdf6740c6..113c057ed 100644
--- a/test/libapt/assert.h
+++ b/test/libapt/assert.h
@@ -1,4 +1,5 @@
#include <iostream>
+#include <cstdlib>
#define equals(x,y) assertEquals(y, x, __LINE__)
#define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
@@ -6,6 +7,7 @@
template < typename X, typename Y >
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;
+ std::exit(EXIT_FAILURE);
}
template < typename X, typename Y >
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 578f2da4d..969d6e2d9 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -93,7 +93,7 @@ SLIBS = -lapt-pkg
SOURCE = cdromreducesourcelist_test.cc
include $(PROGRAM_H)
-# text IndexCopy::ConvertToSourceList
+# test IndexCopy::ConvertToSourceList
PROGRAM = IndexCopyToSourceList${BASENAME}
SLIBS = -lapt-pkg
SOURCE = indexcopytosourcelist_test.cc
@@ -103,3 +103,10 @@ PROGRAM = FileUtl${BASENAME}
SLIBS = -lapt-pkg
SOURCE = fileutl_test.cc
include $(PROGRAM_H)
+
+# test tagfile
+PROGRAM = PkgTagFile${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = tagfile_test.cc
+include $(PROGRAM_H)
+
diff --git a/test/libapt/run-tests b/test/libapt/run-tests
index 45a3157f7..f18be6d2b 100755
--- a/test/libapt/run-tests
+++ b/test/libapt/run-tests
@@ -7,6 +7,7 @@ echo "Compiling the tests …"
echo "Running all testcases …"
LDPATH="$DIR/../../build/bin"
EXT="_libapt_test"
+EXIT_CODE=0
# detect if output is on a terminal (colorful) or better not
if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null; then
@@ -106,9 +107,15 @@ do
fi
echo -n "Testing with ${NAME} "
- LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} && echo "$TESTOKAY" || echo "$TESTFAIL"
+ if LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} ; then
+ echo "$TESTOKAY"
+ else
+ echo "$TESTFAIL"
+ EXIT_CODE=1
+ fi
if [ -n "$tmppath" -a -d "$tmppath" ]; then
rm -rf "$tmppath"
fi
done
+exit $EXIT_CODE
diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc
new file mode 100644
index 000000000..d12c74c95
--- /dev/null
+++ b/test/libapt/tagfile_test.cc
@@ -0,0 +1,58 @@
+#include <apt-pkg/fileutl.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[])
+{
+ FileFd fd;
+ const char contents[] = "FieldA-12345678: the value of the field";
+ 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);
+
+ pkgTagFile tfile(&fd);
+ pkgTagSection section;
+ equals(tfile.Step(section), true);
+
+ /* It has one field */
+ equals(section.Count(), 1);
+
+ /* ... and it is called FieldA-12345678 */
+ equals(section.Exists("FieldA-12345678"), true);
+
+ /* its value is correct */
+ equals(section.FindS("FieldA-12345678"), std::string("the value of the field"));
+ /* A non-existent field has an empty string as value */
+ equals(section.FindS("FieldB-12345678"), std::string());
+
+ /* ... and Exists does not lie about missing fields... */
+ equalsNot(section.Exists("FieldB-12345678"), true);
+
+ /* There is only one section in this tag file */
+ equals(tfile.Step(section), false);
+
+ /* clean up handled by atexit handler, so just return here */
+ return 0;
+}