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

Unified Diff: tests/Writer32Test.cpp

Issue 22359003: allow NULL in writeString/readString (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: style nit Created 7 years, 4 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/SkWriter32.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/Writer32Test.cpp
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index e5b93634ac743447b22fdb7f155573809d5a49d6..6ecfcf3edadd87c32b0edcce0ce128de0c1756e7 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -21,6 +21,34 @@ static void check_contents(skiatest::Reporter* reporter, const SkWriter32& write
REPORTER_ASSERT(reporter, !memcmp(storage.get(), expected, size));
}
+static void test_string_null(skiatest::Reporter* reporter) {
+ uint8_t storage[8];
+ SkWriter32 writer(0, storage, sizeof(storage));
+ SkReader32 reader(storage, sizeof(storage));
+
+ const char* str;
+ size_t len;
+
+ // Can we write NULL?
+ writer.writeString(NULL);
+ const int32_t null[] = { 0xFFFF };
+ check_contents(reporter, writer, null, sizeof(null));
+ str = reader.readString(&len);
+ REPORTER_ASSERT(reporter, NULL == str);
+ REPORTER_ASSERT(reporter, 0 == len);
+
+ writer.reset(storage, sizeof(storage));
+ reader.rewind();
+
+ // Is NULL distinct from ""?
+ writer.writeString("");
+ const int32_t empty[] = { 0x0, 0x0 };
+ check_contents(reporter, writer, empty, sizeof(empty));
+ str = reader.readString(&len);
+ REPORTER_ASSERT(reporter, 0 == strcmp("", str));
+ REPORTER_ASSERT(reporter, 0 == len);
+}
+
static void test_rewind(skiatest::Reporter* reporter) {
SkSWriter32<32> writer(32);
int32_t array[3] = { 1, 2, 4 };
@@ -228,6 +256,7 @@ static void Tests(skiatest::Reporter* reporter) {
testWritePad(reporter, &writer);
}
+ test_string_null(reporter);
test_ptr(reporter);
test_rewind(reporter);
}
« no previous file with comments | « src/core/SkWriter32.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698