diff options
Diffstat (limited to 'tests/MatrixTest.cpp')
-rw-r--r-- | tests/MatrixTest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp index 68e587bd49..052687da34 100644 --- a/tests/MatrixTest.cpp +++ b/tests/MatrixTest.cpp @@ -27,6 +27,25 @@ static bool is_identity(const SkMatrix& m) { return nearly_equal(m, identity); } +static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) { + // add 100 in case we have a bug, I don't want to kill my stack in the test + char buffer[SkMatrix::kMaxFlattenSize + 100]; + uint32_t size1 = m.flatten(NULL); + uint32_t size2 = m.flatten(buffer); + REPORTER_ASSERT(reporter, size1 == size2); + REPORTER_ASSERT(reporter, size1 <= SkMatrix::kMaxFlattenSize); + + SkMatrix m2; + uint32_t size3 = m2.unflatten(buffer); + REPORTER_ASSERT(reporter, size1 == size2); + REPORTER_ASSERT(reporter, m == m2); + + char buffer2[SkMatrix::kMaxFlattenSize + 100]; + size3 = m2.flatten(buffer2); + REPORTER_ASSERT(reporter, size1 == size2); + REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); +} + void TestMatrix(skiatest::Reporter* reporter) { SkMatrix mat, inverse, iden1, iden2; @@ -40,11 +59,13 @@ void TestMatrix(skiatest::Reporter* reporter) { mat.invert(&inverse); iden1.setConcat(mat, inverse); REPORTER_ASSERT(reporter, is_identity(iden1)); + test_flatten(reporter, mat); mat.setScale(SK_Scalar1/2, SK_Scalar1/2); mat.invert(&inverse); iden1.setConcat(mat, inverse); REPORTER_ASSERT(reporter, is_identity(iden1)); + test_flatten(reporter, mat); mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0); mat.postRotate(SkIntToScalar(25)); @@ -54,6 +75,8 @@ void TestMatrix(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, is_identity(iden1)); iden2.setConcat(inverse, mat); REPORTER_ASSERT(reporter, is_identity(iden2)); + test_flatten(reporter, mat); + test_flatten(reporter, iden2); // rectStaysRect test { |