### Install kissfft with custom prefix using Make Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/README.md Installs kissfft with the installation prefix '/tmp/1234' and the same build options as the previous Make example. ```bash make PREFIX=/tmp/1234 KISSFFT_DATATYPE=int16_t KISSFFT_STATIC=1 KISSFFT_OPENMP=1 install ``` -------------------------------- ### CMakeLists.txt: Install chromaprint library Source: https://github.com/acoustid/chromaprint/blob/master/src/CMakeLists.txt Installs the chromaprint target, exporting it as ChromaprintTargets, placing the library, headers, and public header in the appropriate install directories, and assigning the component 'chromaprint'. ```CMake install(TARGETS chromaprint EXPORT ChromaprintTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT chromaprint ) ``` -------------------------------- ### Install Google Mock libraries Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/googlemock/CMakeLists.txt Installs the gmock and gmock_main libraries using the install_project function. ```cmake install_project(gmock gmock_main) ``` -------------------------------- ### Build and install GoogleTest with make Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/googletest/README.md Builds GoogleTest with make and installs it to /usr/local/ by default. ```bash make sudo make install # Install in /usr/local/ by default ``` -------------------------------- ### EXPECT_THAT with matchers example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/assertions.md Shows how to use EXPECT_THAT and ASSERT_THAT with matchers like StartsWith, MatchesRegex, AllOf, Gt, and Lt. Requires including and using the testing namespace. The example verifies that value1 starts with "Hello", value2 matches a regular expression, and value3 is between 5 and 10. ```cpp #include using ::testing::AllOf; using ::testing::Gt; using ::testing::Lt; using ::testing::MatchesRegex; using ::testing::StartsWith; ... EXPECT_THAT(value1, StartsWith("Hello")); EXPECT_THAT(value2, MatchesRegex("Line \\d+")); ASSERT_THAT(value3, AllOf(Gt(5), Lt(10))); ``` -------------------------------- ### Configure cross-compilation installation Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/pkgconfig.md Set the installation prefix and use DESTDIR to install GoogleTest into your sysroot. ```bash mkdir build && cmake -DCMAKE_INSTALL_PREFIX=/usr .. make -j install DESTDIR=/home/MYUSER/sysroot ``` -------------------------------- ### Install MinGW32 environment Source: https://github.com/acoustid/chromaprint/wiki/Building-on-Linux Install the MinGW32 cross-compilation environment on Ubuntu using apt-get. ```console $ sudo apt-get install mingw32 ``` -------------------------------- ### Install kissfft with custom prefix using CMake Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/README.md Installs kissfft with the installation prefix '/tmp/1234' using CMake. Configures with the prefix and build options, then builds and installs. ```bash mkdir build && cd build cmake -DCMAKE_INSTALL_PREFIX=/tmp/1234 -DKISSFFT_DATATYPE=int16_t -DKISSFFT_STATIC=ON -DKISSFFT_OPENMP=ON .. make all make install ``` -------------------------------- ### REGISTER_TYPED_TEST_SUITE_P example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Example showing how to define a type-parameterized test suite, define tests, and register them with REGISTER_TYPED_TEST_SUITE_P. ```cpp // Define the test suite and tests. TYPED_TEST_SUITE_P(MyFixture); TYPED_TEST_P(MyFixture, HasPropertyA) { ... } TYPED_TEST_P(MyFixture, HasPropertyB) { ... } // Register the tests in the test suite. REGISTER_TYPED_TEST_SUITE_P(MyFixture, HasPropertyA, HasPropertyB); ``` -------------------------------- ### Example of EXPECT_CALL with multiple actions Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_for_dummies.md A practical example showing how to define a sequence of return values for a method call. ```cpp using ::testing::Return; ... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) .WillOnce(Return(150)) .WillRepeatedly(Return(200)); ``` -------------------------------- ### Install rules for gtest and gtest_main Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/googletest/CMakeLists.txt Installs the gtest and gtest_main targets. ```cmake install_project(gtest gtest_main) ``` -------------------------------- ### Custom Predicate-Formatter Example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/assertions.md An example showing how to define a predicate-formatter and use it with EXPECT_PRED_FORMAT2. ```cpp // Returns the smallest prime common divisor of m and n, // or 1 when m and n are mutually prime. int SmallestPrimeCommonDivisor(int m, int n) { ... } // Returns true if m and n have no common divisors except 1. bool MutuallyPrime(int m, int n) { ... } // A predicate-formatter for asserting that two integers are mutually prime. testing::AssertionResult AssertMutuallyPrime(const char* m_expr, const char* n_expr, int m, int n) { if (MutuallyPrime(m, n)) return testing::AssertionSuccess(); return testing::AssertionFailure() << m_expr << " and " << n_expr << " (" << m << " and " << n << ") are not mutually prime, " << "as they have a common divisor " << SmallestPrimeCommonDivisor(m, n); } ... const int a = 3; const int b = 4; const int c = 10; ... EXPECT_PRED_FORMAT2(AssertMutuallyPrime, a, b); // Succeeds EXPECT_PRED_FORMAT2(AssertMutuallyPrime, b, c); // Fails ``` -------------------------------- ### Install kissfft library and headers Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/CMakeLists.txt Installs the kissfft target and its public headers to the appropriate directories, and exports the CMake target with the kissfft:: namespace. ```cmake install(TARGETS kissfft EXPORT kissfft ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(FILES kiss_fft.h kissfft.hh kiss_fftnd.h kiss_fftndr.h kiss_fftr.h DESTINATION "${PKGINCLUDEDIR}") ``` -------------------------------- ### Install fastconv, fastconvr, and fft Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/tools/CMakeLists.txt Installs the fastconv, fastconvr, and fft targets to the appropriate library and binary directories, with public headers to PKGINCLUDEDIR. ```cmake install(TARGETS fastconv fastconvr fft ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PUBLIC_HEADER DESTINATION ${PKGINCLUDEDIR}) ``` -------------------------------- ### Specify FFmpeg installation path Source: https://github.com/acoustid/chromaprint/blob/master/README.md Use the FFMPEG_ROOT option if FFmpeg is installed in a non-standard location. ```bash $ cmake -DFFMPEG_ROOT=/path/to/local/ffmpeg/install . ``` -------------------------------- ### INSTANTIATE_TYPED_TEST_SUITE_P example with Types Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Example showing how to instantiate a type-parameterized test suite with a Types object. The type alias is necessary for the macro to parse correctly. ```cpp using MyTypes = ::testing::Types; INSTANTIATE_TYPED_TEST_SUITE_P(MyInstantiation, MyFixture, MyTypes); ``` -------------------------------- ### UnitTest::start_timestamp Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the time of the test program start, in ms from the start of the UNIX epoch. ```APIDOC ## UnitTest::start_timestamp ### Description Gets the time of the test program start, in ms from the start of the UNIX epoch. ### Method `TimeInMillis UnitTest::start_timestamp() const` ### Returns - `TimeInMillis` - The start timestamp in milliseconds since the UNIX epoch. ``` -------------------------------- ### Include hermetic build setup Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/googlemock/CMakeLists.txt Includes the hermetic_build.cmake file if available, and calls pre_project_set_up_hermetic_build() if defined. ```cmake include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) if (COMMAND pre_project_set_up_hermetic_build) # Google Test also calls hermetic setup functions from add_subdirectory, # although its changes will not affect things at the current scope. pre_project_set_up_hermetic_build() endif() ``` -------------------------------- ### Build Chromaprint from source Source: https://github.com/acoustid/chromaprint/blob/master/README.md Standard commands to configure, build, and install the Chromaprint shared library and fpcalc utility. ```bash $ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TOOLS=ON . $ make $ sudo make install ``` -------------------------------- ### Environment Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Represents a global test environment. Provides protected methods SetUp() and TearDown() that can be overridden to define environment setup and teardown. ```APIDOC ## Environment ### Description Represents a global test environment. See Global Set-Up and Tear-Down. ### Type Class ### Namespace testing ### Protected Methods #### SetUp - Signature: virtual void Environment::SetUp() - Description: Override this to define how to set up the environment. #### TearDown - Signature: virtual void Environment::TearDown() - Description: Override this to define how to tear down the environment. ``` -------------------------------- ### Example generated pkg-config file Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/pkgconfig.md A sample of the content found in a generated .pc file for GoogleTest. ```text libdir=/usr/lib64 includedir=/usr/include Name: gtest Description: GoogleTest (without main() function) Version: 1.11.0 URL: https://github.com/google/googletest Libs: -L${libdir} -lgtest -lpthread Cflags: -I${includedir} -DGTEST_HAS_PTHREAD=1 -lpthread ``` -------------------------------- ### Example JSON report Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md A sample JSON report generated from the example test program, showing test results and failure details. ```json { "tests": 3, "failures": 1, "errors": 0, "time": "0.035s", "timestamp": "2011-10-31T18:52:42Z", "name": "AllTests", "testsuites": [ { "name": "MathTest", "tests": 2, "failures": 1, "errors": 0, "time": "0.015s", "testsuite": [ { "name": "Addition", "file": "test.cpp", "line": 1, "status": "RUN", "time": "0.007s", "classname": "", "failures": [ { "message": "Value of: add(1, 1)\n Actual: 3\nExpected: 2", "type": "" }, { "message": "Value of: add(1, -1)\n Actual: 1\nExpected: 0", "type": "" } ] }, { "name": "Subtraction", "file": "test.cpp", "line": 2, "status": "RUN", "time": "0.005s", "classname": "" } ] }, { "name": "LogicTest", "tests": 1, "failures": 0, "errors": 0, "time": "0.005s", "testsuite": [ { "name": "NonContradiction", "file": "test.cpp", "line": 3, "status": "RUN", "time": "0.005s", "classname": "" } ] } ] } ``` -------------------------------- ### Test::SetUp Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Protected virtual method that can be overridden to perform test fixture setup. Called before each individual test. ```APIDOC ## Test::SetUp ### Description Override this to perform test fixture setup. GoogleTest calls `SetUp()` before running each individual test. ### Method `virtual void Test::SetUp()` ### Parameters None. ### Returns None. ``` -------------------------------- ### TestEventListener::OnEnvironmentsSetUpStart Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Fired before environment set-up for each iteration of tests starts. ```APIDOC ## TestEventListener::OnEnvironmentsSetUpStart ### Description Fired before environment set-up for each iteration of tests starts. ### Method virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) ### Parameters - **unit_test** (const UnitTest&) - Required - The unit test object. ``` -------------------------------- ### Use case example for RegisterTest Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md Complete example showing a custom fixture, a test class with a data parameter, and a registration function that dynamically registers tests for each value. The factory must return the fixture type. The registration must happen before `RUN_ALL_TESTS()`. ```c++ class MyFixture : public testing::Test { public: // All of these optional, just like in regular macro usage. static void SetUpTestSuite() { ... } static void TearDownTestSuite() { ... } void SetUp() override { ... } void TearDown() override { ... } }; class MyTest : public MyFixture { public: explicit MyTest(int data) : data_(data) {} void TestBody() override { ... } private: int data_; }; void RegisterMyTests(const std::vector& values) { for (int v : values) { testing::RegisterTest( "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr, std::to_string(v).c_str(), __FILE__, __LINE__, // Important to use the fixture type as the return type here. [=]() -> MyFixture* { return new MyTest(v); }); } } ... int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); std::vector values_to_test = LoadValuesFromConfig(); RegisterMyTests(values_to_test); ... return RUN_ALL_TESTS(); } ``` -------------------------------- ### TestEventListener::OnTestStart Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Fired before the test starts. ```APIDOC ## TestEventListener::OnTestStart ### Description Fired before the test starts. ### Method virtual void OnTestStart(const TestInfo& test_info) ### Parameters - **test_info** (const TestInfo&) - Required - The test info object. ``` -------------------------------- ### EXPECT_PRED2 usage example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/assertions.md Shows how to use EXPECT_PRED2 to verify a predicate function with two arguments. ```cpp // Returns true if 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; ... EXPECT_PRED2(MutuallyPrime, a, b); // Succeeds EXPECT_PRED2(MutuallyPrime, b, c); // Fails ``` -------------------------------- ### StartsWith(prefix) Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/matchers.md Matches if the argument starts with the specified prefix. ```APIDOC ## StartsWith(prefix) ### Description Matches if the argument starts with the specified prefix. ### Parameters - **prefix** (string) - Required - The prefix to check for. ### Notes - Works for wide strings. ``` -------------------------------- ### Standard gMock Workflow Example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cheat_sheet.md Demonstrates the typical workflow of importing symbols, creating a mock, setting default actions, defining expectations, and exercising the code. ```cpp 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(MyProductionFunction(&foo), "good"); // #5 } // #6 ``` -------------------------------- ### TestResult::start_timestamp Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the time of the test case start, in ms from the start of the UNIX epoch. ```APIDOC ## TestResult::start_timestamp ### Description Gets the time of the test case start, in ms from the start of the UNIX epoch. ### Method TimeInMillis TestResult::start_timestamp() const ### Returns - **TimeInMillis** - The start timestamp in milliseconds since the UNIX epoch. ``` -------------------------------- ### TestSuite::start_timestamp Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the time of the test suite start, in ms from the start of the UNIX epoch. ```APIDOC ## TestSuite::start_timestamp ### Description Gets the time of the test suite start, in ms from the start of the UNIX epoch. ### Method `TimeInMillis TestSuite::start_timestamp() const` ### Returns - **TimeInMillis** - The start timestamp in milliseconds since UNIX epoch. ``` -------------------------------- ### Declaring a function for testing Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/primer.md An example of a function declaration that will be tested. ```cpp int Factorial(int n); // Returns the factorial of n ``` -------------------------------- ### Implement per-test-suite set-up and tear-down in C++ Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md This example demonstrates defining static resources and lifecycle methods within a test fixture class to share resources across multiple tests. ```c++ class FooTest : public testing::Test { protected: // Per-test-suite set-up. // Called before the first test in this test suite. // Can be omitted if not needed. static void SetUpTestSuite() { shared_resource_ = new ...; // If `shared_resource_` is **not deleted** in `TearDownTestSuite()`, // reallocation should be prevented because `SetUpTestSuite()` may be called // in subclasses of FooTest and lead to memory leak. // // if (shared_resource_ == nullptr) { // shared_resource_ = new ...; // } } // Per-test-suite tear-down. // Called after the last test in this test suite. // Can be omitted if not needed. static void TearDownTestSuite() { delete shared_resource_; shared_resource_ = nullptr; } // You can define per-test set-up logic as usual. void SetUp() override { ... } // You can define per-test tear-down logic as usual. void TearDown() override { ... } // Some expensive resource shared by all tests. static T* shared_resource_; }; T* FooTest::shared_resource_ = nullptr; TEST_F(FooTest, Test1) { ... you can refer to shared_resource_ here ... } TEST_F(FooTest, Test2) { ... you can refer to shared_resource_ here ... } ``` -------------------------------- ### Create hello_test.cc with basic assertions Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/quickstart-bazel.md Create a file named hello_test.cc in your my_workspace directory. This file includes the main GoogleTest header and demonstrates basic assertions: EXPECT_STRNE and EXPECT_EQ. ```cpp #include // Demonstrate some basic assertions. TEST(HelloTest, BasicAssertions) { // Expect two strings not to be equal. EXPECT_STRNE("hello", "world"); // Expect equality. EXPECT_EQ(7 * 6, 42); } ``` -------------------------------- ### Build universal binary framework for Mac OS X 10.5 or newer Source: https://github.com/acoustid/chromaprint/wiki/Building-on-OS-X Use these commands to build a universal binary framework with deployment target 10.5 or newer. Uses the default compiler, the MacOSX10.5.sdk, and architectures ppc, i368, and x86_64. Run 'make' and 'make install' after configuration. ```console $ cmake -DCMAKE_BUILD_TYPE=Release \ -DBUILD_FRAMEWORK=ON \ -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.5.sdk/ \ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.5 \ -DCMAKE_OSX_ARCHITECTURES="ppc;i368;x86_64" $ make $ make install ``` -------------------------------- ### TestEventListener::OnEnvironmentsTearDownStart Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Fired before environment tear-down for each iteration of tests starts. ```APIDOC ## TestEventListener::OnEnvironmentsTearDownStart ### Description Fired before environment tear-down for each iteration of tests starts. ### Method virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) ### Parameters - **unit_test** (const UnitTest&) - Required - The unit test object. ``` -------------------------------- ### Create project directory Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/quickstart-cmake.md Create a new directory for your project and navigate into it using the terminal. ```bash $ mkdir my_project && cd my_project ``` -------------------------------- ### Configure CMakeLists.txt with FetchContent Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/quickstart-cmake.md Create a CMakeLists.txt file to define the project, set C++14 requirements, and declare the GoogleTest dependency using the FetchContent module. ```cmake cmake_minimum_required(VERSION 3.14) project(my_project) # GoogleTest requires at least C++14 set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) FetchContent_Declare( googletest URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) ``` -------------------------------- ### EXPECT_PRED2 failure message example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/assertions.md Displays the failure message generated by the failing EXPECT_PRED2 assertion in the previous example. ```text MutuallyPrime(b, c) is false, where b is 4 c is 10 ``` -------------------------------- ### SCOPED_TRACE example in test sub-routine Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md An example showing how SCOPED_TRACE provides context for failures occurring within a sub-routine call. ```c++ 10: void Sub1(int n) { 11: EXPECT_EQ(Bar(n), 1); 12: EXPECT_EQ(Bar(n + 1), 2); 13: } 14: 15: TEST(FooTest, Bar) { 16: { 17: SCOPED_TRACE("A"); // This trace point will be included in 18: // every failure in this scope. 19: Sub1(1); 20: } 21: // Now it won't. 22: Sub1(9); 23: } ``` -------------------------------- ### Build kissfft as static library with int16_t and OpenMP using CMake Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/README.md Builds kissfft with the same configuration as the Make example but using CMake. Creates a build directory, configures with CMake, and builds. ```bash mkdir build && cd build cmake -DKISSFFT_DATATYPE=int16_t -DKISSFFT_STATIC=ON -DKISSFFT_OPENMP=ON .. make all ``` -------------------------------- ### ACTION_TEMPLATE example: DuplicateArg Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Example action template that converts the k-th argument to type T and copies it to output. Uses HAS_2_TEMPLATE_PARAMS and AND_1_VALUE_PARAMS. ```cpp // DuplicateArg(output) converts the k-th argument of the mock // function to type T and copies it to *output. ACTION_TEMPLATE(DuplicateArg, // Note the comma between int and k: HAS_2_TEMPLATE_PARAMS(int, k, typename, T), AND_1_VALUE_PARAMS(output)) { *output = T(std::get(args)); } ``` -------------------------------- ### Unprotected commas in MOCK_METHOD (bad example) Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Shows that unprotected commas prevent MOCK_METHOD from parsing arguments correctly. These examples will not compile. ```cpp class MockFoo { public: MOCK_METHOD(std::pair, GetPair, ()); // Won't compile! MOCK_METHOD(bool, CheckMap, (std::map, bool)); // Won't compile! }; ``` -------------------------------- ### Build and run unit tests Source: https://github.com/acoustid/chromaprint/blob/master/README.md Commands to configure the build for tests and execute the test suite. ```bash $ cmake -DBUILD_TESTS=ON . $ make check ``` -------------------------------- ### Conditionally build and install psdpng Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/tools/CMakeLists.txt Builds psdpng only when KISSFFT_DATATYPE is not 'simd'. Requires libpng via pkg-config and links it. Installs the target similarly. ```cmake # psdpng does not build with "simd" datatype if(NOT KISSFFT_DATATYPE MATCHES "simd") include(FindPkgConfig) pkg_check_modules(libpng REQUIRED IMPORTED_TARGET libpng) add_kissfft_executable(psdpng psdpng.c) target_link_libraries(psdpng PRIVATE PkgConfig::libpng) install(TARGETS psdpng ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PUBLIC_HEADER DESTINATION ${PKGINCLUDEDIR}) endif() ``` -------------------------------- ### Test::SetUpTestSuite Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Static method that performs shared setup for all tests in a test suite. Called before the first test in the suite runs. ```APIDOC ## Test::SetUpTestSuite ### Description Performs shared setup for all tests in the test suite. GoogleTest calls `SetUpTestSuite()` before running the first test in the test suite. ### Method `static void Test::SetUpTestSuite()` ### Parameters None. ### Returns None. ``` -------------------------------- ### Build universal binary framework for Mac OS X 10.4 Source: https://github.com/acoustid/chromaprint/wiki/Building-on-OS-X Use these commands to build a universal binary framework with deployment target 10.4. Requires gcc-4.0 and c++-4.0 compilers, the MacOSX10.4u.sdk, and architectures ppc, i368, and x86_64. Run 'make' and 'make install' after configuration. ```console $ cmake -DCMAKE_BUILD_TYPE=Release \ -DBUILD_FRAMEWORK=ON \ -DCMAKE_C_COMPILER=/usr/bin/gcc-4.0 \ -DCMAKE_CXX_COMPILER=/usr/bin/c++-4.0 \ -DCMAKE_OSX_SYSROOT=/Developer/SDKs/MacOSX10.4u.sdk/ \ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.4 \ -DCMAKE_OSX_ARCHITECTURES="ppc;i368;x86_64" $ make $ make install ``` -------------------------------- ### Example XML report output Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md An example XML report generated from the test program above, showing the structure and attributes such as tests, failures, time, and timestamp. ```xml ... ... ``` -------------------------------- ### Instantiation syntax for action templates Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Shows how to create an instance of an action template with template arguments and value arguments. Value argument types are inferred by the compiler. ```cpp ActionName(v1, ..., v_n) ``` -------------------------------- ### TEST_P example with GetParam() Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Example of a value-parameterized test that uses GetParam() to access the test parameter. The test body can contain any code under test; assertions determine the outcome. ```cpp TEST_P(MyTestSuite, DoesSomething) { ... EXPECT_TRUE(DoSomething(GetParam())); ... } ``` -------------------------------- ### Using Add action Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Shows how to use the Add action with a parameter value of 5. ```cpp // Returns argument #0 + 5. ... WillOnce(Add(5)); ``` -------------------------------- ### ACTION macro example: IncrementArg1 Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Defines an action that increments the value pointed to by the first argument (arg1). The action returns the incremented value. This example is used with WillOnce(IncrementArg1()). ```cpp ACTION(IncrementArg1) { return ++(*arg1); } ``` -------------------------------- ### Sharding example: test functions in foo_test Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md Example test functions used to illustrate sharding. The test program foo_test contains these five test functions, which are distributed across shards. ```cpp TEST(A, V) TEST(A, W) TEST(B, X) TEST(B, Y) TEST(B, Z) ``` -------------------------------- ### Build kissfft as static library with int16_t and OpenMP using Make Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/README.md Builds kissfft as a static library with int16_t datatype and OpenMP support using Make. Run from the kissfft source tree. ```bash make KISSFFT_DATATYPE=int16_t KISSFFT_STATIC=1 KISSFFT_OPENMP=1 all ``` -------------------------------- ### GTEST_SKIP() in test case and fixture SetUp() Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md Use GTEST_SKIP() to skip a single test or all tests in a fixture. When called in SetUp(), tests for that fixture are skipped. A custom message can be streamed to GTEST_SKIP(). ```c++ TEST(SkipTest, DoesSkip) { GTEST_SKIP() << "Skipping single test"; FAIL(); // Won't fail; it won't be executed } class SkipFixture : public ::testing::Test { protected: void SetUp() override { GTEST_SKIP() << "Skipping all tests for this fixture"; } }; // Tests for SkipFixture won't be executed. TEST_F(SkipFixture, SkipsOneTest) { FAIL(); // Won't fail; it won't be executed } ``` -------------------------------- ### Example MATCHER_P matcher HasAbsoluteValue Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Example matcher that checks if the absolute value of the argument equals the given value. The description string is empty, so the failure message uses the matcher name and parameter. ```cpp MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } ``` -------------------------------- ### ScopedTrace usage example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Example of creating a testing::ScopedTrace instance. The trace is included in every test failure message generated in the scope of the instance's lifetime, and is undone when the instance is destroyed. ```cpp testing::ScopedTrace trace("file.cc", 123, "message"); ``` -------------------------------- ### Derived test fixture example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/faq.md Shows how to share logic among test suites by deriving a fixture from a base fixture, calling base SetUp/TearDown, and using TEST_F with the derived fixture. ```c++ // Defines a base test fixture. class BaseTest : public ::testing::Test { protected: ... }; // Derives a fixture FooTest from BaseTest. class FooTest : public BaseTest { protected: void SetUp() override { BaseTest::SetUp(); // Sets up the base fixture first. ... additional set-up work ... } void TearDown() override { ... 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 ... ``` -------------------------------- ### TYPED_TEST_SUITE fixture class template example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Example of a fixture class template parameterized by a type, used with TYPED_TEST_SUITE. The fixture inherits from testing::Test and defines a type alias and member variables. ```cpp template class MyFixture : public testing::Test { public: ... using List = std::list; static T shared_; T value_; }; ``` -------------------------------- ### Defining and using a custom matcher class Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md This example demonstrates creating a custom matcher class BarPlusBazEqMatcher to verify an invariant property and a factory function BarPlusBazEq to return the matcher. ```cpp class BarPlusBazEqMatcher { public: using is_gtest_matcher = void; explicit BarPlusBazEqMatcher(int expected_sum) : expected_sum_(expected_sum) {} bool MatchAndExplain(const Foo& foo, std::ostream* /* listener */) const { return (foo.bar() + foo.baz()) == expected_sum_; } void DescribeTo(std::ostream* os) const { *os << "bar() + baz() equals " << expected_sum_; } void DescribeNegationTo(std::ostream* os) const { *os << "bar() + baz() does not equal " << expected_sum_; } private: const int expected_sum_; }; ::testing::Matcher BarPlusBazEq(int expected_sum) { return BarPlusBazEqMatcher(expected_sum); } ... Foo foo; EXPECT_THAT(foo, BarPlusBazEq(5))...; ``` -------------------------------- ### Define types and interface for move-only example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Defines the AccessLevel enum, Buzz class, and Buzzer interface used in the move-only mocking examples. Buzzer methods return and accept std::unique_ptr. ```cpp enum class AccessLevel { kInternal, kPublic }; class Buzz { public: explicit Buzz(AccessLevel access) { ... } ... }; class Buzzer { public: virtual ~Buzzer() {} virtual std::unique_ptr MakeBuzz(StringPiece text) = 0; virtual bool ShareBuzz(std::unique_ptr buzz, int64_t timestamp) = 0; ... }; ``` -------------------------------- ### Create a Bazel workspace directory Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/quickstart-bazel.md Creates a new directory named my_workspace and changes into it. This is the first step in setting up a Bazel workspace. ```shell $ mkdir my_workspace && cd my_workspace ``` -------------------------------- ### Error Output for Incorrect std::ref() Example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md This is the expected failure output when the incorrect std::ref() example is run. It shows that the actual value is 0 instead of 42, illustrating the timing issue. ```text Value of: foo.GetValue() Actual: 0 Expected: 42 ``` -------------------------------- ### Configure GoogleTest and add all_tests executable Source: https://github.com/acoustid/chromaprint/blob/master/tests/CMakeLists.txt Sets GoogleTest options, adds the googletest subdirectory, and creates the all_tests executable with all test source files. Links against chromaprint, gtest, and gtest_main. ```cmake include(GoogleTest) set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) mark_as_advanced(BUILD_GMOCK INSTALL_GTEST GTEST_HAS_ABSL) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) add_subdirectory("${PROJECT_SOURCE_DIR}/src/3rdparty/googletest" "test/3rdparty/googletest") add_executable(all_tests $ main.cpp test_api.cpp test_utils.cpp test_quantizer.cpp test_filter.cpp test_filter_utils.cpp test_audio_processor.cpp test_simhash.cpp test_chromaprint.cpp test_chroma.cpp test_chroma_filter.cpp test_chroma_resampler.cpp test_fingerprint_compressor.cpp test_fingerprint_decompressor.cpp test_fingerprint_matcher.cpp test_silence_remover.cpp test_moving_average.cpp test_utils_gradient.cpp test_utils_gaussian_filter.cpp ../src/fft_test.cpp ../src/audio/audio_slicer_test.cpp ../src/utils/base64_test.cpp ../src/utils/rolling_integral_image_test.cpp ) target_include_directories(all_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(all_tests PRIVATE chromaprint gtest gtest_main) ``` -------------------------------- ### TYPED_TEST example with TypeParam and TestFixture Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Example of a typed test that uses TypeParam to access the type parameter, TestFixture:: to access static members, and typename TestFixture:: to refer to typedefs. Requires the fixture to be defined with TYPED_TEST_SUITE. ```cpp TYPED_TEST(MyFixture, Example) { // Inside a test, refer to the special name TypeParam to get the type // parameter. Since we are inside a derived class template, C++ requires // us to visit the members of MyFixture via 'this'. TypeParam n = this->value_; // To visit static members of the fixture, add the 'TestFixture::' // prefix. n += TestFixture::shared_; // To refer to typedefs in the fixture, add the 'typename TestFixture::' // prefix. The 'typename' is required to satisfy the compiler. typename TestFixture::List values; values.push_back(n); ... } ``` -------------------------------- ### Build Google Test and Google Mock with make Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/CONTRIBUTING.md After configuring with CMake, run make to build the tests. ```shell make ``` -------------------------------- ### TestProperty::value Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the user-supplied value. ```APIDOC ## TestProperty::value ### Description Gets the user-supplied value. ### Method value ### Signature const char* value() const ### Returns - **const char*** - The user-supplied value. ``` -------------------------------- ### Compile Chromaprint with CMake Source: https://github.com/acoustid/chromaprint/wiki/Building-on-Linux Clone the repository and run cmake and make to compile Chromaprint using the specified toolchain file. ```console $ git clone git://github.com/lalinsky/chromaprint.git $ cd chromaprint $ cmake \ -DBUILD_EXAMPLES=ON -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE=~/code/mingw32/mingw.cmake \ -DCMAKE_INSTALL_PREFIX=~/code/mingw32/install/ . $ make $ make install ``` -------------------------------- ### TestProperty::key Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the user-supplied key. ```APIDOC ## TestProperty::key ### Description Gets the user-supplied key. ### Method key ### Signature const char* key() const ### Returns - **const char*** - The user-supplied key. ``` -------------------------------- ### UnitTest::total_test_count Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the number of all tests. ```APIDOC ## UnitTest::total_test_count ### Description Gets the number of all tests. ### Method `int UnitTest::total_test_count() const` ### Returns - `int` - The total number of tests. ``` -------------------------------- ### Call set_up_hermetic_build Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/googlemock/CMakeLists.txt Invokes set_up_hermetic_build() if the command is defined. ```cmake if (COMMAND set_up_hermetic_build) set_up_hermetic_build() endif() ``` -------------------------------- ### TestEventListener::OnTestSuiteStart Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Fired before the test suite starts. ```APIDOC ## TestEventListener::OnTestSuiteStart ### Description Fired before the test suite starts. ### Method virtual void OnTestSuiteStart(const TestSuite& test_suite) ### Parameters - **test_suite** (const TestSuite&) - Required - The test suite object. ``` -------------------------------- ### TestEventListener::OnTestProgramStart Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Fired before any test activity starts. ```APIDOC ## TestEventListener::OnTestProgramStart ### Description Fired before any test activity starts. ### Method virtual void OnTestProgramStart(const UnitTest& unit_test) ### Parameters - **unit_test** (const UnitTest&) - Required - The unit test object. ``` -------------------------------- ### ACTION_P example: Add Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Defines a parameterized action that adds a parameter 'n' to the first argument (arg0). Used with WillOnce(Add(5)). ```cpp ACTION_P(Add, n) { return arg0 + n; } ``` -------------------------------- ### TestPartResult::summary Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the summary of the failure message. ```APIDOC ## TestPartResult::summary ### Description Gets the summary of the failure message. ### Method summary ### Signature const char* TestPartResult::summary() const ### Returns - **const char*** - The summary of the failure message. ``` -------------------------------- ### Configure FFTW3 dependency and add bm_fftw benchmark Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/kissfft/test/CMakeLists.txt Selects the FFTW3 package based on KISSFFT_FLOAT, finds it via pkg-config, and links it to the bm_fftw benchmark. ```cmake include(FindPkgConfig) if(KISSFFT_FLOAT) set(fftw3_pkg fftw3f) else() set(fftw3_pkg fftw3) endif() pkg_check_modules(fftw3 REQUIRED IMPORTED_TARGET ${fftw3_pkg}) add_kissfft_test_executable(bm_fftw benchfftw.c pstats.c) target_link_libraries(bm_fftw PRIVATE PkgConfig::fftw3) ``` -------------------------------- ### MockFunction usage example Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Shows how to create a MockFunction, set expectations on Call(), and pass the proxy to the code under test. Expectations are verified when the mock goes out of scope. ```cpp TEST(FooTest, RunsCallbackWithBarArgument) { // 1. Create a mock object. MockFunction mock_function; // 2. Set expectations on Call() method. EXPECT_CALL(mock_function, Call("bar")).WillOnce(Return(1)); // 3. Exercise code that uses std::function. Foo(mock_function.AsStdFunction()); // Foo's signature can be either of: // void Foo(const std::function& fun); // void Foo(std::function fun); // 4. All expectations will be verified when mock_function // goes out of scope and is destroyed. } ``` -------------------------------- ### UnitTest::elapsed_time Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the elapsed time, in milliseconds. ```APIDOC ## UnitTest::elapsed_time ### Description Gets the elapsed time, in milliseconds. ### Method `TimeInMillis UnitTest::elapsed_time() const` ### Returns - `TimeInMillis` - The elapsed time in milliseconds. ``` -------------------------------- ### UnitTest::test_to_run_count Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the number of tests that should run. ```APIDOC ## UnitTest::test_to_run_count ### Description Gets the number of tests that should run. ### Method `int UnitTest::test_to_run_count() const` ### Returns - `int` - The number of tests that should run. ``` -------------------------------- ### Match Selected Arguments with Args Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/gmock_cook_book.md Use Args(m) to match a subset of arguments as a tuple against a matcher. ```cpp using ::testing::_; using ::testing::AllOf; using ::testing::Args; using ::testing::Lt; ... EXPECT_CALL(foo, Blah) .With(AllOf(Args<0, 1>(Lt()), Args<1, 2>(Lt()))); ``` -------------------------------- ### UnitTest::disabled_test_count Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the number of disabled tests. ```APIDOC ## UnitTest::disabled_test_count ### Description Gets the number of disabled tests. ### Method `int UnitTest::disabled_test_count() const` ### Returns - `int` - The number of disabled tests. ``` -------------------------------- ### UnitTest::failed_test_count Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/reference/testing.md Gets the number of failed tests. ```APIDOC ## UnitTest::failed_test_count ### Description Gets the number of failed tests. ### Method `int UnitTest::failed_test_count() const` ### Returns - `int` - The number of failed tests. ``` -------------------------------- ### Add a custom event listener in main() Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/docs/advanced.md Shows how to initialize GoogleTest, get the event listener list, and append a custom listener (MinimalistPrinter) before running tests. GoogleTest takes ownership of the listener. ```c++ int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); // Gets hold of the event listener list. testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); // Adds a listener to the end. GoogleTest takes the ownership. listeners.Append(new MinimalistPrinter); return RUN_ALL_TESTS(); } ``` -------------------------------- ### Configure build with CMake for both Google Test and Google Mock tests Source: https://github.com/acoustid/chromaprint/blob/master/src/3rdparty/googletest/CONTRIBUTING.md Use this CMake command to set up a build directory and configure both Google Test and Google Mock tests. Replace ${GTEST_REPO_DIR} with the path to the repository. ```shell mkdir mybuild cd mybuild cmake -Dgtest_build_tests=ON -Dgmock_build_tests=ON ${GTEST_REPO_DIR} ```