OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "ppapi/tests/test_var.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 RUN_TEST(Utf8WithEmbeddedNulls, filter); | 39 RUN_TEST(Utf8WithEmbeddedNulls, filter); |
40 RUN_TEST(VarToUtf8ForWrongType, filter); | 40 RUN_TEST(VarToUtf8ForWrongType, filter); |
41 } | 41 } |
42 | 42 |
43 std::string TestVar::TestBasicString() { | 43 std::string TestVar::TestBasicString() { |
44 uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( | 44 uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( |
45 instance_->pp_instance()); | 45 instance_->pp_instance()); |
46 { | 46 { |
47 const char kStr[] = "Hello"; | 47 const char kStr[] = "Hello"; |
48 const uint32_t kStrLen(sizeof(kStr) - 1); | 48 const uint32_t kStrLen(sizeof(kStr) - 1); |
49 PP_Var str = var_interface_->VarFromUtf8(pp::Module::Get()->pp_module(), | 49 PP_Var str = var_interface_->VarFromUtf8(kStr, kStrLen); |
50 kStr, kStrLen); | |
51 ASSERT_EQ(PP_VARTYPE_STRING, str.type); | 50 ASSERT_EQ(PP_VARTYPE_STRING, str.type); |
52 | 51 |
53 // Reading back the string should work. | 52 // Reading back the string should work. |
54 uint32_t len = 0; | 53 uint32_t len = 0; |
55 const char* result = var_interface_->VarToUtf8(str, &len); | 54 const char* result = var_interface_->VarToUtf8(str, &len); |
56 ASSERT_EQ(kStrLen, len); | 55 ASSERT_EQ(kStrLen, len); |
57 ASSERT_EQ(0, strncmp(kStr, result, kStrLen)); | 56 ASSERT_EQ(0, strncmp(kStr, result, kStrLen)); |
58 | 57 |
59 // Destroy the string, readback should now fail. | 58 // Destroy the string, readback should now fail. |
60 var_interface_->Release(str); | 59 var_interface_->Release(str); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 PASS(); | 114 PASS(); |
116 } | 115 } |
117 | 116 |
118 std::string TestVar::TestNullInputInUtf8Conversion() { | 117 std::string TestVar::TestNullInputInUtf8Conversion() { |
119 // 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 |
120 // cannot be exercised via the C++ interface. | 119 // cannot be exercised via the C++ interface. |
121 PP_Var converted_string; | 120 PP_Var converted_string; |
122 | 121 |
123 // 0-length string should not dereference input string, and should produce | 122 // 0-length string should not dereference input string, and should produce |
124 // an empty string. | 123 // an empty string. |
125 converted_string = var_interface_->VarFromUtf8( | 124 converted_string = var_interface_->VarFromUtf8(NULL, 0); |
126 pp::Module::Get()->pp_module(), NULL, 0); | |
127 if (converted_string.type != PP_VARTYPE_STRING) { | 125 if (converted_string.type != PP_VARTYPE_STRING) { |
128 return "Expected 0 length to return empty string."; | 126 return "Expected 0 length to return empty string."; |
129 } | 127 } |
130 | 128 |
131 // Now convert it back. | 129 // Now convert it back. |
132 uint32_t length = kInvalidLength; | 130 uint32_t length = kInvalidLength; |
133 const char* result = NULL; | 131 const char* result = NULL; |
134 result = var_interface_->VarToUtf8(converted_string, &length); | 132 result = var_interface_->VarToUtf8(converted_string, &length); |
135 if (length != 0) { | 133 if (length != 0) { |
136 return "Expected 0 length string on conversion."; | 134 return "Expected 0 length string on conversion."; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 if (length != 0) { | 242 if (length != 0) { |
245 return "Expected 0 on string conversion from Double var."; | 243 return "Expected 0 on string conversion from Double var."; |
246 } | 244 } |
247 if (result != NULL) { | 245 if (result != NULL) { |
248 return "Expected NULL on string conversion from Double var."; | 246 return "Expected NULL on string conversion from Double var."; |
249 } | 247 } |
250 | 248 |
251 PASS(); | 249 PASS(); |
252 } | 250 } |
253 | 251 |
OLD | NEW |