forked from aria2/aria2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferedFileTest.cc
58 lines (41 loc) · 1.44 KB
/
BufferedFileTest.cc
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 "BufferedFile.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
#include "File.h"
namespace aria2 {
class BufferedFileTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(BufferedFileTest);
CPPUNIT_TEST(testOpen);
CPPUNIT_TEST_SUITE_END();
public:
void testOpen();
};
CPPUNIT_TEST_SUITE_REGISTRATION(BufferedFileTest);
void BufferedFileTest::testOpen()
{
File f(A2_TEST_OUT_DIR "/aria2_BufferedFileTest_testOpen");
f.remove();
BufferedFile fail(f.getPath().c_str(), IOFile::READ);
CPPUNIT_ASSERT(!fail);
BufferedFile wr(f.getPath().c_str(), IOFile::WRITE);
CPPUNIT_ASSERT(wr);
std::string msg = "aria2 rules\nalpha\nbravo\ncharlie";
wr.write(msg.data(), msg.size());
wr.close();
BufferedFile rd(f.getPath().c_str(), IOFile::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