Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: gin/converter_unittest.cc

Issue 663673002: Convert the few remaining ARRAYSIZE_UNSAFE -> arraysize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 { Number::New(instance_->isolate(), 1).As<Value>(), true }, 48 { Number::New(instance_->isolate(), 1).As<Value>(), true },
49 { Number::New(instance_->isolate(), -1).As<Value>(), true }, 49 { Number::New(instance_->isolate(), -1).As<Value>(), true },
50 { Number::New(instance_->isolate(), 0.1).As<Value>(), true }, 50 { Number::New(instance_->isolate(), 0.1).As<Value>(), true },
51 { String::NewFromUtf8(instance_->isolate(), "").As<Value>(), false }, 51 { String::NewFromUtf8(instance_->isolate(), "").As<Value>(), false },
52 { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), true }, 52 { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), true },
53 { Object::New(instance_->isolate()).As<Value>(), true }, 53 { Object::New(instance_->isolate()).As<Value>(), true },
54 { Null(instance_->isolate()).As<Value>(), false }, 54 { Null(instance_->isolate()).As<Value>(), false },
55 { Undefined(instance_->isolate()).As<Value>(), false }, 55 { Undefined(instance_->isolate()).As<Value>(), false },
56 }; 56 };
57 57
58 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 58 for (size_t i = 0; i < arraysize(test_data); ++i) {
59 bool result = false; 59 bool result = false;
60 EXPECT_TRUE(Converter<bool>::FromV8(instance_->isolate(), 60 EXPECT_TRUE(Converter<bool>::FromV8(instance_->isolate(),
61 test_data[i].input, &result)); 61 test_data[i].input, &result));
62 EXPECT_EQ(test_data[i].expected, result); 62 EXPECT_EQ(test_data[i].expected, result);
63 63
64 result = true; 64 result = true;
65 EXPECT_TRUE(Converter<bool>::FromV8(instance_->isolate(), 65 EXPECT_TRUE(Converter<bool>::FromV8(instance_->isolate(),
66 test_data[i].input, &result)); 66 test_data[i].input, &result));
67 EXPECT_EQ(test_data[i].expected, result); 67 EXPECT_EQ(test_data[i].expected, result);
68 } 68 }
69 } 69 }
70 70
71 TEST_F(ConverterTest, Int32) { 71 TEST_F(ConverterTest, Int32) {
72 HandleScope handle_scope(instance_->isolate()); 72 HandleScope handle_scope(instance_->isolate());
73 73
74 int test_data_to[] = {-1, 0, 1}; 74 int test_data_to[] = {-1, 0, 1};
75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data_to); ++i) { 75 for (size_t i = 0; i < arraysize(test_data_to); ++i) {
76 EXPECT_TRUE(Converter<int32_t>::ToV8(instance_->isolate(), test_data_to[i]) 76 EXPECT_TRUE(Converter<int32_t>::ToV8(instance_->isolate(), test_data_to[i])
77 ->StrictEquals( 77 ->StrictEquals(
78 Integer::New(instance_->isolate(), test_data_to[i]))); 78 Integer::New(instance_->isolate(), test_data_to[i])));
79 } 79 }
80 80
81 struct { 81 struct {
82 v8::Handle<v8::Value> input; 82 v8::Handle<v8::Value> input;
83 bool expect_sucess; 83 bool expect_sucess;
84 int expected_result; 84 int expected_result;
85 } test_data_from[] = { 85 } test_data_from[] = {
86 { Boolean::New(instance_->isolate(), false).As<Value>(), false, 0 }, 86 { Boolean::New(instance_->isolate(), false).As<Value>(), false, 0 },
87 { Boolean::New(instance_->isolate(), true).As<Value>(), false, 0 }, 87 { Boolean::New(instance_->isolate(), true).As<Value>(), false, 0 },
88 { Integer::New(instance_->isolate(), -1).As<Value>(), true, -1 }, 88 { Integer::New(instance_->isolate(), -1).As<Value>(), true, -1 },
89 { Integer::New(instance_->isolate(), 0).As<Value>(), true, 0 }, 89 { Integer::New(instance_->isolate(), 0).As<Value>(), true, 0 },
90 { Integer::New(instance_->isolate(), 1).As<Value>(), true, 1 }, 90 { Integer::New(instance_->isolate(), 1).As<Value>(), true, 1 },
91 { Number::New(instance_->isolate(), -1).As<Value>(), true, -1 }, 91 { Number::New(instance_->isolate(), -1).As<Value>(), true, -1 },
92 { Number::New(instance_->isolate(), 1.1).As<Value>(), false, 0 }, 92 { Number::New(instance_->isolate(), 1.1).As<Value>(), false, 0 },
93 { String::NewFromUtf8(instance_->isolate(), "42").As<Value>(), false, 0 }, 93 { String::NewFromUtf8(instance_->isolate(), "42").As<Value>(), false, 0 },
94 { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), false, 0 }, 94 { String::NewFromUtf8(instance_->isolate(), "foo").As<Value>(), false, 0 },
95 { Object::New(instance_->isolate()).As<Value>(), false, 0 }, 95 { Object::New(instance_->isolate()).As<Value>(), false, 0 },
96 { Array::New(instance_->isolate()).As<Value>(), false, 0 }, 96 { Array::New(instance_->isolate()).As<Value>(), false, 0 },
97 { v8::Null(instance_->isolate()).As<Value>(), false, 0 }, 97 { v8::Null(instance_->isolate()).As<Value>(), false, 0 },
98 { v8::Undefined(instance_->isolate()).As<Value>(), false, 0 }, 98 { v8::Undefined(instance_->isolate()).As<Value>(), false, 0 },
99 }; 99 };
100 100
101 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data_from); ++i) { 101 for (size_t i = 0; i < arraysize(test_data_from); ++i) {
102 int32_t result = std::numeric_limits<int32_t>::min(); 102 int32_t result = std::numeric_limits<int32_t>::min();
103 bool success = Converter<int32_t>::FromV8(instance_->isolate(), 103 bool success = Converter<int32_t>::FromV8(instance_->isolate(),
104 test_data_from[i].input, &result); 104 test_data_from[i].input, &result);
105 EXPECT_EQ(test_data_from[i].expect_sucess, success) << i; 105 EXPECT_EQ(test_data_from[i].expect_sucess, success) << i;
106 if (success) 106 if (success)
107 EXPECT_EQ(test_data_from[i].expected_result, result) << i; 107 EXPECT_EQ(test_data_from[i].expected_result, result) << i;
108 } 108 }
109 } 109 }
110 110
111 TEST_F(ConverterTest, Vector) { 111 TEST_F(ConverterTest, Vector) {
(...skipping 13 matching lines...) Expand all
125 ->StrictEquals(js_array->Get(static_cast<int>(i)))); 125 ->StrictEquals(js_array->Get(static_cast<int>(i))));
126 } 126 }
127 127
128 std::vector<int> actual; 128 std::vector<int> actual;
129 EXPECT_TRUE(Converter<std::vector<int> >::FromV8(instance_->isolate(), 129 EXPECT_TRUE(Converter<std::vector<int> >::FromV8(instance_->isolate(),
130 js_array, &actual)); 130 js_array, &actual));
131 EXPECT_EQ(expected, actual); 131 EXPECT_EQ(expected, actual);
132 } 132 }
133 133
134 } // namespace gin 134 } // namespace gin
OLDNEW
« no previous file with comments | « device/hid/hid_report_descriptor_unittest.cc ('k') | google_apis/drive/drive_api_url_generator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698