cpp_photon/test/ConfigFile_test.cpp

55 lines
1.5 KiB
C++
Raw Normal View History

2005-05-15 02:50:07 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
2005-07-19 18:41:36 +00:00
// $Id: ConfigFile_test.cpp,v 1.2 2005/07/19 18:41:36 cozman Exp $
2005-05-15 02:50:07 +00:00
#include "photon.hpp"
#include <iostream>
#include <cassert>
using namespace photon;
2005-07-19 18:41:36 +00:00
// Simple test of ConfigFile functionality
// Tests reading/writing to a ConfigFile
// Successful test will simply output a message indicating success.
2005-05-15 02:50:07 +00:00
class ConfigTest : public Application
{
public:
int main(const StrVec& args)
{
2005-07-19 18:41:36 +00:00
util::ConfigFile c1("config1.ini"),c2;
2005-05-15 02:50:07 +00:00
c2.open("config2.ini");
2005-07-19 18:41:36 +00:00
// set three variables
2005-05-15 02:50:07 +00:00
c1.setVariable("sec","int",3);
c1.setVariable("sec","float",3.0f);
c1.setVariable("sec","string","three");
2005-07-19 18:41:36 +00:00
// ensure all 3 variables were written correctly
2005-05-15 02:50:07 +00:00
assert(c1.getVariable("sec","int",0) == 3);
assert(c1.getVariable("sec","float",0.0f) == 3.0f);
assert(c1.getVariable("sec","string",std::string()) == "three");
2005-07-19 18:41:36 +00:00
// check reading/default value functionality
2005-05-15 02:50:07 +00:00
assert(c2.getVariable("sec","var",-1) != -1);
assert(c2.getVariable("sec2","var",-1) != -1);
assert(c2.getVariable("sec2","hex",0) == 0);
c1.close();
c2.close();
2005-07-19 18:41:36 +00:00
// got here, meaning success
std::cerr << "ConfigFile test completed successfully!\n";
2005-05-15 02:50:07 +00:00
return 0;
}
};
2005-07-19 18:41:36 +00:00
ENTRYPOINT(ConfigTest) // make ConfigTest the entrypoint class