1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "third_party/blink/renderer/platform/geometry/float_box_test_helpers.h"
26
27 #include "third_party/blink/renderer/platform/geometry/float_box.h"
28 #include "third_party/blink/renderer/platform/geometry/geometry_test_helpers.h"
29
30 const static float kTestEpsilon = 1e-6;
31
32 namespace blink {
33 namespace float_box_test {
34
ApproximatelyEqual(const float & a,const float & b)35 bool ApproximatelyEqual(const float& a, const float& b) {
36 return geometry_test::ApproximatelyEqual(a, b, kTestEpsilon);
37 }
38
ApproximatelyEqual(const FloatBox & a,const FloatBox & b)39 bool ApproximatelyEqual(const FloatBox& a, const FloatBox& b) {
40 if (!ApproximatelyEqual(a.X(), b.X()) || !ApproximatelyEqual(a.Y(), b.Y()) ||
41 !ApproximatelyEqual(a.Z(), b.Z()) ||
42 !ApproximatelyEqual(a.Width(), b.Width()) ||
43 !ApproximatelyEqual(a.Height(), b.Height()) ||
44 !ApproximatelyEqual(a.Depth(), b.Depth())) {
45 return false;
46 }
47 return true;
48 }
49
AssertAlmostEqual(const char * expr,const char * n_expr,const FloatBox & m,const FloatBox & n)50 testing::AssertionResult AssertAlmostEqual(const char* expr,
51 const char* n_expr,
52 const FloatBox& m,
53 const FloatBox& n) {
54 if (!ApproximatelyEqual(m, n)) {
55 return testing::AssertionFailure()
56 << " Value of:" << n_expr << std::endl
57 << " Actual:" << testing::PrintToString(n) << std::endl
58 << "Expected Approx:" << expr << std::endl
59 << " Which is:" << testing::PrintToString(m);
60 }
61 return testing::AssertionSuccess();
62 }
63
AssertContains(const char * expr,const char * n_expr,const FloatBox & m,const FloatBox & n)64 testing::AssertionResult AssertContains(const char* expr,
65 const char* n_expr,
66 const FloatBox& m,
67 const FloatBox& n) {
68 FloatBox new_m = m;
69 new_m.ExpandTo(n);
70 if (!ApproximatelyEqual(m, new_m)) {
71 return testing::AssertionFailure()
72 << " Value of:" << n_expr << std::endl
73 << " Actual:" << testing::PrintToString(n) << std::endl
74 << "Not Contained in:" << expr << std::endl
75 << " Which is:" << testing::PrintToString(m);
76 }
77 return testing::AssertionSuccess();
78 }
79
80 } // namespace float_box_test
81 } // namespace blink
82