CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
TestContext.h
1
2#ifndef _aspose_testing_test_context_h_
3#define _aspose_testing_test_context_h_
4
5#include <system/object.h>
6#include <system/shared_ptr.h>
7#include <system/string.h>
8#include <gtest/gtest.h>
9#include <vector>
10#include <string>
11
12namespace NUnit { namespace Framework {
13
16{
19 {
20 friend struct TestContext;
21
22 public:
26 {
27 return m_full_name;
28 }
29
33 {
34 return m_name;
35 }
36
37 private:
41 TestAdapter(const System::String& full_name, const System::String& name) :m_full_name(full_name), m_name(name) {}
42 MEMBER_FUNCTION_MAKE_OBJECT(TestAdapter, CODEPORTING_ARGS(const System::String& full_name, const System::String& name), CODEPORTING_ARGS(full_name, name));
43
45 System::String m_full_name;
47 System::String m_name;
48 };
49
53 {
54 static TestContext testContext;
55 return &testContext;
56 }
57
61 {
62 const auto test_dir = get_TestDirectory_static();
63 return test_dir;
64 }
65
69 {
70 const auto info = ::testing::UnitTest::GetInstance()->current_test_info();
71 const auto& name = System::String::FromUtf8(info->name());
72 const auto& full_name = System::String::FromUtf8(info->test_case_name()) + u"." + name; // Namespace missing
73 return TestAdapter::MakeObject(full_name, name);
74 }
75
76private:
79 static System::String get_TestDirectory_static()
80 {
81 const auto argvs = ::testing::internal::GetArgvs();
82
83 if (argvs.empty() || argvs[0].empty())
84 {
85 return System::String(u"");
86 }
87
88 ::testing::internal::FilePath filePath(argvs[0]);
89 const auto directoryName = filePath.RemoveFileName();
90 return System::String::FromUtf8(directoryName.string());
91 }
92};
93
94}}
95
96#endif //_aspose_testing_test_context_h_
TestAdapter adapts a Test for consumption by the user test code.
Definition: TestContext.h:19
System::String get_FullName()
Gets full name of the test.
Definition: TestContext.h:25
System::String get_Name()
Gets name of the test.
Definition: TestContext.h:32
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
static String FromUtf8(const char *utf8)
Creates String from utf8 string.
Definition: exceptions.h:943
Context in which testing takes place.
Definition: TestContext.h:16
System::String get_TestDirectory()
Returns test directory.
Definition: TestContext.h:60
System::SharedPtr< TestContext::TestAdapter > get_Test()
Returns current test info.
Definition: TestContext.h:68
static TestContext * get_CurrentContext()
Returns current test context.
Definition: TestContext.h:52