aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/DataRefTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-19 20:16:01 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-19 20:16:01 +0000
commit8c5c7a905b708f7c0a991ca7c872af645544afef (patch)
tree974279a91657b0a5d9b74e106bc6b723ab59e7e5 /tests/DataRefTest.cpp
parent0c888286f7db7e9cd861b2e425a17e109601d3fa (diff)
add SkDataTable, to efficiently store an immutable array. Includes a builder
helper class. Review URL: https://codereview.chromium.org/14188049 git-svn-id: http://skia.googlecode.com/svn/trunk@8779 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/DataRefTest.cpp')
-rw-r--r--tests/DataRefTest.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp
index 8c002c80c0..449149af95 100644
--- a/tests/DataRefTest.cpp
+++ b/tests/DataRefTest.cpp
@@ -8,6 +8,7 @@
#include "Test.h"
#include "SkData.h"
#include "SkDataSet.h"
+#include "SkDataTable.h"
#include "SkStream.h"
template <typename T> class SkTUnref {
@@ -22,6 +23,79 @@ private:
T* fRef;
};
+static void test_simpletable(skiatest::Reporter* reporter) {
+ const int idata[] = { 1, 4, 9, 16, 25, 63 };
+ int icount = SK_ARRAY_COUNT(idata);
+ SkAutoTUnref<SkDataTable> itable(SkDataTable::NewCopyArray(idata,
+ sizeof(idata[0]),
+ icount));
+ REPORTER_ASSERT(reporter, itable->count() == icount);
+ for (int i = 0; i < icount; ++i) {
+ size_t size;
+ REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i));
+ REPORTER_ASSERT(reporter, *itable->atDataT<int>(i, &size) == idata[i]);
+ REPORTER_ASSERT(reporter, sizeof(int) == size);
+ }
+}
+
+static void test_vartable(skiatest::Reporter* reporter) {
+ const char* str[] = {
+ "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
+ };
+ int count = SK_ARRAY_COUNT(str);
+ size_t sizes[SK_ARRAY_COUNT(str)];
+ for (int i = 0; i < count; ++i) {
+ sizes[i] = strlen(str[i]) + 1;
+ }
+
+ SkAutoTUnref<SkDataTable> table(SkDataTable::NewCopyArrays(
+ (const void*const*)str, sizes, count));
+
+ REPORTER_ASSERT(reporter, table->count() == count);
+ for (int i = 0; i < count; ++i) {
+ size_t size;
+ REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]);
+ REPORTER_ASSERT(reporter, !strcmp(table->atDataT<const char>(i, &size),
+ str[i]));
+ REPORTER_ASSERT(reporter, size == sizes[i]);
+
+ const char* s = table->atStr(i);
+ REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
+ }
+}
+
+static void test_tablebuilder(skiatest::Reporter* reporter) {
+ const char* str[] = {
+ "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
+ };
+ int count = SK_ARRAY_COUNT(str);
+
+ SkDataTableBuilder builder(16);
+
+ for (int i = 0; i < count; ++i) {
+ builder.append(str[i], strlen(str[i]) + 1);
+ }
+ SkAutoTUnref<SkDataTable> table(builder.createDataTable());
+
+ REPORTER_ASSERT(reporter, table->count() == count);
+ for (int i = 0; i < count; ++i) {
+ size_t size;
+ REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1);
+ REPORTER_ASSERT(reporter, !strcmp(table->atDataT<const char>(i, &size),
+ str[i]));
+ REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1);
+
+ const char* s = table->atStr(i);
+ REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
+ }
+}
+
+static void test_datatable(skiatest::Reporter* reporter) {
+ test_simpletable(reporter);
+ test_vartable(reporter);
+ test_tablebuilder(reporter);
+}
+
static void unrefAll(const SkDataSet::Pair pairs[], int count) {
for (int i = 0; i < count; ++i) {
pairs[i].fValue->unref();
@@ -146,6 +220,7 @@ static void TestData(skiatest::Reporter* reporter) {
test_cstring(reporter);
test_dataset(reporter);
+ test_datatable(reporter);
}
#include "TestClassDef.h"