testing.h (2135B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #ifndef LIB_JXL_TESTING_H_ 7 #define LIB_JXL_TESTING_H_ 8 9 // GTest/GMock specific macros / wrappers. 10 11 // gmock unconditionally redefines those macros (to wrong values). 12 // Lets include it only here and mitigate the problem. 13 #pragma push_macro("PRIdS") 14 #pragma push_macro("PRIuS") 15 #include "gmock/gmock.h" 16 #pragma pop_macro("PRIuS") 17 #pragma pop_macro("PRIdS") 18 19 #include "gtest/gtest.h" 20 // JPEGXL_ENABLE_BOXES, JPEGXL_ENABLE_TRANSCODE_JPEG 21 #include "lib/jxl/common.h" 22 23 #ifdef JXL_DISABLE_SLOW_TESTS 24 #define JXL_SLOW_TEST(X) DISABLED_##X 25 #else 26 #define JXL_SLOW_TEST(X) X 27 #endif // JXL_DISABLE_SLOW_TESTS 28 29 #if JPEGXL_ENABLE_TRANSCODE_JPEG 30 #define JXL_TRANSCODE_JPEG_TEST(X) X 31 #else 32 #define JXL_TRANSCODE_JPEG_TEST(X) DISABLED_##X 33 #endif // JPEGXL_ENABLE_TRANSCODE_JPEG 34 35 #if JPEGXL_ENABLE_BOXES 36 #define JXL_BOXES_TEST(X) X 37 #else 38 #define JXL_BOXES_TEST(X) DISABLED_##X 39 #endif // JPEGXL_ENABLE_BOXES 40 41 #ifdef THREAD_SANITIZER 42 #define JXL_TSAN_SLOW_TEST(X) DISABLED_##X 43 #else 44 #define JXL_TSAN_SLOW_TEST(X) X 45 #endif // THREAD_SANITIZER 46 47 #if defined(__x86_64__) 48 #define JXL_X86_64_TEST(X) X 49 #else 50 #define JXL_X86_64_TEST(X) DISABLED_##X 51 #endif // defined(__x86_64__) 52 53 // googletest before 1.10 didn't define INSTANTIATE_TEST_SUITE_P() but instead 54 // used INSTANTIATE_TEST_CASE_P which is now deprecated. 55 #ifdef INSTANTIATE_TEST_SUITE_P 56 #define JXL_GTEST_INSTANTIATE_TEST_SUITE_P INSTANTIATE_TEST_SUITE_P 57 #else 58 #define JXL_GTEST_INSTANTIATE_TEST_SUITE_P INSTANTIATE_TEST_CASE_P 59 #endif 60 61 // Ensures that we don't make our test bounds too lax, effectively disabling the 62 // tests. 63 MATCHER_P(IsSlightlyBelow, max, "") { 64 return max * 0.75 <= arg && arg <= max * 1.0; 65 } 66 67 #define JXL_EXPECT_OK(F) \ 68 { \ 69 std::stringstream _; \ 70 EXPECT_TRUE(F) << _.str(); \ 71 } 72 73 #define JXL_ASSERT_OK(F) \ 74 { \ 75 std::stringstream _; \ 76 ASSERT_TRUE(F) << _.str(); \ 77 } 78 79 #endif // LIB_JXL_TESTING_H_