pw_i2c: Add gmock for initiator

Change-Id: I588ae0c745bfbdd6dd079e3226e9aff07eac6e0d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/48360
Commit-Queue: Kevin Zeng <zengk@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_i2c/BUILD b/pw_i2c/BUILD
index 986f56c..ee0afb8 100644
--- a/pw_i2c/BUILD
+++ b/pw_i2c/BUILD
@@ -108,6 +108,18 @@
     ],
 )
 
+pw_cc_library(
+    name = "initiator_gmock",
+    hdrs = [
+        "public/pw_i2c/initiator_gmock.h",
+    ],
+    includes = ["public"],
+    deps = [
+        ":initiator",
+        "$dir_pw_third_party/googletest",
+    ],
+)
+
 pw_cc_test(
     name = "initiator_mock_test",
     srcs = [
diff --git a/pw_i2c/BUILD.gn b/pw_i2c/BUILD.gn
index 99ba0c3..c913979 100644
--- a/pw_i2c/BUILD.gn
+++ b/pw_i2c/BUILD.gn
@@ -79,6 +79,15 @@
   ]
 }
 
+pw_source_set("gmock") {
+  public_configs = [ ":public_include_path" ]
+  public_deps = [
+    ":initiator",
+    "$dir_pw_third_party/googletest",
+  ]
+  public = [ "public/pw_i2c/initiator_gmock.h" ]
+}
+
 # TODO: add mock_test here once chrono backend is supported for stm32f429i-disc1
 pw_test_group("tests") {
   tests = [
diff --git a/pw_i2c/docs.rst b/pw_i2c/docs.rst
index 60e04c2..168a784 100644
--- a/pw_i2c/docs.rst
+++ b/pw_i2c/docs.rst
@@ -40,7 +40,6 @@
 
 pw::i2c::MockInitiator
 ----------------------
-
 A generic mocked backend for for pw::i2c::Initiator. This is specifically
 intended for use when developing drivers for i2c devices. This is structured
 around a set of 'transactions' where each transaction contains a write, read and
@@ -79,3 +78,7 @@
   // Optionally check if the mocked transaction list has been exhausted.
   // Alternatively this is also called from MockInitiator::~MockInitiator().
   EXPECT_EQ(mocked_i2c.Finalize(), OkStatus());
+
+pw::i2c::GmockInitiator
+-----------------------
+gMock of Initiator used for testing and mocking out the Initiator.
diff --git a/pw_i2c/public/pw_i2c/initiator_gmock.h b/pw_i2c/public/pw_i2c/initiator_gmock.h
new file mode 100644
index 0000000..58f3a12
--- /dev/null
+++ b/pw_i2c/public/pw_i2c/initiator_gmock.h
@@ -0,0 +1,32 @@
+// Copyright 2021 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//     https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+#pragma once
+
+#include "gmock/gmock.h"
+#include "pw_i2c/initiator.h"
+
+namespace pw::i2c {
+
+class GmockInitiator : public Initiator {
+ public:
+  MOCK_METHOD(Status,
+              DoWriteReadFor,
+              (Address device_address,
+               ConstByteSpan tx_buffer,
+               ByteSpan rx_buffer,
+               chrono::SystemClock::duration for_at_least),
+              (override));
+};
+
+}  // namespace pw::i2c