{"id":19715683,"url":"https://github.com/mickaelblet/mockf","last_synced_at":"2026-01-11T22:04:08.152Z","repository":{"id":101617880,"uuid":"173421673","full_name":"MickaelBlet/mockf","owner":"MickaelBlet","description":"Mock C/C++ functions using gmock","archived":false,"fork":false,"pushed_at":"2025-02-06T03:26:56.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-12T00:39:43.957Z","etag":null,"topics":["cpp98-compatible","google-mock","google-test","header-only","libc","mock"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MickaelBlet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-03-02T08:14:07.000Z","updated_at":"2025-02-06T03:31:01.000Z","dependencies_parsed_at":"2024-02-26T01:29:24.891Z","dependency_job_id":"7323d03c-06ba-420f-a49f-d36ada58d01c","html_url":"https://github.com/MickaelBlet/mockf","commit_stats":null,"previous_names":["mickaelblet/mockc"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/MickaelBlet/mockf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MickaelBlet%2Fmockf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MickaelBlet%2Fmockf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MickaelBlet%2Fmockf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MickaelBlet%2Fmockf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MickaelBlet","download_url":"https://codeload.github.com/MickaelBlet/mockf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MickaelBlet%2Fmockf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28324856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T18:42:50.174Z","status":"ssl_error","status_checked_at":"2026-01-11T18:39:13.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp98-compatible","google-mock","google-test","header-only","libc","mock"],"created_at":"2024-11-11T22:39:07.763Z","updated_at":"2026-01-11T22:04:08.128Z","avatar_url":"https://github.com/MickaelBlet.png","language":"C++","readme":"# MockF\n\nMock **C**/**C++** functions using gmock.  \nWork with the `dl` library.  \nFor more examples, see [docs/examples.md](docs/examples.md).\n\n## Quickstart\n\n```cpp\n#include \"unistd.h\" // write\n\n#include \"blet/mockf.h\"\n\nusing ::testing::_;\n\n// Create a mock class for write\nMOCKF_FUNCTION3(ssize_t, write, (int /* fd */, const void* /* buf */, size_t /* nbytes */));\n\nACTION(write) {\n    write(STDOUT_FILENO, \"write: real in mock!\\n\", sizeof(\"write: real in mock!\\n\") - 1);\n    return -42;\n}\n\nTEST(mockf, example_write) {\n    // Initialize an instance of the write mock\n    MOCKF_INIT(write);\n\n    // Use EXPECT_CALL with MOCKF\n    MOCKF_EXPECT_CALL(write, (0, _, _))\n        .WillRepeatedly(write()); // Use the write action\n\n    {\n        // Enable mock\n        MOCKF_GUARD(write);\n        // Use mock\n        EXPECT_EQ(write(0, \"mock\", sizeof(\"mock\") - 1), -42); \n    } // Mock is disabled here\n\n    // Use the real write function\n    write(STDOUT_FILENO, \"write: use real\\n\", sizeof(\"write: use real\\n\") - 1);\n}\n```\n\n### Result\n\n```\nRunning main() from gmock_main.cc\n[==========] Running 1 test from 1 test case.\n[----------] Global test environment set-up.\n[----------] 1 test from mockf\n[ RUN      ] mockf.example_write\nwrite: real in mock!\nwrite: use real\n[       OK ] mockf.example_write (0 ms)\n[----------] 1 test from mockf (0 ms total)\n\n[----------] Global test environment tear-down\n[==========] 1 test from 1 test case ran. (0 ms total)\n[  PASSED  ] 1 test.\n```\n\n## Macros\n\n```cpp\n// Create a mock class\n// Place this at the top of the test source file after includes\nMOCKF_FUNCTION(ssize_t, write, (int /* fd */, const void* /* buf */, size_t /* nbytes */));\n// Or, if using C++98 with the pedantic flag\nMOCKF_FUNCTION3(ssize_t, write, (int /* fd */, const void* /* buf */, size_t /* nbytes */));\n\n// With attributes\nMOCKF_ATTRIBUTE_FUNCTION(int, stat, (const char* /* file */, struct stat* /* buf */), throw());\n// Or, if using C++98 with the pedantic flag\nMOCKF_ATTRIBUTE_FUNCTION2(int, stat, (const char* /* file */, struct stat* /* buf */), throw());\n\n// Create a variadic mock class\n// Place this at the top of the test source file after includes\n// Replace '...' with 'va_list'\nMOCKF_VARIADIC_FUNCTION(int, fcntl (int /* fd */, int /* cmd */, ...));\n// Or, if using C++98 with the pedantic flag\nMOCKF_VARIADIC_FUNCTION3(int, fcntl (int /* fd */, int /* cmd */, ...));\n\n// With attributes\nMOCKF_VARIADIC_ATTRIBUTE_FUNCTION(int, ioctl, (int /* fd */, unsigned long int /* request */, ...), throw());\n// Or, if using C++98 with the pedantic flag\nMOCKF_VARIADIC_ATTRIBUTE_FUNCTION3(int, ioctl, (int /* fd */, unsigned long int /* request */, ...), throw());\n\n// Create an instance of the write mock class (mockf_write)\nMOCKF_INIT(write);\n// Get the mockf instance of write\nMOCKF_INSTANCE(write)\n\n// Enable the mock function\nMOCKF_ENABLE(write);\n// Disable the mock function\nMOCKF_DISABLE(write);\n// Create a guard for the mock function\nMOCKF_GUARD(write);\n// Disable at construction, enable at destruction\nMOCKF_GUARD_REVERSE(write);\n\n// Use EXPECT_CALL\nMOCKF_EXPECT_CALL(write, (::testing::_, ::testing::_, ::testing::_))\n// Equivalent to EXPECT_CALL(MOCKF_INSTANCE(write), write(::testing::_, ::testing::_, ::testing::_))\n\n// For C++98 with the pedantic flag, define 'MOCKF_DISABLE_VARIADIC_MACROS' to disable variadic macros\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmickaelblet%2Fmockf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmickaelblet%2Fmockf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmickaelblet%2Fmockf/lists"}