-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
115 lines (97 loc) · 2.99 KB
/
test.cpp
File metadata and controls
115 lines (97 loc) · 2.99 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
#include <map>
#include <string>
// Support Types required by the generated header
// These mock the types found in the original source
struct TestStruct
{
int a = 1;
int b = 2;
};
typedef enum TestEnum
{
TEST_ENUM_A,
TEST_ENUM_B,
TEST_ENUM_C
} TestEnum;
// Include generated header
#include "vidl_generated.h"
// Mock Handler
class TestHandler : public VIDLHandler
{
public:
bool function0_called = false;
bool function1_called = false;
bool function2_called = false;
// override Handle_FunctionTest0
void Handle_FunctionTest0(VIDL_FunctionTest0* cmd) override
{
function0_called = true;
std::cout << "Handle_FunctionTest0 called with x=" << cmd->x << std::endl;
assert(cmd->x == 10);
assert(cmd->y == 20);
assert(cmd->a == true);
assert(cmd->enum_ == TEST_ENUM_A);
}
void Handle_FunctionTest1(VIDL_FunctionTest1* cmd) override
{
function1_called = true;
}
void Handle_FunctionTest2(VIDL_FunctionTest2* cmd) override
{
function2_called = true;
std::cout << "Handle_FunctionTest2 called with pointer checking" << std::endl;
assert(cmd->x != nullptr);
assert(*cmd->x == 999);
assert(cmd->ptr != nullptr);
assert(cmd->ptr->a == 123);
}
};
int main()
{
std::cout << "Running C++ Integration Tests..." << std::endl;
// Test 1: Constructors
{
std::cout << "[Test 1] Constructors" << std::endl;
VIDL_FunctionTest0 cmd(10, 20, true, TEST_ENUM_A);
assert(cmd.x == 10);
assert(cmd.y == 20);
assert(cmd.a == true);
assert(cmd.enum_ == TEST_ENUM_A);
assert(cmd.MAGIC == VIDL_FunctionTest0::kMagic);
}
// Test 2: Polymorphism
{
std::cout << "[Test 2] Polymorphism & Dispatch" << std::endl;
TestHandler handler;
VIDL_FunctionTest0 cmd(10, 20, true, TEST_ENUM_A);
// Dispatch
handler.HandleCmd(&cmd);
assert(handler.function0_called == true);
assert(handler.function1_called == false);
}
// Test 3: Pointer/Complex Types
{
std::cout << "[Test 3] Pointers" << std::endl;
TestHandler handler;
uint32_t val = 999;
TestStruct ts;
ts.a = 123;
VIDL_FunctionTest2 cmd(&val, &ts);
handler.HandleCmd(&cmd);
assert(handler.function2_called == true);
}
// Test 4: Magic Numbers
{
std::cout << "[Test 4] Unique Magic Numbers" << std::endl;
assert(VIDL_FunctionTest0::kMagic != VIDL_FunctionTest1::kMagic);
assert(VIDL_FunctionTest0::kMagic != VIDL_FunctionTest2::kMagic);
std::cout << "Magic 0: " << std::hex << VIDL_FunctionTest0::kMagic << std::endl;
std::cout << "Magic 1: " << std::hex << VIDL_FunctionTest1::kMagic << std::endl;
}
std::cout << "All C++ Tests Passed!" << std::endl;
return 0;
}