Add format script which invokes clang-format on the C++ source code (#41)

On Windows machines, clang-format.exe must be in the PATH environment variable.
This commit is contained in:
Tyler Veness
2016-05-20 17:30:37 -07:00
committed by Peter Johnson
parent 68690643d2
commit e14e45da76
383 changed files with 13787 additions and 13198 deletions

View File

@@ -10,8 +10,8 @@
#include <AnalogTrigger.h>
#include <Counter.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static const double kDelayTime = 0.01;
@@ -20,8 +20,8 @@ static const double kDelayTime = 0.01;
*/
class AnalogLoopTest : public testing::Test {
protected:
AnalogInput *m_input;
AnalogOutput *m_output;
AnalogInput* m_input;
AnalogOutput* m_output;
virtual void SetUp() override {
m_input = new AnalogInput(TestBench::kFakeAnalogOutputChannel);
@@ -102,8 +102,8 @@ TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
<< "Analog trigger counter did not count 50 ticks";
}
static void InterruptHandler(uint32_t interruptAssertedMask, void *param) {
*(int *)param = 12345;
static void InterruptHandler(uint32_t interruptAssertedMask, void* param) {
*(int*)param = 12345;
}
TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
@@ -112,7 +112,8 @@ TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
trigger.SetLimitsVoltage(2.0f, 3.0f);
// Given an interrupt handler that sets an int to 12345
std::shared_ptr<AnalogTriggerOutput> triggerOutput = trigger.CreateOutput(kState);
std::shared_ptr<AnalogTriggerOutput> triggerOutput =
trigger.CreateOutput(kState);
triggerOutput->RequestInterrupts(InterruptHandler, &param);
triggerOutput->EnableInterrupts();

View File

@@ -7,8 +7,8 @@
#include <AnalogOutput.h>
#include <AnalogPotentiometer.h>
#include <Timer.h>
#include <ControllerPower.h>
#include <Timer.h>
#include "TestBench.h"
#include "gtest/gtest.h"
@@ -17,8 +17,8 @@ static const double kAngle = 180.0;
class AnalogPotentiometerTest : public testing::Test {
protected:
AnalogOutput *m_fakePot;
AnalogPotentiometer *m_pot;
AnalogOutput* m_fakePot;
AnalogPotentiometer* m_pot;
virtual void SetUp() override {
m_fakePot = new AnalogOutput(TestBench::kAnalogOutputChannel);

View File

@@ -6,13 +6,13 @@
/*----------------------------------------------------------------------------*/
#include <AnalogOutput.h>
#include <DigitalOutput.h>
#include <CANJaguar.h>
#include <DigitalOutput.h>
#include <Relay.h>
#include <Timer.h>
#include <WPIErrors.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static constexpr double kSpikeTime = 0.5;
@@ -39,10 +39,10 @@ static constexpr double kMotorPercent = 0.5;
static constexpr double kMotorSpeed = 100;
class CANJaguarTest : public testing::Test {
protected:
CANJaguar *m_jaguar;
CANJaguar* m_jaguar;
DigitalOutput *m_fakeForwardLimit, *m_fakeReverseLimit;
AnalogOutput *m_fakePotentiometer;
Relay *m_spike;
AnalogOutput* m_fakePotentiometer;
Relay* m_spike;
virtual void SetUp() override {
m_spike = new Relay(TestBench::kCANJaguarRelayChannel, Relay::kForwardOnly);
@@ -110,7 +110,8 @@ class CANJaguarTest : public testing::Test {
finalSpeed = m_jaguar->GetSpeed();
EXPECT_FALSE(SignNum(initialSpeed) == SignNum(finalSpeed))
<< "CAN Jaguar did not invert direction negative. Initial displacement "
"was: " << initialSpeed << " Final displacement was: " << finalSpeed
"was: "
<< initialSpeed << " Final displacement was: " << finalSpeed
<< " Sign of initial displacement was: " << SignNum(initialSpeed)
<< " Sign of final displacement was: " << SignNum(finalSpeed);
}
@@ -121,8 +122,7 @@ class CANJaguarTest : public testing::Test {
* causes a ResourceAlreadyAllocated error.
*/
TEST_F(CANJaguarTest, AlreadyAllocatedError) {
std::cout << "The following errors are expected." << std::endl
<< std::endl;
std::cout << "The following errors are expected." << std::endl << std::endl;
CANJaguar jaguar(TestBench::kCANJaguarID);
EXPECT_EQ(wpi_error_value_ResourceAlreadyAllocated,
@@ -135,8 +135,7 @@ TEST_F(CANJaguarTest, AlreadyAllocatedError) {
* out-of-range error.
*/
TEST_F(CANJaguarTest, 64OutOfRangeError) {
std::cout << "The following errors are expected." << std::endl
<< std::endl;
std::cout << "The following errors are expected." << std::endl << std::endl;
CANJaguar jaguar(64);
EXPECT_EQ(wpi_error_value_ChannelIndexOutOfRange, jaguar.GetError().GetCode())
@@ -148,8 +147,7 @@ TEST_F(CANJaguarTest, 64OutOfRangeError) {
* error.
*/
TEST_F(CANJaguarTest, 0OutOfRangeError) {
std::cout << "The following errors are expected." << std::endl
<< std::endl;
std::cout << "The following errors are expected." << std::endl << std::endl;
CANJaguar jaguar(0);
EXPECT_EQ(wpi_error_value_ChannelIndexOutOfRange, jaguar.GetError().GetCode())

View File

@@ -7,8 +7,8 @@
#include <CANTalon.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
const int deviceId = 0;
@@ -71,6 +71,6 @@ TEST(CANTalonTest, DISABLED_PositionModeWorks) {
TEST(CANTalonTest, GetFaults) {
CANTalon talon(deviceId);
EXPECT_EQ(talon.GetFaults(),0);
EXPECT_EQ(talon.GetStickyFaults(),0);
EXPECT_EQ(talon.GetFaults(), 0);
EXPECT_EQ(talon.GetStickyFaults(), 0);
}

View File

@@ -6,21 +6,18 @@
/*----------------------------------------------------------------------------*/
#include <CircularBuffer.h>
#include "gtest/gtest.h"
#include <array>
#include "gtest/gtest.h"
static const std::array<double, 10> values = {751.848, 766.366, 342.657,
234.252, 716.126, 132.344,
445.697, 22.727, 421.125,
799.913};
static const std::array<double, 10> values = {
751.848, 766.366, 342.657, 234.252, 716.126,
132.344, 445.697, 22.727, 421.125, 799.913};
static const std::array<double, 8> pushFrontOut = {799.913, 421.125, 22.727,
445.697, 132.344, 716.126,
234.252, 342.657};
static const std::array<double, 8> pushFrontOut = {
799.913, 421.125, 22.727, 445.697, 132.344, 716.126, 234.252, 342.657};
static const std::array<double, 8> pushBackOut = {342.657, 234.252, 716.126,
132.344, 445.697, 22.727,
421.125, 799.913};
static const std::array<double, 8> pushBackOut = {
342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913};
TEST(CircularBufferTest, PushFrontTest) {
CircularBuffer<double> queue(8);
@@ -63,27 +60,27 @@ TEST(CircularBufferTest, PushPopTest) {
* front-most elements.
*/
queue.PushBack(4.0); // Overwrite 1 with 4
queue.PushBack(4.0); // Overwrite 1 with 4
// The buffer now contains 2, 3 and 4
EXPECT_EQ(2.0, queue[0]);
EXPECT_EQ(3.0, queue[1]);
EXPECT_EQ(4.0, queue[2]);
queue.PushBack(5.0); // Overwrite 2 with 5
queue.PushBack(5.0); // Overwrite 2 with 5
// The buffer now contains 3, 4 and 5
EXPECT_EQ(3.0, queue[0]);
EXPECT_EQ(4.0, queue[1]);
EXPECT_EQ(5.0, queue[2]);
EXPECT_EQ(5.0, queue.PopBack()); // 5 is removed
EXPECT_EQ(5.0, queue.PopBack()); // 5 is removed
// The buffer now contains 3 and 4
EXPECT_EQ(3.0, queue[0]);
EXPECT_EQ(4.0, queue[1]);
EXPECT_EQ(3.0, queue.PopFront()); // 3 is removed
EXPECT_EQ(3.0, queue.PopFront()); // 3 is removed
// Leaving only one element with value == 4
EXPECT_EQ(4.0, queue[0]);

View File

@@ -10,12 +10,12 @@
#include "HAL/cpp/priority_condition_variable.h"
#include "HAL/cpp/priority_mutex.h"
#include "gtest/gtest.h"
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <thread>
#include "gtest/gtest.h"
namespace wpilib {
namespace testing {
@@ -41,7 +41,7 @@ class ConditionVariableTest : public ::testing::Test {
// Information for when running with predicates.
std::atomic<bool> m_pred_var{false};
void ShortSleep(unsigned long time=10) {
void ShortSleep(unsigned long time = 10) {
std::this_thread::sleep_for(std::chrono::milliseconds(time));
}
@@ -58,8 +58,7 @@ class ConditionVariableTest : public ::testing::Test {
ShortSleep();
bool locked = m_mutex.try_lock();
if (locked) m_mutex.unlock();
EXPECT_TRUE(locked)
<< "The condition variable failed to unlock the lock.";
EXPECT_TRUE(locked) << "The condition variable failed to unlock the lock.";
}
void NotifyAll() { m_cond.notify_all(); }
@@ -91,13 +90,12 @@ class ConditionVariableTest : public ::testing::Test {
// the timeout works properly.
void WaitTimeTest(bool wait_for) {
std::atomic<bool> timed_out{true};
auto wait_until = [this, &timed_out, wait_for](std::atomic<bool> &done) {
auto wait_until = [this, &timed_out, wait_for](std::atomic<bool>& done) {
priority_lock lock(m_mutex);
done = false;
if (wait_for) {
auto wait_time = std::chrono::milliseconds(100);
timed_out =
m_cond.wait_for(lock, wait_time) == std::cv_status::timeout;
timed_out = m_cond.wait_for(lock, wait_time) == std::cv_status::timeout;
} else {
auto wait_time =
std::chrono::system_clock::now() + std::chrono::milliseconds(100);
@@ -138,8 +136,8 @@ class ConditionVariableTest : public ::testing::Test {
// false, the return value will be false.
std::atomic<bool> retval{true};
auto predicate = [this]() -> bool { return m_pred_var; };
auto wait_until =
[this, &retval, predicate, wait_for](std::atomic<bool> &done) {
auto wait_until = [this, &retval, predicate,
wait_for](std::atomic<bool>& done) {
priority_lock lock(m_mutex);
done = false;
if (wait_for) {
@@ -203,15 +201,19 @@ class ConditionVariableTest : public ::testing::Test {
// std::terminate is called and all threads are terminated.
// Detaching is non-optimal, but should allow the rest of the tests to run
// before anything drastic occurs.
if (m_done1) m_watcher1.join();
else m_watcher1.detach();
if (m_done2) m_watcher2.join();
else m_watcher2.detach();
if (m_done1)
m_watcher1.join();
else
m_watcher1.detach();
if (m_done2)
m_watcher2.join();
else
m_watcher2.detach();
}
};
TEST_F(ConditionVariableTest, NotifyAll) {
auto wait = [this](std::atomic<bool> &done) {
auto wait = [this](std::atomic<bool>& done) {
priority_lock lock(m_mutex);
done = false;
m_cond.wait(lock);
@@ -226,7 +228,7 @@ TEST_F(ConditionVariableTest, NotifyAll) {
}
TEST_F(ConditionVariableTest, NotifyOne) {
auto wait = [this](std::atomic<bool> &done) {
auto wait = [this](std::atomic<bool>& done) {
priority_lock lock(m_mutex);
done = false;
m_cond.wait(lock);
@@ -248,7 +250,7 @@ TEST_F(ConditionVariableTest, NotifyOne) {
TEST_F(ConditionVariableTest, WaitWithPredicate) {
auto predicate = [this]() -> bool { return m_pred_var; };
auto wait_predicate = [this, predicate](std::atomic<bool> &done) {
auto wait_predicate = [this, predicate](std::atomic<bool>& done) {
priority_lock lock(m_mutex);
done = false;
m_cond.wait(lock, predicate);
@@ -262,24 +264,20 @@ TEST_F(ConditionVariableTest, WaitWithPredicate) {
PredicateTest();
}
TEST_F(ConditionVariableTest, WaitUntil) {
WaitTimeTest(false);
}
TEST_F(ConditionVariableTest, WaitUntil) { WaitTimeTest(false); }
TEST_F(ConditionVariableTest, WaitUntilWithPredicate) {
WaitTimePredicateTest(false);
}
TEST_F(ConditionVariableTest, WaitFor) {
WaitTimeTest(true);
}
TEST_F(ConditionVariableTest, WaitFor) { WaitTimeTest(true); }
TEST_F(ConditionVariableTest, WaitForWithPredicate) {
WaitTimePredicateTest(true);
}
TEST_F(ConditionVariableTest, NativeHandle) {
auto wait = [this](std::atomic<bool> &done) {
auto wait = [this](std::atomic<bool>& done) {
priority_lock lock(m_mutex);
done = false;
m_cond.wait(lock);

View File

@@ -10,8 +10,8 @@
#include <Talon.h>
#include <Timer.h>
#include <Victor.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static const double kMotorDelay = 2.5;
@@ -19,12 +19,12 @@ static const double kMaxPeriod = 2.0;
class CounterTest : public testing::Test {
protected:
Counter *m_talonCounter;
Counter *m_victorCounter;
Counter *m_jaguarCounter;
Talon *m_talon;
Victor *m_victor;
Jaguar *m_jaguar;
Counter* m_talonCounter;
Counter* m_victorCounter;
Counter* m_jaguarCounter;
Talon* m_talon;
Victor* m_victor;
Jaguar* m_jaguar;
virtual void SetUp() override {
m_talonCounter = new Counter(TestBench::kTalonEncoderChannelA);

View File

@@ -10,8 +10,8 @@
#include <DigitalOutput.h>
#include <InterruptableSensorBase.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static const double kCounterTime = 0.001;
@@ -26,8 +26,8 @@ static const double kSynchronousInterruptTimeTolerance = 0.01;
*/
class DIOLoopTest : public testing::Test {
protected:
DigitalInput *m_input;
DigitalOutput *m_output;
DigitalInput* m_input;
DigitalOutput* m_output;
virtual void SetUp() override {
m_input = new DigitalInput(TestBench::kLoop1InputChannel);
@@ -70,15 +70,16 @@ TEST_F(DIOLoopTest, DIOPWM) {
EXPECT_FALSE(m_input->Get()) << "The digital output was turned off, but "
<< "the digital input is on.";
//Set frequency to 2.0 Hz
// Set frequency to 2.0 Hz
m_output->SetPWMRate(2.0);
//Enable PWM, but leave it off
// Enable PWM, but leave it off
m_output->EnablePWM(0.0);
Wait(0.5);
m_output->UpdateDutyCycle(0.5);
m_input->RequestInterrupts();
m_input->SetUpSourceEdge(false, true);
InterruptableSensorBase::WaitResult result = m_input->WaitForInterrupt(3.0, true);
InterruptableSensorBase::WaitResult result =
m_input->WaitForInterrupt(3.0, true);
Wait(0.5);
bool firstCycle = m_input->Get();
@@ -101,7 +102,7 @@ TEST_F(DIOLoopTest, DIOPWM) {
bool secondAfterStop = m_input->Get();
EXPECT_EQ(InterruptableSensorBase::WaitResult::kFallingEdge, result)
<< "WaitForInterrupt was not falling.";
<< "WaitForInterrupt was not falling.";
EXPECT_FALSE(firstCycle) << "Input not low after first delay";
EXPECT_TRUE(secondCycle) << "Input not high after second delay";
@@ -136,8 +137,8 @@ TEST_F(DIOLoopTest, FakeCounter) {
EXPECT_EQ(100, counter.Get()) << "Counter did not count up to 100.";
}
static void InterruptHandler(uint32_t interruptAssertedMask, void *param) {
*(int *)param = 12345;
static void InterruptHandler(uint32_t interruptAssertedMask, void* param) {
*(int*)param = 12345;
}
TEST_F(DIOLoopTest, AsynchronousInterruptWorks) {
@@ -157,8 +158,8 @@ TEST_F(DIOLoopTest, AsynchronousInterruptWorks) {
EXPECT_EQ(12345, param) << "The interrupt did not run.";
}
static void *InterruptTriggerer(void *data) {
DigitalOutput *output = static_cast<DigitalOutput *>(data);
static void* InterruptTriggerer(void* data) {
DigitalOutput* output = static_cast<DigitalOutput*>(data);
output->Set(false);
Wait(kSynchronousInterruptTime);
output->Set(true);
@@ -171,7 +172,8 @@ TEST_F(DIOLoopTest, SynchronousInterruptWorks) {
// If we have another thread trigger the interrupt in a few seconds
pthread_t interruptTriggererLoop;
pthread_create(&interruptTriggererLoop, nullptr, InterruptTriggerer, m_output);
pthread_create(&interruptTriggererLoop, nullptr, InterruptTriggerer,
m_output);
// Then this thread should pause and resume after that number of seconds
Timer timer;

View File

@@ -6,9 +6,9 @@
/*----------------------------------------------------------------------------*/
#include <Counter.h>
#include <DigitalGlitchFilter.h>
#include <DigitalInput.h>
#include <Encoder.h>
#include <DigitalGlitchFilter.h>
#include "gtest/gtest.h"
/**

View File

@@ -10,19 +10,19 @@
#include <DigitalOutput.h>
#include <Encoder.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static const double kDelayTime = 0.001;
class FakeEncoderTest : public testing::Test {
protected:
DigitalOutput *m_outputA;
DigitalOutput *m_outputB;
AnalogOutput *m_indexOutput;
DigitalOutput* m_outputA;
DigitalOutput* m_outputB;
AnalogOutput* m_indexOutput;
Encoder *m_encoder;
AnalogTrigger *m_indexAnalogTrigger;
Encoder* m_encoder;
AnalogTrigger* m_indexAnalogTrigger;
std::shared_ptr<AnalogTriggerOutput> m_indexAnalogTriggerOutput;
virtual void SetUp() override {

View File

@@ -5,17 +5,17 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include <cmath>
#include <functional>
#include <memory>
#include <random>
#include <thread>
#include <cmath>
#include <Filters/LinearDigitalFilter.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "Base.h"
#include "TestBench.h"
#include "gtest/gtest.h"
enum FilterNoiseTestType { TEST_SINGLE_POLE_IIR, TEST_MOVAVG };
@@ -42,16 +42,14 @@ constexpr double kStdDev = 10.0;
*/
class NoiseGenerator : public PIDSource {
public:
NoiseGenerator(double (*dataFunc)(double), double stdDev) :
m_distr(0.0, stdDev) {
NoiseGenerator(double (*dataFunc)(double), double stdDev)
: m_distr(0.0, stdDev) {
m_dataFunc = dataFunc;
}
void SetPIDSourceType(PIDSourceType pidSource) override {}
double Get() {
return m_dataFunc(m_count) + m_noise;
}
double Get() { return m_dataFunc(m_count) + m_noise; }
double PIDGet() override {
m_noise = m_distr(m_gen);
@@ -59,9 +57,7 @@ class NoiseGenerator : public PIDSource {
return m_dataFunc(m_count) + m_noise;
}
void Reset() {
m_count = -TestBench::kFilterStep;
}
void Reset() { m_count = -TestBench::kFilterStep; }
private:
std::function<double(double)> m_dataFunc;
@@ -83,24 +79,24 @@ class FilterNoiseTest : public testing::TestWithParam<FilterNoiseTestType> {
std::unique_ptr<PIDSource> m_filter;
std::shared_ptr<NoiseGenerator> m_noise;
static double GetData(double t) {
return 100.0 * std::sin(2.0 * M_PI * t);
}
static double GetData(double t) { return 100.0 * std::sin(2.0 * M_PI * t); }
void SetUp() override {
m_noise = std::make_shared<NoiseGenerator>(GetData, kStdDev);
switch (GetParam()) {
case TEST_SINGLE_POLE_IIR: {
m_filter = std::make_unique<LinearDigitalFilter>(LinearDigitalFilter::SinglePoleIIR(m_noise,
TestBench::kSinglePoleIIRTimeConstant,
TestBench::kFilterStep));
m_filter = std::make_unique<LinearDigitalFilter>(
LinearDigitalFilter::SinglePoleIIR(
m_noise, TestBench::kSinglePoleIIRTimeConstant,
TestBench::kFilterStep));
break;
}
case TEST_MOVAVG: {
m_filter = std::make_unique<LinearDigitalFilter>(LinearDigitalFilter::MovingAverage(m_noise,
TestBench::kMovAvgTaps));
m_filter = std::make_unique<LinearDigitalFilter>(
LinearDigitalFilter::MovingAverage(m_noise,
TestBench::kMovAvgTaps));
break;
}
}

View File

@@ -5,17 +5,17 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include <cmath>
#include <functional>
#include <memory>
#include <random>
#include <thread>
#include <cmath>
#include <Filters/LinearDigitalFilter.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "Base.h"
#include "TestBench.h"
#include "gtest/gtest.h"
enum FilterOutputTestType { TEST_SINGLE_POLE_IIR, TEST_HIGH_PASS, TEST_MOVAVG };
@@ -37,9 +37,7 @@ std::ostream& operator<<(std::ostream& os, const FilterOutputTestType& type) {
class DataWrapper : public PIDSource {
public:
DataWrapper(double (*dataFunc)(double)) {
m_dataFunc = dataFunc;
}
DataWrapper(double (*dataFunc)(double)) { m_dataFunc = dataFunc; }
virtual void SetPIDSourceType(PIDSourceType pidSource) {}
@@ -48,9 +46,7 @@ class DataWrapper : public PIDSource {
return m_dataFunc(m_count);
}
void Reset() {
m_count = -TestBench::kFilterStep;
}
void Reset() { m_count = -TestBench::kFilterStep; }
private:
std::function<double(double)> m_dataFunc;
@@ -77,24 +73,26 @@ class FilterOutputTest : public testing::TestWithParam<FilterOutputTestType> {
switch (GetParam()) {
case TEST_SINGLE_POLE_IIR: {
m_filter = std::make_unique<LinearDigitalFilter>(LinearDigitalFilter::SinglePoleIIR(m_data,
TestBench::kSinglePoleIIRTimeConstant,
TestBench::kFilterStep));
m_filter = std::make_unique<LinearDigitalFilter>(
LinearDigitalFilter::SinglePoleIIR(
m_data, TestBench::kSinglePoleIIRTimeConstant,
TestBench::kFilterStep));
m_expectedOutput = TestBench::kSinglePoleIIRExpectedOutput;
break;
}
case TEST_HIGH_PASS: {
m_filter = std::make_unique<LinearDigitalFilter>(LinearDigitalFilter::HighPass(m_data,
TestBench::kHighPassTimeConstant,
TestBench::kFilterStep));
m_filter =
std::make_unique<LinearDigitalFilter>(LinearDigitalFilter::HighPass(
m_data, TestBench::kHighPassTimeConstant,
TestBench::kFilterStep));
m_expectedOutput = TestBench::kHighPassExpectedOutput;
break;
}
case TEST_MOVAVG: {
m_filter = std::make_unique<LinearDigitalFilter>(LinearDigitalFilter::MovingAverage(m_data,
TestBench::kMovAvgTaps));
m_filter = std::make_unique<LinearDigitalFilter>(
LinearDigitalFilter::MovingAverage(m_data, TestBench::kMovAvgTaps));
m_expectedOutput = TestBench::kMovAvgExpectedOutput;
break;
}
@@ -109,7 +107,8 @@ TEST_P(FilterOutputTest, FilterOutput) {
m_data->Reset();
double filterOutput = 0.0;
for (double t = 0.0; t < TestBench::kFilterTime; t += TestBench::kFilterStep) {
for (double t = 0.0; t < TestBench::kFilterTime;
t += TestBench::kFilterStep) {
filterOutput = m_filter->PIDGet();
}

View File

@@ -11,12 +11,12 @@
#include <Talon.h>
#include <Timer.h>
#include <Victor.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
enum MotorEncoderTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
std::ostream &operator<<(std::ostream &os, MotorEncoderTestType const &type) {
std::ostream& operator<<(std::ostream& os, MotorEncoderTestType const& type) {
switch (type) {
case TEST_VICTOR:
os << "Victor";
@@ -41,8 +41,8 @@ static constexpr double kMotorTime = 0.5;
*/
class MotorEncoderTest : public testing::TestWithParam<MotorEncoderTestType> {
protected:
SpeedController *m_speedController;
Encoder *m_encoder;
SpeedController* m_speedController;
Encoder* m_encoder;
virtual void SetUp() override {
switch (GetParam()) {
@@ -145,7 +145,9 @@ TEST_P(MotorEncoderTest, PositionPIDController) {
RecordProperty("PIDError", pid.GetError());
EXPECT_TRUE(pid.OnTarget()) << "PID loop did not converge within 10 seconds. Goal was: "<<goal<<" Error was: "<<pid.GetError();
EXPECT_TRUE(pid.OnTarget())
<< "PID loop did not converge within 10 seconds. Goal was: " << goal
<< " Error was: " << pid.GetError();
}
/**
@@ -167,7 +169,9 @@ TEST_P(MotorEncoderTest, VelocityPIDController) {
pid.Disable();
RecordProperty("PIDError", pid.GetError());
EXPECT_TRUE(pid.OnTarget()) << "PID loop did not converge within 10 seconds. Goal was: " << 600 << " Error was: " << pid.GetError();
EXPECT_TRUE(pid.OnTarget())
<< "PID loop did not converge within 10 seconds. Goal was: " << 600
<< " Error was: " << pid.GetError();
}
/**

View File

@@ -10,13 +10,13 @@
#include <Talon.h>
#include <Timer.h>
#include <Victor.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
enum MotorInvertingTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
static const double motorSpeed = 0.15;
static const double delayTime = 0.5;
std::ostream &operator<<(std::ostream &os, MotorInvertingTestType const &type) {
std::ostream& operator<<(std::ostream& os, MotorInvertingTestType const& type) {
switch (type) {
case TEST_VICTOR:
os << "Victor";
@@ -34,8 +34,8 @@ std::ostream &operator<<(std::ostream &os, MotorInvertingTestType const &type) {
class MotorInvertingTest
: public testing::TestWithParam<MotorInvertingTestType> {
protected:
SpeedController *m_speedController;
Encoder *m_encoder;
SpeedController* m_speedController;
Encoder* m_encoder;
virtual void SetUp() override {
switch (GetParam()) {
case TEST_VICTOR:

View File

@@ -8,10 +8,10 @@
#include "HAL/cpp/priority_mutex.h"
#include "TestBench.h"
#include "gtest/gtest.h"
#include <atomic>
#include <condition_variable>
#include <thread>
#include "gtest/gtest.h"
namespace wpilib {
namespace testing {
@@ -67,7 +67,7 @@ void SetThreadRealtimePriorityOrDie(int priority) {
template <typename MutexType>
class LowPriorityThread {
public:
LowPriorityThread(MutexType *mutex)
LowPriorityThread(MutexType* mutex)
: m_mutex(mutex), m_hold_mutex(1), m_success(0) {}
void operator()() {
@@ -75,7 +75,8 @@ class LowPriorityThread {
SetThreadRealtimePriorityOrDie(20);
m_mutex->lock();
m_started.Notify();
while (m_hold_mutex.test_and_set()) {}
while (m_hold_mutex.test_and_set()) {
}
m_mutex->unlock();
m_success.store(1);
}
@@ -86,7 +87,7 @@ class LowPriorityThread {
private:
// priority_mutex to grab and release.
MutexType *m_mutex;
MutexType* m_mutex;
Notification m_started;
// Atomic type used to signal when the thread should unlock the mutex.
// Using a mutex to protect something could cause other issues, and a delay
@@ -134,7 +135,7 @@ class BusyWaitingThread {
template <typename MutexType>
class HighPriorityThread {
public:
HighPriorityThread(MutexType *mutex) : m_mutex(mutex), m_success(0) {}
HighPriorityThread(MutexType* mutex) : m_mutex(mutex), m_success(0) {}
void operator()() {
SetProcessorAffinity(0);
@@ -149,7 +150,7 @@ class HighPriorityThread {
private:
Notification m_started;
MutexType *m_mutex;
MutexType* m_mutex;
std::atomic<int> m_success;
};
@@ -220,7 +221,7 @@ class InversionTestRunner {
bool m_success = false;
};
//TODO: Fix roborio permissions to run as root.
// TODO: Fix roborio permissions to run as root.
// Priority inversion test.
TEST(MutexTest, DISABLED_PriorityInversionTest) {

View File

@@ -7,12 +7,12 @@
#include <Notifier.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
unsigned notifierCounter;
void notifierHandler(void *) { notifierCounter++; }
void notifierHandler(void*) { notifierCounter++; }
/**
* Test if the Wait function works

View File

@@ -12,8 +12,8 @@
#include <DoubleSolenoid.h>
#include <Solenoid.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
/* The PCM switches the compressor up to a couple seconds after the pressure
switch changes. */
@@ -29,11 +29,11 @@ static const double kCompressorOffVoltage = 1.68;
class PCMTest : public testing::Test {
protected:
Compressor *m_compressor;
Compressor* m_compressor;
DigitalOutput *m_fakePressureSwitch;
AnalogInput *m_fakeCompressor;
DoubleSolenoid *m_doubleSolenoid;
DigitalOutput* m_fakePressureSwitch;
AnalogInput* m_fakeCompressor;
DoubleSolenoid* m_doubleSolenoid;
DigitalInput *m_fakeSolenoid1, *m_fakeSolenoid2;
virtual void SetUp() override {
@@ -138,17 +138,20 @@ TEST_F(PCMTest, DoubleSolenoid) {
Wait(kSolenoidDelayTime);
EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kOff) << "Solenoid does not read off";
EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kOff)
<< "Solenoid does not read off";
solenoid.Set(DoubleSolenoid::kForward);
Wait(kSolenoidDelayTime);
EXPECT_FALSE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn on";
EXPECT_TRUE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn off";
EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kForward) << "Solenoid does not read forward";
EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kForward)
<< "Solenoid does not read forward";
solenoid.Set(DoubleSolenoid::kReverse);
Wait(kSolenoidDelayTime);
EXPECT_TRUE(m_fakeSolenoid1->Get()) << "Solenoid #1 did not turn off";
EXPECT_FALSE(m_fakeSolenoid2->Get()) << "Solenoid #2 did not turn on";
EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kReverse) << "Solenoid does not read reverse";
EXPECT_TRUE(solenoid.Get() == DoubleSolenoid::kReverse)
<< "Solenoid does not read reverse";
}

View File

@@ -6,74 +6,81 @@
/*----------------------------------------------------------------------------*/
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "PIDSource.h"
#include "PIDController.h"
#include "PIDOutput.h"
#include "PIDSource.h"
#include "TestBench.h"
#include "gtest/gtest.h"
class PIDToleranceTest : public testing::Test{
protected:
const double setpoint = 50.0;
const double range = 200;
const double tolerance = 10.0;
class fakeInput : public PIDSource{
public:
double val = 0;
void SetPIDSourceType(PIDSourceType pidSource){
}
PIDSourceType GetPIDSourceType(){
return PIDSourceType::kDisplacement;
}
double PIDGet(){;
return val;
}
};
class fakeOutput : public PIDOutput{
void PIDWrite(float output){
}
};
fakeInput inp;
fakeOutput out;
PIDController *pid;
virtual void SetUp() override {
pid = new PIDController(0.5,0.0,0.0,&inp,&out);
pid->SetInputRange(-range/2,range/2);
}
virtual void TearDown() override {
delete pid;
}
virtual void reset(){
inp.val = 0;
}
class PIDToleranceTest : public testing::Test {
protected:
const double setpoint = 50.0;
const double range = 200;
const double tolerance = 10.0;
class fakeInput : public PIDSource {
public:
double val = 0;
void SetPIDSourceType(PIDSourceType pidSource) {}
PIDSourceType GetPIDSourceType() { return PIDSourceType::kDisplacement; }
double PIDGet() {
;
return val;
}
};
class fakeOutput : public PIDOutput {
void PIDWrite(float output) {}
};
fakeInput inp;
fakeOutput out;
PIDController* pid;
virtual void SetUp() override {
pid = new PIDController(0.5, 0.0, 0.0, &inp, &out);
pid->SetInputRange(-range / 2, range / 2);
}
virtual void TearDown() override { delete pid; }
virtual void reset() { inp.val = 0; }
};
TEST_F(PIDToleranceTest, Absolute){
reset();
pid->SetAbsoluteTolerance(tolerance);
pid->SetSetpoint(setpoint);
pid->Enable();
EXPECT_FALSE(pid->OnTarget())<<"Error was in tolerance when it should not have been. Error was " << pid->GetAvgError();
inp.val = setpoint+tolerance/2;
Wait(1.0);
EXPECT_TRUE(pid->OnTarget())<<"Error was not in tolerance when it should have been. Error was " << pid->GetAvgError();
inp.val = setpoint+10*tolerance;
Wait(1.0);
EXPECT_FALSE(pid->OnTarget())<<"Error was in tolerance when it should not have been. Error was " << pid->GetAvgError();
TEST_F(PIDToleranceTest, Absolute) {
reset();
pid->SetAbsoluteTolerance(tolerance);
pid->SetSetpoint(setpoint);
pid->Enable();
EXPECT_FALSE(pid->OnTarget())
<< "Error was in tolerance when it should not have been. Error was "
<< pid->GetAvgError();
inp.val = setpoint + tolerance / 2;
Wait(1.0);
EXPECT_TRUE(pid->OnTarget())
<< "Error was not in tolerance when it should have been. Error was "
<< pid->GetAvgError();
inp.val = setpoint + 10 * tolerance;
Wait(1.0);
EXPECT_FALSE(pid->OnTarget())
<< "Error was in tolerance when it should not have been. Error was "
<< pid->GetAvgError();
}
TEST_F(PIDToleranceTest, Percent){
reset();
pid->SetPercentTolerance(tolerance);
pid->SetSetpoint(setpoint);
pid->Enable();
EXPECT_FALSE(pid->OnTarget())<<"Error was in tolerance when it should not have been. Error was " << pid->GetAvgError();
inp.val = setpoint+(tolerance)/200*range;//half of percent tolerance away from setpoint
Wait(1.0);
EXPECT_TRUE(pid->OnTarget())<<"Error was not in tolerance when it should have been. Error was " << pid->GetAvgError();
inp.val = setpoint+(tolerance)/50*range;//double percent tolerance away from setPoint
Wait(1.0);
EXPECT_FALSE(pid->OnTarget())<<"Error was in tolerance when it should not have been. Error was " << pid->GetAvgError();
TEST_F(PIDToleranceTest, Percent) {
reset();
pid->SetPercentTolerance(tolerance);
pid->SetSetpoint(setpoint);
pid->Enable();
EXPECT_FALSE(pid->OnTarget())
<< "Error was in tolerance when it should not have been. Error was "
<< pid->GetAvgError();
inp.val = setpoint +
(tolerance) / 200 *
range; // half of percent tolerance away from setpoint
Wait(1.0);
EXPECT_TRUE(pid->OnTarget())
<< "Error was not in tolerance when it should have been. Error was "
<< pid->GetAvgError();
inp.val =
setpoint +
(tolerance) / 50 * range; // double percent tolerance away from setPoint
Wait(1.0);
EXPECT_FALSE(pid->OnTarget())
<< "Error was in tolerance when it should not have been. Error was "
<< pid->GetAvgError();
}

View File

@@ -10,17 +10,17 @@
#include <Talon.h>
#include <Timer.h>
#include <Victor.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static const double kMotorTime = 0.25;
class PowerDistributionPanelTest : public testing::Test {
protected:
PowerDistributionPanel *m_pdp;
Talon *m_talon;
Victor *m_victor;
Jaguar *m_jaguar;
PowerDistributionPanel* m_pdp;
Talon* m_talon;
Victor* m_victor;
Jaguar* m_jaguar;
virtual void SetUp() override {
m_pdp = new PowerDistributionPanel();
@@ -55,4 +55,3 @@ TEST_F(PowerDistributionPanelTest, CheckCurrentTalon) {
ASSERT_GT(m_pdp->GetCurrent(TestBench::kTalonPDPChannel), 0)
<< "The Talon current was not positive";
}

View File

@@ -7,11 +7,11 @@
#include <Preferences.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include <cstdio>
#include <fstream>
#include "gtest/gtest.h"
static const char *kFileName = "networktables.ini";
static const char* kFileName = "networktables.ini";
static const double kSaveTime = 1.2;
/**
@@ -23,17 +23,23 @@ TEST(PreferencesTest, ReadPreferencesFromFile) {
std::remove(kFileName);
std::ofstream preferencesFile(kFileName);
preferencesFile << "[NetworkTables Storage 3.0]" << std::endl;
preferencesFile << "string \"/Preferences/testFileGetString\"=\"Hello, preferences file\""
<< std::endl;
preferencesFile
<< "string \"/Preferences/testFileGetString\"=\"Hello, preferences file\""
<< std::endl;
preferencesFile << "double \"/Preferences/testFileGetInt\"=1" << std::endl;
preferencesFile << "double \"/Preferences/testFileGetDouble\"=0.5" << std::endl;
preferencesFile << "double \"/Preferences/testFileGetFloat\"=0.25" << std::endl;
preferencesFile << "boolean \"/Preferences/testFileGetBoolean\"=true" << std::endl;
preferencesFile << "double \"/Preferences/testFileGetLong\"=1000000000000000000" << std::endl;
preferencesFile << "double \"/Preferences/testFileGetDouble\"=0.5"
<< std::endl;
preferencesFile << "double \"/Preferences/testFileGetFloat\"=0.25"
<< std::endl;
preferencesFile << "boolean \"/Preferences/testFileGetBoolean\"=true"
<< std::endl;
preferencesFile
<< "double \"/Preferences/testFileGetLong\"=1000000000000000000"
<< std::endl;
preferencesFile.close();
NetworkTable::Initialize();
Preferences *preferences = Preferences::GetInstance();
Preferences* preferences = Preferences::GetInstance();
EXPECT_EQ("Hello, preferences file",
preferences->GetString("testFileGetString"));
EXPECT_EQ(1, preferences->GetInt("testFileGetInt"));
@@ -52,7 +58,7 @@ TEST(PreferencesTest, WritePreferencesToFile) {
NetworkTable::GlobalDeleteAll();
std::remove(kFileName);
NetworkTable::Initialize();
Preferences *preferences = Preferences::GetInstance();
Preferences* preferences = Preferences::GetInstance();
preferences->PutString("testFilePutString", "Hello, preferences file");
preferences->PutInt("testFilePutInt", 1);
preferences->PutDouble("testFilePutDouble", 0.5);
@@ -63,7 +69,7 @@ TEST(PreferencesTest, WritePreferencesToFile) {
Wait(kSaveTime);
static char const *kExpectedFileContents[] = {
static char const* kExpectedFileContents[] = {
"[NetworkTables Storage 3.0]",
"boolean \"/Preferences/testFilePutBoolean\"=true",
"double \"/Preferences/testFilePutDouble\"=0.5",

View File

@@ -5,20 +5,20 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include "Relay.h"
#include <DigitalInput.h>
#include <Relay.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "Relay.h"
#include "gtest/gtest.h"
static const double kDelayTime = 0.01;
class RelayTest : public testing::Test {
protected:
Relay *m_relay;
DigitalInput *m_forward;
DigitalInput *m_reverse;
Relay* m_relay;
DigitalInput* m_forward;
DigitalInput* m_reverse;
virtual void SetUp() override {
m_relay = new Relay(TestBench::kRelayChannel);

View File

@@ -42,5 +42,5 @@ class TestEnvironment : public testing::Environment {
virtual void TearDown() override {}
};
testing::Environment *const environment =
testing::Environment* const environment =
testing::AddGlobalTestEnvironment(new TestEnvironment);

View File

@@ -9,8 +9,8 @@
#include <AnalogGyro.h>
#include <Servo.h>
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static constexpr double kServoResetTime = 2.0;
@@ -29,9 +29,9 @@ static constexpr double kSensitivity = 0.013;
*/
class TiltPanCameraTest : public testing::Test {
protected:
static AnalogGyro *m_gyro;
static AnalogGyro* m_gyro;
Servo *m_tilt, *m_pan;
Accelerometer *m_spiAccel;
Accelerometer* m_spiAccel;
static void SetUpTestCase() {
// The gyro object blocks for 5 seconds in the constructor, so only
@@ -66,7 +66,7 @@ class TiltPanCameraTest : public testing::Test {
}
};
AnalogGyro *TiltPanCameraTest::m_gyro = nullptr;
AnalogGyro* TiltPanCameraTest::m_gyro = nullptr;
/**
* Test if the gyro angle defaults to 0 immediately after being reset.

View File

@@ -6,14 +6,14 @@
/*----------------------------------------------------------------------------*/
#include <Timer.h>
#include "gtest/gtest.h"
#include "TestBench.h"
#include "gtest/gtest.h"
static const double kWaitTime = 0.5;
class TimerTest : public testing::Test {
protected:
Timer *m_timer;
Timer* m_timer;
virtual void SetUp() override { m_timer = new Timer; }

View File

@@ -32,7 +32,7 @@ class CommandTest : public testing::Test {
*/
void TeardownScheduler() { Scheduler::GetInstance()->ResetAll(); }
void AssertCommandState(MockCommand &command, int initialize, int execute,
void AssertCommandState(MockCommand& command, int initialize, int execute,
int isFinished, int end, int interrupted) {
EXPECT_EQ(initialize, command.GetInitializeCount());
EXPECT_EQ(execute, command.GetExecuteCount());
@@ -44,10 +44,10 @@ class CommandTest : public testing::Test {
class ASubsystem : public Subsystem {
private:
Command *m_command = nullptr;
Command* m_command = nullptr;
public:
ASubsystem(const std::string &name) : Subsystem(name) {}
ASubsystem(const std::string& name) : Subsystem(name) {}
virtual void InitDefaultCommand() override {
if (m_command != nullptr) {
@@ -55,7 +55,7 @@ class ASubsystem : public Subsystem {
}
}
void Init(Command *command) { m_command = command; }
void Init(Command* command) { m_command = command; }
};
// CommandParallelGroupTest ported from CommandParallelGroupTest.java