File: writer_test_cases.cpp

package info (click to toggle)
protozero 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,548 kB
  • sloc: cpp: 20,364; sh: 18; makefile: 14
file content (55 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (2)
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

#include <buffer.hpp>

#include "t/bytes/bytes_testcase.pb.h"

TEMPLATE_TEST_CASE("write bytes field and check with libprotobuf", "",
    buffer_test_string, buffer_test_vector, buffer_test_array, buffer_test_external) {

    TestType buffer;
    typename TestType::writer_type pw{buffer.buffer()};

    TestBytes::Test msg;

    SECTION("empty") {
        pw.add_string(1, "");

        msg.ParseFromArray(buffer.data(), buffer.size());

        REQUIRE(msg.s().empty());
    }

    SECTION("one") {
        pw.add_string(1, "x");

        msg.ParseFromArray(buffer.data(), buffer.size());

        REQUIRE(msg.s() == "x");
    }

    SECTION("string") {
        pw.add_string(1, "foobar");

        msg.ParseFromArray(buffer.data(), buffer.size());

        REQUIRE(msg.s() == "foobar");
    }

    SECTION("binary") {
        std::string data;
        data.append(1, static_cast<char>(1));
        data.append(1, static_cast<char>(2));
        data.append(1, static_cast<char>(3));

        pw.add_string(1, data);

        msg.ParseFromArray(buffer.data(), buffer.size());

        REQUIRE(msg.s().size() == 3);
        REQUIRE(msg.s()[1] == static_cast<char>(2));
        REQUIRE(msg.s()[2] == static_cast<char>(3));
        REQUIRE(msg.s()[2] == static_cast<char>(3));
    }

}