forked from acgreek/ExtremeCMock
-
Notifications
You must be signed in to change notification settings - Fork 0
iamCode/ExtremeCMock
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
to install execute `make; sudo make install` to build execute `sudo make -f Makefile32 install ` for ia32 build or `sudo make -f Makefile64 install` for ia64 build to build the system default, you can just execute 'sudo make install' on ubuntu you may need to install for ia32 build on 64 bit platform: sudo apt-get install ia32-libs sudo apt-get install libc6-dev-i386 for examples of how to use to mock a function see test.c to use this add to your compile commandline `pkg-config ExtremeCUnit --cflags` and to the link command line `pkg-config ExtremeCUnit --libs` to build and run the test app, you need to install my ExtremeCUnit testing framework https://github.com/acgreek/ExtremeCUnit, then in this directory, execute 'make run', if you see no errors all tests passed. To version status of each test execute dist/test -v EXAMPLE Say you have some library that function you want to test and it call the libc function 'time_t time(time_t * t)'. That is going to return current time which is not necessarily going to be consistent in your test. So here is is an example of how to mock the time function. It works even when some library you are linking with calls the time function source for mock_time.c : .. #include <time.h> #include <stdio.h> #include <ExtremeCMock.h> long time_mock() { static int now = 10; return now++; } int main (int argc, char *argv) { printf("time is now %lu\n", time(NULL)); mock_func(time,time_mock); printf("time is now %lu\n", time(NULL)); printf("time is now %lu\n", time(NULL)); unmock_all(); printf("time is now %lu\n", time(NULL)); return 0; } .. compile and run : ac@agcarat-laptop:~/my-src/ExtremeCMock$ gcc -o mock_time mock_time.c `pkg-config --cflags --libs ExtremeCMock` ac@agcarat-laptop:~/my-src/ExtremeCMock$ ./mock_time time is now 1343102848 time is now 10 time is now 11 time is now 1343102848
About
Mock a function in c at run time
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published