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

Side by Side Diff: util/stdlib/string_number_conversion_test.cc

Issue 807463004: win: avoid warnings in string_number_conversion_test.cc (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 {"0x10", true, 16}, 46 {"0x10", true, 16},
47 {"-0x10", true, -16}, 47 {"-0x10", true, -16},
48 {"+0x20", true, 32}, 48 {"+0x20", true, 32},
49 {"0xf", true, 15}, 49 {"0xf", true, 15},
50 {"0xg", false, 0}, 50 {"0xg", false, 0},
51 {"0x7fffffff", true, std::numeric_limits<int>::max()}, 51 {"0x7fffffff", true, std::numeric_limits<int>::max()},
52 {"0x7FfFfFfF", true, std::numeric_limits<int>::max()}, 52 {"0x7FfFfFfF", true, std::numeric_limits<int>::max()},
53 {"0x80000000", false, 0}, 53 {"0x80000000", false, 0},
54 {"0xFFFFFFFF", false, 0}, 54 {"0xFFFFFFFF", false, 0},
55 {"-0x7fffffff", true, -2147483647}, 55 {"-0x7fffffff", true, -2147483647},
56 #if defined(COMPILER_MSVC)
Mark Mentovai 2014/12/16 14:17:47 build/build_config.h for this if it’s still necess
57 #pragma warning(push)
58 // Unary minus applied to unsigned type, result still unsigned.
59 #pragma warning(disable: 4146)
60 #endif
56 {"-0x80000000", true, -2147483648}, 61 {"-0x80000000", true, -2147483648},
Mark Mentovai 2014/12/16 14:17:47 Would static_cast<>() also silence the warning? I
scottmg 2014/12/16 17:53:56 Cast inside i.e. -static_cast<int>(2147483648) avo
62 #if defined(COMPILER_MSVC)
63 #pragma warning(pop)
64 #endif
57 {"-0x80000001", false, 0}, 65 {"-0x80000001", false, 0},
58 {"-0xffffffff", false, 0}, 66 {"-0xffffffff", false, 0},
59 {"0x100000000", false, 0}, 67 {"0x100000000", false, 0},
60 {"0xabcdef", true, 11259375}, 68 {"0xabcdef", true, 11259375},
61 {"010", true, 8}, 69 {"010", true, 8},
62 {"-010", true, -8}, 70 {"-010", true, -8},
63 {"+020", true, 16}, 71 {"+020", true, 16},
64 {"07", true, 7}, 72 {"07", true, 7},
65 {"08", false, 0}, 73 {"08", false, 0},
66 {" 0", false, 0}, 74 {" 0", false, 0},
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (valid) { 109 if (valid) {
102 EXPECT_EQ(kTestData[index].value, value) 110 EXPECT_EQ(kTestData[index].value, value)
103 << "index " << index << ", string " << kTestData[index].string; 111 << "index " << index << ", string " << kTestData[index].string;
104 } 112 }
105 } else { 113 } else {
106 EXPECT_FALSE(valid) << "index " << index << ", string " 114 EXPECT_FALSE(valid) << "index " << index << ", string "
107 << kTestData[index].string << ", value " << value; 115 << kTestData[index].string << ", value " << value;
108 } 116 }
109 } 117 }
110 118
111 // Ensure that embedded NUL characters are treated as bad input. 119 // Ensure that embedded NUL characters are treated as bad input. The string
112 const char input[] = "6\0006"; 120 // is split to avoid MSVC warning:
121 // "decimal digit terminates octal escape sequence".
122 const char input[] = "6\000" "6";
113 base::StringPiece input_string(input, arraysize(input) - 1); 123 base::StringPiece input_string(input, arraysize(input) - 1);
114 int output; 124 int output;
115 EXPECT_FALSE(StringToNumber(input_string, &output)); 125 EXPECT_FALSE(StringToNumber(input_string, &output));
116 126
117 // Ensure that a NUL is not required at the end of the string. 127 // Ensure that a NUL is not required at the end of the string.
118 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output)); 128 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output));
119 EXPECT_EQ(6, output); 129 EXPECT_EQ(6, output);
120 } 130 }
121 131
122 TEST(StringNumberConversion, StringToUnsignedInt) { 132 TEST(StringNumberConversion, StringToUnsignedInt) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (valid) { 207 if (valid) {
198 EXPECT_EQ(kTestData[index].value, value) 208 EXPECT_EQ(kTestData[index].value, value)
199 << "index " << index << ", string " << kTestData[index].string; 209 << "index " << index << ", string " << kTestData[index].string;
200 } 210 }
201 } else { 211 } else {
202 EXPECT_FALSE(valid) << "index " << index << ", string " 212 EXPECT_FALSE(valid) << "index " << index << ", string "
203 << kTestData[index].string << ", value " << value; 213 << kTestData[index].string << ", value " << value;
204 } 214 }
205 } 215 }
206 216
207 // Ensure that embedded NUL characters are treated as bad input. 217 // Ensure that embedded NUL characters are treated as bad input.
Mark Mentovai 2014/12/16 14:17:47 The existing comment was duplicated from above, so
scottmg 2014/12/16 17:53:56 Done.
208 const char input[] = "6\0006"; 218 const char input[] = "6\000" "6";
209 base::StringPiece input_string(input, arraysize(input) - 1); 219 base::StringPiece input_string(input, arraysize(input) - 1);
210 unsigned int output; 220 unsigned int output;
211 EXPECT_FALSE(StringToNumber(input_string, &output)); 221 EXPECT_FALSE(StringToNumber(input_string, &output));
212 222
213 // Ensure that a NUL is not required at the end of the string. 223 // Ensure that a NUL is not required at the end of the string.
214 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output)); 224 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output));
215 EXPECT_EQ(6u, output); 225 EXPECT_EQ(6u, output);
216 } 226 }
217 227
218 } // namespace 228 } // namespace
219 } // namespace test 229 } // namespace test
220 } // namespace crashpad 230 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698