Peter Qiu | c0beca5 | 2015-09-03 11:25:46 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 16 | |
| 17 | #include "shill/service_under_test.h" |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | #include "shill/mock_adaptors.h" |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 22 | #include "shill/property_accessor.h" |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 23 | |
| 24 | using std::string; |
| 25 | |
| 26 | namespace shill { |
| 27 | |
| 28 | // static |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 29 | const char ServiceUnderTest::kKeyValueStoreProperty[] = "key_value_store"; |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 30 | const char ServiceUnderTest::kRpcId[] = "/mock_device_rpc"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 31 | const char ServiceUnderTest::kStringsProperty[] = "strings"; |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 32 | const char ServiceUnderTest::kStorageId[] = "service"; |
| 33 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 34 | ServiceUnderTest::ServiceUnderTest(ControlInterface* control_interface, |
| 35 | EventDispatcher* dispatcher, |
| 36 | Metrics* metrics, |
| 37 | Manager* manager) |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 38 | : Service(control_interface, dispatcher, metrics, manager, |
| 39 | Technology::kUnknown) { |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 40 | mutable_store()->RegisterStrings(kStringsProperty, &strings_); |
| 41 | mutable_store()->RegisterDerivedKeyValueStore( |
| 42 | kKeyValueStoreProperty, |
| 43 | KeyValueStoreAccessor( |
| 44 | new CustomAccessor<ServiceUnderTest, KeyValueStore>( |
| 45 | this, &ServiceUnderTest::GetKeyValueStore, |
| 46 | &ServiceUnderTest::SetKeyValueStore))); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | ServiceUnderTest::~ServiceUnderTest() {} |
| 50 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 51 | string ServiceUnderTest::GetRpcIdentifier() const { |
| 52 | return ServiceMockAdaptor::kRpcId; |
| 53 | } |
| 54 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 55 | string ServiceUnderTest::GetDeviceRpcId(Error* /*error*/) const { |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 56 | return kRpcId; |
| 57 | } |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 58 | |
| 59 | string ServiceUnderTest::GetStorageIdentifier() const { return kStorageId; } |
| 60 | |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 61 | bool ServiceUnderTest::SetKeyValueStore( |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 62 | const KeyValueStore& value, Error* error) { |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 63 | key_value_store_.Clear(); |
| 64 | key_value_store_.CopyFrom(value); |
| 65 | return true; |
| 66 | } |
| 67 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 68 | KeyValueStore ServiceUnderTest::GetKeyValueStore(Error* error) { |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 69 | return key_value_store_; |
| 70 | } |
| 71 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 72 | } // namespace shill |