You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.3 KiB

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