| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkTInternalSList.h" | 8 #include "SkTInternalSList.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 | 10 |
| 11 class SListEntry { | 11 class SListEntry { |
| 12 public: | 12 public: |
| 13 SListEntry* next() { return getSListNext(); } | 13 SListEntry* next() { return getSListNext(); } |
| 14 private: | 14 private: |
| 15 SK_DECLARE_INTERNAL_SLIST_INTERFACE(SListEntry); | 15 SK_DECLARE_INTERNAL_SLIST_INTERFACE(SListEntry); |
| 16 }; | 16 }; |
| 17 | 17 |
| 18 static bool verifyEmptyList(skiatest::Reporter* reporter, | 18 static bool verifyEmptyList(skiatest::Reporter* reporter, |
| 19 const SkTInternalSList<SListEntry>& list, | 19 const SkTInternalSList<SListEntry>& list, |
| 20 const char* stage) { | 20 const char* stage) { |
| 21 | 21 |
| 22 if (!list.isEmpty()) { | 22 if (!list.isEmpty()) { |
| 23 ERRORF(reporter, "%s - List not empty", stage); | 23 ERRORF(reporter, "%s - List not empty", stage); |
| 24 return false; | 24 return false; |
| 25 } | 25 } |
| 26 if (0 != list.getCount()) { | 26 if (0 != list.getCount()) { |
| 27 ERRORF(reporter, "%s - List count is not zero, %d instead", stage, list.
getCount()); | 27 ERRORF(reporter, "%s - List count is not zero, %d instead", stage, list.
getCount()); |
| 28 return false; | 28 return false; |
| 29 } | 29 } |
| 30 if (NULL != list.head()) { | 30 if (list.head()) { |
| 31 ERRORF(reporter, "%s - List has elements when empty", stage); | 31 ERRORF(reporter, "%s - List has elements when empty", stage); |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 static bool verifyList(skiatest::Reporter* reporter, | 37 static bool verifyList(skiatest::Reporter* reporter, |
| 38 const SkTInternalSList<SListEntry>& list, | 38 const SkTInternalSList<SListEntry>& list, |
| 39 const char* stage, | 39 const char* stage, |
| 40 SListEntry* start, int count, int step = 1) { | 40 SListEntry* start, int count, int step = 1) { |
| 41 SListEntry* next = list.head(); | 41 SListEntry* next = list.head(); |
| 42 if (list.getCount() != count) { | 42 if (list.getCount() != count) { |
| 43 ERRORF(reporter, "%s - List was too short, %d instead of %d", stage, lis
t.getCount(), count); | 43 ERRORF(reporter, "%s - List was too short, %d instead of %d", stage, lis
t.getCount(), count); |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 int index = 0; | 46 int index = 0; |
| 47 for(SListEntry* value = start; index < count; value += step, ++index) { | 47 for(SListEntry* value = start; index < count; value += step, ++index) { |
| 48 if (NULL == next) { | 48 if (NULL == next) { |
| 49 ERRORF(reporter, "%s - List too short, should be %d", stage, count); | 49 ERRORF(reporter, "%s - List too short, should be %d", stage, count); |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 if (next!= value) { | 52 if (next!= value) { |
| 53 ERRORF(reporter, "%s - List entries at index %d of %d don't match",
stage, index, count); | 53 ERRORF(reporter, "%s - List entries at index %d of %d don't match",
stage, index, count); |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 next = next->next(); | 56 next = next->next(); |
| 57 } | 57 } |
| 58 if (NULL != next) { | 58 if (next) { |
| 59 ERRORF(reporter, "%s - List too long, should be %d", stage, count); | 59 ERRORF(reporter, "%s - List too long, should be %d", stage, count); |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static void testTInternalSList(skiatest::Reporter* reporter) { | 65 static void testTInternalSList(skiatest::Reporter* reporter) { |
| 66 // Build a test array of data | 66 // Build a test array of data |
| 67 static const int testArraySize = 10; | 67 static const int testArraySize = 10; |
| 68 SListEntry testArray[testArraySize]; | 68 SListEntry testArray[testArraySize]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Check pushAll when non empty works | 102 // Check pushAll when non empty works |
| 103 other.push(list.pop()); | 103 other.push(list.pop()); |
| 104 other.pushAll(&list); | 104 other.pushAll(&list); |
| 105 verifyEmptyList(reporter, list, "pushAll"); | 105 verifyEmptyList(reporter, list, "pushAll"); |
| 106 verifyList(reporter, other, "pushAll", &testArray[0], testArraySize, 1); | 106 verifyList(reporter, other, "pushAll", &testArray[0], testArraySize, 1); |
| 107 } | 107 } |
| 108 | 108 |
| 109 DEF_TEST(SList, reporter) { | 109 DEF_TEST(SList, reporter) { |
| 110 testTInternalSList(reporter); | 110 testTInternalSList(reporter); |
| 111 } | 111 } |
| OLD | NEW |