From ccb2beb0e1e078a33a8603ec591adadf78ff148a Mon Sep 17 00:00:00 2001 From: fluxgen Date: Mon, 4 Feb 2002 23:48:31 +0000 Subject: initial import --- src/tests/Makefile | 33 ++++++++++ src/tests/Resourcetest.cc | 139 +++++++++++++++++++++++++++++++++++++++++++ src/tests/StringUtiltest.cc | 140 +++++++++++++++++++++++++++++++++++++++++++ src/tests/keys | 30 ++++++++++ src/tests/main.cc | 142 ++++++++++++++++++++++++++++++++++++++++++++ src/tests/testKeys.cc | 66 ++++++++++++++++++++ 6 files changed, 550 insertions(+) create mode 100644 src/tests/Makefile create mode 100644 src/tests/Resourcetest.cc create mode 100644 src/tests/StringUtiltest.cc create mode 100644 src/tests/keys create mode 100644 src/tests/main.cc create mode 100644 src/tests/testKeys.cc diff --git a/src/tests/Makefile b/src/tests/Makefile new file mode 100644 index 0000000..ac8fdb0 --- /dev/null +++ b/src/tests/Makefile @@ -0,0 +1,33 @@ +OBJ=StringUtiltest.o ../StringUtil.o +CXX=g++ +CXXFLAGS= -I.. -DDEBUG -Wall -g -O2 +LIBS= +XFLAGS= -I/usr/X11R6/include +XLIBS= -L/usr/X11R6/lib -lX11 +all: testStringUtil testKeys testResource + +.cc.o: + $(CXX) -c $(CXXFLAGS) $< + +StringUtil.o: ../StringUtil.cc ../StringUtil.hh + $(CXX) -c $(CXXFLAGS) ../StringUtil.cc -o StringUtil.o + +Keys.o: ../Keys.cc ../Keys.hh + $(CXX) -c $(CXXFLAGS) $(XFLAGS) ../Keys.cc -o Keys.o + +Resource.o: ../Resource.cc ../Resource.hh + $(CXX) -c $(CXXFLAGS) $(XFLAGS) ../Resource.cc -o Resource.o + +testStringUtil: StringUtiltest.o StringUtil.o + $(CXX) $(LIBS) StringUtiltest.o StringUtil.o -o testStringUtil +testKeys: Keys.o testKeys.o StringUtil.o + $(CXX) $(LIBS) $(XLIBS) StringUtil.o Keys.o testKeys.o -o testKeys +testResource: Resourcetest.o Resource.o + ${CXX} ${LIBS} ${XLIBS} Resourcetest.o Resource.o -o testResource + +run: testResource testKeys testStringUtil + ./testKeys + ./testStringUtil + ./testResource +clean: + rm -f *.o diff --git a/src/tests/Resourcetest.cc b/src/tests/Resourcetest.cc new file mode 100644 index 0000000..8cfae58 --- /dev/null +++ b/src/tests/Resourcetest.cc @@ -0,0 +1,139 @@ +// Resourcetest.cc +// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "Resource.hh" + +//use of strcasecmp +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif // _GNU_SOURCE + +#include +#include + +using namespace std; + +enum TestEnum{TEST1, THIS_IS_TRUE, USE_LOVE}; + +//---------------- +// Manipulators +//----------------- + +template<> +void Resource:: +setFromString(const char *str) { + if (strcasecmp(str, "TEST1")==0) + *this = TEST1; + else if (strcasecmp(str, "THIS_IS_TRUE")==0) + *this = THIS_IS_TRUE; + else if (strcasecmp(str, "USE_LOVE")==0) + *this = USE_LOVE; +} + +template<> +void Resource:: +setFromString(const char* strval) { + int val; + if (sscanf(strval, "%d", &val)==1) + *this = val; +} + +template<> +void Resource:: +setFromString(const char *strval) { + *this = strval; +} + +template<> +void Resource:: +setFromString(char const *strval) { + if (strcasecmp(strval, "true")==0) + *this = true; + else + *this = false; +} + +//----------------- +// accessors +//----------------- +template<> +std::string Resource:: +getString() { + switch (m_value) { + case TEST1: + return string("TEST1"); + case THIS_IS_TRUE: + return string("THIS_IS_TRUE"); + case USE_LOVE: + return string("USE_LOVE"); + } + return string(""); +} + +template<> +std::string Resource:: +getString() { + return std::string(**this == true ? "true" : "false"); +} + +template<> +std::string Resource:: +getString() { + char strval[256]; + sprintf(strval, "%d", **this); + return std::string(strval); +} + +template<> +std::string Resource:: +getString() { return **this; } + +int main(int argc, char **argv) { + + ResourceManager rm; + // resources + Resource val(rm, 123, "session.test", "Session.Test"); + Resource boolval(rm, true, "session.bool", "Session.Bool"); + Resource strval(rm, "none", "string", "String"); + Resource enumval(rm, TEST1, "enumval", "EnumVal"); + + const char *defaultfile_open = "res", + *defaultfile_save = "res_save"; + + if (argc>1) { + if(!rm.load(argv[1])) + cerr<<"Faild to load database: "< +#include +#include + +#ifdef UDS +#include +#include +// configure UDS +uds::uds_flags_t uds::flags = uds::leak_check|uds::log_allocs; +#endif + +using namespace std; + +void testStringtok() { + vector ls; + StringUtil::stringtok(ls, " arg1 arg2 \targ3\n arg4 arg5\t\t\t\targ6\n\n \n\n \t\t\narg7"); + cerr<<"Size: "<::const_iterator i = ls.begin(); + i != ls.end(); ++i) { + cerr << ':' << (*i) << ":\n"; + } +} + +void testExpandFilename() { + auto_ptr filename(StringUtil::expandFilename("~/filename/~filename2/file3~/file4")); + cerr<<"test "; + string test = string(getenv("HOME"))+"/filename/~filename2/file3~/file4"; + if (strcmp(test.c_str(), filename.get())==0) + cerr<<"ok."; + else + cerr<<"faild"; + cerr< stringlist; + stringlist.push_back(" \t\t\t \t[(in \\)\t haha )] \t\t "); + stringlist.push_back("(in\\)) {_ _ my_ _}"); + stringlist.push_back("(in) {_ _ my_ _}"); + stringlist.push_back("(in){_ _ my_ _}"); + stringlist.push_back("\t \t \t ( in ) {haha}"); + stringlist.push_back("\t \t \t (( in \\) ) {haha}"); + stringlist.push_back("\t \t \t (( in \\) ){hihi}"); + stringlist.push_back("\t \t \t (( in \\) )|{hihi}"); + for (unsigned int i=0; i +#include +#include +#include + +using namespace std; + +bool loadMenu(string filename); +bool loadMenu2(string filename); + +void showError(int line, int pos, string& instr) { + + cerr<<"Error on line: "<1) + filename = argv[1]; + if (loadMenu2(filename)) + cout<<"Load successfull"< stringlist; + stringlist.push_back(" \t\t\t \t[(in \\)\t haha )] \t\t "); + stringlist.push_back("(in\\)) {_ _ my_ _}"); + stringlist.push_back("(in) {_ _ my_ _}"); + stringlist.push_back("(in){_ _ my_ _}"); + stringlist.push_back("\t \t \t ( in ) {haha}"); + stringlist.push_back("\t \t \t (( in \\) ) {haha}"); + stringlist.push_back("\t \t \t (( in \\) ){hihi}"); + stringlist.push_back("\t \t \t (( in \\) )|{hihi}"); + for (unsigned int i=0; i args; + int line=0; + while (!menufile.eof()) { + //read a line + getline(menufile, instr); + line++; + string arg; + int pos = StringUtil::getStringBetween(arg, instr.c_str(), '[', ']'); + if (pos<=0) { + showError(line, -pos, instr); + continue; + } + + cerr<<"("< +#include +#include + +#ifdef UDS +#include +// configure UDS +uds::uds_flags_t uds::flags = uds::leak_check|uds::log_allocs; +#endif + +using namespace std; + +void testKeys(int argc, char **argv) { + Display *display = XOpenDisplay(0); + + if (display==0) { + cerr<<"Cant open display."<1) { + cerr<<"Loading file: "<load(const_cast(argv[1])); + } else { + cerr<<"Using default file: "<load(const_cast(default_keyfile)); + } + + keys->load(const_cast(default_keyfile)); + + delete keys; + + XCloseDisplay(display); +} + +int main(int argc, char **argv) { + #ifdef UDS + uds::Init uds_init; + #endif + testKeys(argc, argv); +} -- cgit v0.11.2