blob: f36d3fe64c4be8be109042ee73676bb0c25891ff [file] [log] [blame]
tsniatowski9b465ba2016-04-29 05:53:20 +09001// 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
3// found in the LICENSE file.
4
5
6#include "base/bit_cast.h"
7
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace base {
11namespace {
12
13TEST(BitCastTest, FloatIntFloat) {
14 float f = 3.1415926f;
15 int i = bit_cast<int32_t>(f);
16 float f2 = bit_cast<float>(i);
17 EXPECT_EQ(f, f2);
18}
19
20struct A {
21 int x;
22};
23
24TEST(BitCastTest, StructureInt) {
25 A a = { 1 };
26 int b = bit_cast<int>(a);
27 EXPECT_EQ(1, b);
28}
29
tsniatowski9b465ba2016-04-29 05:53:20 +090030} // namespace
31} // namespace base