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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "ppapi/c/pp_var.h" | 9 #include "ppapi/c/pp_var.h" |
10 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
11 #include "ppapi/proxy/ppapi_proxy_test.h" | 11 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 12 #include "ppapi/proxy/ppb_var_proxy.h" |
12 | 13 |
13 // TODO(dmichael): Make PPB_Var_Proxy and PluginResourceTracker thread-safe and | 14 // TODO(dmichael): Make PPB_Var_Proxy and PluginResourceTracker thread-safe and |
14 // add thread-safety tests here. | 15 // add thread-safety tests here. |
15 | 16 |
16 namespace { | 17 namespace { |
17 std::string VarToString(const PP_Var& var, const PPB_Var* ppb_var) { | 18 std::string VarToString(const PP_Var& var, const PPB_Var* ppb_var) { |
18 uint32_t len = 0; | 19 uint32_t len = 0; |
19 const char* utf8 = ppb_var->VarToUtf8(var, &len); | 20 const char* utf8 = ppb_var->VarToUtf8(var, &len); |
20 return std::string(utf8, len); | 21 return std::string(utf8, len); |
21 } | 22 } |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 namespace ppapi { | 25 namespace ppapi { |
25 namespace proxy { | 26 namespace proxy { |
26 | 27 |
27 class PPB_VarTest : public PluginProxyTest { | 28 class PPB_VarTest : public PluginProxyTest { |
28 public: | 29 public: |
29 PPB_VarTest() {} | 30 PPB_VarTest() {} |
30 }; | 31 }; |
31 | 32 |
32 TEST_F(PPB_VarTest, Strings) { | 33 TEST_F(PPB_VarTest, Strings) { |
33 const PPB_Var* ppb_var = static_cast<const PPB_Var*>( | 34 const PPB_Var* ppb_var = GetPPB_Var_Interface(); |
34 plugin_dispatcher()->GetInterfaceFromDispatcher(PPB_VAR_INTERFACE)); | |
35 | 35 |
36 // Make a vector of strings, where the value of test_strings[i] is "i". | 36 // Make a vector of strings, where the value of test_strings[i] is "i". |
37 const int kNumStrings = 5; | 37 const int kNumStrings = 5; |
38 std::vector<std::string> test_strings(kNumStrings); | 38 std::vector<std::string> test_strings(kNumStrings); |
39 for (int i = 0; i < kNumStrings; ++i) | 39 for (int i = 0; i < kNumStrings; ++i) |
40 test_strings[i] = base::IntToString(i); | 40 test_strings[i] = base::IntToString(i); |
41 | 41 |
42 std::vector<PP_Var> vars(kNumStrings); | 42 std::vector<PP_Var> vars(kNumStrings); |
43 for (int i = 0; i < kNumStrings; ++i) { | 43 for (int i = 0; i < kNumStrings; ++i) { |
44 vars[i] = ppb_var->VarFromUtf8(pp_module(), | 44 vars[i] = ppb_var->VarFromUtf8(pp_module(), |
(...skipping 23 matching lines...) Expand all Loading... |
68 uint32_t len = 10; | 68 uint32_t len = 10; |
69 const char* utf8 = ppb_var->VarToUtf8(vars[i], &len); | 69 const char* utf8 = ppb_var->VarToUtf8(vars[i], &len); |
70 EXPECT_EQ(NULL, utf8); | 70 EXPECT_EQ(NULL, utf8); |
71 EXPECT_EQ(0u, len); | 71 EXPECT_EQ(0u, len); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 } // namespace proxy | 75 } // namespace proxy |
76 } // namespace ppapi | 76 } // namespace ppapi |
77 | 77 |
OLD | NEW |