OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 "chromeos/network/shill_property_util.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "third_party/cros_system_api/dbus/service_constants.h" | |
9 | |
10 namespace chromeos { | |
11 | |
12 namespace { | |
13 | |
14 class NetworkTypePatternTest : public testing::Test { | |
15 public: | |
16 NetworkTypePatternTest() | |
17 : cellular_(NetworkTypePattern::Cellular()), | |
18 default_(NetworkTypePattern::Default()), | |
19 ethernet_(NetworkTypePattern::Ethernet()), | |
20 mobile_(NetworkTypePattern::Mobile()), | |
21 non_virtual_(NetworkTypePattern::NonVirtual()), | |
22 wimax_(NetworkTypePattern::Wimax()), | |
23 wireless_(NetworkTypePattern::Wireless()) {} | |
24 | |
25 bool MatchesPattern(const NetworkTypePattern& a, | |
26 const NetworkTypePattern& b) { | |
27 // Verify that NetworkTypePattern::MatchesPattern is symmetric. | |
28 EXPECT_TRUE(a.MatchesPattern(b) == b.MatchesPattern(a)); | |
29 return a.MatchesPattern(b); | |
30 } | |
31 | |
32 protected: | |
33 const NetworkTypePattern cellular_; | |
34 const NetworkTypePattern default_; | |
35 const NetworkTypePattern ethernet_; | |
36 const NetworkTypePattern mobile_; | |
37 const NetworkTypePattern non_virtual_; | |
38 const NetworkTypePattern wimax_; | |
39 const NetworkTypePattern wireless_; | |
40 }; | |
41 | |
42 } // namespace | |
43 | |
44 TEST_F(NetworkTypePatternTest, MatchesType) { | |
45 EXPECT_TRUE(mobile_.MatchesType(flimflam::kTypeCellular)); | |
46 EXPECT_TRUE(mobile_.MatchesType(flimflam::kTypeWimax)); | |
47 EXPECT_FALSE(mobile_.MatchesType(flimflam::kTypeWifi)); | |
48 | |
49 EXPECT_TRUE(wireless_.MatchesType(flimflam::kTypeWifi)); | |
stevenjb
2013/09/04 20:40:39
We should check that wireless_ also matches Cellul
pneubeck (no reviews)
2013/09/05 08:28:34
Done.
| |
50 EXPECT_FALSE(wireless_.MatchesType(flimflam::kTypeEthernet)); | |
51 } | |
52 | |
53 TEST_F(NetworkTypePatternTest, MatchesPattern) { | |
54 // Each pair of {Mobile, Wireless, Cellular} is matching. Matching is | |
55 // reflexive. | |
56 EXPECT_TRUE(MatchesPattern(mobile_, mobile_)); | |
57 EXPECT_TRUE(MatchesPattern(wireless_, wireless_)); | |
58 | |
59 EXPECT_TRUE(MatchesPattern(mobile_, wireless_)); | |
60 EXPECT_TRUE(MatchesPattern(mobile_, cellular_)); | |
61 EXPECT_TRUE(MatchesPattern(wireless_, cellular_)); | |
stevenjb
2013/09/04 20:40:39
Maybe check symmetry too: (wireless_, mobile_), (c
pneubeck (no reviews)
2013/09/05 08:28:34
That's what MatchesPattern of the test fixture doe
stevenjb
2013/09/05 17:17:23
Oh, right, I missed that.
| |
62 | |
63 // Cellular matches NonVirtual. NonVirtual matches Ethernet. But Cellular | |
64 // doesn't match Ethernet. | |
65 EXPECT_TRUE(MatchesPattern(cellular_, non_virtual_)); | |
66 EXPECT_TRUE(MatchesPattern(non_virtual_, ethernet_)); | |
67 EXPECT_FALSE(MatchesPattern(cellular_, ethernet_)); | |
68 | |
69 // Default matches anything. | |
70 EXPECT_TRUE(MatchesPattern(default_, default_)); | |
71 EXPECT_TRUE(MatchesPattern(default_, non_virtual_)); | |
72 EXPECT_TRUE(MatchesPattern(default_, cellular_)); | |
73 } | |
74 | |
75 TEST_F(NetworkTypePatternTest, Equals) { | |
76 EXPECT_TRUE(mobile_.Equals(mobile_)); | |
77 EXPECT_FALSE(mobile_.Equals(cellular_)); | |
78 EXPECT_FALSE(cellular_.Equals(mobile_)); | |
79 } | |
80 | |
81 TEST_F(NetworkTypePatternTest, Primitive) { | |
82 const NetworkTypePattern primitive_cellular = | |
83 NetworkTypePattern::Primitive(flimflam::kTypeCellular); | |
84 EXPECT_TRUE(cellular_.Equals(primitive_cellular)); | |
85 EXPECT_TRUE(primitive_cellular.Equals(cellular_)); | |
86 | |
87 const NetworkTypePattern primitive_wimax = | |
88 NetworkTypePattern::Primitive(flimflam::kTypeWimax); | |
89 EXPECT_TRUE(wimax_.Equals(primitive_wimax)); | |
90 EXPECT_TRUE(primitive_wimax.Equals(wimax_)); | |
91 } | |
92 | |
93 TEST_F(NetworkTypePatternTest, ToDebugString) { | |
94 EXPECT_EQ(default_.ToDebugString(), "PatternDefault"); | |
95 EXPECT_EQ(mobile_.ToDebugString(), "PatternMobile"); | |
96 EXPECT_EQ(cellular_.ToDebugString(), "cellular"); | |
97 } | |
98 | |
99 } // namespace chromeos | |
OLD | NEW |