/**
 * If we write a new networktables.ini with some sample values, test that
 * we get those same values back using the Preference class.
 */
TEST(PreferencesTest, ReadPreferencesFromFile) {
  NetworkTable::Shutdown();
  std::remove(kFileName);
  std::ofstream preferencesFile(kFileName);
  preferencesFile << "[NetworkTables Storage 3.0]" << 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.close();
  NetworkTable::Initialize();

  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"));
}
Exemple #2
0
void CameraTest::Execute() {
    cameraLEDsSubsystem->GreenOn();
    cameraLEDsSubsystem->BlueOff();

    // Allow time for the LEDs to light up
    if(!timer->HasPeriodPassed(0.1)) { return; }   // min tested was 80ms

    Preferences * prefs = Preferences::GetInstance();

    // Capture an image from the camera and save it to flash
    timer->Reset();
    ColorImage * image;
    if (prefs->GetInt("image_retain", 1) == 1) {
        cameraSubsystem->RetainImage("/cameratest.jpg");
        image = cameraSubsystem->CaptureImage();
        cameraSubsystem->RetainImage(NULL);  // stop retaining
        printf("[CAMERA] Captured image and wrote to /cameratest.jpg in %.1f ms\n", timer->Get() * 1000);
    } else {
        image = cameraSubsystem->CaptureImage();
        printf("[CAMERA] Captured image in %.1f ms\n", timer->Get() * 1000);
    }

    // Load preferences for filtering threshold image
    Threshold threshold = Threshold(prefs->GetInt("hue_low", 100), prefs->GetInt("hue_high", 140),
                                    prefs->GetInt("sat_low", 90), prefs->GetInt("sat_high", 255),
                                    prefs->GetInt("lum_low", 20), prefs->GetInt("lum_high", 255));

    // Process the captured image
    timer->Reset();
    ImageProcessor * ip = new ImageProcessor();
    ip->SetThreshold(threshold);
    ip->Process(image);
    printf("[CAMERA] Image processed in %.1f ms\n", timer->Get() * 1000);

    // Write the processed images to flash
    if (prefs->GetInt("image_retain", 1) == 1) {
        timer->Reset();
        ip->WriteImages("/cameratest");
        printf("[CAMERA] Processed images written to /cameratest.*.bmp in %.1f ms\n", timer->Get() * 1000);
    }

    // Generate a target report
    timer->Reset();
    TargetReport * tr = new TargetReport(ip->GetThresholdImage(), ip->GetFilteredImage());
    tr->Generate();
    printf("[CAMERA] Target report generated in %.1f ms\n", timer->Get() * 1000);

    tr->OutputScores();

    finished = true;

    delete tr;
    delete ip;
}