Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] added tests for matrices #47754

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
../../../flutter/impeller/fixtures
../../../flutter/impeller/geometry/README.md
../../../flutter/impeller/geometry/geometry_unittests.cc
../../../flutter/impeller/geometry/matrix_unittests.cc
../../../flutter/impeller/geometry/rect_unittests.cc
../../../flutter/impeller/golden_tests/README.md
../../../flutter/impeller/golden_tests_harvester/.dart_tool
Expand Down
1 change: 1 addition & 0 deletions impeller/geometry/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impeller_component("geometry_unittests") {
testonly = true
sources = [
"geometry_unittests.cc",
"matrix_unittests.cc",
"rect_unittests.cc",
]

Expand Down
3 changes: 2 additions & 1 deletion impeller/geometry/geometry_asserts.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ inline ::testing::AssertionResult MatrixNear(impeller::Matrix a,
&& NumberNear(a.m[15], b.m[15]);

return equal ? ::testing::AssertionSuccess()
: ::testing::AssertionFailure() << "Matrixes are not equal.";
: ::testing::AssertionFailure()
<< "Matrixes are not equal " << a << " " << b;
}

inline ::testing::AssertionResult QuaternionNear(impeller::Quaternion a,
Expand Down
28 changes: 28 additions & 0 deletions impeller/geometry/matrix_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gtest/gtest.h"

#include "flutter/impeller/geometry/matrix.h"

#include "flutter/impeller/geometry/geometry_asserts.h"

namespace impeller {
namespace testing {

TEST(MatrixTest, Multiply) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this test as documentation on how to transform a quad would have saved me a few minutes.

Matrix x(0.0, 0.0, 0.0, 1.0, //
1.0, 0.0, 0.0, 1.0, //
0.0, 1.0, 0.0, 1.0, //
1.0, 1.0, 0.0, 1.0);
Matrix translate = Matrix::MakeTranslation({10, 20, 0});
Matrix result = translate * x;
EXPECT_TRUE(MatrixNear(result, Matrix(10.0, 20.0, 0.0, 1.0, //
11.0, 20.0, 0.0, 1.0, //
10.0, 21.0, 0.0, 1.0, //
11.0, 21.0, 0.0, 1.0)));
}

} // namespace testing
} // namespace impeller