summaryrefslogtreecommitdiffstats
blob: f1732aea6613a7371f475385054766de1dfe9425 (plain)
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
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <boost/lexical_cast.hpp>

#include <gtest/gtest.h>

#include <Swiften/Base/ByteArray.h>

using namespace Swift;

TEST(ByteArrayTest, testGetData_NoData) {
    ByteArray testling;

    ASSERT_EQ(reinterpret_cast<const char*>(NULL), reinterpret_cast<const char*>(vecptr(testling)));
}

TEST(ByteArrayTest, testToString) {
    ByteArray testling(createByteArray("abcde"));

    ASSERT_EQ(std::string("abcde"), byteArrayToString(testling));
}

TEST(ByteArrayTest, testToString_NullTerminated) {
    ByteArray testling(createByteArray("abcde\0", 6));

    ASSERT_EQ(std::string("abcde"), byteArrayToString(testling));
}

TEST(ByteArrayTest, testToString_TwoNullTerminated) {
    ByteArray testling(createByteArray("abcde\0\0", 7));

    ASSERT_EQ(std::string("abcde"), byteArrayToString(testling));
}

TEST(ByteArrayTest, testToString_AllNull) {
    ByteArray testling(createByteArray("\0\0", 2));

    ASSERT_EQ(std::string(""), byteArrayToString(testling));
}