WPILib Reorganization

This is a major restructuring of the WPILib repository to simply build
procedures and remove the remnants of Maven from everything except the
eclipse plugins. Gradle files have been largely simplified or rewritten,
taking advantage of splitting up parts of the build into separate build
files for ease of reading.

The eclipse plugins are now in a separate project, as is ntcore. All
dependencies are resolved via Maven dependencies, with the
Jenkins-maintained WPILib repo. Project structures have also been
simplified: we no longer have separate subprojects inside wpilibc and
wpilibj. Where possible, these changes hav been done with git renames,
to make sure we still have full history for all repositories. Other
unrelated subprojects have also been broken out: OutlineViewer is now a
separate project.

Change-Id: Ib4e2a6e1a2f66427a14f16612b0e0d69ed661878
This commit is contained in:
Fredric Silberberg
2015-09-24 20:26:49 -04:00
parent c20d34c2b6
commit 6d854afb0e
1769 changed files with 2278 additions and 333177 deletions

View File

@@ -0,0 +1,59 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Before;
import edu.wpi.first.wpilibj.mocks.MockCommand;
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
/**
* @author jonathanleitschuh
*
*/
public abstract class AbstractCommandTest extends AbstractComsSetup {
@Before
public void commandSetup() {
Scheduler.getInstance().removeAll();
Scheduler.getInstance().enable();
}
public class ASubsystem extends Subsystem {
Command command;
protected void initDefaultCommand() {
if (command != null) {
setDefaultCommand(command);
}
}
public void init(Command command) {
this.command = command;
}
}
public void assertCommandState(MockCommand command, int initialize, int execute, int isFinished,
int end, int interrupted) {
assertEquals(initialize, command.getInitializeCount());
assertEquals(execute, command.getExecuteCount());
assertEquals(isFinished, command.getIsFinishedCount());
assertEquals(end, command.getEndCount());
assertEquals(interrupted, command.getInterruptedCount());
}
public void sleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException ex) {
fail("Sleep Interrupted!?!?!?!?");
}
}
}

View File

@@ -0,0 +1,149 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import edu.wpi.first.wpilibj.buttons.InternalButton;
import edu.wpi.first.wpilibj.mocks.MockCommand;
/**
* @author Mitchell
* @author jonathanleitschuh
*
*/
public class ButtonTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(ButtonTest.class.getName());
private InternalButton button1;
private InternalButton button2;
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
button1 = new InternalButton();
button2 = new InternalButton();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Simple Button Test
*/
@Test
public void test() {
MockCommand command1 = new MockCommand();
MockCommand command2 = new MockCommand();
MockCommand command3 = new MockCommand();
MockCommand command4 = new MockCommand();
button1.whenPressed(command1);
button1.whenReleased(command2);
button1.whileHeld(command3);
button2.whileHeld(command4);
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
assertCommandState(command4, 0, 0, 0, 0, 0);
button1.setPressed(true);
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
assertCommandState(command4, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
assertCommandState(command4, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 1, 1, 1, 0, 0);
assertCommandState(command4, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 2, 2, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 1, 2, 2, 0, 0);
assertCommandState(command4, 0, 0, 0, 0, 0);
button2.setPressed(true);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 3, 3, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 1, 3, 3, 0, 0);
assertCommandState(command4, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 4, 4, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 1, 4, 4, 0, 0);
assertCommandState(command4, 1, 1, 1, 0, 0);
button1.setPressed(false);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 5, 5, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 1, 4, 4, 0, 1);
assertCommandState(command4, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 6, 6, 0, 0);
assertCommandState(command2, 1, 1, 1, 0, 0);
assertCommandState(command3, 1, 4, 4, 0, 1);
assertCommandState(command4, 1, 3, 3, 0, 0);
button2.setPressed(false);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 7, 7, 0, 0);
assertCommandState(command2, 1, 2, 2, 0, 0);
assertCommandState(command3, 1, 4, 4, 0, 1);
assertCommandState(command4, 1, 3, 3, 0, 1);
command1.cancel();
Scheduler.getInstance().run();
assertCommandState(command1, 1, 7, 7, 0, 1);
assertCommandState(command2, 1, 3, 3, 0, 0);
assertCommandState(command3, 1, 4, 4, 0, 1);
assertCommandState(command4, 1, 3, 3, 0, 1);
command2.setHasFinished(true);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 7, 7, 0, 1);
assertCommandState(command2, 1, 4, 4, 1, 0);
assertCommandState(command3, 1, 4, 4, 0, 1);
assertCommandState(command4, 1, 3, 3, 0, 1);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 7, 7, 0, 1);
assertCommandState(command2, 1, 4, 4, 1, 0);
assertCommandState(command3, 1, 4, 4, 0, 1);
assertCommandState(command4, 1, 3, 3, 0, 1);
}
}

