Using C++14 to mock C functions
summary
Uses C++14 macros and templates to mock C functions at test time, specifically replacing libc-style send(fd,buf,len,flags) with a test lambda or programmable mock; library called preach is header-only, scope-bound (RAII) so replacements last until block exit, and avoids singletons or stringly-typed expectations. Works with real socket signatures, enforces type-safe mocks, supports queued return values and call-count/argument expectations. Requires a simple build-time symbol remap (or compile switch) and the runtime macro implementation; demos show it working.
AI-written summary · about
related talks
06mMocking C++
01h 01m“Mocking Frameworks considered harmful”
53mUsing Trompeloeil - a mocking framework for modern C++
01h 18mMocking Framworks considered, harmful?!
01h 25mUsing Trompeloeil, a mocking framework for modern C++
01h 01mAdvanced Unit Testing in C & C++
52mPlease don’t mock me
46mTestability and C++ API Design
