cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / tests / lib / test-fields-bin.cpp
1 /*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Copyright (C) 2023 EfficiOS Inc.
5 */
6
7 #include "common/assert.h"
8
9 #include "utils/run-in.hpp"
10
11 #include "tap/tap.h"
12
13 namespace {
14
15 constexpr int NR_TESTS = 2;
16
17 class TestStringClear final : public RunIn
18 {
19 public:
20 void onMsgIterInit(const bt2::SelfMessageIterator self) override
21 {
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();
27
28 payloadCls->appendMember("str", *traceCls->createStringFieldClass());
29 eventCls->payloadFieldClass(*payloadCls);
30
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();
35
36 /* Set the field to a known non-empty value */
37 *field = "pomme";
38 BT_ASSERT(field.value() == "pomme");
39
40 /* Clear the field, verify its value and length */
41 field.clear();
42 ok(field.value() == "", "string field is empty");
43 ok(field.length() == 0, "string field length is 0");
44 }
45 };
46
47 } /* namespace */
48
49 int main()
50 {
51 plan_tests(NR_TESTS);
52
53 TestStringClear testStringClear;
54 runIn(testStringClear);
55
56 return exit_status();
57 }
This page took 0.030016 seconds and 4 git commands to generate.