OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 TEST(SequenceCollectorRegression) { | 211 TEST(SequenceCollectorRegression) { |
212 SequenceCollector<char> collector(16); | 212 SequenceCollector<char> collector(16); |
213 collector.StartSequence(); | 213 collector.StartSequence(); |
214 collector.Add('0'); | 214 collector.Add('0'); |
215 collector.AddBlock( | 215 collector.AddBlock( |
216 i::Vector<const char>("12345678901234567890123456789012", 32)); | 216 i::Vector<const char>("12345678901234567890123456789012", 32)); |
217 i::Vector<char> seq = collector.EndSequence(); | 217 i::Vector<char> seq = collector.EndSequence(); |
218 CHECK_EQ(0, strncmp("0123456789012345678901234567890123", | 218 CHECK_EQ(0, strncmp("0123456789012345678901234567890123", |
219 seq.start(), seq.length())); | 219 seq.start(), seq.length())); |
220 } | 220 } |
| 221 |
| 222 |
| 223 #define MAX_VALUE(type) std::numeric_limits<type>::max() |
| 224 |
| 225 TEST(OverflowChecks) { |
| 226 // int32_t |
| 227 CHECK(!MultiplyOverflows<int32_t>(50, 50)); |
| 228 CHECK(MultiplyOverflows<int32_t>(MAX_VALUE(int32_t), 4)); |
| 229 |
| 230 CHECK(!AdditionOverflows<int32_t>(50, 50)); |
| 231 CHECK(!AdditionOverflows<int32_t>(MAX_VALUE(int32_t) - 1, 1)); |
| 232 CHECK(AdditionOverflows<int32_t>(MAX_VALUE(int32_t), 1)); |
| 233 |
| 234 // uint32_t |
| 235 CHECK(!MultiplyOverflows<uint32_t>(MAX_VALUE(int32_t), 2)); |
| 236 CHECK(MultiplyOverflows<uint32_t>(MAX_VALUE(int32_t), 4)); |
| 237 |
| 238 CHECK(!AdditionOverflows<uint32_t>(MAX_VALUE(int32_t), 1)); |
| 239 CHECK(AdditionOverflows<uint32_t>(MAX_VALUE(uint32_t), 1)); |
| 240 |
| 241 // signed char |
| 242 CHECK(AdditionOverflows<int8_t>(MAX_VALUE(int8_t), 1)); |
| 243 CHECK(MultiplyOverflows<int8_t>(64, 4)); |
| 244 |
| 245 // unsigned char |
| 246 CHECK(!AdditionOverflows<uint8_t>(MAX_VALUE(int8_t), 1)); |
| 247 CHECK(AdditionOverflows<uint8_t>(MAX_VALUE(uint8_t), 1)); |
| 248 CHECK(!MultiplyOverflows<uint8_t>(64, 3)); |
| 249 CHECK(MultiplyOverflows<uint8_t>(64, 4)); |
| 250 } |
OLD | NEW |