projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tests/lib: C++ify `conds/utils.cpp` a bit
[babeltrace.git]
/
tests
/
lib
/
conds
/
utils.cpp
diff --git
a/tests/lib/conds/utils.cpp
b/tests/lib/conds/utils.cpp
index 7a70e72f4a01a372d7367a6608e700f2cf077416..4df4340c3565624552302948ed9f2fd9dd542fbf 100644
(file)
--- a/
tests/lib/conds/utils.cpp
+++ b/
tests/lib/conds/utils.cpp
@@
-4,45
+4,43
@@
* Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
*/
* Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
*/
-#include <iostream>
-
-#include <glib.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
#include <stdlib.h>
#include <string.h>
#include <babeltrace2/babeltrace.h>
#include "common/assert.h"
+#include "cpp-common/vendor/fmt/core.h"
#include "cpp-common/vendor/nlohmann/json.hpp"
#include "../utils/run-in.hpp"
#include "utils.hpp"
#include "cpp-common/vendor/nlohmann/json.hpp"
#include "../utils/run-in.hpp"
#include "utils.hpp"
-static void run_trigger(const struct cond_trigger *trigger)
+namespace {
+
+void runTrigger(const cond_trigger& trigger) noexcept
{
{
- switch (trigger
->
func_type) {
+ switch (trigger
.
func_type) {
case COND_TRIGGER_FUNC_TYPE_BASIC:
case COND_TRIGGER_FUNC_TYPE_BASIC:
- trigger
->
func.basic();
+ trigger
.
func.basic();
break;
case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT:
break;
case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT:
- runInCompClsInit(trigger
->
func.run_in_comp_cls_init);
+ runInCompClsInit(trigger
.
func.run_in_comp_cls_init);
break;
default:
abort();
}
}
break;
default:
abort();
}
}
-static void list_triggers(const struct cond_trigger triggers[], size_t trigger_count)
+void listTriggers(const bt2s::span<const cond_trigger> triggers) noexcept
{
{
-
nlohmann::json trigger_a
rray = nlohmann::json::array();
+
auto triggerA
rray = nlohmann::json::array();
- for (size_t i = 0; i < trigger_count; i++) {
- nlohmann::json trigger_obj = nlohmann::json::object();
- const cond_trigger& trigger = triggers[i];
+ for (auto& trigger : triggers) {
+ auto triggerObj = nlohmann::json::object();
/* Condition ID */
/* Condition ID */
- trigger
_o
bj["cond-id"] = trigger.cond_id;
+ trigger
O
bj["cond-id"] = trigger.cond_id;
/* Name starts with condition ID */
std::string name = trigger.cond_id;
/* Name starts with condition ID */
std::string name = trigger.cond_id;
@@
-52,28
+50,28
@@
static void list_triggers(const struct cond_trigger triggers[], size_t trigger_c
name += trigger.suffix;
}
name += trigger.suffix;
}
- trigger
_o
bj["name"] = std::move(name);
- trigger
_array.push_back(std::move(trigger_o
bj));
+ trigger
O
bj["name"] = std::move(name);
+ trigger
Array.push_back(std::move(triggerO
bj));
}
}
- auto str = trigger_array.dump();
- std::cout << str;
- std::flush(std::cout);
+ fmt::println("{}", triggerArray.dump());
}
}
-void cond_main(int argc, const char *argv[], const struct cond_trigger triggers[],
- size_t trigger_count)
+} /* namespace */
+
+void condMain(const int argc, const char ** const argv,
+ const bt2s::span<const cond_trigger> triggers) noexcept
{
BT_ASSERT(argc >= 2);
if (strcmp(argv[1], "list") == 0) {
{
BT_ASSERT(argc >= 2);
if (strcmp(argv[1], "list") == 0) {
- list
_triggers(triggers, trigger_count
);
+ list
Triggers(triggers
);
} else if (strcmp(argv[1], "run") == 0) {
int index;
BT_ASSERT(argc >= 3);
index = atoi(argv[2]);
} else if (strcmp(argv[1], "run") == 0) {
int index;
BT_ASSERT(argc >= 3);
index = atoi(argv[2]);
- BT_ASSERT(index >= 0 && index < trigger
_count
);
- run
_trigger(&
triggers[index]);
+ BT_ASSERT(index >= 0 && index < trigger
s.size()
);
+ run
Trigger(
triggers[index]);
}
}
}
}
This page took
0.024162 seconds
and
4
git commands to generate.