2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-06-14 19:22:21 +00:00
|
|
|
#include "Test.h"
|
2011-06-24 13:07:31 +00:00
|
|
|
#include "SkData.h"
|
2011-06-14 19:22:21 +00:00
|
|
|
|
|
|
|
static void* gGlobal;
|
|
|
|
|
|
|
|
static void delete_int_proc(const void* ptr, size_t len, void* context) {
|
|
|
|
int* data = (int*)ptr;
|
|
|
|
SkASSERT(context == gGlobal);
|
|
|
|
delete[] data;
|
|
|
|
}
|
|
|
|
|
2011-06-24 13:07:31 +00:00
|
|
|
static void assert_len(skiatest::Reporter* reporter, SkData* ref, size_t len) {
|
2011-06-14 19:22:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, ref->size() == len);
|
|
|
|
}
|
|
|
|
|
2011-06-24 13:07:31 +00:00
|
|
|
static void assert_data(skiatest::Reporter* reporter, SkData* ref,
|
2011-06-14 19:22:21 +00:00
|
|
|
const void* data, size_t len) {
|
|
|
|
REPORTER_ASSERT(reporter, ref->size() == len);
|
|
|
|
REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len));
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
static void TestDataRef(skiatest::Reporter* reporter) {
|
2011-06-14 19:22:21 +00:00
|
|
|
const char* str = "We the people, in order to form a more perfect union.";
|
|
|
|
const int N = 10;
|
|
|
|
|
2011-06-24 13:07:31 +00:00
|
|
|
SkData* r0 = SkData::NewEmpty();
|
|
|
|
SkData* r1 = SkData::NewWithCopy(str, strlen(str));
|
|
|
|
SkData* r2 = SkData::NewWithProc(new int[N], N*sizeof(int),
|
2011-06-14 19:22:21 +00:00
|
|
|
delete_int_proc, gGlobal);
|
2011-06-24 13:07:31 +00:00
|
|
|
SkData* r3 = SkData::NewSubset(r1, 7, 6);
|
2011-06-14 19:22:21 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
assert_len(reporter, r3, 6);
|
|
|
|
|
|
|
|
assert_data(reporter, r1, str, strlen(str));
|
|
|
|
assert_data(reporter, r3, "people", 6);
|
|
|
|
|
2011-06-24 13:07:31 +00:00
|
|
|
SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
|
2011-06-14 19:22:21 +00:00
|
|
|
assert_len(reporter, tmp, 0);
|
|
|
|
tmp->unref();
|
2011-06-24 13:07:31 +00:00
|
|
|
tmp = SkData::NewSubset(r1, 0, 0);
|
2011-06-14 19:22:21 +00:00
|
|
|
assert_len(reporter, tmp, 0);
|
|
|
|
tmp->unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("DataRef", DataRefTestClass, TestDataRef)
|