OLD | NEW |
---|---|
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 29 matching lines...) Expand all Loading... | |
40 RUN_TEST(InvalidAndEmpty); | 40 RUN_TEST(InvalidAndEmpty); |
41 RUN_TEST(InvalidUtf8); | 41 RUN_TEST(InvalidUtf8); |
42 RUN_TEST(NullInputInUtf8Conversion); | 42 RUN_TEST(NullInputInUtf8Conversion); |
43 RUN_TEST(ValidUtf8); | 43 RUN_TEST(ValidUtf8); |
44 RUN_TEST(Utf8WithEmbeddedNulls); | 44 RUN_TEST(Utf8WithEmbeddedNulls); |
45 RUN_TEST(VarToUtf8ForWrongType); | 45 RUN_TEST(VarToUtf8ForWrongType); |
46 RUN_TEST(HasPropertyAndMethod); | 46 RUN_TEST(HasPropertyAndMethod); |
47 } | 47 } |
48 | 48 |
49 std::string TestVarDeprecated::TestBasicString() { | 49 std::string TestVarDeprecated::TestBasicString() { |
50 uint32_t before_object = testing_interface_->GetLiveObjectCount( | 50 uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( |
51 pp::Module::Get()->pp_module()); | 51 pp::Module::Get()->pp_module()); |
piman
2011/01/20 00:26:23
pp::Module::Get()->pp_module() -> instance_->pp_in
| |
52 { | 52 { |
53 const uint32_t kStrLen = 5; | 53 const uint32_t kStrLen = 5; |
54 const char kStr[kStrLen + 1] = "Hello"; | 54 const char kStr[kStrLen + 1] = "Hello"; |
55 PP_Var str = var_interface_->VarFromUtf8(pp::Module::Get()->pp_module(), | 55 PP_Var str = var_interface_->VarFromUtf8(pp::Module::Get()->pp_module(), |
56 kStr, sizeof(kStr) - 1); | 56 kStr, sizeof(kStr) - 1); |
57 ASSERT_EQ(PP_VARTYPE_STRING, str.type); | 57 ASSERT_EQ(PP_VARTYPE_STRING, str.type); |
58 | 58 |
59 // Reading back the string should work. | 59 // Reading back the string should work. |
60 uint32_t len = 0; | 60 uint32_t len = 0; |
61 const char* result = var_interface_->VarToUtf8(str, &len); | 61 const char* result = var_interface_->VarToUtf8(str, &len); |
62 ASSERT_EQ(kStrLen, len); | 62 ASSERT_EQ(kStrLen, len); |
63 ASSERT_EQ(0, strncmp(kStr, result, kStrLen)); | 63 ASSERT_EQ(0, strncmp(kStr, result, kStrLen)); |
64 | 64 |
65 // Destroy the string, readback should now fail. | 65 // Destroy the string, readback should now fail. |
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_->GetLiveObjectsForInstance( |
74 pp::Module::Get()->pp_module()) == before_object); | 74 instance_->pp_instance()) == before_object); |
75 | 75 |
76 PASS(); | 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. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 PASS(); | 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_->GetLiveObjectsForInstance( |
255 pp::Module::Get()->pp_module()); | 255 instance_->pp_instance()); |
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. |
261 pp::Var exception; | 261 pp::Var exception; |
262 ASSERT_TRUE(window.HasProperty("scrollX", &exception)); | 262 ASSERT_TRUE(window.HasProperty("scrollX", &exception)); |
263 ASSERT_TRUE(exception.is_undefined()); | 263 ASSERT_TRUE(exception.is_undefined()); |
264 ASSERT_FALSE(window.HasMethod("scrollX", &exception)); | 264 ASSERT_FALSE(window.HasMethod("scrollX", &exception)); |
265 ASSERT_TRUE(exception.is_undefined()); | 265 ASSERT_TRUE(exception.is_undefined()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 | 314 |
315 // Get a valid property/method when the exception is set returns false. | 315 // Get a valid property/method when the exception is set returns false. |
316 exception = pp::Var("Bad something-or-other exception"); | 316 exception = pp::Var("Bad something-or-other exception"); |
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_->GetLiveObjectsForInstance( |
325 pp::Module::Get()->pp_module()) == before_objects); | 325 instance_->pp_instance()) == before_objects); |
326 | 326 |
327 PASS(); | 327 PASS(); |
328 } | 328 } |
329 | 329 |
OLD | NEW |