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

[This is a reland of a previous change that got reverted due
 to a python ebuild bug which has since been fixed.]

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:47574

Change-Id: I830837afe7cddc135d718628f6adbd512a19f85c
Reviewed-on: https://gerrit.chromium.org/gerrit/47573
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: Gaurav Shah <gauravsh@chromium.org>
Tested-by: Gaurav Shah <gauravsh@chromium.org>
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