[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[RFC PATCH 2/3] Add test for using ExtractTar on compressed files



Git-Dch: ignore
---
 test/libapt/extracttar_test.cc | 37 +++++++++++++++++++++++++++++++++++++
 test/libapt/makefile           |  6 ++++++
 2 files changed, 43 insertions(+)
 create mode 100644 test/libapt/extracttar_test.cc

diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc
new file mode 100644
index 0000000..592acb0
--- /dev/null
+++ b/test/libapt/extracttar_test.cc
@@ -0,0 +1,37 @@
+#include <apt-pkg/error.h>
+#include <apt-pkg/extracttar.h>
+#include <iostream>
+#include <stdlib.h>
+
+#include "assert.h"
+class Stream : public pkgDirStream
+{
+   public:
+    int count;
+    Stream () { count = 0; }
+    virtual bool DoItem(Item &Itm,int &Fd) { (void)Itm; (void)Fd; count++; return true; }
+    virtual bool Fail(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; }
+    virtual bool FinishedFile(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; }
+    virtual bool Process(Item &Itm,const unsigned char * Data, unsigned long Size,unsigned long Pos) { (void)Itm; (void) Data; (void) Size; (void) Pos; return true; }
+    virtual ~Stream() {}
+};
+
+int main(void)
+{
+    if (system("tar c makefile | gzip > tar.tgz") != 0)
+        return 1;
+    FileFd fd("tar.tgz", FileFd::ReadOnly);
+    unlink("tar.tgz");
+    ExtractTar tar(fd, -1, "gzip");
+
+    // Run multiple times, because we want to check not only that extraction
+    // works, but also that it works multiple times (important for python-apt)
+    for (int i = 0; i < 5; i++) {
+        Stream stream;
+        fd.Seek(0);
+        tar.Go(stream);
+        if (_error->PendingError())
+            return _error->DumpErrors(), 1;
+        equals(stream.count, 1);
+    }
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 66d6ea7..1cb049d 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -123,3 +123,9 @@ SLIBS = -lapt-pkg
 SOURCE = sourcelist_test.cc
 include $(PROGRAM_H)
 
+# test sourcelist
+PROGRAM = ExtractTar${BASENAME}
+SLIBS = -lapt-pkg -lapt-inst
+SOURCE = extracttar_test.cc
+include $(PROGRAM_H)
+
-- 
1.9.0


Reply to: