diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-12 20:47:53 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-12 20:47:53 +0000 |
commit | 51c62a6cfadc302bb65bb5a98e358c93223dc73f (patch) | |
tree | 34371459b9ab82133c9a2b723029fadc2fc3ef3c /tests | |
parent | 64a0ec36555352ec31aa7c5a7630a5d042b010ba (diff) |
add readPtr and writePtr to SkReader32 and SkWriter32
add template helper SkSWriter32, which allocates initial storage buffer
Review URL: https://codereview.appspot.com/6299075
git-svn-id: http://skia.googlecode.com/svn/trunk@4237 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Writer32Test.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp index 35fb29f38e..311f37d8fb 100644 --- a/tests/Writer32Test.cpp +++ b/tests/Writer32Test.cpp @@ -12,6 +12,34 @@ #include "SkWriter32.h" #include "Test.h" +static void test_ptr(skiatest::Reporter* reporter) { + SkSWriter32<32> writer(32); + + void* p0 = reporter; + void* p1 = &writer; + + // try writing ptrs where at least one of them may be at a non-multiple of + // 8 boundary, to confirm this works on 64bit machines. + + writer.writePtr(p0); + writer.write8(0x33); + writer.writePtr(p1); + writer.write8(0x66); + + size_t size = writer.size(); + REPORTER_ASSERT(reporter, 2 * sizeof(void*) + 2 * sizeof(int32_t)); + + char buffer[32]; + SkASSERT(sizeof(buffer) >= size); + writer.flatten(buffer); + + SkReader32 reader(buffer, size); + REPORTER_ASSERT(reporter, reader.readPtr() == p0); + REPORTER_ASSERT(reporter, reader.readInt() == 0x33); + REPORTER_ASSERT(reporter, reader.readPtr() == p1); + REPORTER_ASSERT(reporter, reader.readInt() == 0x66); +} + static void test1(skiatest::Reporter* reporter, SkWriter32* writer) { const uint32_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (size_t i = 0; i < SK_ARRAY_COUNT(data); ++i) { @@ -79,8 +107,7 @@ static void Tests(skiatest::Reporter* reporter) { // small storage { - intptr_t storage[8]; - SkWriter32 writer(100, storage, sizeof(storage)); + SkSWriter32<8 * sizeof(intptr_t)> writer(100); test1(reporter, &writer); writer.reset(); // should just rewind our storage test2(reporter, &writer); @@ -88,12 +115,13 @@ static void Tests(skiatest::Reporter* reporter) { // large storage { - intptr_t storage[1024]; - SkWriter32 writer(100, storage, sizeof(storage)); + SkSWriter32<1024 * sizeof(intptr_t)> writer(100); test1(reporter, &writer); writer.reset(); // should just rewind our storage test2(reporter, &writer); } + + test_ptr(reporter); } #include "TestClassDef.h" |