|
1 | 1 | #include <string> |
2 | 2 | #include <vector> |
| 3 | +#include <array> |
3 | 4 | #include <sstream> |
4 | 5 | #include <catch.hpp> |
5 | 6 | #include "cppkafka/buffer.h" |
6 | 7 |
|
7 | 8 | using std::string; |
8 | 9 | using std::vector; |
| 10 | +using std::array; |
9 | 11 | using std::ostringstream; |
10 | 12 |
|
11 | 13 | using namespace cppkafka; |
@@ -36,14 +38,32 @@ TEST_CASE("conversions", "[buffer]") { |
36 | 38 | } |
37 | 39 |
|
38 | 40 | TEST_CASE("construction", "[buffer]") { |
| 41 | + // From string |
39 | 42 | const string str_data = "Hello world!"; |
40 | | - const vector<uint8_t> data(str_data.begin(), str_data.end()); |
41 | | - const Buffer buffer(data); |
42 | | - const Buffer buffer2(data.begin(), data.end()); |
43 | | - const Buffer buffer3(str_data.data(), str_data.data() + str_data.size()); |
| 43 | + // From vector |
| 44 | + const vector<uint8_t> vector_data(str_data.begin(), str_data.end()); |
| 45 | + // From array |
| 46 | + const array<char,12> array_data{'H','e','l','l','o',' ','w','o','r','l','d','!'}; |
| 47 | + // From raw array |
| 48 | + const char raw_array[12]{'H','e','l','l','o',' ','w','o','r','l','d','!'}; |
| 49 | + |
| 50 | + // Build buffers |
| 51 | + const Buffer buffer(vector_data); //vector |
| 52 | + const Buffer buffer2(vector_data.begin(), vector_data.end()); //iterators |
| 53 | + const Buffer buffer3(str_data.data(), str_data.data() + str_data.size()); //char iterators |
| 54 | + const Buffer buffer4(array_data); //arrays |
| 55 | + const Buffer buffer5(raw_array); //raw arrays |
| 56 | + const Buffer buffer6(str_data); //string |
| 57 | + const Buffer buffer7(str_data.data(), str_data.size()); //type + size |
| 58 | + |
| 59 | + // Test |
44 | 60 | CHECK(str_data == buffer); |
45 | 61 | CHECK(buffer == buffer2); |
46 | 62 | CHECK(buffer == buffer3); |
| 63 | + CHECK(buffer == buffer4); |
| 64 | + CHECK(buffer == buffer5); |
| 65 | + CHECK(buffer == buffer6); |
| 66 | + CHECK(buffer == buffer7); |
47 | 67 | } |
48 | 68 |
|
49 | 69 |
|
|
0 commit comments