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

Side by Side Diff: chrome/tools/profile_reset/jtl_compiler_unittest.cc

Issue 641363003: Convert ARRAYSIZE_UNSAFE -> arraysize in chrome/, outside of chrome/browser/. (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 "chrome/tools/profile_reset/jtl_compiler.h" 5 #include "chrome/tools/profile_reset/jtl_compiler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/profile_resetter/jtl_foundation.h" 10 #include "chrome/browser/profile_resetter/jtl_foundation.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 {"compare_to_stored_bool(\"name\").", 69 {"compare_to_stored_bool(\"name\").",
70 OP_COMPARE_NODE_TO_STORED_BOOL(GetHash("name"))}, 70 OP_COMPARE_NODE_TO_STORED_BOOL(GetHash("name"))},
71 {"compare_to_stored_hash(\"name\").", 71 {"compare_to_stored_hash(\"name\").",
72 OP_COMPARE_NODE_TO_STORED_HASH(GetHash("name"))}, 72 OP_COMPARE_NODE_TO_STORED_HASH(GetHash("name"))},
73 {"compare_substring_hashed(\"pattern\").", 73 {"compare_substring_hashed(\"pattern\").",
74 OP_COMPARE_NODE_SUBSTRING( 74 OP_COMPARE_NODE_SUBSTRING(
75 GetHash("pattern"), EncodeUint32(7), EncodeUint32(766))}, 75 GetHash("pattern"), EncodeUint32(7), EncodeUint32(766))},
76 {"break.", OP_STOP_EXECUTING_SENTENCE}, 76 {"break.", OP_STOP_EXECUTING_SENTENCE},
77 {"break;", OP_STOP_EXECUTING_SENTENCE + OP_END_OF_SENTENCE}}; 77 {"break;", OP_STOP_EXECUTING_SENTENCE + OP_END_OF_SENTENCE}};
78 78
79 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 79 for (size_t i = 0; i < arraysize(cases); ++i) {
80 SCOPED_TRACE(cases[i].source_code); 80 SCOPED_TRACE(cases[i].source_code);
81 std::string bytecode; 81 std::string bytecode;
82 EXPECT_TRUE(JtlCompiler::Compile( 82 EXPECT_TRUE(JtlCompiler::Compile(
83 cases[i].source_code, kTestHashSeed, &bytecode, NULL)); 83 cases[i].source_code, kTestHashSeed, &bytecode, NULL));
84 EXPECT_EQ(cases[i].expected_bytecode, bytecode); 84 EXPECT_EQ(cases[i].expected_bytecode, bytecode);
85 } 85 }
86 } 86 }
87 87
88 TEST(JtlCompiler, CompileEntireProgram) { 88 TEST(JtlCompiler, CompileEntireProgram) {
89 const char kSourceCode[] = 89 const char kSourceCode[] =
(...skipping 27 matching lines...) Expand all
117 EXPECT_EQ(2u, error.line_number); 117 EXPECT_EQ(2u, error.line_number);
118 EXPECT_EQ(JtlCompiler::CompileError::INVALID_OPERATION_NAME, 118 EXPECT_EQ(JtlCompiler::CompileError::INVALID_OPERATION_NAME,
119 error.error_code); 119 error.error_code);
120 } 120 }
121 121
122 TEST(JtlCompiler, InvalidArgumentsCount) { 122 TEST(JtlCompiler, InvalidArgumentsCount) {
123 const char* kSourceCodes[] = { 123 const char* kSourceCodes[] = {
124 "any().\nstore_bool(\"name\", true, \"superfluous argument\");\n", 124 "any().\nstore_bool(\"name\", true, \"superfluous argument\");\n",
125 "any().\nstore_bool(\"name\");"}; // missing argument 125 "any().\nstore_bool(\"name\");"}; // missing argument
126 126
127 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSourceCodes); ++i) { 127 for (size_t i = 0; i < arraysize(kSourceCodes); ++i) {
128 SCOPED_TRACE(kSourceCodes[i]); 128 SCOPED_TRACE(kSourceCodes[i]);
129 std::string bytecode; 129 std::string bytecode;
130 JtlCompiler::CompileError error; 130 JtlCompiler::CompileError error;
131 EXPECT_FALSE(JtlCompiler::Compile( 131 EXPECT_FALSE(JtlCompiler::Compile(
132 kSourceCodes[i], kTestHashSeed, &bytecode, &error)); 132 kSourceCodes[i], kTestHashSeed, &bytecode, &error));
133 EXPECT_THAT(error.context, testing::StartsWith("store_bool")); 133 EXPECT_THAT(error.context, testing::StartsWith("store_bool"));
134 EXPECT_EQ(1u, error.line_number); 134 EXPECT_EQ(1u, error.line_number);
135 EXPECT_EQ(JtlCompiler::CompileError::INVALID_ARGUMENT_COUNT, 135 EXPECT_EQ(JtlCompiler::CompileError::INVALID_ARGUMENT_COUNT,
136 error.error_code); 136 error.error_code);
137 } 137 }
(...skipping 10 matching lines...) Expand all
148 {"compare_hashed", "any()\n.\ncompare_hashed(false);"}, 148 {"compare_hashed", "any()\n.\ncompare_hashed(false);"},
149 {"store_hash", "any()\n.\nstore_hash(\"name\", false);"}, 149 {"store_hash", "any()\n.\nstore_hash(\"name\", false);"},
150 {"store_hash", "any()\n.\nstore_hash(\"name\", \"foo\");"}, 150 {"store_hash", "any()\n.\nstore_hash(\"name\", \"foo\");"},
151 {"compare_stored_bool", 151 {"compare_stored_bool",
152 "any()\n.\ncompare_stored_bool(\"name\", \"need a bool\", false);"}, 152 "any()\n.\ncompare_stored_bool(\"name\", \"need a bool\", false);"},
153 {"compare_stored_bool", 153 {"compare_stored_bool",
154 "any()\n.\ncompare_stored_bool(\"name\", false, \"need a bool\");"}, 154 "any()\n.\ncompare_stored_bool(\"name\", false, \"need a bool\");"},
155 {"compare_substring_hashed", 155 {"compare_substring_hashed",
156 "any()\n.\ncompare_substring_hashed(true);"}}; 156 "any()\n.\ncompare_substring_hashed(true);"}};
157 157
158 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 158 for (size_t i = 0; i < arraysize(cases); ++i) {
159 SCOPED_TRACE(cases[i].source_code); 159 SCOPED_TRACE(cases[i].source_code);
160 std::string bytecode; 160 std::string bytecode;
161 JtlCompiler::CompileError error; 161 JtlCompiler::CompileError error;
162 EXPECT_FALSE(JtlCompiler::Compile( 162 EXPECT_FALSE(JtlCompiler::Compile(
163 cases[i].source_code, kTestHashSeed, &bytecode, &error)); 163 cases[i].source_code, kTestHashSeed, &bytecode, &error));
164 EXPECT_THAT(error.context, 164 EXPECT_THAT(error.context,
165 testing::StartsWith(cases[i].expected_context_prefix)); 165 testing::StartsWith(cases[i].expected_context_prefix));
166 EXPECT_EQ(2u, error.line_number); 166 EXPECT_EQ(2u, error.line_number);
167 EXPECT_EQ(JtlCompiler::CompileError::INVALID_ARGUMENT_TYPE, 167 EXPECT_EQ(JtlCompiler::CompileError::INVALID_ARGUMENT_TYPE,
168 error.error_code); 168 error.error_code);
169 } 169 }
170 } 170 }
171 171
172 TEST(JtlCompiler, InvalidArgumentValue) { 172 TEST(JtlCompiler, InvalidArgumentValue) {
173 struct TestCase { 173 struct TestCase {
174 std::string expected_context_prefix; 174 std::string expected_context_prefix;
175 std::string source_code; 175 std::string source_code;
176 } cases[] = { 176 } cases[] = {
177 {"compare_substring_hashed", "compare_substring_hashed(\"\");"}}; 177 {"compare_substring_hashed", "compare_substring_hashed(\"\");"}};
178 178
179 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 179 for (size_t i = 0; i < arraysize(cases); ++i) {
180 SCOPED_TRACE(cases[i].source_code); 180 SCOPED_TRACE(cases[i].source_code);
181 std::string bytecode; 181 std::string bytecode;
182 JtlCompiler::CompileError error; 182 JtlCompiler::CompileError error;
183 EXPECT_FALSE(JtlCompiler::Compile( 183 EXPECT_FALSE(JtlCompiler::Compile(
184 cases[i].source_code, kTestHashSeed, &bytecode, &error)); 184 cases[i].source_code, kTestHashSeed, &bytecode, &error));
185 EXPECT_THAT(error.context, 185 EXPECT_THAT(error.context,
186 testing::StartsWith(cases[i].expected_context_prefix)); 186 testing::StartsWith(cases[i].expected_context_prefix));
187 EXPECT_EQ(0u, error.line_number); 187 EXPECT_EQ(0u, error.line_number);
188 EXPECT_EQ(JtlCompiler::CompileError::INVALID_ARGUMENT_VALUE, 188 EXPECT_EQ(JtlCompiler::CompileError::INVALID_ARGUMENT_VALUE,
189 error.error_code); 189 error.error_code);
(...skipping 18 matching lines...) Expand all
208 std::string bytecode; 208 std::string bytecode;
209 JtlCompiler::CompileError error; 209 JtlCompiler::CompileError error;
210 EXPECT_FALSE( 210 EXPECT_FALSE(
211 JtlCompiler::Compile(kSourceCode, kTestHashSeed, &bytecode, &error)); 211 JtlCompiler::Compile(kSourceCode, kTestHashSeed, &bytecode, &error));
212 EXPECT_THAT(error.context, testing::StartsWith("go")); 212 EXPECT_THAT(error.context, testing::StartsWith("go"));
213 EXPECT_EQ(1u, error.line_number); 213 EXPECT_EQ(1u, error.line_number);
214 EXPECT_EQ(JtlCompiler::CompileError::PARSING_ERROR, error.error_code); 214 EXPECT_EQ(JtlCompiler::CompileError::PARSING_ERROR, error.error_code);
215 } 215 }
216 216
217 } // namespace 217 } // namespace
OLDNEW
« no previous file with comments | « chrome/tools/convert_dict/convert_dict_unittest.cc ('k') | chrome/tools/profile_reset/jtl_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698