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 65 66 67 68
|
#include <wibble/config.h>
#include <wibble/sys/buffer.h>
using namespace std;
using namespace wibble::sys;
#include <wibble/tests/tut-wibble.h>
namespace tut {
struct sys_buffer_shar {};
TESTGRP( sys_buffer );
// Empty buffers should be properly empty
template<> template<>
void to::test< 1 >() {
Buffer buf;
ensure_equals(buf.size(), 0u);
ensure_equals(buf.data(), (void*)0);
}
// Nonempty buffers should be properly nonempty
template<> template<>
void to::test< 2 >() {
Buffer buf(1);
ensure_equals(buf.size(), 1u);
ensure(buf.data() != 0);
}
// Construct by copy should work
template<> template<>
void to::test< 3 >() {
const char* str = "Ciao";
Buffer buf(str, 4);
ensure_equals(buf.size(), 4u);
ensure(memcmp(str, buf.data(), 4) == 0);
}
// Resize should work and preserve the contents
template<> template<>
void to::test< 4 >() {
const char* str = "Ciao";
Buffer buf(str, 4);
ensure_equals(buf.size(), 4u);
ensure(memcmp(str, buf.data(), 4) == 0);
buf.resize(8);
ensure_equals(buf.size(), 8u);
ensure(memcmp(str, buf.data(), 4) == 0);
}
// Check creation by taking ownership of another buffer
template<> template<>
void to::test< 5 >() {
char* str = new char[4];
memcpy(str, "ciao", 4);
Buffer buf(str, 4, true);
ensure_equals(buf.size(), 4u);
ensure_equals((void*)str, buf.data());
}
}
// vim:set ts=4 sw=4:
|