{"id":20468985,"url":"https://github.com/neko-box-coder/simpleoverride","last_synced_at":"2025-06-18T22:39:20.460Z","repository":{"id":171475054,"uuid":"647810678","full_name":"Neko-Box-Coder/SimpleOverride","owner":"Neko-Box-Coder","description":"Allow overriding return value or setting arguments, similar to mocking but more flexible","archived":false,"fork":false,"pushed_at":"2023-11-20T21:42:54.000Z","size":183,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T01:48:49.026Z","etag":null,"topics":["c-plus-plus","cpp","cpp11","mock","mocking-framework"],"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/Neko-Box-Coder.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}},"created_at":"2023-05-31T15:07:44.000Z","updated_at":"2023-07-20T13:17:18.000Z","dependencies_parsed_at":"2023-11-13T23:38:21.573Z","dependency_job_id":null,"html_url":"https://github.com/Neko-Box-Coder/SimpleOverride","commit_stats":null,"previous_names":["neko-box-coder/simpleoverride"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neko-Box-Coder%2FSimpleOverride","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neko-Box-Coder%2FSimpleOverride/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neko-Box-Coder%2FSimpleOverride/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neko-Box-Coder%2FSimpleOverride/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neko-Box-Coder","download_url":"https://codeload.github.com/Neko-Box-Coder/SimpleOverride/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242031569,"owners_count":20060608,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["c-plus-plus","cpp","cpp11","mock","mocking-framework"],"created_at":"2024-11-15T14:07:32.498Z","updated_at":"2025-03-05T13:20:13.391Z","avatar_url":"https://github.com/Neko-Box-Coder.png","language":"C++","readme":"## Simple Override\n\n---\n\n\u003e #### This Has Been Superceeded By [CppOverride](https://github.com/Neko-Box-Coder/CppOverride)\n\n---\n\nA simple framework for overriding function behaviours.\n\nThis allows overriding return value or setting arguments, similar to mocking but more flexible\n\n```cpp\n#include \"SimpleOverride.hpp\"\n\nSimpleOverride Overrider;\n\nint ChangeReturnValue(int a, float* b)\n{\n    //SO_RETURN_IF_FOUND(functionOverrideObj, functionRef, returnType, args...)\n    SO_RETURN_IF_FOUND(Overrider, ChangeReturnValue(int, float*), int, a, b);\n    \n    return 0;\n}\n\nvoid SetArgumentValue(int a, float\u0026 b, int* c)\n{\n    //SO_MODIFY_ARGUMENTS_IF_FOUND(overrideObj, functionRef, args...)\n    SO_MODIFY_ARGUMENTS_IF_FOUND(Overrider, SetArgumentValue(int, float\u0026, int*), a, b, c);\n    \n    //You can also use SO_ARGUMENTS_AND_RETURN_IF_FOUND to return a specify value\n    //  When the condition is met\n}\n\nint main()\n{\n    //Example of overriding return value\n    SO_OVERRIDE_RETURNS (Overrider, ChangeReturnValue(int, float*))  \n                        .Returns(1)\n                        \n                        //Pointers are automatically dereferenced when getting compared.\n                        //      Unless it is cast to void*, then it won't be dereferenced.\n                        .WhenCalledWith(2, 3.f)\n                        \n                        //By default, it is infinite times if not specified\n                        .Times(2);\n\n    float testFloat = 3.f;\n    assert(ChangeReturnValue(2, \u0026testFloat) == 1 \u0026\u0026 ChangeReturnValue(2, \u0026testFloat) == 1);\n    \n    testFloat = 4.f;\n    assert(ChangeReturnValue(4, \u0026testFloat) == 0);\n    \n    \n    //Example of overriding argument value\n\n    SO_OVERRIDE_ARGS(Overrider, SetArgumentValue(int, float\u0026, int*))\n    \n                    //Again, pointers are automatically dereferenced when getting set\n                    .SetArgs(SO_DONT_SET, 2.f, 3)\n                    .WhenCalledWith(4, SO_ANY, SO_ANY);\n\n    int testInt = 5;\n    SetArgumentValue(4, testFloat, \u0026testInt);\n    assert(testFloat == 2.f \u0026\u0026 testInt == 3);\n    \n    std::cout \u003c\u003c \"Success\\n\";\n    \n    //------------------------------------------------\n    //Extra:\n    //------------------------------------------------\n    \n    //ReturnsByAction and SetArgsByAction can also be used to return or set arguments by lambda\n    \n    //SO_DECLARE_INSTNACE(OverrideObjName) macro can be used inside a class declaration to \n    //  declare an instance of overriding object\n\n    //SO_DECLARE_OVERRIDE_METHODS(OverrideObjName) macro can be used inside a class declaration \n    //  to declare proxy methods inline implementations to the override object\n    \n    //SO_NonCopyable and SO_NonComparable can be used for objects that are not copyable or comparable.\n    //  These objects won't be compared against in WhenCalledWith.\n    \n    //You also have access to \"If\" clause for additonal conditions\n    \n    //Similarly, you have \"WhenCalledExpectedly_Do\" and \"Otherwise_Do\" clauses for performing custom actions\n    //  when the condition is matched or not respectively\n    \n    //For usage on these extra actions, see Tests/SimpleOverrideTests.cpp\n    \n    return 0;\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneko-box-coder%2Fsimpleoverride","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneko-box-coder%2Fsimpleoverride","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneko-box-coder%2Fsimpleoverride/lists"}