aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-30 14:03:21 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-30 14:03:21 +0000
commit1cf58d03a87e1ff17cd47e9de3da4c678456618d (patch)
tree2db1871402b6ea330351de7b04da11f30d6047ae /tests
parenta9b0623eac4a473517c15418dbdc1e331ee752d2 (diff)
add SkWriter32::rewindToOffset() -- used for peephole edits in picture recording
git-svn-id: http://skia.googlecode.com/svn/trunk@5345 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/Writer32Test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index f2dcf90ea7..fdc074547d 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -13,6 +13,32 @@
#include "SkWriter32.h"
#include "Test.h"
+static void check_contents(skiatest::Reporter* reporter, const SkWriter32& writer,
+ const void* expected, size_t size) {
+ SkAutoSMalloc<256> storage(size);
+ REPORTER_ASSERT(reporter, writer.bytesWritten() == size);
+ writer.flatten(storage.get());
+ REPORTER_ASSERT(reporter, !memcmp(storage.get(), expected, size));
+}
+
+static void test_rewind(skiatest::Reporter* reporter) {
+ SkSWriter32<32> writer(32);
+ int32_t array[3] = { 1, 2, 4 };
+
+ REPORTER_ASSERT(reporter, 0 == writer.bytesWritten());
+ for (size_t i = 0; i < SK_ARRAY_COUNT(array); ++i) {
+ writer.writeInt(array[i]);
+ }
+ check_contents(reporter, writer, array, sizeof(array));
+
+ writer.rewindToOffset(2*sizeof(int32_t));
+ REPORTER_ASSERT(reporter, sizeof(array) - 4 == writer.bytesWritten());
+ writer.writeInt(3);
+ REPORTER_ASSERT(reporter, sizeof(array) == writer.bytesWritten());
+ array[2] = 3;
+ check_contents(reporter, writer, array, sizeof(array));
+}
+
static void test_ptr(skiatest::Reporter* reporter) {
SkSWriter32<32> writer(32);
@@ -182,6 +208,7 @@ static void Tests(skiatest::Reporter* reporter) {
}
test_ptr(reporter);
+ test_rewind(reporter);
}
#include "TestClassDef.h"