Index: tests/DiscardableMemoryTest.cpp |
diff --git a/tests/DiscardableMemoryTest.cpp b/tests/DiscardableMemoryTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7310f68bd66c5e3e287412489b9ebe1d1f64a510 |
--- /dev/null |
+++ b/tests/DiscardableMemoryTest.cpp |
@@ -0,0 +1,34 @@ |
+/* |
+ * 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!"; |
scroggo
2013/11/22 15:37:05
nit: Do either of these need to be static?
hal.canary
2013/11/22 16:37:27
Done.
|
+ static const size_t len = sizeof(testString); |
+ SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len)); |
+ REPORTER_ASSERT(reporter, dm.get() != NULL); |
+ if (NULL == dm.get()) { |
+ 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) { |
+ return; |
+ } |
+ ptr = dm->data(); |
+ REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len)); |
+ dm->unlock(); |
+} |
+ |