| OLD | NEW |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 1 #include "Test.h" | 8 #include "Test.h" |
| 2 | 9 |
| 3 #include "SkRecord.h" | 10 #include "SkRecord.h" |
| 4 #include "SkRecordPattern.h" | 11 #include "SkRecordPattern.h" |
| 5 #include "SkRecorder.h" | 12 #include "SkRecorder.h" |
| 6 #include "SkRecords.h" | 13 #include "SkRecords.h" |
| 7 | 14 |
| 8 using namespace SkRecords; | 15 using namespace SkRecords; |
| 9 typedef Pattern3<Is<Save>, | 16 typedef Pattern3<Is<Save>, |
| 10 Is<ClipRect>, | 17 Is<ClipRect>, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 SkRecorder recorder(&record, 1920, 1200); | 47 SkRecorder recorder(&record, 1920, 1200); |
| 41 | 48 |
| 42 // There will be two save-clipRect-restore blocks [0,3) and [3,6). | 49 // There will be two save-clipRect-restore blocks [0,3) and [3,6). |
| 43 for (int i = 0; i < 2; i++) { | 50 for (int i = 0; i < 2; i++) { |
| 44 recorder.save(); | 51 recorder.save(); |
| 45 recorder.clipRect(SkRect::MakeWH(300, 200)); | 52 recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 46 recorder.restore(); | 53 recorder.restore(); |
| 47 } | 54 } |
| 48 | 55 |
| 49 // We should match only at 0 and 3. Going over the length should fail grace
fully. | 56 // We should match only at 0 and 3. Going over the length should fail grace
fully. |
| 50 for (unsigned i = 0; i < 8; i++) { | 57 for (int i = 0; i < 8; i++) { |
| 51 if (i == 0 || i == 3) { | 58 if (i == 0 || i == 3) { |
| 52 REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3); | 59 REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3); |
| 53 } else { | 60 } else { |
| 54 REPORTER_ASSERT(r, !pattern.match(&record, i)); | 61 REPORTER_ASSERT(r, !pattern.match(&record, i)); |
| 55 } | 62 } |
| 56 } | 63 } |
| 57 } | 64 } |
| 58 | 65 |
| 59 DEF_TEST(RecordPattern_DontMatchSubsequences, r) { | 66 DEF_TEST(RecordPattern_DontMatchSubsequences, r) { |
| 60 SaveClipRectRestore pattern; | 67 SaveClipRectRestore pattern; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 99 |
| 93 DEF_TEST(RecordPattern_Complex, r) { | 100 DEF_TEST(RecordPattern_Complex, r) { |
| 94 Pattern3<Is<Save>, | 101 Pattern3<Is<Save>, |
| 95 Star<Not<Or3<Is<Save>, | 102 Star<Not<Or3<Is<Save>, |
| 96 Is<Restore>, | 103 Is<Restore>, |
| 97 IsDraw> > >, | 104 IsDraw> > >, |
| 98 Is<Restore> > pattern; | 105 Is<Restore> > pattern; |
| 99 | 106 |
| 100 SkRecord record; | 107 SkRecord record; |
| 101 SkRecorder recorder(&record, 1920, 1200); | 108 SkRecorder recorder(&record, 1920, 1200); |
| 102 unsigned start, begin, end; | 109 int start, begin, end; |
| 103 | 110 |
| 104 start = record.count(); | 111 start = record.count(); |
| 105 recorder.save(); | 112 recorder.save(); |
| 106 recorder.clipRect(SkRect::MakeWH(300, 200)); | 113 recorder.clipRect(SkRect::MakeWH(300, 200)); |
| 107 recorder.restore(); | 114 recorder.restore(); |
| 108 REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count()); | 115 REPORTER_ASSERT(r, pattern.match(&record, 0) == record.count()); |
| 109 end = start; | 116 end = start; |
| 110 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); | 117 REPORTER_ASSERT(r, pattern.search(&record, &begin, &end)); |
| 111 REPORTER_ASSERT(r, begin == start); | 118 REPORTER_ASSERT(r, begin == start); |
| 112 REPORTER_ASSERT(r, end == record.count()); | 119 REPORTER_ASSERT(r, end == record.count()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 136 | 143 |
| 137 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { | 144 DEF_TEST(RecordPattern_SaveLayerIsNotADraw, r) { |
| 138 Pattern1<IsDraw> pattern; | 145 Pattern1<IsDraw> pattern; |
| 139 | 146 |
| 140 SkRecord record; | 147 SkRecord record; |
| 141 SkRecorder recorder(&record, 1920, 1200); | 148 SkRecorder recorder(&record, 1920, 1200); |
| 142 recorder.saveLayer(NULL, NULL); | 149 recorder.saveLayer(NULL, NULL); |
| 143 | 150 |
| 144 REPORTER_ASSERT(r, !pattern.match(&record, 0)); | 151 REPORTER_ASSERT(r, !pattern.match(&record, 0)); |
| 145 } | 152 } |
| OLD | NEW |