Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: mojo/public/cpp/bindings/tests/constant_unittest.cc

Issue 2637393002: Make mojom-generated C++ string constants really constant. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/test_constants.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cmath>
6
7 #include "base/strings/string_piece.h"
5 #include "mojo/public/interfaces/bindings/tests/test_constants.mojom.h" 8 #include "mojo/public/interfaces/bindings/tests/test_constants.mojom.h"
6 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
7 10
8 namespace mojo { 11 namespace mojo {
9 namespace test { 12 namespace test {
10 13
11 TEST(ConstantTest, GlobalConstants) { 14 TEST(ConstantTest, GlobalConstants) {
12 // Compile-time constants. 15 // Compile-time constants.
13 static_assert(kBoolValue == true, ""); 16 static_assert(kBoolValue == true, "");
14 static_assert(kInt8Value == -2, ""); 17 static_assert(kInt8Value == -2, "");
15 static_assert(kUint8Value == 128U, ""); 18 static_assert(kUint8Value == 128U, "");
16 static_assert(kInt16Value == -233, ""); 19 static_assert(kInt16Value == -233, "");
17 static_assert(kUint16Value == 44204U, ""); 20 static_assert(kUint16Value == 44204U, "");
18 static_assert(kInt32Value == -44204, ""); 21 static_assert(kInt32Value == -44204, "");
19 static_assert(kUint32Value == 4294967295U, ""); 22 static_assert(kUint32Value == 4294967295U, "");
20 static_assert(kInt64Value == -9223372036854775807, ""); 23 static_assert(kInt64Value == -9223372036854775807, "");
21 static_assert(kUint64Value == 9999999999999999999ULL, ""); 24 static_assert(kUint64Value == 9999999999999999999ULL, "");
25 static_assert(kDoubleValue == 3.14159, "");
26 static_assert(kFloatValue == 2.71828f, "");
22 27
23 EXPECT_DOUBLE_EQ(kDoubleValue, 3.14159); 28 EXPECT_EQ(base::StringPiece(kStringValue), "test string contents");
24 EXPECT_FLOAT_EQ(kFloatValue, 2.71828f); 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);
25 } 37 }
26 38
27 TEST(ConstantTest, StructConstants) { 39 TEST(ConstantTest, StructConstants) {
28 // Compile-time constants. 40 // Compile-time constants.
29 static_assert(StructWithConstants::kInt8Value == 5U, ""); 41 static_assert(StructWithConstants::kInt8Value == 5U, "");
42 static_assert(StructWithConstants::kFloatValue == 765.432f, "");
30 43
31 EXPECT_FLOAT_EQ(StructWithConstants::kFloatValue, 765.432f); 44 EXPECT_EQ(base::StringPiece(StructWithConstants::kStringValue),
45 "struct test string contents");
32 } 46 }
33 47
34 TEST(ConstantTest, InterfaceConstants) { 48 TEST(ConstantTest, InterfaceConstants) {
35 // Compile-time constants. 49 // Compile-time constants.
36 static_assert(InterfaceWithConstants::kUint32Value == 20100722, ""); 50 static_assert(InterfaceWithConstants::kUint32Value == 20100722, "");
51 static_assert(InterfaceWithConstants::kDoubleValue == 12.34567, "");
37 52
38 EXPECT_DOUBLE_EQ(InterfaceWithConstants::kDoubleValue, 12.34567); 53 EXPECT_EQ(base::StringPiece(InterfaceWithConstants::kStringValue),
54 "interface test string contents");
55 EXPECT_EQ(base::StringPiece(InterfaceWithConstants::Name_),
56 "mojo::test::InterfaceWithConstants");
39 } 57 }
40 58
41 } // namespace test 59 } // namespace test
42 } // namespace mojo 60 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/test_constants.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698