libhal-google / libhal-mock

Mocks, fakes, simulation and other testing utilities for libhal
Apache License 2.0
1 stars 3 forks source link

Add `hal::callback_tester` #7

Closed kammce closed 1 year ago

kammce commented 2 years ago

hal::callback_tester is a unit testing helper class for detecting if a callback has been called and has been stored in the correct place. In many cases, testing if a callback was installed correctly isn't as easy as simply checking if the function address pointers are the same. With std::function and the usage of lambdas, there usually isn't a fixed address to compare against. So the only real way to test this is to insert/install a callback into a driver, extract the inner callback and call it. The callback will record that it has been called. This allows the user to know that the correct callback was installed and used at the appropriate time.

kammce commented 1 year ago

Resolved with the introduction of hal::callback_recorder