2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2023 EfficiOS Inc.
7 #include "common/assert.h"
9 #include "utils/run-in.hpp"
15 constexpr int NR_TESTS
= 2;
17 class TestStringClear final
: public RunIn
20 void onMsgIterInit(const bt2::SelfMessageIterator self
) override
22 /* Boilerplate to get a string field */
23 const auto traceCls
= self
.component().createTraceClass();
24 const auto streamCls
= traceCls
->createStreamClass();
25 const auto eventCls
= streamCls
->createEventClass();
26 const auto payloadCls
= traceCls
->createStructureFieldClass();
28 payloadCls
->appendMember("str", *traceCls
->createStringFieldClass());
29 eventCls
->payloadFieldClass(*payloadCls
);
31 const auto trace
= traceCls
->instantiate();
32 const auto stream
= streamCls
->instantiate(*trace
);
33 const auto msg
= self
.createEventMessage(*eventCls
, *stream
);
34 const auto field
= (*msg
->event().payloadField())["str"]->asString();
36 /* Set the field to a known non-empty value */
38 BT_ASSERT(field
.value() == "pomme");
40 /* Clear the field, verify its value and length */
42 ok(field
.value() == "", "string field is empty");
43 ok(field
.length() == 0, "string field length is 0");
53 TestStringClear testStringClear
;
54 runIn(testStringClear
);