Less strict CHECK for DeviceCapabilities results.
[chromium-blink-merge.git] / chromeos / network / shill_property_util_unittest.cc
blob2d8b764232c5d914c3195d12669829eeb0da8b96
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.
5 #include "chromeos/network/shill_property_util.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/cros_system_api/dbus/service_constants.h"
10 namespace chromeos {
12 namespace {
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()) {}
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);
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_;
42 } // namespace
44 TEST_F(NetworkTypePatternTest, MatchesType) {
45 EXPECT_TRUE(mobile_.MatchesType(shill::kTypeCellular));
46 EXPECT_TRUE(mobile_.MatchesType(shill::kTypeWimax));
47 EXPECT_FALSE(mobile_.MatchesType(shill::kTypeWifi));
49 EXPECT_TRUE(wireless_.MatchesType(shill::kTypeWifi));
50 EXPECT_TRUE(wireless_.MatchesType(shill::kTypeCellular));
51 EXPECT_TRUE(wireless_.MatchesType(shill::kTypeWimax));
52 EXPECT_FALSE(wireless_.MatchesType(shill::kTypeEthernet));
55 TEST_F(NetworkTypePatternTest, MatchesPattern) {
56 // Each pair of {Mobile, Wireless, Cellular} is matching. Matching is
57 // reflexive and symmetric (checked in MatchesPattern).
58 EXPECT_TRUE(MatchesPattern(mobile_, mobile_));
59 EXPECT_TRUE(MatchesPattern(wireless_, wireless_));
60 EXPECT_TRUE(MatchesPattern(cellular_, cellular_));
62 EXPECT_TRUE(MatchesPattern(mobile_, wireless_));
63 EXPECT_TRUE(MatchesPattern(mobile_, cellular_));
64 EXPECT_TRUE(MatchesPattern(wireless_, cellular_));
66 // Cellular matches NonVirtual. NonVirtual matches Ethernet. But Cellular
67 // doesn't match Ethernet.
68 EXPECT_TRUE(MatchesPattern(cellular_, non_virtual_));
69 EXPECT_TRUE(MatchesPattern(non_virtual_, ethernet_));
70 EXPECT_FALSE(MatchesPattern(cellular_, ethernet_));
72 // Default matches anything.
73 EXPECT_TRUE(MatchesPattern(default_, default_));
74 EXPECT_TRUE(MatchesPattern(default_, non_virtual_));
75 EXPECT_TRUE(MatchesPattern(default_, cellular_));
78 TEST_F(NetworkTypePatternTest, Equals) {
79 EXPECT_TRUE(mobile_.Equals(mobile_));
80 EXPECT_FALSE(mobile_.Equals(cellular_));
81 EXPECT_FALSE(cellular_.Equals(mobile_));
84 TEST_F(NetworkTypePatternTest, Primitive) {
85 const NetworkTypePattern primitive_cellular =
86 NetworkTypePattern::Primitive(shill::kTypeCellular);
87 EXPECT_TRUE(cellular_.Equals(primitive_cellular));
88 EXPECT_TRUE(primitive_cellular.Equals(cellular_));
90 const NetworkTypePattern primitive_wimax =
91 NetworkTypePattern::Primitive(shill::kTypeWimax);
92 EXPECT_TRUE(wimax_.Equals(primitive_wimax));
93 EXPECT_TRUE(primitive_wimax.Equals(wimax_));
96 TEST_F(NetworkTypePatternTest, ToDebugString) {
97 EXPECT_EQ(default_.ToDebugString(), "PatternDefault");
98 EXPECT_EQ(mobile_.ToDebugString(), "PatternMobile");
99 EXPECT_EQ(cellular_.ToDebugString(), "cellular");
102 } // namespace chromeos