Index: chromeos/dbus/shill_client_unittest_base.h |
diff --git a/chromeos/dbus/shill_client_unittest_base.h b/chromeos/dbus/shill_client_unittest_base.h |
index 1c56a17d3bb719d835f2bc5b7916bf3861ff16e8..33d1fcfb9f74e4f983725a7d92364ed653ff7009 100644 |
--- a/chromeos/dbus/shill_client_unittest_base.h |
+++ b/chromeos/dbus/shill_client_unittest_base.h |
@@ -7,9 +7,11 @@ |
#include <string> |
+#include "base/json/json_writer.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop.h" |
+#include "base/values.h" |
#include "chromeos/dbus/dbus_method_call_status.h" |
#include "chromeos/dbus/shill_client_helper.h" |
#include "dbus/mock_bus.h" |
@@ -17,6 +19,11 @@ |
#include "dbus/object_proxy.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+using ::testing::MatcherInterface; |
+using ::testing::MatchResultListener; |
+using ::testing::Matcher; |
+using ::testing::MakeMatcher; |
+ |
namespace base { |
class Value; |
@@ -32,6 +39,41 @@ class MessageReader; |
namespace chromeos { |
+// A gmock matcher for base::Value types, so we can match them in expectations. |
+class ValueMatcher |
+ : public MatcherInterface<const base::Value&> { |
+ public: |
+ explicit ValueMatcher(const base::Value& value) |
+ : expected_value_(value.DeepCopy()) {} |
+ |
+ virtual bool MatchAndExplain(const base::Value& value, |
+ MatchResultListener* listener) const { |
hashimoto
2012/09/21 11:52:01
Could you move these method definitions to .cc fil
Greg Spencer (Chromium)
2012/09/21 22:03:47
Done.
|
+ return expected_value_->Equals(&value); |
+ } |
+ |
+ virtual void DescribeTo(::std::ostream* os) const { |
+ std::string expected_value_str; |
+ base::JSONWriter::WriteWithOptions(expected_value_.get(), |
+ base::JSONWriter::OPTIONS_PRETTY_PRINT, |
+ &expected_value_str); |
+ *os << "value equals " << expected_value_str; |
+ } |
+ |
+ virtual void DescribeNegationTo(::std::ostream* os) const { |
+ std::string expected_value_str; |
+ base::JSONWriter::WriteWithOptions(expected_value_.get(), |
+ base::JSONWriter::OPTIONS_PRETTY_PRINT, |
+ &expected_value_str); |
+ *os << "value does not equal " << expected_value_str; |
+ } |
+ private: |
+ scoped_ptr<base::Value> expected_value_; |
+}; |
+ |
+inline Matcher<const base::Value&> ValueEq(const base::Value& expected_value) { |
+ return MakeMatcher(new ValueMatcher(expected_value)); |
+} |
+ |
// A class to provide functionalities needed for testing Shill D-Bus clients. |
class ShillClientUnittestBase : public testing::Test { |
public: |
@@ -54,6 +96,16 @@ class ShillClientUnittestBase : public testing::Test { |
ShillClientHelper::ErrorCallback GetCallback(); |
}; |
+ // A mock PropertyChangedObserver that can be used to check expected values. |
+ class MockPropertyChangeObserver |
+ : public ShillClientHelper::PropertyChangedObserver { |
+ public: |
+ MockPropertyChangeObserver(); |
+ ~MockPropertyChangeObserver(); |
+ MOCK_METHOD2(OnPropertyChanged, void(const std::string& name, |
+ const base::Value& value)); |
+ }; |
+ |
explicit ShillClientUnittestBase(const std::string& interface_name, |
const dbus::ObjectPath& object_path); |
virtual ~ShillClientUnittestBase(); |
@@ -74,12 +126,6 @@ class ShillClientUnittestBase : public testing::Test { |
// Sends property changed signal to the tested client. |
void SendPropertyChangedSignal(dbus::Signal* signal); |
- // Checks the name and the value which are sent by PropertyChanged signal. |
- static void ExpectPropertyChanged(const std::string& expected_name, |
- const base::Value* expected_value, |
- const std::string& name, |
- const base::Value& value); |
- |
// Expects the reader to be empty. |
static void ExpectNoArgument(dbus::MessageReader* reader); |
@@ -109,6 +155,9 @@ class ShillClientUnittestBase : public testing::Test { |
const base::DictionaryValue* expected_result, |
DBusMethodCallStatus call_status, |
const base::DictionaryValue& result); |
+ static void ExpectDictionaryValueResultWithoutStatus( |
+ const base::DictionaryValue* expected_result, |
+ const base::DictionaryValue& result); |
// A message loop to emulate asynchronous behavior. |
MessageLoop message_loop_; |