From dbc936dff3357f74fc60e124d912a2179b909b0d Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 28 Jun 2012 15:40:09 +0000 Subject: add SkData::NewFromCString() git-svn-id: http://skia.googlecode.com/svn/trunk@4383 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/DataRefTest.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'tests/DataRefTest.cpp') diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp index 56c5d11725..0b72c4a93a 100644 --- a/tests/DataRefTest.cpp +++ b/tests/DataRefTest.cpp @@ -26,21 +26,29 @@ static void assert_data(skiatest::Reporter* reporter, SkData* ref, REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len)); } +static void test_cstring(skiatest::Reporter* reporter) { + const char str[] = "Hello world"; + size_t len = strlen(str); + + SkAutoTUnref r0(SkData::NewWithCopy(str, len)); + SkAutoTUnref r1(SkData::NewWithCString(str)); + + REPORTER_ASSERT(reporter, r0->equals(r1)); + + SkAutoTUnref r2(SkData::NewWithCString(NULL)); + REPORTER_ASSERT(reporter, r2->isEmpty()); +} + static void TestDataRef(skiatest::Reporter* reporter) { const char* str = "We the people, in order to form a more perfect union."; const int N = 10; - SkData* r0 = SkData::NewEmpty(); - SkData* r1 = SkData::NewWithCopy(str, strlen(str)); - SkData* r2 = SkData::NewWithProc(new int[N], N*sizeof(int), - delete_int_proc, gGlobal); - SkData* r3 = SkData::NewSubset(r1, 7, 6); + SkAutoTUnref r0(SkData::NewEmpty()); + SkAutoTUnref r1(SkData::NewWithCopy(str, strlen(str))); + SkAutoTUnref r2(SkData::NewWithProc(new int[N], N*sizeof(int), + delete_int_proc, gGlobal)); + SkAutoTUnref r3(SkData::NewSubset(r1, 7, 6)); - SkAutoUnref aur0(r0); - SkAutoUnref aur1(r1); - SkAutoUnref aur2(r2); - SkAutoUnref aur3(r3); - assert_len(reporter, r0, 0); assert_len(reporter, r1, strlen(str)); assert_len(reporter, r2, N * sizeof(int)); @@ -55,6 +63,8 @@ static void TestDataRef(skiatest::Reporter* reporter) { tmp = SkData::NewSubset(r1, 0, 0); assert_len(reporter, tmp, 0); tmp->unref(); + + test_cstring(reporter); } #include "TestClassDef.h" -- cgit v1.2.3