Index: tests/DiscardableMemoryTest.cpp |
diff --git a/tests/DiscardableMemoryTest.cpp b/tests/DiscardableMemoryTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f7a37f2e5be02df261c6ed2a7fe0e4f7fcb7aab |
--- /dev/null |
+++ b/tests/DiscardableMemoryTest.cpp |
@@ -0,0 +1,32 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkDiscardableMemory.h" |
+ |
+#include "Test.h" |
+#include "TestClassDef.h" |
+ |
+DEF_TEST(DiscardableMemory, reporter) { |
+ static const char testString[] = "HELLO, WORLD!"; |
+ SkDiscardableMemory* dm = SkDiscardableMemory::Create(sizeof(testString)); |
+ REPORTER_ASSERT(reporter, dm != NULL); |
+ if (NULL == dm) |
scroggo
2013/11/22 14:34:14
Our style guide suggests using braces like so:
if
hal.canary
2013/11/22 15:17:54
Done.
|
+ return; |
+ void* ptr = dm->data(); |
+ REPORTER_ASSERT(reporter, ptr != NULL); |
+ memcpy(ptr, testString, sizeof(testString)); |
+ dm->unlock(); |
+ bool success = dm->lock(); |
+ REPORTER_ASSERT(reporter, success); |
+ if (!success) |
scroggo
2013/11/22 14:34:14
braces
hal.canary
2013/11/22 15:17:54
Done.
|
+ return; |
scroggo
2013/11/22 14:34:14
dm is leaked here. Maybe wrap it in an SkAutoTDele
hal.canary
2013/11/22 15:17:54
Done.
|
+ ptr = dm->data(); |
+ REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, sizeof(testString))); |
+ dm->unlock(); |
+ SkDELETE(dm); |
+} |
+ |