1 // Copyright 2017 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 "mojo/core/ports/name.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace mojo {
10 namespace core {
11 namespace ports {
12 namespace test {
13
TEST(NameTest,Defaults)14 TEST(NameTest, Defaults) {
15 PortName default_port_name;
16 EXPECT_EQ(kInvalidPortName, default_port_name);
17
18 NodeName default_node_name;
19 EXPECT_EQ(kInvalidNodeName, default_node_name);
20 }
21
TEST(NameTest,PortNameChecks)22 TEST(NameTest, PortNameChecks) {
23 PortName port_name_a(50, 100);
24 PortName port_name_b(50, 100);
25 PortName port_name_c(100, 50);
26
27 EXPECT_EQ(port_name_a, port_name_b);
28 EXPECT_NE(port_name_a, port_name_c);
29 EXPECT_NE(port_name_b, port_name_c);
30
31 EXPECT_LT(port_name_a, port_name_c);
32 EXPECT_LT(port_name_b, port_name_c);
33 EXPECT_FALSE(port_name_a < port_name_b);
34 EXPECT_FALSE(port_name_b < port_name_a);
35
36 std::hash<PortName> port_hash_fn;
37
38 size_t hash_a = port_hash_fn(port_name_a);
39 size_t hash_b = port_hash_fn(port_name_b);
40 size_t hash_c = port_hash_fn(port_name_c);
41
42 EXPECT_EQ(hash_a, hash_b);
43 EXPECT_NE(hash_a, hash_c);
44 EXPECT_NE(hash_b, hash_c);
45 }
46
TEST(NameTest,NodeNameChecks)47 TEST(NameTest, NodeNameChecks) {
48 NodeName node_name_a(50, 100);
49 NodeName node_name_b(50, 100);
50 NodeName node_name_c(100, 50);
51
52 EXPECT_EQ(node_name_a, node_name_b);
53 EXPECT_NE(node_name_a, node_name_c);
54 EXPECT_NE(node_name_b, node_name_c);
55
56 EXPECT_LT(node_name_a, node_name_c);
57 EXPECT_LT(node_name_b, node_name_c);
58 EXPECT_FALSE(node_name_a < node_name_b);
59 EXPECT_FALSE(node_name_b < node_name_a);
60
61 std::hash<NodeName> node_hash_fn;
62
63 size_t hash_a = node_hash_fn(node_name_a);
64 size_t hash_b = node_hash_fn(node_name_b);
65 size_t hash_c = node_hash_fn(node_name_c);
66
67 EXPECT_EQ(hash_a, hash_b);
68 EXPECT_NE(hash_a, hash_c);
69 EXPECT_NE(hash_b, hash_c);
70 }
71
72 } // namespace test
73 } // namespace ports
74 } // namespace core
75 } // namespace mojo
76