-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring sequence diagrams test cases (#266)
- Loading branch information
Showing
49 changed files
with
3,233 additions
and
2,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* tests/t20001/test_case.cc | ||
* tests/t20001/test_case.h | ||
* | ||
* Copyright (c) 2021-2024 Bartek Kryza <[email protected]> | ||
* | ||
|
@@ -16,18 +16,66 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
TEST_CASE("t20001", "[test-case][sequence]") | ||
TEST_CASE("t20001") | ||
{ | ||
auto [config, db] = load_config("t20001"); | ||
using namespace clanguml::test; | ||
|
||
auto diagram = config.diagrams["t20001_sequence"]; | ||
auto [config, db, diagram, model] = | ||
CHECK_SEQUENCE_MODEL("t20001", "t20001_sequence"); | ||
|
||
REQUIRE(diagram->name == "t20001_sequence"); | ||
CHECK_SEQUENCE_DIAGRAM( | ||
config, diagram, *model, | ||
[](const auto &src) { | ||
REQUIRE(HasTitle(src, "Basic sequence diagram example")); | ||
|
||
auto model = generate_sequence_diagram(*db, diagram); | ||
REQUIRE(MessageOrder(src, | ||
{ | ||
// | ||
{"tmain()", "A", "A()"}, // | ||
{"tmain()", "B", "B(A &)"}, // | ||
|
||
REQUIRE(model->name() == "t20001_sequence"); | ||
{"tmain()", "A", "add(int,int)"}, // | ||
|
||
{"tmain()", "B", "wrap_add3(int,int,int)"}, // | ||
{"B", "A", "add3(int,int,int)"}, // | ||
{"A", "A", "add(int,int)"}, // | ||
{"A", "A", "log_result(int)", Static{}}, // | ||
{"B", "A", "log_result(int)", Static{}} // | ||
})); | ||
|
||
REQUIRE(!HasMessage(src, {"A", {"detail", "C"}, "add(int,int)"})); | ||
|
||
REQUIRE(HasComment(src, "t20001 test diagram of type sequence")); | ||
|
||
REQUIRE(HasMessageComment(src, "tmain()", "Just add 2 numbers")); | ||
|
||
REQUIRE(HasMessageComment(src, "tmain()", "And now add another 2")); | ||
}, | ||
[](const json_t &src) { | ||
const auto &A = get_participant(src.src, "A"); | ||
|
||
CHECK(A.has_value()); | ||
|
||
CHECK(A.value()["type"] == "class"); | ||
CHECK(A.value()["name"] == "A"); | ||
CHECK(A.value()["display_name"] == "A"); | ||
CHECK(A.value()["namespace"] == "clanguml::t20001"); | ||
CHECK(A.value()["source_location"]["file"] == "t20001.cc"); | ||
CHECK(A.value()["source_location"]["line"] == 13); | ||
|
||
const auto &tmain = get_participant(src.src, "tmain()"); | ||
|
||
CHECK(tmain.has_value()); | ||
|
||
CHECK(tmain.value()["type"] == "function"); | ||
CHECK(tmain.value()["name"] == "tmain"); | ||
CHECK(tmain.value()["display_name"] == "tmain()"); | ||
CHECK(tmain.value()["namespace"] == "clanguml::t20001"); | ||
CHECK(tmain.value()["source_location"]["file"] == "t20001.cc"); | ||
CHECK(tmain.value()["source_location"]["line"] == 61); | ||
}); | ||
|
||
/* | ||
{ | ||
auto src = generate_sequence_puml(diagram, *model); | ||
AliasMatcher _A(src); | ||
|
@@ -118,4 +166,5 @@ TEST_CASE("t20001", "[test-case][sequence]") | |
save_mermaid(config.output_directory(), diagram->name + ".mmd", src); | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* tests/t20002/test_case.cc | ||
* tests/t20002/test_case.h | ||
* | ||
* Copyright (c) 2021-2024 Bartek Kryza <[email protected]> | ||
* | ||
|
@@ -16,18 +16,28 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
TEST_CASE("t20002", "[test-case][sequence]") | ||
TEST_CASE("t20002") | ||
{ | ||
auto [config, db] = load_config("t20002"); | ||
|
||
auto diagram = config.diagrams["t20002_sequence"]; | ||
|
||
REQUIRE(diagram->name == "t20002_sequence"); | ||
|
||
auto model = generate_sequence_diagram(*db, diagram); | ||
|
||
REQUIRE(model->name() == "t20002_sequence"); | ||
|
||
using namespace clanguml::test; | ||
|
||
auto [config, db, diagram, model] = | ||
CHECK_SEQUENCE_MODEL("t20002", "t20002_sequence"); | ||
|
||
CHECK_SEQUENCE_DIAGRAM(config, diagram, *model, [](const auto &src) { | ||
REQUIRE(IsFunctionParticipant(src, "m1()")); | ||
REQUIRE(IsFunctionParticipant(src, "m2()")); | ||
REQUIRE(IsFunctionParticipant(src, "m3()")); | ||
REQUIRE(IsFunctionParticipant(src, "m4()")); | ||
|
||
REQUIRE(MessageOrder(src, | ||
{ | ||
// | ||
{"m1()", "m2()", ""}, // | ||
{"m2()", "m3()", ""}, // | ||
{"m3()", "m4()", ""} // | ||
})); | ||
}); | ||
/* | ||
{ | ||
auto src = generate_sequence_puml(diagram, *model); | ||
AliasMatcher _A(src); | ||
|
@@ -72,5 +82,5 @@ TEST_CASE("t20002", "[test-case][sequence]") | |
REQUIRE_THAT(src, HasCall(_A("m3()"), _A("m4()"), "")); | ||
save_mermaid(config.output_directory(), diagram->name + ".mmd", src); | ||
} | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* tests/t20003/test_case.cc | ||
* tests/t20003/test_case.h | ||
* | ||
* Copyright (c) 2021-2024 Bartek Kryza <[email protected]> | ||
* | ||
|
@@ -16,56 +16,67 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
TEST_CASE("t20003", "[test-case][sequence]") | ||
TEST_CASE("t20003") | ||
{ | ||
auto [config, db] = load_config("t20003"); | ||
using namespace clanguml::test; | ||
|
||
auto diagram = config.diagrams["t20003_sequence"]; | ||
auto [config, db, diagram, model] = | ||
CHECK_SEQUENCE_MODEL("t20003", "t20003_sequence"); | ||
|
||
REQUIRE(diagram->name == "t20003_sequence"); | ||
CHECK_SEQUENCE_DIAGRAM(config, diagram, *model, [](const auto &src) { | ||
REQUIRE(IsFunctionTemplateParticipant(src, "m1<T>(T)")); | ||
REQUIRE(IsFunctionTemplateParticipant(src, "m2<T>(T)")); | ||
REQUIRE(IsFunctionTemplateParticipant(src, "m3<T>(T)")); | ||
REQUIRE(IsFunctionTemplateParticipant(src, "m4<T>(T)")); | ||
|
||
auto model = generate_sequence_diagram(*db, diagram); | ||
REQUIRE(MessageOrder(src, | ||
{ | ||
// | ||
{"m1<T>(T)", "m2<T>(T)", ""}, // | ||
{"m2<T>(T)", "m3<T>(T)", ""}, // | ||
{"m3<T>(T)", "m4<T>(T)", ""} // | ||
})); | ||
}); | ||
/* | ||
{ | ||
auto src = generate_sequence_puml(diagram, *model); | ||
AliasMatcher _A(src); | ||
REQUIRE(model->name() == "t20003_sequence"); | ||
REQUIRE_THAT(src, StartsWith("@startuml")); | ||
REQUIRE_THAT(src, EndsWith("@enduml\n")); | ||
{ | ||
auto src = generate_sequence_puml(diagram, *model); | ||
AliasMatcher _A(src); | ||
REQUIRE_THAT(src, HasCall(_A("m1<T>(T)"), _A("m2<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m2<T>(T)"), _A("m3<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m3<T>(T)"), _A("m4<T>(T)"), "")); | ||
REQUIRE_THAT(src, StartsWith("@startuml")); | ||
REQUIRE_THAT(src, EndsWith("@enduml\n")); | ||
save_puml(config.output_directory(), diagram->name + ".puml", src); | ||
} | ||
REQUIRE_THAT(src, HasCall(_A("m1<T>(T)"), _A("m2<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m2<T>(T)"), _A("m3<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m3<T>(T)"), _A("m4<T>(T)"), "")); | ||
{ | ||
auto j = generate_sequence_json(diagram, *model); | ||
save_puml(config.output_directory(), diagram->name + ".puml", src); | ||
} | ||
using namespace json; | ||
{ | ||
auto j = generate_sequence_json(diagram, *model); | ||
std::vector<int> messages = {FindMessage(j, "m1<T>(T)", "m2<T>(T)", | ||
""), FindMessage(j, "m2<T>(T)", "m3<T>(T)", ""), FindMessage(j, | ||
"m3<T>(T)", "m4<T>(T)", "")}; | ||
using namespace json; | ||
REQUIRE(std::is_sorted(messages.begin(), messages.end())); | ||
std::vector<int> messages = {FindMessage(j, "m1<T>(T)", "m2<T>(T)", ""), | ||
FindMessage(j, "m2<T>(T)", "m3<T>(T)", ""), | ||
FindMessage(j, "m3<T>(T)", "m4<T>(T)", "")}; | ||
save_json(config.output_directory(), diagram->name + ".json", j); | ||
} | ||
REQUIRE(std::is_sorted(messages.begin(), messages.end())); | ||
{ | ||
auto src = generate_sequence_mermaid(diagram, *model); | ||
save_json(config.output_directory(), diagram->name + ".json", j); | ||
} | ||
mermaid::SequenceDiagramAliasMatcher _A(src); | ||
using mermaid::HasCall; | ||
{ | ||
auto src = generate_sequence_mermaid(diagram, *model); | ||
REQUIRE_THAT(src, HasCall(_A("m1<T>(T)"), _A("m2<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m2<T>(T)"), _A("m3<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m3<T>(T)"), _A("m4<T>(T)"), "")); | ||
mermaid::SequenceDiagramAliasMatcher _A(src); | ||
using mermaid::HasCall; | ||
|
||
REQUIRE_THAT(src, HasCall(_A("m1<T>(T)"), _A("m2<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m2<T>(T)"), _A("m3<T>(T)"), "")); | ||
REQUIRE_THAT(src, HasCall(_A("m3<T>(T)"), _A("m4<T>(T)"), "")); | ||
|
||
save_mermaid(config.output_directory(), diagram->name + ".mmd", src); | ||
} | ||
save_mermaid(config.output_directory(), diagram->name + ".mmd", | ||
src); | ||
}*/ | ||
} |
Oops, something went wrong.