-
Notifications
You must be signed in to change notification settings - Fork 2
/
mime-binary_body-tests.cpp
72 lines (51 loc) · 1.86 KB
/
mime-binary_body-tests.cpp
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
69
70
71
72
/**
Copyright 2010-2019 Red Anchor Trading Co. Ltd.
Distributed under the Boost Software License, Version 1.0.
See <http://www.boost.org/LICENSE_1_0.txt>
*/
#include "fost-inet-test.hpp"
#include <fost/mime.hpp>
#include <fost/exception/unicode_encoding.hpp>
using namespace fostlib;
FSL_TEST_SUITE(mime__binary_body);
FSL_TEST_FUNCTION(constructor) {
std::vector<unsigned char> data(256, 123);
binary_body body(data);
FSL_CHECK(body.data() == data);
}
FSL_TEST_FUNCTION(iterator) {
std::vector<unsigned char> data(256, 123);
binary_body body(data);
const_memory_block block = *body.begin();
FSL_CHECK_EQ(bytes(block), 256u);
for (const unsigned char *c(
reinterpret_cast<const unsigned char *>(block.first));
c != block.second; ++c)
FSL_CHECK_EQ(*c, 123);
}
FSL_TEST_FUNCTION(convert_to_text_empty) {
std::vector<unsigned char> data(256, 0);
binary_body body(data);
FSL_CHECK_EQ(coerce<utf8_string>(body), coerce<utf8_string>(data));
}
FSL_TEST_FUNCTION(convert_to_text_fails) {
std::vector<unsigned char> data(256, 0x80);
binary_body body(data);
FSL_CHECK_EXCEPTION(
coerce<string>(body), fostlib::exceptions::unicode_encoding &);
}
FSL_TEST_FUNCTION(construct_from_byte_array) {
std::vector<char> data(256, 0x20);
binary_body body(&data[0], &data[0] + data.size());
FSL_CHECK_EQ(coerce<string>(body), string(256, ' '));
}
FSL_TEST_FUNCTION(construct_from_signed_byte_array) {
std::vector<signed char> data(256, 0x20);
binary_body body(&data[0], &data[0] + data.size());
FSL_CHECK_EQ(coerce<string>(body), string(256, ' '));
}
FSL_TEST_FUNCTION(construct_from_unsigned_byte_array) {
std::vector<unsigned char> data(256, 0x20);
binary_body body(&data[0], &data[0] + data.size());
FSL_CHECK_EQ(coerce<string>(body), string(256, ' '));
}