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 void testStringClear() noexcept
19 runInMsgIterClsInit([](const bt2::SelfMessageIterator self
) {
20 /* Boilerplate to get a string field */
21 const auto traceCls
= self
.component().createTraceClass();
22 const auto streamCls
= traceCls
->createStreamClass();
23 const auto eventCls
= streamCls
->createEventClass();
24 const auto payloadCls
= traceCls
->createStructureFieldClass();
26 payloadCls
->appendMember("str", *traceCls
->createStringFieldClass());
27 eventCls
->payloadFieldClass(*payloadCls
);
29 const auto trace
= traceCls
->instantiate();
30 const auto stream
= streamCls
->instantiate(*trace
);
31 const auto msg
= self
.createEventMessage(*eventCls
, *stream
);
32 const auto field
= (*msg
->event().payloadField())["str"]->asString();
34 /* Set the field to a known non-empty value */
36 BT_ASSERT(field
.value() == "pomme");
38 /* Clear the field, verify its value and length */
40 ok(field
.value() == "", "string field is empty");
41 ok(field
.length() == 0, "string field length is 0");
This page took 0.036691 seconds and 4 git commands to generate.