diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-06-06 17:02:24 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2011-06-07 14:00:04 -0400 |
commit | 0b15698a8c76bb8abc1b555c1d91892669b4118f (patch) | |
tree | 08732d5fbb7484ce7e10c65c96fb56294053073a /tests | |
parent | 9770b0f3d2b5d512daac50c2c9561d2c073cd8d2 (diff) | |
download | external_skia-0b15698a8c76bb8abc1b555c1d91892669b4118f.zip external_skia-0b15698a8c76bb8abc1b555c1d91892669b4118f.tar.gz external_skia-0b15698a8c76bb8abc1b555c1d91892669b4118f.tar.bz2 |
Skia Merge (revision 1510)
This CL includes bug fixes and closely mirrors the version of
Skia used in Chrome M13, which is likely to be our baseline for
ICS.
The CL also adds source files for the SampleApp which will allow
us to execute basic skia tests. The SampleApp requires the
utils/views directory in order to run.
Finally, we have included the PDF backend for Skia in order to
experiment with using it to generate PDF files for certain
applications.
Note: The SampleApp and PDF code are not built as part of libskia.
Change-Id: I1895ccfbd8074e25f19148cc7bd1b4af571fb307
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.mk | 2 | ||||
-rw-r--r-- | tests/ClipStackTest.cpp | 3 | ||||
-rw-r--r-- | tests/MatrixTest.cpp | 6 | ||||
-rw-r--r-- | tests/PDFPrimitivesTest.cpp | 6 | ||||
-rw-r--r-- | tests/PathTest.cpp | 53 | ||||
-rw-r--r-- | tests/Reader32Test.cpp | 93 | ||||
-rw-r--r-- | tests/UtilsTest.cpp | 2 | ||||
-rw-r--r-- | tests/Writer32Test.cpp | 90 | ||||
-rw-r--r-- | tests/tests_files.mk | 2 |
9 files changed, 215 insertions, 42 deletions
diff --git a/tests/Android.mk b/tests/Android.mk index 09c7739..5823b0e 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -26,6 +26,7 @@ LOCAL_SRC_FILES:= \ ParsePathTest.cpp \ PathMeasureTest.cpp \ PathTest.cpp \ + Reader32Test.cpp \ RefDictTest.cpp \ RegionTest.cpp \ Sk64Test.cpp \ @@ -36,6 +37,7 @@ LOCAL_SRC_FILES:= \ Test.cpp \ TestSize.cpp \ UtilsTest.cpp \ + Writer32Test.cpp \ XfermodeTest.cpp # The name of the file with a main function must diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp index 4ef33ff..eafdd69 100644 --- a/tests/ClipStackTest.cpp +++ b/tests/ClipStackTest.cpp @@ -107,7 +107,8 @@ static void TestClipStack(skiatest::Reporter* reporter) { // all of the above rects should have been intersected, leaving only 1 rect SkClipStack::B2FIter iter(stack); const SkClipStack::B2FIter::Clip* clip = iter.next(); - const SkRect answer = { 25, 25, 75, 75 }; + SkRect answer; + answer.iset(25, 25, 75, 75); REPORTER_ASSERT(reporter, clip); REPORTER_ASSERT(reporter, clip->fRect); diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp index 49a98c2..4125f9f 100644 --- a/tests/MatrixTest.cpp +++ b/tests/MatrixTest.cpp @@ -2,10 +2,12 @@ #include "SkMatrix.h" static bool nearly_equal_scalar(SkScalar a, SkScalar b) { + // Note that we get more compounded error for multiple operations when + // SK_SCALAR_IS_FIXED. #ifdef SK_SCALAR_IS_FLOAT - const float tolerance = 0.000005f; + const SkScalar tolerance = SK_Scalar1 / 200000; #else - const int32_t tolerance = 8; + const SkScalar tolerance = SK_Scalar1 / 1024; #endif return SkScalarAbs(a - b) <= tolerance; diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 6feab51..9a58fa6 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -122,15 +122,14 @@ static void TestPDFPrimitives(skiatest::Reporter* reporter) { realHalf->unref(); // SkRefPtr and new both took a reference. CheckObjectOutput(reporter, realHalf.get(), "0.5", true); +#if defined(SK_SCALAR_IS_FLOAT) SkRefPtr<SkPDFScalar> bigScalar = new SkPDFScalar(110999.75); bigScalar->unref(); // SkRefPtr and new both took a reference. -#if defined(SK_SCALAR_IS_FIXED) || !defined(SK_ALLOW_LARGE_PDF_SCALARS) +#if !defined(SK_ALLOW_LARGE_PDF_SCALARS) CheckObjectOutput(reporter, bigScalar.get(), "111000", true); #else CheckObjectOutput(reporter, bigScalar.get(), "110999.75", true); -#endif -#if defined(SK_SCALAR_IS_FLOAT) && defined(SK_ALLOW_LARGE_PDF_SCALARS) SkRefPtr<SkPDFScalar> biggerScalar = new SkPDFScalar(50000000.1); biggerScalar->unref(); // SkRefPtr and new both took a reference. CheckObjectOutput(reporter, biggerScalar.get(), "50000000", true); @@ -139,6 +138,7 @@ static void TestPDFPrimitives(skiatest::Reporter* reporter) { smallestScalar->unref(); // SkRefPtr and new both took a reference. CheckObjectOutput(reporter, smallestScalar.get(), "0.00001526", true); #endif +#endif SkRefPtr<SkPDFString> stringSimple = new SkPDFString("test ) string ( foo"); stringSimple->unref(); // SkRefPtr and new both took a reference. diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index 3884308..7e4e6bc 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -13,15 +13,13 @@ static void test_convexity2(skiatest::Reporter* reporter) { SkPath pt; pt.moveTo(0, 0); pt.close(); -// check_convexity(reporter, pt, SkPath::kConvex_Convexity); - check_convexity(reporter, pt, SkPath::kUnknown_Convexity); + check_convexity(reporter, pt, SkPath::kConvex_Convexity); SkPath line; line.moveTo(12, 20); line.lineTo(-12, -20); line.close(); - // check_convexity(reporter, pt, SkPath::kConvex_Convexity); - check_convexity(reporter, pt, SkPath::kUnknown_Convexity); + check_convexity(reporter, pt, SkPath::kConvex_Convexity); SkPath triLeft; triLeft.moveTo(0, 0); @@ -79,21 +77,21 @@ static void test_convexity2(skiatest::Reporter* reporter) { SkPath spiral; spiral.moveTo(0, 0); - spiral.lineTo(1, 0); - spiral.lineTo(1, 1); - spiral.lineTo(0, 1); - spiral.lineTo(0,.5); - spiral.lineTo(.5,.5); - spiral.lineTo(.5,.75); + spiral.lineTo(100, 0); + spiral.lineTo(100, 100); + spiral.lineTo(0, 100); + spiral.lineTo(0, 50); + spiral.lineTo(50, 50); + spiral.lineTo(50, 75); spiral.close(); check_convexity(reporter, spiral, SkPath::kConcave_Convexity); SkPath dent; - dent.moveTo(0, 0); - dent.lineTo(1, 1); - dent.lineTo(0, 1); - dent.lineTo(-.5,2); - dent.lineTo(-2, 1); + dent.moveTo(SkIntToScalar(0), SkIntToScalar(0)); + dent.lineTo(SkIntToScalar(100), SkIntToScalar(100)); + dent.lineTo(SkIntToScalar(0), SkIntToScalar(100)); + dent.lineTo(SkIntToScalar(-50), SkIntToScalar(200)); + dent.lineTo(SkIntToScalar(-200), SkIntToScalar(100)); dent.close(); check_convexity(reporter, dent, SkPath::kConcave_Convexity); } @@ -133,13 +131,12 @@ static void setFromString(SkPath* path, const char str[]) { } static void test_convexity(skiatest::Reporter* reporter) { - static const SkPath::Convexity U = SkPath::kUnknown_Convexity; static const SkPath::Convexity C = SkPath::kConcave_Convexity; static const SkPath::Convexity V = SkPath::kConvex_Convexity; SkPath path; - REPORTER_ASSERT(reporter, U == SkPath::ComputeConvexity(path)); + REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); path.addCircle(0, 0, 10); REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); path.addCircle(0, 0, 10); // 2nd circle @@ -155,8 +152,9 @@ static void test_convexity(skiatest::Reporter* reporter) { const char* fPathStr; SkPath::Convexity fExpectedConvexity; } gRec[] = { - { "0 0", SkPath::kUnknown_Convexity }, - { "0 0 10 10", SkPath::kUnknown_Convexity }, + { "", SkPath::kConvex_Convexity }, + { "0 0", SkPath::kConvex_Convexity }, + { "0 0 10 10", SkPath::kConvex_Convexity }, { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity }, { "0 0 10 10 10 20", SkPath::kConvex_Convexity }, { "0 0 10 10 10 0", SkPath::kConvex_Convexity }, @@ -188,7 +186,7 @@ void TestPath(skiatest::Reporter* reporter) { SkRect bounds, bounds2; REPORTER_ASSERT(reporter, p.isEmpty()); - REPORTER_ASSERT(reporter, !p.isConvex()); + REPORTER_ASSERT(reporter, p.isConvex()); REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); REPORTER_ASSERT(reporter, !p.isInverseFillType()); REPORTER_ASSERT(reporter, p == p2); @@ -198,17 +196,14 @@ void TestPath(skiatest::Reporter* reporter) { bounds.set(0, 0, SK_Scalar1, SK_Scalar1); - p.setIsConvex(false); p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); check_convex_bounds(reporter, p, bounds); p.reset(); - p.setIsConvex(false); p.addOval(bounds); check_convex_bounds(reporter, p, bounds); p.reset(); - p.setIsConvex(false); p.addRect(bounds); check_convex_bounds(reporter, p, bounds); @@ -245,18 +240,6 @@ void TestPath(skiatest::Reporter* reporter) { p.getLastPt(&pt); REPORTER_ASSERT(reporter, pt.fX == SK_Scalar1); - // check that reset and rewind clear the convex hint back to false - p.setIsConvex(false); - REPORTER_ASSERT(reporter, !p.isConvex()); - p.setIsConvex(true); - REPORTER_ASSERT(reporter, p.isConvex()); - p.reset(); - REPORTER_ASSERT(reporter, !p.isConvex()); - p.setIsConvex(true); - REPORTER_ASSERT(reporter, p.isConvex()); - p.rewind(); - REPORTER_ASSERT(reporter, !p.isConvex()); - test_convexity(reporter); test_convexity2(reporter); } diff --git a/tests/Reader32Test.cpp b/tests/Reader32Test.cpp new file mode 100644 index 0000000..c752b0f --- /dev/null +++ b/tests/Reader32Test.cpp @@ -0,0 +1,93 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + +#include "SkReader32.h" +#include "Test.h" + +static void assert_eof(skiatest::Reporter* reporter, const SkReader32& reader) { + REPORTER_ASSERT(reporter, reader.eof()); + REPORTER_ASSERT(reporter, reader.size() == reader.offset()); + REPORTER_ASSERT(reporter, (const char*)reader.peek() == + (const char*)reader.base() + reader.size()); +} + +static void assert_start(skiatest::Reporter* reporter, const SkReader32& reader) { + REPORTER_ASSERT(reporter, 0 == reader.offset()); + REPORTER_ASSERT(reporter, reader.size() == reader.available()); + REPORTER_ASSERT(reporter, reader.isAvailable(reader.size())); + REPORTER_ASSERT(reporter, !reader.isAvailable(reader.size() + 1)); + REPORTER_ASSERT(reporter, reader.peek() == reader.base()); +} + +static void assert_empty(skiatest::Reporter* reporter, const SkReader32& reader) { + REPORTER_ASSERT(reporter, 0 == reader.size()); + REPORTER_ASSERT(reporter, 0 == reader.offset()); + REPORTER_ASSERT(reporter, 0 == reader.available()); + REPORTER_ASSERT(reporter, !reader.isAvailable(1)); + assert_eof(reporter, reader); + assert_start(reporter, reader); +} + +static void Tests(skiatest::Reporter* reporter) { + SkReader32 reader; + assert_empty(reporter, reader); + REPORTER_ASSERT(reporter, NULL == reader.base()); + REPORTER_ASSERT(reporter, NULL == reader.peek()); + + size_t i; + + const int32_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const SkScalar data2[] = { 0, SK_Scalar1, -SK_Scalar1, SK_Scalar1/2 }; + char buffer[SkMax32(sizeof(data), sizeof(data2))]; + + reader.setMemory(data, sizeof(data)); + for (i = 0; i < SK_ARRAY_COUNT(data); ++i) { + REPORTER_ASSERT(reporter, sizeof(data) == reader.size()); + REPORTER_ASSERT(reporter, i*4 == reader.offset()); + REPORTER_ASSERT(reporter, (const void*)data == reader.base()); + REPORTER_ASSERT(reporter, (const void*)&data[i] == reader.peek()); + REPORTER_ASSERT(reporter, data[i] == reader.readInt()); + } + assert_eof(reporter, reader); + reader.rewind(); + assert_start(reporter, reader); + reader.read(buffer, sizeof(data)); + REPORTER_ASSERT(reporter, !memcmp(data, buffer, sizeof(data))); + + reader.setMemory(data2, sizeof(data2)); + for (i = 0; i < SK_ARRAY_COUNT(data2); ++i) { + REPORTER_ASSERT(reporter, sizeof(data2) == reader.size()); + REPORTER_ASSERT(reporter, i*4 == reader.offset()); + REPORTER_ASSERT(reporter, (const void*)data2 == reader.base()); + REPORTER_ASSERT(reporter, (const void*)&data2[i] == reader.peek()); + REPORTER_ASSERT(reporter, data2[i] == reader.readScalar()); + } + assert_eof(reporter, reader); + reader.rewind(); + assert_start(reporter, reader); + reader.read(buffer, sizeof(data2)); + REPORTER_ASSERT(reporter, !memcmp(data2, buffer, sizeof(data2))); + + reader.setMemory(NULL, 0); + assert_empty(reporter, reader); + REPORTER_ASSERT(reporter, NULL == reader.base()); + REPORTER_ASSERT(reporter, NULL == reader.peek()); +} + +#include "TestClassDef.h" +DEFINE_TESTCLASS("Reader32", Reader32Class, Tests) + diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp index a051af2..4f36afe 100644 --- a/tests/UtilsTest.cpp +++ b/tests/UtilsTest.cpp @@ -64,7 +64,7 @@ static void test_autounref(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); } -////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// #define kSEARCH_COUNT 91 diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp new file mode 100644 index 0000000..63b1209 --- /dev/null +++ b/tests/Writer32Test.cpp @@ -0,0 +1,90 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + +#include "SkReader32.h" +#include "SkWriter32.h" +#include "Test.h" + +static void test1(skiatest::Reporter* reporter, SkWriter32* writer) { + const uint32_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + for (size_t i = 0; i < SK_ARRAY_COUNT(data); ++i) { + REPORTER_ASSERT(reporter, i*4 == writer->size()); + writer->write32(data[i]); + uint32_t* addr = writer->peek32(i * 4); + REPORTER_ASSERT(reporter, data[i] == *addr); + } + + char buffer[sizeof(data)]; + REPORTER_ASSERT(reporter, sizeof(buffer) == writer->size()); + writer->flatten(buffer); + REPORTER_ASSERT(reporter, !memcmp(data, buffer, sizeof(buffer))); +} + +static void test2(skiatest::Reporter* reporter, SkWriter32* writer) { + static const char gStr[] = "abcdefghimjklmnopqrstuvwxyz"; + size_t i; + + size_t len = 0; + for (i = 0; i <= 26; ++i) { + len += SkWriter32::WriteStringSize(gStr, i); + writer->writeString(gStr, i); + } + REPORTER_ASSERT(reporter, writer->size() == len); + + SkAutoMalloc storage(len); + writer->flatten(storage.get()); + + SkReader32 reader; + reader.setMemory(storage.get(), len); + for (i = 0; i <= 26; ++i) { + REPORTER_ASSERT(reporter, !reader.eof()); + const char* str = reader.readString(&len); + REPORTER_ASSERT(reporter, i == len); + REPORTER_ASSERT(reporter, strlen(str) == len); + REPORTER_ASSERT(reporter, !memcmp(str, gStr, len)); + } + REPORTER_ASSERT(reporter, reader.eof()); +} + +static void Tests(skiatest::Reporter* reporter) { + // dynamic allocator + { + SkWriter32 writer(256 * 4); + REPORTER_ASSERT(reporter, NULL == writer.getSingleBlock()); + test1(reporter, &writer); + + writer.reset(); + test2(reporter, &writer); + } + + // single-block + { + SkWriter32 writer(0); + uint32_t storage[256]; + REPORTER_ASSERT(reporter, NULL == writer.getSingleBlock()); + writer.reset(storage, sizeof(storage)); + REPORTER_ASSERT(reporter, (void*)storage == writer.getSingleBlock()); + test1(reporter, &writer); + + writer.reset(storage, sizeof(storage)); + test2(reporter, &writer); + } +} + +#include "TestClassDef.h" +DEFINE_TESTCLASS("Writer32", Writer32Class, Tests) + diff --git a/tests/tests_files.mk b/tests/tests_files.mk index 28d5fe7..9b90179 100644 --- a/tests/tests_files.mk +++ b/tests/tests_files.mk @@ -22,6 +22,7 @@ SOURCE := \ ParsePathTest.cpp \ PathMeasureTest.cpp \ PathTest.cpp \ + Reader32Test.cpp \ RefDictTest.cpp \ RegionTest.cpp \ Sk64Test.cpp \ @@ -33,4 +34,5 @@ SOURCE := \ Test.cpp \ TestSize.cpp \ UtilsTest.cpp \ + Writer32Test.cpp \ XfermodeTest.cpp |