@@ -18,9 +18,28 @@ namespace ArduinoContextTest
1818 ArduinoFakeContext* context = getArduinoFakeContext ();
1919 ArduinoFakeInstances* instances = context->Instances ;
2020
21+ // Broke pointers for testing purposes
22+ context->Instances ->Serial = nullptr ;
23+ context->Instances ->SPI = nullptr ;
24+
25+ TEST_ASSERT_NULL (context->Instances ->Serial );
26+ TEST_ASSERT_NULL (context->Instances ->SPI );
27+
2128 ArduinoFakeReset ();
2229
23- TEST_ASSERT_NOT_EQUAL (context->Instances , instances);
30+ // After reset, a new instance of ArduinoFakeInstances should be created
31+ // and the previous instance should be deleted.
32+ // The Serial and SPI instances should also be reset to nullptr.
33+ TEST_ASSERT_NOT_NULL (context->Instances );
34+ TEST_ASSERT_NOT_NULL (context->Instances ->Serial );
35+ TEST_ASSERT_NOT_NULL (context->Instances ->SPI );
36+
37+ // A simple pointer comparison like TEST_ASSERT_NOT_EQUAL(context->Instances, instances);
38+ // is not a reliable way to check if a new instance was created, because
39+ // memory allocators can reuse the same address for new objects after deletion.
40+ // This means a new instance could be created at the same memory location as the old one,
41+ // causing the test to fail even though the instance is actually new.
42+ // To properly verify a new instance, you should check object identity or state, not just pointer values.
2443 }
2544
2645 void test_function_mock (void )
0 commit comments