mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2013 The Chromium OS 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 "shill/service_property_change_test.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <chromeos/dbus/service_constants.h> |
| 10 | #include <gtest/gtest.h> |
| 11 | #include <gmock/gmock.h> |
| 12 | |
| 13 | #include "shill/error.h" |
| 14 | #include "shill/mock_adaptors.h" |
| 15 | #include "shill/service.h" |
| 16 | |
| 17 | using std::string; |
| 18 | using testing::_; |
| 19 | using testing::AnyNumber; |
| 20 | using testing::Mock; |
| 21 | |
| 22 | namespace shill { |
| 23 | |
| 24 | // Some of these tests are duplicative, as we also have broader tests |
| 25 | // for specific setters. However, it's convenient to have all the property |
| 26 | // change notifications documented (and tested) in one place. |
| 27 | |
| 28 | void TestCommonPropertyChanges(ServiceRefPtr service, |
| 29 | ServiceMockAdaptor *adaptor) { |
| 30 | Error error; |
| 31 | |
| 32 | EXPECT_EQ(Service::kStateIdle, service->state()); |
| 33 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 34 | service->SetState(Service::kStateConnected); |
| 35 | Mock::VerifyAndClearExpectations(adaptor); |
| 36 | |
| 37 | // TODO(quiche): Once crosbug.com/34528 is resolved, add a test |
| 38 | // that service->SetConnection emits kIPConfigProperty changed. |
| 39 | |
| 40 | bool connectable = service->connectable(); |
| 41 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kConnectableProperty, _)); |
| 42 | service->SetConnectable(!connectable); |
| 43 | Mock::VerifyAndClearExpectations(adaptor); |
| 44 | |
| 45 | EXPECT_EQ(string(), service->guid()); |
| 46 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kGuidProperty, _)); |
| 47 | service->SetGuid("some garbage", &error); |
| 48 | Mock::VerifyAndClearExpectations(adaptor); |
| 49 | |
| 50 | EXPECT_FALSE(service->favorite()); |
| 51 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kAutoConnectProperty, _)) |
| 52 | .Times(AnyNumber()); |
| 53 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kFavoriteProperty, _)); |
| 54 | service->MakeFavorite(); |
| 55 | Mock::VerifyAndClearExpectations(adaptor); |
| 56 | |
| 57 | EXPECT_EQ(0, service->priority()); |
| 58 | EXPECT_CALL(*adaptor, EmitIntChanged(flimflam::kPriorityProperty, _)); |
| 59 | service->SetPriority(1, &error); |
| 60 | Mock::VerifyAndClearExpectations(adaptor); |
| 61 | |
| 62 | EXPECT_EQ(string(), service->GetProxyConfig(&error)); |
| 63 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kProxyConfigProperty, _)); |
| 64 | service->SetProxyConfig("some garbage", &error); |
| 65 | Mock::VerifyAndClearExpectations(adaptor); |
| 66 | |
| 67 | uint8 strength = service->strength(); |
| 68 | EXPECT_CALL(*adaptor, |
| 69 | EmitUint8Changed(flimflam::kSignalStrengthProperty, _)); |
| 70 | service->SetStrength(strength+1); |
| 71 | Mock::VerifyAndClearExpectations(adaptor); |
| 72 | |
| 73 | EXPECT_EQ(string(), service->error_details()); |
| 74 | EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, _)); |
| 75 | service->SetErrorDetails("some garbage"); |
| 76 | Mock::VerifyAndClearExpectations(adaptor); |
| 77 | |
| 78 | EXPECT_EQ(Service::kFailureUnknown, service->failure()); |
| 79 | EXPECT_EQ(Service::ConnectFailureToString(Service::kFailureUnknown), |
| 80 | service->error()); |
| 81 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 82 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _)); |
| 83 | service->SetFailure(Service::kFailureAAA); |
| 84 | Mock::VerifyAndClearExpectations(adaptor); |
| 85 | |
| 86 | EXPECT_NE(Service::ConnectFailureToString(Service::kFailureUnknown), |
| 87 | service->error()); |
| 88 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 89 | EXPECT_CALL(*adaptor, EmitStringChanged(kErrorDetailsProperty, _)); |
| 90 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _)); |
| 91 | service->SetState(Service::kStateConnected); |
| 92 | Mock::VerifyAndClearExpectations(adaptor); |
| 93 | |
| 94 | EXPECT_EQ(Service::ConnectFailureToString(Service::kFailureUnknown), |
| 95 | service->error()); |
| 96 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kStateProperty, _)); |
| 97 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kErrorProperty, _)); |
| 98 | service->SetFailureSilent(Service::kFailureAAA); |
| 99 | Mock::VerifyAndClearExpectations(adaptor); |
| 100 | } |
| 101 | |
| 102 | void TestAutoConnectPropertyChange(ServiceRefPtr service, |
| 103 | ServiceMockAdaptor *adaptor) { |
| 104 | bool auto_connect = service->auto_connect(); |
| 105 | EXPECT_CALL(*adaptor, EmitBoolChanged(flimflam::kAutoConnectProperty, _)); |
| 106 | service->SetAutoConnect(!auto_connect); |
| 107 | Mock::VerifyAndClearExpectations(adaptor); |
| 108 | } |
| 109 | |
| 110 | void TestNamePropertyChange(ServiceRefPtr service, |
| 111 | ServiceMockAdaptor *adaptor) { |
| 112 | Error error; |
| 113 | string name = service->GetNameProperty(&error); |
| 114 | EXPECT_CALL(*adaptor, EmitStringChanged(flimflam::kNameProperty, _)); |
| 115 | service->SetNameProperty(name + " and some new stuff", &error); |
| 116 | Mock::VerifyAndClearExpectations(adaptor); |
| 117 | } |
| 118 | |
| 119 | } // namespace shill |