Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2014-2017. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include <cstdlib> |
| 9 | |
| 10 | #include "DriverStation.h" |
| 11 | #include "HAL/HAL.h" |
| 12 | #include "LiveWindow/LiveWindow.h" |
| 13 | #include "Timer.h" |
| 14 | #include "gtest/gtest.h" |
| 15 | |
| 16 | using namespace frc; |
| 17 | |
| 18 | class TestEnvironment : public testing::Environment { |
| 19 | bool m_alreadySetUp = false; |
| 20 | |
| 21 | public: |
| 22 | void SetUp() override { |
| 23 | /* Only set up once. This allows gtest_repeat to be used to |
| 24 | automatically repeat tests. */ |
| 25 | if (m_alreadySetUp) return; |
| 26 | m_alreadySetUp = true; |
| 27 | |
| 28 | if (!HAL_Initialize(0)) { |
| 29 | std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; |
| 30 | std::exit(-1); |
| 31 | } |
| 32 | |
| 33 | /* This sets up the network communications library to enable the driver |
| 34 | station. After starting network coms, it will loop until the driver |
| 35 | station returns that the robot is enabled, to ensure that tests |
| 36 | will be able to run on the hardware. */ |
| 37 | HAL_ObserveUserProgramStarting(); |
| 38 | LiveWindow::GetInstance()->SetEnabled(false); |
| 39 | |
| 40 | std::cout << "Waiting for enable" << std::endl; |
| 41 | |
| 42 | while (!DriverStation::GetInstance().IsEnabled()) { |
| 43 | Wait(0.1); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void TearDown() override {} |
| 48 | }; |
| 49 | |
| 50 | testing::Environment* const environment = |
| 51 | testing::AddGlobalTestEnvironment(new TestEnvironment); |