File: GZipFileTest.cc

package info (click to toggle)
aria2 1.37.0%2Bdebian-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,128 kB
  • sloc: cpp: 115,006; ansic: 9,140; makefile: 1,466; ruby: 475; python: 373; sh: 260; xml: 176
file content (58 lines) | stat: -rw-r--r-- 1,446 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "GZipFile.h"

#include <iostream>

#include <cppunit/extensions/HelperMacros.h>

#include "File.h"

namespace aria2 {

class GZipFileTest : public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE(GZipFileTest);
  CPPUNIT_TEST(testOpen);
  CPPUNIT_TEST_SUITE_END();

public:
  void testOpen();
};

CPPUNIT_TEST_SUITE_REGISTRATION(GZipFileTest);

void GZipFileTest::testOpen()
{
  File f(A2_TEST_OUT_DIR "/aria2_GZipFileTest_testOpen");
  f.remove();
  GZipFile fail(f.getPath().c_str(), GZipFile::READ);
  CPPUNIT_ASSERT(!fail);

  GZipFile wr(f.getPath().c_str(), GZipFile::WRITE);
  CPPUNIT_ASSERT(wr);
  std::string msg = "aria2 rules\nalpha\nbravo\ncharlie";
  wr.write(msg.data(), msg.size());
  wr.close();

  GZipFile rd(f.getPath().c_str(), GZipFile::READ);
  char buf[256];
  size_t len = rd.read(buf, 11);
  CPPUNIT_ASSERT_EQUAL((size_t)11, len);
  buf[len] = '\0';
  CPPUNIT_ASSERT_EQUAL(std::string("aria2 rules"), std::string(buf));

  CPPUNIT_ASSERT(rd.gets(buf, sizeof(buf)));
  CPPUNIT_ASSERT_EQUAL(std::string("\n"), std::string(buf));

  CPPUNIT_ASSERT(rd.gets(buf, sizeof(buf)));
  CPPUNIT_ASSERT_EQUAL(std::string("alpha\n"), std::string(buf));

  CPPUNIT_ASSERT(rd.getsn(buf, sizeof(buf)));
  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), std::string(buf));

  CPPUNIT_ASSERT(rd.getsn(buf, sizeof(buf)));
  CPPUNIT_ASSERT_EQUAL(std::string("charlie"), std::string(buf));

  CPPUNIT_ASSERT(rd.eof());
}

} // namespace aria2