pw_i2c: Fix build issues with initiator mock
Other small cleanup with initiator mock. Also added the initiator mock
unit test into the pw_i2c test group.
Testing: Host test -- OK
Change-Id: If8397f1c8622d4bb5f371eb8322b1b16deb6fe2b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/49341
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Kevin Zeng <zengk@google.com>
diff --git a/pw_i2c/BUILD.gn b/pw_i2c/BUILD.gn
index c913979..f0a39fa 100644
--- a/pw_i2c/BUILD.gn
+++ b/pw_i2c/BUILD.gn
@@ -75,7 +75,11 @@
sources = [ "initiator_mock.cc" ]
public_deps = [
":initiator",
+ "$dir_pw_bytes",
+ ]
+ deps = [
"$dir_pw_assert",
+ "$dir_pw_unit_test",
]
}
@@ -93,6 +97,7 @@
tests = [
":address_test",
":device_test",
+ ":initiator_mock_test",
":register_device_test",
]
}
@@ -118,8 +123,9 @@
}
pw_test("initiator_mock_test") {
+ enable_if = pw_chrono_SYSTEM_CLOCK_BACKEND != ""
sources = [ "initiator_mock_test.cc" ]
- deps = [ ":initiator_mock" ]
+ deps = [ ":mock" ]
}
pw_doc_group("docs") {
diff --git a/pw_i2c/initiator_mock.cc b/pw_i2c/initiator_mock.cc
index b0d2997..45dd340 100644
--- a/pw_i2c/initiator_mock.cc
+++ b/pw_i2c/initiator_mock.cc
@@ -13,8 +13,7 @@
// the License.
#include "pw_i2c/initiator_mock.h"
-#include <iostream>
-
+#include "gtest/gtest.h"
#include "pw_assert/check.h"
namespace pw::i2c {
@@ -62,4 +61,4 @@
MockInitiator::~MockInitiator() { EXPECT_EQ(Finalize(), OkStatus()); }
-} // namespace pw::i2c
\ No newline at end of file
+} // namespace pw::i2c
diff --git a/pw_i2c/public/pw_i2c/initiator_mock.h b/pw_i2c/public/pw_i2c/initiator_mock.h
index d7dd094..fa37cd2 100644
--- a/pw_i2c/public/pw_i2c/initiator_mock.h
+++ b/pw_i2c/public/pw_i2c/initiator_mock.h
@@ -16,9 +16,8 @@
#include <cstddef>
#include <optional>
-#include "gtest/gtest.h"
-#include "initiator.h"
#include "pw_bytes/span.h"
+#include "pw_i2c/initiator.h"
namespace pw::i2c {
@@ -70,11 +69,11 @@
Address device_address,
ConstByteSpan read_buffer,
std::optional<chrono::SystemClock::duration> for_at_least = std::nullopt) {
- return std::move(Transaction(expected_return_value,
- device_address,
- ConstByteSpan(),
- read_buffer,
- for_at_least));
+ return Transaction(expected_return_value,
+ device_address,
+ ConstByteSpan(),
+ read_buffer,
+ for_at_least);
}
// WriteTransaction is a helper that constructs a write only transaction.
@@ -83,11 +82,11 @@
Address device_address,
ConstByteSpan write_buffer,
std::optional<chrono::SystemClock::duration> for_at_least = std::nullopt) {
- return std::move(Transaction(expected_return_value,
- device_address,
- write_buffer,
- ConstByteSpan(),
- for_at_least));
+ return Transaction(expected_return_value,
+ device_address,
+ write_buffer,
+ ConstByteSpan(),
+ for_at_least);
}
// MockInitiator takes a series of read and/or write transactions and
@@ -147,4 +146,4 @@
return std::to_array(transactions);
}
-} // namespace pw::i2c
\ No newline at end of file
+} // namespace pw::i2c