MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / ctor_dtor_test

Function ctor_dtor_test

tests/system_test/ctor_dtor_test.cpp:63–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61};
62
63auto ctor_dtor_test() -> bool {
64 klog::Info("Running C++ Runtime Tests...");
65
66 // 1. Verify Global Initialization
67 EXPECT_EQ(global_value_with_init, 42, "Global int init");
68 EXPECT_EQ(global_u32_value_with_init, 0xa1a2a3a4UL, "Global uint32 init");
69 EXPECT_EQ(global_u64_value_with_init, 0xb1b2b3b4b5b6b7b8ULL,
70 "Global uint64 init");
71 EXPECT_EQ(global_u16_value_with_init, 0x1234, "Global uint16 init");
72 EXPECT_EQ(global_u8a_value_with_init, 0x42, "Global uint8 a init");
73 EXPECT_EQ(global_u8b_value_with_init, 0x43, "Global uint8 b init");
74 EXPECT_EQ(global_u8c_value_with_init, 0x44, "Global uint8 c init");
75 EXPECT_EQ(global_u8d_value_with_init, 0x45, "Global uint8 d init");
76
77 // 2. Verify Global Constructors
78 // global_value1_with_constructor was initialized to 1
79 // constructor_destructor_1 adds 0x200
80 // constructor_destructor_4 adds 0x100000
81 // Expected: 1 | 0x200 | 0x100000 = 0x100201 (1049089)
82 unsigned int expected_v1 = 1 | 0x200 | 0x100000;
83 EXPECT_EQ(global_value1_with_constructor, expected_v1,
84 "Global constructor execution 1");
85
86 unsigned int expected_v2 = 2 | 0x200 | 0x100000;
87 EXPECT_EQ(global_value2_with_constructor, expected_v2,
88 "Global constructor execution 2");
89
90 // 3. Verify Class Member, Virtual Function, and Stack Object Destructor
91 int start_dtor = g_dtor_count;
92 {
93 auto inst_class = InsClass();
94 EXPECT_EQ(inst_class.val, 'B', "Class constructor body");
95 inst_class.Func();
96 EXPECT_EQ(inst_class.val, 'C', "Virtual function dispatch");
97 }
98 EXPECT_EQ(g_dtor_count, start_dtor + 1,
99 "Stack object destructor verification");
100
101 // 4. Verify Static Local Variable
102 static InsClass inst_class_static;
103 EXPECT_TRUE(inst_class_static.val == 'B' || inst_class_static.val == 'C',
104 "Static local object constructor/persistence");
105 inst_class_static.Func();
106 EXPECT_EQ(inst_class_static.val, 'C', "Static local object virtual func");
107
108 klog::Info("PASS: All C++ Runtime Tests passed.");
109
110 return true;
111}

Callers

nothing calls this directly

Calls 3

InfoFunction · 0.85
InsClassClass · 0.85
FuncMethod · 0.80

Tested by

no test coverage detected