bit_cast_unittest.cc 584 B

12345678910111213141516171819202122232425262728293031
  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
  3. // found in the LICENSE file.
  4. #include "base/bit_cast.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace base {
  7. namespace {
  8. TEST(BitCastTest, FloatIntFloat) {
  9. float f = 3.1415926f;
  10. int i = bit_cast<int32_t>(f);
  11. float f2 = bit_cast<float>(i);
  12. EXPECT_EQ(f, f2);
  13. }
  14. struct A {
  15. int x;
  16. };
  17. TEST(BitCastTest, StructureInt) {
  18. A a = { 1 };
  19. int b = bit_cast<int>(a);
  20. EXPECT_EQ(1, b);
  21. }
  22. } // namespace
  23. } // namespace base