OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <algorithm> // for min() | 7 #include <algorithm> // for min() |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } else { | 280 } else { |
281 EXPECT_NE(reinterpret_cast<void*>(NULL), p) << | 281 EXPECT_NE(reinterpret_cast<void*>(NULL), p) << |
282 "calloc(n, s) should succeed"; | 282 "calloc(n, s) should succeed"; |
283 for (int i = 0; i < n*s; i++) { | 283 for (int i = 0; i < n*s; i++) { |
284 EXPECT_EQ('\0', p[i]); | 284 EXPECT_EQ('\0', p[i]); |
285 } | 285 } |
286 free(p); | 286 free(p); |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
| 290 // MSVC C4530 complains about exception handler usage when exceptions are |
| 291 // disabled. Temporarily disable that warning so we can test that they are, in |
| 292 // fact, disabled. |
| 293 #if defined(OS_WIN) |
| 294 #pragma warning(push) |
| 295 #pragma warning(disable: 4530) |
| 296 #endif |
290 | 297 |
291 // A global test counter for number of times the NewHandler is called. | 298 // A global test counter for number of times the NewHandler is called. |
292 static int news_handled = 0; | 299 static int news_handled = 0; |
293 static void TestNewHandler() { | 300 static void TestNewHandler() { |
294 ++news_handled; | 301 ++news_handled; |
295 throw std::bad_alloc(); | 302 throw std::bad_alloc(); |
296 } | 303 } |
297 | 304 |
298 // Because we compile without exceptions, we expect these will not throw. | 305 // Because we compile without exceptions, we expect these will not throw. |
299 static void TestOneNewWithoutExceptions(void* (*func)(size_t), | 306 static void TestOneNewWithoutExceptions(void* (*func)(size_t), |
(...skipping 24 matching lines...) Expand all Loading... |
324 std::new_handler saved_handler = std::set_new_handler(0); | 331 std::new_handler saved_handler = std::set_new_handler(0); |
325 TestOneNewWithoutExceptions(func, false); | 332 TestOneNewWithoutExceptions(func, false); |
326 | 333 |
327 // test with new_handler: | 334 // test with new_handler: |
328 std::set_new_handler(TestNewHandler); | 335 std::set_new_handler(TestNewHandler); |
329 TestOneNewWithoutExceptions(func, true); | 336 TestOneNewWithoutExceptions(func, true); |
330 EXPECT_EQ(news_handled, 1) << "nothrow new_handler was not called."; | 337 EXPECT_EQ(news_handled, 1) << "nothrow new_handler was not called."; |
331 std::set_new_handler(saved_handler); | 338 std::set_new_handler(saved_handler); |
332 } | 339 } |
333 | 340 |
| 341 #if defined(OS_WIN) |
| 342 #pragma warning(pop) |
| 343 #endif |
| 344 |
334 } // namespace | 345 } // namespace |
335 | 346 |
336 //----------------------------------------------------------------------------- | 347 //----------------------------------------------------------------------------- |
337 | 348 |
338 TEST(Atomics, AtomicIncrementWord) { | 349 TEST(Atomics, AtomicIncrementWord) { |
339 TestAtomicIncrement<AtomicWord>(); | 350 TestAtomicIncrement<AtomicWord>(); |
340 } | 351 } |
341 | 352 |
342 TEST(Atomics, AtomicIncrement32) { | 353 TEST(Atomics, AtomicIncrement32) { |
343 TestAtomicIncrement<Atomic32>(); | 354 TestAtomicIncrement<Atomic32>(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 522 } |
512 } | 523 } |
513 | 524 |
514 #endif | 525 #endif |
515 | 526 |
516 | 527 |
517 int main(int argc, char** argv) { | 528 int main(int argc, char** argv) { |
518 testing::InitGoogleTest(&argc, argv); | 529 testing::InitGoogleTest(&argc, argv); |
519 return RUN_ALL_TESTS(); | 530 return RUN_ALL_TESTS(); |
520 } | 531 } |
OLD | NEW |