File: test-fields-bin.cpp

package info (click to toggle)
babeltrace2 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 42,660 kB
  • sloc: cpp: 106,162; ansic: 78,276; python: 27,115; sh: 9,053; makefile: 1,807; xml: 46
file content (57 lines) | stat: -rw-r--r-- 1,531 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
56
57
/*
 * SPDX-License-Identifier: GPL-2.0-only
 *
 * Copyright (C) 2023 EfficiOS Inc.
 */

#include "common/assert.h"

#include "utils/run-in.hpp"

#include "tap/tap.h"

namespace {

constexpr int NR_TESTS = 2;

class TestStringClear final : public RunIn
{
public:
    void onMsgIterInit(const bt2::SelfMessageIterator self) override
    {
        /* Boilerplate to get a string field */
        const auto traceCls = self.component().createTraceClass();
        const auto streamCls = traceCls->createStreamClass();
        const auto eventCls = streamCls->createEventClass();
        const auto payloadCls = traceCls->createStructureFieldClass();

        payloadCls->appendMember("str", *traceCls->createStringFieldClass());
        eventCls->payloadFieldClass(*payloadCls);

        const auto trace = traceCls->instantiate();
        const auto stream = streamCls->instantiate(*trace);
        const auto msg = self.createEventMessage(*eventCls, *stream);
        const auto field = (*msg->event().payloadField())["str"]->asString();

        /* Set the field to a known non-empty value */
        *field = "pomme";
        BT_ASSERT(field.value() == "pomme");

        /* Clear the field, verify its value and length */
        field.clear();
        ok(field.value() == "", "string field is empty");
        ok(field.length() == 0, "string field length is 0");
    }
};

} /* namespace */

int main()
{
    plan_tests(NR_TESTS);

    TestStringClear testStringClear;
    runIn(testStringClear, 0);

    return exit_status();
}