diff options
author | deva <deva> | 2009-07-24 09:11:52 +0000 |
---|---|---|
committer | deva <deva> | 2009-07-24 09:11:52 +0000 |
commit | 511859ef8028bb75032a965b490faa67b174a4e6 (patch) | |
tree | f803fce448b03f9a0586a493484983ea59215025 /server/src/macrolist.cc | |
parent | cdc1e51494c6afc16f00e2d5829db5250a801f42 (diff) |
Made some more tests, and documented the header file.
Diffstat (limited to 'server/src/macrolist.cc')
-rw-r--r-- | server/src/macrolist.cc | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/server/src/macrolist.cc b/server/src/macrolist.cc index 1117ed9..f067fb1 100644 --- a/server/src/macrolist.cc +++ b/server/src/macrolist.cc @@ -70,9 +70,9 @@ MacroList::MacroList(std::string macropath) } } -std::string MacroList::getLatestVersion(std::string macro) +std::string MacroList::getLatestVersion(std::string macro) throw(Exception) { - if(find(macro) == end()) return ""; + if(find(macro) == end()) throw Exception("Macro ["+macro+"] does not exist"); MacroListItem mli = (*this)[macro]; if(mli.size() == 0) return ""; printf("Search for %s - found %s v%s\n", @@ -84,9 +84,12 @@ std::string MacroList::getLatestVersion(std::string macro) #ifdef TEST_MACROLIST +#define MACRODIR "/home" // We assume this directory exists and does not contain any xml files! + int main() { - MacroList lst("/home"); + // Test sorting + MacroList lst(MACRODIR); lst["macro1"][VersionStr("1.0")] = "macro1-1.0.xml"; lst["macro1"][VersionStr("1.1")] = "macro1-1.1.xml"; @@ -95,19 +98,53 @@ int main() lst["macro2"][VersionStr("1.0")] = "macro2.xml"; lst["macro3"][VersionStr("1.0")] = "macro3.xml"; + std::vector<std::string> refs; + refs.push_back("macro1-1.2.xml"); + refs.push_back("macro1-1.1.1.xml"); + refs.push_back("macro1-1.1.xml"); + refs.push_back("macro1-1.0.xml"); + refs.push_back("macro2.xml"); + refs.push_back("macro3.xml"); + MacroList::iterator i = lst.begin(); + std::vector<std::string>::iterator k = refs.begin(); while(i != lst.end()) { MacroListItem::iterator j = i->second.begin(); while(j != i->second.end()) { - printf("%s - v%s file: %s\n", + printf("%s - v%s file: %s - should be %s\n", i->first.c_str(), ((std::string)j->first).c_str(), - j->second.c_str()); - j++; + j->second.c_str(), + k->c_str()); + if(j->second != *k) return 1; + j++; k++; } i++; } + // Test lookup of latest versions. + std::string m1 = lst.getLatestVersion("macro1"); + printf("Latest macro1: %s\n", m1.c_str()); + if(m1 != MACRODIR"/macro1-1.2.xml") return 1; + + std::string m2 = lst.getLatestVersion("macro2"); + printf("Latest macro2: %s\n", m2.c_str()); + if(m2 != MACRODIR"/macro2.xml") return 1; + + std::string m3 = lst.getLatestVersion("macro3"); + printf("Latest macro3: %s\n", m3.c_str()); + if(m3 != MACRODIR"/macro3.xml") return 1; + + // Look for non existing macro (this should throw an exception) + try { + std::string m4 = lst.getLatestVersion("macro4"); + } catch(Exception &e) { + printf("ERROR: %s\n", e.what()); + goto onandon; + } + return 1; + onandon: + return 0; } |