From 6eb549e8ca3d88d7536859fd5aa3343fc3011f2f Mon Sep 17 00:00:00 2001 From: "vandebo@chromium.org" Date: Fri, 4 Jan 2013 18:11:21 +0000 Subject: Revert "Remove SkRefPtr" - r7021 samplecode/ still needs to be updated. Review URL: https://codereview.appspot.com/7032048 git-svn-id: http://skia.googlecode.com/svn/trunk@7022 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/PDFPrimitivesTest.cpp | 102 ++++++++++++++++++++++++++++---------------- tests/UtilsTest.cpp | 30 +++++++++++++ 2 files changed, 95 insertions(+), 37 deletions(-) (limited to 'tests') diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp index 42fc133b3c..5cbb9057be 100644 --- a/tests/PDFPrimitivesTest.cpp +++ b/tests/PDFPrimitivesTest.cpp @@ -94,9 +94,11 @@ static void SimpleCheckObjectOutput(skiatest::Reporter* reporter, static void TestPDFStream(skiatest::Reporter* reporter) { char streamBytes[] = "Test\nFoo\tBar"; - SkAutoTUnref streamData(new SkMemoryStream( - streamBytes, strlen(streamBytes), true)); - SkAutoTUnref stream(new SkPDFStream(streamData.get())); + SkRefPtr streamData = new SkMemoryStream( + streamBytes, strlen(streamBytes), true); + streamData->unref(); // SkRefPtr and new both took a reference. + SkRefPtr stream = new SkPDFStream(streamData.get()); + stream->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput( reporter, stream.get(), "<> stream\nTest\nFoo\tBar\nendstream"); @@ -112,7 +114,8 @@ static void TestPDFStream(skiatest::Reporter* reporter) { "with an uncompressed string."; SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, strlen(streamBytes2))); - SkAutoTUnref stream(new SkPDFStream(streamData2.get())); + SkRefPtr stream = new SkPDFStream(streamData2.get()); + stream->unref(); // SkRefPtr and new both took a reference. SkDynamicMemoryWStream compressedByteStream; SkFlate::Deflate(streamData2.get(), &compressedByteStream); @@ -143,11 +146,13 @@ static void TestPDFStream(skiatest::Reporter* reporter) { static void TestCatalog(skiatest::Reporter* reporter) { SkPDFCatalog catalog((SkPDFDocument::Flags)0); - SkAutoTUnref int1(new SkPDFInt(1)); - SkAutoTUnref int2(new SkPDFInt(2)); - SkAutoTUnref int3(new SkPDFInt(3)); - int1.get()->ref(); - SkAutoTUnref int1Again(int1.get()); + SkRefPtr int1 = new SkPDFInt(1); + int1->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int2 = new SkPDFInt(2); + int2->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int3 = new SkPDFInt(3); + int3->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int1Again(int1.get()); catalog.addObject(int1.get(), false); catalog.addObject(int2.get(), false); @@ -168,9 +173,12 @@ static void TestCatalog(skiatest::Reporter* reporter) { } static void TestObjectRef(skiatest::Reporter* reporter) { - SkAutoTUnref int1(new SkPDFInt(1)); - SkAutoTUnref int2(new SkPDFInt(2)); - SkAutoTUnref int2ref(new SkPDFObjRef(int2.get())); + SkRefPtr int1 = new SkPDFInt(1); + int1->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int2 = new SkPDFInt(2); + int2->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int2ref = new SkPDFObjRef(int2.get()); + int2ref->unref(); // SkRefPtr and new both took a reference. SkPDFCatalog catalog((SkPDFDocument::Flags)0); catalog.addObject(int1.get(), false); @@ -187,11 +195,16 @@ static void TestObjectRef(skiatest::Reporter* reporter) { } static void TestSubstitute(skiatest::Reporter* reporter) { - SkAutoTUnref proxy(new SkPDFTestDict()); - SkAutoTUnref stub(new SkPDFTestDict()); - SkAutoTUnref int33(new SkPDFInt(33)); - SkAutoTUnref stubResource(new SkPDFDict()); - SkAutoTUnref int44(new SkPDFInt(44)); + SkRefPtr proxy = new SkPDFTestDict(); + proxy->unref(); // SkRefPtr and new both took a reference. + SkRefPtr stub = new SkPDFTestDict(); + stub->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int33 = new SkPDFInt(33); + int33->unref(); // SkRefPtr and new both took a reference. + SkRefPtr stubResource = new SkPDFDict(); + stubResource->unref(); // SkRefPtr and new both took a reference. + SkRefPtr int44 = new SkPDFInt(44); + int44->unref(); // SkRefPtr and new both took a reference. stub->insert("Value", int33.get()); stubResource->insert("InnerValue", int44.get()); @@ -218,74 +231,89 @@ static void TestSubstitute(skiatest::Reporter* reporter) { } static void TestPDFPrimitives(skiatest::Reporter* reporter) { - SkAutoTUnref int42(new SkPDFInt(42)); + SkRefPtr int42 = new SkPDFInt(42); + int42->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, int42.get(), "42"); - SkAutoTUnref realHalf(new SkPDFScalar(SK_ScalarHalf)); + SkRefPtr realHalf = new SkPDFScalar(SK_ScalarHalf); + realHalf->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, realHalf.get(), "0.5"); #if defined(SK_SCALAR_IS_FLOAT) - SkAutoTUnref bigScalar(new SkPDFScalar(110999.75f)); + SkRefPtr bigScalar = new SkPDFScalar(110999.75f); + bigScalar->unref(); // SkRefPtr and new both took a reference. #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) SimpleCheckObjectOutput(reporter, bigScalar.get(), "111000"); #else SimpleCheckObjectOutput(reporter, bigScalar.get(), "110999.75"); - SkAutoTUnref biggerScalar(new SkPDFScalar(50000000.1)); + SkRefPtr biggerScalar = new SkPDFScalar(50000000.1); + biggerScalar->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, biggerScalar.get(), "50000000"); - SkAutoTUnref smallestScalar(new SkPDFScalar(1.0/65536)); + SkRefPtr smallestScalar = new SkPDFScalar(1.0/65536); + smallestScalar->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, smallestScalar.get(), "0.00001526"); #endif #endif - SkAutoTUnref stringSimple( - new SkPDFString("test ) string ( foo")); + SkRefPtr stringSimple = new SkPDFString("test ) string ( foo"); + stringSimple->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, stringSimple.get(), "(test \\) string \\( foo)"); - SkAutoTUnref stringComplex( - new SkPDFString("\ttest ) string ( foo")); + SkRefPtr stringComplex = + new SkPDFString("\ttest ) string ( foo"); + stringComplex->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, stringComplex.get(), "<0974657374202920737472696E67202820666F6F>"); - SkAutoTUnref name(new SkPDFName("Test name\twith#tab")); + SkRefPtr name = new SkPDFName("Test name\twith#tab"); + name->unref(); // SkRefPtr and new both took a reference. const char expectedResult[] = "/Test#20name#09with#23tab"; CheckObjectOutput(reporter, name.get(), expectedResult, strlen(expectedResult), false, false); - SkAutoTUnref escapedName(new SkPDFName("A#/%()<>[]{}B")); + SkRefPtr escapedName = new SkPDFName("A#/%()<>[]{}B"); + escapedName->unref(); // SkRefPtr and new both took a reference. const char escapedNameExpected[] = "/A#23#2F#25#28#29#3C#3E#5B#5D#7B#7DB"; CheckObjectOutput(reporter, escapedName.get(), escapedNameExpected, strlen(escapedNameExpected), false, false); // Test that we correctly handle characters with the high-bit set. const unsigned char highBitCString[] = {0xDE, 0xAD, 'b', 'e', 0xEF, 0}; - SkAutoTUnref highBitName( - new SkPDFName((const char*)highBitCString)); + SkRefPtr highBitName = new SkPDFName((const char*)highBitCString); + highBitName->unref(); // SkRefPtr and new both took a reference. const char highBitExpectedResult[] = "/#DE#ADbe#EF"; CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult, strlen(highBitExpectedResult), false, false); - SkAutoTUnref array(new SkPDFArray); + SkRefPtr array = new SkPDFArray; + array->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, array.get(), "[]"); array->append(int42.get()); SimpleCheckObjectOutput(reporter, array.get(), "[42]"); array->append(realHalf.get()); SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]"); - SkAutoTUnref int0(new SkPDFInt(0)); + SkRefPtr int0 = new SkPDFInt(0); + int0->unref(); // SkRefPtr and new both took a reference. array->append(int0.get()); SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]"); - SkAutoTUnref int1(new SkPDFInt(1)); + SkRefPtr int1 = new SkPDFInt(1); + int1->unref(); // SkRefPtr and new both took a reference. array->setAt(0, int1.get()); SimpleCheckObjectOutput(reporter, array.get(), "[1 0.5 0]"); - SkAutoTUnref dict(new SkPDFDict); + SkRefPtr dict = new SkPDFDict; + dict->unref(); // SkRefPtr and new both took a reference. SimpleCheckObjectOutput(reporter, dict.get(), "<<>>"); - SkAutoTUnref n1(new SkPDFName("n1")); + SkRefPtr n1 = new SkPDFName("n1"); + n1->unref(); // SkRefPtr and new both took a reference. dict->insert(n1.get(), int42.get()); SimpleCheckObjectOutput(reporter, dict.get(), "<>"); - SkAutoTUnref n2(new SkPDFName("n2")); - SkAutoTUnref n3(new SkPDFName("n3")); + SkRefPtr n2 = new SkPDFName("n2"); + n2->unref(); // SkRefPtr and new both took a reference. + SkRefPtr n3 = new SkPDFName("n3"); + n3->unref(); // SkRefPtr and new both took a reference. dict->insert(n2.get(), realHalf.get()); dict->insert(n3.get(), array.get()); SimpleCheckObjectOutput(reporter, dict.get(), diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp index 7f27f7e78e..1c2f870d1f 100644 --- a/tests/UtilsTest.cpp +++ b/tests/UtilsTest.cpp @@ -27,6 +27,35 @@ private: SK_DEFINE_INST_COUNT(RefClass) +static void test_refptr(skiatest::Reporter* reporter) { + RefClass* r0 = new RefClass(0); + + SkRefPtr rc0; + REPORTER_ASSERT(reporter, rc0.get() == NULL); + REPORTER_ASSERT(reporter, !rc0); + + SkRefPtr rc1; + REPORTER_ASSERT(reporter, rc0 == rc1); + REPORTER_ASSERT(reporter, rc0.get() != r0); + + rc0 = r0; + REPORTER_ASSERT(reporter, rc0); + REPORTER_ASSERT(reporter, rc0 != rc1); + REPORTER_ASSERT(reporter, rc0.get() == r0); + + rc1 = rc0; + REPORTER_ASSERT(reporter, rc1); + REPORTER_ASSERT(reporter, rc0 == rc1); + REPORTER_ASSERT(reporter, rc0.get() == r0); + + rc0 = NULL; + REPORTER_ASSERT(reporter, rc0.get() == NULL); + REPORTER_ASSERT(reporter, !rc0); + REPORTER_ASSERT(reporter, rc0 != rc1); + + r0->unref(); +} + static void test_autounref(skiatest::Reporter* reporter) { RefClass obj(0); REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); @@ -149,6 +178,7 @@ static void TestUTF(skiatest::Reporter* reporter) { test_utf16(reporter); test_search(reporter); + test_refptr(reporter); test_autounref(reporter); } -- cgit v1.2.3