OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 | 5 |
6 #include "base/bit_cast.h" | 6 #include "base/bit_cast.h" |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
11 namespace { | 11 namespace { |
12 | 12 |
13 TEST(BitCastTest, FloatIntFloat) { | 13 TEST(BitCastTest, FloatIntFloat) { |
14 float f = 3.1415926f; | 14 float f = 3.1415926f; |
15 int i = bit_cast<int32_t>(f); | 15 int i = bit_cast<int32_t>(f); |
16 float f2 = bit_cast<float>(i); | 16 float f2 = bit_cast<float>(i); |
17 EXPECT_EQ(f, f2); | 17 EXPECT_EQ(f, f2); |
18 } | 18 } |
19 | 19 |
20 struct A { | 20 struct A { |
21 int x; | 21 int x; |
22 }; | 22 }; |
23 | 23 |
24 TEST(BitCastTest, StructureInt) { | 24 TEST(BitCastTest, StructureInt) { |
25 A a = { 1 }; | 25 A a = { 1 }; |
26 int b = bit_cast<int>(a); | 26 int b = bit_cast<int>(a); |
27 EXPECT_EQ(1, b); | 27 EXPECT_EQ(1, b); |
28 } | 28 } |
29 | 29 |
30 | |
31 } // namespace | 30 } // namespace |
32 } // namespace base | 31 } // namespace base |
OLD | NEW |