OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkRefCnt.h" | 10 #include "SkRefCnt.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 REPORTER_ASSERT(reporter, NULL == tmp.get()); | 41 REPORTER_ASSERT(reporter, NULL == tmp.get()); |
42 | 42 |
43 obj.ref(); | 43 obj.ref(); |
44 REPORTER_ASSERT(reporter, 2 == obj.getRefCnt()); | 44 REPORTER_ASSERT(reporter, 2 == obj.getRefCnt()); |
45 { | 45 { |
46 SkAutoTUnref<RefClass> tmp2(&obj); | 46 SkAutoTUnref<RefClass> tmp2(&obj); |
47 } | 47 } |
48 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); | 48 REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); |
49 } | 49 } |
50 | 50 |
| 51 static void test_autostarray(skiatest::Reporter* reporter) { |
| 52 RefClass obj0(0); |
| 53 RefClass obj1(1); |
| 54 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 55 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 56 |
| 57 { |
| 58 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp; |
| 59 REPORTER_ASSERT(reporter, 0 == tmp.count()); |
| 60 |
| 61 tmp.reset(0); // test out reset(0) when already at 0 |
| 62 tmp.reset(4); // this should force a new allocation |
| 63 REPORTER_ASSERT(reporter, 4 == tmp.count()); |
| 64 tmp[0] = &obj0; |
| 65 tmp[1] = &obj1; |
| 66 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 67 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 68 |
| 69 // test out reset with data in the array (and a new allocation) |
| 70 tmp.reset(0); |
| 71 REPORTER_ASSERT(reporter, 0 == tmp.count()); |
| 72 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 73 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 74 |
| 75 tmp.reset(2); // this should use the preexisting allocation |
| 76 REPORTER_ASSERT(reporter, 2 == tmp.count()); |
| 77 tmp[0] = &obj0; |
| 78 tmp[1] = &obj1; |
| 79 } |
| 80 |
| 81 // test out destructor with data in the array (and using existing allocation
) |
| 82 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 83 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 84 |
| 85 { |
| 86 // test out allocating ctor (this should allocate new memory) |
| 87 SkAutoSTArray<2, SkRefPtr<RefClass> > tmp(4); |
| 88 REPORTER_ASSERT(reporter, 4 == tmp.count()); |
| 89 |
| 90 tmp[0] = &obj0; |
| 91 tmp[1] = &obj1; |
| 92 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 93 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 94 |
| 95 // Test out resut with data in the array and malloced storage |
| 96 tmp.reset(0); |
| 97 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 98 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 99 |
| 100 tmp.reset(2); // this should use the preexisting storage |
| 101 tmp[0] = &obj0; |
| 102 tmp[1] = &obj1; |
| 103 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 104 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 105 |
| 106 tmp.reset(4); // this should force a new malloc |
| 107 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 108 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 109 |
| 110 tmp[0] = &obj0; |
| 111 tmp[1] = &obj1; |
| 112 REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt()); |
| 113 REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt()); |
| 114 } |
| 115 |
| 116 REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt()); |
| 117 REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt()); |
| 118 } |
| 119 |
51 ///////////////////////////////////////////////////////////////////////////// | 120 ///////////////////////////////////////////////////////////////////////////// |
52 | 121 |
53 #define kSEARCH_COUNT 91 | 122 #define kSEARCH_COUNT 91 |
54 | 123 |
55 static void test_search(skiatest::Reporter* reporter) { | 124 static void test_search(skiatest::Reporter* reporter) { |
56 int i, array[kSEARCH_COUNT]; | 125 int i, array[kSEARCH_COUNT]; |
57 SkMWCRandom rand; | 126 SkMWCRandom rand; |
58 | 127 |
59 for (i = 0; i < kSEARCH_COUNT; i++) { | 128 for (i = 0; i < kSEARCH_COUNT; i++) { |
60 array[i] = rand.nextS(); | 129 array[i] = rand.nextS(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 REPORTER_ASSERT(reporter, n == 1); | 212 REPORTER_ASSERT(reporter, n == 1); |
144 REPORTER_ASSERT(reporter, u0 == u1); | 213 REPORTER_ASSERT(reporter, u0 == u1); |
145 REPORTER_ASSERT(reporter, u0 == gTest[i].fUni); | 214 REPORTER_ASSERT(reporter, u0 == gTest[i].fUni); |
146 REPORTER_ASSERT(reporter, | 215 REPORTER_ASSERT(reporter, |
147 p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8)); | 216 p - gTest[i].fUtf8 == (int)strlen(gTest[i].fUtf8)); |
148 } | 217 } |
149 | 218 |
150 test_utf16(reporter); | 219 test_utf16(reporter); |
151 test_search(reporter); | 220 test_search(reporter); |
152 test_autounref(reporter); | 221 test_autounref(reporter); |
| 222 test_autostarray(reporter); |
153 } | 223 } |
154 | 224 |
155 #include "TestClassDef.h" | 225 #include "TestClassDef.h" |
156 DEFINE_TESTCLASS("Utils", UtfTestClass, TestUTF) | 226 DEFINE_TESTCLASS("Utils", UtfTestClass, TestUTF) |
OLD | NEW |