property_store_unittest.h revision bebf1b8bce52b88c2cc2d93200b9405f9c19cf21
1// Copyright (c) 2012 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#ifndef SHILL_PROPERTY_STORE_UNITTEST_H_ 6#define SHILL_PROPERTY_STORE_UNITTEST_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include <base/memory/scoped_ptr.h> 13#include <base/files/scoped_temp_dir.h> 14#include <dbus-c++/dbus.h> 15#include <gmock/gmock.h> 16#include <gtest/gtest.h> 17 18#include "shill/dbus_adaptor.h" 19#include "shill/error.h" 20#include "shill/event_dispatcher.h" 21#include "shill/manager.h" 22#include "shill/mock_control.h" 23#include "shill/mock_glib.h" 24#include "shill/mock_metrics.h" 25#include "shill/property_store.h" 26 27namespace shill { 28 29class PropertyStoreTest : public testing::TestWithParam< ::DBus::Variant > { 30 public: 31 // In real code, it's frowned upon to have non-POD static members, as there 32 // can be ordering issues if your constructors have side effects. 33 // These constructors don't, and declaring these as static lets me 34 // autogenerate a bunch of unit test code that I would otherwise need to 35 // copypaste. So I think it's safe and worth it. 36 static const ::DBus::Variant kBoolV; 37 static const ::DBus::Variant kByteV; 38 static const ::DBus::Variant kInt16V; 39 static const ::DBus::Variant kInt32V; 40 static const ::DBus::Variant kKeyValueStoreV; 41 static const ::DBus::Variant kStringV; 42 static const ::DBus::Variant kStringmapV; 43 static const ::DBus::Variant kStringmapsV; 44 static const ::DBus::Variant kStringsV; 45 static const ::DBus::Variant kUint16V; 46 static const ::DBus::Variant kUint32V; 47 static const ::DBus::Variant kUint64V; 48 49 PropertyStoreTest(); 50 virtual ~PropertyStoreTest(); 51 52 virtual void SetUp(); 53 MOCK_METHOD1(TestCallback, void(const std::string &property_name)); 54 55 protected: 56 Manager *manager() { return &manager_; } 57 MockControl *control_interface() { return &control_interface_; } 58 EventDispatcher *dispatcher() { return &dispatcher_; } 59 MockGLib *glib() { return &glib_; } 60 MockMetrics *metrics() { return &metrics_; } 61 62 const std::string &run_path() const { return path_; } 63 const std::string &storage_path() const { return path_; } 64 65 const std::string &internal_error() const { return internal_error_; } 66 const std::string &invalid_args() const { return invalid_args_; } 67 const std::string &invalid_prop() const { return invalid_prop_; } 68 69 private: 70 const std::string internal_error_; 71 const std::string invalid_args_; 72 const std::string invalid_prop_; 73 base::ScopedTempDir dir_; 74 const std::string path_; 75 MockControl control_interface_; 76 EventDispatcher dispatcher_; 77 testing::NiceMock<MockMetrics> metrics_; 78 MockGLib glib_; 79 Manager manager_; 80}; 81 82} // namespace shill 83#endif // SHILL_PROPERTY_STORE_UNITTEST_H_ 84