-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestSignatureParser.cpp
93 lines (80 loc) · 3.6 KB
/
TestSignatureParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @file TestSignatureParser.cpp
* @brief
*
* @author Kerby
* @date 2022-12-20
*/
#define BOOST_TEST_MAIN
#if !defined( WIN32 )
#define BOOST_TEST_DYN_LINK
#endif
#include <boost/test/unit_test.hpp>
#include <windows.h>
#include <iostream>
#include "SysExports.h"
// Create a test suite
BOOST_AUTO_TEST_SUITE(SignatureParserTestSuite)
// Define a test case for parsing a valid function signature
BOOST_AUTO_TEST_CASE(ParseValidSignature) {
// Create an instance of the SignatureParser
SignatureParser parser;
FunctionSpec spec;
spec.m_SerialID = 0;
spec.m_dwAddress = 0;
// Define the input string and expected output
std::string input = "public: bool __thiscall FooClass::Foo(void)";
std::string expectedName = "Foo";
std::vector<std::string> expectedParamTypes = {"void"};
parse_info<> r = parser.Parse(input.c_str(), spec);
std::cout << "Function ID: " << spec.m_SerialID << std::endl;
std::cout << "Function Address: " << spec.m_dwAddress << std::endl;
std::cout << "Function name: " << spec.m_Name << std::endl;
std::cout << "Return Type: " << spec.m_ReturnType << std::endl;
std::cout << "Call Type: " << spec.m_CallType << std::endl;
for ( FunctionSpec::ParamVec::size_type i = 0; i < spec.m_ParamTypes.size() ; ++i ){
std::cout << "Parameter: " << spec.m_ParamTypes[i] << "'\n";
}
if ( !r.full ){
BOOST_FAIL("Parsing was not successful");
}
// Check that the parsed name and parameter types match the expected values
BOOST_CHECK_EQUAL(spec.m_Name, expectedName);
// BOOST_CHECK_EQUAL_COLLECTIONS(spec.m_ParamTypes.begin(), spec.m_ParamTypes.end(),
// expectedParamTypes.begin(), expectedParamTypes.end());
}
BOOST_AUTO_TEST_CASE(ParseClassReturnType) {
// Create an instance of the SignatureParser
SignatureParser parser;
FunctionSpec spec;
spec.m_SerialID = 0;
spec.m_dwAddress = 0;
// Define the input string and expected output
std::string input = "public: class Foo::Bar::Baz __thiscall Foo::Bar::Baz::bar(__int64,double)";
std::string expectedName = "bar";
std::vector<std::string> expectedParamTypes = {"__int64"};
try {
parse_info<> r = parser.Parse(input.c_str(), spec);
std::cout << "Function ID: " << spec.m_SerialID << std::endl;
std::cout << "Function Address: " << spec.m_dwAddress << std::endl;
std::cout << "Function name: " << spec.m_Name << std::endl;
std::cout << "Return Type: " << spec.m_ReturnType << std::endl;
std::cout << "Call Type: " << spec.m_CallType << std::endl;
for ( FunctionSpec::ParamVec::size_type i = 0; i < spec.m_ParamTypes.size() ; ++i ){
std::cout << "Parameter: " << spec.m_ParamTypes[i] << "'\n";
}
if ( !r.full ){
std::string errorInput = input.substr(0, r.stop - input.c_str());
//std::cout << "Parse error at position " << r.stop << ": " << errorInput << std::endl;
std::cout << "Parse error at position " << r.stop << std::endl;
BOOST_FAIL("Parsing was not successful");
}
} catch (const std::invalid_argument& e) {
e.what();
}
}
// Define a test case for parsing an invalid function signature
BOOST_AUTO_TEST_CASE(ParseInvalidSignature) {
}
// End the test suite
BOOST_AUTO_TEST_SUITE_END()