| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkDataTable.h" | 9 #include "SkDataTable.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "Test.h" | 14 #include "Test.h" |
| 15 | 15 |
| 16 static void test_is_equal(skiatest::Reporter* reporter, | 16 static void test_is_equal(skiatest::Reporter* reporter, |
| 17 const SkDataTable* a, const SkDataTable* b) { | 17 const SkDataTable* a, const SkDataTable* b) { |
| 18 REPORTER_ASSERT(reporter, a->count() == b->count()); | 18 REPORTER_ASSERT(reporter, a->count() == b->count()); |
| 19 for (int i = 0; i < a->count(); ++i) { | 19 for (int i = 0; i < a->count(); ++i) { |
| 20 size_t sizea, sizeb; | 20 size_t sizea, sizeb; |
| 21 const void* mema = a->at(i, &sizea); | 21 const void* mema = a->at(i, &sizea); |
| 22 const void* memb = b->at(i, &sizeb); | 22 const void* memb = b->at(i, &sizeb); |
| 23 REPORTER_ASSERT(reporter, sizea == sizeb); | 23 REPORTER_ASSERT(reporter, sizea == sizeb); |
| 24 REPORTER_ASSERT(reporter, !memcmp(mema, memb, sizea)); | 24 REPORTER_ASSERT(reporter, !memcmp(mema, memb, sizea)); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 static void test_datatable_is_empty(skiatest::Reporter* reporter, | 28 static void test_datatable_is_empty(skiatest::Reporter* reporter, SkDataTable* t
able) { |
| 29 SkDataTable* table) { | |
| 30 REPORTER_ASSERT(reporter, table->isEmpty()); | 29 REPORTER_ASSERT(reporter, table->isEmpty()); |
| 31 REPORTER_ASSERT(reporter, 0 == table->count()); | 30 REPORTER_ASSERT(reporter, 0 == table->count()); |
| 32 } | 31 } |
| 33 | 32 |
| 34 static void test_emptytable(skiatest::Reporter* reporter) { | 33 static void test_emptytable(skiatest::Reporter* reporter) { |
| 35 SkAutoTUnref<SkDataTable> table0(SkDataTable::NewEmpty()); | 34 sk_sp<SkDataTable> table0(SkDataTable::MakeEmpty()); |
| 36 SkAutoTUnref<SkDataTable> table1(SkDataTable::NewCopyArrays(nullptr, nullptr
, 0)); | 35 sk_sp<SkDataTable> table1(SkDataTable::MakeCopyArrays(nullptr, nullptr, 0)); |
| 37 SkAutoTUnref<SkDataTable> table2(SkDataTable::NewCopyArray(nullptr, 0, 0)); | 36 sk_sp<SkDataTable> table2(SkDataTable::MakeCopyArray(nullptr, 0, 0)); |
| 38 SkAutoTUnref<SkDataTable> table3(SkDataTable::NewArrayProc(nullptr, 0, 0, | 37 sk_sp<SkDataTable> table3(SkDataTable::MakeArrayProc(nullptr, 0, 0, nullptr,
nullptr)); |
| 39 nullptr, nullptr)
); | |
| 40 | 38 |
| 41 test_datatable_is_empty(reporter, table0); | 39 test_datatable_is_empty(reporter, table0.get()); |
| 42 test_datatable_is_empty(reporter, table1); | 40 test_datatable_is_empty(reporter, table1.get()); |
| 43 test_datatable_is_empty(reporter, table2); | 41 test_datatable_is_empty(reporter, table2.get()); |
| 44 test_datatable_is_empty(reporter, table3); | 42 test_datatable_is_empty(reporter, table3.get()); |
| 45 | 43 |
| 46 test_is_equal(reporter, table0, table1); | 44 test_is_equal(reporter, table0.get(), table1.get()); |
| 47 test_is_equal(reporter, table0, table2); | 45 test_is_equal(reporter, table0.get(), table2.get()); |
| 48 test_is_equal(reporter, table0, table3); | 46 test_is_equal(reporter, table0.get(), table3.get()); |
| 49 } | 47 } |
| 50 | 48 |
| 51 static void test_simpletable(skiatest::Reporter* reporter) { | 49 static void test_simpletable(skiatest::Reporter* reporter) { |
| 52 const int idata[] = { 1, 4, 9, 16, 25, 63 }; | 50 const int idata[] = { 1, 4, 9, 16, 25, 63 }; |
| 53 int icount = SK_ARRAY_COUNT(idata); | 51 int icount = SK_ARRAY_COUNT(idata); |
| 54 SkAutoTUnref<SkDataTable> itable(SkDataTable::NewCopyArray(idata, | 52 sk_sp<SkDataTable> itable(SkDataTable::MakeCopyArray(idata, sizeof(idata[0])
, icount)); |
| 55 sizeof(idata[0]), | |
| 56 icount)); | |
| 57 REPORTER_ASSERT(reporter, itable->count() == icount); | 53 REPORTER_ASSERT(reporter, itable->count() == icount); |
| 58 for (int i = 0; i < icount; ++i) { | 54 for (int i = 0; i < icount; ++i) { |
| 59 size_t size; | 55 size_t size; |
| 60 REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i)); | 56 REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i)); |
| 61 REPORTER_ASSERT(reporter, *itable->atT<int>(i, &size) == idata[i]); | 57 REPORTER_ASSERT(reporter, *itable->atT<int>(i, &size) == idata[i]); |
| 62 REPORTER_ASSERT(reporter, sizeof(int) == size); | 58 REPORTER_ASSERT(reporter, sizeof(int) == size); |
| 63 } | 59 } |
| 64 } | 60 } |
| 65 | 61 |
| 66 static void test_vartable(skiatest::Reporter* reporter) { | 62 static void test_vartable(skiatest::Reporter* reporter) { |
| 67 const char* str[] = { | 63 const char* str[] = { |
| 68 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" | 64 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" |
| 69 }; | 65 }; |
| 70 int count = SK_ARRAY_COUNT(str); | 66 int count = SK_ARRAY_COUNT(str); |
| 71 size_t sizes[SK_ARRAY_COUNT(str)]; | 67 size_t sizes[SK_ARRAY_COUNT(str)]; |
| 72 for (int i = 0; i < count; ++i) { | 68 for (int i = 0; i < count; ++i) { |
| 73 sizes[i] = strlen(str[i]) + 1; | 69 sizes[i] = strlen(str[i]) + 1; |
| 74 } | 70 } |
| 75 | 71 |
| 76 SkAutoTUnref<SkDataTable> table(SkDataTable::NewCopyArrays( | 72 sk_sp<SkDataTable> table(SkDataTable::MakeCopyArrays((const void*const*)str,
sizes, count)); |
| 77 (const void*const*)str, sizes, count)); | |
| 78 | 73 |
| 79 REPORTER_ASSERT(reporter, table->count() == count); | 74 REPORTER_ASSERT(reporter, table->count() == count); |
| 80 for (int i = 0; i < count; ++i) { | 75 for (int i = 0; i < count; ++i) { |
| 81 size_t size; | 76 size_t size; |
| 82 REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]); | 77 REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]); |
| 83 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size), | 78 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size), |
| 84 str[i])); | 79 str[i])); |
| 85 REPORTER_ASSERT(reporter, size == sizes[i]); | 80 REPORTER_ASSERT(reporter, size == sizes[i]); |
| 86 | 81 |
| 87 const char* s = table->atStr(i); | 82 const char* s = table->atStr(i); |
| 88 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); | 83 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); |
| 89 } | 84 } |
| 90 } | 85 } |
| 91 | 86 |
| 92 static void test_tablebuilder(skiatest::Reporter* reporter) { | 87 static void test_tablebuilder(skiatest::Reporter* reporter) { |
| 93 const char* str[] = { | 88 const char* str[] = { |
| 94 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" | 89 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" |
| 95 }; | 90 }; |
| 96 int count = SK_ARRAY_COUNT(str); | 91 int count = SK_ARRAY_COUNT(str); |
| 97 | 92 |
| 98 SkDataTableBuilder builder(16); | 93 SkDataTableBuilder builder(16); |
| 99 | 94 |
| 100 for (int i = 0; i < count; ++i) { | 95 for (int i = 0; i < count; ++i) { |
| 101 builder.append(str[i], strlen(str[i]) + 1); | 96 builder.append(str[i], strlen(str[i]) + 1); |
| 102 } | 97 } |
| 103 SkAutoTUnref<SkDataTable> table(builder.detachDataTable()); | 98 sk_sp<SkDataTable> table(builder.detachDataTable()); |
| 104 | 99 |
| 105 REPORTER_ASSERT(reporter, table->count() == count); | 100 REPORTER_ASSERT(reporter, table->count() == count); |
| 106 for (int i = 0; i < count; ++i) { | 101 for (int i = 0; i < count; ++i) { |
| 107 size_t size; | 102 size_t size; |
| 108 REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1); | 103 REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1); |
| 109 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size), | 104 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size), |
| 110 str[i])); | 105 str[i])); |
| 111 REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1); | 106 REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1); |
| 112 | 107 |
| 113 const char* s = table->atStr(i); | 108 const char* s = table->atStr(i); |
| 114 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); | 109 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); |
| 115 } | 110 } |
| 116 } | 111 } |
| 117 | 112 |
| 118 static void test_globaltable(skiatest::Reporter* reporter) { | 113 static void test_globaltable(skiatest::Reporter* reporter) { |
| 119 static const int gData[] = { | 114 static const int gData[] = { |
| 120 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 | 115 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 |
| 121 }; | 116 }; |
| 122 int count = SK_ARRAY_COUNT(gData); | 117 int count = SK_ARRAY_COUNT(gData); |
| 123 | 118 |
| 124 SkAutoTUnref<SkDataTable> table(SkDataTable::NewArrayProc(gData, | 119 sk_sp<SkDataTable> table( |
| 125 sizeof(gData[0]), count, nullptr, null
ptr)); | 120 SkDataTable::MakeArrayProc(gData, sizeof(gData[0]), count, nullptr, null
ptr)); |
| 126 | 121 |
| 127 REPORTER_ASSERT(reporter, table->count() == count); | 122 REPORTER_ASSERT(reporter, table->count() == count); |
| 128 for (int i = 0; i < count; ++i) { | 123 for (int i = 0; i < count; ++i) { |
| 129 size_t size; | 124 size_t size; |
| 130 REPORTER_ASSERT(reporter, table->atSize(i) == sizeof(int)); | 125 REPORTER_ASSERT(reporter, table->atSize(i) == sizeof(int)); |
| 131 REPORTER_ASSERT(reporter, *table->atT<const char>(i, &size) == i); | 126 REPORTER_ASSERT(reporter, *table->atT<const char>(i, &size) == i); |
| 132 REPORTER_ASSERT(reporter, sizeof(int) == size); | 127 REPORTER_ASSERT(reporter, sizeof(int) == size); |
| 133 } | 128 } |
| 134 } | 129 } |
| 135 | 130 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 366 } |
| 372 | 367 |
| 373 SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot()); | 368 SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot()); |
| 374 REPORTER_ASSERT(r, stream); | 369 REPORTER_ASSERT(r, stream); |
| 375 if (stream) { | 370 if (stream) { |
| 376 REPORTER_ASSERT(r, stream->hasLength()); | 371 REPORTER_ASSERT(r, stream->hasLength()); |
| 377 REPORTER_ASSERT(r, stream->getLength() == 0); | 372 REPORTER_ASSERT(r, stream->getLength() == 0); |
| 378 REPORTER_ASSERT(r, stream->skip(10) == 0); | 373 REPORTER_ASSERT(r, stream->skip(10) == 0); |
| 379 } | 374 } |
| 380 } | 375 } |
| OLD | NEW |