]> git.saurik.com Git - apt.git/blame - test/libapt/extracttar_test.cc
Get rid of the old buildsystem
[apt.git] / test / libapt / extracttar_test.cc
CommitLineData
992a1e83
JAK
1#include <apt-pkg/error.h>
2#include <apt-pkg/extracttar.h>
3#include <iostream>
4#include <stdlib.h>
5
6#include <gtest/gtest.h>
7#include "assert.h"
8
9class Stream : public pkgDirStream
10{
11 public:
12 int count;
13 Stream () { count = 0; }
14 virtual bool DoItem(Item &Itm,int &Fd) { (void)Itm; (void)Fd; count++; return true; }
15 virtual bool Fail(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; }
16 virtual bool FinishedFile(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; }
17 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; }
18 virtual ~Stream() {}
19};
20
21TEST(ExtractTar, ExtractTar)
22{
b7aa74a1 23 EXPECT_EQ(system("tar c /etc/passwd 2>/dev/null | gzip > tar.tgz"), 0);
992a1e83
JAK
24
25 FileFd fd("tar.tgz", FileFd::ReadOnly);
26 unlink("tar.tgz");
27 ExtractTar tar(fd, -1, "gzip");
28
29 // Run multiple times, because we want to check not only that extraction
30 // works, but also that it works multiple times (important for python-apt)
31 for (int i = 0; i < 5; i++) {
32 Stream stream;
33 fd.Seek(0);
34 tar.Go(stream);
35 if (_error->PendingError()) {
36 _error->DumpErrors();
37 EXPECT_FALSE(true);
38 }
39 EXPECT_EQ(stream.count, 1);
40 }
41}