2014-07-30 17:32:14 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
Replaced WPILib.h includes in integration tests with the minimum required subheaders to improve compilation times
I ran the benchmark in a tmpfs with an Intel Core i5-2430M. I ran it three times for each combination of build invokation and source tree.
First, I tested "make". For master (eb7d55f), I measured an average of 42.751s with a standard deviation of 0.372s. For this commit, I measured an average of 33.394s with a standard deviation of 0.140s. There was a 9.356s, or 22%, improvement with a total error of 1.3%.
Second, I tested "make -j4". For master (eb7d55f), I measured an average of 21.723s with a standard deviation of 0.158s. For this commit, I measured an average of 16.823s with a standard deviation of 0.340s. There was a 4.900s, or 23%, improvement with a total error of 2.7%.
Change-Id: Idb3adce62ed8ef449360c6583896b6da3565cf58
2015-07-22 02:34:12 -07:00
|
|
|
#include <Preferences.h>
|
|
|
|
|
#include <Timer.h>
|
2014-07-30 17:32:14 -04:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
2014-09-10 14:05:51 -04:00
|
|
|
static const char *kFileName = "/home/lvuser/wpilib-preferences.ini";
|
2014-07-30 17:32:14 -04:00
|
|
|
static const double kSaveTime = 0.2;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If we write a new wpilib-preference.ini with some sample values, test that
|
|
|
|
|
* we get those same values back using the Preference class.
|
|
|
|
|
*/
|
|
|
|
|
TEST(PreferencesTest, ReadPreferencesFromFile) {
|
2015-06-25 15:07:55 -04:00
|
|
|
std::remove(kFileName);
|
|
|
|
|
std::ofstream preferencesFile(kFileName);
|
|
|
|
|
preferencesFile << "[Preferences]" << std::endl;
|
|
|
|
|
preferencesFile << "testFileGetString=\"Hello, preferences file\""
|
|
|
|
|
<< std::endl;
|
|
|
|
|
preferencesFile << "testFileGetInt=\"1\"" << std::endl;
|
|
|
|
|
preferencesFile << "testFileGetDouble=\"0.5\"" << std::endl;
|
|
|
|
|
preferencesFile << "testFileGetFloat=\"0.25\"" << std::endl;
|
|
|
|
|
preferencesFile << "testFileGetBoolean=\"true\"" << std::endl;
|
|
|
|
|
preferencesFile << "testFileGetLong=\"1000000000000000000\"" << std::endl;
|
|
|
|
|
preferencesFile.close();
|
2014-07-30 17:32:14 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Preferences *preferences = Preferences::GetInstance();
|
|
|
|
|
EXPECT_EQ("Hello, preferences file",
|
|
|
|
|
preferences->GetString("testFileGetString"));
|
|
|
|
|
EXPECT_EQ(1, preferences->GetInt("testFileGetInt"));
|
|
|
|
|
EXPECT_FLOAT_EQ(0.5, preferences->GetDouble("testFileGetDouble"));
|
|
|
|
|
EXPECT_FLOAT_EQ(0.25f, preferences->GetFloat("testFileGetFloat"));
|
|
|
|
|
EXPECT_TRUE(preferences->GetBoolean("testFileGetBoolean"));
|
|
|
|
|
EXPECT_EQ(1000000000000000000ll, preferences->GetLong("testFileGetLong"));
|
2014-07-30 17:32:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If we set some values using the Preferences class, test that they show up
|
|
|
|
|
* in wpilib-preferences.ini
|
|
|
|
|
*/
|
|
|
|
|
TEST(PreferencesTest, WritePreferencesToFile) {
|
2015-06-25 15:07:55 -04:00
|
|
|
Preferences *preferences = Preferences::GetInstance();
|
|
|
|
|
preferences->PutString("testFilePutString", "Hello, preferences file");
|
|
|
|
|
preferences->PutInt("testFilePutInt", 1);
|
|
|
|
|
preferences->PutDouble("testFilePutDouble", 0.5);
|
|
|
|
|
preferences->PutFloat("testFilePutFloat", 0.25f);
|
|
|
|
|
preferences->PutBoolean("testFilePutBoolean", true);
|
|
|
|
|
preferences->PutLong("testFilePutLong", 1000000000000000000ll);
|
|
|
|
|
preferences->Save();
|
2014-07-30 17:32:14 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
Wait(kSaveTime);
|
2014-07-30 17:32:14 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
static char const *kExpectedFileContents[] = {
|
|
|
|
|
"[Preferences]", "testFileGetString=\"Hello, preferences file\"",
|
|
|
|
|
"testFileGetInt=\"1\"", "testFileGetDouble=\"0.5\"",
|
|
|
|
|
"testFileGetFloat=\"0.25\"", "testFileGetBoolean=\"true\"",
|
|
|
|
|
"testFileGetLong=\"1000000000000000000\""};
|
2014-07-30 17:32:14 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
std::ifstream preferencesFile(kFileName);
|
2015-06-23 04:49:51 -07:00
|
|
|
for (auto& kExpectedFileContent : kExpectedFileContents) {
|
2015-06-25 15:07:55 -04:00
|
|
|
ASSERT_FALSE(preferencesFile.eof())
|
|
|
|
|
<< "Preferences file prematurely reached EOF";
|
2014-07-30 17:32:14 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
std::string line;
|
|
|
|
|
std::getline(preferencesFile, line);
|
2014-07-30 17:32:14 -04:00
|
|
|
|
2015-06-23 04:49:51 -07:00
|
|
|
ASSERT_EQ(kExpectedFileContent, line)
|
2015-06-25 15:07:55 -04:00
|
|
|
<< "A line in wpilib-preferences.ini was not correct";
|
|
|
|
|
}
|
2014-07-30 17:32:14 -04:00
|
|
|
}
|