{"id":19119363,"url":"https://github.com/thebeachmaster/gtest","last_synced_at":"2026-06-14T01:33:14.951Z","repository":{"id":85933612,"uuid":"131287492","full_name":"TheBeachMaster/gtest","owner":"TheBeachMaster","description":"Build and Test C++ libraries with Google Test Framework","archived":false,"fork":false,"pushed_at":"2018-04-27T12:44:21.000Z","size":1057,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-20T11:09:32.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheBeachMaster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-27T11:25:40.000Z","updated_at":"2018-04-27T12:44:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"1cd436bc-8659-4040-b4fb-6008182f6d81","html_url":"https://github.com/TheBeachMaster/gtest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TheBeachMaster/gtest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBeachMaster%2Fgtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBeachMaster%2Fgtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBeachMaster%2Fgtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBeachMaster%2Fgtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheBeachMaster","download_url":"https://codeload.github.com/TheBeachMaster/gtest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheBeachMaster%2Fgtest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34306772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T05:09:21.004Z","updated_at":"2026-06-14T01:33:14.944Z","avatar_url":"https://github.com/TheBeachMaster.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gtest\nBuild and Test C++ libraries with Google Test Framework \n \n\u003e This repo should provide a basic understanding of how to use Google Test Framework, and Linking libraries using CMake Build tool\n \n\u003e Build Status \n\n\n[![Travis](https://img.shields.io/travis/TheBeachMaster/gtest.svg?style=for-the-badge)](https://travis-ci.org/TheBeachMaster/gtest/)\n  \n\n\u003e Basics \n\n- CMakeList \n\n\u003cdetails\u003e\n\u003csummary\u003e  \nCMake Configuration \n\u003c/summary\u003e \n\n \n ```text \n\n# CMake Version\ncmake_minimum_required(VERSION 2.8)\n\n# Project Name\nproject(MathFunc CXX)\n\n# Build for Release\nset(CMAKE_BUILD_TYPE Release)\nmessage(WARNING \"A ${CMAKE_BUILD_TYPE} build configuration is detected\")\n\n# Where to throw Binaries\nset(CMAKE_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/lib)\nset(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/out)\nset(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})\nset(LIBRARY_OUTPUT_PATH ${CMAKE_LIBRARY_DIR})\n\n# Add directories\nset(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/lib)\ninclude_directories(\"${PROJECT_INCLUDE_DIR}\")\ninclude_directories(\"${PROJECT_SOURCE_DIR}\")\n\n# Optional args for running Google Test\noption (DO_TEST \"Run Google Test\" OFF) \n\n# Add Source Files\nset(PROJECT_SRCS  ${PROJECT_SOURCE_DIR}/src/main.cc )\n\n# Add Library Source Files\nset(LIB_SRC  ${PROJECT_SOURCE_DIR}/lib/mymathfunc.cc )\n\n# Build shared Libs\nadd_library(${PROJECT_NAME}_shared SHARED ${LIB_SRC})\nset(SHARED_LIB ${PROJECT_NAME}_shared)\n\n# Build static Libs\nadd_library(${PROJECT_NAME}_static STATIC ${LIB_SRC})\nset(STATIC_LIB ${PROJECT_NAME}_static)\n\n# Fix symbol visibility\ninclude(GenerateExportHeader)\nGENERATE_EXPORT_HEADER(${SHARED_LIB}\n    BASE_NAME ${SHARED_LIB}\n    EXPORT_MACRO_NAME ${SHARED_LIB}_EXPORTS\n    EXPORT_FILE_NAME ${SHARED_LIB}_EXPORTS.h\n    STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC)\n\n    \nif(DO_TEST)\n    include_directories(\"${PROJECT_SOURCE_DIR}/include/googletest/googletest/include\")\n    add_subdirectory(include/googletest)\n    set(TEST_LIBS_FLAGS ${CMAKE_LIBRARY_DIR}/libgtest_main.a m gtest pthread ${SHARED_LIB})\n    add_executable(test_mathfunc \n        ${PROJECT_SOURCE_DIR}/test/test_mymathfunc.cc) \n    add_dependencies(test_mathfunc gtest_main)\n    target_link_libraries(test_mathfunc ${TEST_LIBS_FLAGS})\nendif (DO_TEST)\n\n# Build Exec\nadd_executable(${PROJECT_NAME}_st ${PROJECT_SRCS})\ntarget_link_libraries(${PROJECT_NAME}_st ${STATIC_LIB})\n\nadd_executable(${PROJECT_NAME}_sh ${PROJECT_SRCS})\ntarget_link_libraries(${PROJECT_NAME}_sh ${SHARED_LIB}) \n\n```       \n\n\n\u003c/details\u003e \n \n-  Library \n\n\u003cdetails\u003e \n\u003csummary\u003e \nSample Library File \n\u003c/summary\u003e \n\n```c++ \n#include \"mymathfunc.hpp\"\n\n    double MyMathFunc::add(double a, double b)\n    {\n        return a + b;\n    }\n\n    double MyMathFunc::multiply(double a, double b)\n    {\n        return a * b;\n    }\n\n    double MyMathFunc::divide(double a, double b)\n    {\n        return a / b;\n    }\n\n    double MyMathFunc::subtract(double a, double b)\n    {\n        return a - b;\n    }\n\n    double MyMathFunc::square(double a)\n    {\n        return a * a;\n    }\n```   \n \n```c++ \n#ifndef MYMATHFUNC_H\n#define MYMATHFUNC_H\n\n    class MyMathFunc\n    {\n    public:\n        MyMathFunc(){}\n        static double add(double a, double b);\n        static double subtract(double a, double b);\n        static double multiply(double a, double b);\n        static double divide(double a, double b);\n        static double square(double a);\n        \n    };\n\n#endif // !MYMATHFUNC_H\n```   \n\n\u003c/details\u003e   \n \n-  Test \n\n\u003cdetails\u003e\n\u003csummary\u003e\nTest Cases \n\u003c/summary\u003e \n\n```c++ \n #include \"../lib/mymathfunc.hpp\"\n#include \u003cgtest/gtest.h\u003e\n#include \u003ciostream\u003e\n#include \u003ccstdlib\u003e\n\nusing namespace std;\nMyMathFunc func_test;\n\nclass MyMathFuncTest : public ::testing::Test {\nprotected:\n\tvirtual void SetUp() { }\n\tvirtual void TearDown() {}\npublic:\n    static const double a = 47.98;\n    static const double b = 18.25;\n};\n\nTEST_F(MyMathFuncTest, test_addition)\n{\n    EXPECT_DOUBLE_EQ(66.23,func_test.add(a, b));\n}\n\nTEST_F(MyMathFuncTest, test_subtraction)\n{\n    EXPECT_DOUBLE_EQ(29.73,func_test.subtract(a, b));\n}\nTEST_F(MyMathFuncTest, test_division)\n{\n    EXPECT_NEAR(2.62904, func_test.divide(a, b), 0.0000011);\n}\nTEST_F(MyMathFuncTest, test_multiply)\n{\n    EXPECT_DOUBLE_EQ(875.635,func_test.multiply(a, b));\n}\nTEST_F(MyMathFuncTest, test_square)\n{\n    EXPECT_DOUBLE_EQ(2302.0804,func_test.square(a));\n    EXPECT_DOUBLE_EQ(333.0625,func_test.square(b));\n}\nint main(int argc, char * argv[])\n{\n\t/*The method is initializes the Google framework and must be called before RUN_ALL_TESTS */\n\t::testing::InitGoogleTest(\u0026argc, argv);\n\n\t/*RUN_ALL_TESTS automatically detects and runs all the tests defined using the TEST macro.\n\tIt's must be called only once in the code because multiple calls lead to conflicts and,\n\ttherefore, are not supported.\n\t*/\n\treturn RUN_ALL_TESTS();\n}\n``` \n   \n\u003c/details\u003e   \n \n- App file \n\n\u003cdetails\u003e \n\u003csummary\u003e \nApplication File \n\u003c/summary\u003e  \n\n```c++ \n #include \u003ciostream\u003e\n#include \u003ccstdlib\u003e\n#include \"../lib/mymathfunc.hpp\"\n\nusing namespace std;\nMyMathFunc func;\nint main()\n{\n    \n    double a = 19.85;\n    double b = 8.91;\n    \n    cout \u003c\u003c \"a + b = \" \u003c\u003c\n        func.add(a, b) \u003c\u003c endl;\n    cout \u003c\u003c \"a - b = \" \u003c\u003c\n        func.subtract(a, b) \u003c\u003c endl;\n    cout \u003c\u003c \"a * b = \" \u003c\u003c\n        func.multiply(a, b) \u003c\u003c endl;\n    cout \u003c\u003c \"a / b = \" \u003c\u003c\n        func.divide(a, b) \u003c\u003c endl;\n    cout \u003c\u003c \"a * a = \" \u003c\u003c\n        func.square(a) \u003c\u003c endl;\n    return 0;\n}\n``` \n\n\u003c/details\u003e  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthebeachmaster%2Fgtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthebeachmaster%2Fgtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthebeachmaster%2Fgtest/lists"}