MCPcopy Create free account
hub / github.com/cpputest/cpputest / FakeOutput

Class FakeOutput

tests/CppUTest/CommandLineTestRunnerTest.cpp:299–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297}
298
299struct FakeOutput
300{
301 FakeOutput() : SaveFOpen(PlatformSpecificFOpen), SaveFPuts(PlatformSpecificFPuts),
302 SaveFClose(PlatformSpecificFClose), SavePutchar(PlatformSpecificPutchar)
303 {
304 installFakes();
305 currentFake = this;
306 }
307
308 ~FakeOutput()
309 {
310 currentFake = NULLPTR;
311 restoreOriginals();
312 }
313
314 void installFakes()
315 {
316 PlatformSpecificFOpen = (FOpenFunc)fopen_fake;
317 PlatformSpecificFPuts = (FPutsFunc)fputs_fake;
318 PlatformSpecificFClose = (FCloseFunc)fclose_fake;
319 PlatformSpecificPutchar = (PutcharFunc)putchar_fake;
320 }
321
322 void restoreOriginals()
323 {
324 PlatformSpecificPutchar = SavePutchar;
325 PlatformSpecificFOpen = SaveFOpen;
326 PlatformSpecificFPuts = SaveFPuts;
327 PlatformSpecificFClose = SaveFClose;
328 }
329
330 static PlatformSpecificFile fopen_fake(const char*, const char*)
331 {
332 return (PlatformSpecificFile) NULLPTR;
333 }
334
335 static void fputs_fake(const char* str, PlatformSpecificFile)
336 {
337 currentFake->file += str;
338 }
339
340 static void fclose_fake(PlatformSpecificFile)
341 {
342 }
343
344 static int putchar_fake(int c)
345 {
346 currentFake->console += StringFrom((char)c);
347 return c;
348 }
349
350 SimpleString file;
351 SimpleString console;
352
353 static FakeOutput* currentFake;
354private:
355 FOpenFunc SaveFOpen;
356 FPutsFunc SaveFPuts;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected