Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1501)

Unified Diff: tests/UtilsTest.cpp

Issue 18915010: Fix leak in SkAutoSTArray (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fix the assert Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkTemplates.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/UtilsTest.cpp
===================================================================
--- tests/UtilsTest.cpp (revision 10052)
+++ tests/UtilsTest.cpp (working copy)
@@ -48,6 +48,75 @@
REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
}
+static void test_autostarray(skiatest::Reporter* reporter) {
+ RefClass obj0(0);
+ RefClass obj1(1);
+ REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+
+ {
+ SkAutoSTArray<2, SkRefPtr<RefClass> > tmp;
+ REPORTER_ASSERT(reporter, 0 == tmp.count());
+
+ tmp.reset(0); // test out reset(0) when already at 0
+ tmp.reset(4); // this should force a new allocation
+ REPORTER_ASSERT(reporter, 4 == tmp.count());
+ tmp[0] = &obj0;
+ tmp[1] = &obj1;
+ REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+
+ // test out reset with data in the array (and a new allocation)
+ tmp.reset(0);
+ REPORTER_ASSERT(reporter, 0 == tmp.count());
+ REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+
+ tmp.reset(2); // this should use the preexisting allocation
+ REPORTER_ASSERT(reporter, 2 == tmp.count());
+ tmp[0] = &obj0;
+ tmp[1] = &obj1;
+ }
+
+ // test out destructor with data in the array (and using existing allocation)
+ REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+
+ {
+ // test out allocating ctor (this should allocate new memory)
+ SkAutoSTArray<2, SkRefPtr<RefClass> > tmp(4);
+ REPORTER_ASSERT(reporter, 4 == tmp.count());
+
+ tmp[0] = &obj0;
+ tmp[1] = &obj1;
+ REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+
+ // Test out resut with data in the array and malloced storage
+ tmp.reset(0);
+ REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+
+ tmp.reset(2); // this should use the preexisting storage
+ tmp[0] = &obj0;
+ tmp[1] = &obj1;
+ REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+
+ tmp.reset(4); // this should force a new malloc
+ REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+
+ tmp[0] = &obj0;
+ tmp[1] = &obj1;
+ REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ }
+
+ REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+}
+
/////////////////////////////////////////////////////////////////////////////
#define kSEARCH_COUNT 91
@@ -150,6 +219,7 @@
test_utf16(reporter);
test_search(reporter);
test_autounref(reporter);
+ test_autostarray(reporter);
}
#include "TestClassDef.h"
« no previous file with comments | « include/core/SkTemplates.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698