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_char_set.h" | 5 #include "ppapi/tests/test_char_set.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_char_set_dev.h" | 7 #include "ppapi/c/dev/ppb_char_set_dev.h" |
8 #include "ppapi/cpp/dev/memory_dev.h" | 8 #include "ppapi/cpp/dev/memory_dev.h" |
9 #include "ppapi/cpp/module.h" | 9 #include "ppapi/cpp/module.h" |
10 #include "ppapi/tests/testing_instance.h" | 10 #include "ppapi/tests/testing_instance.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 utf8result = char_set_interface_->UTF16ToCharSet( | 96 utf8result = char_set_interface_->UTF16ToCharSet( |
97 instance_->pp_instance(), &utf16[0], static_cast<uint32_t>(utf16.size()), | 97 instance_->pp_instance(), &utf16[0], static_cast<uint32_t>(utf16.size()), |
98 "poopiepants", PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf8result_len); | 98 "poopiepants", PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf8result_len); |
99 ASSERT_TRUE(!utf8result); | 99 ASSERT_TRUE(!utf8result); |
100 ASSERT_TRUE(utf8result_len == 0); | 100 ASSERT_TRUE(utf8result_len == 0); |
101 | 101 |
102 PASS(); | 102 PASS(); |
103 } | 103 } |
104 | 104 |
105 std::string TestCharSet::TestCharSetToUTF16() { | 105 std::string TestCharSet::TestCharSetToUTF16() { |
| 106 pp::Memory_Dev memory; |
| 107 |
106 // Empty string. | 108 // Empty string. |
107 uint32_t utf16result_len; | 109 uint32_t utf16result_len; |
108 uint16_t* utf16result = char_set_interface_->CharSetToUTF16( | 110 uint16_t* utf16result = char_set_interface_->CharSetToUTF16( |
109 instance_->pp_instance(), "", 0, "latin1", | 111 instance_->pp_instance(), "", 0, "latin1", |
110 PP_CHARSET_CONVERSIONERROR_FAIL, &utf16result_len); | 112 PP_CHARSET_CONVERSIONERROR_FAIL, &utf16result_len); |
111 ASSERT_TRUE(utf16result); | 113 ASSERT_TRUE(utf16result); |
112 ASSERT_TRUE(utf16result_len == 0); | 114 ASSERT_TRUE(utf16result_len == 0); |
113 ASSERT_TRUE(utf16result[0] == 0); | 115 ASSERT_TRUE(utf16result[0] == 0); |
| 116 memory.MemFree(utf16result); |
114 | 117 |
115 // Basic Latin1. | 118 // Basic Latin1. |
116 char latin1[] = "H\xef"; | 119 char latin1[] = "H\xef"; |
117 utf16result = char_set_interface_->CharSetToUTF16( | 120 utf16result = char_set_interface_->CharSetToUTF16( |
118 instance_->pp_instance(), latin1, 2, "latin1", | 121 instance_->pp_instance(), latin1, 2, "latin1", |
119 PP_CHARSET_CONVERSIONERROR_FAIL, &utf16result_len); | 122 PP_CHARSET_CONVERSIONERROR_FAIL, &utf16result_len); |
120 ASSERT_TRUE(utf16result); | 123 ASSERT_TRUE(utf16result); |
121 ASSERT_TRUE(utf16result_len == 2); | 124 ASSERT_TRUE(utf16result_len == 2); |
122 ASSERT_TRUE(utf16result[0] == 'H' && utf16result[1] == 0xef && | 125 ASSERT_TRUE(utf16result[0] == 'H' && utf16result[1] == 0xef && |
123 utf16result[2] == 0); | 126 utf16result[2] == 0); |
| 127 memory.MemFree(utf16result); |
124 | 128 |
125 // Invalid input encoding with FAIL. | 129 // Invalid input encoding with FAIL. |
126 char badutf8[] = "A\xe4Z"; | 130 char badutf8[] = "A\xe4Z"; |
127 utf16result = char_set_interface_->CharSetToUTF16( | 131 utf16result = char_set_interface_->CharSetToUTF16( |
128 instance_->pp_instance(), badutf8, 3, "utf8", | 132 instance_->pp_instance(), badutf8, 3, "utf8", |
129 PP_CHARSET_CONVERSIONERROR_FAIL, &utf16result_len); | 133 PP_CHARSET_CONVERSIONERROR_FAIL, &utf16result_len); |
130 ASSERT_TRUE(!utf16result); | 134 ASSERT_TRUE(!utf16result); |
131 ASSERT_TRUE(utf16result_len == 0); | 135 ASSERT_TRUE(utf16result_len == 0); |
| 136 memory.MemFree(utf16result); |
132 | 137 |
133 // Invalid input with SKIP. | 138 // Invalid input with SKIP. |
134 utf16result = char_set_interface_->CharSetToUTF16( | 139 utf16result = char_set_interface_->CharSetToUTF16( |
135 instance_->pp_instance(), badutf8, 3, "utf8", | 140 instance_->pp_instance(), badutf8, 3, "utf8", |
136 PP_CHARSET_CONVERSIONERROR_SKIP, &utf16result_len); | 141 PP_CHARSET_CONVERSIONERROR_SKIP, &utf16result_len); |
137 ASSERT_TRUE(utf16result); | 142 ASSERT_TRUE(utf16result); |
138 ASSERT_TRUE(utf16result_len == 2); | 143 ASSERT_TRUE(utf16result_len == 2); |
139 ASSERT_TRUE(utf16result[0] == 'A' && utf16result[1] == 'Z' && | 144 ASSERT_TRUE(utf16result[0] == 'A' && utf16result[1] == 'Z' && |
140 utf16result[2] == 0); | 145 utf16result[2] == 0); |
| 146 memory.MemFree(utf16result); |
141 | 147 |
142 // Invalid input with SUBSTITUTE. | 148 // Invalid input with SUBSTITUTE. |
143 utf16result = char_set_interface_->CharSetToUTF16( | 149 utf16result = char_set_interface_->CharSetToUTF16( |
144 instance_->pp_instance(), badutf8, 3, "utf8", | 150 instance_->pp_instance(), badutf8, 3, "utf8", |
145 PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf16result_len); | 151 PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf16result_len); |
146 ASSERT_TRUE(utf16result); | 152 ASSERT_TRUE(utf16result); |
147 ASSERT_TRUE(utf16result_len == 3); | 153 ASSERT_TRUE(utf16result_len == 3); |
148 ASSERT_TRUE(utf16result[0] == 'A' && utf16result[1] == 0xFFFD && | 154 ASSERT_TRUE(utf16result[0] == 'A' && utf16result[1] == 0xFFFD && |
149 utf16result[2] == 'Z' && utf16result[3] == 0); | 155 utf16result[2] == 'Z' && utf16result[3] == 0); |
| 156 memory.MemFree(utf16result); |
150 | 157 |
151 // Invalid encoding name. | 158 // Invalid encoding name. |
152 utf16result = char_set_interface_->CharSetToUTF16( | 159 utf16result = char_set_interface_->CharSetToUTF16( |
153 instance_->pp_instance(), badutf8, 3, "poopiepants", | 160 instance_->pp_instance(), badutf8, 3, "poopiepants", |
154 PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf16result_len); | 161 PP_CHARSET_CONVERSIONERROR_SUBSTITUTE, &utf16result_len); |
155 ASSERT_TRUE(!utf16result); | 162 ASSERT_TRUE(!utf16result); |
156 ASSERT_TRUE(utf16result_len == 0); | 163 ASSERT_TRUE(utf16result_len == 0); |
| 164 memory.MemFree(utf16result); |
157 | 165 |
158 PASS(); | 166 PASS(); |
159 } | 167 } |
160 | 168 |
161 std::string TestCharSet::TestGetDefaultCharSet() { | 169 std::string TestCharSet::TestGetDefaultCharSet() { |
162 // Test invalid instance. | 170 // Test invalid instance. |
163 pp::Var result(pp::Var::PassRef(), char_set_interface_->GetDefaultCharSet(0)); | 171 pp::Var result(pp::Var::PassRef(), char_set_interface_->GetDefaultCharSet(0)); |
164 ASSERT_TRUE(result.is_undefined()); | 172 ASSERT_TRUE(result.is_undefined()); |
165 | 173 |
166 // Just make sure the default char set is a nonempty string. | 174 // Just make sure the default char set is a nonempty string. |
(...skipping 14 matching lines...) Expand all Loading... |
181 | 189 |
182 std::vector<uint16_t> result_vector; | 190 std::vector<uint16_t> result_vector; |
183 if (!result) | 191 if (!result) |
184 return result_vector; | 192 return result_vector; |
185 | 193 |
186 result_vector.assign(result, &result[result_len]); | 194 result_vector.assign(result, &result[result_len]); |
187 pp::Memory_Dev memory; | 195 pp::Memory_Dev memory; |
188 memory.MemFree(result); | 196 memory.MemFree(result); |
189 return result_vector; | 197 return result_vector; |
190 } | 198 } |
OLD | NEW |