aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-04 17:59:42 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-04 17:59:42 +0000
commite8a76ae8edc4f90456f9d8f90e56bf97f2657f3a (patch)
tree4e7d18468236dd4af78d207d719a9c265e86facd /tests
parent2fb96cc5d713451216bd63d5dc8d19abc8550730 (diff)
Remove SkRefPtr
Review URL: https://codereview.appspot.com/7030059 git-svn-id: http://skia.googlecode.com/svn/trunk@7021 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/PDFPrimitivesTest.cpp102
-rw-r--r--tests/UtilsTest.cpp30
2 files changed, 37 insertions, 95 deletions
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 5cbb9057be..42fc133b3c 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -94,11 +94,9 @@ static void SimpleCheckObjectOutput(skiatest::Reporter* reporter,
static void TestPDFStream(skiatest::Reporter* reporter) {
char streamBytes[] = "Test\nFoo\tBar";
- SkRefPtr<SkMemoryStream> streamData = new SkMemoryStream(
- streamBytes, strlen(streamBytes), true);
- streamData->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFStream> stream = new SkPDFStream(streamData.get());
- stream->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkMemoryStream> streamData(new SkMemoryStream(
+ streamBytes, strlen(streamBytes), true));
+ SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get()));
SimpleCheckObjectOutput(
reporter, stream.get(),
"<</Length 12\n>> stream\nTest\nFoo\tBar\nendstream");
@@ -114,8 +112,7 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
"with an uncompressed string.";
SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2,
strlen(streamBytes2)));
- SkRefPtr<SkPDFStream> stream = new SkPDFStream(streamData2.get());
- stream->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get()));
SkDynamicMemoryWStream compressedByteStream;
SkFlate::Deflate(streamData2.get(), &compressedByteStream);
@@ -146,13 +143,11 @@ static void TestPDFStream(skiatest::Reporter* reporter) {
static void TestCatalog(skiatest::Reporter* reporter) {
SkPDFCatalog catalog((SkPDFDocument::Flags)0);
- SkRefPtr<SkPDFInt> int1 = new SkPDFInt(1);
- int1->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> int2 = new SkPDFInt(2);
- int2->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> int3 = new SkPDFInt(3);
- int3->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> int1Again(int1.get());
+ SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
+ SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
+ SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3));
+ int1.get()->ref();
+ SkAutoTUnref<SkPDFInt> int1Again(int1.get());
catalog.addObject(int1.get(), false);
catalog.addObject(int2.get(), false);
@@ -173,12 +168,9 @@ static void TestCatalog(skiatest::Reporter* reporter) {
}
static void TestObjectRef(skiatest::Reporter* reporter) {
- SkRefPtr<SkPDFInt> int1 = new SkPDFInt(1);
- int1->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> int2 = new SkPDFInt(2);
- int2->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFObjRef> int2ref = new SkPDFObjRef(int2.get());
- int2ref->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
+ SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
+ SkAutoTUnref<SkPDFObjRef> int2ref(new SkPDFObjRef(int2.get()));
SkPDFCatalog catalog((SkPDFDocument::Flags)0);
catalog.addObject(int1.get(), false);
@@ -195,16 +187,11 @@ static void TestObjectRef(skiatest::Reporter* reporter) {
}
static void TestSubstitute(skiatest::Reporter* reporter) {
- SkRefPtr<SkPDFTestDict> proxy = new SkPDFTestDict();
- proxy->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFTestDict> stub = new SkPDFTestDict();
- stub->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> int33 = new SkPDFInt(33);
- int33->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFDict> stubResource = new SkPDFDict();
- stubResource->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFInt> int44 = new SkPDFInt(44);
- int44->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFTestDict> proxy(new SkPDFTestDict());
+ SkAutoTUnref<SkPDFTestDict> stub(new SkPDFTestDict());
+ SkAutoTUnref<SkPDFInt> int33(new SkPDFInt(33));
+ SkAutoTUnref<SkPDFDict> stubResource(new SkPDFDict());
+ SkAutoTUnref<SkPDFInt> int44(new SkPDFInt(44));
stub->insert("Value", int33.get());
stubResource->insert("InnerValue", int44.get());
@@ -231,89 +218,74 @@ static void TestSubstitute(skiatest::Reporter* reporter) {
}
static void TestPDFPrimitives(skiatest::Reporter* reporter) {
- SkRefPtr<SkPDFInt> int42 = new SkPDFInt(42);
- int42->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFInt> int42(new SkPDFInt(42));
SimpleCheckObjectOutput(reporter, int42.get(), "42");
- SkRefPtr<SkPDFScalar> realHalf = new SkPDFScalar(SK_ScalarHalf);
- realHalf->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFScalar> realHalf(new SkPDFScalar(SK_ScalarHalf));
SimpleCheckObjectOutput(reporter, realHalf.get(), "0.5");
#if defined(SK_SCALAR_IS_FLOAT)
- SkRefPtr<SkPDFScalar> bigScalar = new SkPDFScalar(110999.75f);
- bigScalar->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFScalar> bigScalar(new SkPDFScalar(110999.75f));
#if !defined(SK_ALLOW_LARGE_PDF_SCALARS)
SimpleCheckObjectOutput(reporter, bigScalar.get(), "111000");
#else
SimpleCheckObjectOutput(reporter, bigScalar.get(), "110999.75");
- SkRefPtr<SkPDFScalar> biggerScalar = new SkPDFScalar(50000000.1);
- biggerScalar->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFScalar> biggerScalar(new SkPDFScalar(50000000.1));
SimpleCheckObjectOutput(reporter, biggerScalar.get(), "50000000");
- SkRefPtr<SkPDFScalar> smallestScalar = new SkPDFScalar(1.0/65536);
- smallestScalar->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFScalar> smallestScalar(new SkPDFScalar(1.0/65536));
SimpleCheckObjectOutput(reporter, smallestScalar.get(), "0.00001526");
#endif
#endif
- SkRefPtr<SkPDFString> stringSimple = new SkPDFString("test ) string ( foo");
- stringSimple->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFString> stringSimple(
+ new SkPDFString("test ) string ( foo"));
SimpleCheckObjectOutput(reporter, stringSimple.get(),
"(test \\) string \\( foo)");
- SkRefPtr<SkPDFString> stringComplex =
- new SkPDFString("\ttest ) string ( foo");
- stringComplex->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFString> stringComplex(
+ new SkPDFString("\ttest ) string ( foo"));
SimpleCheckObjectOutput(reporter, stringComplex.get(),
"<0974657374202920737472696E67202820666F6F>");
- SkRefPtr<SkPDFName> name = new SkPDFName("Test name\twith#tab");
- name->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFName> name(new SkPDFName("Test name\twith#tab"));
const char expectedResult[] = "/Test#20name#09with#23tab";
CheckObjectOutput(reporter, name.get(), expectedResult,
strlen(expectedResult), false, false);
- SkRefPtr<SkPDFName> escapedName = new SkPDFName("A#/%()<>[]{}B");
- escapedName->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFName> escapedName(new SkPDFName("A#/%()<>[]{}B"));
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};
- SkRefPtr<SkPDFName> highBitName = new SkPDFName((const char*)highBitCString);
- highBitName->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFName> highBitName(
+ new SkPDFName((const char*)highBitCString));
const char highBitExpectedResult[] = "/#DE#ADbe#EF";
CheckObjectOutput(reporter, highBitName.get(), highBitExpectedResult,
strlen(highBitExpectedResult), false, false);
- SkRefPtr<SkPDFArray> array = new SkPDFArray;
- array->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFArray> array(new SkPDFArray);
SimpleCheckObjectOutput(reporter, array.get(), "[]");
array->append(int42.get());
SimpleCheckObjectOutput(reporter, array.get(), "[42]");
array->append(realHalf.get());
SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5]");
- SkRefPtr<SkPDFInt> int0 = new SkPDFInt(0);
- int0->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFInt> int0(new SkPDFInt(0));
array->append(int0.get());
SimpleCheckObjectOutput(reporter, array.get(), "[42 0.5 0]");
- SkRefPtr<SkPDFInt> int1 = new SkPDFInt(1);
- int1->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
array->setAt(0, int1.get());
SimpleCheckObjectOutput(reporter, array.get(), "[1 0.5 0]");
- SkRefPtr<SkPDFDict> dict = new SkPDFDict;
- dict->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFDict> dict(new SkPDFDict);
SimpleCheckObjectOutput(reporter, dict.get(), "<<>>");
- SkRefPtr<SkPDFName> n1 = new SkPDFName("n1");
- n1->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFName> n1(new SkPDFName("n1"));
dict->insert(n1.get(), int42.get());
SimpleCheckObjectOutput(reporter, dict.get(), "<</n1 42\n>>");
- SkRefPtr<SkPDFName> n2 = new SkPDFName("n2");
- n2->unref(); // SkRefPtr and new both took a reference.
- SkRefPtr<SkPDFName> n3 = new SkPDFName("n3");
- n3->unref(); // SkRefPtr and new both took a reference.
+ SkAutoTUnref<SkPDFName> n2(new SkPDFName("n2"));
+ SkAutoTUnref<SkPDFName> n3(new SkPDFName("n3"));
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 1c2f870d1f..7f27f7e78e 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -27,35 +27,6 @@ private:
SK_DEFINE_INST_COUNT(RefClass)
-static void test_refptr(skiatest::Reporter* reporter) {
- RefClass* r0 = new RefClass(0);
-
- SkRefPtr<RefClass> rc0;
- REPORTER_ASSERT(reporter, rc0.get() == NULL);
- REPORTER_ASSERT(reporter, !rc0);
-
- SkRefPtr<RefClass> 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());
@@ -178,7 +149,6 @@ static void TestUTF(skiatest::Reporter* reporter) {
test_utf16(reporter);
test_search(reporter);
- test_refptr(reporter);
test_autounref(reporter);
}