View File

@@ -0,0 +1,106 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import static org.junit.Assert.*;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import edu.wpi.first.wpilibj.mocks.MockCommand;
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
/**
* Ported from the old CrioTest Classes
*$
* @author Mitchell
* @author Jonathan Leitschuh
*/
public class CommandParallelGroupTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(CommandParallelGroupTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Simple Parallel Command Group With 2 commands one command terminates first
*/
@Test
public void testParallelCommandGroupWithTwoCommands() {
MockCommand command1 = new MockCommand();
MockCommand command2 = new MockCommand();
CommandGroup commandGroup = new CommandGroup();
commandGroup.addParallel(command1);
commandGroup.addParallel(command2);
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
commandGroup.start();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 0);
assertCommandState(command2, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 2, 2, 0, 0);
assertCommandState(command2, 1, 2, 2, 0, 0);
command1.setHasFinished(true);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 3, 3, 1, 0);
assertCommandState(command2, 1, 3, 3, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 3, 3, 1, 0);
assertCommandState(command2, 1, 4, 4, 0, 0);
command2.setHasFinished(true);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 3, 3, 1, 0);
assertCommandState(command2, 1, 5, 5, 1, 0);
}
public void sleep(long time) {
try {
Thread.sleep(time);
} catch (InterruptedException ex) {
fail("Sleep Interrupted!?!?!?!?");
}
}
}

View File

@@ -0,0 +1,105 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import static org.junit.Assert.*;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import edu.wpi.first.wpilibj.mocks.MockCommand;
/**
* Ported from the old CrioTest Classes
*$
* @author Mitchell
* @author Jonathan Leitschuh
*/
public class CommandScheduleTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(CommandScheduleTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Simple scheduling of a command and making sure the command is run and
* successfully terminates
*/
@Test
public void testRunAndTerminate() {
MockCommand command = new MockCommand();
command.start();
assertCommandState(command, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 2, 2, 0, 0);
command.setHasFinished(true);
assertCommandState(command, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 3, 3, 1, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 3, 3, 1, 0);
}
/**
* Simple scheduling of a command and making sure the command is run and
* cancels correctly
*/
@Test
public void testRunAndCancel() {
MockCommand command = new MockCommand();
command.start();
assertCommandState(command, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 3, 3, 0, 0);
command.cancel();
assertCommandState(command, 1, 3, 3, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 3, 3, 0, 1);
Scheduler.getInstance().run();
assertCommandState(command, 1, 3, 3, 0, 1);
}
}

View File

@@ -0,0 +1,142 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import edu.wpi.first.wpilibj.mocks.MockCommand;
/**
* Ported from the old CrioTest Classes
*$
* @author Mitchell
* @author Jonathan Leitschuh
*/
public class CommandSequentialGroupTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(CommandSequentialGroupTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Simple Command Group With 3 commands that all depend on a subsystem. Some
* commands have a timeout
*/
@Test(timeout = 20000)
public void testThreeCommandOnSubSystem() {
logger.fine("Begining Test");
final ASubsystem subsystem = new ASubsystem();
logger.finest("Creating Mock Command1");
MockCommand command1 = new MockCommand() {
{
requires(subsystem);
}
};
logger.finest("Creating Mock Command2");
MockCommand command2 = new MockCommand() {
{
requires(subsystem);
}
};
logger.finest("Creating Mock Command3");
MockCommand command3 = new MockCommand() {
{
requires(subsystem);
}
};
logger.finest("Creating Command Group");
CommandGroup commandGroup = new CommandGroup();
commandGroup.addSequential(command1, 1.0);
commandGroup.addSequential(command2, 2.0);
commandGroup.addSequential(command3);
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
logger.finest("Starting Command group");
commandGroup.start();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
sleep(1000);// command 1 timeout
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 1, 1, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 0);
assertCommandState(command3, 0, 0, 0, 0, 0);
sleep(2000);// command 2 timeout
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 1);
assertCommandState(command3, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 1);
assertCommandState(command3, 1, 2, 2, 0, 0);
command3.setHasFinished(true);
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 1);
assertCommandState(command3, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 1);
assertCommandState(command3, 1, 3, 3, 1, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 1);
assertCommandState(command3, 1, 3, 3, 1, 0);
}
}

View File

