blob: b3f55002a5dd376c3171562096eb222e5048aa0c [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* 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 <DriverStation.h>
9#include <LiveWindow/LiveWindow.h>
10#include <Timer.h>
11#include "gtest/gtest.h"
12
13class TestEnvironment : public testing::Environment {
14 bool m_alreadySetUp = false;
15
16 public:
17 virtual void SetUp() override {
18 /* Only set up once. This allows gtest_repeat to be used to
19 automatically repeat tests. */
20 if (m_alreadySetUp) return;
21 m_alreadySetUp = true;
22
23 if (!HALInitialize()) {
24 std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl;
25 exit(-1);
26 }
27
28 /* This sets up the network communications library to enable the driver
29 station. After starting network coms, it will loop until the driver
30 station returns that the robot is enabled, to ensure that tests
31 will be able to run on the hardware. */
32 HALNetworkCommunicationObserveUserProgramStarting();
33 LiveWindow::GetInstance()->SetEnabled(false);
34
35 std::cout << "Waiting for enable" << std::endl;
36
37 while (!DriverStation::GetInstance().IsEnabled()) {
38 Wait(0.1);
39 }
40 }
41
42 virtual void TearDown() override {}
43};
44
45testing::Environment *const environment =
46 testing::AddGlobalTestEnvironment(new TestEnvironment);