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

Side by Side Diff: ppapi/tests/test_var_deprecated.cc

Issue 4182010: Use PASS() everywhere in ppapi/tests. (Closed) Base URL: https://ppapi.googlecode.com/svn/trunk/tests
Patch Set: First. Created 9 years, 11 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 | « ppapi/tests/test_url_util.cc ('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 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_var_deprecated.h" 5 #include "ppapi/tests/test_var_deprecated.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 var_interface_->Release(str); 66 var_interface_->Release(str);
67 result = var_interface_->VarToUtf8(str, &len); 67 result = var_interface_->VarToUtf8(str, &len);
68 ASSERT_EQ(0, len); 68 ASSERT_EQ(0, len);
69 ASSERT_EQ(NULL, result); 69 ASSERT_EQ(NULL, result);
70 } 70 }
71 71
72 // Make sure nothing leaked. 72 // Make sure nothing leaked.
73 ASSERT_TRUE(testing_interface_->GetLiveObjectCount( 73 ASSERT_TRUE(testing_interface_->GetLiveObjectCount(
74 pp::Module::Get()->pp_module()) == before_object); 74 pp::Module::Get()->pp_module()) == before_object);
75 75
76 return std::string(); 76 PASS();
77 } 77 }
78 78
79 std::string TestVarDeprecated::TestInvalidAndEmpty() { 79 std::string TestVarDeprecated::TestInvalidAndEmpty() {
80 PP_Var invalid_string; 80 PP_Var invalid_string;
81 invalid_string.type = PP_VARTYPE_STRING; 81 invalid_string.type = PP_VARTYPE_STRING;
82 invalid_string.value.as_id = 31415926; 82 invalid_string.value.as_id = 31415926;
83 83
84 // Invalid strings should give NULL as the return value. 84 // Invalid strings should give NULL as the return value.
85 uint32_t len = std::numeric_limits<uint32_t>::max(); 85 uint32_t len = std::numeric_limits<uint32_t>::max();
86 const char* result = var_interface_->VarToUtf8(invalid_string, &len); 86 const char* result = var_interface_->VarToUtf8(invalid_string, &len);
87 ASSERT_EQ(0, len); 87 ASSERT_EQ(0, len);
88 ASSERT_EQ(NULL, result); 88 ASSERT_EQ(NULL, result);
89 89
90 // Same with vars that are not strings. 90 // Same with vars that are not strings.
91 len = std::numeric_limits<uint32_t>::max(); 91 len = std::numeric_limits<uint32_t>::max();
92 pp::Var int_var(42); 92 pp::Var int_var(42);
93 result = var_interface_->VarToUtf8(int_var.pp_var(), &len); 93 result = var_interface_->VarToUtf8(int_var.pp_var(), &len);
94 ASSERT_EQ(0, len); 94 ASSERT_EQ(0, len);
95 ASSERT_EQ(NULL, result); 95 ASSERT_EQ(NULL, result);
96 96
97 // Empty strings should return non-NULL. 97 // Empty strings should return non-NULL.
98 pp::Var empty_string(""); 98 pp::Var empty_string("");
99 len = std::numeric_limits<uint32_t>::max(); 99 len = std::numeric_limits<uint32_t>::max();
100 result = var_interface_->VarToUtf8(empty_string.pp_var(), &len); 100 result = var_interface_->VarToUtf8(empty_string.pp_var(), &len);
101 ASSERT_EQ(0, len); 101 ASSERT_EQ(0, len);
102 ASSERT_NE(NULL, result); 102 ASSERT_NE(NULL, result);
103 103
104 return std::string(); 104 PASS();
105 } 105 }
106 106
107 std::string TestVarDeprecated::TestInvalidUtf8() { 107 std::string TestVarDeprecated::TestInvalidUtf8() {
108 // utf8じゃない (japanese for "is not utf8") in shift-jis encoding. 108 // utf8じゃない (japanese for "is not utf8") in shift-jis encoding.
109 static const char kSjisString[] = "utf8\x82\xb6\x82\xe1\x82\xc8\x82\xa2"; 109 static const char kSjisString[] = "utf8\x82\xb6\x82\xe1\x82\xc8\x82\xa2";
110 pp::Var sjis(kSjisString); 110 pp::Var sjis(kSjisString);
111 if (!sjis.is_null()) 111 if (!sjis.is_null())
112 return "Non-UTF8 string permitted."; 112 return "Non-UTF8 string permitted.";
113 113
114 return ""; 114 PASS();
115 } 115 }
116 116
117 std::string TestVarDeprecated::TestNullInputInUtf8Conversion() { 117 std::string TestVarDeprecated::TestNullInputInUtf8Conversion() {
118 // This test talks directly to the C interface to access edge cases that 118 // This test talks directly to the C interface to access edge cases that
119 // cannot be exercised via the C++ interface. 119 // cannot be exercised via the C++ interface.
120 PP_Var converted_string; 120 PP_Var converted_string;
121 121
122 // 0-length string should not dereference input string, and should produce 122 // 0-length string should not dereference input string, and should produce
123 // an empty string. 123 // an empty string.
124 converted_string = var_interface_->VarFromUtf8( 124 converted_string = var_interface_->VarFromUtf8(
(...skipping 13 matching lines...) Expand all
138 return "Expected a non-null result for 0-lengthed string from VarToUtf8."; 138 return "Expected a non-null result for 0-lengthed string from VarToUtf8.";
139 } 139 }
140 140
141 // Should not crash, and make an empty string. 141 // Should not crash, and make an empty string.
142 const char* null_string = NULL; 142 const char* null_string = NULL;
143 pp::Var null_var(null_string); 143 pp::Var null_var(null_string);
144 if (!null_var.is_string() || null_var.AsString() != "") { 144 if (!null_var.is_string() || null_var.AsString() != "") {
145 return "Expected NULL input to make an empty string Var."; 145 return "Expected NULL input to make an empty string Var.";
146 } 146 }
147 147
148 return ""; 148 PASS();
149 } 149 }
150 150
151 std::string TestVarDeprecated::TestValidUtf8() { 151 std::string TestVarDeprecated::TestValidUtf8() {
152 // From UTF8 string -> PP_Var. 152 // From UTF8 string -> PP_Var.
153 // Chinese for "I am utf8." 153 // Chinese for "I am utf8."
154 static const char kValidUtf8[] = "\xe6\x88\x91\xe6\x98\xafutf8."; 154 static const char kValidUtf8[] = "\xe6\x88\x91\xe6\x98\xafutf8.";
155 pp::Var converted_string(kValidUtf8); 155 pp::Var converted_string(kValidUtf8);
156 156
157 if (converted_string.is_null()) 157 if (converted_string.is_null())
158 return "Unable to convert valid utf8 to var."; 158 return "Unable to convert valid utf8 to var.";
159 159
160 // Since we're already here, test PP_Var back to UTF8 string. 160 // Since we're already here, test PP_Var back to UTF8 string.
161 std::string returned_string = converted_string.AsString(); 161 std::string returned_string = converted_string.AsString();
162 162
163 // We need to check against 1 less than sizeof because the resulting string 163 // We need to check against 1 less than sizeof because the resulting string
164 // is technically not NULL terminated by API design. 164 // is technically not NULL terminated by API design.
165 if (returned_string.size() != sizeof(kValidUtf8) - 1) { 165 if (returned_string.size() != sizeof(kValidUtf8) - 1) {
166 return "Unable to convert utf8 string back from var."; 166 return "Unable to convert utf8 string back from var.";
167 } 167 }
168 if (returned_string != kValidUtf8) { 168 if (returned_string != kValidUtf8) {
169 return "String mismatches on conversion back from PP_Var."; 169 return "String mismatches on conversion back from PP_Var.";
170 } 170 }
171 171
172 return ""; 172 PASS();
173 } 173 }
174 174
175 std::string TestVarDeprecated::TestUtf8WithEmbeddedNulls() { 175 std::string TestVarDeprecated::TestUtf8WithEmbeddedNulls() {
176 // From UTF8 string with embedded nulls -> PP_Var. 176 // From UTF8 string with embedded nulls -> PP_Var.
177 // Chinese for "also utf8." 177 // Chinese for "also utf8."
178 static const char kUtf8WithEmbededNull[] = "\xe6\xb9\x9f\xe6\x98\xaf\0utf8."; 178 static const char kUtf8WithEmbededNull[] = "\xe6\xb9\x9f\xe6\x98\xaf\0utf8.";
179 std::string orig_string(kUtf8WithEmbededNull, 179 std::string orig_string(kUtf8WithEmbededNull,
180 sizeof(kUtf8WithEmbededNull) -1); 180 sizeof(kUtf8WithEmbededNull) -1);
181 pp::Var converted_string(orig_string); 181 pp::Var converted_string(orig_string);
182 182
183 if (converted_string.is_null()) 183 if (converted_string.is_null())
184 return "Unable to convert utf8 with embedded nulls to var."; 184 return "Unable to convert utf8 with embedded nulls to var.";
185 185
186 // Since we're already here, test PP_Var back to UTF8 string. 186 // Since we're already here, test PP_Var back to UTF8 string.
187 std::string returned_string = converted_string.AsString(); 187 std::string returned_string = converted_string.AsString();
188 188
189 if (returned_string.size() != orig_string.size()) { 189 if (returned_string.size() != orig_string.size()) {
190 return "Unable to convert utf8 with embedded nulls back from var."; 190 return "Unable to convert utf8 with embedded nulls back from var.";
191 } 191 }
192 if (returned_string != orig_string) { 192 if (returned_string != orig_string) {
193 return "String mismatches on conversion back from PP_Var."; 193 return "String mismatches on conversion back from PP_Var.";
194 } 194 }
195 195
196 return ""; 196 PASS();
197 } 197 }
198 198
199 std::string TestVarDeprecated::TestVarToUtf8ForWrongType() { 199 std::string TestVarDeprecated::TestVarToUtf8ForWrongType() {
200 uint32_t length = kInvalidLength; 200 uint32_t length = kInvalidLength;
201 const char* result = NULL; 201 const char* result = NULL;
202 result = var_interface_->VarToUtf8(PP_MakeUndefined(), &length); 202 result = var_interface_->VarToUtf8(PP_MakeUndefined(), &length);
203 if (length != 0) { 203 if (length != 0) {
204 return "Expected 0 on string conversion from Void var."; 204 return "Expected 0 on string conversion from Void var.";
205 } 205 }
206 if (result != NULL) { 206 if (result != NULL) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 length = kInvalidLength; 240 length = kInvalidLength;
241 result = NULL; 241 result = NULL;
242 result = var_interface_->VarToUtf8(PP_MakeDouble(1.0), &length); 242 result = var_interface_->VarToUtf8(PP_MakeDouble(1.0), &length);
243 if (length != 0) { 243 if (length != 0) {
244 return "Expected 0 on string conversion from Double var."; 244 return "Expected 0 on string conversion from Double var.";
245 } 245 }
246 if (result != NULL) { 246 if (result != NULL) {
247 return "Expected NULL on string conversion from Double var."; 247 return "Expected NULL on string conversion from Double var.";
248 } 248 }
249 249
250 return ""; 250 PASS();
251 } 251 }
252 252
253 std::string TestVarDeprecated::TestHasPropertyAndMethod() { 253 std::string TestVarDeprecated::TestHasPropertyAndMethod() {
254 uint32_t before_objects = testing_interface_->GetLiveObjectCount( 254 uint32_t before_objects = testing_interface_->GetLiveObjectCount(
255 pp::Module::Get()->pp_module()); 255 pp::Module::Get()->pp_module());
256 { 256 {
257 pp::Var window = instance_->GetWindowObject(); 257 pp::Var window = instance_->GetWindowObject();
258 ASSERT_TRUE(window.is_object()); 258 ASSERT_TRUE(window.is_object());
259 259
260 // Regular property. 260 // Regular property.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 ASSERT_FALSE(window.HasProperty("find", &exception)); 317 ASSERT_FALSE(window.HasProperty("find", &exception));
318 ASSERT_FALSE(exception.is_undefined()); 318 ASSERT_FALSE(exception.is_undefined());
319 ASSERT_FALSE(window.HasMethod("find", &exception)); 319 ASSERT_FALSE(window.HasMethod("find", &exception));
320 ASSERT_FALSE(exception.is_undefined()); 320 ASSERT_FALSE(exception.is_undefined());
321 } 321 }
322 322
323 // Make sure nothing leaked. 323 // Make sure nothing leaked.
324 ASSERT_TRUE(testing_interface_->GetLiveObjectCount( 324 ASSERT_TRUE(testing_interface_->GetLiveObjectCount(
325 pp::Module::Get()->pp_module()) == before_objects); 325 pp::Module::Get()->pp_module()) == before_objects);
326 326
327 return std::string(); 327 PASS();
328 } 328 }
329 329
OLDNEW
« no previous file with comments | « ppapi/tests/test_url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698