@@ -0,0 +1,155 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import edu.wpi.first.wpilibj.mocks.MockCommand;
/**
* Ported from the old CrioTest Classes
*$
* @author Mitchell
* @author Jonathan Leitschuh
*/
public class CommandSupersedeTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(CommandSupersedeTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Testing one command superseding another because of dependencies
*/
@Test
public void testOneCommandSupersedingAnotherBecauseOfDependencies() {
final ASubsystem subsystem = new ASubsystem();
MockCommand command1 = new MockCommand() {
{
requires(subsystem);
}
};
MockCommand command2 = new MockCommand() {
{
requires(subsystem);
}
};
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
command1.start();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 2, 2, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 3, 3, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
command2.start();
assertCommandState(command1, 1, 3, 3, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 4, 4, 0, 1);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 4, 4, 0, 1);
assertCommandState(command2, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 4, 4, 0, 1);
assertCommandState(command2, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 4, 4, 0, 1);
assertCommandState(command2, 1, 3, 3, 0, 0);
}
/**
* Testing one command failing superseding another because of dependencies
* because the first command cannot be interrupted"
*/
@Test
public void testCommandFailingSupersedingBecauseFirstCanNotBeInterrupted() {
final ASubsystem subsystem = new ASubsystem();
MockCommand command1 = new MockCommand() {
{
requires(subsystem);
setInterruptible(false);
}
};
MockCommand command2 = new MockCommand() {
{
requires(subsystem);
}
};
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
command1.start();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 0, 0, 0, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 1, 1, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 2, 2, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 3, 3, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
command2.start();
assertCommandState(command1, 1, 3, 3, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command1, 1, 4, 4, 0, 0);
assertCommandState(command2, 0, 0, 0, 0, 0);
}
}

View File

@@ -0,0 +1,25 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import edu.wpi.first.wpilibj.test.AbstractTestSuite;
/**
* @author jonathanleitschuh
*
*/
@RunWith(Suite.class)
@SuiteClasses({ButtonTest.class, CommandParallelGroupTest.class, CommandScheduleTest.class,
CommandSequentialGroupTest.class, CommandSupersedeTest.class, CommandTimeoutTest.class,
DefaultCommandTest.class})
public class CommandTestSuite extends AbstractTestSuite {
}

View File

@@ -0,0 +1,93 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import static org.junit.Assert.*;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import edu.wpi.first.wpilibj.mocks.MockCommand;
/**
* @author jonathanleitschuh
*
*/
public class CommandTimeoutTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(CommandTimeoutTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Command 2 second Timeout Test
*/
@Test
public void testTwoSecondTimeout() {
final ASubsystem subsystem = new ASubsystem();
MockCommand command = new MockCommand() {
{
requires(subsystem);
setTimeout(2);
}
@Override
public boolean isFinished() {
return super.isFinished() || isTimedOut();
}
};
command.start();
assertCommandState(command, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 3, 3, 0, 0);
sleep(2000);
Scheduler.getInstance().run();
assertCommandState(command, 1, 4, 4, 1, 0);
Scheduler.getInstance().run();
assertCommandState(command, 1, 4, 4, 1, 0);
}
}

View File

@@ -0,0 +1,169 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2014. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.command;
import static org.junit.Assert.*;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import edu.wpi.first.wpilibj.mocks.MockCommand;
/**
* @author jonathanleitschuh
*
*/
public class DefaultCommandTest extends AbstractCommandTest {
private static final Logger logger = Logger.getLogger(DefaultCommandTest.class.getName());
protected Logger getClassLogger() {
return logger;
}
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {}
/**
* Testing of default commands where the interrupting command ends itself
*/
@Test
public void testDefaultCommandWhereTheInteruptingCommandEndsItself() {
final ASubsystem subsystem = new ASubsystem();
MockCommand defaultCommand = new MockCommand() {
{
requires(subsystem);
}
};
MockCommand anotherCommand = new MockCommand() {
{
requires(subsystem);
}
};
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
subsystem.init(defaultCommand);
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
anotherCommand.start();
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
anotherCommand.setHasFinished(true);
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 2, 4, 4, 0, 1);
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 2, 5, 5, 0, 1);
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
}
/**
* Testing of default commands where the interrupting command is canceled
*/
@Test
public void testDefaultCommandsInterruptingCommandCanceled() {
final ASubsystem subsystem = new ASubsystem();
MockCommand defaultCommand = new MockCommand() {
{
requires(subsystem);
}
};
MockCommand anotherCommand = new MockCommand() {
{
requires(subsystem);
}
};
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
subsystem.init(defaultCommand);
subsystem.initDefaultCommand();
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
anotherCommand.start();
assertCommandState(defaultCommand, 1, 2, 2, 0, 0);
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 0, 0, 0, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 1, 1, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
anotherCommand.cancel();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 0);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 1, 3, 3, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 2, 4, 4, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
Scheduler.getInstance().run();
assertCommandState(defaultCommand, 2, 5, 5, 0, 1);
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
}
}