OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "gin/converter.h" | 5 #include "gin/converter.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 TEST_F(ConverterTest, Vector) { | 111 TEST_F(ConverterTest, Vector) { |
112 HandleScope handle_scope(instance_->isolate()); | 112 HandleScope handle_scope(instance_->isolate()); |
113 | 113 |
114 std::vector<int> expected; | 114 std::vector<int> expected; |
115 expected.push_back(-1); | 115 expected.push_back(-1); |
116 expected.push_back(0); | 116 expected.push_back(0); |
117 expected.push_back(1); | 117 expected.push_back(1); |
118 | 118 |
119 auto maybe = Converter<std::vector<int>>::ToV8( | 119 Local<Array> js_array = Local<Array>::Cast( |
120 instance_->isolate()->GetCurrentContext(), expected); | 120 Converter<std::vector<int>>::ToV8(instance_->isolate(), expected)); |
121 Local<Value> js_value; | 121 ASSERT_FALSE(js_array.IsEmpty()); |
122 EXPECT_TRUE(maybe.ToLocal(&js_value)); | 122 EXPECT_EQ(3u, js_array->Length()); |
123 Local<Array> js_array2 = Local<Array>::Cast(js_value); | |
124 EXPECT_EQ(3u, js_array2->Length()); | |
125 for (size_t i = 0; i < expected.size(); ++i) { | 123 for (size_t i = 0; i < expected.size(); ++i) { |
126 EXPECT_TRUE(Integer::New(instance_->isolate(), expected[i]) | 124 EXPECT_TRUE(Integer::New(instance_->isolate(), expected[i]) |
127 ->StrictEquals(js_array2->Get(static_cast<int>(i)))); | 125 ->StrictEquals(js_array->Get(static_cast<int>(i)))); |
128 } | 126 } |
| 127 |
| 128 std::vector<int> actual; |
| 129 EXPECT_TRUE(Converter<std::vector<int> >::FromV8(instance_->isolate(), |
| 130 js_array, &actual)); |
| 131 EXPECT_EQ(expected, actual); |
129 } | 132 } |
130 | 133 |
131 } // namespace gin | 134 } // namespace gin |
OLD | NEW |