### Setting up Qt (Linux) Source: https://github.com/rezonality/zep/blob/master/README.md Installs the default Qt5 development packages using apt and sets an environment variable QT_INSTALL_LOCATION pointing to the Qt installation path. This variable needs to be adjusted based on the actual installation location. ```bash # for Qt/Demo support sudo apt install qt5-default # Adapt to your installation path - you will need to set this appropriately set QT_INSTALL_LOCATION="/usr/include/x86_64-linux-gnu/qt5" ``` -------------------------------- ### Checkout Google Test Source via SVN (Quick Start) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_6_XcodeGuide.md Provides the Subversion command to download the Google Test source code trunk from the official repository as part of the quick start guide for integrating Google Test into an Xcode project. ```Shell svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only ``` -------------------------------- ### Google Test Main Function and Test Fixture Example (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_7_Primer.md Provides a complete boilerplate example for a Google Test executable's `main()` function, including the necessary `::testing::InitGoogleTest()` call and the `RUN_ALL_TESTS()` macro. It also demonstrates defining a test fixture (`FooTest`) with `SetUp` and `TearDown` methods and defining test cases (`TEST_F`). ```C++ #include "this/package/foo.h" #include "gtest/gtest.h" namespace { // The fixture for testing class Foo. class FooTest : public ::testing::Test { protected: // You can remove any or all of the following functions if its body // is empty. FooTest() { // You can do set-up work for each test here. } virtual ~FooTest() { // You can do clean-up work that doesn't throw exceptions here. } // If the constructor and destructor are not enough for setting up // and cleaning up each test, you can define the following methods: virtual void SetUp() { // Code here will be called immediately after the constructor (right // before each test). } virtual void TearDown() { // Code here will be called immediately after each test (right // before the destructor). } // Objects declared here can be used by all tests in the test case for Foo. }; // Tests that the Foo::Bar() method does Abc. TEST_F(FooTest, MethodBarDoesAbc) { const string input_filepath = "this/package/testdata/myinputfile.dat"; const string output_filepath = "this/package/testdata/myoutputfile.dat"; Foo f; EXPECT_EQ(0, f.Bar(input_filepath, output_filepath)); } // Tests that Foo does Xyz. TEST_F(FooTest, DoesXyz) { // Exercises the Xyz feature of Foo. } } // namespace int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ``` -------------------------------- ### Install Google Mock Libraries and Headers Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/CMakeLists.txt Defines installation rules for the built libraries (`gmock` and `gmock_main`) and the Google Mock public header files. Libraries are installed to the `lib` destination, and headers to the `include/gmock` destination. ```CMake install(TARGETS gmock gmock_main DESTINATION lib) install(DIRECTORY ${gmock_SOURCE_DIR}/include/gmock DESTINATION include) ``` -------------------------------- ### Install Zep ImGui Demo Executable Target - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Defines installation rules for the `ZepDemo` executable target, handling platform-specific requirements like macOS bundles. It specifies destinations for the executable, archives, and libraries during installation. ```CMake if (APPLE) install(TARGETS ${DEMO_NAME} EXPORT zep-targets COMPONENT binaries BUNDLE DESTINATION . COMPONENT Runtime RUNTIME DESTINATION bin COMPONENT Runtime ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS}) else() install(TARGETS ${DEMO_NAME} EXPORT zep-targets COMPONENT binaries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/imgui INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS} ) endif() ``` -------------------------------- ### Installing Dependencies (Linux) Source: https://github.com/rezonality/zep/blob/master/README.md Installs necessary build tools (cmake) and version control (git) using apt on Linux systems. Requires root privileges. ```bash sudo apt install cmake sudo apt install git ``` -------------------------------- ### Setting and Getting Text with Clip Library (C++) Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/clip/README.md This snippet demonstrates the basic usage of the clip library to copy text to the clipboard using `clip::set_text` and retrieve it using `clip::get_text`. It includes necessary headers and prints the retrieved text to the console. ```C++ #include "clip.h" #include int main() { clip::set_text("Hello World"); std::string value; clip::get_text(value); std::cout << value << "\n"; } ``` -------------------------------- ### Install Font File for Zep ImGui Demo - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Configures the installation rule for the `Cousine-Regular.ttf` font file, ensuring it is copied to the `imgui` subdirectory within the installation's binary directory (`${CMAKE_INSTALL_BINDIR}`). ```CMake install(FILES ${DEMO_ROOT}/demo_imgui/res/Cousine-Regular.ttf COMPONENT binaries DESTINATION ${CMAKE_INSTALL_BINDIR}/imgui ) ``` -------------------------------- ### Run windeployqt and Install Output (CMake) Source: https://github.com/rezonality/zep/blob/master/demos/demo_qt/CMakeLists.txt If the `Qt6::windeployqt` target exists, this block adds a post-build custom command to execute `windeployqt` on the built application executable in a temporary directory. It then defines an installation rule to copy the contents of this temporary deployment directory to the installation bin directory. ```CMake if(TARGET Qt6::windeployqt) # execute windeployqt in a tmp directory after build add_custom_command(TARGET ${DEMO_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/windeployqt" COMMAND set PATH=%PATH%$${qt5_install_prefix}/bin COMMAND Qt6::windeployqt --dir "${CMAKE_CURRENT_BINARY_DIR}/windeployqt" "$/$" ) # copy deployment directory during installation install( DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/windeployqt/" DESTINATION ${CMAKE_INSTALL_BINDIR}/qt COMPONENT binaries ) endif() ``` -------------------------------- ### Setting up Qt (Windows) Source: https://github.com/rezonality/zep/blob/master/README.md Sets the environment variable QT_INSTALL_LOCATION to the path of the Qt installation directory on Windows. This path should be updated to match the user's specific Qt installation. ```bat set QT_INSTALL_LOCATION=C:\Qt\5.10.0\msvc2017_64 ``` -------------------------------- ### Install Zep Include Directory Source: https://github.com/rezonality/zep/blob/master/demos/demo_qt/CMakeLists.txt Installs the Zep include directory to the standard CMake include installation path, making the Zep headers available for other projects. ```CMake install(DIRECTORY ${ZEP_ROOT}/include/zep COMPONENT source DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### Installing Dependencies (Mac) Source: https://github.com/rezonality/zep/blob/master/README.md Installs necessary build tools (cmake) and version control (git) using Homebrew on macOS systems. Requires Homebrew to be installed. ```bash brew install cmake brew install git ``` -------------------------------- ### Define Installation Rules for Executable Source: https://github.com/rezonality/zep/blob/master/demos/demo_qt/CMakeLists.txt Specifies how the executable target should be installed, including destinations for the executable itself (bundled on macOS, in a 'qt' subdirectory on others) and associated files. ```CMake if (APPLE) install(TARGETS ${DEMO_NAME} EXPORT zep-targets COMPONENT binaries BUNDLE DESTINATION . COMPONENT Runtime RUNTIME DESTINATION bin COMPONENT Runtime ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS} ) else() install(TARGETS ${DEMO_NAME} EXPORT zep-targets COMPONENT binaries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/qt INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS} ) endif() ``` -------------------------------- ### Add Example Executable using add_example Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/clip/examples/CMakeLists.txt Calls the previously defined `add_example` function with a specific name (e.g., 'copy', 'helloworld', 'paste', etc.). This single line expands to adding an executable and linking it to the `clip` library, demonstrating the function's usage for configuring multiple examples efficiently. ```CMake add_example(copy) ``` -------------------------------- ### Building and Installing Library (Windows) Source: https://github.com/rezonality/zep/blob/master/README.md Creates and navigates into a build directory, configures CMake to build only the Zep library (disabling demos and tests) using Visual Studio 2022, and then builds and installs the library to the system. ```cmake mkdir build cd build cmake -G "Visual Studio 17 2022" -DBUILD_IMGUI=0 -DBUILD_TESTS=0 -DBUILD_DEMOS=0 .. cmake --build . --target install ``` -------------------------------- ### Adding Examples and Tests Subdirectories Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/clip/CMakeLists.txt Includes the 'examples' and 'tests' subdirectories in the build process if the respective CMake options are enabled, and enables testing for the 'tests' subdirectory. ```CMake if(CLIP_EXAMPLES) add_subdirectory(examples) endif() if(CLIP_TESTS) enable_testing() add_subdirectory(tests) endif() ``` -------------------------------- ### Define Installation Rules for Libraries and Headers Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/CMakeLists.txt Specifies the rules for installing the built `gtest` and `gtest_main` libraries to the `lib` destination and the public header files (`include/gtest`) to the `include` destination during the installation step (`make install` or `cmake --install`). ```CMake install(TARGETS gtest gtest_main DESTINATION lib) install(DIRECTORY ${gtest_SOURCE_DIR}/include/gtest DESTINATION include) ``` -------------------------------- ### Integrating Library with CMake Source: https://github.com/rezonality/zep/blob/master/README.md Demonstrates how to find the installed Zep library using find_package and link it to a target project (MYPROJECT) in a CMakeLists.txt file. Requires the Zep library to be installed on the system. ```cmake find_package(Zep REQUIRED) target_link_libraries(MYPROJECT PRIVATE Zep::Zep) ``` -------------------------------- ### Examples of Field and Property Matchers in Google Mock C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_6/CookBook.md Provides specific examples demonstrating the usage of `Field` and `Property` matchers. `Field(&Foo::number, Ge(3))` matches a `Foo` object (or pointer) where the `number` member is >= 3. `Property(&Foo::name, StartsWith("John "))` matches a `Foo` object (or pointer) where the `name()` method returns a string starting with "John ". ```C++ Field(&Foo::number, Ge(3)) ``` ```C++ Property(&Foo::name, StartsWith("John ")) ``` -------------------------------- ### Installing Zep Target Files in CMake Source: https://github.com/rezonality/zep/blob/master/src/CMakeLists.txt Defines the installation rules for the 'Zep' target, specifying destinations for the archive, library, runtime files, and include directories upon installation. ```CMake install(TARGETS Zep EXPORT zep-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${LIBLEGACY_INCLUDE_DIRS} ) ``` -------------------------------- ### Execute Post-Project Hermetic Setup Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/CMakeLists.txt If the `set_up_hermetic_build` command exists, this block executes it after the project has been defined. This function performs setup steps that require the project context. ```CMake if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() ``` -------------------------------- ### Execute Pre-Project Hermetic Setup Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/CMakeLists.txt If the `pre_project_set_up_hermetic_build` command exists (meaning the hermetic build script was included), this block executes it. This function performs setup steps before the main project definition. ```CMake if (COMMAND pre_project_set_up_hermetic_build) pre_project_set_up_hermetic_build() endif() ``` -------------------------------- ### Example Google Mock Test Flow - C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_6/CheatSheet.md Provides a complete example demonstrating the typical sequence of steps in a Google Mock test: importing names, creating mocks, setting default actions, setting expectations, exercising code, and implicit verification on destruction. ```C++ using ::testing::Return; // #1 TEST(BarTest, DoesThis) { MockFoo foo; // #2 ON_CALL(foo, GetSize()) // #3 .WillByDefault(Return(1)); // ... other default actions ... EXPECT_CALL(foo, Describe(5)) // #4 .Times(3) .WillRepeatedly(Return("Category 5")); // ... other expectations ... EXPECT_EQ("good", MyProductionFunction(&foo)); // #5 } // #6 ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/rezonality/zep/blob/master/CMakeLists.txt Installs the generated package configuration and version files to the specified destination, making the package discoverable. ```CMake install( FILES ${CMAKE_BINARY_DIR}/cmake/zep-config.cmake ${CMAKE_BINARY_DIR}/cmake/zep-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zep ) ``` -------------------------------- ### Boilerplate main() function for Google Test (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/Primer.md Provides a standard template for the `main` function in a Google Test executable. It includes necessary headers, defines a test fixture class with `SetUp` and `TearDown`, shows example tests, and demonstrates the required calls to `::testing::InitGoogleTest()` and `RUN_ALL_TESTS()`. ```C++ #include "this/package/foo.h" #include "gtest/gtest.h" namespace { // The fixture for testing class Foo. class FooTest : public ::testing::Test { protected: // You can remove any or all of the following functions if its body // is empty. FooTest() { // You can do set-up work for each test here. } virtual ~FooTest() { // You can do clean-up work that doesn't throw exceptions here. } // If the constructor and destructor are not enough for setting up // and cleaning up each test, you can define the following methods: virtual void SetUp() { // Code here will be called immediately after the constructor (right // before each test). } virtual void TearDown() { // Code here will be called immediately after each test (right // before the destructor). } // Objects declared here can be used by all tests in the test case for Foo. }; // Tests that the Foo::Bar() method does Abc. TEST_F(FooTest, MethodBarDoesAbc) { const string input_filepath = "this/package/testdata/myinputfile.dat"; const string output_filepath = "this/package/testdata/myoutputfile.dat"; Foo f; EXPECT_EQ(0, f.Bar(input_filepath, output_filepath)); } // Tests that Foo does Xyz. TEST_F(FooTest, DoesXyz) { // Exercises the Xyz feature of Foo. } } // namespace int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ``` -------------------------------- ### Google Mock EXPECT_CALL Example with Times and Return Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_7/ForDummies.md An example demonstrating the use of EXPECT_CALL with Times, WillOnce, and WillRepeatedly clauses to specify the number of calls and different return values for a mock method. ```C++ using ::testing::Return;... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) .WillOnce(Return(150)) .WillRepeatedly(Return(200)); ``` -------------------------------- ### Defining Derived Google Test Fixtures (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/FAQ.md Demonstrates how to create a hierarchy of Google Test fixtures. A base fixture (`BaseTest`) provides common setup/teardown, and derived fixtures (`FooTest`) inherit from it, allowing for shared logic while adding specific setup/teardown or members. Shows the correct way to call base class `SetUp` and `TearDown` methods within the derived class. ```cpp // Defines a base test fixture. class BaseTest : public ::testing::Test { protected: ... }; // Derives a fixture FooTest from BaseTest. class FooTest : public BaseTest { protected: virtual void SetUp() { BaseTest::SetUp(); // Sets up the base fixture first. ... additional set-up work ... } virtual void TearDown() { ... clean-up work for FooTest ... BaseTest::TearDown(); // Remember to tear down the base fixture // after cleaning up FooTest! } ... functions and variables for FooTest ... }; // Tests that use the fixture FooTest. TEST_F(FooTest, Bar) { ... } TEST_F(FooTest, Baz) { ... } ... additional fixtures derived from BaseTest ... ``` -------------------------------- ### Setting up Monomorphic Action Example - C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_5/CookBook.md Includes necessary `using` declarations for gMock components (`_`, `Action`, `ActionInterface`, `MakeAction`) and a `typedef` defining the signature for the mock method used in the example (`int(int*)`). ```C++ using ::testing::_; using ::testing::Action; using ::testing::ActionInterface; using ::testing::MakeAction; typedef int IncrementMethod(int*); ``` -------------------------------- ### Example: Multi-Parameter Google Mock Action (ACTION_P2) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_7/CookBook.md Demonstrates defining an action with multiple parameters using ACTION_P2. The example `ReturnDistanceTo` calculates the Euclidean distance from arguments `arg0` and `arg1` to parameters `x` and `y`. ```C++ ACTION_P2(ReturnDistanceTo, x, y) { double dx = arg0 - x; double dy = arg1 - y; return sqrt(dx*dx + dy*dy); } ``` -------------------------------- ### Deriving Google Test Fixtures in C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_6_FAQ.md Demonstrates how to create a base test fixture and derive specific test fixtures from it to share common setup and teardown logic. It shows the typical structure using `::testing::Test`, `SetUp()`, `TearDown()`, and `TEST_F()`. ```C++ // Defines a base test fixture. class BaseTest : public ::testing::Test { protected: ... }; // Derives a fixture FooTest from BaseTest. class FooTest : public BaseTest { protected: virtual void SetUp() { BaseTest::SetUp(); // Sets up the base fixture first. ... additional set-up work ... } virtual void TearDown() { ... clean-up work for FooTest ... BaseTest::TearDown(); // Remember to tear down the base fixture // after cleaning up FooTest! } ... functions and variables for FooTest ... }; // Tests that use the fixture FooTest. TEST_F(FooTest, Bar) { ... } TEST_F(FooTest, Baz) { ... } ... additional fixtures derived from BaseTest ... ``` -------------------------------- ### Example: Setting Expectations with Times and Actions (Google Mock) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/ForDummies.md A concrete example demonstrating how to use EXPECT_CALL with Times, WillOnce, and WillRepeatedly clauses and the Return action to specify the number of calls and return values for a mock method. ```cpp using ::testing::Return;... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) .WillOnce(Return(150)) .WillRepeatedly(Return(200)); ``` -------------------------------- ### Execute Hermetic Build Setup Function Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/CMakeLists.txt Calls the `set_up_hermetic_build` function if it was defined by the included `hermetic_build.cmake` script. This is part of the hermetic build setup process. ```CMake if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() ``` -------------------------------- ### Example Usage of ASSERT_THAT and EXPECT_THAT with Google Mock Matchers in C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/CookBook.md Provides a concrete example of using EXPECT_THAT and ASSERT_THAT in a Google Test case. It demonstrates checking string properties using StartsWith and MatchesRegex, and checking numeric ranges using AllOf, Ge, and Le. The example highlights the readability and informative output of these assertion macros. Requires including "gmock/gmock.h" and using directives for relevant matchers. ```C++ #include "gmock/gmock.h" using ::testing::AllOf; using ::testing::Ge; using ::testing::Le; using ::testing::MatchesRegex; using ::testing::StartsWith; ... EXPECT_THAT(Foo(), StartsWith("Hello")); EXPECT_THAT(Bar(), MatchesRegex("Line \\d+")); ASSERT_THAT(Baz(), AllOf(Ge(5), Le(10))); ``` -------------------------------- ### Cloning and Initializing Source Source: https://github.com/rezonality/zep/blob/master/README.md Clones the Zep repository, navigates into the directory, initializes and updates git submodules, and runs the platform-specific prebuild script to prepare dependencies. ```bash git clone https://github.com/Rezonality/zep zep cd zep git submodule update --init ./prebuild.sh or prebuild.bat (select based on your system) ``` -------------------------------- ### C++ Example Predicate Function and Test Data Setup Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_5_AdvancedGuide.md Defines a sample boolean predicate function `MutuallyPrime` and constant integer variables `a`, `b`, and `c` used as arguments in subsequent examples demonstrating Google Test's `EXPECT_PRED2` assertion. ```C++ bool MutuallyPrime(int m, int n) { ... } const int a = 3; const int b = 4; const int c = 10; ``` -------------------------------- ### Examples of ASSERT_DEATH Usage - C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/FAQ.md Provides various examples demonstrating the flexibility of the statement argument in Google Test's death assertion macros like ASSERT_DEATH. It shows how the statement can be a simple function call, a complex expression, or even a compound statement, and how death tests can be used within loops. ```cpp // A death test can be a simple function call. TEST(MyDeathTest, FunctionCall) { ASSERT_DEATH(Xyz(5), "Xyz failed"); } // Or a complex expression that references variables and functions. TEST(MyDeathTest, ComplexExpression) { const bool c = Condition(); ASSERT_DEATH((c ? Func1(0) : object2.Method("test")), "(Func1|Method) failed"); } // Death assertions can be used any where in a function. In // particular, they can be inside a loop. TEST(MyDeathTest, InsideLoop) { // Verifies that Foo(0), Foo(1), ..., and Foo(4) all die. for (int i = 0; i < 5; i++) { EXPECT_DEATH_M(Foo(i), "Foo has \\d+ errors", ::testing::Message() << "where i is " << i); } } // A death assertion can contain a compound statement. TEST(MyDeathTest, CompoundStatement) { // Verifies that at lease one of Bar(0), Bar(1), ..., and // Bar(4) dies. ASSERT_DEATH({ for (int i = 0; i < 5; i++) { Bar(i); } }, "Bar has \\d+ errors");} ``` -------------------------------- ### Setup Zep ImGui Demo Project and Variables - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Defines the root directory and name for the demo, declares the CMake project with a version, and includes meta files relevant to the ImGui build. ```CMake set(DEMO_ROOT ${ZEP_ROOT}/demos) set(DEMO_NAME ZepDemo) project(ZepDemo VERSION 0.1.0.0) add_project_meta(META_FILES_TO_INCLUDE IS_IMGUI) ``` -------------------------------- ### View svn:externals Property Example Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_5_XcodeGuide.md Example showing the use of the `svn propget` command to view the `svn:externals` property on a directory ('trunk'). The output demonstrates how an external dependency (Google Test trunk) is configured to be checked out into a specific subdirectory ('externals/src/googletest'). ```Shell [Computer:svn] user$ svn propget svn:externals trunk externals/src/googletest http://googletest.googlecode.com/svn/trunk ``` -------------------------------- ### Build and Run Sample Test with Make Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/README.md Navigates to the Google Test `make/` directory, executes the Makefile to build the library and sample tests, and then runs the compiled sample test executable. ```Shell cd ${GTEST_DIR}/make make ./sample1_unittest ``` -------------------------------- ### Example: Matching Object Method Result with Property (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_5/CookBook.md Provides an example of using the Property matcher to match an object based on the return value of one of its methods. This snippet shows how to match an object 'x' of type Foo if the result of its 'name()' method starts with "John ". The method must be const and take no arguments. ```C++ Property(&Foo::name, StartsWith("John ")) ``` -------------------------------- ### Instantiating Mock Object (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/CookBook.md Shows the simple instantiation of the `MockBuzzer` class, which is used in the subsequent examples to demonstrate setting expectations and actions. ```C++ MockBuzzer mock_buzzer_; ``` -------------------------------- ### Example: Using Google Mock Doctor with Make (Shell) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_5/FrequentlyAskedQuestions.md Provides a specific example demonstrating how to pipe the compiler output from a `make` command for a test target into the Google Mock Doctor tool. ```Shell make my_test 2>&1 | gmd ``` -------------------------------- ### Redirecting Google Test Output (Shell) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/FAQ.md Provides a shell command example for redirecting the standard output of a Google Test executable to a file, separating test results from other log messages. ```shell ./my_test > googletest_output.txt ``` -------------------------------- ### Building Sample Test with Makefile (GNU Make) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/README.md Navigates to the make directory, runs GNU make to build the Google Mock library and a sample test, and then executes the compiled test binary. ```Shell cd ${GMOCK_DIR}/make make ./gmock_test ``` -------------------------------- ### Example: Adding Parameter to Argument in Google Mock ACTION_P Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_7/CookBook.md Provides a simple example of an ACTION_P named `Add` that takes a parameter `n` and returns the sum of the first argument (`arg0`) and the parameter. ```C++ ACTION_P(Add, n) { return arg0 + n; } ``` -------------------------------- ### Field and Property Matcher Examples - Google Mock C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_7/CookBook.md Provides concrete examples of using `Field()` and `Property()` matchers. `Field(&Foo::number, Ge(3))` matches an object whose `number` member is >= 3. `Property(&Foo::name, StartsWith("John "))` matches an object whose `name()` method returns a string starting with "John ". These matchers also work with pointers. ```C++ Field(&Foo::number, Ge(3)) ``` ```C++ Property(&Foo::name, StartsWith("John ")) ``` -------------------------------- ### Examples of ASSERT_THAT/EXPECT_THAT with Google Mock Matchers in C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_7/CookBook.md Provides concrete examples of using `EXPECT_THAT` and `ASSERT_THAT` with various Google Mock matchers (`StartsWith`, `MatchesRegex`, `AllOf`, `Ge`, `Le`) to verify function return values in Google Test assertions. ```C++ #include "gmock/gmock.h" using ::testing::AllOf; using ::testing::Ge; using ::testing::Le; using ::testing::MatchesRegex; using ::testing::StartsWith; ... EXPECT_THAT(Foo(), StartsWith("Hello")); EXPECT_THAT(Bar(), MatchesRegex("Line \\d+")); ASSERT_THAT(Baz(), AllOf(Ge(5), Le(10))); ``` -------------------------------- ### Defining Overloaded Predicate Functions (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_7_FAQ.md Example of defining overloaded functions that might be used as predicates in Google Test assertions like EXPECT_PRED*. This setup can lead to compiler ambiguity when used directly with predicate macros. ```C++ bool IsPositive(int n) { return n > 0; } bool IsPositive(double x) { return x > 0; } ``` -------------------------------- ### Testing Empty Queue State with Google Test Fixture C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_5_Primer.md An example test using the `QueueTest` fixture (`TEST_F`) to verify that a queue object (`q0_`) that was not initialized in the fixture's `SetUp` method is initially empty, using the `EXPECT_EQ` assertion. ```C++ TEST_F(QueueTest, IsEmptyInitially) { EXPECT_EQ(0, q0_.size()); } ``` -------------------------------- ### Defining Boolean Predicate and Variables for Google Test Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_7_AdvancedGuide.md Defines a boolean predicate function MutuallyPrime and integer variables a, b, and c used as arguments in subsequent EXPECT_PRED2 examples. This setup demonstrates how to use existing boolean functions with predicate assertions. ```C++ // Returns true iff m and n have no common divisors except 1. bool MutuallyPrime(int m, int n) { ... } const int a = 3; const int b = 4; const int c = 10; ``` -------------------------------- ### Link Libraries to Zep ImGui Demo Executable - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Links the necessary libraries to the `ZepDemo` executable target. This includes the Zep library itself, SDL2 (handling static vs dynamic linking), imgui, gl3w, tinyfiledialogs, and platform-specific libraries (`${PLATFORM_LINKLIBS}`). ```CMake target_link_libraries (${DEMO_NAME} PRIVATE Zep $ $,SDL2::SDL2,SDL2::SDL2-static> imgui::imgui unofficial::gl3w::gl3w tinyfiledialogs::tinyfiledialogs ${PLATFORM_LINKLIBS} ) ``` -------------------------------- ### Defining Google Test Fixture for Queue - C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_6_Primer.md Creates a test fixture class `QueueTest` inheriting from `::testing::Test`. It declares instances of the `Queue` and uses the `SetUp` method to initialize them with specific data before each test run, providing a consistent starting state. ```C++ class QueueTest : public ::testing::Test { protected: virtual void SetUp() { q1_.Enqueue(1); q2_.Enqueue(2); q2_.Enqueue(3); } // virtual void TearDown() {} Queue q0_; Queue q1_; Queue q2_; }; ``` -------------------------------- ### Basic Google Mock Test Setup in C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_5/ForDummies.md Demonstrates a simple C++ test using Google Mock and Google Test. It includes necessary headers, imports the `testing` namespace, creates a mock object, sets an expectation using `EXPECT_CALL` for a method to be called at least once, exercises the code under test, and initializes/runs the tests. ```C++ #include "path/to/mock-turtle.h" #include #include using ::testing::AtLeast; // #1 TEST(PainterTest, CanDrawSomething) { MockTurtle turtle; // #2 EXPECT_CALL(turtle, PenDown()) // #3 .Times(AtLeast(1)); Painter painter(&turtle); // #4 EXPECT_TRUE(painter.DrawCircle(0, 0, 10)); } // #5 int main(int argc, char** argv) { // The following line must be executed to initialize Google Mock // (and Google Test) before running the tests. ::testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); } ``` -------------------------------- ### Example Google Mock Test with Verbose Output (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_7/CookBook.md Provides a complete example of a Google Mock test case, including defining a mock class, setting expectations using EXPECT_CALL, and making calls to the mock object. This snippet is used to demonstrate the detailed output produced when Google Mock's verbosity is set to "info", showing how calls match expectations. It requires the Google Mock and Google Test libraries. ```C++ using testing::_; using testing::HasSubstr; using testing::Return; class MockFoo { public: MOCK_METHOD2(F, void(const string& x, const string& y)); }; TEST(Foo, Bar) { MockFoo mock; EXPECT_CALL(mock, F(_, _)).WillRepeatedly(Return()); EXPECT_CALL(mock, F("a", "b")); EXPECT_CALL(mock, F("c", HasSubstr("d"))); mock.F("a", "good"); mock.F("a", "b"); } ``` -------------------------------- ### Deriving Google Test Fixtures (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/V1_7_FAQ.md This snippet illustrates how to create a base Google Test fixture (`BaseTest`) and derive specific test fixtures (`FooTest`) from it. It shows the typical pattern for overriding `SetUp` and `TearDown` methods to perform setup and cleanup, including calling the base class methods. It also demonstrates how to use the derived fixture with the `TEST_F` macro. ```C++ // Defines a base test fixture. class BaseTest : public ::testing::Test { protected: ... }; // Derives a fixture FooTest from BaseTest. class FooTest : public BaseTest { protected: virtual void SetUp() { BaseTest::SetUp(); // Sets up the base fixture first. ... additional set-up work ... } virtual void TearDown() { ... clean-up work for FooTest ... BaseTest::TearDown(); // Remember to tear down the base fixture // after cleaning up FooTest! } ... functions and variables for FooTest ... }; // Tests that use the fixture FooTest. TEST_F(FooTest, Bar) { ... } TEST_F(FooTest, Baz) { ... } ... additional fixtures derived from BaseTest ... ``` -------------------------------- ### Examples of EXPECT_THAT and ASSERT_THAT with Matchers in Google Test C++ Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_6/CookBook.md Provides examples of using `EXPECT_THAT` and `ASSERT_THAT` with various Google Mock matchers (`StartsWith`, `MatchesRegex`, `AllOf`, `Ge`, `Le`) to verify the return values of functions within Google Test assertions. ```C++ EXPECT_THAT(Foo(), StartsWith("Hello")); EXPECT_THAT(Bar(), MatchesRegex("Line \\d+")); ASSERT_THAT(Baz(), AllOf(Ge(5), Le(10))); ``` -------------------------------- ### Implementing Google Test Event Listener (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/AdvancedGuide.md Google Test provides an event listener API to receive notifications about test progress and failures. This example shows a simple listener subclassing `EmptyTestEventListener` to print messages when a test starts, ends, or has a test part result. ```C++ class MinimalistPrinter : public ::testing::EmptyTestEventListener { // Called before a test starts. virtual void OnTestStart(const ::testing::TestInfo& test_info) { printf("*** Test %s.%s starting.\n", test_info.test_case_name(), test_info.name()); } // Called after a failed assertion or a SUCCEED() invocation. virtual void OnTestPartResult( const ::testing::TestPartResult& test_part_result) { printf("%s in %s:%d\n%s\n", test_part_result.failed() ? "*** Failure" : "Success", test_part_result.file_name(), test_part_result.line_number(), test_part_result.summary()); } // Called after a test ends. virtual void OnTestEnd(const ::testing::TestInfo& test_info) { printf("*** Test %s.%s ending.\n", test_info.test_case_name(), test_info.name()); } }; ``` -------------------------------- ### Building Demo with CMake (Linux/Mac) Source: https://github.com/rezonality/zep/blob/master/README.md Configures the CMake project to generate Unix Makefiles, disabling Qt and enabling ImGui, and sets the build type to Release. The second command then builds the project using the generated makefiles. ```cmake cmake -G "Unix Makefiles" -DBUILD_QT=OFF -DBUILD_IMGUI=ON -DCMAKE_BUILD_TYPE=Release .. cmake --build . --config Release ``` -------------------------------- ### Set Include Directories for Zep ImGui Demo - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Specifies the directories where the compiler should look for header files when building the `ZepDemo` executable. This includes Zep's core includes, demo includes, DPI and Janet specific includes, Freetype includes, SDL2 root, and the CMake binary directory for generated headers. Freetype includes are added conditionally for non-Windows platforms again, which might be redundant or specific to a build setup. ```CMake target_include_directories(${DEMO_NAME} PRIVATE ${ZEP_ROOT}/include ${ZEP_ROOT}/demos ${ZEP_ROOT}/demos/demo_imgui/dpi ${ZEP_ROOT}/demos/demo_imgui/janet ${FREETYPE_INCLUDE_DIRS} ${SDL2_ROOT_DIR} ${CMAKE_BINARY_DIR}) if (NOT WIN32) target_include_directories(${DEMO_NAME} PRIVATE ${FREETYPE_INCLUDE_DIRS}) endif() ``` -------------------------------- ### EXPECT_CALL Example with Times and Will (Google Mock C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_5/ForDummies.md This Google Mock C++ example demonstrates setting an expectation on the `turtle` object's `GetX()` method. It specifies that the method will be called 5 times, returning 100 the first time, 150 the second, and 200 repeatedly thereafter, illustrating the use of `.Times()`, `.WillOnce()`, and `.WillRepeatedly()`. ```C++ using ::testing::Return;... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) .WillOnce(Return(150)) .WillRepeatedly(Return(200)); ``` -------------------------------- ### Setting up Scenario for IgnoreResult Action (C++) Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/v1_6/CookBook.md Defines helper functions `Process` (returns `int`) and `DoSomething` (returns `string`), and a mock class `MockFoo` with methods `Abc` (returns `void`) and `Xyz` (returns `bool`). This setup provides examples of functions and mock methods with incompatible return types, illustrating the need for `IgnoreResult`. ```C++ using ::testing::_; using ::testing::Invoke; using ::testing::Return; int Process(const MyData& data); string DoSomething(); class MockFoo : public Foo { public: MOCK_METHOD1(Abc, void(const MyData& data)); MOCK_METHOD0(Xyz, bool()); }; ... ``` -------------------------------- ### Example Google Test Using Mock Objects Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googlemock/docs/CheatSheet.md Provides a complete example of a Google Test case demonstrating the typical steps for using mocks: importing names, creating mocks, setting default actions with `ON_CALL`, setting expectations with `EXPECT_CALL`, exercising the code under test, and relying on automatic verification upon mock destruction. ```C++ using ::testing::Return; // #1 TEST(BarTest, DoesThis) { MockFoo foo; // #2 ON_CALL(foo, GetSize()) // #3 .WillByDefault(Return(1)); // ... other default actions ... EXPECT_CALL(foo, Describe(5)) // #4 .Times(3) .WillRepeatedly(Return("Category 5")); // ... other expectations ... EXPECT_EQ("good", MyProductionFunction(&foo)); // #5 } // #6 ``` -------------------------------- ### Using Google Test Predicate Assertions with Overloaded or Template Functions Source: https://github.com/rezonality/zep/blob/master/tests/googletest/googletest/docs/FAQ.md Explains how to use Google Test's ASSERT_PRED* and EXPECT_PRED* macros with overloaded or template functions, which can cause compiler errors due to ambiguity or preprocessor issues. Provides examples of problematic usage and correct workarounds using explicit casts or parentheses. ```cpp bool IsPositive(int n) { return n > 0; } bool IsPositive(double x) { return x > 0; } ``` ```cpp EXPECT_PRED1(IsPositive, 5); ``` ```cpp EXPECT_PRED1(*static_cast*(IsPositive), 5); ``` ```cpp template bool IsNegative(T x) { return x < 0; } ``` ```cpp ASSERT_PRED1(IsNegative**, -5); ``` ```cpp ASSERT_PRED2(*GreaterThan*, 5, 0); ``` ```cpp ASSERT_PRED2(*(GreaterThan)*, 5, 0); ``` -------------------------------- ### Installing Zep Include Directory in CMake Source: https://github.com/rezonality/zep/blob/master/src/CMakeLists.txt Installs the public include directory containing Zep headers to the specified installation include directory. ```CMake install(DIRECTORY ${ZEP_ROOT}/include/zep DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### Building Demo with CMake (Windows) Source: https://github.com/rezonality/zep/blob/master/README.md Configures the CMake project to generate a Visual Studio 2022 solution, disabling Qt and enabling ImGui, and sets the build type to Release. The second command then builds the project using the generated solution. Assumes Visual Studio 2022 is installed. ```cmake cmake -G "Visual Studio 17 2022" -DBUILD_QT=OFF -DBUILD_IMGUI=ON -DCMAKE_BUILD_TYPE=Release .. cmake --build . --config Release ``` -------------------------------- ### Registering and Setting Custom Clipboard Format with Clip Library (C++) Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/clip/README.md This example shows how to register a user-defined clipboard format using `clip::register_format`. It then uses a `clip::lock` to clear the clipboard and set data for both the standard text format and the newly registered custom format. ```C++ #include "clip.h" int main() { clip::format my_format = clip::register_format("com.appname.FormatName"); int value = 32; clip::lock l; l.clear(); l.set_data(clip::text_format(), "Alternative text for value 32"); l.set_data(my_format, &value, sizeof(int)); } ``` -------------------------------- ### Find Required Dependencies for Zep ImGui Demo - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Locates necessary external libraries using `find_package`, ensuring that tinyfiledialogs, SDL2, imgui, gl3w, and Freetype are available and configured before proceeding with the build. ```CMake find_package(tinyfiledialogs CONFIG REQUIRED) find_package(SDL2 CONFIG REQUIRED) find_package(imgui CONFIG REQUIRED) find_package(gl3w CONFIG REQUIRED) find_package(Freetype CONFIG REQUIRED) ``` -------------------------------- ### Define Source Files for Zep ImGui Demo - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt Specifies the source files required for the demo executable, including platform-specific clipboard (`clip`) sources conditionally based on the operating system (Windows, macOS, X11), and lists all core demo and Zep ImGui integration source files. ```CMake set(CLIP_SOURCE ${DEMO_ROOT}/demo_imgui/clip/clip.cpp ${DEMO_ROOT}/demo_imgui/clip/image.cpp ) if(WIN32) LIST(APPEND CLIP_SOURCE ${DEMO_ROOT}/demo_imgui/clip/clip_win.cpp) endif() if (UNIX) if (APPLE) LIST(APPEND CLIP_SOURCE ${DEMO_ROOT}/demo_imgui/clip/clip_osx.mm) else() LIST(APPEND CLIP_SOURCE ${DEMO_ROOT}/demo_imgui/clip/clip_x11.cpp) endif() # APPLE endif() # UNIX set(DEMO_SOURCE_IMGUI ${DEMO_ROOT}/demo_imgui/janet/janet.c ${DEMO_ROOT}/demo_imgui/janet_utils.cpp ${DEMO_ROOT}/demo_imgui/main.cpp ${DEMO_ROOT}/demo_imgui/dpi/dpi.cpp ${DEMO_ROOT}/demo_imgui/dpi/dpi.h ${DEMO_ROOT}/demo_imgui/CMakeLists.txt ${ZEP_ROOT}/include/zep/imgui/display_imgui.h ${ZEP_ROOT}/include/zep/imgui/editor_imgui.h ${META_FILES_TO_INCLUDE} ${CLIP_SOURCE} ) ``` -------------------------------- ### Handle Conditional Resource Deployment and Linking - CMake Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/CMakeLists.txt On Windows, this command copies existing resource files (`${RESOURCE_DEPLOY_FILES}`) to the build output directory. On non-Windows platforms, it links the Freetype libraries to the demo executable. ```CMake if (WIN32) copy_existing_files(${PROJECT_NAME} "${RESOURCE_DEPLOY_FILES}" ${CMAKE_CURRENT_BINARY_DIR}/$(Configuration) ) else() target_link_libraries (${DEMO_NAME} PRIVATE ${FREETYPE_LIBRARIES} ) endif() ``` -------------------------------- ### Include GNUInstallDirs Module Source: https://github.com/rezonality/zep/blob/master/CMakeLists.txt Includes the standard GNUInstallDirs module to define standard installation directory variables (like CMAKE_INSTALL_LIBDIR, CMAKE_INSTALL_BINDIR, etc.). ```CMake include(GNUInstallDirs) ``` -------------------------------- ### Defining Build Options Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/clip/CMakeLists.txt Defines CMake options that allow users to control whether examples, tests, and X11 PNG image support are included in the build. ```CMake option(CLIP_EXAMPLES "Compile clip examples" on) option(CLIP_TESTS "Compile clip tests" on) if(UNIX AND NOT APPLE) option(CLIP_X11_WITH_PNG "Compile with libpng to support copy/paste image in png format" on) endif() ``` -------------------------------- ### Define CMake Function add_example Source: https://github.com/rezonality/zep/blob/master/demos/demo_imgui/clip/examples/CMakeLists.txt Defines a reusable CMake function named `add_example` that takes one argument, `name`. Inside the function, it creates an executable with the given `name` from a source file named `${name}.cpp` and links this executable against the `clip` library target. ```CMake function(add_example name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} clip) endfunction() ``` -------------------------------- ### Locating Built Demo (Windows) Source: https://github.com/rezonality/zep/blob/master/README.md Provides the typical relative path to the built ImGui demo executable on Windows after a successful build in the Debug configuration. ```bat .\build\demos\demo_imgui\Debug\ZepDemo.exe ```