1010namespace power_grid_model ::main_core::utils {
1111
1212namespace {
13- // TODO test with a non used type
1413struct AComponent {
1514 using UpdateType = void ;
1615 static constexpr char const * name = " a_component" ;
@@ -31,18 +30,19 @@ TEST_CASE("MainModelType") {
3130 static_assert (ModelType::index_of_component<Source> == 1 );
3231 static_assert (ModelType::n_types == 2 );
3332
34- CHECK (ModelType::run_functor_with_all_component_types_return_array (
35- []<typename CompType>() { return CompType::name; }) == std::array<const char *, 2 >{" node" , " source" });
33+ CHECK (ModelType::run_functor_with_all_component_types_return_array ([]<typename CompType>() {
34+ return std::string_view (CompType::name);
35+ }) == std::array<std::string_view, 2 >{" node" , " source" });
3636
37- std::vector<const char * > calls;
37+ std::vector<std::string_view > calls;
3838 ModelType::run_functor_with_all_component_types_return_void (
39- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
40- CHECK (calls == std::vector<const char * >{" node" , " source" });
39+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
40+ CHECK (calls == std::vector<std::string_view >{" node" , " source" });
4141
4242 calls.clear ();
4343 run_functor_with_tuple_return_void<typename ModelType::TopologyTypesTuple>(
44- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
45- CHECK (calls == std::vector<const char * >{" node" , " source" });
44+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
45+ CHECK (calls == std::vector<std::string_view >{" node" , " source" });
4646
4747 // static_assert(is_constructible_v<MainModelImpl<ModelType>>);
4848 }
@@ -62,18 +62,18 @@ TEST_CASE("MainModelType") {
6262 static_assert (ModelType::n_types == 3 );
6363
6464 CHECK (ModelType::run_functor_with_all_component_types_return_array ([]<typename CompType>() {
65- return CompType::name;
66- }) == std::array<const char * , 3 >{" node" , " line" , " source" });
65+ return std::string_view ( CompType::name) ;
66+ }) == std::array<std::string_view , 3 >{" node" , " line" , " source" });
6767
68- std::vector<const char * > calls;
68+ std::vector<std::string_view > calls;
6969 ModelType::run_functor_with_all_component_types_return_void (
70- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
71- CHECK (calls == std::vector<const char * >{" node" , " line" , " source" });
70+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
71+ CHECK (calls == std::vector<std::string_view >{" node" , " line" , " source" });
7272 calls.clear ();
7373
7474 run_functor_with_tuple_return_void<typename ModelType::TopologyTypesTuple>(
75- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
76- CHECK (calls == std::vector<const char * >{" node" , " branch" , " source" });
75+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
76+ CHECK (calls == std::vector<std::string_view >{" node" , " branch" , " source" });
7777 }
7878 SUBCASE (" Different component order: Line Source Node" ) {
7979 using ModelType =
@@ -91,18 +91,18 @@ TEST_CASE("MainModelType") {
9191 static_assert (ModelType::n_types == 3 );
9292
9393 CHECK (ModelType::run_functor_with_all_component_types_return_array ([]<typename CompType>() {
94- return CompType::name;
95- }) == std::array<const char * , 3 >{" line" , " source" , " node" });
94+ return std::string_view ( CompType::name) ;
95+ }) == std::array<std::string_view , 3 >{" line" , " source" , " node" });
9696
97- std::vector<const char * > calls;
97+ std::vector<std::string_view > calls;
9898 ModelType::run_functor_with_all_component_types_return_void (
99- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
100- CHECK (calls == std::vector<const char * >{" line" , " source" , " node" });
99+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
100+ CHECK (calls == std::vector<std::string_view >{" line" , " source" , " node" });
101101 calls.clear ();
102102
103103 run_functor_with_tuple_return_void<typename ModelType::TopologyTypesTuple>(
104- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
105- CHECK (calls == std::vector<const char * >{" node" , " branch" , " source" });
104+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
105+ CHECK (calls == std::vector<std::string_view >{" node" , " branch" , " source" });
106106 }
107107
108108 SUBCASE (" Node AComponent Source" ) {
@@ -121,18 +121,18 @@ TEST_CASE("MainModelType") {
121121 static_assert (ModelType::n_types == 3 );
122122
123123 CHECK (ModelType::run_functor_with_all_component_types_return_array ([]<typename CompType>() {
124- return CompType::name;
125- }) == std::array<const char * , 3 >{" node" , " a_component" , " source" });
124+ return std::string_view ( CompType::name) ;
125+ }) == std::array<std::string_view , 3 >{" node" , " a_component" , " source" });
126126
127- std::vector<const char * > calls;
127+ std::vector<std::string_view > calls;
128128 ModelType::run_functor_with_all_component_types_return_void (
129- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
130- CHECK (calls == std::vector<const char * >{" node" , " a_component" , " source" });
129+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
130+ CHECK (calls == std::vector<std::string_view >{" node" , " a_component" , " source" });
131131
132132 calls.clear ();
133133 run_functor_with_tuple_return_void<typename ModelType::TopologyTypesTuple>(
134- [&calls]<typename CompType>() { calls.push_back (CompType::name); });
135- CHECK (calls == std::vector<const char * >{" node" , " source" });
134+ [&calls]<typename CompType>() { calls.push_back (std::string_view ( CompType::name) ); });
135+ CHECK (calls == std::vector<std::string_view >{" node" , " source" });
136136 }
137137
138138 SUBCASE (" Bad case: Line Source" ) {
0 commit comments