OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkMallocPixelRef.h" | 9 #include "SkMallocPixelRef.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 static void delete_uint8_proc(void* ptr, void*) { | 12 static void delete_uint8_proc(void* ptr, void*) { |
13 delete[] static_cast<uint8_t*>(ptr); | 13 delete[] static_cast<uint8_t*>(ptr); |
14 } | 14 } |
15 | 15 |
16 static void set_to_one_proc(void*, void* context) { | 16 static void set_to_one_proc(void*, void* context) { |
17 *(static_cast<int*>(context)) = 1; | 17 *(static_cast<int*>(context)) = 1; |
18 } | 18 } |
19 | 19 |
20 /** | 20 /** |
21 * This test contains basic sanity checks concerning SkMallocPixelRef. | 21 * This test contains basic sanity checks concerning SkMallocPixelRef. |
22 */ | 22 */ |
23 DEF_TEST(MallocPixelRef, reporter) { | 23 DEF_TEST(MallocPixelRef, reporter) { |
24 REPORTER_ASSERT(reporter, true); | 24 REPORTER_ASSERT(reporter, true); |
25 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13); | 25 SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13); |
26 { | 26 { |
27 SkAutoTUnref<SkMallocPixelRef> pr( | 27 SkAutoTUnref<SkMallocPixelRef> pr( |
28 SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, NULL)); | 28 SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, nullptr)
); |
29 // rowbytes too small. | 29 // rowbytes too small. |
30 REPORTER_ASSERT(reporter, NULL == pr.get()); | 30 REPORTER_ASSERT(reporter, nullptr == pr.get()); |
31 } | 31 } |
32 { | 32 { |
33 size_t rowBytes = info.minRowBytes() - 1; | 33 size_t rowBytes = info.minRowBytes() - 1; |
34 size_t size = info.getSafeSize(rowBytes); | 34 size_t size = info.getSafeSize(rowBytes); |
35 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 35 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
36 SkAutoTUnref<SkMallocPixelRef> pr( | 36 SkAutoTUnref<SkMallocPixelRef> pr( |
37 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data)); | 37 SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data)); |
38 // rowbytes too small. | 38 // rowbytes too small. |
39 REPORTER_ASSERT(reporter, NULL == pr.get()); | 39 REPORTER_ASSERT(reporter, nullptr == pr.get()); |
40 } | 40 } |
41 { | 41 { |
42 size_t rowBytes = info.minRowBytes() + 2; | 42 size_t rowBytes = info.minRowBytes() + 2; |
43 size_t size = info.getSafeSize(rowBytes) - 1; | 43 size_t size = info.getSafeSize(rowBytes) - 1; |
44 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 44 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
45 SkAutoTUnref<SkMallocPixelRef> pr( | 45 SkAutoTUnref<SkMallocPixelRef> pr( |
46 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data)); | 46 SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data)); |
47 // data too small. | 47 // data too small. |
48 REPORTER_ASSERT(reporter, NULL == pr.get()); | 48 REPORTER_ASSERT(reporter, nullptr == pr.get()); |
49 } | 49 } |
50 size_t rowBytes = info.minRowBytes() + 7; | 50 size_t rowBytes = info.minRowBytes() + 7; |
51 size_t size = info.getSafeSize(rowBytes) + 9; | 51 size_t size = info.getSafeSize(rowBytes) + 9; |
52 { | 52 { |
53 SkAutoMalloc memory(size); | 53 SkAutoMalloc memory(size); |
54 SkAutoTUnref<SkMallocPixelRef> pr( | 54 SkAutoTUnref<SkMallocPixelRef> pr( |
55 SkMallocPixelRef::NewDirect(info, memory.get(), rowBytes, NULL)); | 55 SkMallocPixelRef::NewDirect(info, memory.get(), rowBytes, nullptr)); |
56 REPORTER_ASSERT(reporter, pr.get() != NULL); | 56 REPORTER_ASSERT(reporter, pr.get() != nullptr); |
57 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); | 57 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); |
58 } | 58 } |
59 { | 59 { |
60 SkAutoTUnref<SkMallocPixelRef> pr( | 60 SkAutoTUnref<SkMallocPixelRef> pr( |
61 SkMallocPixelRef::NewAllocate(info, rowBytes, NULL)); | 61 SkMallocPixelRef::NewAllocate(info, rowBytes, nullptr)); |
62 REPORTER_ASSERT(reporter, pr.get() != NULL); | 62 REPORTER_ASSERT(reporter, pr.get() != nullptr); |
63 REPORTER_ASSERT(reporter, pr->pixels()); | 63 REPORTER_ASSERT(reporter, pr->pixels()); |
64 } | 64 } |
65 { | 65 { |
66 void* addr = static_cast<void*>(new uint8_t[size]); | 66 void* addr = static_cast<void*>(new uint8_t[size]); |
67 SkAutoTUnref<SkMallocPixelRef> pr( | 67 SkAutoTUnref<SkMallocPixelRef> pr( |
68 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, addr, | 68 SkMallocPixelRef::NewWithProc(info, rowBytes, nullptr, addr, |
69 delete_uint8_proc, NULL)); | 69 delete_uint8_proc, nullptr)); |
70 REPORTER_ASSERT(reporter, pr.get() != NULL); | 70 REPORTER_ASSERT(reporter, pr.get() != nullptr); |
71 REPORTER_ASSERT(reporter, addr == pr->pixels()); | 71 REPORTER_ASSERT(reporter, addr == pr->pixels()); |
72 } | 72 } |
73 { | 73 { |
74 int x = 0; | 74 int x = 0; |
75 SkAutoMalloc memory(size); | 75 SkAutoMalloc memory(size); |
76 SkAutoTUnref<SkMallocPixelRef> pr( | 76 SkAutoTUnref<SkMallocPixelRef> pr( |
77 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, | 77 SkMallocPixelRef::NewWithProc(info, rowBytes, nullptr, |
78 memory.get(), set_to_one_proc, | 78 memory.get(), set_to_one_proc, |
79 static_cast<void*>(&x))); | 79 static_cast<void*>(&x))); |
80 REPORTER_ASSERT(reporter, pr.get() != NULL); | 80 REPORTER_ASSERT(reporter, pr.get() != nullptr); |
81 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); | 81 REPORTER_ASSERT(reporter, memory.get() == pr->pixels()); |
82 REPORTER_ASSERT(reporter, 0 == x); | 82 REPORTER_ASSERT(reporter, 0 == x); |
83 pr.reset(NULL); | 83 pr.reset(nullptr); |
84 // make sure that set_to_one_proc was called. | 84 // make sure that set_to_one_proc was called. |
85 REPORTER_ASSERT(reporter, 1 == x); | 85 REPORTER_ASSERT(reporter, 1 == x); |
86 } | 86 } |
87 { | 87 { |
88 void* addr = static_cast<void*>(new uint8_t[size]); | 88 void* addr = static_cast<void*>(new uint8_t[size]); |
89 REPORTER_ASSERT(reporter, addr != NULL); | 89 REPORTER_ASSERT(reporter, addr != nullptr); |
90 SkAutoTUnref<SkMallocPixelRef> pr( | 90 SkAutoTUnref<SkMallocPixelRef> pr( |
91 SkMallocPixelRef::NewWithProc(info, rowBytes, NULL, addr, | 91 SkMallocPixelRef::NewWithProc(info, rowBytes, nullptr, addr, |
92 delete_uint8_proc, NULL)); | 92 delete_uint8_proc, nullptr)); |
93 REPORTER_ASSERT(reporter, addr == pr->pixels()); | 93 REPORTER_ASSERT(reporter, addr == pr->pixels()); |
94 } | 94 } |
95 { | 95 { |
96 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 96 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
97 SkData* dataPtr = data.get(); | 97 SkData* dataPtr = data.get(); |
98 REPORTER_ASSERT(reporter, dataPtr->unique()); | 98 REPORTER_ASSERT(reporter, dataPtr->unique()); |
99 SkAutoTUnref<SkMallocPixelRef> pr( | 99 SkAutoTUnref<SkMallocPixelRef> pr( |
100 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data.get())); | 100 SkMallocPixelRef::NewWithData(info, rowBytes, nullptr, data.get())); |
101 REPORTER_ASSERT(reporter, !(dataPtr->unique())); | 101 REPORTER_ASSERT(reporter, !(dataPtr->unique())); |
102 data.reset(NULL); | 102 data.reset(nullptr); |
103 REPORTER_ASSERT(reporter, dataPtr->unique()); | 103 REPORTER_ASSERT(reporter, dataPtr->unique()); |
104 REPORTER_ASSERT(reporter, dataPtr->data() == pr->pixels()); | 104 REPORTER_ASSERT(reporter, dataPtr->data() == pr->pixels()); |
105 } | 105 } |
106 } | 106 } |
OLD | NEW |