OLD | NEW |
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 #if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) | 5 #if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS) |
6 #include <mmintrin.h> | 6 #include <mmintrin.h> |
7 #endif | 7 #endif |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 // Since that's intentional, we need to shut this warning off. | 555 // Since that's intentional, we need to shut this warning off. |
556 #if defined(COMPILER_MSVC) | 556 #if defined(COMPILER_MSVC) |
557 #pragma warning(disable : 4756) | 557 #pragma warning(disable : 4756) |
558 #endif | 558 #endif |
559 | 559 |
560 int small_positive = 1; | 560 int small_positive = 1; |
561 int small_negative = -1; | 561 int small_negative = -1; |
562 double double_small = 1.0; | 562 double double_small = 1.0; |
563 double double_large = numeric_limits<double>::max(); | 563 double double_large = numeric_limits<double>::max(); |
564 double double_infinity = numeric_limits<float>::infinity(); | 564 double double_infinity = numeric_limits<float>::infinity(); |
| 565 double double_large_int = numeric_limits<int>::max(); |
| 566 double double_small_int = numeric_limits<int>::min(); |
565 | 567 |
566 // Just test that the casts compile, since the other tests cover logic. | 568 // Just test that the casts compile, since the other tests cover logic. |
567 EXPECT_EQ(0, checked_cast<int>(static_cast<size_t>(0))); | 569 EXPECT_EQ(0, checked_cast<int>(static_cast<size_t>(0))); |
568 EXPECT_EQ(0, strict_cast<int>(static_cast<char>(0))); | 570 EXPECT_EQ(0, strict_cast<int>(static_cast<char>(0))); |
569 EXPECT_EQ(0, strict_cast<int>(static_cast<unsigned char>(0))); | 571 EXPECT_EQ(0, strict_cast<int>(static_cast<unsigned char>(0))); |
570 EXPECT_EQ(0U, strict_cast<unsigned>(static_cast<unsigned char>(0))); | 572 EXPECT_EQ(0U, strict_cast<unsigned>(static_cast<unsigned char>(0))); |
571 EXPECT_EQ(1ULL, static_cast<uint64_t>(StrictNumeric<size_t>(1U))); | 573 EXPECT_EQ(1ULL, static_cast<uint64_t>(StrictNumeric<size_t>(1U))); |
572 EXPECT_EQ(1ULL, static_cast<uint64_t>(SizeT(1U))); | 574 EXPECT_EQ(1ULL, static_cast<uint64_t>(SizeT(1U))); |
573 EXPECT_EQ(1U, static_cast<size_t>(StrictNumeric<unsigned>(1U))); | 575 EXPECT_EQ(1U, static_cast<size_t>(StrictNumeric<unsigned>(1U))); |
574 | 576 |
(...skipping 12 matching lines...) Expand all Loading... |
587 static_cast<int>(small_negative)); | 589 static_cast<int>(small_negative)); |
588 EXPECT_EQ(saturated_cast<int>(small_positive), | 590 EXPECT_EQ(saturated_cast<int>(small_positive), |
589 static_cast<int>(small_positive)); | 591 static_cast<int>(small_positive)); |
590 EXPECT_EQ(saturated_cast<unsigned>(small_negative), | 592 EXPECT_EQ(saturated_cast<unsigned>(small_negative), |
591 static_cast<unsigned>(0)); | 593 static_cast<unsigned>(0)); |
592 EXPECT_EQ(saturated_cast<int>(double_small), | 594 EXPECT_EQ(saturated_cast<int>(double_small), |
593 static_cast<int>(double_small)); | 595 static_cast<int>(double_small)); |
594 EXPECT_EQ(saturated_cast<int>(double_large), numeric_limits<int>::max()); | 596 EXPECT_EQ(saturated_cast<int>(double_large), numeric_limits<int>::max()); |
595 EXPECT_EQ(saturated_cast<float>(double_large), double_infinity); | 597 EXPECT_EQ(saturated_cast<float>(double_large), double_infinity); |
596 EXPECT_EQ(saturated_cast<float>(-double_large), -double_infinity); | 598 EXPECT_EQ(saturated_cast<float>(-double_large), -double_infinity); |
| 599 EXPECT_EQ(numeric_limits<int>::min(), saturated_cast<int>(double_small_int)); |
| 600 EXPECT_EQ(numeric_limits<int>::max(), saturated_cast<int>(double_large_int)); |
597 } | 601 } |
598 | 602 |
OLD | NEW |