| 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 "SkRandom.h" | 8 #include "SkRandom.h" |
| 9 #include "SkRefCnt.h" | 9 #include "SkRefCnt.h" |
| 10 #include "SkTSearch.h" | 10 #include "SkTSearch.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); | 46 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 static void test_autostarray(skiatest::Reporter* reporter) { | 49 static void test_autostarray(skiatest::Reporter* reporter) { |
| 50 RefClass obj0(0); | 50 RefClass obj0(0); |
| 51 RefClass obj1(1); | 51 RefClass obj1(1); |
| 52 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); | 52 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 53 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); | 53 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 54 | 54 |
| 55 { | 55 { |
| 56 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp; | 56 SkAutoSTArray<2, SkAutoTUnref<RefClass> > tmp; |
| 57 REPORTER_ASSERT(reporter, 0 == tmp.count()); | 57 REPORTER_ASSERT(reporter, 0 == tmp.count()); |
| 58 | 58 |
| 59 tmp.reset(0); // test out reset(0) when already at 0 | 59 tmp.reset(0); // test out reset(0) when already at 0 |
| 60 tmp.reset(4); // this should force a new allocation | 60 tmp.reset(4); // this should force a new allocation |
| 61 REPORTER_ASSERT(reporter, 4 == tmp.count()); | 61 REPORTER_ASSERT(reporter, 4 == tmp.count()); |
| 62 tmp[0] = &obj0; | 62 tmp[0].reset(SkRef(&obj0)); |
| 63 tmp[1] = &obj1; | 63 tmp[1].reset(SkRef(&obj1)); |
| 64 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); | 64 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 65 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); | 65 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 66 | 66 |
| 67 // test out reset with data in the array (and a new allocation) | 67 // test out reset with data in the array (and a new allocation) |
| 68 tmp.reset(0); | 68 tmp.reset(0); |
| 69 REPORTER_ASSERT(reporter, 0 == tmp.count()); | 69 REPORTER_ASSERT(reporter, 0 == tmp.count()); |
| 70 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); | 70 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 71 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); | 71 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 72 | 72 |
| 73 tmp.reset(2); // this should use the preexisting allocation | 73 tmp.reset(2); // this should use the preexisting allocation |
| 74 REPORTER_ASSERT(reporter, 2 == tmp.count()); | 74 REPORTER_ASSERT(reporter, 2 == tmp.count()); |
| 75 tmp[0] = &obj0; | 75 tmp[0].reset(SkRef(&obj0)); |
| 76 tmp[1] = &obj1; | 76 tmp[1].reset(SkRef(&obj1)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // test out destructor with data in the array (and using existing allocation
) | 79 // test out destructor with data in the array (and using existing allocation
) |
| 80 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); | 80 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 81 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); | 81 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 82 | 82 |
| 83 { | 83 { |
| 84 // test out allocating ctor (this should allocate new memory) | 84 // test out allocating ctor (this should allocate new memory) |
| 85 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp(4); | 85 SkAutoSTArray<2, SkAutoTUnref<RefClass> > tmp(4); |
| 86 REPORTER_ASSERT(reporter, 4 == tmp.count()); | 86 REPORTER_ASSERT(reporter, 4 == tmp.count()); |
| 87 | 87 |
| 88 tmp[0] = &obj0; | 88 tmp[0].reset(SkRef(&obj0)); |
| 89 tmp[1] = &obj1; | 89 tmp[1].reset(SkRef(&obj1)); |
| 90 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); | 90 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 91 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); | 91 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 92 | 92 |
| 93 // Test out resut with data in the array and malloced storage | 93 // Test out resut with data in the array and malloced storage |
| 94 tmp.reset(0); | 94 tmp.reset(0); |
| 95 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); | 95 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 96 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); | 96 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 97 | 97 |
| 98 tmp.reset(2); // this should use the preexisting storage | 98 tmp.reset(2); // this should use the preexisting storage |
| 99 tmp[0] = &obj0; | 99 tmp[0].reset(SkRef(&obj0)); |
| 100 tmp[1] = &obj1; | 100 tmp[1].reset(SkRef(&obj1)); |
| 101 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); | 101 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 102 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); | 102 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 103 | 103 |
| 104 tmp.reset(4); // this should force a new malloc | 104 tmp.reset(4); // this should force a new malloc |
| 105 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); | 105 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 106 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); | 106 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 107 | 107 |
| 108 tmp[0] = &obj0; | 108 tmp[0].reset(SkRef(&obj0)); |
| 109 tmp[1] = &obj1; | 109 tmp[1].reset(SkRef(&obj1)); |
| 110 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); | 110 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 111 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); | 111 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); | 114 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 115 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); | 115 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 ///////////////////////////////////////////////////////////////////////////// | 118 ///////////////////////////////////////////////////////////////////////////// |
| 119 | 119 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 REPORTER_ASSERT(reporter, u0 == gTest[i].fUni); | 212 REPORTER_ASSERT(reporter, u0 == gTest[i].fUni); |
| 213 REPORTER_ASSERT(reporter, | 213 REPORTER_ASSERT(reporter, |
| 214 p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8)); | 214 p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 test_utf16(reporter); | 217 test_utf16(reporter); |
| 218 test_search(reporter); | 218 test_search(reporter); |
| 219 test_autounref(reporter); | 219 test_autounref(reporter); |
| 220 test_autostarray(reporter); | 220 test_autostarray(reporter); |
| 221 } | 221 } |
| OLD | NEW |