Added test case for sequence diagram with multiple translation units

This commit is contained in:
Bartek Kryza
2022-12-05 23:57:00 +01:00
parent 14c2cb6263
commit f7a1130bab
15 changed files with 256 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ diagrams:
glob:
- ../../tests/t00048/b_t00048.cc
- ../../tests/t00048/a_t00048.cc
- ../../tests/t00048/t00048.cc
using_namespace: clanguml::t00048
parse_includes: true
include:

17
tests/t20014/.clang-uml Normal file
View File

@@ -0,0 +1,17 @@
compilation_database_dir: ..
output_directory: puml
diagrams:
t20014_sequence:
type: sequence
glob:
- ../../tests/t20014/t20014.cc
- ../../tests/t20014/t20014_c.cc
- ../../tests/t20014/t20014_b.cc
- ../../tests/t20014/t20014_a.cc
include:
namespaces:
- clanguml::t20014
using_namespace:
- clanguml::t20014
start_from:
- function: "clanguml::t20014::tmain()"

View File

@@ -0,0 +1,9 @@
#pragma once
namespace clanguml {
namespace t20014 {
int tmain();
}
}

View File

@@ -0,0 +1,12 @@
#pragma once
namespace clanguml {
namespace t20014 {
struct A {
int a1(int i, int j);
int a2(int i, int j);
};
}
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "t20014_a.h"
namespace clanguml {
namespace t20014 {
struct B {
int b1(int i, int);
int b2(int i, int);
A a_;
};
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
namespace clanguml {
namespace t20014 {
template <typename T, typename F> struct C {
F c1(F i, F j) {
return c_.b1(i, j);
}
F c2(F i, F j){
return c_.b2(i, j);
}
T c_;
};
}
}

23
tests/t20014/t20014.cc Normal file
View File

@@ -0,0 +1,23 @@
#include "include/t20014.h"
#include "include/t20014_b.h"
#include "include/t20014_c.h"
namespace clanguml {
namespace t20014 {
void log(const char *msg) { }
int tmain()
{
B b;
C<B, int> c;
b.b1(0, 1);
b.b2(1, 2);
c.c1(2, 3);
return 0;
}
}
}

10
tests/t20014/t20014_a.cc Normal file
View File

@@ -0,0 +1,10 @@
#include "include/t20014_a.h"
namespace clanguml {
namespace t20014 {
int A::a1(int i, int j) { return i + j; }
int A::a2(int i, int j) { return i - j; }
}
}

10
tests/t20014/t20014_b.cc Normal file
View File

@@ -0,0 +1,10 @@
#include "include/t20014_b.h"
namespace clanguml {
namespace t20014 {
int B::b1(int i, int j) { return a_.a1(i, j); }
int B::b2(int i, int j) { return a_.a2(i, j); }
}
}

17
tests/t20014/t20014_c.cc Normal file
View File

@@ -0,0 +1,17 @@
#include "include/t20014_c.h"
namespace clanguml {
namespace t20014 {
//template <typename T, typename F> F C<T, F>::c1(F i, F j)
//{
// return c_.b1(i, j);
//}
//
//template <typename T, typename F> F C<T, F>::c2(F i, F j)
//{
// return c_.b2(i, j);
//}
}
}

49
tests/t20014/test_case.h Normal file
View File

@@ -0,0 +1,49 @@
/**
* tests/t20014/test_case.h
*
* Copyright (c) 2021-2022 Bartek Kryza <bkryza@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
TEST_CASE("t20014", "[test-case][sequence]")
{
auto [config, db] = load_config("t20014");
auto diagram = config.diagrams["t20014_sequence"];
REQUIRE(diagram->name == "t20014_sequence");
auto model = generate_sequence_diagram(*db, diagram);
REQUIRE(model->name() == "t20014_sequence");
auto puml = generate_sequence_puml(diagram, *model);
AliasMatcher _A(puml);
REQUIRE_THAT(puml, StartsWith("@startuml"));
REQUIRE_THAT(puml, EndsWith("@enduml\n"));
// Check if all calls exist
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b1(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a1(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("B"), "b2(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("B"), _A("A"), "a2(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("tmain()"), _A("C<B,int>"), "c1(int,int)"));
REQUIRE_THAT(puml, HasCall(_A("C<B,int>"), _A("B"), "b1(int,int)"));
save_puml(
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
}

View File

@@ -260,6 +260,7 @@ using namespace clanguml::test::matchers;
#include "t20011/test_case.h"
#include "t20012/test_case.h"
#include "t20013/test_case.h"
#include "t20014/test_case.h"
///
/// Package diagram tests