1 // Copyright 2015 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 #include <cmath>
6 
7 #include "base/strings/string_piece.h"
8 #include "mojo/public/interfaces/bindings/tests/test_constants.mojom.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace mojo {
12 namespace test {
13 
TEST(ConstantTest,GlobalConstants)14 TEST(ConstantTest, GlobalConstants) {
15   // Compile-time constants.
16   static_assert(kBoolValue == true, "");
17   static_assert(kInt8Value == -2, "");
18   static_assert(kUint8Value == 128U, "");
19   static_assert(kInt16Value == -233, "");
20   static_assert(kUint16Value == 44204U, "");
21   static_assert(kInt32Value == -44204, "");
22   static_assert(kUint32Value == 4294967295U, "");
23   static_assert(kInt64Value == -9223372036854775807, "");
24   static_assert(kUint64Value == 9999999999999999999ULL, "");
25   static_assert(kDoubleValue == 3.14159, "");
26   static_assert(kFloatValue == 2.71828f, "");
27 
28   EXPECT_EQ(base::StringPiece(kStringValue), "test string contents");
29   EXPECT_TRUE(std::isnan(kDoubleNaN));
30   EXPECT_TRUE(std::isinf(kDoubleInfinity));
31   EXPECT_TRUE(std::isinf(kDoubleNegativeInfinity));
32   EXPECT_NE(kDoubleInfinity, kDoubleNegativeInfinity);
33   EXPECT_TRUE(std::isnan(kFloatNaN));
34   EXPECT_TRUE(std::isinf(kFloatInfinity));
35   EXPECT_TRUE(std::isinf(kFloatNegativeInfinity));
36   EXPECT_NE(kFloatInfinity, kFloatNegativeInfinity);
37 }
38 
TEST(ConstantTest,StructConstants)39 TEST(ConstantTest, StructConstants) {
40   // Compile-time constants.
41   static_assert(StructWithConstants::kInt8Value == 5U, "");
42   static_assert(StructWithConstants::kFloatValue == 765.432f, "");
43 
44   EXPECT_EQ(base::StringPiece(StructWithConstants::kStringValue),
45             "struct test string contents");
46 }
47 
TEST(ConstantTest,InterfaceConstants)48 TEST(ConstantTest, InterfaceConstants) {
49   // Compile-time constants.
50   static_assert(InterfaceWithConstants::kUint32Value == 20100722, "");
51   static_assert(InterfaceWithConstants::kDoubleValue == 12.34567, "");
52 
53   EXPECT_EQ(base::StringPiece(InterfaceWithConstants::kStringValue),
54             "interface test string contents");
55   EXPECT_EQ(base::StringPiece(InterfaceWithConstants::Name_),
56             "mojo.test.InterfaceWithConstants");
57 }
58 
59 }  // namespace test
60 }  // namespace mojo
61