1 // Copyright 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CC_TEST_GEOMETRY_TEST_UTILS_H_ 6 #define CC_TEST_GEOMETRY_TEST_UTILS_H_ 7 8 #include "cc/cc_export.h" 9 10 namespace gfx { 11 class Transform; 12 } 13 14 namespace cc { 15 16 // These are macros instead of functions so that we get useful line numbers 17 // where a test failed. 18 #define EXPECT_FLOAT_RECT_EQ(expected, actual) \ 19 do { \ 20 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 21 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 22 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ 23 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ 24 } while (false) 25 26 #define EXPECT_RECT_EQ(expected, actual) \ 27 do { \ 28 const gfx::Rect& actualRect = actual; \ 29 EXPECT_EQ(expected.x(), actualRect.x()); \ 30 EXPECT_EQ(expected.y(), actualRect.y()); \ 31 EXPECT_EQ(expected.width(), actualRect.width()); \ 32 EXPECT_EQ(expected.height(), actualRect.height()); \ 33 } while (false) 34 35 #define EXPECT_RECT_NEAR(expected, actual, abs_error) \ 36 do { \ 37 EXPECT_NEAR((expected).x(), (actual).x(), (abs_error)); \ 38 EXPECT_NEAR((expected).y(), (actual).y(), (abs_error)); \ 39 EXPECT_NEAR((expected).width(), (actual).width(), (abs_error)); \ 40 EXPECT_NEAR((expected).height(), (actual).height(), (abs_error)); \ 41 } while (false) 42 43 #define EXPECT_POINT3F_EQ(expected, actual) \ 44 do { \ 45 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 46 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 47 EXPECT_FLOAT_EQ((expected).z(), (actual).z()); \ 48 } while (false) 49 50 #define EXPECT_VECTOR_EQ(expected, actual) \ 51 do { \ 52 EXPECT_EQ((expected).x(), (actual).x()); \ 53 EXPECT_EQ((expected).y(), (actual).y()); \ 54 } while (false) 55 56 #define EXPECT_VECTOR2DF_EQ(expected, actual) \ 57 do { \ 58 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 59 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 60 } while (false) 61 62 #define EXPECT_VECTOR2DF_NEAR(expected, actual, abs_error) \ 63 do { \ 64 EXPECT_NEAR((expected).x(), (actual).x(), (abs_error)); \ 65 EXPECT_NEAR((expected).y(), (actual).y(), (abs_error)); \ 66 } while (false) 67 68 #define EXPECT_VECTOR3DF_EQ(expected, actual) \ 69 do { \ 70 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 71 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 72 EXPECT_FLOAT_EQ((expected).z(), (actual).z()); \ 73 } while (false) 74 75 #define EXPECT_VECTOR3DF_NEAR(expected, actual, abs_error) \ 76 do { \ 77 EXPECT_NEAR((expected).x(), (actual).x(), (abs_error)); \ 78 EXPECT_NEAR((expected).y(), (actual).y(), (abs_error)); \ 79 EXPECT_NEAR((expected).z(), (actual).z(), (abs_error)); \ 80 } while (false) 81 82 #define EXPECT_FLOAT_ARRAY_EQ(expected, actual, count) \ 83 do { \ 84 for (int i = 0; i < count; i++) { \ 85 EXPECT_FLOAT_EQ((expected)[i], (actual)[i]); \ 86 } \ 87 } while (false) 88 89 #define EXPECT_FLOAT_SIZE_EQ(expected, actual) \ 90 do { \ 91 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ 92 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ 93 } while (false) 94 95 #define EXPECT_SIZE_EQ(expected, actual) \ 96 do { \ 97 EXPECT_EQ((expected).width(), (actual).width()); \ 98 EXPECT_EQ((expected).height(), (actual).height()); \ 99 } while (false) 100 101 // This is a function rather than a macro because when this is included as a 102 // macro in bulk, it causes a significant slow-down in compilation time. This 103 // problem exists with both gcc and clang, and bugs have been filed at 104 // http://llvm.org/bugs/show_bug.cgi?id=13651 105 // and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54337 106 void ExpectTransformationMatrixEq(const gfx::Transform& expected, 107 const gfx::Transform& actual); 108 109 #define EXPECT_TRANSFORMATION_MATRIX_EQ(expected, actual) \ 110 do { \ 111 ExpectTransformationMatrixEq(expected, actual); \ 112 } while (false) 113 114 void ExpectTransformationMatrixNear(const gfx::Transform& expected, 115 const gfx::Transform& actual, 116 float abs_error); 117 118 #define EXPECT_TRANSFORMATION_MATRIX_NEAR(expected, actual, abs_error) \ 119 do { \ 120 ExpectTransformationMatrixNear(expected, actual, abs_error); \ 121 } while (false) 122 123 // Should be used in test code only, for convenience. Production code should use 124 // the gfx::Transform::GetInverse() API. 125 gfx::Transform Inverse(const gfx::Transform& transform); 126 127 } // namespace cc 128 129 #endif // CC_TEST_GEOMETRY_TEST_UTILS_H_ 130