aboutsummaryrefslogtreecommitdiffstats
path: root/filedistribution/src/tests/common/testCommon.cpp
blob: 704c9647a5097de87e710176067bc943c49c2124 (plain) (blame)
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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN

#include <vespa/filedistribution/common/buffer.h>

#include <boost/test/unit_test.hpp>
#include <string>

namespace fd = filedistribution;

const size_t bufferCapacity = 10;

fd::Buffer
getBuffer() {
    const char* test = "test";
    fd::Buffer buffer(test, test + strlen(test));
    buffer.reserve(bufferCapacity);
    buffer.push_back(0);
    return buffer;
}

BOOST_AUTO_TEST_CASE(bufferTest) {
    fd::Buffer buffer(getBuffer());
    BOOST_CHECK(buffer.begin() != 0);
    BOOST_CHECK_EQUAL(bufferCapacity, buffer.capacity());
    BOOST_CHECK_EQUAL(5u, buffer.size());
    BOOST_CHECK_EQUAL(std::string("test"), buffer.begin());
}

struct Callback {
    bool* _called;
    Callback(bool *called)
        :_called(called)
    {}

    void operator()(const std::string& str) {
        BOOST_CHECK_EQUAL("abcd", str);
        *_called = true;
    }
};