Debian Codegraph @

src/mpt/string/tests/tests_string_buffer.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_STRING_TESTS_STRING_BUFFER_HPP
4 #define MPT_STRING_TESTS_STRING_BUFFER_HPP
5
6
7
8 #include "mpt/base/detect_compiler.hpp"
9 #include "mpt/base/namespace.hpp"
10 #include "mpt/string/buffer.hpp"
11 #include "mpt/test/test.hpp"
12 #include "mpt/test/test_macros.hpp"
13
14 #include <string>
15
16
17
18 namespace mpt {
19 inline namespace MPT_INLINE_NS {
20
21
22
23 namespace tests {
24 namespace string {
25 namespace buffer {
26
27 #if MPT_COMPILER_CLANG
28 #pragma clang diagnostic push
29 #pragma clang diagnostic ignored "-Wglobal-constructors"
30 #endif
31 MPT_TEST_GROUP_INLINE("mpt/string/buffer")
32 #if MPT_COMPILER_CLANG
33 #pragma clang diagnostic pop
34 #endif
35 {
36 {
37 char buf[4] = {'x', 'x', 'x', 'x'};
38 mpt::WriteAutoBuf(buf) = std::string("foobar");
39 MPT_TEST_EXPECT_EQUAL(buf[0], 'f');
40 MPT_TEST_EXPECT_EQUAL(buf[1], 'o');
41 MPT_TEST_EXPECT_EQUAL(buf[2], 'o');
42 MPT_TEST_EXPECT_EQUAL(buf[3], '\0');
43 }
44 {
45 char buf[4] = {'x', 'x', 'x', 'x'};
46 char foobar[] = {'f', 'o', 'o', 'b', 'a', 'r', '\0'};
47 mpt::WriteTypedBuf<std::string>(buf) = (char *)foobar;
48 MPT_TEST_EXPECT_EQUAL(buf[0], 'f');
49 MPT_TEST_EXPECT_EQUAL(buf[1], 'o');
50 MPT_TEST_EXPECT_EQUAL(buf[2], 'o');
51 MPT_TEST_EXPECT_EQUAL(buf[3], '\0');
52 }
53 {
54 char buf[4] = {'x', 'x', 'x', 'x'};
55 mpt::WriteTypedBuf<std::string>(buf) = (const char *)"foobar";
56 MPT_TEST_EXPECT_EQUAL(buf[0], 'f');
57 MPT_TEST_EXPECT_EQUAL(buf[1], 'o');
58 MPT_TEST_EXPECT_EQUAL(buf[2], 'o');
59 MPT_TEST_EXPECT_EQUAL(buf[3], '\0');
60 }
61 {
62 char buf[4] = {'x', 'x', 'x', 'x'};
63 mpt::WriteTypedBuf<std::string>(buf) = "foobar";
64 MPT_TEST_EXPECT_EQUAL(buf[0], 'f');
65 MPT_TEST_EXPECT_EQUAL(buf[1], 'o');
66 MPT_TEST_EXPECT_EQUAL(buf[2], 'o');
67 MPT_TEST_EXPECT_EQUAL(buf[3], '\0');
68 }
69 {
70 const char buf[4] = {'f', 'o', 'o', 'b'};
71 std::string foo = mpt::ReadAutoBuf(buf);
72 MPT_TEST_EXPECT_EQUAL(foo, std::string("foob"));
73 }
74 }
75
76 } // namespace buffer
77 } // namespace string
78 } // namespace tests
79
80
81
82 } // namespace MPT_INLINE_NS
83 } // namespace mpt
84
85
86
87 #endif // MPT_STRING_TESTS_STRING_BUFFER_HPP