config_test.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/base/config.h"
00016 
00017 #include <cstdint>
00018 
00019 #include "gtest/gtest.h"
00020 #include "absl/synchronization/internal/thread_pool.h"
00021 
00022 namespace {
00023 
00024 TEST(ConfigTest, Endianness) {
00025   union {
00026     uint32_t value;
00027     uint8_t data[sizeof(uint32_t)];
00028   } number;
00029   number.data[0] = 0x00;
00030   number.data[1] = 0x01;
00031   number.data[2] = 0x02;
00032   number.data[3] = 0x03;
00033 #if defined(ABSL_IS_LITTLE_ENDIAN) && defined(ABSL_IS_BIG_ENDIAN)
00034 #error Both ABSL_IS_LITTLE_ENDIAN and ABSL_IS_BIG_ENDIAN are defined
00035 #elif defined(ABSL_IS_LITTLE_ENDIAN)
00036   EXPECT_EQ(UINT32_C(0x03020100), number.value);
00037 #elif defined(ABSL_IS_BIG_ENDIAN)
00038   EXPECT_EQ(UINT32_C(0x00010203), number.value);
00039 #else
00040 #error Unknown endianness
00041 #endif
00042 }
00043 
00044 #if defined(ABSL_HAVE_THREAD_LOCAL)
00045 TEST(ConfigTest, ThreadLocal) {
00046   static thread_local int mine_mine_mine = 16;
00047   EXPECT_EQ(16, mine_mine_mine);
00048   {
00049     absl::synchronization_internal::ThreadPool pool(1);
00050     pool.Schedule([&] {
00051       EXPECT_EQ(16, mine_mine_mine);
00052       mine_mine_mine = 32;
00053       EXPECT_EQ(32, mine_mine_mine);
00054     });
00055   }
00056   EXPECT_EQ(16, mine_mine_mine);
00057 }
00058 #endif
00059 
00060 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14