File: buffer.cpp

package info (click to toggle)
libfilezilla 0.52.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,492 kB
  • sloc: cpp: 30,965; sh: 4,241; makefile: 375; xml: 37
file content (64 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
#include "../lib/libfilezilla/buffer.hpp"

#include "test_utils.hpp"

#include <string.h>

class buffer_test final : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE(buffer_test);
	CPPUNIT_TEST(test_simple);
	CPPUNIT_TEST(test_append);
	CPPUNIT_TEST_SUITE_END();

public:
	void setUp() {}
	void tearDown() {}

	void test_simple();
	void test_append();
};

CPPUNIT_TEST_SUITE_REGISTRATION(buffer_test);

void buffer_test::test_simple()
{
	fz::buffer buf;
	buf.append("foo");
	buf.append("bar");

	ASSERT_EQUAL(size_t(6), buf.size());

	buf.consume(3);
	buf.append("baz");

	ASSERT_EQUAL(size_t(6), buf.size());

	fz::buffer buf2;
	memcpy(buf2.get(42), "barbaz", 6);
	buf2.add(6);

	CPPUNIT_ASSERT(buf == buf2);
}

void buffer_test::test_append()
{
	fz::buffer buf;
	buf.reserve(10);
	size_t const cap = buf.capacity();
	buf.add(cap);
	for (size_t i = 0; i < cap; ++i) {
		buf[i] = static_cast<unsigned char>(i);
	}
	buf.consume(5);
	buf.append(buf.get(), 5);
	CPPUNIT_ASSERT(buf.size() == buf.capacity());

	for (size_t i = 0; i < cap - 5; ++i) {
		CPPUNIT_ASSERT(buf[i] == static_cast<unsigned char>(i + 5));
	}

	for (size_t i = 0; i < 5; ++i) {
		CPPUNIT_ASSERT(buf[cap - 5 + i] == static_cast<unsigned char>(i + 5));
	}
}