cpp-common/bt2c: add `format_as()` functions for `Uuid` and `UuidView`
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 22 Mar 2024 02:29:30 +0000 (22:29 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
Change-Id: I6530144e78d6aa10dedb320b90a4c208aa572e9d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12138
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2c/fmt.hpp
tests/Makefile.am
tests/cpp-common/test-uuid.cpp [new file with mode: 0644]

index 8db4b1b630b88cf731bd0141e4ddd1fd83091990..8af3d71e49ca84f0205fb6f20e112ea84e5a5aed 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "common/common.h"
 #include "cpp-common/bt2/message.hpp"
+#include "cpp-common/bt2c/uuid.hpp"
 #include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */
 
 namespace bt2 {
@@ -16,3 +17,12 @@ inline const char *format_as(const MessageType type)
 }
 
 } /* namespace bt2 */
+
+namespace bt2c {
+
+inline std::string format_as(const UuidView uuid)
+{
+    return uuid.str();
+}
+
+} /* namespace bt2c */
index 88c385e00349d3d7d6bf121a0dcbc929f86ee177..6136c771b6d201765150ca83d45b1d302983f888 100644 (file)
@@ -100,8 +100,19 @@ cpp_common_test_c_string_view_SOURCES = \
 cpp_common_test_c_string_view_LDADD = \
        $(COMMON_TEST_LDADD)
 
+noinst_PROGRAMS += \
+       cpp-common/test-uuid
+
+cpp_common_test_uuid_SOURCES = \
+       cpp-common/test-uuid.cpp
+
+cpp_common_test_uuid_LDADD = \
+       $(COMMON_TEST_LDADD) \
+       $(top_builddir)/src/cpp-common/vendor/fmt/libfmt.la
+
 TESTS_CPP_COMMON = \
-       cpp-common/test-c-string-view
+       cpp-common/test-c-string-view \
+       cpp-common/test-uuid
 
 TESTS_LIB = \
        lib/test-bt-uuid \
diff --git a/tests/cpp-common/test-uuid.cpp b/tests/cpp-common/test-uuid.cpp
new file mode 100644 (file)
index 0000000..a84ed38
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2024 EfficiOS, Inc.
+ */
+
+#include "cpp-common/bt2c/fmt.hpp"
+#include "cpp-common/bt2c/uuid.hpp"
+#include "cpp-common/vendor/fmt/format.h"
+
+#include "tap/tap.h"
+
+namespace {
+
+constexpr auto uuidStr = "c2281e4a-699b-4b78-903f-2f8407fe2b77";
+const bt2c::Uuid uuid {uuidStr};
+const bt2c::UuidView uuidView {uuid};
+
+void testFormatAs()
+{
+    const auto resUuid = fmt::to_string(uuid);
+    const auto resUuidView = fmt::to_string(uuidView);
+
+    ok(resUuid == uuidStr, "result of format_as() for `Uuid` is expected");
+    ok(resUuidView == uuidStr, "result of format_as() for `UuidView` is expected");
+}
+
+} /* namespace */
+
+int main()
+{
+    plan_tests(2);
+    testFormatAs();
+    return exit_status();
+}
This page took 0.025245 seconds and 4 git commands to generate.