aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-14 19:22:21 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-06-14 19:22:21 +0000
commit1622c99150a1d7401118ddcdd85077934a379890 (patch)
tree2507d5e9d70979cc06556df3650478061cee4ef7 /tests
parent35ae8ea9befa4ebc9576769ecc7b48c4644f535f (diff)
add
git-svn-id: http://skia.googlecode.com/svn/trunk@1589 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/DataRefTest.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp
new file mode 100644
index 0000000000..7590ebbd52
--- /dev/null
+++ b/tests/DataRefTest.cpp
@@ -0,0 +1,54 @@
+#include "Test.h"
+#include "SkDataRef.h"
+
+static void* gGlobal;
+
+static void delete_int_proc(const void* ptr, size_t len, void* context) {
+ int* data = (int*)ptr;
+ SkASSERT(context == gGlobal);
+ delete[] data;
+}
+
+static void assert_len(skiatest::Reporter* reporter, SkDataRef* ref, size_t len) {
+ REPORTER_ASSERT(reporter, ref->size() == len);
+}
+
+static void assert_data(skiatest::Reporter* reporter, SkDataRef* ref,
+ const void* data, size_t len) {
+ REPORTER_ASSERT(reporter, ref->size() == len);
+ REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len));
+}
+
+void TestDataRef(skiatest::Reporter* reporter) {
+ const char* str = "We the people, in order to form a more perfect union.";
+ const int N = 10;
+
+ SkDataRef* r0 = SkDataRef::NewEmpty();
+ SkDataRef* r1 = SkDataRef::NewWithCopy(str, strlen(str));
+ SkDataRef* r2 = SkDataRef::NewWithProc(new int[N], N*sizeof(int),
+ delete_int_proc, gGlobal);
+ SkDataRef* r3 = SkDataRef::NewSubset(r1, 7, 6);
+
+ SkAutoUnref aur0(r0);
+ SkAutoUnref aur1(r1);
+ SkAutoUnref aur2(r2);
+ SkAutoUnref aur3(r3);
+
+ assert_len(reporter, r0, 0);
+ assert_len(reporter, r1, strlen(str));
+ assert_len(reporter, r2, N * sizeof(int));
+ assert_len(reporter, r3, 6);
+
+ assert_data(reporter, r1, str, strlen(str));
+ assert_data(reporter, r3, "people", 6);
+
+ SkDataRef* tmp = SkDataRef::NewSubset(r1, strlen(str), 10);
+ assert_len(reporter, tmp, 0);
+ tmp->unref();
+ tmp = SkDataRef::NewSubset(r1, 0, 0);
+ assert_len(reporter, tmp, 0);
+ tmp->unref();
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("DataRef", DataRefTestClass, TestDataRef)