From ebd9667ba6363245ba0c4b0c312dbbb966b586f1 Mon Sep 17 00:00:00 2001 From: Patrick Plenefisch Date: Sat, 20 Sep 2014 23:08:44 -0400 Subject: [PATCH] Expose and fix error where old subsystems were being referended after use in tests Change-Id: I50e66b3d61f5c70dee653ab3e9899f2286f3741c --- wpilibc/wpilibC++/include/Commands/Scheduler.h | 1 + wpilibc/wpilibC++/src/Commands/Scheduler.cpp | 17 +++++++++++++++++ .../src/command/CommandTest.cpp | 8 ++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/wpilibc/wpilibC++/include/Commands/Scheduler.h b/wpilibc/wpilibC++/include/Commands/Scheduler.h index 0fada5fe58..851eccf55e 100644 --- a/wpilibc/wpilibC++/include/Commands/Scheduler.h +++ b/wpilibc/wpilibC++/include/Commands/Scheduler.h @@ -34,6 +34,7 @@ public: void Run(); void Remove(Command *command); void RemoveAll(); + void ResetAll(); void SetEnabled(bool enabled); void UpdateTable(); diff --git a/wpilibc/wpilibC++/src/Commands/Scheduler.cpp b/wpilibc/wpilibC++/src/Commands/Scheduler.cpp index 02eb9e9515..a064976ff0 100644 --- a/wpilibc/wpilibC++/src/Commands/Scheduler.cpp +++ b/wpilibc/wpilibC++/src/Commands/Scheduler.cpp @@ -26,6 +26,10 @@ Scheduler::Scheduler() : m_table = NULL; m_enabled = true; + m_runningCommandsChanged = false; + toCancel = NULL; + commands = NULL; + ids = NULL; } Scheduler::~Scheduler() { @@ -215,6 +219,19 @@ void Scheduler::RemoveAll() { } } +/** + * Completely resets the scheduler. Undefined behavior if running. + */ +void Scheduler::ResetAll() +{ + RemoveAll(); + m_subsystems.clear(); + m_buttons.clear(); + m_additions.clear(); + m_commands.clear(); + m_table = NULL; +} + /** * Update the network tables associated with the Scheduler object on the SmartDashboard */ diff --git a/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp b/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp index 80ab73f0fb..4789ddedc4 100644 --- a/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp +++ b/wpilibc/wpilibC++IntegrationTests/src/command/CommandTest.cpp @@ -26,7 +26,7 @@ protected: * scope of the test. */ void TeardownScheduler(){ - Scheduler::GetInstance()->RemoveAll(); + Scheduler::GetInstance()->ResetAll(); } void AssertCommandState(MockCommand &command, int initialize, int execute, int isFinished, int end, int interrupted){ @@ -224,11 +224,11 @@ TEST_F(CommandTest, ThreeCommandOnSubSystem){ //CommandSequentialGroupTest ported from CommandSequentialGroupTest.java TEST_F(CommandTest, OneCommandSupersedingAnotherBecauseOfDependencies){ - ASubsystem subsystem("Command Superseding Test Subsystem"); + ASubsystem* subsystem = new ASubsystem("Command Superseding Test Subsystem"); MockCommand command1; - command1.Requires(&subsystem); + command1.Requires(subsystem); MockCommand command2; - command2.Requires(&subsystem); + command2.Requires(subsystem); AssertCommandState(command1, 0, 0, 0, 0, 0);