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

Unified Diff: tests/DataRefTest.cpp

Issue 14188049: add SkDataTable, to efficiently store an immutable array. Includes a builder (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « src/core/SkDataTable.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/DataRefTest.cpp
===================================================================
--- tests/DataRefTest.cpp (revision 8772)
+++ tests/DataRefTest.cpp (working copy)
@@ -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 @@
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 @@
test_cstring(reporter);
test_dataset(reporter);
+ test_datatable(reporter);
}
#include "TestClassDef.h"
« no previous file with comments | « src/core/SkDataTable.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698