{"id":461670,"date":"2025-05-30T21:02:14","date_gmt":"2025-05-30T21:02:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=461670"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=461670","title":{"rendered":"<span>\u041f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0432 \u041e\u041e\u041f \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0432 C++<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041e\u0431\u0449\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430<\/h2>\n<p>Legacy \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0430 \u0421++ \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u044b\u043c\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438.<br \/> \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e:<\/p>\n<ul>\n<li>\n<p>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043a\u0430\u043a \u041e\u041e\u041f \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 boost, SOCI \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440)<\/p>\n<\/li>\n<li>\n<p>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 (OpenGL \u0447\u0435\u0440\u0435\u0437 \u0421 API, POSIX \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440)<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440: \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u043c\u044f\u0442\u0438.<br \/> \u0412\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 &#8212; \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0438\u043c\u0435\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b?<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0443 GTest\/GMock (\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u043a \u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 framework \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 C++) \u0443\u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/google.github.io\/googletest\/gmock_cook_book.html#mocking-free-functions\">\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a> \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043d\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0439, \u0435\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435 \u0431\u044b\u043b\u0430 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 \u041e\u041e\u041f \u0441\u0442\u0438\u043b\u044c, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<h3>\u041e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/apriorit\/gmock-global\/tree\/master\">gmock-global<\/a> &#8212; header \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f mock \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0435 \u041e\u041e\u041f \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/google\/googletest\">Gtest\/Gmock<\/a> &#8212; gtest framework \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u0441\u0430\u043c\u0430\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0421++.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u0440\u0430 \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a gmock-global \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 gtest \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0430\u043f\u043b\u0430\u0442\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u043a\u0443\u0441\u043a\u043e\u0432 \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. GTest\/GMock &#8212; \u043a\u0430\u043a \u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 framework \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0432 legacy \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043d\u0430 C++.<br \/> \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0442\u0438\u043f\u0430 Catch2 \u0438\u043b\u0438 Boost:Test \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u044c\u0441\u044f \u0442.\u043a. \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438\u0445 \u0441 \u043c\u043e\u043a\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0434\u043e\u043f. \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 FakeIt)<\/p>\n<h2>\u041e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u043c\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f<\/h2>\n<p>\u041f\u0443\u0441\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <em>some_func_foo<\/em>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0412 \u0434\u0430\u043b\u044c\u0439\u0448\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>some_func_foo<\/em>.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430<\/h3>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<\/p>\n<pre><code>lib\/ \u251c\u2500 CMakeLists.txt \u251c\u2500 include\/ \u2502  \u251c\u2500 mylib.h \u251c\u2500 src\/ \u2502  \u251c\u2500 mylib.cpp <\/code><\/pre>\n<p>mylib.h<\/p>\n<pre><code class=\"cpp\">#pragma once  int some_func_foo(int a); <\/code><\/pre>\n<p>mylib.cpp<\/p>\n<pre><code class=\"cpp\">#include \"mylib.h\" #include &lt;iostream&gt;  int some_func_foo(int a){     return 42 + a; } <\/code><\/pre>\n<p>CMakeLists.txt<\/p>\n<pre><code>cmake_minimum_required(VERSION 3.10) project(mylib)  include_directories(${CMAKE_CURRENT_SOURCE_DIR}\/include) add_library(mylib STATIC      src\/mylib.cpp )  set_target_properties(mylib PROPERTIES PUBLIC_HEADER include\/mylib.h)  install(TARGETS mylib         ARCHIVE DESTINATION lib         PUBLIC_HEADER DESTINATION include) <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c static .a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438. \u0414\u0430\u043d\u043d\u0430\u044f \u043b\u0438\u0431\u0430 \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0435\u0440\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0435\u0435 \u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441\u0432\u044f\u0437\u043a\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 + header \u0444\u0430\u0439\u043b.<br \/> \u0414\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 mylib \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:<\/p>\n<pre><code>mkdir build &amp;&amp; cd build cmake .. make make install <\/code><\/pre>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432 \/usr\/local\/lib \u0438 \/usr\/local\/include \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442<\/h3>\n<p>\u041f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <em>some_func_foo<\/em><\/p>\n<pre><code class=\"cpp\">class Foo{ public:     int CallSomeLibMethod(int a){         return some_func_foo(a);     } }; <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 <em>some_func_foo<\/em> \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u043b\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b.<br \/> \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 gmock-global, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 gmock-global<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 gmock-global \u0438\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 header \u0444\u0430\u0439\u043b\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441\u0435\u0431\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442<br \/> \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:<\/p>\n<pre><code>test\/ \u251c\u2500 CMakeLists.txt \u251c\u2500 include\/ \u2502  \u251c\u2500 gmock-global\/ \u2502  \u2502  \u251c\u2500 gmock-global.h \u251c\u2500 TestSomeFunc.cpp <\/code><\/pre>\n<p>CMakeLists.txt<\/p>\n<pre><code>cmake_minimum_required(VERSION 3.10) project(test_mylib)  find_package(GTest REQUIRED)  add_executable(test_runner      TestSomeFunc.cpp )  target_include_directories(test_runner PRIVATE     include\/ )  target_link_libraries(test_runner PRIVATE     GTest::gtest_main     GTest::gmock      GTest::gmock_main     \"-Wl,--whole-archive\"     \/usr\/local\/lib\/libmylib.a     \"-Wl,--no-whole-archive\" )  enable_testing() add_test(NAME SomeFuncTest COMMAND test_runner) <\/code><\/pre>\n<p>\u0424\u043b\u0430\u0433\u0438 whole-archive \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442.\u043a. \u0442\u0430\u043a\u043e\u0439 \u043a\u0435\u0439\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 framework\u043e\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 gmock-global<\/h3>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0438 \u043c\u043e\u043a \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u041f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0448 \u043c\u043e\u043a<\/p>\n<pre><code class=\"cpp\">MOCK_GLOBAL_FUNC1(some_func_foo, int(int)); <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0435\u043b\u0435 \u0442\u0435\u0441\u0442\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 <em>EXPECT_GLOBAL_CALL<\/em> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">TEST(SomeFuncTest, CallsMock) {     Foo obj;     EXPECT_GLOBAL_CALL(some_func_foo, some_func_foo(_)).Times(1).WillOnce(Return(10));     EXPECT_EQ(obj.CallSomeLibMethod(42), 10); } <\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 header \u0444\u0430\u0439\u043b\u044b \u0438 testing namespace.<br \/> \u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0438\u0436\u0435<\/p>\n<pre><code class=\"cpp\">#include \"mylib.h\" #include &lt;gtest\/gtest.h&gt; #include &lt;gmock\/gmock.h&gt; #include &lt;gmock-global\/gmock-global.h&gt;  using namespace testing; MOCK_GLOBAL_FUNC1(some_func_foo, int(int));  class Foo{ public:     int CallSomeLibMethod(int a){         return some_func_foo(a);     } };  TEST(SomeFuncTest, CallsMock) {     Foo obj;     EXPECT_GLOBAL_CALL(some_func_foo, some_func_foo(_)).Times(1).WillOnce(Return(10));     EXPECT_EQ(obj.CallSomeLibMethod(42), 10); }  int main(int argc, char** argv) {     ::testing::InitGoogleTest(&amp;argc, argv);     return RUN_ALL_TESTS(); } <\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u0430\u043a \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 GTest\/Gmock.<br \/> \u0421\u043e\u0431\u0435\u0440\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code>mkdir build &amp;&amp; cd build cmake .. make make install <\/code><\/pre>\n<p>\u041d\u043e \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0430:<\/p>\n<pre><code>\/usr\/bin\/ld: \/usr\/local\/lib\/libmylib.a(mylib.cpp.o): in function `some_func_foo': mylib.cpp:(.text+0x0): multiple definition of `some_func_foo'; CMakeFiles\/test_runner.dir\/TestSomeFunc.cpp.o:TestSomeFunc.cpp:(.text+0x0): first defined here <\/code><\/pre>\n<p>\u0421 \u0447\u0435\u043c \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e? \u0415\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 inotify \u0444\u0443\u043d\u043a\u0446\u0438\u044e inotify_init, \u0442\u043e \u043e\u043d\u0430 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043c\u043e\u043a\u0430\u0435\u0442\u0441\u044f<\/p>\n<pre><code class=\"cpp\">#include \"mylib.h\" #include &lt;gtest\/gtest.h&gt; #include &lt;gmock\/gmock.h&gt; #include &lt;gmock-global\/gmock-global.h&gt; #include &lt;sys\/inotify.h&gt;  using namespace testing; \/\/MOCK_GLOBAL_FUNC1(some_func_foo, int(int)); MOCK_GLOBAL_FUNC0(inotify_init, int(void));  class Foo{ public:     int CallSomeLibMethod(int a){         \/\/return some_func_foo(a);         return inotify_init();     } };  TEST(SomeFuncTest, CallsMock) {     Foo obj;     \/\/EXPECT_GLOBAL_CALL(some_func_foo, some_func_foo(_)).Times(1).WillOnce(Return(10));     EXPECT_GLOBAL_CALL(inotify_init, inotify_init()).Times(1).WillOnce(Return(-1));     EXPECT_EQ(obj.CallSomeLibMethod(42), -1); }  int main(int argc, char** argv) {     ::testing::InitGoogleTest(&amp;argc, argv);     return RUN_ALL_TESTS(); } <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code>.\/test_runner  [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from SomeFuncTest [ RUN      ] SomeFuncTest.CallsMock [       OK ] SomeFuncTest.CallsMock (0 ms) [----------] 1 test from SomeFuncTest (0 ms total)  [----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (0 ms total) [  PASSED  ] 1 test. <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043c\u043e\u043a\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 gmock-global, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043d\u0435\u0442, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441 <em>MOCK_GLOBAL_FUNC0<\/em>.<br \/> \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430 \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u043a\u0430<\/p>\n<pre><code class=\"cpp\">#define MOCK_GLOBAL_FUNC0_(tn, constness, ct, Method, ...) \\ class gmock_globalmock_##Method { \\ public:\\   gmock_globalmock_##Method(const char* tag) : m_tag(tag) {}  \\   const char* const m_tag; \\   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method () constness {  \\     static_assert((std::tuple_size&lt;                          \\         tn ::testing::internal::Function&lt;__VA_ARGS__&gt;::ArgumentTuple&gt;::value \\             == 0), \\         \"this method does not take 0 arguments\");  \\     GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \\     return GMOCK_MOCKER_(0, constness, Method).Invoke(); \\   } \\   ::testing::MockSpec&lt;__VA_ARGS__&gt; \\       gmock_##Method() constness { \\     GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \\     return GMOCK_MOCKER_(0, constness, Method).With(); \\   } \\   mutable ::testing::FunctionMocker&lt;__VA_ARGS__&gt; GMOCK_MOCKER_(0, constness, \\       Method); \\    }; \\    std::unique_ptr&lt; gmock_globalmock_##Method &gt; gmock_globalmock_##Method##_instance;\\    GMOCK_RESULT_(tn, __VA_ARGS__) ct Method() constness { \\        MOCK_GLOBAL_CHECK_INIT(Method); \\        return gmock_globalmock_##Method##_instance-&gt;Method();\\       }\\  #define MOCK_GLOBAL_FUNC0(m, ...) MOCK_GLOBAL_FUNC0_(, , , m, __VA_ARGS__) <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 global mock \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 gmock_globalmock_##Method, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u043e\u043a\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041f\u0440\u0438 \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <em>some_func_foo<\/em>:<\/p>\n<pre><code class=\"cpp\">class gmock_globalmock_some_func_foo { public:   gmock_globalmock_some_func_foo(const char *tag) : m_tag(tag) {}   const char *const m_tag;   ::testing::internal::Function&lt;int(int)&gt;::Result some_func_foo(::testing::internal::Function&lt;int(int)&gt;::template Arg&lt;1 - 1&gt;::type gmock_a1)   {     static_assert((std::tuple_size&lt;::testing::internal::Function&lt;int(int)&gt;::ArgumentTuple&gt;::value == 1), \"this method does not take 1 arguments\");     gmock1_some_func_foo_7.SetOwnerAndName(this, \"some_func_foo\");     return gmock1_some_func_foo_7.Invoke(gmock_a1);   }   ::testing::MockSpec&lt;int(int)&gt; gmock_some_func_foo(const ::testing::Matcher&lt;::testing::internal::Function&lt;int(int)&gt;::template Arg&lt;1 - 1&gt;::type&gt; &amp;gmock_a1)   {     gmock1_some_func_foo_7.RegisterOwner(this);     return gmock1_some_func_foo_7.With(gmock_a1);   }   mutable ::testing::FunctionMocker&lt;int(int)&gt; gmock1_some_func_foo_7; }; std::unique_ptr&lt;gmock_globalmock_some_func_foo&gt; gmock_globalmock_some_func_foo_instance; ::testing::internal::Function&lt;int(int)&gt;::Result some_func_foo(::testing::internal::Function&lt;int(int)&gt;::template Arg&lt;1 - 1&gt;::type gmock_a1) {   if (!gmock_globalmock_some_func_foo_instance)   {     throw std::logic_error(\"You forgot to call EXPECT_GLOBAL_CALL for \"                            \"some_func_foo\");   };   return gmock_globalmock_some_func_foo_instance-&gt;some_func_foo(gmock_a1); }; <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u0432\u043e\u0439\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 some_func_foo \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<pre><code class=\"cpp\">::testing::internal::Function&lt;int(int)&gt;::Result some_func_foo(::testing::internal::Function&lt;int(int)&gt;::template Arg&lt;1 - 1&gt;::type gmock_a1) <\/code><\/pre>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u0443 some_func_foo \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0434\u0435\u043b\u0430\u0442\u044c inline, \u0442\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043b\u0438\u043d\u043a\u043e\u0432\u043a\u0438  \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c header \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u0437\u044f\u043b\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442, \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430. \ud83d\ude42<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 gmock-global \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0438\u043d\u0443\u0441. \u0415\u0441\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u043d\u0430\u0434\u043e \u043c\u043e\u043a\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 header \u0444\u0430\u0439\u043b\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a inline, \u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0438\u0441\u043a \u043e\u0448\u0438\u0431\u043a\u0438 \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0430.<\/p>\n<p>\u0418\u0437 \u043a\u0435\u0439\u0441\u0430 \u0432\u044b\u0448\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0432\u043e\u0434\u043e\u0432:<\/p>\n<ul>\n<li>\n<p>gmock-global \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u044b \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/p>\n<\/li>\n<li>\n<p>\u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u0437-\u0437\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0439\u043c\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u0430 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e wrapper \u043d\u0430\u0434 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u043d\u043e \u0441 \u043b\u0435\u0433\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0439 \u0432 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f wrapper \u043d\u0430\u0434 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e GTest\/GMock<\/h3>\n<p>\u041e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043f\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044e <a href=\"https:\/\/google.github.io\/googletest\/gmock_cook_book.html#mocking-free-functions\">\u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u041e\u041e\u041f \u0432\u0440\u0430\u043f\u043f\u0435\u0440 \u043d\u0430\u0434 \u043d\u0430\u0448\u0435\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u043a \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u043a\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">class LibraryInterface{ public:     virtual int wrp_some_func_foo(int a) = 0; };  class MyLibWrapper : public LibraryInterface { public:     int wrp_some_func_foo(int a) override {         return some_func_foo(a);     } };  class LibraryMock : public LibraryInterface { public:     MOCK_METHOD(int, wrp_some_func_foo, (int), (override)); }; <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430, \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u042d\u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0434\u0430\u0435\u0442 \u0438\u043c\u043f\u0430\u043a\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0442\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432 \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u043d\u043e\u0441. \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438.<br \/> \u0412\u0430\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043c\u043e\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u0430 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 global-mock, \u043d\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430, \u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043b\u0438\u043d\u043a\u043e\u0432\u043a\u043e\u0439 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442. \u0427\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, GTest \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0440\u0430\u043f\u043f\u0435\u0440, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434 wrp_some_func_foo.<\/p>\n<pre><code class=\"cpp\">class LibraryMock : public LibraryInterface { public: \/\/some static assert   typename ::testing::internal::Function&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt;::Result wrp_some_func_foo(typename ::testing::internal::Function&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt;::template Arg&lt;0&gt;::type gmock_a0) override   {     gmock01_wrp_some_func_foo_21.SetOwnerAndName(this, \"wrp_some_func_foo\");     return gmock01_wrp_some_func_foo_21.Invoke(::std::forward&lt;typename ::testing::internal::Function&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt;::template Arg&lt;0&gt;::type&gt;(gmock_a0));   }   ::testing::MockSpec&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt; gmock_wrp_some_func_foo(const ::testing::Matcher&lt;typename ::testing::internal::Function&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt;::template Arg&lt;0&gt;::type&gt; &amp;gmock_a0)   {     gmock01_wrp_some_func_foo_21.RegisterOwner(this);     return gmock01_wrp_some_func_foo_21.With(gmock_a0);   }   ::testing::MockSpec&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt; gmock_wrp_some_func_foo(const ::testing::internal::WithoutMatchers &amp;, ::testing::internal::Function&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt; *) const { return ::testing::internal::ThisRefAdjuster&lt;int&gt;::Adjust(*this).gmock_wrp_some_func_foo(::testing::A&lt;typename ::testing::internal::Function&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt;::template Arg&lt;0&gt;::type&gt;()); }   mutable ::testing::FunctionMocker&lt;::testing::internal::identity_t&lt;int&gt;(int)&gt; gmock01_wrp_some_func_foo_21; }; <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0441\u0440\u0430\u0437\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432.<br \/> \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 Foo \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430.<br \/> \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u043d\u0430\u0448\u0438\u043c \u043c\u043e\u043a\u043e\u043c, \u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430 \u043b\u0438\u0431\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043e\u043a\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u0432\u0440\u0430\u043f\u043f\u0435\u0440, \u043d\u043e \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b \u043d\u0430\u0448 \u043c\u043e\u043a.<\/p>\n<pre><code class=\"cpp\">class Foo{ private:     std::shared_ptr&lt;LibraryInterface&gt; lib_wrp; public:     Foo(std::shared_ptr&lt;LibraryInterface&gt; rte_wrp = std::make_shared&lt;MyLibWrapper&gt;());     int CallSomeLibMethod(int a){         return lib_wrp-&gt;wrp_some_func_foo(a);     } };  Foo::Foo(std::shared_ptr&lt;LibraryInterface&gt; rte_wrp) : lib_wrp(rte_wrp){} <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0433\u0438\u0431\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043b\u0438\u0431\u043e \u0432 \u0442\u0435\u0441\u0442\u0430\u0445. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0442\u0435\u0441\u0442-\u043a\u0435\u0439\u0441\u043e\u0432.<br \/> \u0415\u0449\u0435 \u043e\u0434\u043d\u043e \u0434\u043e\u0441\u0442\u043e\u0438\u043d\u0441\u0442\u0432\u043e, \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0432 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e, \u043c\u0435\u043d\u044f\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e, \u0430 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430 \u043e\u0434\u043d\u0443 \u0442\u0430\u0441\u043a\u0443 (\u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u043e\u0442\u043c\u0435\u0447\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f).<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c EXPECT_CALL \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u043e\u043a \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0430.<br \/> \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">TEST(SomeFuncTest, CallsMock) {     std::shared_ptr&lt;LibraryMock&gt; mock = std::make_shared&lt;LibraryMock&gt;();     Foo obj(mock);     EXPECT_CALL(*mock, wrp_some_func_foo(_)).WillRepeatedly(Return(10));     EXPECT_EQ(obj.CallSomeLibMethod(20), 10); } <\/code><\/pre>\n<pre><code>[==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from SomeFuncTest [ RUN      ] SomeFuncTest.CallsMock [       OK ] SomeFuncTest.CallsMock (0 ms) [----------] 1 test from SomeFuncTest (0 ms total)  [----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (0 ms total) [  PASSED  ] 1 test. <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u043a\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0442\u0435\u0441\u0442 \u043a\u0435\u0439\u0441\u043e\u0432.<\/p>\n<h3>\u0412\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>\u0413\u043e\u0432\u043e\u0440\u044f \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043c\u044b \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0443\u043d\u043a\u0442\u0430\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u0435\u0449\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u044b \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u0435\u0437 \u041e\u041e\u041f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043b\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0438 \u0438\u043c\u0435\u0442\u044c \u0433\u0438\u0431\u043a\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043d\u0443\u0436\u043d\u044b\u0445 \u0432\u0430\u043c \u0437\u0430\u0433\u043b\u0443\u0448\u0435\u043a<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u0436\u0435 legacy \u043f\u0440\u043e\u0435\u043a\u0442, \u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0432\u0430 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f (\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430\u0448\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432): <\/p>\n<ul>\n<li>\n<p>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0431\u043e gmock-global \u0438\u043b\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043c\u043e\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u0443\u044e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430-\u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/914372\/\"> https:\/\/habr.com\/ru\/articles\/914372\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041e\u0431\u0449\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430<\/h2>\n<p>Legacy \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0430 \u0421++ \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u044b\u043c\u0438, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438.<br \/> \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e:<\/p>\n<ul>\n<li>\n<p>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043a\u0430\u043a \u041e\u041e\u041f \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 boost, SOCI \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440)<\/p>\n<\/li>\n<li>\n<p>\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 (OpenGL \u0447\u0435\u0440\u0435\u0437 \u0421 API, POSIX \u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440)<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440: \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u043c\u044f\u0442\u0438.<br \/> \u0412\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 &#8212; \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0438\u043c\u0435\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b?<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0443 GTest\/GMock (\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u043a \u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 framework \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 C++) \u0443\u0436\u0435 \u0435\u0441\u0442\u044c <a href=\"https:\/\/google.github.io\/googletest\/gmock_cook_book.html#mocking-free-functions\">\u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a> \u0447\u0435\u0440\u0435\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0440\u0430\u043f\u043f\u0435\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043d\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0439, \u0435\u0441\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0435 \u0431\u044b\u043b\u0430 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 \u041e\u041e\u041f \u0441\u0442\u0438\u043b\u044c, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u0430\u043c\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439.<\/p>\n<h3>\u041e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/apriorit\/gmock-global\/tree\/master\">gmock-global<\/a> &#8212; header \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f mock \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043d\u0435 \u041e\u041e\u041f \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/google\/googletest\">Gtest\/Gmock<\/a> &#8212; gtest framework \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u0430\u043a \u0441\u0430\u043c\u0430\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0421++.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u0440\u0430 \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a gmock-global \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 gtest \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0430\u043f\u043b\u0430\u0442\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u044f \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u043a\u0443\u0441\u043a\u043e\u0432 \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. GTest\/GMock &#8212; \u043a\u0430\u043a \u0441\u0430\u043c\u044b\u0439 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 framework \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0432 legacy \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043d\u0430 C++.<br \/> \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0442\u0438\u043f\u0430 Catch2 \u0438\u043b\u0438 Boost:Test \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u044c\u0441\u044f \u0442.\u043a. \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0439 \u0438\u0445 \u0441 \u043c\u043e\u043a\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0434\u043e\u043f. \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (\u043a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440 FakeIt)<\/p>\n<h2>\u041e\u0431\u043e\u0437\u0440\u0435\u0432\u0430\u0435\u043c\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f<\/h2>\n<p>\u041f\u0443\u0441\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0435\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <em>some_func_foo<\/em>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0412 \u0434\u0430\u043b\u044c\u0439\u0448\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>some_func_foo<\/em>.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430<\/h3>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<\/p>\n<pre><code>lib\/ \u251c\u2500 CMakeLists.txt \u251c\u2500 include\/ \u2502  \u251c\u2500 mylib.h \u251c\u2500 src\/ \u2502  \u251c\u2500 mylib.cpp <\/code><\/pre>\n<p>mylib.h<\/p>\n<pre><code class=\"cpp\">#pragma once  int some_func_foo(int a); <\/code><\/pre>\n<p>mylib.cpp<\/p>\n<pre><code class=\"cpp\">#include \"mylib.h\" #include &lt;iostream&gt;  int some_func_foo(int a){     return 42 + a; } <\/code><\/pre>\n<p>CMakeLists.txt<\/p>\n<pre><code>cmake_minimum_required(VERSION 3.10) project(mylib)  include_directories(${CMAKE_CURRENT_SOURCE_DIR}\/include) add_library(mylib STATIC      src\/mylib.cpp )  set_target_properties(mylib PROPERTIES PUBLIC_HEADER include\/mylib.h)  install(TARGETS mylib         ARCHIVE DESTINATION lib         PUBLIC_HEADER DESTINATION include) <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c static .a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438. \u0414\u0430\u043d\u043d\u0430\u044f \u043b\u0438\u0431\u0430 \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0435\u0440\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0435\u0435 \u0438 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441\u0432\u044f\u0437\u043a\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 + header \u0444\u0430\u0439\u043b.<br \/> \u0414\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 mylib \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:<\/p>\n<pre><code>mkdir build &amp;&amp; cd build cmake .. make make install <\/code><\/pre>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432 \/usr\/local\/lib \u0438 \/usr\/local\/include \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442<\/h3>\n<p>\u041f\u0443\u0441\u0442\u044c \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <em>some_func_foo<\/em><\/p>\n<pre><code class=\"cpp\">class Foo{ public:     int CallSomeLibMethod(int a){         return some_func_foo(a);     } }; <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 <em>some_func_foo<\/em> \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0438\u043b\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b.<br \/> \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 gmock-global, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<h3>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 gmock-global<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 gmock-global \u0438\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 header \u0444\u0430\u0439\u043b\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441\u0435\u0431\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442<br \/> \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430:<\/p>\n<pre><code>test\/ \u251c\u2500 CMakeLists.txt \u251c\u2500 include\/ \u2502  \u251c\u2500 gmock-global\/ \u2502  \u2502  \u251c\u2500 gmock-global.h \u251c\u2500 TestSomeFunc.cpp <\/code><\/pre>\n<p>CMakeLists.txt<\/p>\n<pre><code>cmake_minimum_required(VERSION 3.10) project(test_mylib)  find_package(GTest REQUIRED)  add_executable(test_runner      TestSomeFunc.cpp )  target_include_directories(test_runner PRIVATE     include\/ )  target_link_libraries(test_runner PRIVATE     GTest::gtest_main     GTest::gmock      GTest::gmock_main     \"-Wl,--whole-archive\"     \/usr\/local\/lib\/libmylib.a     \"-Wl,--no-whole-archive\" )  enable_testing() add_test(NAME SomeFuncTest COMMAND test_runner) <\/code><\/pre>\n<p>\u0424\u043b\u0430\u0433\u0438 whole-archive \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442.\u043a. \u0442\u0430\u043a\u043e\u0439 \u043a\u0435\u0439\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 framework\u043e\u0432 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 gmock-global<\/h3>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u0438 \u043c\u043e\u043a \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<br \/> \u041f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0448 \u043c\u043e\u043a<\/p>\n<pre><code class=\"cpp\">MOCK_GLOBAL_FUNC1(some_func_foo, int(int)); <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432 \u0442\u0435\u043b\u0435 \u0442\u0435\u0441\u0442\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u0447\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 <em>EXPECT_GLOBAL_CALL<\/em> \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">TEST(SomeFuncTest, CallsMock) {     Foo obj;     EXPECT_GLOBAL_CALL(some_func_foo, some_func_foo(_)).Times(1).WillOnce(Return(10));     EXPECT_EQ(obj.CallSomeLibMethod(42), 10); } <\/code><\/pre>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 header \u0444\u0430\u0439\u043b\u044b \u0438 testing namespace.<br \/> \u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0438\u0436\u0435<\/p>\n<pre><code class=\"cpp\">#include \"mylib.h\" #include &lt;gtest\/gtest.h&gt; #include &lt;gmock\/gmock.h&gt; #include &lt;gmock-global\/gmock-global.h&gt;  using namespace testing; MOCK_GLOBAL_FUNC1(some_func_foo, int(int));  class Foo{ public:     int CallSomeLibMethod(int a){         return some_func_foo(a);     } };  TEST(SomeFuncTest, CallsMock) {     Foo obj;     EXPECT_GLOBAL_CALL(some_func_foo, some_func_foo(_)).Times(1).WillOnce(Return(10));     EXPECT_EQ(obj.CallSomeLibMethod(42), 10); }  int main(int argc, char** argv) {     ::testing::InitGoogleTest(&amp;argc, argv);     return RUN_ALL_TESTS(); } <\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u0430\u043a \u044d\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 GTest\/Gmock.<br \/> \u0421\u043e\u0431\u0435\u0440\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:<\/p>\n<pre><code>mkdir build &amp;&amp; cd build cmake .. make make install <\/code><\/pre>\n<p>\u041d\u043e \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0430 \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0430:<\/p>\n<pre><code>\/usr\/bin\/ld: \/usr\/local\/lib\/libmylib.a(mylib.cpp.o): in function `some_func_foo': mylib.cpp:(.text+0x0): multiple definition of `some_func_foo'; CMakeFiles\/test_runner.dir\/TestSomeFunc.cpp.o:TestSomeFunc.cpp:(.text+0x0): first defined here <\/code><\/pre>\n<p>\u0421 \u0447\u0435\u043c \u044d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e? \u0415\u0441\u043b\u0438 \u0432\u0437\u044f\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 inotify \u0444\u0443\u043d\u043a\u0446\u0438\u044e inotify_init, \u0442\u043e \u043e\u043d\u0430 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043c\u043e\u043a\u0430\u0435\u0442\u0441\u044f<\/p>\n<pre><code class=\"cpp\">#include \"mylib.h\" #include &lt;gtest\/gtest.h&gt; #include &lt;gmock\/gmock.h&gt; #include &lt;gmock-global\/gmock-global.h&gt; #include &lt;sys\/inotify.h&gt;  using namespace testing; \/\/MOCK_GLOBAL_FUNC1(some_func_foo, int(int)); MOCK_GLOBAL_FUNC0(inotify_init, int(void));  class Foo{ public:     int CallSomeLibMethod(int a){         \/\/return some_func_foo(a);         return inotify_init();     } };  TEST(SomeFuncTest, CallsMock) {     Foo obj;     \/\/EXPECT_GLOBAL_CALL(some_func_foo, some_func_foo(_)).Times(1).WillOnce(Return(10));     EXPECT_GLOBAL_CALL(inotify_init, inotify_init()).Times(1).WillOnce(Return(-1));     EXPECT_EQ(obj.CallSomeLibMethod(42), -1); }  int main(int argc, char** argv) {     ::testing::InitGoogleTest(&amp;argc, argv);     return RUN_ALL_TESTS(); } <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code>.\/test_runner  [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from SomeFuncTest [ RUN      ] SomeFuncTest.CallsMock [       OK ] SomeFuncTest.CallsMock (0 ms) [----------] 1 test from SomeFuncTest (0 ms total)  [----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (0 ms total) [  PASSED  ] 1 test. <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443, \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u0434\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043c\u043e\u043a\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 gmock-global, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u043d\u0435\u0442, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043a\u0430\u043a \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441 <em>MOCK_GLOBAL_FUNC0<\/em>.<br \/> \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430 \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u043e\u043a\u0430<\/p>\n<pre><code class=\"cpp\">#define MOCK_GLOBAL_FUNC0_(tn, constness, ct, Method, ...) \\ class gmock_globalmock_##Method { \\ public:\\   gmock_globalmock_##Method(const char* tag) : m_tag(tag) {}  \\   const char* const m_tag; \\   GMOCK_RESULT_(tn, __VA_ARGS__) ct Method () constness {  \\     static_assert((std::tuple_size&lt;                          \\         tn ::testing::internal::Function&lt;__VA_ARGS__&gt;::ArgumentTuple&gt;::value \\             == 0), \\         \"this method does not take 0 arguments\");  \\     GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \\     return GMOCK_MOCKER_(0, constness, Method).Invoke(); \\   } \\   ::testing::MockSpec&lt;__VA_ARGS__&gt; \\       gmock_##Method() constness { \\     GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \\     return GMOCK_MOCKER_(0, constness, Method).With(); \\   } \\   mutable ::testing::FunctionMocker&lt;__VA_ARGS__&gt; GMOCK_MOCKER_(0, constness, \\       Method); \\    }; \\    std::unique_ptr&lt; gmock_globalmock_##Method &gt; gmock_globalmock_##Method##_instance;\\    GMOCK_RESULT_(tn, __VA_ARGS__) ct Method() constness { \\        MOCK_GLOBAL_CHECK_INIT(Method); \\        return gmock_globalmock_##Method##_instance-&gt;Method();\\       }\\  #define MOCK_GLOBAL_FUNC0(m, ...) MOCK_GLOBAL_FUNC0_(, , , m, __VA_ARGS__) <\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 global mock \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441 gmock_globalmock_##Method, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u043e\u043a\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041f\u0440\u0438 \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 <em>some_func_foo<\/em>:<\/p>\n<pre><code class=\"cpp\">class gmock_globalmock_some_func_foo { public:   gmock_globalmock_some_func_foo(const char *tag) : m_tag(tag) {}   const char *const m_tag;   ::testing::internal::Function&lt;int(int)&gt;::Result some_func_foo(::testing::internal::Function&lt;int(int)&gt;::template Arg&lt;1 - 1&gt;::type gmock_a1)   {     static_assert((std::tuple_size&lt;::testing::internal::Function&lt;int(int)&gt;::ArgumentTuple&gt;::value == 1), \"this method does not take 1 arguments\");<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-461670","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/461670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=461670"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/461670\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=461670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=461670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=461670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}