shill: Add a GMock printer for ::DBus::Variant types

GMock 1.6 will otherwise attempt to generate its own at compile time.
That fails because GMock infers DBus::Variant as an integer type
and will try to generate code that uses DBus::Variant::operator T() on
the value where [T = long long]. The operator >> is not defined
for (DBus::MessageIter&, long long).

BUG=chromium:211445
TEST=FEATURES=test emerge-lumpy shill with gtest 1.6
CQ-DEPEND=CL:46420

Change-Id: I8e49abf877b44e0d187787f1b75aa5598a667da9
Reviewed-on: https://gerrit.chromium.org/gerrit/46428
Commit-Queue: Gaurav Shah <gauravsh@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Tested-by: Gaurav Shah <gauravsh@chromium.org>
diff --git a/Makefile b/Makefile
index 8e34018..7c1751b 100644
--- a/Makefile
+++ b/Makefile
@@ -341,6 +341,7 @@
 	dbus_adaptor_unittest.o \
 	dbus_manager_unittest.o \
 	dbus_properties_unittest.o \
+	dbus_variant_gmock_printer.o \
 	default_profile_unittest.o \
 	device_info_unittest.o \
 	device_unittest.o \
diff --git a/dbus_properties.h b/dbus_properties.h
index 8239291..db678f2 100644
--- a/dbus_properties.h
+++ b/dbus_properties.h
@@ -13,6 +13,7 @@
 #include <dbus-c++/types.h>
 
 #include "shill/accessor_interface.h"
+#include "shill/dbus_variant_gmock_printer.h"
 
 namespace shill {
 
diff --git a/dbus_variant_gmock_printer.cc b/dbus_variant_gmock_printer.cc
new file mode 100644
index 0000000..bd67d3b
--- /dev/null
+++ b/dbus_variant_gmock_printer.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/dbus_variant_gmock_printer.h"
+
+#include <gmock/gmock.h>
+
+#include "shill/dbus_adaptor.h"
+
+namespace DBus {
+
+void PrintTo(const ::DBus::Variant &value, ::std::ostream *os) {
+  if (shill::DBusAdaptor::IsBool(value.signature()))
+    *os << value.reader().get_bool();
+  else if (shill::DBusAdaptor::IsByte(value.signature()))
+    *os << value.reader().get_byte();
+  else if (shill::DBusAdaptor::IsInt16(value.signature()))
+    *os << value.reader().get_int16();
+  else if (shill::DBusAdaptor::IsInt32(value.signature()))
+    *os << value.reader().get_int32();
+  else if (shill::DBusAdaptor::IsPath(value.signature()))
+    *os << value.reader().get_path();
+  else if (shill::DBusAdaptor::IsString(value.signature()))
+    *os << value.reader().get_string();
+  else if (shill::DBusAdaptor::IsStringmap(value.signature()))
+    *os << testing::PrintToString(value.operator shill::Stringmap());
+  else if (shill::DBusAdaptor::IsStringmaps(value.signature()))
+    *os << testing::PrintToString(value.operator shill::Stringmaps());
+  else if (shill::DBusAdaptor::IsStrings(value.signature()))
+    *os << testing::PrintToString(value.operator shill::Strings());
+  else if (shill::DBusAdaptor::IsUint16(value.signature()))
+    *os << value.reader().get_uint16();
+  else if (shill::DBusAdaptor::IsUint32(value.signature()))
+    *os << value.reader().get_uint32();
+  else if (shill::DBusAdaptor::IsUint64(value.signature()))
+    *os << value.reader().get_uint64();
+  else
+    *os << "(Do not know how to print: unknown type: " << value.signature()
+        << ")";
+}
+
+}  // namespace DBus
diff --git a/dbus_variant_gmock_printer.h b/dbus_variant_gmock_printer.h
new file mode 100644
index 0000000..c0fe6ad
--- /dev/null
+++ b/dbus_variant_gmock_printer.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_DBUS_VARIANT_GMOCK_PRINTER_H_
+#define SHILL_DBUS_VARIANT_GMOCK_PRINTER_H_
+
+#include <dbus-c++/types.h>
+
+namespace DBus {
+
+// A GMock printer for DBus::Variant types.  This also suppresses
+// GMock from attempting (and failing) to generate its own printer
+// for DBus::Variant.
+void PrintTo(const ::DBus::Variant& var, ::std::ostream* os);
+
+}  // namespace DBus
+
+#endif  // SHILL_DBUS_VARIANT_GMOCK_PRINTER_H_
diff --git a/mock_supplicant_interface_proxy.h b/mock_supplicant_interface_proxy.h
index 289231c..69f903d 100644
--- a/mock_supplicant_interface_proxy.h
+++ b/mock_supplicant_interface_proxy.h
@@ -11,6 +11,7 @@
 #include <base/basictypes.h>
 #include <gmock/gmock.h>
 
+#include "shill/dbus_variant_gmock_printer.h"
 #include "shill/refptr_types.h"
 #include "shill/supplicant_interface_proxy_interface.h"
 
diff --git a/mock_supplicant_process_proxy.h b/mock_supplicant_process_proxy.h
index a8fb934..ec4a1a0 100644
--- a/mock_supplicant_process_proxy.h
+++ b/mock_supplicant_process_proxy.h
@@ -11,6 +11,7 @@
 #include <base/basictypes.h>
 #include <gmock/gmock.h>
 
+#include "shill/dbus_variant_gmock_printer.h"
 #include "shill/supplicant_process_proxy_interface.h"
 
 namespace shill {