From 3aa1273512cbb5a8b587589724d5eb1baab10103 Mon Sep 17 00:00:00 2001 From: Phitherek Date: Mon, 18 Mar 2013 23:55:04 +0100 Subject: [PATCH] ConfigFile class after tests, written Makefiles --- ConfigFile.cpp | 6 +++--- ConfigFile.h | 1 + Makefile | 20 +++++++++----------- tests/ConfigFileTest.cpp | 37 +++++++++++++++++++++++++++++++++++++ tests/Makefile | 7 +++++++ 5 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 tests/ConfigFileTest.cpp create mode 100644 tests/Makefile diff --git a/ConfigFile.cpp b/ConfigFile.cpp index 9362ef0..77c4ccf 100644 --- a/ConfigFile.cpp +++ b/ConfigFile.cpp @@ -10,15 +10,15 @@ conf.close(); throw FileException(path, "reading", "Could not open file!"); } _path = path; -string action = "parse"; +std::string action = "parse"; while(!conf.eof()) { std::string line = ""; conf >> line; if(conf) { if(action == "parse") { if(line[0] == '[') { -int i = 1; -string sa = ""; +unsigned int i = 1; +std::string sa = ""; while(line[i] != ']') { if(i >= line.length()-1 && line[i] != ']') { std::string err = ""; diff --git a/ConfigFile.h b/ConfigFile.h index 62da438..3ae4fe1 100644 --- a/ConfigFile.h +++ b/ConfigFile.h @@ -32,3 +32,4 @@ public: void write(); ///< A function that writes the changes to config file. }; } +#endif diff --git a/Makefile b/Makefile index ca1ae8f..f35a40e 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,15 @@ all: - g++ -o 3m 3m.cpp make -C filetesters + make -C tests debug: - g++ -o 3m 3m.cpp -g make -C filetesters debug + make -C tests debug clean: - rm 3m make -C filetesters clean + make -C tests clean cleantemp: rm *~ make -C filetesters cleantemp -3m: - g++ -o 3m 3m.cpp -3mdebug: - g++ -o 3m 3m.cpp -g -3mclean: - rm 3m -3mcleantemp: - rm *~ filetesters: make -C filetesters ftdebug: @@ -26,3 +18,9 @@ ftclean: make -C filetesters clean ftcleantemp: make -C filetesters cleantemp +tests: + make -C tests +testsdebug: + make -C tests debug +testsclean: + make -C testsclean diff --git a/tests/ConfigFileTest.cpp b/tests/ConfigFileTest.cpp new file mode 100644 index 0000000..446b17a --- /dev/null +++ b/tests/ConfigFileTest.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include "../ConfigFile.h" +#include "../3mExceptions.h" +using namespace std; + +int main() { +cout << "3m Tests: ConfigFile v. 0.1 (C) 2013 by Phitherek_" << endl; +cout << "Give me the settings path: "; +string path; +cin >> path; +try { +mmm::ConfigFile conf(path); +cout << "Config parsed successfully! Here are the results: " << endl << "localpath: " << conf.getLocalPath() << endl << "modlist: " << conf.getModList() << endl << "repoinfo: " << conf.getRepoInfo() << endl; +string localpath, modlist, repoinfo; +cout << "Enter new localpath: " << endl; +cin >> localpath; +cout << "modlist: " << endl; +cin >> modlist; +cout << "repoinfo: " << endl; +cin >> repoinfo; +conf.getLocalPath() = localpath; +conf.getModList() = modlist; +conf.getRepoInfo() = repoinfo; +cout << "Generating the config file..." << endl; +conf.write(); +cout << "All OK! Thank you for testing!" << endl; +return EXIT_SUCCESS; +} catch(mmm::FileException& exc) { +cout << "File exception occured: " << exc.what() << endl; +return 1; +} catch(mmm::ParseException& exc) { +cout << "Parse exception occured: " << exc.what() << endl; +return 2; +} +} diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..60461c7 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,7 @@ +CXXFLAGS=-Wall +all: + ${CXX} ${CXXFLAGS} -o ConfigFileTest ConfigFileTest.cpp ../ConfigFile.cpp ../3mExceptions.cpp +debug: + ${CXX} ${CXXFLAGS} -o ConfigFileTest ConfigFileTest.cpp ../ConfigFile.cpp ../3mExceptions.cpp -g +clean: + rm -rf ConfigFileTest