Ejemplo n.º 1
0
void PreferencesTest::testSave() {
  ola::FilePreferenceSaverThread saver_thread;
  saver_thread.Start();
  FileBackedPreferences *preferences = new FileBackedPreferences(
      ".", "output", &saver_thread);
  preferences->Clear();

  string data_path = "./ola-output.conf";
  unlink(data_path.c_str());
  string key1 = "foo";
  string key2 = "bat";
  string key3 = "/dev/ttyUSB0";
  string value1 = "bar";
  string value2 = "baz";
  string value3 = "boo";
  string multi_key = "multi";
  preferences->SetValue(key1, value1);
  preferences->SetValue(key2, value2);
  preferences->SetValue(key3, value3);
  preferences->SetMultipleValue(multi_key, "1");
  preferences->SetMultipleValue(multi_key, "2");
  preferences->SetMultipleValue(multi_key, "3");
  preferences->Save();

  saver_thread.Syncronize();

  FileBackedPreferences *input_preferences = new
    FileBackedPreferences("", "input", NULL);
  input_preferences->LoadFromFile(data_path);
  OLA_ASSERT(*preferences == *input_preferences);
  delete preferences;
  delete input_preferences;

  saver_thread.Join();
}
Ejemplo n.º 2
0
/*
 * Check that we can load from a file
 */
void PreferencesTest::testLoad() {
  FileBackedPreferences *preferences = new FileBackedPreferences(
      "", "dummy", NULL);
  preferences->Clear();
  preferences->SetValue("foo", "bad");
  preferences->LoadFromFile("./testdata/test_preferences.conf");

  OLA_ASSERT_EQ(string("bar"), preferences->GetValue("foo"));
  OLA_ASSERT_EQ(string("bat"), preferences->GetValue("baz"));

  vector<string> values = preferences->GetMultipleValue("multi");
  OLA_ASSERT_EQ((size_t) 3, values.size());
  OLA_ASSERT_EQ(string("1"), values.at(0));
  OLA_ASSERT_EQ(string("2"), values.at(1));
  OLA_ASSERT_EQ(string("3"), values.at(2));
  delete preferences;
}