Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: tests/PaintTest.cpp

Issue 21949007: Remove operator== from SkPaint (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Static function Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/views/animated/SkStaticTextView.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "Test.h" 8 #include "Test.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel()); 126 REPORTER_ASSERT(reporter, gLevels[i] == p0.getFilterLevel());
127 p1 = p0; 127 p1 = p0;
128 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel()); 128 REPORTER_ASSERT(reporter, gLevels[i] == p1.getFilterLevel());
129 129
130 p0.reset(); 130 p0.reset();
131 REPORTER_ASSERT(reporter, 131 REPORTER_ASSERT(reporter,
132 SkPaint::kNone_FilterLevel == p0.getFilterLevel()); 132 SkPaint::kNone_FilterLevel == p0.getFilterLevel());
133 } 133 }
134 } 134 }
135 135
136 // Only useful for test_copy. Checks the fields that are set.
137 static bool check_equal(const SkPaint& a, const SkPaint &b) {
138 return a.getLooper() == b.getLooper() &&
139 a.getMaskFilter() == b.getMaskFilter() &&
140 a.getStrokeWidth() == b.getStrokeWidth() &&
141 a.getStyle() == b.getStyle() &&
142 a.getTextAlign() == b.getTextAlign();
143 }
144
136 static void test_copy(skiatest::Reporter* reporter) { 145 static void test_copy(skiatest::Reporter* reporter) {
137 SkPaint paint; 146 SkPaint paint;
138 // set a few member variables 147 // set a few member variables
139 paint.setStyle(SkPaint::kStrokeAndFill_Style); 148 paint.setStyle(SkPaint::kStrokeAndFill_Style);
140 paint.setTextAlign(SkPaint::kLeft_Align); 149 paint.setTextAlign(SkPaint::kLeft_Align);
141 paint.setStrokeWidth(SkIntToScalar(2)); 150 paint.setStrokeWidth(SkIntToScalar(2));
142 // set a few pointers 151 // set a few pointers
143 SkLayerDrawLooper* looper = new SkLayerDrawLooper(); 152 SkLayerDrawLooper* looper = new SkLayerDrawLooper();
144 paint.setLooper(looper)->unref(); 153 paint.setLooper(looper)->unref();
145 SkMaskFilter* mask = SkBlurMaskFilter::Create(1, SkBlurMaskFilter::kNormal_B lurStyle); 154 SkMaskFilter* mask = SkBlurMaskFilter::Create(1, SkBlurMaskFilter::kNormal_B lurStyle);
146 paint.setMaskFilter(mask)->unref(); 155 paint.setMaskFilter(mask)->unref();
147 156
148 // copy the paint using the copy constructor and check they are the same 157 // copy the paint using the copy constructor and check they are the same
149 SkPaint copiedPaint = paint; 158 SkPaint copiedPaint = paint;
150 REPORTER_ASSERT(reporter, paint == copiedPaint); 159 REPORTER_ASSERT(reporter, check_equal(paint, copiedPaint));
151 160
152 #ifdef SK_BUILD_FOR_ANDROID 161 #ifdef SK_BUILD_FOR_ANDROID
153 // the copy constructor should preserve the Generation ID 162 // the copy constructor should preserve the Generation ID
154 uint32_t paintGenID = paint.getGenerationID(); 163 uint32_t paintGenID = paint.getGenerationID();
155 uint32_t copiedPaintGenID = copiedPaint.getGenerationID(); 164 uint32_t copiedPaintGenID = copiedPaint.getGenerationID();
156 REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID); 165 REPORTER_ASSERT(reporter, paintGenID == copiedPaintGenID);
157 REPORTER_ASSERT(reporter, !memcmp(&paint, &copiedPaint, sizeof(paint))); 166 REPORTER_ASSERT(reporter, check_equal(paint, copiedPaint));
158 #endif 167 #endif
159 168
160 // copy the paint using the equal operator and check they are the same 169 // copy the paint using the equal operator and check they are the same
161 copiedPaint = paint; 170 copiedPaint = paint;
162 REPORTER_ASSERT(reporter, paint == copiedPaint); 171 REPORTER_ASSERT(reporter, check_equal(paint, copiedPaint));
163 172
164 #ifdef SK_BUILD_FOR_ANDROID 173 #ifdef SK_BUILD_FOR_ANDROID
165 // the equals operator should increment the Generation ID 174 // the equals operator should increment the Generation ID
166 REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID); 175 REPORTER_ASSERT(reporter, paint.getGenerationID() == paintGenID);
167 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; 176 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ;
168 copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value 177 copiedPaintGenID = copiedPaint.getGenerationID(); // reset to the new value
169 REPORTER_ASSERT(reporter, memcmp(&paint, &copiedPaint, sizeof(paint))); 178 REPORTER_ASSERT(reporter, memcmp(&paint, &copiedPaint, sizeof(paint)));
170 #endif 179 #endif
171 180
172 // clean the paint and check they are back to their initial states 181 // clean the paint and check they are back to their initial states
173 SkPaint cleanPaint; 182 SkPaint cleanPaint;
174 paint.reset(); 183 paint.reset();
175 copiedPaint.reset(); 184 copiedPaint.reset();
176 REPORTER_ASSERT(reporter, cleanPaint == paint); 185 REPORTER_ASSERT(reporter, check_equal(cleanPaint, paint));
177 REPORTER_ASSERT(reporter, cleanPaint == copiedPaint); 186 REPORTER_ASSERT(reporter, check_equal(cleanPaint, copiedPaint));
178 187
179 #ifdef SK_BUILD_FOR_ANDROID 188 #ifdef SK_BUILD_FOR_ANDROID
180 // the reset function should increment the Generation ID 189 // the reset function should increment the Generation ID
181 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID); 190 REPORTER_ASSERT(reporter, paint.getGenerationID() != paintGenID);
182 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ; 191 REPORTER_ASSERT(reporter, copiedPaint.getGenerationID() != copiedPaintGenID) ;
183 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint))); 192 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &paint, sizeof(cleanPaint)));
184 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPain t))); 193 REPORTER_ASSERT(reporter, memcmp(&cleanPaint, &copiedPaint, sizeof(cleanPain t)));
185 #endif 194 #endif
186 } 195 }
187 196
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 254
246 // need to implement charsToGlyphs on other backends (e.g. linux, win) 255 // need to implement charsToGlyphs on other backends (e.g. linux, win)
247 // before we can run this tests everywhere 256 // before we can run this tests everywhere
248 if (false) { 257 if (false) {
249 test_cmap(reporter); 258 test_cmap(reporter);
250 } 259 }
251 } 260 }
252 261
253 #include "TestClassDef.h" 262 #include "TestClassDef.h"
254 DEFINE_TESTCLASS("Paint", TestPaintClass, TestPaint) 263 DEFINE_TESTCLASS("Paint", TestPaintClass, TestPaint)
OLDNEW
« no previous file with comments | « src/views/animated/SkStaticTextView.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698