CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
for_each_member_tools.h
1
2#pragma once
3
4#include <gtest/gtest.h>
5#include <cstring>
6#include <algorithm>
7
8namespace System {
9
10 inline bool is_vp_test(const ::testing::TestInfo* test_info)
11 {
12 const char* suite_name = test_info->test_suite_name();
13
14 auto suite_name_len = std::strlen(suite_name);
15
16 bool has_slash = std::any_of(suite_name, suite_name + suite_name_len, [](char ch){ return ch == '/';});
17
18 const char suffix[] = "VP";
19 bool is_ends_with_VP = (std::strncmp(suite_name + suite_name_len - 2, suffix, 2) == 0);
20
21 return has_slash && is_ends_with_VP;
22 }
23
24 inline bool is_parametrized_test(const ::testing::TestInfo* test_info)
25 {
26 const char *name = test_info->name();
27 auto name_len = std::strlen(name);
28 return std::any_of(name, name + name_len, [](char ch) { return ch == '/'; });
29 }
30
31 inline std::string ForEachMemberGVName() {
32 const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
33
34 if (is_vp_test(test_info))
35 {
36 // TestEquationsAndFormulas/Test13733VP
37 std::string case_name = test_info->name();
38 // Test/34
39 std::string suite_name = test_info->test_suite_name();
40
41 auto slash_it = std::find(suite_name.begin(), suite_name.end(), '/');
42 std::string gv_name(suite_name.begin(), slash_it);
43 // gv_name == "TestEquationsAndFormulas"
44 gv_name += '_';
45 // gv_name == "TestEquationsAndFormulas_"
46 gv_name.append(slash_it + 1, suite_name.end() - 2);
47 // gv_name == "TestEquationsAndFormulas_Test13733"
48 gv_name += '_';
49 // gv_name == "TestEquationsAndFormulas_Test13733_"
50
51 slash_it = std::find(case_name.begin(), case_name.end(), '/');
52 gv_name.append(slash_it + 1, case_name.end());
53 // gv_name == "TestEquationsAndFormulas_Test13733_34"
54
55 gv_name += ".gv";
56 // gv_name == "TestEquationsAndFormulas_Test13733_34.gv"
57
58 return gv_name;
59 }
60
61 if (is_parametrized_test(test_info))
62 { //LatexToPdfConverterTests_PDFNET_55738.Test/1
63
64 //LatexToPdfConverterTests_PDFNET_55738
65 std::string gv_name{ test_info->test_suite_name() };
66 //Test/1
67 std::string case_name = test_info->name();
68
69 auto slash_it = std::find(case_name.begin(), case_name.end(), '/');
70 gv_name += '_';
71 //LatexToPdfConverterTests_PDFNET_55738_
72 gv_name.append(case_name.begin(), slash_it);
73 //LatexToPdfConverterTests_PDFNET_55738_Test
74 gv_name.append(slash_it + 1, case_name.end());
75 //LatexToPdfConverterTests_PDFNET_55738_Test_1
76 gv_name += ".gv";
77 //LatexToPdfConverterTests_PDFNET_55738_Test_1.gv
78
79 return gv_name;
80 }
81
82 return std::string(test_info->test_suite_name()) + "_" + std::string(test_info->name()) + ".gv";
83 }
84
85
86}
Definition: db_command.h:9
std::string ForEachMemberGVName()
Definition: for_each_member_tools.h:31
bool is_vp_test(const ::testing::TestInfo *test_info)
Definition: for_each_member_tools.h:10
bool is_parametrized_test(const ::testing::TestInfo *test_info)
Definition: for_each_member_tools.h:24