20 #include "gtest/gtest.h" 28 struct marshall {
char buf[N]; };
31 void TestMarshall(
const T values[],
int num_values) {
32 for (
int i = 0;
i < num_values; ++
i) {
37 ASSERT_EQ(0, memcmp(&t0, &t1,
sizeof(T)));
38 ASSERT_EQ(0, memcmp(&m0, &m1,
sizeof(T)));
50 template <
typename T,
typename I>
51 void TestIntegral(
const T values[],
int num_values) {
52 for (
int i = 0;
i < num_values; ++
i) {
57 ASSERT_EQ(0, memcmp(&t0, &t1,
sizeof(T)));
63 static const bool bool_list[] = {
false,
true };
67 TEST(BitCast, Int32) {
68 static const int32_t int_list[] =
69 { 0, 1, 100, 2147483647, -1, -100, -2147483647, -2147483647-1 };
73 TEST(BitCast, Int64) {
74 static const int64_t int64_list[] =
75 { 0, 1, 1LL << 40, -1, -(1LL<<40) };
79 TEST(BitCast, Uint64) {
80 static const uint64_t uint64_list[] =
81 { 0, 1, 1LLU << 40, 1LLU << 63 };
85 TEST(BitCast, Float) {
86 static const float float_list[] =
87 { 0.0f, 1.0f, -1.0f, 10.0f, -10.0f,
88 1e10f, 1e20f, 1e-10f, 1e-20f,
92 TestIntegral<float, unsigned>(float_list,
ABSL_ARRAYSIZE(float_list));
95 TEST(BitCast, Double) {
96 static const double double_list[] =
97 { 0.0, 1.0, -1.0, 10.0, -10.0,
98 1e10, 1e100, 1e-10, 1e-100,
100 3.141592653589793238462643383279502884197169399375105820974944 };
102 TestIntegral<double, int64_t>(double_list,
ABSL_ARRAYSIZE(double_list));
103 TestIntegral<double, uint64_t>(double_list,
ABSL_ARRAYSIZE(double_list));
TEST(NotificationTest, SanityTest)
Dest bit_cast(const Source &source)
#define ABSL_ARRAYSIZE(array)