| 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 |
| 11 #include "ppapi/c/dev/ppb_testing_dev.h" | 11 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 12 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
| 13 #include "ppapi/c/ppb_var.h" | 13 #include "ppapi/c/ppb_var.h" |
| 14 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
| 15 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 16 #include "ppapi/cpp/var.h" | 16 #include "ppapi/cpp/var.h" |
| 17 #include "ppapi/tests/testing_instance.h" | 17 #include "ppapi/tests/testing_instance.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 uint32_t kInvalidLength = static_cast<uint32_t>(-1); | 21 uint32_t kInvalidLength = static_cast<uint32_t>(-1); |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 REGISTER_TEST_CASE(Var); | 25 REGISTER_TEST_CASE(Var); |
| 26 | 26 |
| 27 bool TestVar::Init() { | 27 bool TestVar::Init() { |
| 28 var_interface_ = static_cast<const PPB_Var*>( | 28 var_interface_ = static_cast<const PPB_Var*>( |
| 29 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); | 29 pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); |
| 30 return var_interface_ && InitTestingInterface(); | 30 return var_interface_ && CheckTestingInterface(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TestVar::RunTests(const std::string& filter) { | 33 void TestVar::RunTests(const std::string& filter) { |
| 34 RUN_TEST(BasicString, filter); | 34 RUN_TEST(BasicString, filter); |
| 35 RUN_TEST(InvalidAndEmpty, filter); | 35 RUN_TEST(InvalidAndEmpty, filter); |
| 36 RUN_TEST(InvalidUtf8, filter); | 36 RUN_TEST(InvalidUtf8, filter); |
| 37 RUN_TEST(NullInputInUtf8Conversion, filter); | 37 RUN_TEST(NullInputInUtf8Conversion, filter); |
| 38 RUN_TEST(ValidUtf8, filter); | 38 RUN_TEST(ValidUtf8, filter); |
| 39 RUN_TEST(Utf8WithEmbeddedNulls, filter); | 39 RUN_TEST(Utf8WithEmbeddedNulls, filter); |
| 40 RUN_TEST(VarToUtf8ForWrongType, filter); | 40 RUN_TEST(VarToUtf8ForWrongType, filter); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Now convert it back. | 129 // Now convert it back. |
| 130 uint32_t length = kInvalidLength; | 130 uint32_t length = kInvalidLength; |
| 131 const char* result = NULL; | 131 const char* result = NULL; |
| 132 result = var_interface_->VarToUtf8(converted_string, &length); | 132 result = var_interface_->VarToUtf8(converted_string, &length); |
| 133 if (length != 0) { | 133 if (length != 0) { |
| 134 return "Expected 0 length string on conversion."; | 134 return "Expected 0 length string on conversion."; |
| 135 } | 135 } |
| 136 if (result == NULL) { | 136 if (result == NULL) { |
| 137 return "Expected a non-null result for 0-lengthed string from VarToUtf8."; | 137 return "Expected a non-null result for 0-lengthed string from VarToUtf8."; |
| 138 } | 138 } |
| 139 var_interface_->Release(converted_string); |
| 139 | 140 |
| 140 // Should not crash, and make an empty string. | 141 // Should not crash, and make an empty string. |
| 141 const char* null_string = NULL; | 142 const char* null_string = NULL; |
| 142 pp::Var null_var(null_string); | 143 pp::Var null_var(null_string); |
| 143 if (!null_var.is_string() || null_var.AsString() != "") { | 144 if (!null_var.is_string() || null_var.AsString() != "") { |
| 144 return "Expected NULL input to make an empty string Var."; | 145 return "Expected NULL input to make an empty string Var."; |
| 145 } | 146 } |
| 146 | 147 |
| 147 PASS(); | 148 PASS(); |
| 148 } | 149 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (length != 0) { | 243 if (length != 0) { |
| 243 return "Expected 0 on string conversion from Double var."; | 244 return "Expected 0 on string conversion from Double var."; |
| 244 } | 245 } |
| 245 if (result != NULL) { | 246 if (result != NULL) { |
| 246 return "Expected NULL on string conversion from Double var."; | 247 return "Expected NULL on string conversion from Double var."; |
| 247 } | 248 } |
| 248 | 249 |
| 249 PASS(); | 250 PASS(); |
| 250 } | 251 } |
| 251 | 252 |
| OLD | NEW |