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

Side by Side Diff: gm/gm_error.h

Issue 14187007: GM: allow caller to specify which result types trigger an error (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: sync_to_r8651 Created 7 years, 8 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 | « no previous file | gm/gmmain.cpp » ('j') | 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 2013 Google Inc. 2 * Copyright 2013 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 /* 8 /*
9 * Error codes used by gmmain.cpp. 9 * Error codes used by gmmain.cpp.
10 */ 10 */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return "MissingExpectations"; 51 return "MissingExpectations";
52 case kWritingReferenceImage_ErrorType: 52 case kWritingReferenceImage_ErrorType:
53 return "WritingReferenceImage"; 53 return "WritingReferenceImage";
54 } 54 }
55 // control should never reach here 55 // control should never reach here
56 SkDEBUGFAIL("getErrorTypeName() called with unknown type"); 56 SkDEBUGFAIL("getErrorTypeName() called with unknown type");
57 return "Unknown"; 57 return "Unknown";
58 } 58 }
59 59
60 /** 60 /**
61 * Fills in "type" with the ErrorType associated with name "name".
62 * Returns true if we found one, false if it is an unknown type name.
63 */
64 static bool getErrorTypeByName(const char name[], ErrorType *type) {
65 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
66 ErrorType thisType = static_cast<ErrorType>(typeInt);
67 const char *thisTypeName = getErrorTypeName(thisType);
68 if (0 == strcmp(thisTypeName, name)) {
69 *type = thisType;
70 return true;
71 }
72 }
73 return false;
74 }
75
76 /**
61 * A combination of 0 or more ErrorTypes. 77 * A combination of 0 or more ErrorTypes.
62 */ 78 */
63 class ErrorCombination { 79 class ErrorCombination {
64 public: 80 public:
65 ErrorCombination() : fBitfield(0) {} 81 ErrorCombination() : fBitfield(0) {}
66 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {} 82 ErrorCombination(const ErrorType type) : fBitfield(1 << type) {}
67 83
68 /** 84 /**
69 * Returns true iff there are NO errors. 85 * Returns true iff there are NO errors.
70 */ 86 */
(...skipping 16 matching lines...) Expand all
87 } 103 }
88 104
89 /** 105 /**
90 * Returns true iff this ErrorCombination includes this ErrorType. 106 * Returns true iff this ErrorCombination includes this ErrorType.
91 */ 107 */
92 bool includes(const ErrorType type) const { 108 bool includes(const ErrorType type) const {
93 return !(0 == (this->fBitfield & (1 << type))); 109 return !(0 == (this->fBitfield & (1 << type)));
94 } 110 }
95 111
96 /** 112 /**
113 * Returns a string representation of all ErrorTypes in this
114 * ErrorCombination.
115 *
116 * @param separator text with which to separate ErrorType names
117 */
118 SkString asString(const char separator[]) const {
119 SkString s;
120 for (int typeInt = 0; typeInt <= kLast_ErrorType; typeInt++) {
121 ErrorType type = static_cast<ErrorType>(typeInt);
122 if (this->includes(type)) {
123 if (!s.isEmpty()) {
124 s.append(separator);
125 }
126 s.append(getErrorTypeName(type));
127 }
128 }
129 return s;
130 }
131
132 /**
97 * Returns a new ErrorCombination, which includes the union of all 133 * Returns a new ErrorCombination, which includes the union of all
98 * ErrorTypes in two ErrorCombination objects (this and other). 134 * ErrorTypes in two ErrorCombination objects (this and other).
99 */ 135 */
100 ErrorCombination plus(const ErrorCombination& other) const { 136 ErrorCombination plus(const ErrorCombination& other) const {
101 ErrorCombination retval; 137 ErrorCombination retval;
102 retval.fBitfield = this->fBitfield | other.fBitfield; 138 retval.fBitfield = this->fBitfield | other.fBitfield;
103 return retval; 139 return retval;
104 } 140 }
105 141
106 /** 142 /**
107 * Returns a new ErrorCombination, which is a copy of "this" 143 * Returns a new ErrorCombination, which is a copy of "this"
108 * but with all ErrorTypes in "other" removed. 144 * but with all ErrorTypes in "other" removed.
109 */ 145 */
110 ErrorCombination minus(const ErrorCombination& other) const { 146 ErrorCombination minus(const ErrorCombination& other) const {
111 ErrorCombination retval; 147 ErrorCombination retval;
112 retval.fBitfield = this->fBitfield & ~(other.fBitfield); 148 retval.fBitfield = this->fBitfield & ~(other.fBitfield);
113 return retval; 149 return retval;
114 } 150 }
115 151
116 private: 152 private:
117 int fBitfield; 153 int fBitfield;
118 }; 154 };
119 155
120 // No errors at all. 156 // No errors at all.
121 const static ErrorCombination kEmpty_ErrorCombination; 157 const static ErrorCombination kEmpty_ErrorCombination;
122 } 158 }
123 159
124 #endif // ifndef gm_error_DEFINED 160 #endif // ifndef gm_error_DEFINED
OLDNEW
« no previous file with comments | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698