From 190b469d567a5426d4449f93fbcd5ab906c5a5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Fri, 28 Mar 2014 11:50:39 +0000 Subject: [PATCH] fixed a lot of issues, now successfully runs the test with --enable-pedantic; refs #8 --- doc/doxyfile.in | 6 +- doc/doxygenlayout.xml | 184 ---------------------- doc/examples/arguments.cxx | 6 +- doc/examples/smartpointer.cxx | 1 + src/arg.cxx | 15 +- src/autostacktracelog4cxx.cxx | 24 +-- src/configfile.cxx | 17 +- src/exec.cxx | 62 +++++--- src/mrw/arg.hxx | 13 +- src/mrw/args.hxx | 23 +-- src/mrw/auto.hxx | 30 +++- src/mrw/checkcxx11.hxx | 6 + src/mrw/deque.hxx | 18 +++ src/mrw/exec.hxx | 5 +- src/mrw/functiontrace.hxx | 2 +- src/mrw/iomanip.hxx | 2 +- src/mrw/list.hxx | 8 +- src/mrw/multiset.hxx | 18 +++ src/mrw/set.hxx | 22 ++- src/mrw/smartpointer.hxx | 8 +- src/mrw/string.hxx | 16 ++ src/mrw/vector.hxx | 40 ++++- src/stacktrace.cxx | 50 +++--- test/auto_test.cxx | 14 +- test/configfile_test.cxx | 45 ++++-- test/dynamiclibrary_test.cxx | 2 +- test/exec_test.cxx | 68 ++++---- test/functiontrace_test.cxx | 8 +- test/makefile.am | 4 +- test/mrwautofunctiontracelog4cxx_test.cxx | 18 +-- test/smartpointer_test.cxx | 7 +- test/stdext_test.cxx | 62 ++++---- test/string_test.cxx | 3 +- 33 files changed, 398 insertions(+), 409 deletions(-) delete mode 100644 doc/doxygenlayout.xml diff --git a/doc/doxyfile.in b/doc/doxyfile.in index a20f176..c6cc6e1 100644 --- a/doc/doxyfile.in +++ b/doc/doxyfile.in @@ -588,7 +588,7 @@ FILE_VERSION_FILTER = # You can optionally specify a file name after the option, if omitted # DoxygenLayout.xml will be used as the name of the layout file. -LAYOUT_FILE = doxygenlayout.xml +LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files # containing the references data. This must be a list of .bib files. The @@ -723,7 +723,7 @@ EXCLUDE_SYMBOLS = # directories that contain example code fragments that are included (see # the \include command). -EXAMPLE_PATH = . +EXAMPLE_PATH = @top_srcdir@ # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp @@ -737,7 +737,7 @@ EXAMPLE_PATTERNS = # commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. -EXAMPLE_RECURSIVE = NO +EXAMPLE_RECURSIVE = YES # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see diff --git a/doc/doxygenlayout.xml b/doc/doxygenlayout.xml deleted file mode 100644 index 4e20439..0000000 --- a/doc/doxygenlayout.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/examples/arguments.cxx b/doc/examples/arguments.cxx index 8b2155f..b41a2ab 100644 --- a/doc/examples/arguments.cxx +++ b/doc/examples/arguments.cxx @@ -33,11 +33,7 @@ int main(int argc, char** argv) try { // bind and evaluate options #ifdef MRW__OLD_PRE11_COMPILER - mrw::args::list l; - mrw::args::decl::param_list pl = mrw::args::decl::param_list(); - (mrw::args::decl::param_list())<second->args().size()>=argc) + if (it!=_longopts.end() || i+(int)it->second->args().size()>=argc) throw mrw::invalid_argument(arg); it->second->set(); - for (int j(0), l(it->second->args().size()); jsecond->args().size()); jsecond->args().setable(j)) = argv[++i]; } } else if (arg.find("-")==0) { // short arguments // first check all, then set all - for (int j(1), l(arg.size()); jsecond->args().size()>0 && - (j+1!=l || i+it->second->args().size()>=argc)) + if (it==_shortopts.end() || + (it->second->args().size()>0 && + (j+1!=l || i+(int)it->second->args().size()>=argc))) throw mrw::invalid_argument(arg); } - for (int j(1), l(arg.size()); jsecond->set(); if (j+1==l && it->second->args().size()>0) { - for (int k(0); k < it->second->args().size(); ++k) { + for (int k(0); k < (int)it->second->args().size(); ++k) { *(it->second->args().setable(k)) = argv[++i]; } } diff --git a/src/autostacktracelog4cxx.cxx b/src/autostacktracelog4cxx.cxx index ba8b519..837837c 100644 --- a/src/autostacktracelog4cxx.cxx +++ b/src/autostacktracelog4cxx.cxx @@ -100,17 +100,17 @@ namespace mrw { try { throw; } catch (const mrw::exception& x) { - std::string txt(std::string("Reason:\n")+x.what() + std::string txt2(std::string("Reason:\n")+x.what() +"\nStack:\n"+x.stacktrace()); - logger->fatal(std::string(txt.begin(), txt.end())); + logger->fatal(std::string(txt2.begin(), txt2.end())); } catch (const std::exception& x) { - std::string txt(std::string("Reason:\n")+x.what() + std::string txt2(std::string("Reason:\n")+x.what() +"\nStack:\n"+st); - logger->fatal(std::string(txt.begin(), txt.end())); + logger->fatal(std::string(txt2.begin(), txt2.end())); } catch (...) { - std::string txt(std::string("Reason: **** not available ****") + std::string txt2(std::string("Reason: **** not available ****") +"\nStack:\n"+st); - logger->fatal(std::string(txt.begin(), txt.end())); + logger->fatal(std::string(txt2.begin(), txt2.end())); } throw std::bad_exception(); } @@ -156,17 +156,17 @@ namespace mrw { try { throw; } catch (const mrw::exception& x) { - std::string txt(std::string("Reason:\n")+x.what() + std::string txt2(std::string("Reason:\n")+x.what() +"\nStack:\n"+x.stacktrace()); - logger->fatal(std::string(txt.begin(), txt.end())); + logger->fatal(std::string(txt2.begin(), txt2.end())); } catch (const std::exception& x) { - std::string txt(std::string("Reason:\n")+x.what() + std::string txt2(std::string("Reason:\n")+x.what() +"\nStack:\n"+st); - logger->fatal(std::string(txt.begin(), txt.end())); + logger->fatal(std::string(txt2.begin(), txt2.end())); } catch (...) { - std::string txt(std::string("Reason: **** not available ****") + std::string txt2(std::string("Reason: **** not available ****") +"\nStack:\n"+st); - logger->fatal(std::string(txt.begin(), txt.end())); + logger->fatal(std::string(txt2.begin(), txt2.end())); } exit(1); } diff --git a/src/configfile.cxx b/src/configfile.cxx index 8351b9b..c3d4908 100644 --- a/src/configfile.cxx +++ b/src/configfile.cxx @@ -106,8 +106,8 @@ mrw::ConfigFileReader::parseValue(const std::string& file, endVal = file.find_last_not_of("\n\t ", // remove trailing white spaces endVal!=std::string::npos?endVal-1:endVal)+1; std::string::size_type realEnd(endVal!=std::string::npos && // quotes? - (file[realStart]=='"' && file[endVal]=='"' || - file[realStart]=='\'' && file[endVal]=='\'') + ((file[realStart]=='"' && file[endVal]=='"') || + (file[realStart]=='\'' && file[endVal]=='\'')) ? endVal+1 : endVal); if (endVal<=startVal) return std::make_pair // empty value @@ -152,18 +152,21 @@ mrw::ConfigFileWriter& mrw::ConfigFileWriter::save() throw(std::exception) { changed = true; // check if we need quoting std::string value(var->second.value); - if (value.find_first_of("[=#")!=std::string::npos) - if (value.find('"')==std::string::npos) + if (value.find_first_of("[=#")!=std::string::npos) { + if (value.find('"')==std::string::npos) { value = '"'+value+'"'; - else if (value.find('\'')==std::string::npos) + } else if (value.find('\'')==std::string::npos) { value = '\''+value+'\''; - else + } else { throw mrw::invalid_argument("Configuration value is not quotable: " +value); + } + } // recalculate all positions if (var->second.start && value.size() != var->second.end-var->second.start) { - int diff(value.size()-var->second.end+var->second.start); + std::string::size_type diff + (value.size()-var->second.end+var->second.start); for (Values::iterator sec2(_values.begin()); sec2!=_values.end(); ++sec2) for (Values::mapped_type::iterator var2(sec2->second.begin()); diff --git a/src/exec.cxx b/src/exec.cxx index fd17e3f..1a23582 100644 --- a/src/exec.cxx +++ b/src/exec.cxx @@ -208,25 +208,29 @@ mrw::Exec& mrw::Exec::execute(bool exc) throw(std::exception) { one. */ while (num1||num2||!res) try { // not end of files or child terminated if (!res && (res=waitpid(pid, &s, WNOHANG))) - if (res!=pid || WIFEXITED(s)!=0 && WEXITSTATUS(s)!=0) + if (res!=pid || (WIFEXITED(s)!=0 && WEXITSTATUS(s)!=0)) throw ExecutionFailedExc("execution failed", *_cmd); if (num1<=0&&num2<=0) usleep(10000); // nothing to read last time // check and handle stdout - if (num1 && (num1=read(stdOut.istream(), buf, sizeof(buf)))>0) + if (num1 && (num1=read(stdOut.istream(), buf, sizeof(buf)))>0) { _res += std::string(buf, num1); - else if (num1==-1) - if (errno!=EINTR&&errno!=EAGAIN) + } else if (num1==-1) { + if (errno!=EINTR&&errno!=EAGAIN) { throw ExecutionFailedExc("readin stdout", *_cmd); - else + } else { num1 = 1; + } + } // check and handle stderr - if (num2 && (num2=read(stdErr.istream(), buf, sizeof(buf)))>0) + if (num2 && (num2=read(stdErr.istream(), buf, sizeof(buf)))>0) { _err += std::string(buf, num2); - else if (num2==-1) - if (errno!=EINTR&&errno!=EAGAIN) + } else if (num2==-1) { + if (errno!=EINTR&&errno!=EAGAIN) { throw ExecutionFailedExc("readin stderr", *_cmd); - else + } else { num2 = 1; + } + } } catch (...) { _success = false; if (exc) throw; @@ -283,7 +287,7 @@ mrw::Exec& mrw::Exec::execute(const std::string& input, bool exc) one. */ while (num0||num1||num2||!res) try { // not end of files or child terminated if (!res && (res=waitpid(pid, &s, WNOHANG))) - if (res!=pid || WIFEXITED(s)!=0 && WEXITSTATUS(s)!=0) + if (res!=pid || (WIFEXITED(s)!=0 && WEXITSTATUS(s)!=0)) throw ExecutionFailedExc("execution failed", *_cmd); if (num0<=0&&num1<=0&&num2<=0) usleep(10000); // no activity last time // check and handle stdin @@ -292,27 +296,32 @@ mrw::Exec& mrw::Exec::execute(const std::string& input, bool exc) in = in.substr(num0); else if ((unsigned int)num0==in.size()) num0=0, stdIn.close_out(); - } else if (num0==-1) + } else if (num0==-1) { if (errno!=EINTR&&errno!=EAGAIN) throw ExecutionFailedExc("writing stdin", *_cmd); else num0 = 1; + } // check and handle stdout - if (num1 && (num1=read(stdOut.istream(), buf, sizeof(buf)))>0) + if (num1 && (num1=read(stdOut.istream(), buf, sizeof(buf)))>0) { _res += std::string(buf, num1); - else if (num1==-1) - if (errno!=EINTR&&errno!=EAGAIN) + } else if (num1==-1) { + if (errno!=EINTR&&errno!=EAGAIN) { throw ExecutionFailedExc("readin stdout", *_cmd); - else + } else { num1 = 1; + } + } // check and handle stderr - if (num2 && (num2=read(stdErr.istream(), buf, sizeof(buf)))>0) + if (num2 && (num2=read(stdErr.istream(), buf, sizeof(buf)))>0) { _err += std::string(buf, num2); - else if (num2==-1) - if (errno!=EINTR&&errno!=EAGAIN) + } else if (num2==-1) { + if (errno!=EINTR&&errno!=EAGAIN) { throw ExecutionFailedExc("readin stderr", *_cmd); - else + } else { num2 = 1; + } + } } catch (...) { _success = false; if (exc) throw; @@ -498,7 +507,7 @@ std::pair char buf[4096]; int s(0); if (!_lastPid && (_lastPid=waitpid(_pid, &s, WNOHANG))) { - if (_lastPid!=_pid || WIFEXITED(s)!=0 && WEXITSTATUS(s)!=0) + if (_lastPid!=_pid || (WIFEXITED(s)!=0 && WEXITSTATUS(s)!=0)) throw ExecutionFailedExc("execution failed", *_cmd); } // check and handle stdin @@ -508,27 +517,30 @@ std::pair _input = _input.substr(_num0); else if ((unsigned int)_num0==_input.size()) _input.clear(); - } else if (_num0==-1) + } else if (_num0==-1) { if (errno!=EINTR&&errno!=EAGAIN) throw ExecutionFailedExc("writing stdin", *_cmd); else _num0 = 1; + } // check and handle stdout - if (_num1 && (_num1=::read(_stdOut->istream(), buf, sizeof(buf)))>0) + if (_num1 && (_num1=::read(_stdOut->istream(), buf, sizeof(buf)))>0) { _res += output.first=std::string(buf, _num1); - else if (_num1==-1) + } else if (_num1==-1) { if (errno!=EINTR&&errno!=EAGAIN) throw ExecutionFailedExc("readin stdout", *_cmd); else _num1 = 1; + } // check and handle stderr - if (_num2 && (_num2=::read(_stdErr->istream(), buf, sizeof(buf)))>0) + if (_num2 && (_num2=::read(_stdErr->istream(), buf, sizeof(buf)))>0) { _err += output.second=std::string(buf, _num2); - else if (_num2==-1) + } else if (_num2==-1) { if (errno!=EINTR&&errno!=EAGAIN) throw ExecutionFailedExc("readin stderr", *_cmd); else _num2 = 1; + } if (_finish && !_input.size()) { _stdIn->close_out(); _num0 = 0; diff --git a/src/mrw/arg.hxx b/src/mrw/arg.hxx index 3f41f92..73205fe 100644 --- a/src/mrw/arg.hxx +++ b/src/mrw/arg.hxx @@ -332,7 +332,7 @@ namespace mrw { public: /// @brief returns the number of (mandatory) parameter - int size() const throw(std::bad_exception) { + Params::size_type size() const throw(std::bad_exception) { return _params.size(); } @@ -774,13 +774,14 @@ namespace mrw { <<"OPTIONS:"<_shortname<<" | "<_longname; - for (int i(0); i_param.size(); ++i) - std::cout<<" <"<<(*it)[i]->typestr()<<">"; + for (Param::Params::size_type i(0); i_param.size(); ++i) + std::cout<<" <"<<(*it)[(unsigned int)i]->typestr()<<">"; if (it->_param.size()>0) std::cout<<" (default: "; - for (int i(0); i_param.size()-1; ++i) - std::cout<<(*it)[i]->printable()<<" "; + for (Param::Params::size_type i(0); i_param.size()-1; ++i) + std::cout<<(*it)[(unsigned int)i]->printable()<<" "; if (it->_param.size()>0) - std::cout<<(*it)[it->_param.size()-1]->printable()<<")"; + std::cout<<(*it)[(unsigned int)(it->_param.size()-1)]->printable() + <<")"; std::cout<help()<0) diff --git a/src/mrw/args.hxx b/src/mrw/args.hxx index e701dc6..b3294f0 100644 --- a/src/mrw/args.hxx +++ b/src/mrw/args.hxx @@ -23,7 +23,7 @@ /** @page oldcompiler Workaround for old non C++11 compilers ... to be documented @note Old compilers are automatically detected and the flag - @refs MRW__OLD_PRE11_COMPILER is set. + @ref MRW__OLD_PRE11_COMPILER is set. */ // Add version information for @c what and @c ident @@ -240,12 +240,12 @@ namespace mrw { } /// Initialize all parameters according to the commandline options. /** Sets up the parser from the @ref list of parameters - @param argc the argument count as given in C++ @c main function - @param argv the array of arguments as given in C++ @c main function - @param descr a string describing what the program does, - used in @ref show_help - @param l list of options and parameters to be parsed - @raram ret documentation of the return values of the program */ + @param argc the argument count as given in C++ @c main function + @param argv the array of arguments as given in C++ @c main function + @param desc a string describing what the program does, + used in @ref show_help + @param l list of options and parameters to be parsed + @param ret documentation of the return values of the program */ static void parse(int argc, char** argv, const std::string& desc, list l, const std::string& ret = std::string()) { filename(argv[0]); // store filename for later use in help @@ -286,8 +286,9 @@ namespace mrw { const std::string& description_txt="DESCRIPTION", const std::string& options_txt="OPTIONS", const std::string& returns_txt="RETURNS", - int max_line=80, int indent=2, int long_indent=4, - int option_len=16, int param_len=21) { + unsigned int max_line=80, unsigned int indent=2, + unsigned int long_indent=4, + unsigned int option_len=16, unsigned int param_len=21) { std::cout<desc.size()>max_line-indent-option_len-param_len) std::cout<desc; else - std::cout<desc; + std::cout<desc; std::cout< is the same as std::auto_ptr, but can be stored in STL containers @code @@ -55,7 +55,7 @@ namespace mrw { - mrw::AutoMapper calls @c munmap on memory mapped files - mrw::AutoBfd automatically calls @c bfd_close - If this is not enough, you can @c typedef your own ressource + If this is not enough, you can @c typedef your own resource handler from the template class mrw::AutoResource<>. For example, mrw::AutoFile is defined as: @code @@ -101,6 +101,8 @@ namespace mrw { typename FREE_TYPE = RESOURCE_TYPE> class AutoResource { public: + /// @brief type of the resource + typedef RESOURCE_TYPE Type; /// @brief Construct from an allocated resource. /// The resource is freed if necessary. /// AutoResource takes over ownership of the resource. @@ -218,7 +220,11 @@ namespace mrw { return reset(other.release()); } /// @brief Get the resource. - operator T* const() const throw(std::bad_exception) { + operator const T*() const throw(std::bad_exception) { + return _res; + } + /// @brief Get the resource. + operator T*() throw(std::bad_exception) { return _res; } /// @brief find out, if a value is set @@ -227,7 +233,11 @@ namespace mrw { return _res!=0; } /// @brief Access the AutoPtr like a normal pointer. - T*const operator->() {return _res;} + const T* operator->() const {return _res;} + /// @brief Access the AutoPtr like a normal pointer. + T* operator->() {return _res;} + /// @brief Dereference the AutoPtr like a normal pointer. + const T& operator*() const {return *_res;} /// @brief Dereference the AutoPtr like a normal pointer. T& operator*() {return *_res;} /// @brief get the resetted resource for resetting it. @@ -308,7 +318,11 @@ namespace mrw { return reset(other.release()); } /// @brief Get the resource. - operator T* const() const throw(std::bad_exception) { + operator const T*() const throw(std::bad_exception) { + return _res; + } + /// @brief Get the resource. + operator T*() throw(std::bad_exception) { return _res; } /// @brief find out, if a value is set @@ -317,7 +331,11 @@ namespace mrw { return _res!=0; } /// @brief Access the AutoPtrAry like a normal pointer. - T*const operator->() {return _res;} + const T* operator->() const {return _res;} + /// @brief Access the AutoPtrAry like a normal pointer. + T* operator->() {return _res;} + /// @brief Dereference the AutoPtrAry like a normal pointer. + const T& operator*() const {return *_res;} /// @brief Dereference the AutoPtrAry like a normal pointer. T& operator*() {return *_res;} /// @brief get the resetted resource for resetting it. diff --git a/src/mrw/checkcxx11.hxx b/src/mrw/checkcxx11.hxx index 7c04581..9306bab 100644 --- a/src/mrw/checkcxx11.hxx +++ b/src/mrw/checkcxx11.hxx @@ -47,6 +47,12 @@ namespace std { explicit shared_ptr(): boost::shared_ptr() {} explicit shared_ptr(T* p): boost::shared_ptr(p) {} }; + // auto_ptr is deprecated in favour of unique_ptr, simulate unique_ptr + template class unique_ptr: public std::auto_ptr { + public: + explicit unique_ptr(): auto_ptr() {} + explicit unique_ptr(T* p): auto_ptr(p) {} + }; }; # endif # endif diff --git a/src/mrw/deque.hxx b/src/mrw/deque.hxx index 38f8158..f349324 100644 --- a/src/mrw/deque.hxx +++ b/src/mrw/deque.hxx @@ -76,6 +76,24 @@ template return copy; } +/* @brief push a char* to a dequeue of string + + @code + std::dequeue test; + test<<"Hello"<<"World"; + @endcode + + @param l a dequeue of string values (that can be constructed from char*) + @param o a value to be inserted into dequeue @c l + @pre \#include */ +template + std::deque& operator<<(std::deque& l, + const char *const o) + throw(std::bad_exception) { + l.push_back(T(o)); + return l; +} + /** @brief extract the first value of a deque @code diff --git a/src/mrw/exec.hxx b/src/mrw/exec.hxx index eb07766..9030f1b 100644 --- a/src/mrw/exec.hxx +++ b/src/mrw/exec.hxx @@ -434,9 +434,10 @@ while (!exec.finished()) res+=exec.read().first; bool _finished; bool _finish; - std::auto_ptr _stdIn, _stdOut, _stdErr; + std::shared_ptr _stdIn, _stdOut, _stdErr; std::string _input; - int _num0, _num1, _num2, _lastPid, _pid; + ssize_t _num0, _num1, _num2; + int _lastPid, _pid; }; //============================================================================ diff --git a/src/mrw/functiontrace.hxx b/src/mrw/functiontrace.hxx index d1dfe5b..4817a38 100644 --- a/src/mrw/functiontrace.hxx +++ b/src/mrw/functiontrace.hxx @@ -42,7 +42,7 @@ #else # define LOG4CXX_CVS # define MRW_LOG4CXX_LOCATION \ - ::log4cxx::spi::LocationInfo(_file.c_str(), _name.c_str(), _line) + ::log4cxx::spi::LocationInfo(_file.c_str(), _name.c_str(), (int)_line) #define MRW_LEVEL_DEBUG ::log4cxx::Level::getDebug() #define MRW_LEVEL_INFO ::log4cxx::Level::getInfo() #define MRW_LEVEL_WARN ::log4cxx::Level::getWarn() diff --git a/src/mrw/iomanip.hxx b/src/mrw/iomanip.hxx index aaf92cd..18196d6 100644 --- a/src/mrw/iomanip.hxx +++ b/src/mrw/iomanip.hxx @@ -65,7 +65,7 @@ namespace mrw { } return const_cast(s); } - template basic_split& operator<<(T t) { + template basic_split& operator<<(const T& t) { if (!_os) throw std::runtime_error("wrong use of split, it is an io" " manipulator and must be used within" diff --git a/src/mrw/list.hxx b/src/mrw/list.hxx index e738438..4e560a6 100644 --- a/src/mrw/list.hxx +++ b/src/mrw/list.hxx @@ -65,7 +65,7 @@ @param l a list of values @param o a value to be inserted into list @c l - @pre #include + @pre \#include */ template std::list& operator<<(std::list& l, const T& o) @@ -84,7 +84,7 @@ template @param l a list of values @param o a value to be inserted into list @c l - @pre #include + @pre \#include */ template std::list operator<<(const std::list& l, const T& o) @@ -105,8 +105,8 @@ template @param o a value to be inserted into list @c l @pre \#include */ template - std::list operator<<(std::list l, - const char *const o) + std::list& operator<<(std::list& l, + const char *const o) throw(std::bad_exception) { l.push_back(T(o)); return l; diff --git a/src/mrw/multiset.hxx b/src/mrw/multiset.hxx index 53269ab..bcec36c 100644 --- a/src/mrw/multiset.hxx +++ b/src/mrw/multiset.hxx @@ -78,6 +78,24 @@ template return copy; } +/* @brief push a char* to a multiset of string + + @code + std::multiset test; + test<<"Hello"<<"World"; + @endcode + + @param l a multiset of string values (that can be constructed from char*) + @param o a value to be inserted into multiset @c l + @pre \#include */ +template + std::multiset& operator<<(std::multiset& l, + const char *const o) + throw(std::bad_exception) { + l.push_back(T(o)); + return l; +} + /** @brief extract the first value of a multiset @code diff --git a/src/mrw/set.hxx b/src/mrw/set.hxx index c5296cb..1ed31c9 100644 --- a/src/mrw/set.hxx +++ b/src/mrw/set.hxx @@ -48,7 +48,7 @@ @throw mrw::invalid_argument, if element is already in set @param l a set of values @param o a value to be inserted into set @c l - @pre #include + @pre \#include */ template std::set& operator<<(std::set& l, const T& o) @@ -71,7 +71,7 @@ template @throw mrw::invalid_argument, if element is already in set @param l a set of values @param o a value to be inserted into set @c l - @pre #include + @pre \#include */ template std::set operator<<(const std::set& l, const T& o) @@ -84,6 +84,24 @@ template return copy; } +/* @brief push a char* to a set of string + + @code + std::set test; + test<<"Hello"<<"World"; + @endcode + + @param l a set of string values (that can be constructed from char*) + @param o a value to be inserted into set @c l + @pre \#include */ +template + std::set& operator<<(std::set& l, + const char *const o) + throw(std::bad_exception) { + l.push_back(T(o)); + return l; +} + /** @brief extract the first value of a set @code diff --git a/src/mrw/smartpointer.hxx b/src/mrw/smartpointer.hxx index 365d5c8..c77d95b 100644 --- a/src/mrw/smartpointer.hxx +++ b/src/mrw/smartpointer.hxx @@ -34,6 +34,8 @@ namespace mrw { }; class SmartPointerParent { + public: + virtual ~SmartPointerParent() {} protected: template PointerCounter* getCounter(TYPE& sp) throw() { @@ -102,7 +104,7 @@ namespace mrw { _cnt(0), _ptr(dynamic_cast(getPointer(o))) { if (_ptr) _cnt = getCounter(o)->incr(); } - ~SmartPointer() throw() { + virtual ~SmartPointer() throw() { drop(); } SmartPointer& operator=(const SmartPointer& o) throw() { @@ -133,10 +135,10 @@ namespace mrw { const TYPE& operator*() const throw() { return *_ptr; } - TYPE* const operator->() throw() { + TYPE* operator->() throw() { return _ptr; } - const TYPE* const operator->() const throw() { + const TYPE* operator->() const throw() { return _ptr; } operator bool() throw() { diff --git a/src/mrw/string.hxx b/src/mrw/string.hxx index e365ead..963d0e0 100644 --- a/src/mrw/string.hxx +++ b/src/mrw/string.hxx @@ -304,6 +304,22 @@ template std::string& operator<<(std::string& s, const T& o) return s+=mrw::string(o); } +/** @brief append any value to a string + + @code + std::string()<<"length is: "< + @pre T must support operator<< to a stream +*/ +template std::string operator<<(const std::string& s, const T& o) + throw(std::bad_exception) { + return s+=mrw::string(o); +} + /** @brief extract any value from a string @code diff --git a/src/mrw/vector.hxx b/src/mrw/vector.hxx index b2a8048..a3f8455 100644 --- a/src/mrw/vector.hxx +++ b/src/mrw/vector.hxx @@ -50,12 +50,50 @@ @pre \#include */ template - std::vector operator<<(std::vector l, const T& o) + std::vector& operator<<(std::vector& l, const T& o) throw(std::bad_exception) { l.push_back(o); return l; } +/** @brief push a value to a constant vector + + Makes a copy and returns the copy. + + @code + std::vector()<<1<<2<<3<<4<<5<<6<<7<<8; + @endcode + + @param l a vector of values + @param o a value to be inserted into vector @c l + @pre \#include +*/ +template + std::vector operator<<(const std::vector& l, const T& o) + throw(std::bad_exception) { + std::vector copy(l); + copy.push_back(o); + return ; +} + +/* @brief push a char* to a vector of string + + @code + std::vector test; + test<<"Hello"<<"World"; + @endcode + + @param l a vector of string values (that can be constructed from char*) + @param o a value to be inserted into vector @c l + @pre \#include */ +template + std::vector& operator<<(std::vector& l, + const char *const o) + throw(std::bad_exception) { + l.push_back(T(o)); + return l; +} + /** @brief extract the first value of a vector @code diff --git a/src/stacktrace.cxx b/src/stacktrace.cxx index cfbbf8f..4922504 100644 --- a/src/stacktrace.cxx +++ b/src/stacktrace.cxx @@ -79,7 +79,7 @@ namespace mrw { if (res) { /* Now put back any stripped dots. */ if (p==name) return static_cast(res); - std::string add_dots('.', p-name); + std::string add_dots(p-name, '.'); return add_dots+=static_cast(res); } return name; @@ -97,22 +97,27 @@ mrw::StackTrace::StackTrace() throw(std::bad_exception) { _trace.push_back(ba[i]); } // crash ...? -// # elif defined(__GNUG__) -// { -// # define PUSH(i) \ -// (__builtin_frame_address(i)!=0 ? \ -// (_trace.push_back(__builtin_return_address(i)), true) : false) -// PUSH(0) && PUSH(1) && PUSH(2) && PUSH(3) && PUSH(4) && PUSH(5) && -// PUSH(6) && PUSH(7) && PUSH(8) && PUSH(9) && PUSH(10) && PUSH(11) && -// PUSH(12) && PUSH(13) && PUSH(14) && PUSH(15) && PUSH(16) && PUSH(17) -// && PUSH(18) && PUSH(19) && PUSH(20) && PUSH(21) && PUSH(22) && -// PUSH(23) && PUSH(24) && PUSH(25) && PUSH(26) && PUSH(27) && PUSH(28) -// && PUSH(29) && PUSH(30) && PUSH(31) && PUSH(32) && PUSH(33) && -// PUSH(34) && PUSH(35) && PUSH(36) && PUSH(37) && PUSH(38) && PUSH(39) -// && PUSH(40) && PUSH(41) && PUSH(42) && PUSH(43) && PUSH(44) && -// PUSH(45) && PUSH(46) && PUSH(47) && PUSH(48) && PUSH(49); -// # undef PUSH -// } +# elif defined(__GNUG__) + { +# define __MRW_PUSH(i) \ + (__builtin_frame_address(i)!=0 && __builtin_return_address(i)!=0? \ + (_trace.push_back(__builtin_return_address(i)), true) : false) + + __MRW_PUSH(0) && __MRW_PUSH(1) && __MRW_PUSH(2) && __MRW_PUSH(3) + && __MRW_PUSH(4) && __MRW_PUSH(5) && __MRW_PUSH(6) && __MRW_PUSH(7) + && __MRW_PUSH(8) && __MRW_PUSH(9) && __MRW_PUSH(10) && __MRW_PUSH(11) + && __MRW_PUSH(12) && __MRW_PUSH(13) && __MRW_PUSH(14) && __MRW_PUSH(15) + && __MRW_PUSH(16) && __MRW_PUSH(17) && __MRW_PUSH(18) && __MRW_PUSH(19) + && __MRW_PUSH(20) && __MRW_PUSH(21) && __MRW_PUSH(22) && __MRW_PUSH(23) + && __MRW_PUSH(24) && __MRW_PUSH(25) && __MRW_PUSH(26) && __MRW_PUSH(27) + && __MRW_PUSH(28) && __MRW_PUSH(29) && __MRW_PUSH(30) && __MRW_PUSH(31) + && __MRW_PUSH(32) && __MRW_PUSH(33) && __MRW_PUSH(34) && __MRW_PUSH(35) + && __MRW_PUSH(36) && __MRW_PUSH(37) && __MRW_PUSH(38) && __MRW_PUSH(39) + && __MRW_PUSH(40) && __MRW_PUSH(41) && __MRW_PUSH(42) && __MRW_PUSH(43) + && __MRW_PUSH(44) && __MRW_PUSH(45) && __MRW_PUSH(46) && __MRW_PUSH(47) + && __MRW_PUSH(48) && __MRW_PUSH(49); +# undef __MRW_PUSH + } # else # warning "You need GNU gcc or GNU glibc to be able to use mrw::StackTrace" # endif @@ -161,11 +166,10 @@ mrw::StackTrace::~StackTrace() throw() { //---------------------------------------------------------------------------- mrw::StackTrace::operator std::string() const throw(std::bad_exception) { std::stringstream s; - bool first(true); - unsigned int fusz(0), adsz(0); //lisz(0), fisz(0) + std::string::size_type fusz(0), adsz(0); //lisz(0), fisz(0) std::list l; for (AddressTrace::const_reverse_iterator it(_trace.rbegin()); - it!=_trace.rend(); ++it, first=false) { + it!=_trace.rend(); ++it) { CodePos c(translate(*it)); if (((std::stringstream&)(std::stringstream()< adsz) @@ -175,8 +179,8 @@ mrw::StackTrace::operator std::string() const throw(std::bad_exception) { l.push_back(c); } for (std::list::iterator it(l.begin()); it!=l.end(); ++it) - s<<'['<address<<"] " - <function<function.size()+1)<<' ' + s<<'['<address<<"] " + <function<function.size()+1))<<' ' <file<<':'<line<0) + if (lib.size() && lib[0]!='[' && lib[lib.size()-1]!=']' && addr!=0) res<0); // file is now open @@ -61,24 +61,24 @@ public: CPPUNIT_ASSERT(i==b && cc==-1); // it's ok now b = open("test.dat", O_RDONLY); //close(i); - CPPUNIT_ASSERT(read(i, &c, 1)==-1); // old file is closed + CPPUNIT_ASSERT_EQUAL((ssize_t)-1, read(i, &c, 1)); // old file is closed i = b.reset(); - CPPUNIT_ASSERT(read(i, &c, 1)==-1); // new file is closed + CPPUNIT_ASSERT_EQUAL((ssize_t)-1, read(i, &c, 1)); // new file is closed i = a = open("test.dat", O_RDONLY); } - CPPUNIT_ASSERT(read(i, &c, 1)==-1); // file is closed now + CPPUNIT_ASSERT_EQUAL((ssize_t)-1, read(i, &c, 1)); // file is closed now } void AutoFree() { const char C[] = "Hello World"; mrw::Auto::Free c(malloc(sizeof(C))); CPPUNIT_ASSERT(c); strncpy(c, C, sizeof(C)); - CPPUNIT_ASSERT(std::string(c)==C); + CPPUNIT_ASSERT_EQUAL(std::string(C), std::string(c)); mrw::Auto::Free c2(c.release()); CPPUNIT_ASSERT(c==0 && c2!=0); - CPPUNIT_ASSERT(std::string(c2)==C); + CPPUNIT_ASSERT_EQUAL(std::string(C), std::string(c2)); c2.reset(); - CPPUNIT_ASSERT(c2==0); + CPPUNIT_ASSERT_EQUAL((char*)0, (char*)c2); } CPPUNIT_TEST_SUITE(AutoTest); CPPUNIT_TEST(AutoFile); diff --git a/test/configfile_test.cxx b/test/configfile_test.cxx index 8a7f5bb..b00b843 100644 --- a/test/configfile_test.cxx +++ b/test/configfile_test.cxx @@ -35,31 +35,42 @@ public: std::string srcdir(mrw::ifelse(getenv("srcdir"), ".")); mrw::File::copy(srcdir+"/configfile.ini", "configfile2.ini"); mrw::ConfigFileWriter config("configfile2.ini"); - CPPUNIT_ASSERT(config("", "xxx", ".")=="yyy"); - CPPUNIT_ASSERT(config("Section", "abc", ".")==""); - CPPUNIT_ASSERT(config("Section", "def", ".")=="hallo welt"); - CPPUNIT_ASSERT(config("Section", "ghi", ".")==""); - CPPUNIT_ASSERT(config("Section", "jkl", ".")=="mn\n op qr\n st"); - CPPUNIT_ASSERT(config("Other Section", "1234", ".")=="5678=90"); - CPPUNIT_ASSERT(config("Other Section", "here we are", ".") - =="some contents"); - CPPUNIT_ASSERT(config("Other Section", "here", ".")==""); + CPPUNIT_ASSERT_EQUAL(std::string("yyy"), config("", "xxx", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string(), config("Section", "abc", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("hallo welt"), + config("Section", "def", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string(), config("Section", "ghi", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("mn\n op qr\n st"), + config("Section", "jkl", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("5678=90"), + config("Other Section", "1234", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("some contents"), + config("Other Section", "here we are", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string(), config("Other Section", "here", ".")()); config("", "xxx", ".")="0"; config("Section", "abc", ".")="1"; - CPPUNIT_ASSERT(config("New Section", "a first one", "sgadd")=="sgadd"); + CPPUNIT_ASSERT_EQUAL(std::string("sgadd"), + config("New Section", "a first one", "sgadd")()); config("Section", "def", ".")="Und=Tschuess"; config("Section", "ghi", ".")="3"; config("Section", "jkl", ".")="4"; config("Other Section", "1234", ".")="5"; config("Other Section", "here we are", ".")="6"; config("Other Section", "here", ".")="7"; - CPPUNIT_ASSERT(config("Other Section", "no no", ".")=="."); - CPPUNIT_ASSERT(config("Other Section", "no no no", ".")=="."); - CPPUNIT_ASSERT(config("Other Section", "yes", ".")=="."); - CPPUNIT_ASSERT(config("Section", "guguseli", "dadaa")=="dadaa"); - CPPUNIT_ASSERT(config("Section", "guguseli zwei", "dadaa")=="dadaa"); - CPPUNIT_ASSERT(config("Section", "guguseli drei", "dadaa")=="dadaa"); - CPPUNIT_ASSERT(config("New Section", "one more", ".")=="."); + CPPUNIT_ASSERT_EQUAL(std::string("."), + config("Other Section", "no no", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("."), + config("Other Section", "no no no", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("."), + config("Other Section", "yes", ".")()); + CPPUNIT_ASSERT_EQUAL(std::string("dadaa"), + config("Section", "guguseli", "dadaa")()); + CPPUNIT_ASSERT_EQUAL(std::string("dadaa"), + config("Section", "guguseli zwei", "dadaa")()); + CPPUNIT_ASSERT_EQUAL(std::string("dadaa"), + config("Section", "guguseli drei", "dadaa")()); + CPPUNIT_ASSERT_EQUAL(std::string("."), + config("New Section", "one more", ".")()); } CPPUNIT_TEST_SUITE(ConfigFileTest); CPPUNIT_TEST(CheckFile); diff --git a/test/dynamiclibrary_test.cxx b/test/dynamiclibrary_test.cxx index dabaa6a..bad0cb5 100644 --- a/test/dynamiclibrary_test.cxx +++ b/test/dynamiclibrary_test.cxx @@ -30,7 +30,7 @@ class DynamicLibraryTest: public CppUnit::TestFixture { void Load() { mrw::DynamicLibrary lib("libdynamiclibrary_testlib"); int(*test1)(int) = (int(*)(int))lib.symbol("test1"); - CPPUNIT_ASSERT((*test1)(2)==4); + CPPUNIT_ASSERT_EQUAL(4, (*test1)(2)); } void LoadError() { mrw::DynamicLibrary lib("DASist-Sicher_Keine_DynamischePHIPLIOTEEK!!!"); diff --git a/test/exec_test.cxx b/test/exec_test.cxx index 765ae82..b3e43c1 100644 --- a/test/exec_test.cxx +++ b/test/exec_test.cxx @@ -50,40 +50,26 @@ #include #include -#include -#ifdef __GNUG__ -#define LOG std::clog<<__PRETTY_FUNCTION__<<'@'<<__FILE__<<':'<<__LINE__; -#else -#define LOG std::clog<<__FUNCTION__<<'@'<<__FILE__<<':'<<__LINE__; -#endif - class ExecTest: public CppUnit::TestFixture { public: void lsTest() { - LOG; std::string res = (mrw::Cmd("/bin/ls"), "-l", std::string(getenv("srcdir"))+"/..").execute(); CPPUNIT_ASSERT(res.find("COPYING") Logs; Logs logs; for (std::string::size_type pos(0), last(0); @@ -220,15 +220,15 @@ namespace mrw { "Expectation:\n--------------------\n" +it->second+"--------------------", match(it->second)); - mrw::File::remove("mrwautofunctiontracelog4cxx_test-mt.log"); + mrw::File::remove("mrwautofunctiontracelog4cxx_test-mt.trace"); #else CPPUNIT_ASSERT_MESSAGE ("The following text does not match the " "Expectation:\n--------------------\n" - +mrw::File::read("mrwautofunctiontracelog4cxx_test.log") + +mrw::File::read("mrwautofunctiontracelog4cxx_test.trace") +"--------------------", - match(mrw::File::read("mrwautofunctiontracelog4cxx_test.log"))); - mrw::File::remove("mrwautofunctiontracelog4cxx_test.log"); + match(mrw::File::read("mrwautofunctiontracelog4cxx_test.trace"))); + mrw::File::remove("mrwautofunctiontracelog4cxx_test.trace"); #endif } CPPUNIT_TEST_SUITE(AutoFunctionTraceLog4CxxTest); diff --git a/test/smartpointer_test.cxx b/test/smartpointer_test.cxx index 83a0214..aa8a91b 100644 --- a/test/smartpointer_test.cxx +++ b/test/smartpointer_test.cxx @@ -40,7 +40,12 @@ public: Content(int& drop): _drop(drop) {} virtual ~Content() {++_drop;} }; -class A: public Content {public: A(int& d): Content(d) {} virtual void fn() {}}; +class A: public Content { + public: + A(int& d): Content(d) {} + virtual ~A() {} + virtual void fn() {} +}; class B: public A {public: B(int& d): A(d) {}}; class C: public A {public: C(int& d): A(d) {}}; class SmartPointerTest: diff --git a/test/stdext_test.cxx b/test/stdext_test.cxx index 77490c2..aae8571 100644 --- a/test/stdext_test.cxx +++ b/test/stdext_test.cxx @@ -40,30 +40,32 @@ class StdExtTest: public CppUnit::TestFixture { public: void StringConv() { std::string s("Integer="); - int i(4); - CPPUNIT_ASSERT(s+mrw::string(i) == "Integer=4"); + int i(-7382); + CPPUNIT_ASSERT_EQUAL(std::string("Integer=-7382"), s+mrw::string(i)); + CPPUNIT_ASSERT_EQUAL(i, mrw::to(mrw::string(i))); } void StringShift() { std::string s("Integer="); int i(4); - CPPUNIT_ASSERT((s<>s2>>s3>>i2; - CPPUNIT_ASSERT(s2=="Integer=4"); - CPPUNIT_ASSERT(s3=="test"); - CPPUNIT_ASSERT(i2==45); - CPPUNIT_ASSERT(s==" xx"); + CPPUNIT_ASSERT_NO_THROW(s>>s2>>s3>>i2); + CPPUNIT_ASSERT_EQUAL(std::string("Integer=4"), s2); + CPPUNIT_ASSERT_EQUAL(std::string("test"), s3); + CPPUNIT_ASSERT_EQUAL(45, i2); + CPPUNIT_ASSERT_EQUAL(std::string(" xx"), s); s2=""; s3=""; s>>s2; - CPPUNIT_ASSERT(s2=="xx"); - CPPUNIT_ASSERT(s==""); + CPPUNIT_ASSERT_EQUAL(std::string("xx"), s2); + CPPUNIT_ASSERT_EQUAL(std::string(), s); } void StringAdd() { std::string s; s=s+(signed short)1+(signed int)2+(signed long)3+(signed char)'A'+ (unsigned short)1+(unsigned int)2+(unsigned long)3+(unsigned char)'A'+'c'; - CPPUNIT_ASSERT(s=="1236512365c"); + CPPUNIT_ASSERT_EQUAL(std::string("1236512365c"), s); s=(signed short)-4+s; s=(signed int)5+s; s=(signed long)6+s; @@ -73,7 +75,7 @@ public: s=(unsigned long)6+s; s=(unsigned char)8+s; s='a'+s; - CPPUNIT_ASSERT(s=="a8654865-41236512365c"); + CPPUNIT_ASSERT_EQUAL(std::string("a8654865-41236512365c"), s); s+=(signed short)-4; s+=(signed int)5 ; s+=(signed long)6; @@ -83,7 +85,7 @@ public: s+=(unsigned long)6; s+=(unsigned char)8 ; s+='a'; - CPPUNIT_ASSERT(s=="a8654865-41236512365c-45684568a"); + CPPUNIT_ASSERT_EQUAL(std::string("a8654865-41236512365c-45684568a"), s); } void ListShift() { std::list l; @@ -92,9 +94,9 @@ public: l>>i1>>i2>>i3>>i4; // now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8} CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4); - CPPUNIT_ASSERT(l.size()==4); + CPPUNIT_ASSERT_EQUAL(std::list::size_type(4), l.size()); for (int i=0; i<4; (l.pop_front(), ++i)) { - CPPUNIT_ASSERT(l.front()==i+5); + CPPUNIT_ASSERT_EQUAL(i+5, l.front()); } bool exc(false); try { @@ -106,9 +108,11 @@ public: } void VectorShift() { std::vector l; - l<<1<<2<<3<<4<<5<<6<<7<<8; + CPPUNIT_ASSERT_NO_THROW(l<<1<<2<<3<<4<<5<<6<<7<<8); + CPPUNIT_ASSERT_EQUAL(std::vector::size_type(8), l.size()); int i1(0), i2(0), i3(0), i4(0); - l>>i1>>i2>>i3>>i4; + CPPUNIT_ASSERT_NO_THROW(l>>i1>>i2>>i3>>i4); + CPPUNIT_ASSERT_EQUAL(std::vector::size_type(4), l.size()); // now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8} CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4); CPPUNIT_ASSERT(l.size()==4); @@ -125,14 +129,14 @@ public: } void DequeShift() { std::deque l; - l<<1<<2<<3<<4<<5<<6<<7<<8; + CPPUNIT_ASSERT_NO_THROW(l<<1<<2<<3<<4<<5<<6<<7<<8); int i1(0), i2(0), i3(0), i4(0); - l>>i1>>i2>>i3>>i4; + CPPUNIT_ASSERT_NO_THROW(l>>i1>>i2>>i3>>i4); // now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8} CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4); - CPPUNIT_ASSERT(l.size()==4); + CPPUNIT_ASSERT_EQUAL(std::deque::size_type(4), l.size()); for (int i=0; i<4; (l.erase(l.begin()), ++i)) { - CPPUNIT_ASSERT(l.front()==i+5); + CPPUNIT_ASSERT_EQUAL(i+5, l.front()); } bool exc(false); try { @@ -156,7 +160,7 @@ public: s>>i1>>i2>>i3>>i4; // now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8} CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4); - CPPUNIT_ASSERT(s.size()==4); + CPPUNIT_ASSERT_EQUAL(std::set::size_type(4), s.size()); for (int i=0; i<4; ++i) { CPPUNIT_ASSERT(s.find(i+5)!=s.end()); } @@ -170,7 +174,8 @@ public: CPPUNIT_ASSERT(exc); } void MapShift() { - std::map s; + typedef std::map Map; + Map s; bool exc(false); try { s<>i1; @@ -201,7 +206,7 @@ public: s>>i1>>i2>>i3>>i4; // now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8} CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4); - CPPUNIT_ASSERT(s.size()==5); + CPPUNIT_ASSERT_EQUAL(std::multiset::size_type(5), s.size()); for (int i=0; i<5; ++i) { CPPUNIT_ASSERT(s.find(i+5)!=s.end()); } @@ -215,7 +220,8 @@ public: CPPUNIT_ASSERT(exc); } void MultimapShift() { - std::multimap s; + typedef std::multimap Map; + Map s; s<>i1; - CPPUNIT_ASSERT(i1==std::make_pair(2, std::string("two"))); + CPPUNIT_ASSERT(std::make_pair(2, std::string("two"))==i1); bool exc(false); try { s>>i1; diff --git a/test/string_test.cxx b/test/string_test.cxx index 9b2a350..b7bab14 100644 --- a/test/string_test.cxx +++ b/test/string_test.cxx @@ -29,7 +29,8 @@ class StringTest: public CppUnit::TestFixture { void Join() { std::list l; l<<"Hello"<<"World"<<"here"<<"I"<<"am"; - CPPUNIT_ASSERT(mrw::join(l)=="Hello World here I am"); + CPPUNIT_ASSERT_EQUAL(std::list::size_type(5), l.size()); + CPPUNIT_ASSERT_EQUAL(std::string("Hello World here I am"), mrw::join(l)); } void Split() { std::string text("Hello World here I am");