Skip to content

Commit

Permalink
Fixed sequence diagram test utils (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkryza committed Jan 13, 2025
1 parent 7e3247a commit 1fa698c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
16 changes: 14 additions & 2 deletions tests/t20068/test_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,31 @@ TEST_CASE("t20068")
}));
REQUIRE(MessageChainsOrder(src,
{
//
{
//
{Entrypoint{}, "t20068.cc", "aaa()"}, //
{"t20068.cc", "t20068.cc", "ab()"}, //
{"t20068.cc", "t20068.cc", "a()"} //
}, //
//
} //
}));
REQUIRE(MessageChainsOrder(src,
{
{
//
{Entrypoint{}, "t20068.cc", "aaa()"}, //
{"t20068.cc", "t20068.cc", "aa()"}, //
{"t20068.cc", "t20068.cc", "a()"} //
} //
}));
REQUIRE(!MessageChainsOrder(src,
{
{
//
{Entrypoint{}, "t20068.cc", "aaa()"}, //
{"t20068.cc", "t20068.cc", "ba()"}, //
{"t20068.cc", "t20068.cc", "a()"} //
} //
}));
});
}
3 changes: 3 additions & 0 deletions tests/test_case_utils/test_case_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ int find_message_nested(const nlohmann::json &j, const std::string &from,
if (!chain_index.has_value() && !j.contains("messages"))
return -1;

if (chain_index.has_value() && !j.contains("message_chains"))
return -1;

const auto &messages = !chain_index.has_value()
? j["messages"]
: j["message_chains"][chain_index.value()]["messages"];
Expand Down
23 changes: 14 additions & 9 deletions tests/test_cases.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,21 @@ bool HasMessage(const DiagramType &d, const Message &msg)
template <typename DiagramType>
bool MessageOrder(const DiagramType &d, std::vector<Message> messages)
{
const bool kFail = false;
std::vector<int64_t> order;
int64_t offset{0};
order.reserve(messages.size());
std::transform(messages.begin(), messages.end(), std::back_inserter(order),
[&d, &offset](const auto &m) {
offset = FindMessage(d, m, offset);
offset = FindMessage(d, m, offset, kFail);
return offset;
});
bool are_messages_in_order = std::is_sorted(order.begin(), order.end());

if (!are_messages_in_order) {
FAIL(fmt::format(
"Messages are not in order: \n[{}]", fmt::join(order, ",\n")));
if (kFail)
FAIL(fmt::format(
"Messages are not in order: \n[{}]", fmt::join(order, ",\n")));
return false;
}

Expand Down Expand Up @@ -2010,10 +2012,10 @@ bool MessageChainsOrder<json_t>(
{
const auto sequence_chains_count{
d.src["sequences"][0]["message_chains"].size()};
for (uint32_t chain_index = 0; chain_index < sequence_chains_count;
chain_index++) {
for (const auto &messages : message_chains) {

for (const auto &messages : message_chains) {
for (uint32_t chain_index = 0; chain_index < sequence_chains_count;
chain_index++) {
int64_t offset{0};

std::vector<int64_t> order;
Expand All @@ -2023,14 +2025,19 @@ bool MessageChainsOrder<json_t>(
[&d, &offset, chain_index](const auto &m) -> int64_t {
try {
offset = find_message_in_chain(
d, m, offset, true, chain_index);
d, m, offset, false, chain_index);
return offset;
}
catch (...) {
return 0;
}
});

if (count(order.begin(), order.end(), -1) > 0) {
// One of the messages was not found
continue;
}

bool are_messages_in_order =
std::is_sorted(order.begin(), order.end());

Expand All @@ -2039,8 +2046,6 @@ bool MessageChainsOrder<json_t>(
}
}

FAIL(fmt::format("Messages are not in order"));

return false;
}

Expand Down

0 comments on commit 1fa698c

Please sign in to comment.