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.
|
|
|
|
*/
|
2013-12-12 21:11:12 +00:00
|
|
|
|
2011-06-24 13:07:31 +00:00
|
|
|
#include "SkData.h"
|
2013-04-19 20:16:01 +00:00
|
|
|
#include "SkDataTable.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkOSFile.h"
|
2014-01-30 18:58:24 +00:00
|
|
|
#include "SkReadBuffer.h"
|
|
|
|
#include "SkWriteBuffer.h"
|
2013-06-03 17:10:35 +00:00
|
|
|
#include "SkStream.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2012-07-11 17:24:49 +00:00
|
|
|
|
2013-04-21 01:37:46 +00:00
|
|
|
static void test_is_equal(skiatest::Reporter* reporter,
|
|
|
|
const SkDataTable* a, const SkDataTable* b) {
|
|
|
|
REPORTER_ASSERT(reporter, a->count() == b->count());
|
|
|
|
for (int i = 0; i < a->count(); ++i) {
|
|
|
|
size_t sizea, sizeb;
|
|
|
|
const void* mema = a->at(i, &sizea);
|
|
|
|
const void* memb = b->at(i, &sizeb);
|
|
|
|
REPORTER_ASSERT(reporter, sizea == sizeb);
|
|
|
|
REPORTER_ASSERT(reporter, !memcmp(mema, memb, sizea));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 13:51:50 +00:00
|
|
|
static void test_datatable_is_empty(skiatest::Reporter* reporter, SkDataTable* table) {
|
2013-04-21 01:37:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, table->isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == table->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_emptytable(skiatest::Reporter* reporter) {
|
2016-08-05 13:51:50 +00:00
|
|
|
sk_sp<SkDataTable> table0(SkDataTable::MakeEmpty());
|
|
|
|
sk_sp<SkDataTable> table1(SkDataTable::MakeCopyArrays(nullptr, nullptr, 0));
|
|
|
|
sk_sp<SkDataTable> table2(SkDataTable::MakeCopyArray(nullptr, 0, 0));
|
|
|
|
sk_sp<SkDataTable> table3(SkDataTable::MakeArrayProc(nullptr, 0, 0, nullptr, nullptr));
|
|
|
|
|
|
|
|
test_datatable_is_empty(reporter, table0.get());
|
|
|
|
test_datatable_is_empty(reporter, table1.get());
|
|
|
|
test_datatable_is_empty(reporter, table2.get());
|
|
|
|
test_datatable_is_empty(reporter, table3.get());
|
|
|
|
|
|
|
|
test_is_equal(reporter, table0.get(), table1.get());
|
|
|
|
test_is_equal(reporter, table0.get(), table2.get());
|
|
|
|
test_is_equal(reporter, table0.get(), table3.get());
|
2013-04-21 01:37:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:16:01 +00:00
|
|
|
static void test_simpletable(skiatest::Reporter* reporter) {
|
|
|
|
const int idata[] = { 1, 4, 9, 16, 25, 63 };
|
|
|
|
int icount = SK_ARRAY_COUNT(idata);
|
2016-08-05 13:51:50 +00:00
|
|
|
sk_sp<SkDataTable> itable(SkDataTable::MakeCopyArray(idata, sizeof(idata[0]), icount));
|
2013-04-19 20:16:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, itable->count() == icount);
|
|
|
|
for (int i = 0; i < icount; ++i) {
|
|
|
|
size_t size;
|
|
|
|
REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i));
|
2013-04-21 01:37:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, *itable->atT<int>(i, &size) == idata[i]);
|
2013-04-19 20:16:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, sizeof(int) == size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_vartable(skiatest::Reporter* reporter) {
|
|
|
|
const char* str[] = {
|
|
|
|
"", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
|
|
|
|
};
|
|
|
|
int count = SK_ARRAY_COUNT(str);
|
|
|
|
size_t sizes[SK_ARRAY_COUNT(str)];
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
sizes[i] = strlen(str[i]) + 1;
|
|
|
|
}
|
2013-04-20 07:01:07 +00:00
|
|
|
|
2016-08-05 13:51:50 +00:00
|
|
|
sk_sp<SkDataTable> table(SkDataTable::MakeCopyArrays((const void*const*)str, sizes, count));
|
2013-04-20 07:01:07 +00:00
|
|
|
|
2013-04-19 20:16:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, table->count() == count);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
size_t size;
|
|
|
|
REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]);
|
2013-04-21 01:37:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size),
|
2013-04-19 20:16:01 +00:00
|
|
|
str[i]));
|
|
|
|
REPORTER_ASSERT(reporter, size == sizes[i]);
|
2013-04-20 07:01:07 +00:00
|
|
|
|
2013-04-19 20:16:01 +00:00
|
|
|
const char* s = table->atStr(i);
|
|
|
|
REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_tablebuilder(skiatest::Reporter* reporter) {
|
|
|
|
const char* str[] = {
|
|
|
|
"", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
|
|
|
|
};
|
|
|
|
int count = SK_ARRAY_COUNT(str);
|
|
|
|
|
|
|
|
SkDataTableBuilder builder(16);
|
2013-04-20 07:01:07 +00:00
|
|
|
|
2013-04-19 20:16:01 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
builder.append(str[i], strlen(str[i]) + 1);
|
|
|
|
}
|
2016-08-05 13:51:50 +00:00
|
|
|
sk_sp<SkDataTable> table(builder.detachDataTable());
|
2013-04-20 07:01:07 +00:00
|
|
|
|
2013-04-19 20:16:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, table->count() == count);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
size_t size;
|
|
|
|
REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1);
|
2013-04-21 01:37:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size),
|
2013-04-19 20:16:01 +00:00
|
|
|
str[i]));
|
|
|
|
REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1);
|
2013-04-20 07:01:07 +00:00
|
|
|
|
2013-04-19 20:16:01 +00:00
|
|
|
const char* s = table->atStr(i);
|
|
|
|
REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
|
|
|
|
}
|
2013-04-21 01:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_globaltable(skiatest::Reporter* reporter) {
|
|
|
|
static const int gData[] = {
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
|
|
|
};
|
|
|
|
int count = SK_ARRAY_COUNT(gData);
|
|
|
|
|
2016-08-05 13:51:50 +00:00
|
|
|
sk_sp<SkDataTable> table(
|
|
|
|
SkDataTable::MakeArrayProc(gData, sizeof(gData[0]), count, nullptr, nullptr));
|
2013-04-22 12:45:30 +00:00
|
|
|
|
2013-04-21 01:37:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, table->count() == count);
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
size_t size;
|
|
|
|
REPORTER_ASSERT(reporter, table->atSize(i) == sizeof(int));
|
|
|
|
REPORTER_ASSERT(reporter, *table->atT<const char>(i, &size) == i);
|
|
|
|
REPORTER_ASSERT(reporter, sizeof(int) == size);
|
|
|
|
}
|
2013-04-19 20:16:01 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(DataTable, reporter) {
|
2013-04-21 01:37:46 +00:00
|
|
|
test_emptytable(reporter);
|
2013-04-19 20:16:01 +00:00
|
|
|
test_simpletable(reporter);
|
|
|
|
test_vartable(reporter);
|
|
|
|
test_tablebuilder(reporter);
|
2013-04-21 01:37:46 +00:00
|
|
|
test_globaltable(reporter);
|
2013-04-19 20:16:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-14 19:22:21 +00:00
|
|
|
static void* gGlobal;
|
|
|
|
|
2015-06-17 16:58:24 +00:00
|
|
|
static void delete_int_proc(const void* ptr, void* context) {
|
2011-06-14 19:22:21 +00:00
|
|
|
int* data = (int*)ptr;
|
|
|
|
SkASSERT(context == gGlobal);
|
|
|
|
delete[] data;
|
|
|
|
}
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
static void assert_len(skiatest::Reporter* reporter, const sk_sp<SkData>& ref, size_t len) {
|
2011-06-14 19:22:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, ref->size() == len);
|
|
|
|
}
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
static void assert_data(skiatest::Reporter* reporter, const sk_sp<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-28 15:40:09 +00:00
|
|
|
static void test_cstring(skiatest::Reporter* reporter) {
|
|
|
|
const char str[] = "Hello world";
|
|
|
|
size_t len = strlen(str);
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> r0(SkData::MakeWithCopy(str, len + 1));
|
|
|
|
sk_sp<SkData> r1(SkData::MakeWithCString(str));
|
2012-06-28 15:40:09 +00:00
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
REPORTER_ASSERT(reporter, r0->equals(r1.get()));
|
2012-06-28 15:40:09 +00:00
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> r2(SkData::MakeWithCString(nullptr));
|
2012-07-02 20:29:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == r2->size());
|
|
|
|
REPORTER_ASSERT(reporter, 0 == *r2->bytes());
|
2012-06-28 15:40:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 17:10:35 +00:00
|
|
|
static void test_files(skiatest::Reporter* reporter) {
|
2015-01-20 17:30:20 +00:00
|
|
|
SkString tmpDir = skiatest::GetTmpDir();
|
2013-06-07 14:30:36 +00:00
|
|
|
if (tmpDir.isEmpty()) {
|
2013-06-03 17:10:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-06-04 07:00:53 +00:00
|
|
|
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString path = SkOSPath::Join(tmpDir.c_str(), "data_test");
|
2013-06-04 07:00:53 +00:00
|
|
|
|
2013-06-03 17:10:35 +00:00
|
|
|
const char s[] = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
{
|
|
|
|
SkFILEWStream writer(path.c_str());
|
|
|
|
if (!writer.isValid()) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str());
|
2013-06-03 17:10:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
writer.write(s, 26);
|
|
|
|
}
|
|
|
|
|
2015-11-20 21:47:49 +00:00
|
|
|
FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag);
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> r1(SkData::MakeFromFILE(file));
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, r1.get() != nullptr);
|
2013-06-03 17:10:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, r1->size() == 26);
|
|
|
|
REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r1->data()), s, 26) == 0);
|
2013-06-04 07:00:53 +00:00
|
|
|
|
2013-06-03 17:10:35 +00:00
|
|
|
int fd = sk_fileno(file);
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> r2(SkData::MakeFromFD(fd));
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, r2.get() != nullptr);
|
2013-06-03 17:10:35 +00:00
|
|
|
REPORTER_ASSERT(reporter, r2->size() == 26);
|
|
|
|
REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r2->data()), s, 26) == 0);
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Data, 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;
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> r0(SkData::MakeEmpty());
|
|
|
|
sk_sp<SkData> r1(SkData::MakeWithCopy(str, strlen(str)));
|
|
|
|
sk_sp<SkData> r2(SkData::MakeWithProc(new int[N], N*sizeof(int), delete_int_proc, gGlobal));
|
|
|
|
sk_sp<SkData> r3(SkData::MakeSubset(r1.get(), 7, 6));
|
2011-06-14 19:22:21 +00:00
|
|
|
|
|
|
|
assert_len(reporter, r0, 0);
|
|
|
|
assert_len(reporter, r1, strlen(str));
|
|
|
|
assert_len(reporter, r2, N * sizeof(int));
|
|
|
|
assert_len(reporter, r3, 6);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-06-14 19:22:21 +00:00
|
|
|
assert_data(reporter, r1, str, strlen(str));
|
|
|
|
assert_data(reporter, r3, "people", 6);
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> tmp(SkData::MakeSubset(r1.get(), strlen(str), 10));
|
2011-06-14 19:22:21 +00:00
|
|
|
assert_len(reporter, tmp, 0);
|
2016-08-02 21:40:46 +00:00
|
|
|
tmp = SkData::MakeSubset(r1.get(), 0, 0);
|
2011-06-14 19:22:21 +00:00
|
|
|
assert_len(reporter, tmp, 0);
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-06-28 15:40:09 +00:00
|
|
|
test_cstring(reporter);
|
2013-06-03 17:10:35 +00:00
|
|
|
test_files(reporter);
|
2011-06-14 19:22:21 +00:00
|
|
|
}
|
2015-04-29 00:50:31 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "SkRWBuffer.h"
|
|
|
|
|
|
|
|
const char gABC[] = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
|
|
static void check_abcs(skiatest::Reporter* reporter, const char buffer[], size_t size) {
|
|
|
|
REPORTER_ASSERT(reporter, size % 26 == 0);
|
|
|
|
for (size_t offset = 0; offset < size; offset += 26) {
|
|
|
|
REPORTER_ASSERT(reporter, !memcmp(&buffer[offset], gABC, 26));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:59:01 +00:00
|
|
|
// stream should contain an integral number of copies of gABC.
|
2015-04-29 00:50:31 +00:00
|
|
|
static void check_alphabet_stream(skiatest::Reporter* reporter, SkStream* stream) {
|
|
|
|
REPORTER_ASSERT(reporter, stream->hasLength());
|
|
|
|
size_t size = stream->getLength();
|
|
|
|
REPORTER_ASSERT(reporter, size % 26 == 0);
|
|
|
|
|
|
|
|
SkAutoTMalloc<char> storage(size);
|
|
|
|
char* array = storage.get();
|
|
|
|
size_t bytesRead = stream->read(array, size);
|
|
|
|
REPORTER_ASSERT(reporter, bytesRead == size);
|
|
|
|
check_abcs(reporter, array, size);
|
|
|
|
|
|
|
|
// try checking backwards
|
|
|
|
for (size_t offset = size; offset > 0; offset -= 26) {
|
|
|
|
REPORTER_ASSERT(reporter, stream->seek(offset - 26));
|
|
|
|
REPORTER_ASSERT(reporter, stream->getPosition() == offset - 26);
|
|
|
|
REPORTER_ASSERT(reporter, stream->read(array, 26) == 26);
|
|
|
|
check_abcs(reporter, array, 26);
|
|
|
|
REPORTER_ASSERT(reporter, stream->getPosition() == offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// reader should contains an integral number of copies of gABC.
|
|
|
|
static void check_alphabet_buffer(skiatest::Reporter* reporter, const SkROBuffer* reader) {
|
|
|
|
size_t size = reader->size();
|
|
|
|
REPORTER_ASSERT(reporter, size % 26 == 0);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-04-29 00:50:31 +00:00
|
|
|
SkAutoTMalloc<char> storage(size);
|
|
|
|
SkROBuffer::Iter iter(reader);
|
|
|
|
size_t offset = 0;
|
|
|
|
do {
|
|
|
|
SkASSERT(offset + iter.size() <= size);
|
|
|
|
memcpy(storage.get() + offset, iter.data(), iter.size());
|
|
|
|
offset += iter.size();
|
|
|
|
} while (iter.next());
|
|
|
|
REPORTER_ASSERT(reporter, offset == size);
|
|
|
|
check_abcs(reporter, storage.get(), size);
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:59:01 +00:00
|
|
|
#include "SkTaskGroup.h"
|
|
|
|
|
2015-04-29 00:50:31 +00:00
|
|
|
DEF_TEST(RWBuffer, reporter) {
|
|
|
|
// Knowing that the default capacity is 4096, choose N large enough so we force it to use
|
|
|
|
// multiple buffers internally.
|
|
|
|
const int N = 1000;
|
|
|
|
SkROBuffer* readers[N];
|
|
|
|
SkStream* streams[N];
|
|
|
|
|
|
|
|
{
|
|
|
|
SkRWBuffer buffer;
|
|
|
|
for (int i = 0; i < N; ++i) {
|
2016-04-08 19:47:14 +00:00
|
|
|
buffer.append(gABC, 26);
|
2015-04-29 00:50:31 +00:00
|
|
|
readers[i] = buffer.newRBufferSnapshot();
|
|
|
|
streams[i] = buffer.newStreamSnapshot();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, N*26 == buffer.size());
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:59:01 +00:00
|
|
|
// Verify that although the SkRWBuffer's destructor has run, the readers are still valid.
|
2015-04-29 00:50:31 +00:00
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
REPORTER_ASSERT(reporter, (i + 1) * 26U == readers[i]->size());
|
|
|
|
check_alphabet_buffer(reporter, readers[i]);
|
|
|
|
check_alphabet_stream(reporter, streams[i]);
|
|
|
|
readers[i]->unref();
|
2015-08-26 20:07:48 +00:00
|
|
|
delete streams[i];
|
2015-04-29 00:50:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-11 14:38:00 +00:00
|
|
|
|
2016-04-22 13:59:01 +00:00
|
|
|
DEF_TEST(RWBuffer_threaded, reporter) {
|
|
|
|
// Knowing that the default capacity is 4096, choose N large enough so we force it to use
|
|
|
|
// multiple buffers internally.
|
|
|
|
const int N = 1000;
|
|
|
|
SkTaskGroup tasks;
|
|
|
|
SkRWBuffer buffer;
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
buffer.append(gABC, 26);
|
|
|
|
sk_sp<SkROBuffer> reader = sk_sp<SkROBuffer>(buffer.newRBufferSnapshot());
|
|
|
|
SkStream* stream = buffer.newStreamSnapshot();
|
|
|
|
REPORTER_ASSERT(reporter, reader->size() == buffer.size());
|
|
|
|
REPORTER_ASSERT(reporter, stream->getLength() == buffer.size());
|
|
|
|
|
|
|
|
// reader's copy constructor will ref the SkROBuffer, which will be unreffed
|
|
|
|
// when the task ends.
|
|
|
|
// Ownership of stream is passed to the task, which will delete it.
|
|
|
|
tasks.add([reporter, i, reader, stream] {
|
|
|
|
REPORTER_ASSERT(reporter, (i + 1) * 26U == reader->size());
|
|
|
|
REPORTER_ASSERT(reporter, stream->getLength() == reader->size());
|
|
|
|
check_alphabet_buffer(reporter, reader.get());
|
|
|
|
check_alphabet_stream(reporter, stream);
|
|
|
|
REPORTER_ASSERT(reporter, stream->rewind());
|
|
|
|
delete stream;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, N*26 == buffer.size());
|
|
|
|
tasks.wait();
|
|
|
|
}
|
|
|
|
|
2016-01-11 14:38:00 +00:00
|
|
|
// Tests that it is safe to call SkROBuffer::Iter::size() when exhausted.
|
|
|
|
DEF_TEST(RWBuffer_size, r) {
|
|
|
|
SkRWBuffer buffer;
|
|
|
|
buffer.append(gABC, 26);
|
|
|
|
|
|
|
|
SkAutoTUnref<SkROBuffer> roBuffer(buffer.newRBufferSnapshot());
|
|
|
|
SkROBuffer::Iter iter(roBuffer);
|
|
|
|
REPORTER_ASSERT(r, iter.data());
|
|
|
|
REPORTER_ASSERT(r, iter.size() == 26);
|
|
|
|
|
|
|
|
// There is only one block in this buffer.
|
|
|
|
REPORTER_ASSERT(r, !iter.next());
|
|
|
|
REPORTER_ASSERT(r, 0 == iter.size());
|
|
|
|
}
|
2016-02-16 14:59:18 +00:00
|
|
|
|
2016-04-22 13:59:01 +00:00
|
|
|
// Tests that operations (including the destructor) are safe on an SkRWBuffer
|
|
|
|
// without any data appended.
|
2016-02-16 14:59:18 +00:00
|
|
|
DEF_TEST(RWBuffer_noAppend, r) {
|
|
|
|
SkRWBuffer buffer;
|
|
|
|
REPORTER_ASSERT(r, 0 == buffer.size());
|
2016-04-22 13:59:01 +00:00
|
|
|
|
|
|
|
sk_sp<SkROBuffer> roBuffer = sk_sp<SkROBuffer>(buffer.newRBufferSnapshot());
|
|
|
|
REPORTER_ASSERT(r, roBuffer);
|
|
|
|
if (roBuffer) {
|
|
|
|
REPORTER_ASSERT(r, roBuffer->size() == 0);
|
|
|
|
SkROBuffer::Iter iter(roBuffer.get());
|
|
|
|
REPORTER_ASSERT(r, iter.size() == 0);
|
|
|
|
REPORTER_ASSERT(r, !iter.data());
|
|
|
|
REPORTER_ASSERT(r, !iter.next());
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot());
|
|
|
|
REPORTER_ASSERT(r, stream);
|
|
|
|
if (stream) {
|
|
|
|
REPORTER_ASSERT(r, stream->hasLength());
|
|
|
|
REPORTER_ASSERT(r, stream->getLength() == 0);
|
|
|
|
REPORTER_ASSERT(r, stream->skip(10) == 0);
|
|
|
|
}
|
2016-02-16 14:59:18 +00:00
|
|
|
}
|