summaryrefslogtreecommitdiffstats
path: root/vbench/src/tests/memory/memory_test.cpp
blob: 9504914d191252c0926ac219dba221d13c6e590e (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/testapp.h>
#include <vbench/test/all.h>

using namespace vbench;

TEST("empty memory") {
    Memory m;
    EXPECT_EQUAL((const char*)0, m.data);
    EXPECT_EQUAL(0u, m.size);
}

TEST("from string") {
    string str("foo");
    Memory m1(str);
    Memory m2 = str;
    EXPECT_EQUAL(str.data(), m1.data);
    EXPECT_EQUAL(str.size(), m1.size);
    EXPECT_EQUAL(str.data(), m2.data);
    EXPECT_EQUAL(str.size(), m2.size);
}

TEST("from cstring") {
    const char *str = "foo";
    Memory m1(str);
    Memory m2 = str;
    EXPECT_EQUAL(str, m1.data);
    EXPECT_EQUAL(strlen(str), m1.size);
    EXPECT_EQUAL(str, m2.data);
    EXPECT_EQUAL(strlen(str), m2.size);
}

TEST("from ptr and len") {
    string str("foo");
    Memory m1(str.data(), str.size());
    EXPECT_EQUAL(str.data(), m1.data);
    EXPECT_EQUAL(str.size(), m1.size);
}

TEST_MAIN() { TEST_RUN_ALL(); }