Update googletest
Merge commit 'e10c4a83477d150b0abfd84a863450c569f30a1b' into master
Change-Id: I219e458e8d80c0c0d31520e3620adae6d0ee4d64
diff --git a/aos/controls/BUILD b/aos/controls/BUILD
index d529f04..2362708 100644
--- a/aos/controls/BUILD
+++ b/aos/controls/BUILD
@@ -11,9 +11,9 @@
deps = [
":control_loop",
"//aos:queues",
- "//aos/time:time",
"//aos/logging:queue_logging",
"//aos/logging:replay",
+ "//aos/time",
],
)
@@ -27,11 +27,11 @@
"control_loop_test.h",
],
deps = [
- "//aos/time:time",
"//aos/logging:queue_logging",
- "//aos/robot_state:robot_state",
+ "//aos/robot_state",
"//aos/testing:googletest",
"//aos/testing:test_shm",
+ "//aos/time",
],
)
@@ -69,7 +69,6 @@
"//aos/testing:googletest",
"//aos/testing:test_logging",
"//third_party/eigen",
- "//third_party/googletest:googlemock",
],
)
@@ -95,10 +94,10 @@
deps = [
":control_loop_queues",
"//aos:queues",
- "//aos/time:time",
"//aos/logging",
"//aos/logging:queue_logging",
- "//aos/robot_state:robot_state",
+ "//aos/robot_state",
+ "//aos/time",
"//aos/util:log_interval",
],
)
diff --git a/aos/controls/control_loop_test.cc b/aos/controls/control_loop_test.cc
index 61c2fe0..8a21f1f 100644
--- a/aos/controls/control_loop_test.cc
+++ b/aos/controls/control_loop_test.cc
@@ -1,64 +1,10 @@
#include "aos/controls/control_loop_test.h"
-#include "aos/robot_state/robot_state.q.h"
-#include "aos/logging/queue_logging.h"
+#include <chrono>
namespace aos {
namespace testing {
-constexpr ::std::chrono::milliseconds ControlLoopTest::kTimeTick;
-constexpr ::std::chrono::milliseconds ControlLoopTest::kDSPacketTime;
-
-ControlLoopTest::ControlLoopTest() {
- ::aos::joystick_state.Clear();
- ::aos::robot_state.Clear();
-
- ::aos::time::EnableMockTime(current_time_);
-
- SendMessages(false);
-}
-
-ControlLoopTest::~ControlLoopTest() {
- ::aos::joystick_state.Clear();
- ::aos::robot_state.Clear();
-
- ::aos::time::DisableMockTime();
-}
-
-void ControlLoopTest::SendMessages(bool enabled) {
- if (current_time_ >= kDSPacketTime + last_ds_time_ ||
- last_enabled_ != enabled) {
- last_ds_time_ = current_time_;
- auto new_state = ::aos::joystick_state.MakeMessage();
- new_state->fake = true;
-
- new_state->enabled = enabled;
- new_state->autonomous = false;
- new_state->team_id = team_id_;
-
- new_state.Send();
- last_enabled_ = enabled;
- }
-
- {
- auto new_state = ::aos::robot_state.MakeMessage();
-
- new_state->reader_pid = reader_pid_;
- new_state->outputs_enabled = enabled;
- new_state->browned_out = false;
-
- new_state->is_3v3_active = true;
- new_state->is_5v_active = true;
- new_state->voltage_3v3 = 3.3;
- new_state->voltage_5v = 5.0;
-
- new_state->voltage_roborio_in = battery_voltage_;
- new_state->voltage_battery = battery_voltage_;
-
- LOG_STRUCT(INFO, "robot_state", *new_state);
- new_state.Send();
- }
-}
} // namespace testing
} // namespace aos
diff --git a/aos/controls/control_loop_test.h b/aos/controls/control_loop_test.h
index 1633daf..e88b1b7 100644
--- a/aos/controls/control_loop_test.h
+++ b/aos/controls/control_loop_test.h
@@ -1,8 +1,12 @@
#ifndef AOS_CONTROLS_CONTROL_LOOP_TEST_H_
#define AOS_CONTROLS_CONTROL_LOOP_TEST_H_
+#include <chrono>
+
#include "gtest/gtest.h"
+#include "aos/logging/queue_logging.h"
+#include "aos/robot_state/robot_state.q.h"
#include "aos/testing/test_shm.h"
#include "aos/time/time.h"
@@ -14,16 +18,62 @@
// This includes sending the queue messages and Clear()ing the queues when
// appropriate.
// It also includes dealing with ::aos::time.
-class ControlLoopTest : public ::testing::Test {
+template <typename TestBaseClass>
+class ControlLoopTestTemplated : public TestBaseClass {
public:
- ControlLoopTest();
- virtual ~ControlLoopTest();
+ ControlLoopTestTemplated() {
+ ::aos::joystick_state.Clear();
+ ::aos::robot_state.Clear();
+
+ ::aos::time::EnableMockTime(current_time_);
+
+ SendMessages(false);
+ }
+ virtual ~ControlLoopTestTemplated() {
+ ::aos::joystick_state.Clear();
+ ::aos::robot_state.Clear();
+
+ ::aos::time::DisableMockTime();
+ }
void set_team_id(uint16_t team_id) { team_id_ = team_id; }
uint16_t team_id() const { return team_id_; }
// Sends out all of the required queue messages.
- void SendMessages(bool enabled);
+ void SendMessages(bool enabled) {
+ if (current_time_ >= kDSPacketTime + last_ds_time_ ||
+ last_enabled_ != enabled) {
+ last_ds_time_ = current_time_;
+ auto new_state = ::aos::joystick_state.MakeMessage();
+ new_state->fake = true;
+
+ new_state->enabled = enabled;
+ new_state->autonomous = false;
+ new_state->team_id = team_id_;
+
+ new_state.Send();
+ last_enabled_ = enabled;
+ }
+
+ {
+ auto new_state = ::aos::robot_state.MakeMessage();
+
+ new_state->reader_pid = reader_pid_;
+ new_state->outputs_enabled = enabled;
+ new_state->browned_out = false;
+
+ new_state->is_3v3_active = true;
+ new_state->is_5v_active = true;
+ new_state->voltage_3v3 = 3.3;
+ new_state->voltage_5v = 5.0;
+
+ new_state->voltage_roborio_in = battery_voltage_;
+ new_state->voltage_battery = battery_voltage_;
+
+ LOG_STRUCT(INFO, "robot_state", *new_state);
+ new_state.Send();
+ }
+ }
// Ticks time for a single control loop cycle.
void TickTime(::std::chrono::nanoseconds dt = kTimeTick) {
::aos::time::SetMockTime(current_time_ += dt);
@@ -64,6 +114,14 @@
bool last_enabled_ = false;
};
+typedef ControlLoopTestTemplated<::testing::Test> ControlLoopTest;
+
+template <typename TestBaseClass>
+constexpr ::std::chrono::milliseconds ControlLoopTestTemplated<TestBaseClass>::kTimeTick;
+
+template <typename TestBaseClass>
+constexpr ::std::chrono::milliseconds ControlLoopTestTemplated<TestBaseClass>::kDSPacketTime;
+
} // namespace testing
} // namespace aos
diff --git a/aos/testing/BUILD b/aos/testing/BUILD
index f77f0a7..588203a 100644
--- a/aos/testing/BUILD
+++ b/aos/testing/BUILD
@@ -9,7 +9,7 @@
],
visibility = ["//visibility:public"],
deps = [
- "//third_party/googletest",
+ "//third_party/googletest:gtest",
],
)