From b1a399f185e54ffb0565701c86a639078e5b3f91 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Fri, 13 May 2022 00:39:02 +0200 Subject: [PATCH 01/31] working tester class --- src/openms/source/APPLICATIONS/TOPPBase.cpp | 11 +++++++---- src/openms/source/CONCEPT/sources.cmake | 1 + src/tests/class_tests/openms/executables.cmake | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 1211e399aff..6adda1ff6e2 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -253,7 +254,9 @@ namespace OpenMS // test if no options were given if (argc == 1) { + cout << red(); writeLog_("No options given. Aborting!"); + cout << reset_color(); printUsage_(); return ILLEGAL_PARAMETERS; } @@ -574,7 +577,7 @@ namespace OpenMS } } - cerr << "Options (mandatory options marked with '*'):" << "\n"; + cerr << magenta("Options (mandatory options marked with '*'):") << "\n"; //determine max length of parameters (including argument) for indentation UInt max_size = 0; @@ -748,7 +751,7 @@ namespace OpenMS //output cerr << "\n" - << "The following configuration subsections are valid:" << "\n"; + << green("The following configuration subsections are valid:") << "\n"; for (map::const_iterator it = subsections_.begin(); it != subsections_.end(); ++it) { String tmp = String(" - ") + it->first; @@ -756,11 +759,11 @@ namespace OpenMS cerr << ConsoleUtils::breakString(tmp + it->second, indent, 10); cerr << "\n"; } - cerr << "\n" + cerr << blue() << "\n" << ConsoleUtils::breakString("You can write an example INI file using the '-write_ini' option.", 0, 10) << "\n" << ConsoleUtils::breakString("Documentation of subsection parameters can be found in the doxygen documentation or the INIFileEditor.", 0, 10) << "\n" << ConsoleUtils::breakString("For more information, please consult the online documentation for this tool:", 0, 10) << "\n" - << ConsoleUtils::breakString(" - " + docurl, 0, 10) << "\n"; + << ConsoleUtils::breakString(" - " + docurl, 0, 10) << reset_color() << "\n"; } cerr << endl; } diff --git a/src/openms/source/CONCEPT/sources.cmake b/src/openms/source/CONCEPT/sources.cmake index d8e51113075..7b9e179cd8f 100644 --- a/src/openms/source/CONCEPT/sources.cmake +++ b/src/openms/source/CONCEPT/sources.cmake @@ -4,6 +4,7 @@ set(directory source/CONCEPT) ### list all filenames of the directory here set(sources_list ClassTest.cpp +Colorizer.cpp Exception.cpp FuzzyStringComparator.cpp GlobalExceptionHandler.cpp diff --git a/src/tests/class_tests/openms/executables.cmake b/src/tests/class_tests/openms/executables.cmake index 69418cac5c3..b98d6784956 100644 --- a/src/tests/class_tests/openms/executables.cmake +++ b/src/tests/class_tests/openms/executables.cmake @@ -1,5 +1,6 @@ set(concept_executables_list ClassTest_test + Colorizer_test Exception_Base_test FactoryBase_test Factory_test From da8c7dd9a60c7c921d5a3d37f4df83e3402e2345 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Fri, 13 May 2022 00:40:27 +0200 Subject: [PATCH 02/31] funktionierende Testklasse 2 --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 338 ++++++++++++ src/openms/source/CONCEPT/Colorizer.cpp | 501 ++++++++++++++++++ .../openms/source/Colorizer_test.cpp | 201 +++++++ 3 files changed, 1040 insertions(+) create mode 100644 src/openms/include/OpenMS/CONCEPT/Colorizer.h create mode 100644 src/openms/source/CONCEPT/Colorizer.cpp create mode 100644 src/tests/class_tests/openms/source/Colorizer_test.cpp diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h new file mode 100644 index 00000000000..fe0ea45c579 --- /dev/null +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -0,0 +1,338 @@ +// -------------------------------------------------------------------------- +// OpenMS -- Open-Source Mass Spectrometry +// -------------------------------------------------------------------------- +// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, +// ETH Zurich, and Freie Universitaet Berlin 2002-2022. +// +// This software is released under a three-clause BSD license: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of any author or any participating institution +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// For a full list of authors, refer to the file AUTHORS. +// -------------------------------------------------------------------------- +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING +// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// -------------------------------------------------------------------------- +// $Maintainer: Moritz Berger, Tetana Krymovska$ +// $Authors: Moritz Berger, Tetana Krymovska$ +// -------------------------------------------------------------------------- + +#pragma once + +//#include + +#include +#include +#include +#include + +namespace OpenMS +{ + /// enum COLOR for easier Object initialisation. + enum class COLOR + { + black, + red, + green, + yellow, + blue, + magenta, + cyan, + white, + RESET, ///< reset the color to the previous (default?) color + }; + + /** + * @brief A class, that provides options for colored output with the "<<" operator for output streams (cout, cerr) + * + */ + + + + class OPENMS_DLLAPI Colorizer + { +public: + /// Constructor + Colorizer(const COLOR color); + + /// Copy constructor + // Colorizer(const Colorizer &rhs); + + ///Assignment Operator + + + /// Destructor + ~Colorizer(); + + /// + void outputToStream(std::ostream& o_stream); + + /// + void colorStream(std::ostream& stream) const; + + /// + void resetColor(std::ostream& stream); + + /// + bool getReset(); + + /// + std::string getDataAsString(); + + /// insetrion Operator + friend std::ostream& operator<<(std::ostream& o_stream, Colorizer& col); + + + /// Bracket Operator + Colorizer& operator()() + { + reset_ = false; + this->input_.str(""); // clear the stream + return *this; + } + + /// Bracket Operator + template + Colorizer& operator()(T s) + { + this->input_.str(""); // clear the stringstream + this->input_ << s; // add new data + reset_ = true; + return *this; + } + +private: + + const int color_; + + /// input in Colorizer object to be colored + std::stringstream input_; + + /// + bool reset_ = true; + + +/** + * @brief constant string array which saves the Linux color codes. + * 0=black + * 1=red + * 2=green + * 3=yellow + * 4=blue + * 5=magenta + * 6=cyan + * 7=white + * 8=default console color (reset) + * + */ +#if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + /// + inline static constexpr std::array colors_ {16, 12, 10, 14, 9, 13, 11, 15, 15}; + +#elif defined(__linux__) || defined(__OSX__) + /// + inline static constexpr std::array colors_ {"\033[30m", "\033[31m", "\033[32m", "\033[33m", "\033[34m", "\033[35m", "\033[36m", "\033[37m", "\033[0m"}; + +#endif + }; + + + // declaration of all colorizer object. + extern OPENMS_DLLAPI Colorizer black; + extern OPENMS_DLLAPI Colorizer red; + extern OPENMS_DLLAPI Colorizer green; + extern OPENMS_DLLAPI Colorizer yellow; + extern OPENMS_DLLAPI Colorizer blue; + extern OPENMS_DLLAPI Colorizer magenta; + extern OPENMS_DLLAPI Colorizer cyan; + extern OPENMS_DLLAPI Colorizer white; + extern OPENMS_DLLAPI Colorizer reset_color; ///< reset the color to default, alias for 'make_default_color' + //extern /*OPENMS_DLLAPI*/ Colorizer default_color; ///< reset the color to default, alias for 'reset_color' + + //Stream operator declaration + OPENMS_DLLAPI std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col); + + +} + + + // namespace OpenMS + +// // -------------------------------------------------------------------------- +// // OpenMS -- Open-Source Mass Spectrometry +// // -------------------------------------------------------------------------- +// // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, +// // ETH Zurich, and Freie Universitaet Berlin 2002-2022. +// // +// // This software is released under a three-clause BSD license: +// // * Redistributions of source code must retain the above copyright +// // notice, this list of conditions and the following disclaimer. +// // * Redistributions in binary form must reproduce the above copyright +// // notice, this list of conditions and the following disclaimer in the +// // documentation and/or other materials provided with the distribution. +// // * Neither the name of any author or any participating institution +// // may be used to endorse or promote products derived from this software +// // without specific prior written permission. +// // For a full list of authors, refer to the file AUTHORS. +// // -------------------------------------------------------------------------- +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING +// // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// // +// // -------------------------------------------------------------------------- +// // $Maintainer: Moritz Berger, Tetana Krymovska$ +// // $Authors: Moritz Berger, Tetana Krymovska$ +// // -------------------------------------------------------------------------- + +// #pragma once + +// //#include + +// #include +// #include +// #include +// //#include + + +// namespace OpenMS +// { +// /// enum COLOR for easier Object initialisation. +// enum class COLOR +// { +// black, +// red, +// green, +// yellow, +// blue, +// magenta, +// cyan, +// white, +// RESET, ///< reset the color to the previous (default?) color +// }; + +// /** +// * @brief A class, that provides options for colored output with the "<<" operator for output streams (cout, cerr) +// * +// */ +// class Colorizer +// { +// public: +// /// Constructor +// Colorizer(const COLOR color); + +// /// Copy constructor +// // Colorizer(const Colorizer &rhs); + +// ///Assignment Operator + +// /// Destructor +// ~Colorizer(); + +// /// +// void outputToStream(std::ostream& o_stream); + +// /// +// void colorStream(std::ostream& stream) const; + +// /// +// void resetColor(std::ostream& stream); + +// /// +// bool getReset(); + +// /// +// std::string getDataAsString(); + +// /// insetrion Operator +// friend std::ostream& operator<<(std::ostream& o_stream, Colorizer& col); + +// /// Bracket Operator +// Colorizer& operator()() +// { +// reset_ = false; +// this->input_.str(""); // clear the stream +// return *this; +// } + +// /// Bracket Operator +// template +// Colorizer& operator()(T s) +// { +// this->input_.str(""); // clear the stringstream +// this->input_ << s; // add new data +// reset_ = true; +// return *this; +// } + +// private: + +// const int color_; + +// /// input in Colorizer object to be colored +// std::stringstream input_; + +// /// +// bool reset_ = true; + + +// /** +// * @brief constant string array which saves the Linux color codes. +// * 0=black +// * 1=red +// * 2=green +// * 3=yellow +// * 4=blue +// * 5=magenta +// * 6=cyan +// * 7=white +// * 8=default console color (reset) +// * +// */ +// #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) +// /// +// inline static constexpr std::array colors_ {16, 12, 10, 14, 9, 13, 11, 15, 15}; + +// #elif defined(__linux__) || defined(__OSX__) +// /// +// inline static constexpr std::array colors_ {"\033[30m", "\033[31m", "\033[32m", "\033[33m", "\033[34m", "\033[35m", "\033[36m", "\033[37m", "\033[0m"}; + +// #endif +// }; + + +// // declaration of all colorizer object. +// extern /*OPENMS_DLLAPI*/ Colorizer black; +// extern /*OPENMS_DLLAPI*/ Colorizer red; +// extern /*OPENMS_DLLAPI*/ Colorizer green; +// extern /*OPENMS_DLLAPI*/ Colorizer yellow; +// extern /*OPENMS_DLLAPI*/ Colorizer blue; +// extern /*OPENMS_DLLAPI*/ Colorizer magenta; +// extern /*OPENMS_DLLAPI*/ Colorizer cyan; +// extern /*OPENMS_DLLAPI*/ Colorizer white; +// extern /*OPENMS_DLLAPI*/ Colorizer reset_color; ///< reset the color to default, alias for 'make_default_color' +// //extern /*OPENMS_DLLAPI*/ Colorizer default_color; ///< reset the color to default, alias for 'reset_color' + +// } // namespace OpenMS diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp new file mode 100644 index 00000000000..e6e0c150944 --- /dev/null +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -0,0 +1,501 @@ +// -------------------------------------------------------------------------- +// OpenMS -- Open-Source Mass Spectrometry +// -------------------------------------------------------------------------- +// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, +// ETH Zurich, and Freie Universitaet Berlin 2002-2022. +// +// This software is released under a three-clause BSD license: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of any author or any participating institution +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// For a full list of authors, refer to the file AUTHORS. +// -------------------------------------------------------------------------- +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING +// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// -------------------------------------------------------------------------- +// $Maintainer: Moritz Berger, Tetana Krymovska $ +// $Authors: Moritz Berger, Tetana Krymovska$ +// -------------------------------------------------------------------------- + + +// include on FU-server (Linux) +// #include + +// include on Windows PC +//#include + +// include in project +#include + + + +#include + +#ifdef OPENMS_WINDOWSPLATTFORM + #include + #include +#endif + +namespace OpenMS +{ + + // constructor + Colorizer::Colorizer(const COLOR color) : color_((int)color) // color must be in initializer list, because of const keyword + { + } + + /// Default destructor + Colorizer::~Colorizer() + { +// if colorizer object is destroyed, set console color back to def col. +#if defined(__linux__) || defined(__OSX__) + std::cout << colors_[8]; +#endif + } + + /// + void Colorizer::colorStream(std::ostream& stream) const + { +#if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + + if (&std::cout == &stream) + { + // set color of output + ConsoleUtils::getInstance().setCoutColor(colors_[color_]); + } + else if (&std::cerr == &stream) + { + ///set color of error stream + ConsoleUtils::getInstance().setCerrColor(colors_[color_]); + } + + +#elif defined(__linux__) || defined(__OSX__) + // write coloring escape codes into the string + stream << this->colors_[this->color_]; +#endif + } + + /// + void Colorizer::resetColor(std::ostream& stream) + { +#ifdef OPENMS_WINDOWSPLATTFORM + if (&std::cout == &stream) + { + // reset color of output + ConsoleUtils::getInstance().resetCoutColor(); + } + else if (&std::cerr == &stream) + { + ///reset color of error stream + ConsoleUtils::getInstance().resetCerrColor(); + } + + + +#elif defined(__linux__) || defined(__OSX__) + stream << this->colors_[8]; +#endif + } + + /// + bool Colorizer::getReset() + { + return reset_; + } + + /// + std::string Colorizer::getDataAsString() + { + return input_.str(); + } + + // Helper function, to manipulate the output stream in class. + void Colorizer::outputToStream(std::ostream& o_stream) + { + /// color the stream (or console) + colorStream(o_stream); + + // paste text + o_stream << this->input_.str(); + + // if flag reset is set: reset comand line. else dont reset. + if (this->reset_) + { + resetColor(o_stream); + } + } + + + // overload the shift operator (<<) + std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) + { + // colorize string with color set in the object + col.outputToStream(o_stream); + return o_stream; + } + + // Objekte des typs colorizer + OpenMS::Colorizer black(COLOR::black); + OpenMS::Colorizer red(COLOR::red); + OpenMS::Colorizer green(COLOR::green); + OpenMS::Colorizer yellow(COLOR::yellow); + OpenMS::Colorizer blue(COLOR::blue); + OpenMS::Colorizer magenta(COLOR::magenta); + OpenMS::Colorizer cyan(COLOR::cyan); + OpenMS::Colorizer white(COLOR::white); + OpenMS::Colorizer reset_color(COLOR::RESET); + // OpenMS::Colorizer reset_color(COLOR::RESET); + + +} // namespace OpenMS + + + +// // -------------------------------------------------------------------------- +// // OpenMS -- Open-Source Mass Spectrometry +// // -------------------------------------------------------------------------- +// // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, +// // ETH Zurich, and Freie Universitaet Berlin 2002-2022. +// // +// // This software is released under a three-clause BSD license: +// // * Redistributions of source code must retain the above copyright +// // notice, this list of conditions and the following disclaimer. +// // * Redistributions in binary form must reproduce the above copyright +// // notice, this list of conditions and the following disclaimer in the +// // documentation and/or other materials provided with the distribution. +// // * Neither the name of any author or any participating institution +// // may be used to endorse or promote products derived from this software +// // without specific prior written permission. +// // For a full list of authors, refer to the file AUTHORS. +// // -------------------------------------------------------------------------- +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING +// // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// // WHETHER IN CONTRACT, STRICT LIABILITY, OR TcdORT (INCLUDING NEGLIGENCE OR +// // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// // +// // -------------------------------------------------------------------------- +// // $Maintainer: Moritz Berger, Tetana Krymovska $ +// // $Authors: Moritz Berger, Tetana Krymovska$ +// // -------------------------------------------------------------------------- + + +// // include on FU-server (Linux) +// // #include + +// // include on Windows PC +// //#include + +// // include in project +// #include + + + +// #include + +// #ifdef OPENMS_WINDOWSPLATTFORM +// #include +// #include +// #endif + +// namespace OpenMS +// { + +// // constructor +// Colorizer::Colorizer(const COLOR color) : color_((int)color) // color must be in initializer list, because of const keyword +// { +// } + +// /// Default destructor +// Colorizer::~Colorizer() +// { +// // if colorizer object is destroyed, set console color back to def col. +// #if defined(__linux__) || defined(__OSX__) +// std::cout << colors_[8]; +// #endif +// } + +// /// +// void Colorizer::colorStream(std::ostream& stream) const +// { +// #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + +// if (&std::cout == &stream) +// { +// // set color of output +// ConsoleUtils::getInstance().setCoutColor(colors_[color_]); +// } +// else if (&std::cerr == &stream) +// { +// ///set color of error stream +// ConsoleUtils::getInstance().setCerrColor(colors_[color_]); +// } + + +// #elif defined(__linux__) || defined(__OSX__) +// // write coloring escape codes into the string +// stream << this->colors_[this->color_]; +// #endif +// } + +// /// +// void Colorizer::resetColor(std::ostream& stream) +// { +// #ifdef OPENMS_WINDOWSPLATTFORM +// if (&std::cout == &stream) +// { +// // reset color of output +// ConsoleUtils::getInstance().resetCoutColor(); +// } +// else if (&std::cerr == &stream) +// { +// ///reset color of error stream +// ConsoleUtils::getInstance().resetCerrColor(); +// } + + + +// #elif defined(__linux__) || defined(__OSX__) +// stream << this->colors_[8]; +// #endif +// } + +// /// +// bool Colorizer::getReset() +// { +// return reset_; +// } + +// /// +// std::string Colorizer::getDataAsString() +// { +// return input_.str(); +// } + +// // Helper function, to manipulate the output stream in class. +// void Colorizer::outputToStream(std::ostream& o_stream) +// { +// /// color the stream (or console) +// colorStream(o_stream); + +// // paste text +// o_stream << this->input_.str(); + +// // if flag reset is set: reset comand line. else dont reset. +// if (this->reset_) +// { +// resetColor(o_stream); +// } +// } + + +// // overload the shift operator (<<) +// std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) +// { +// // colorize string with color set in the object +// col.outputToStream(o_stream); +// return o_stream; +// } + +// // Objekte des typs colorizer +// OpenMS::Colorizer black(COLOR::black); +// OpenMS::Colorizer red(COLOR::red); +// OpenMS::Colorizer green(COLOR::green); +// OpenMS::Colorizer yellow(COLOR::yellow); +// OpenMS::Colorizer blue(COLOR::blue); +// OpenMS::Colorizer magenta(COLOR::magenta); +// OpenMS::Colorizer cyan(COLOR::cyan); +// OpenMS::Colorizer white(COLOR::white); +// OpenMS::Colorizer reset_color(COLOR::RESET); +// // OpenMS::Colorizer reset_color(COLOR::RESET); + + +// } // namespace OpenMS +// // -------------------------------------------------------------------------- +// // OpenMS -- Open-Source Mass Spectrometry +// // -------------------------------------------------------------------------- +// // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, +// // ETH Zurich, and Freie Universitaet Berlin 2002-2022. +// // +// // This software is released under a three-clause BSD license: +// // * Redistributions of source code must retain the above copyright +// // notice, this list of conditions and the following disclaimer. +// // * Redistributions in binary form must reproduce the above copyright +// // notice, this list of conditions and the following disclaimer in the +// // documentation and/or other materials provided with the distribution. +// // * Neither the name of any author or any participating institution +// // may be used to endorse or promote products derived from this software +// // without specific prior written permission. +// // For a full list of authors, refer to the file AUTHORS. +// // -------------------------------------------------------------------------- +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING +// // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// // +// // -------------------------------------------------------------------------- +// // $Maintainer: Moritz Berger, Tetana Krymovska $ +// // $Authors: Moritz Berger, Tetana Krymovska$ +// // -------------------------------------------------------------------------- + + +// // include on FU-server (Linux) +// // #include + +// // include on Windows PC +// //#include + +// // include in project +// #include + + + +// #include + +// #ifdef OPENMS_WINDOWSPLATTFORM +// #include +// #include +// #endif + +// namespace OpenMS +// { + +// // constructor +// Colorizer::Colorizer(const COLOR color) : color_((int)color) // color must be in initializer list, because of const keyword +// { +// } + +// /// Default destructor +// Colorizer::~Colorizer() +// { +// // if colorizer object is destroyed, set console color back to def col. +// #if defined(__linux__) || defined(__OSX__) +// std::cout << colors_[8]; +// #endif +// } + +// /// +// void Colorizer::colorStream(std::ostream& stream) const +// { +// #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + +// if (&std::cout == &stream) +// { +// // set color of output +// ConsoleUtils::getInstance().setCoutColor(colors_[color_]); +// } +// else if (&std::cerr == &stream) +// { +// ///set color of error stream +// ConsoleUtils::getInstance().setCerrColor(colors_[color_]); +// } + + +// #elif defined(__linux__) || defined(__OSX__) +// // write coloring escape codes into the string +// stream << this->colors_[this->color_]; +// #endif +// } + +// /// +// void Colorizer::resetColor(std::ostream& stream) +// { +// #ifdef OPENMS_WINDOWSPLATTFORM +// if (&std::cout == &stream) +// { +// // reset color of output +// ConsoleUtils::getInstance().resetCoutColor(); +// } +// else if (&std::cerr == &stream) +// { +// ///reset color of error stream +// ConsoleUtils::getInstance().resetCerrColor(); +// } + + + +// #elif defined(__linux__) || defined(__OSX__) +// stream << this->colors_[8]; +// #endif +// } + +// /// +// bool Colorizer::getReset() +// { +// return reset_; +// } + +// /// +// std::string Colorizer::getDataAsString() +// { +// return input_.str(); +// } + +// // Helper function, to manipulate the output stream in class. +// void Colorizer::outputToStream(std::ostream& o_stream) +// { +// /// color the stream (or console) +// colorStream(o_stream); + +// // paste text +// o_stream << this->input_.str(); + +// // if flag reset is set: reset comand line. else dont reset. +// if (this->reset_) +// { +// resetColor(o_stream); +// } +// } + + +// // overload the shift operator (<<) +// std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) +// { +// // colorize string with color set in the object +// col.outputToStream(o_stream); +// return o_stream; +// } + +// // Objekte des typs colorizer +// OpenMS::Colorizer black(COLOR::black); +// OpenMS::Colorizer red(COLOR::red); +// OpenMS::Colorizer green(COLOR::green); +// OpenMS::Colorizer yellow(COLOR::yellow); +// OpenMS::Colorizer blue(COLOR::blue); +// OpenMS::Colorizer magenta(COLOR::magenta); +// OpenMS::Colorizer cyan(COLOR::cyan); +// OpenMS::Colorizer white(COLOR::white); +// OpenMS::Colorizer reset_color(COLOR::RESET); +// // OpenMS::Colorizer reset_color(COLOR::RESET); + + +// } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp new file mode 100644 index 00000000000..ee44b4aec05 --- /dev/null +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -0,0 +1,201 @@ +// -------------------------------------------------------------------------- +// OpenMS -- Open-Source Mass Spectrometry +// -------------------------------------------------------------------------- +// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, +// ETH Zurich, and Freie Universitaet Berlin 2002-2021. +// +// This software is released under a three-clause BSD license: +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// * Neither the name of any author or any participating institution +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// For a full list of authors, refer to the file AUTHORS. +// -------------------------------------------------------------------------- +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING +// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// -------------------------------------------------------------------------- +// $Maintainer: $ +// $Authors: Moritz Berger, Tetana Krymovska$ +// -------------------------------------------------------------------------- + +#include +#include + +/////////////////////////// +#include +/////////////////////////// + +#include +#include +#include +#include +#include + +using namespace OpenMS; +using namespace std; + + +START_TEST(Colorizer(),"$Id$") + +// string asciiString = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + +#if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + +//Check that the colorized input contains the original text and DOES NOT contain ASCI codes +START_SECTION(Colorizer) +{ + string asciiString = "!#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + + stringstream blackStream; + stringstream redStream; + stringstream greenStream; + stringstream yellowStream; + stringstream blueStream; + stringstream magentaStream; + stringstream cyanStream; + stringstream whiteStream; + + string outStream; + + blackStream << black(asciiString); + blackStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + redStream << red(asciiString); + redStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + greenStream << green(asciiString); + greenStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + yellowStream << yellow(asciiString); + yellowStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + blueStream << blue(asciiString); + blueStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + magentaStream << magenta(asciiString); + magentaStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + cyanStream << cyan(asciiString); + cyanStream >> outStream; + TEST_EQUAL(outStream, asciiString) + + whiteStream << white(asciiString); + whiteStream >> outStream; + TEST_EQUAL(outStream, asciiString) +} +END_SECTION + +#elif defined(__linux__) || defined(__OSX__) + + //Check that the colorized input contains the original text and according ASCI codes +START_SECTION(Colorizer) +{ + string asciiString = "!#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + + stringstream blackStream; + stringstream redStream; + stringstream greenStream; + stringstream yellowStream; + stringstream blueStream; + stringstream magentaStream; + stringstream cyanStream; + stringstream whiteStream; + + string outStream; + + blackStream << black(asciiString); + blackStream >> outStream; + TEST_EQUAL(outStream, "\e[30m"+asciiString+"\e[0m") + + redStream << red(asciiString); + redStream >> outStream; + TEST_EQUAL(outStream, "\e[31m"+asciiString+"\e[0m") + + greenStream << green(asciiString); + greenStream >> outStream; + TEST_EQUAL(outStream, "\e[32m"+asciiString+"\e[0m") + + yellowStream << yellow(asciiString); + yellowStream >> outStream; + TEST_EQUAL(outStream, "\e[33m"+asciiString+"\e[0m") + + blueStream << blue(asciiString); + blueStream >> outStream; + TEST_EQUAL(outStream, "\e[34m"+asciiString+"\e[0m") + + magentaStream << magenta(asciiString); + magentaStream >> outStream; + TEST_EQUAL(outStream, "\e[35m"+asciiString+"\e[0m") + + cyanStream << cyan(asciiString); + cyanStream >> outStream; + TEST_EQUAL(outStream, "\e[36m"+asciiString+"\e[0m") + + whiteStream << white(asciiString); + whiteStream >> outStream; + TEST_EQUAL(outStream, "\e[37m"+asciiString+"\e[0m") + +} +END_SECTION + +//testing various inputs for colorizing +START_SECTION(Colorizer black) +{ + //Test variables + char tchar = 'a'; + // unsigned char unsignedChar = 'i'; + // signed char signedChar = 's'; + // short int shortInt = 32766; + // unsigned short int unsShortInt = 600; + // signed short int signShortInt = -32560; + // unsigned long int unsLongInt = 40000000000; + // long long int longLongInt = 981278728478274; + // unsigned long long int unsLongLongInt = -78273829375; + // float flt = 2094.5892; + // double dbl = -253575634.98925; + // long double longDbl= 135315.2929849375; + // wchar_t wideChar = L'S'; + + string outStream; + string outString; + stringstream blackStream; + + blackStream << black(tchar); + blackStream >> outStream; + outString = "\e[30m" + tchar; + outString.append("\e[0m"); + TEST_EQUAL(outStream, outString) + + +} +END_SECTION + +#endif + + + +//Testing other variables +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +END_TEST + From a59a4a950df1394950eb234102c7a2e5572795e2 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Tue, 17 May 2022 14:25:40 +0200 Subject: [PATCH 03/31] Added different input tests for Colorizer testclass, suggested blueprint for further test cases --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 2 + .../openms/source/Colorizer_test.cpp | 291 ++++++++++++++++-- 2 files changed, 268 insertions(+), 25 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index fe0ea45c579..8d6ed60101f 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -40,6 +40,8 @@ #include #include #include +// #include + namespace OpenMS { diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index ee44b4aec05..dfde4f6c499 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -48,9 +48,89 @@ using namespace OpenMS; using namespace std; +/* TO-DO ++ Check if string inputs are unchanged, and ANSI codes inside/not inside +- Windows test - define, copy, TEST if works ++/- Test every color function for all variable sets +- Test every other public function +- Test background color change test case - DEFINE functionality first +- ConsoleUtils Erweiterung +- mention "NOT TESTABLE" methods in sections +*/ + START_TEST(Colorizer(),"$Id$") + //Test variables +char tchar = 'a'; +unsigned char unsignedChar = 'i'; +signed char signedChar = 's'; +short int shortInt = 32766; +unsigned short int unsShortInt = 600; +signed short int signShortInt = -32560; +unsigned long int unsLongInt = 40000000000; +long long int longLongInt = 981278728478274; +unsigned long long int unsLongLongInt = -78273829375; +float flt = 2094.5892; +double dbl = -253575634.98925; +long double longDbl= 135315.2929849375; +wchar_t wideChar = L'S'; + +/* +//////Functions to replace manual creation of stringstreams +//////and comparison strings for TEST_EQUAL for coloured outputs for Linux +////// +//////UNFINISHED!!! + +template +stringstream colorStream(T const& testVariable, Colorizer) +//saves a colored output of an instance of Colorizer into a stream +{ + stringstream coloredStream; + stringstream outputStream; + + coloredStream << Colorizer(testVariable); + coloredStream >> outputStream; + + return outputStream; +} + +string createComparisonANSIString(string testVariable,Colorizer){ + //creates a model string with according ANSI codes to be + //compared to stream created by colorStream + + string comparisonString; + comparisonString.append(blackANSI); + comparisonString.append(to_string(tchar)); + //to_string is causing formatting issues with char variables, + // -> improve + comparisonString.append(resetColorANSI); + + return conparisonString; +} + +*/ + +START_SECTION(Colorizer::colorStream(ostream& stream) const) +{ + NOT_TESTABLE //is testable? +} +END_SECTION + +START_SECTION(outputToStream(ostream& o_stream)) +{ + NOT_TESTABLE //is testable? +} +END_SECTION + +START_SECTION(resetColor(ostream& stream)) +{ + NOT_TESTABLE //is testable? +} +END_SECTION + + + // string asciiString = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) @@ -107,6 +187,17 @@ END_SECTION #elif defined(__linux__) || defined(__OSX__) +//ANSI codes +string blackANSI = "\e[30m"; +string redANSI = "\e[31m"; +string greenANSI = "\e[32m"; +string yellowANSI = "\e[33m"; +string blueANSI = "\e[34m"; +string magentaANSI = "\e[35m"; +string cyanANSI = "\e[36m";; +string whiteANSI = "\e[37m"; +string resetColorANSI = "\e[0m"; + //Check that the colorized input contains the original text and according ASCI codes START_SECTION(Colorizer) { @@ -159,43 +250,193 @@ START_SECTION(Colorizer) END_SECTION //testing various inputs for colorizing -START_SECTION(Colorizer black) +START_SECTION(Colorizer::black()) { - //Test variables - char tchar = 'a'; - // unsigned char unsignedChar = 'i'; - // signed char signedChar = 's'; - // short int shortInt = 32766; - // unsigned short int unsShortInt = 600; - // signed short int signShortInt = -32560; - // unsigned long int unsLongInt = 40000000000; - // long long int longLongInt = 981278728478274; - // unsigned long long int unsLongLongInt = -78273829375; - // float flt = 2094.5892; - // double dbl = -253575634.98925; - // long double longDbl= 135315.2929849375; - // wchar_t wideChar = L'S'; - string outStream; - string outString; + string coloredStream; + string comparisonString; stringstream blackStream; + //char//////////////////////////////////// blackStream << black(tchar); - blackStream >> outStream; - outString = "\e[30m" + tchar; - outString.append("\e[0m"); - TEST_EQUAL(outStream, outString) + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(tchar)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //unsignedChar//////////////////////////// + blackStream << black(unsignedChar); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(unsignedChar)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //signed char/////////////////////////////// + blackStream << black(signedChar); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(signedChar)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //wide char/////////////////////////////// + blackStream << black(wideChar); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(wideChar)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //short int/////////////////////////////// + blackStream << black(shortInt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(shortInt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //unsigned short int/////////////////////////////// + blackStream << black(unsShortInt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(unsShortInt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //signed short int/////////////////////////////// + blackStream << black(signShortInt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(signShortInt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //unsigned long int/////////////////////////////// + blackStream << black(unsLongInt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(unsLongInt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //long long int/////////////////////////////// + blackStream << black(longLongInt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(longLongInt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //unsigned long long int/////////////////////////////// + blackStream << black(unsLongLongInt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(unsLongLongInt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //float/////////////////////////////// + blackStream << black(flt); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(flt)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //double/////////////////////////////// + blackStream << black(dbl); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(dbl)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + + //long double/////////////////////////////// + blackStream << black(longDbl); + blackStream >> coloredStream; + comparisonString.append(blackANSI); + comparisonString.append(to_string(longDbl)); + comparisonString.append(resetColorANSI); + TEST_EQUAL(coloredStream, comparisonString) + + //clearing streams + coloredStream.clear(); + comparisonString = ""; + blackStream.clear(); + } END_SECTION -#endif +//test case - resetting color only for given stream - implement? +//Or is testing of only class methods sufficient? + +#endif -//Testing other variables -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// END_TEST From 7e27de514deeb19b11a094d11e89ebf7e6d8dfc2 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Fri, 20 May 2022 16:45:45 +0200 Subject: [PATCH 04/31] Adding changes to colorizer testclass 1 --- .../openms/source/Colorizer_test.cpp | 401 ++++++------------ 1 file changed, 136 insertions(+), 265 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index dfde4f6c499..cc2afa4ea83 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -48,33 +48,40 @@ using namespace OpenMS; using namespace std; -/* TO-DO +/* TO-DO 1 + Check if string inputs are unchanged, and ANSI codes inside/not inside - Windows test - define, copy, TEST if works +/- Test every color function for all variable sets - Test every other public function -- Test background color change test case - DEFINE functionality first -- ConsoleUtils Erweiterung - mention "NOT TESTABLE" methods in sections +-!!!ALL changes requested after last push */ +/* TO-DO 2 +- UPDATE OpenMS Version (consult) and Colorizer version +- Test background color change test case - DEFINE functionality first +- ConsoleUtils Erweiterung +*/ START_TEST(Colorizer(),"$Id$") //Test variables -char tchar = 'a'; -unsigned char unsignedChar = 'i'; -signed char signedChar = 's'; -short int shortInt = 32766; -unsigned short int unsShortInt = 600; -signed short int signShortInt = -32560; -unsigned long int unsLongInt = 40000000000; -long long int longLongInt = 981278728478274; -unsigned long long int unsLongLongInt = -78273829375; -float flt = 2094.5892; -double dbl = -253575634.98925; -long double longDbl= 135315.2929849375; -wchar_t wideChar = L'S'; +char test_char = 'a'; +int test_int = 15; +float test_float = 2094.5892; +string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; +// string test_string = "ABCDE"; + +//ANSI codes +string const blackANSI = "\e[30m"; +string const redANSI = "\e[31m"; +string const greenANSI = "\e[32m"; +string const yellowANSI = "\e[33m"; +string const blueANSI = "\e[34m"; +string const magentaANSI = "\e[35m"; +string const cyanANSI = "\e[36m";; +string const whiteANSI = "\e[37m"; +string const resetColorANSI = "\e[0m"; /* //////Functions to replace manual creation of stringstreams @@ -106,7 +113,7 @@ string createComparisonANSIString(string testVariable,Colorizer){ // -> improve comparisonString.append(resetColorANSI); - return conparisonString; + return comparisonString; } */ @@ -117,15 +124,27 @@ START_SECTION(Colorizer::colorStream(ostream& stream) const) } END_SECTION -START_SECTION(outputToStream(ostream& o_stream)) +START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { - NOT_TESTABLE //is testable? + Colorizer test_colorizer; + stringstream test_stream; + stringstream test_stream << "ABCDEFGHIJKLM"; + test_colorizer.outputToStream(test_stream); + TEST_EQUAL(test_colortestizer,"ABCDEFGHIJKLM"); + + } END_SECTION -START_SECTION(resetColor(ostream& stream)) +START_SECTION(Colorizer::resetColor(ostream& stream)) { - NOT_TESTABLE //is testable? + stringstream test_stream; + Colorizer test_colorizer; + + test_colorizer.resetColor(); + test_colorizer >> test_stream; + TEST_EQUAL(test_stream, resetColorANSI) + } END_SECTION @@ -133,310 +152,162 @@ END_SECTION // string asciiString = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; -#if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) -//Check that the colorized input contains the original text and DOES NOT contain ASCI codes -START_SECTION(Colorizer) +START_SECTION("Testing static Colorizer") { - string asciiString = "!#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - - stringstream blackStream; - stringstream redStream; - stringstream greenStream; - stringstream yellowStream; - stringstream blueStream; - stringstream magentaStream; - stringstream cyanStream; - stringstream whiteStream; + #ifdef OPENMS_WINDOWSPLATFORM + //Check that the colorized input contains the original text and DOES NOT contain ASCI codes + //TEST ON Windows!S + stringstream colored_stream; - string outStream; + colored_stream << black(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - blackStream << black(asciiString); - blackStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << red(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - redStream << red(asciiString); - redStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << green(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - greenStream << green(asciiString); - greenStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << yellow(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - yellowStream << yellow(asciiString); - yellowStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << blue(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - blueStream << blue(asciiString); - blueStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << magenta(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - magentaStream << magenta(asciiString); - magentaStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << cyan(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - cyanStream << cyan(asciiString); - cyanStream >> outStream; - TEST_EQUAL(outStream, asciiString) + colored_stream << white(test_string); + TEST_EQUAL(colored_stream.str(), test_string) + colored_stream.clear(); - whiteStream << white(asciiString); - whiteStream >> outStream; - TEST_EQUAL(outStream, asciiString) -} -END_SECTION + #elif defined(__linux__) || defined(__OSX__) + //LINUX//////LINUX////LINUX////LINUX////LINUX////LINUX////LINUX//// + //Check that the colorized input contains the original text and according ASCI codes -#elif defined(__linux__) || defined(__OSX__) + stringstream colored_stream; -//ANSI codes -string blackANSI = "\e[30m"; -string redANSI = "\e[31m"; -string greenANSI = "\e[32m"; -string yellowANSI = "\e[33m"; -string blueANSI = "\e[34m"; -string magentaANSI = "\e[35m"; -string cyanANSI = "\e[36m";; -string whiteANSI = "\e[37m"; -string resetColorANSI = "\e[0m"; - - //Check that the colorized input contains the original text and according ASCI codes -START_SECTION(Colorizer) -{ - string asciiString = "!#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + colored_stream << black(test_string); + TEST_EQUAL(colored_stream.str(), blackANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - stringstream blackStream; - stringstream redStream; - stringstream greenStream; - stringstream yellowStream; - stringstream blueStream; - stringstream magentaStream; - stringstream cyanStream; - stringstream whiteStream; + colored_stream << red(test_string); + TEST_EQUAL(colored_stream.str(), redANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - string outStream; + colored_stream << green(test_string); + TEST_EQUAL(colored_stream.str(), greenANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - blackStream << black(asciiString); - blackStream >> outStream; - TEST_EQUAL(outStream, "\e[30m"+asciiString+"\e[0m") + colored_stream << yellow(test_string); + TEST_EQUAL(colored_stream.str(), yellowANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - redStream << red(asciiString); - redStream >> outStream; - TEST_EQUAL(outStream, "\e[31m"+asciiString+"\e[0m") + colored_stream << blue(test_string); + TEST_EQUAL(colored_stream.str(), blueANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - greenStream << green(asciiString); - greenStream >> outStream; - TEST_EQUAL(outStream, "\e[32m"+asciiString+"\e[0m") + colored_stream << magenta(test_string); + TEST_EQUAL(colored_stream.str(), magentaANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - yellowStream << yellow(asciiString); - yellowStream >> outStream; - TEST_EQUAL(outStream, "\e[33m"+asciiString+"\e[0m") + colored_stream << cyan(test_string); + TEST_EQUAL(colored_stream.str(), cyanANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - blueStream << blue(asciiString); - blueStream >> outStream; - TEST_EQUAL(outStream, "\e[34m"+asciiString+"\e[0m") + colored_stream << white(test_string); + TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - magentaStream << magenta(asciiString); - magentaStream >> outStream; - TEST_EQUAL(outStream, "\e[35m"+asciiString+"\e[0m") - cyanStream << cyan(asciiString); - cyanStream >> outStream; - TEST_EQUAL(outStream, "\e[36m"+asciiString+"\e[0m") - whiteStream << white(asciiString); - whiteStream >> outStream; - TEST_EQUAL(outStream, "\e[37m"+asciiString+"\e[0m") + //rewrite streams and test every color + #endif } END_SECTION //testing various inputs for colorizing -START_SECTION(Colorizer::black()) +START_SECTION(Colorizer::yellow()) { string coloredStream; string comparisonString; - stringstream blackStream; + stringstream yellowStream; //char//////////////////////////////////// - blackStream << black(tchar); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(tchar)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //unsignedChar//////////////////////////// - blackStream << black(unsignedChar); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(unsignedChar)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //signed char/////////////////////////////// - blackStream << black(signedChar); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(signedChar)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //wide char/////////////////////////////// - blackStream << black(wideChar); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(wideChar)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //short int/////////////////////////////// - blackStream << black(shortInt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(shortInt)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //unsigned short int/////////////////////////////// - blackStream << black(unsShortInt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(unsShortInt)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //signed short int/////////////////////////////// - blackStream << black(signShortInt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(signShortInt)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //unsigned long int/////////////////////////////// - blackStream << black(unsLongInt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(unsLongInt)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //long long int/////////////////////////////// - blackStream << black(longLongInt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(longLongInt)); + yellowStream << yellow(test_char); + yellowStream >> coloredStream; + comparisonString.append(yellowANSI); + comparisonString.append(to_string(test_char)); comparisonString.append(resetColorANSI); TEST_EQUAL(coloredStream, comparisonString) //clearing streams coloredStream.clear(); comparisonString = ""; - blackStream.clear(); + yellowStream.clear(); - //unsigned long long int/////////////////////////////// - blackStream << black(unsLongLongInt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(unsLongLongInt)); + //int/////////////////////////////// + yellowStream << yellow(test_int); + yellowStream >> coloredStream; + comparisonString.append(yellowANSI); + comparisonString.append(to_string(test_int)); comparisonString.append(resetColorANSI); TEST_EQUAL(coloredStream, comparisonString) //clearing streams coloredStream.clear(); comparisonString = ""; - blackStream.clear(); + yellowStream.clear(); //float/////////////////////////////// - blackStream << black(flt); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(flt)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //double/////////////////////////////// - blackStream << black(dbl); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(dbl)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - blackStream.clear(); - - //long double/////////////////////////////// - blackStream << black(longDbl); - blackStream >> coloredStream; - comparisonString.append(blackANSI); - comparisonString.append(to_string(longDbl)); + yellowStream << yellow(test_float); + yellowStream >> coloredStream; + comparisonString.append(yellowANSI); + comparisonString.append(to_string(test_float)); comparisonString.append(resetColorANSI); TEST_EQUAL(coloredStream, comparisonString) //clearing streams coloredStream.clear(); comparisonString = ""; - blackStream.clear(); - - + yellowStream.clear(); } END_SECTION -//test case - resetting color only for given stream - implement? -//Or is testing of only class methods sufficient? - - -#endif +START_SECTION(Colorizer& operator()()) +{ + stringstream test_stream; + test_stream << blue(); + test_stream << "ABDCE"; + TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE") + test_stream << reset_color(); + TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE"+resetColorANSI) + +} +END_SECTION END_TEST From 8c04f93bb7066b168aace8a14800198dda16cb1a Mon Sep 17 00:00:00 2001 From: tetak94 Date: Mon, 23 May 2022 02:02:10 +0200 Subject: [PATCH 05/31] Updated input testing, minor changes --- .../openms/source/Colorizer_test.cpp | 172 +++++++++++------- 1 file changed, 106 insertions(+), 66 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index cc2afa4ea83..f717097e63c 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -51,7 +51,7 @@ using namespace std; /* TO-DO 1 + Check if string inputs are unchanged, and ANSI codes inside/not inside - Windows test - define, copy, TEST if works -+/- Test every color function for all variable sets ++ Test every color function for all variable sets - Test every other public function - mention "NOT TESTABLE" methods in sections -!!!ALL changes requested after last push @@ -63,6 +63,15 @@ using namespace std; - ConsoleUtils Erweiterung */ +template +//convert any input to string +string convertToString ( T var_input ) +{ + ostringstream ss; + ss << var_input; + return ss.str(); +} + START_TEST(Colorizer(),"$Id$") //Test variables @@ -83,6 +92,8 @@ string const cyanANSI = "\e[36m";; string const whiteANSI = "\e[37m"; string const resetColorANSI = "\e[0m"; + + /* //////Functions to replace manual creation of stringstreams //////and comparison strings for TEST_EQUAL for coloured outputs for Linux @@ -126,11 +137,11 @@ END_SECTION START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { - Colorizer test_colorizer; - stringstream test_stream; - stringstream test_stream << "ABCDEFGHIJKLM"; - test_colorizer.outputToStream(test_stream); - TEST_EQUAL(test_colortestizer,"ABCDEFGHIJKLM"); + // Colorizer test_colorizer; + // stringstream test_stream; + // stringstream test_stream << "ABCDEFGHIJKLM"; + // test_colorizer.outputToStream(test_stream); + // TEST_EQUAL(test_colortestizer,"ABCDEFGHIJKLM"); } @@ -138,22 +149,21 @@ END_SECTION START_SECTION(Colorizer::resetColor(ostream& stream)) { - stringstream test_stream; - Colorizer test_colorizer; - - test_colorizer.resetColor(); - test_colorizer >> test_stream; - TEST_EQUAL(test_stream, resetColorANSI) - -} -END_SECTION + // stringstream test_stream; + // Colorizer test_colorizer; + // test_colorizer.resetColor(); + // test_colorizer >> test_stream; + // TEST_EQUAL(test_stream, resetColorANSI) + #if defined(__linux__) || defined(__OSX__) -// string asciiString = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; + #endif +} +END_SECTION -START_SECTION("Testing static Colorizer") +START_SECTION("Testing Colorizer instances") { #ifdef OPENMS_WINDOWSPLATFORM //Check that the colorized input contains the original text and DOES NOT contain ASCI codes @@ -239,72 +249,102 @@ START_SECTION("Testing static Colorizer") colored_stream.clear(); - - //rewrite streams and test every color #endif } END_SECTION //testing various inputs for colorizing -START_SECTION(Colorizer::yellow()) +START_SECTION("Testing Colorizer inputs") { + #ifdef OPENMS_WINDOWSPLATTFORM + + stringstream colored_stream; + string comparison_string; + + //char//////////////////////////////////// + colored_stream << black(test_char); + comparison_string.append(convertToString(test_char)); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //int///////////////////////////////////// + colored_stream << cyan(test_int); + comparison_string.append(convertToString(test_int)); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //floag/////////////////////////////////// + colored_stream << magenta(test_float); + comparison_string.append(convertToString(test_float)); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; - string coloredStream; - string comparisonString; - stringstream yellowStream; + #elif defined(__linux__) || defined(__OSX__) + stringstream colored_stream; + string comparison_string; - //char//////////////////////////////////// - yellowStream << yellow(test_char); - yellowStream >> coloredStream; - comparisonString.append(yellowANSI); - comparisonString.append(to_string(test_char)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - yellowStream.clear(); - - //int/////////////////////////////// - yellowStream << yellow(test_int); - yellowStream >> coloredStream; - comparisonString.append(yellowANSI); - comparisonString.append(to_string(test_int)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) - - //clearing streams - coloredStream.clear(); - comparisonString = ""; - yellowStream.clear(); - - //float/////////////////////////////// - yellowStream << yellow(test_float); - yellowStream >> coloredStream; - comparisonString.append(yellowANSI); - comparisonString.append(to_string(test_float)); - comparisonString.append(resetColorANSI); - TEST_EQUAL(coloredStream, comparisonString) + //char//////////////////////////////////// + colored_stream << yellow(test_char); + comparison_string.append(yellowANSI); + comparison_string.append(convertToString(test_char)); + comparison_string.append(resetColorANSI); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //int/////////////////////////////// + colored_stream << green(test_int); + comparison_string.append(greenANSI); + comparison_string.append(convertToString(test_int)); + comparison_string.append(resetColorANSI); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; - //clearing streams - coloredStream.clear(); - comparisonString = ""; - yellowStream.clear(); + //float/////////////////////////////// + colored_stream << red(test_float); + comparison_string.append(redANSI); + comparison_string.append(convertToString(test_float)); + comparison_string.append(resetColorANSI); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + #endif } END_SECTION START_SECTION(Colorizer& operator()()) { - stringstream test_stream; - test_stream << blue(); - test_stream << "ABDCE"; - TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE") + // stringstream test_stream; + // test_stream << blue(); + // test_stream << "ABDCE"; + // TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE") - test_stream << reset_color(); - TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE"+resetColorANSI) + // test_stream << reset_color(); + // TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE"+resetColorANSI) } END_SECTION From e84062fef8f09c81f6105902105c5d6123706f7d Mon Sep 17 00:00:00 2001 From: tetak94 Date: Mon, 23 May 2022 02:30:54 +0200 Subject: [PATCH 06/31] Operator test added --- .../openms/source/Colorizer_test.cpp | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index f717097e63c..01fde1b5c9d 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -149,17 +149,11 @@ END_SECTION START_SECTION(Colorizer::resetColor(ostream& stream)) { + // #if defined(__linux__) || defined(__OSX__) // stringstream test_stream; - // Colorizer test_colorizer; - - // test_colorizer.resetColor(); - // test_colorizer >> test_stream; + // test_stream << reset_color(); // TEST_EQUAL(test_stream, resetColorANSI) - - #if defined(__linux__) || defined(__OSX__) - - #endif - + // #endif } END_SECTION @@ -203,7 +197,6 @@ START_SECTION("Testing Colorizer instances") colored_stream.clear(); #elif defined(__linux__) || defined(__OSX__) - //LINUX//////LINUX////LINUX////LINUX////LINUX////LINUX////LINUX//// //Check that the colorized input contains the original text and according ASCI codes stringstream colored_stream; @@ -248,7 +241,6 @@ START_SECTION("Testing Colorizer instances") colored_stream.str(string()); colored_stream.clear(); - #endif } @@ -338,14 +330,22 @@ END_SECTION START_SECTION(Colorizer& operator()()) { - // stringstream test_stream; - // test_stream << blue(); - // test_stream << "ABDCE"; - // TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE") - // test_stream << reset_color(); - // TEST_EQUAL(test_stream.str(),blueANSI+"ABCDE"+resetColorANSI) - + #if defined(__linux__) || defined(__OSX__) + + stringstream test_stream; + + test_stream << green() << "green text" << 123 << "!" << " " << reset_color(); + TEST_EQUAL(test_stream.str(),greenANSI+"green text123! "+resetColorANSI) + test_stream.str(string()); + test_stream.clear(); + + test_stream << reset_color() << "default text" << magenta() << "magenta text"; + TEST_EQUAL(test_stream.str(),resetColorANSI+"default text"+magentaANSI+"magenta text") + test_stream.str(string()); + test_stream.clear(); + + #endif } END_SECTION From 437c009fbcc49b9c77134978d817f1f1b5628aef Mon Sep 17 00:00:00 2001 From: tetak94 Date: Mon, 23 May 2022 03:04:58 +0200 Subject: [PATCH 07/31] added tests of all methods, but improvement is still needed --- .../openms/source/Colorizer_test.cpp | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 01fde1b5c9d..3bed607d68e 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -50,11 +50,11 @@ using namespace std; /* TO-DO 1 + Check if string inputs are unchanged, and ANSI codes inside/not inside -- Windows test - define, copy, TEST if works +- Windows test - try on Windows + Test every color function for all variable sets -- Test every other public function -- mention "NOT TESTABLE" methods in sections --!!!ALL changes requested after last push ++/- Test every other public function ++ mention "NOT TESTABLE" methods in sections ++!!!ALL changes requested after last push */ /* TO-DO 2 @@ -131,29 +131,36 @@ string createComparisonANSIString(string testVariable,Colorizer){ START_SECTION(Colorizer::colorStream(ostream& stream) const) { - NOT_TESTABLE //is testable? + // kind of the same that is done below ...? + //maybe direct access of methods via instance is needed (instance.method()) + //but I didn't yet work out a solution + #if defined(__linux__) || defined(__OSX__) + stringstream test_stream; + test_stream << blue(test_string); + TEST_EQUAL(test_stream.str(), blueANSI+test_string+resetColorANSI) + #endif } END_SECTION START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { - // Colorizer test_colorizer; - // stringstream test_stream; - // stringstream test_stream << "ABCDEFGHIJKLM"; - // test_colorizer.outputToStream(test_stream); - // TEST_EQUAL(test_colortestizer,"ABCDEFGHIJKLM"); - + // kind of the same that is done below and above...? + #if defined(__linux__) || defined(__OSX__) + stringstream test_stream; + test_stream << green(test_string); + TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI) + #endif } END_SECTION START_SECTION(Colorizer::resetColor(ostream& stream)) { - // #if defined(__linux__) || defined(__OSX__) - // stringstream test_stream; - // test_stream << reset_color(); - // TEST_EQUAL(test_stream, resetColorANSI) - // #endif + #if defined(__linux__) || defined(__OSX__) + stringstream test_stream; + test_stream << reset_color(); + TEST_EQUAL(test_stream.str(), resetColorANSI) + #endif } END_SECTION From 6795313738ffee79f0b66480ed0b258f19d4706d Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 25 May 2022 03:48:33 +0200 Subject: [PATCH 08/31] Defined function tests, restructured ifdefs --- .../openms/source/Colorizer_test.cpp | 383 ++++++++++-------- 1 file changed, 208 insertions(+), 175 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 3bed607d68e..593a2cce808 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -55,6 +55,8 @@ using namespace std; +/- Test every other public function + mention "NOT TESTABLE" methods in sections +!!!ALL changes requested after last push + + //ANSI fuer windows leer definieren - ifdefs wegmachen */ /* TO-DO 2 @@ -78,19 +80,36 @@ START_TEST(Colorizer(),"$Id$") char test_char = 'a'; int test_int = 15; float test_float = 2094.5892; -string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; -// string test_string = "ABCDE"; +// string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; +string test_string = "ABCDE"; //ANSI codes -string const blackANSI = "\e[30m"; -string const redANSI = "\e[31m"; -string const greenANSI = "\e[32m"; -string const yellowANSI = "\e[33m"; -string const blueANSI = "\e[34m"; -string const magentaANSI = "\e[35m"; -string const cyanANSI = "\e[36m";; -string const whiteANSI = "\e[37m"; -string const resetColorANSI = "\e[0m"; + +#ifdef OPENMS_WINDOWSPLATFORM + + string const blackANSI = ""; + string const redANSI = ""; + string const greenANSI = ""; + string const yellowANSI = ""; + string const blueANSI = ""; + string const magentaANSI = ""; + string const cyanANSI = ""; + string const whiteANSI = ""; + string const resetColorANSI = ""; + +#elif defined(__linux__) || defined(__OSX__) + + string const blackANSI = "\e[30m"; + string const redANSI = "\e[31m"; + string const greenANSI = "\e[32m"; + string const yellowANSI = "\e[33m"; + string const blueANSI = "\e[34m"; + string const magentaANSI = "\e[35m"; + string const cyanANSI = "\e[36m";; + string const whiteANSI = "\e[37m"; + string const resetColorANSI = "\e[0m"; + +#endif @@ -131,124 +150,141 @@ string createComparisonANSIString(string testVariable,Colorizer){ START_SECTION(Colorizer::colorStream(ostream& stream) const) { - // kind of the same that is done below ...? - //maybe direct access of methods via instance is needed (instance.method()) - //but I didn't yet work out a solution - #if defined(__linux__) || defined(__OSX__) - stringstream test_stream; - test_stream << blue(test_string); - TEST_EQUAL(test_stream.str(), blueANSI+test_string+resetColorANSI) - #endif + //without text + stringstream test_stream; + Colorizer c(COLOR::black); + + c.colorStream(test_stream); + TEST_EQUAL(test_stream.str(), blackANSI) + + //with text + test_stream.str(string()); + test_stream.clear(); + + test_stream << c(test_string); + c.colorStream(test_stream); + TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) + } END_SECTION START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { - // kind of the same that is done below and above...? - #if defined(__linux__) || defined(__OSX__) - stringstream test_stream; - test_stream << green(test_string); - TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI) - #endif + //without text + stringstream test_stream; + Colorizer c(COLOR::cyan); + + c.outputToStream(test_stream); + TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) + + //with text + test_stream.str(string()); + test_stream.clear(); + + test_stream << c(test_string); + c.outputToStream(test_stream); + TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) } END_SECTION START_SECTION(Colorizer::resetColor(ostream& stream)) { - #if defined(__linux__) || defined(__OSX__) - stringstream test_stream; - test_stream << reset_color(); - TEST_EQUAL(test_stream.str(), resetColorANSI) - #endif + stringstream test_stream; + Colorizer c(COLOR::green); + + test_stream << c(test_string); + c.resetColor(test_stream); + TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) } END_SECTION START_SECTION("Testing Colorizer instances") { - #ifdef OPENMS_WINDOWSPLATFORM + //Check that the colorized input contains the original text and DOES NOT contain ASCI codes - //TEST ON Windows!S - stringstream colored_stream; - colored_stream << black(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // #ifdef OPENMS_WINDOWSPLATFORM + // stringstream colored_stream; - colored_stream << red(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << black(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - colored_stream << green(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << red(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - colored_stream << yellow(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << green(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - colored_stream << blue(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << yellow(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - colored_stream << magenta(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << blue(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - colored_stream << cyan(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << magenta(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - colored_stream << white(test_string); - TEST_EQUAL(colored_stream.str(), test_string) - colored_stream.clear(); + // colored_stream << cyan(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); - #elif defined(__linux__) || defined(__OSX__) + // colored_stream << white(test_string); + // TEST_EQUAL(colored_stream.str(), test_string) + // colored_stream.clear(); + + // #elif defined(__linux__) || defined(__OSX__) //Check that the colorized input contains the original text and according ASCI codes - stringstream colored_stream; + stringstream colored_stream; - colored_stream << black(test_string); - TEST_EQUAL(colored_stream.str(), blackANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << black(test_string); + TEST_EQUAL(colored_stream.str(), blackANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << red(test_string); - TEST_EQUAL(colored_stream.str(), redANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << red(test_string); + TEST_EQUAL(colored_stream.str(), redANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << green(test_string); - TEST_EQUAL(colored_stream.str(), greenANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << green(test_string); + TEST_EQUAL(colored_stream.str(), greenANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << yellow(test_string); - TEST_EQUAL(colored_stream.str(), yellowANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << yellow(test_string); + TEST_EQUAL(colored_stream.str(), yellowANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << blue(test_string); - TEST_EQUAL(colored_stream.str(), blueANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << blue(test_string); + TEST_EQUAL(colored_stream.str(), blueANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << magenta(test_string); - TEST_EQUAL(colored_stream.str(), magentaANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << magenta(test_string); + TEST_EQUAL(colored_stream.str(), magentaANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << cyan(test_string); - TEST_EQUAL(colored_stream.str(), cyanANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << cyan(test_string); + TEST_EQUAL(colored_stream.str(), cyanANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - colored_stream << white(test_string); - TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); + colored_stream << white(test_string); + TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) + colored_stream.str(string()); + colored_stream.clear(); - #endif + // #endif } END_SECTION @@ -256,103 +292,100 @@ END_SECTION //testing various inputs for colorizing START_SECTION("Testing Colorizer inputs") { - #ifdef OPENMS_WINDOWSPLATTFORM + // #ifdef OPENMS_WINDOWSPLATTFORM - stringstream colored_stream; - string comparison_string; + // stringstream colored_stream; + // string comparison_string; - //char//////////////////////////////////// - colored_stream << black(test_char); - comparison_string.append(convertToString(test_char)); - TEST_EQUAL(colored_stream.str(), comparison_string) + // //char//////////////////////////////////// + // colored_stream << black(test_char); + // comparison_string.append(convertToString(test_char)); + // TEST_EQUAL(colored_stream.str(), comparison_string) - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - //int///////////////////////////////////// - colored_stream << cyan(test_int); - comparison_string.append(convertToString(test_int)); - TEST_EQUAL(colored_stream.str(), comparison_string) + // //clearing streams + // colored_stream.str(string()); + // colored_stream.clear(); + // comparison_string = ""; + + // //int///////////////////////////////////// + // colored_stream << cyan(test_int); + // comparison_string.append(convertToString(test_int)); + // TEST_EQUAL(colored_stream.str(), comparison_string) - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - //floag/////////////////////////////////// - colored_stream << magenta(test_float); - comparison_string.append(convertToString(test_float)); - TEST_EQUAL(colored_stream.str(), comparison_string) + // //clearing streams + // colored_stream.str(string()); + // colored_stream.clear(); + // comparison_string = ""; + + // //float/////////////////////////////////// + // colored_stream << magenta(test_float); + // comparison_string.append(convertToString(test_float)); + // TEST_EQUAL(colored_stream.str(), comparison_string) - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - #elif defined(__linux__) || defined(__OSX__) - stringstream colored_stream; - string comparison_string; - - //char//////////////////////////////////// - colored_stream << yellow(test_char); - comparison_string.append(yellowANSI); - comparison_string.append(convertToString(test_char)); - comparison_string.append(resetColorANSI); - TEST_EQUAL(colored_stream.str(), comparison_string) - - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - //int/////////////////////////////// - colored_stream << green(test_int); - comparison_string.append(greenANSI); - comparison_string.append(convertToString(test_int)); - comparison_string.append(resetColorANSI); - TEST_EQUAL(colored_stream.str(), comparison_string) - - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - //float/////////////////////////////// - colored_stream << red(test_float); - comparison_string.append(redANSI); - comparison_string.append(convertToString(test_float)); - comparison_string.append(resetColorANSI); - TEST_EQUAL(colored_stream.str(), comparison_string) - - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - #endif + // //clearing streams + // colored_stream.str(string()); + // colored_stream.clear(); + // comparison_string = ""; + + // #elif defined(__linux__) || defined(__OSX__) + stringstream colored_stream; + string comparison_string; + + //char//////////////////////////////////// + colored_stream << yellow(test_char); + comparison_string.append(yellowANSI); + comparison_string.append(convertToString(test_char)); + comparison_string.append(resetColorANSI); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //int/////////////////////////////// + colored_stream << green(test_int); + comparison_string.append(greenANSI); + comparison_string.append(convertToString(test_int)); + comparison_string.append(resetColorANSI); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //float/////////////////////////////// + colored_stream << red(test_float); + comparison_string.append(redANSI); + comparison_string.append(convertToString(test_float)); + comparison_string.append(resetColorANSI); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + // #endif } END_SECTION START_SECTION(Colorizer& operator()()) { + + stringstream test_stream; - #if defined(__linux__) || defined(__OSX__) - - stringstream test_stream; - - test_stream << green() << "green text" << 123 << "!" << " " << reset_color(); - TEST_EQUAL(test_stream.str(),greenANSI+"green text123! "+resetColorANSI) - test_stream.str(string()); - test_stream.clear(); + test_stream << green() << "green text" << 123 << "!" << " " << reset_color(); + TEST_EQUAL(test_stream.str(),greenANSI+"green text123! "+resetColorANSI) + test_stream.str(string()); + test_stream.clear(); - test_stream << reset_color() << "default text" << magenta() << "magenta text"; - TEST_EQUAL(test_stream.str(),resetColorANSI+"default text"+magentaANSI+"magenta text") - test_stream.str(string()); - test_stream.clear(); + test_stream << reset_color() << "default text" << magenta() << "magenta text"; + TEST_EQUAL(test_stream.str(),resetColorANSI+"default text"+magentaANSI+"magenta text") + test_stream.str(string()); + test_stream.clear(); - #endif } END_SECTION From 49b0d2f47adfd1b1e7b86573e22c526168f66b9b Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 25 May 2022 04:09:49 +0200 Subject: [PATCH 09/31] Improved public methods tests --- .../openms/source/Colorizer_test.cpp | 144 +++--------------- 1 file changed, 19 insertions(+), 125 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 593a2cce808..562db89e512 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -48,18 +48,8 @@ using namespace OpenMS; using namespace std; -/* TO-DO 1 -+ Check if string inputs are unchanged, and ANSI codes inside/not inside -- Windows test - try on Windows -+ Test every color function for all variable sets -+/- Test every other public function -+ mention "NOT TESTABLE" methods in sections -+!!!ALL changes requested after last push - - //ANSI fuer windows leer definieren - ifdefs wegmachen -*/ - /* TO-DO 2 +- getReset testable? Why is output always 1? - UPDATE OpenMS Version (consult) and Colorizer version - Test background color change test case - DEFINE functionality first - ConsoleUtils Erweiterung @@ -80,8 +70,7 @@ START_TEST(Colorizer(),"$Id$") char test_char = 'a'; int test_int = 15; float test_float = 2094.5892; -// string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; -string test_string = "ABCDE"; +string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; //ANSI codes @@ -111,43 +100,6 @@ string test_string = "ABCDE"; #endif - - -/* -//////Functions to replace manual creation of stringstreams -//////and comparison strings for TEST_EQUAL for coloured outputs for Linux -////// -//////UNFINISHED!!! - -template -stringstream colorStream(T const& testVariable, Colorizer) -//saves a colored output of an instance of Colorizer into a stream -{ - stringstream coloredStream; - stringstream outputStream; - - coloredStream << Colorizer(testVariable); - coloredStream >> outputStream; - - return outputStream; -} - -string createComparisonANSIString(string testVariable,Colorizer){ - //creates a model string with according ANSI codes to be - //compared to stream created by colorStream - - string comparisonString; - comparisonString.append(blackANSI); - comparisonString.append(to_string(tchar)); - //to_string is causing formatting issues with char variables, - // -> improve - comparisonString.append(resetColorANSI); - - return comparisonString; -} - -*/ - START_SECTION(Colorizer::colorStream(ostream& stream) const) { //without text @@ -199,48 +151,27 @@ START_SECTION(Colorizer::resetColor(ostream& stream)) } END_SECTION -START_SECTION("Testing Colorizer instances") +START_SECTION(Colorizer::getDataAsString()) { + stringstream test_stream; + Colorizer c(COLOR::red); - //Check that the colorized input contains the original text and DOES NOT contain ASCI codes - - // #ifdef OPENMS_WINDOWSPLATFORM - // stringstream colored_stream; - - // colored_stream << black(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); - - // colored_stream << red(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); - - // colored_stream << green(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); - - // colored_stream << yellow(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); - - // colored_stream << blue(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); - - // colored_stream << magenta(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); + test_stream << c(test_string); + test_stream << c.getDataAsString(); + TEST_EQUAL(test_stream.str(), redANSI+test_string+resetColorANSI+test_string) +} +END_SECTION - // colored_stream << cyan(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); +START_SECTION(Colorizer::getReset()) +{ + NOT_TESTABLE +} +END_SECTION - // colored_stream << white(test_string); - // TEST_EQUAL(colored_stream.str(), test_string) - // colored_stream.clear(); +START_SECTION("Testing Colorizer instances") +{ - // #elif defined(__linux__) || defined(__OSX__) - //Check that the colorized input contains the original text and according ASCI codes + //Check that the colorized input contains the original text and according ASCI codes stringstream colored_stream; @@ -292,42 +223,6 @@ END_SECTION //testing various inputs for colorizing START_SECTION("Testing Colorizer inputs") { - // #ifdef OPENMS_WINDOWSPLATTFORM - - // stringstream colored_stream; - // string comparison_string; - - // //char//////////////////////////////////// - // colored_stream << black(test_char); - // comparison_string.append(convertToString(test_char)); - // TEST_EQUAL(colored_stream.str(), comparison_string) - - // //clearing streams - // colored_stream.str(string()); - // colored_stream.clear(); - // comparison_string = ""; - - // //int///////////////////////////////////// - // colored_stream << cyan(test_int); - // comparison_string.append(convertToString(test_int)); - // TEST_EQUAL(colored_stream.str(), comparison_string) - - // //clearing streams - // colored_stream.str(string()); - // colored_stream.clear(); - // comparison_string = ""; - - // //float/////////////////////////////////// - // colored_stream << magenta(test_float); - // comparison_string.append(convertToString(test_float)); - // TEST_EQUAL(colored_stream.str(), comparison_string) - - // //clearing streams - // colored_stream.str(string()); - // colored_stream.clear(); - // comparison_string = ""; - - // #elif defined(__linux__) || defined(__OSX__) stringstream colored_stream; string comparison_string; @@ -366,14 +261,13 @@ START_SECTION("Testing Colorizer inputs") colored_stream.str(string()); colored_stream.clear(); comparison_string = ""; - // #endif } END_SECTION START_SECTION(Colorizer& operator()()) { - + stringstream test_stream; test_stream << green() << "green text" << 123 << "!" << " " << reset_color(); From 3c9f7d7a6d9510785c2c92552ef5a2e3bc694828 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Thu, 9 Jun 2022 16:47:11 +0200 Subject: [PATCH 10/31] possibly fixed ConsoleUtils.cpp compilation issue --- .../OpenMS/APPLICATIONS/ConsoleUtils.h | 137 ++++++- .../source/APPLICATIONS/ConsoleUtils.cpp | 382 +++++++++++++++++- src/openms/source/APPLICATIONS/TOPPBase.cpp | 2 +- 3 files changed, 498 insertions(+), 23 deletions(-) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index d9f83cc9265..8d0a7827e2e 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -35,46 +35,169 @@ #pragma once #include +#include +#include +#include namespace OpenMS { class OPENMS_DLLAPI ConsoleUtils { -public: + public: /// make a string console friendly /// by breaking it into multiple lines according to the console width /// The 'indentation' gives the number of spaces which is prepended beginning at the second (!) /// line, so one gets a left aligned block which has some space to the left. /// An indentation of 0 results in the native console's default behaviour: just break at the end of /// its width and start a new line. - /// but usually one wants nicely intended blocks, which the console does not support - /// 'max_lines' gives the upper limit of lines returned after breaking is finished. + /// but usually one wants nicely indented blocks, which the console does not support + /// 'max_lines' gives the upper limit of lines returned after breaking is finished. /// Excess lines are removed and replaced by '...', BUT the last line will be preserved. /// @param input String to be split /// @param indentation Number of spaces to use for lines 2 until last line. /// @param max_lines Limit of output lines (all others are removed) - static String breakString(const String& input, const Size indentation, const Size max_lines); + static OpenMS::StringList breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos = 0); -private: + const int getConsoleSize() + { + return console_width_; + } + + static ConsoleUtils getInstance() + { + return getInstance_(); + } + + +//#ifdef OPENMS_WINDOWSPLATFORM + + /// reset the color of the windows output handle + void resetCoutColor(); + /// reset the color of the windows error handle + void resetCerrColor(); + + /// reset the color of both output streams + void resetConsoleColor(); + + void setCoutColor(int color_code); + + void setCerrColor(int color_code); + +//#endif + + + + +/// Destructor + ~ConsoleUtils(); + + private: /// width of console we are currently in (if not determinable, set to 80 as default) int console_width_; /// read console settings for output shaping int readConsoleSize_(); + + static ConsoleUtils& getInstance_(); + /// returns a console friendly version of input - String breakString_(const String& input, const Size indentation, const Size max_lines); + OpenMS::StringList breakString_(const String& input, const Size indentation, const Size max_lines, const Size curser_pos); /// C'tor ConsoleUtils(); /// Copy C'tor - ConsoleUtils(const ConsoleUtils &); + ConsoleUtils(const ConsoleUtils&); + + // /// Destructor + // ~ConsoleUtils(); /// Assignment operator + // void operator=(ConsoleUtils const& other); + // void operator=(const ConsoleUtils& other); void operator=(ConsoleUtils const&); + //added "other" here + +//#ifdef OPENMS_WINDOWSPLATFORM + + /// Default console color for output stream + int default_cout_; + + /// Default console color for error stream + int default_cerr_; + + +//#endif + }; + + + + + + + + + + + + + + + + + + class IndentedStringStream + { + public: + IndentedStringStream(std::ostream& stream, const Size indentation, const Size max_lines) : stream_(&stream), indentation_(indentation), max_lines_(max_lines), current_column_pos_(0) + { + max_line_width_ = ConsoleUtils::getInstance().getConsoleSize(); + } + + + template + IndentedStringStream& operator<<(const T& data) + { + + std::stringstream s; + s << data; + const std::string& string_to_print = s.str(); + + //wie viele zeilen sind es / viel viele zeichen in letrzter zeile + + OpenMS::StringList result = ConsoleUtils::breakString(string_to_print,indentation_,max_lines_,current_column_pos_); + + if (result.size()>=2) + { // we completed the previous line, so start counting from the latest incomplete line + current_column_pos_ = result.back().size(); + } + else + { // only one line; simply forward the column position + current_column_pos_ += result.back().size(); + } + + + + *stream_ << ListUtils::concatenate(result, '\n'); + + return *this; + + } +///741 = offset +///763 = indent + + IndentedStringStream& operator<<(Colorizer& colorizer); + + private: + std::ostream* stream_; + int indentation_; + int max_lines_; + int max_line_width_; + int current_column_pos_; }; + } // namespace OpenMS diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index cf5e69335ce..34b58c221c9 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -33,11 +33,10 @@ // -------------------------------------------------------------------------- #include - #include #include -#ifdef OPENMS_WINDOWSPLATFORM +#ifdef OPENMS_WINDOWSPLATTFORM #include // for GetConsoleScreenBufferInfo() #undef min #undef max @@ -54,16 +53,44 @@ namespace OpenMS { // initialize the console width readConsoleSize_(); + + //if operating OS is Windows: save default output color for cour and cerr +#ifdef OPENMS_WINDOWSPLATTFORM + CONSOLE_SCREEN_BUFFER_INFO Info; + HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE handle_stderr = GetStdHandle(STD_ERROR_HANDLE); + + GetConsoleScreenBufferInfo(handle_stdout, &Info); + + default_cout_ = Info.wAttributes; + + GetConsoleScreenBufferInfo(handle_stderr, &Info); + + default_cerr_ = Info.wAttributes; + + /// get and remember 2 default colors +#endif } - ConsoleUtils::ConsoleUtils(ConsoleUtils const& other) : - console_width_(other.console_width_) + ConsoleUtils::~ConsoleUtils() { +#ifdef OPENMS_WINDOWSPLATTFORM + resetConsoleColor(); +#endif } - void ConsoleUtils::operator=(const ConsoleUtils& other) + ConsoleUtils::ConsoleUtils(ConsoleUtils const& other) = default; + void ConsoleUtils::operator=(const ConsoleUtils& other) {}; + // void ConsoleUtils::operator=(const ConsoleUtils& other) = default; + + // void ConsoleUtils::operator=(const ConsoleUtils& other); + + OpenMS::StringList ConsoleUtils::breakString(const String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos) { - console_width_ = other.console_width_; + return getInstance().breakString_(input, indentation, max_lines, curser_pos); } int ConsoleUtils::readConsoleSize_() @@ -93,7 +120,7 @@ namespace OpenMS OPENMS_LOG_DEBUG << "output shaping: COLUMNS env does not exist!" << std::endl; } -#ifdef OPENMS_WINDOWSPLATFORM +#ifdef OPENMS_WINDOWSPLATTFORM HANDLE hOut; CONSOLE_SCREEN_BUFFER_INFO SBInfo; hOut = GetStdHandle(STD_OUTPUT_HANDLE); @@ -111,9 +138,10 @@ namespace OpenMS String output(buff); StringList components; output.split(' ', components); - if (components.size() == 2) + if (components.size() == 2){ console_width_ = components[1].toInt(); } + } else { // TODO: throw ? @@ -140,27 +168,42 @@ namespace OpenMS } return console_width_; + } - String ConsoleUtils::breakString(const String& input, const Size indentation, const Size max_lines) + ConsoleUtils& ConsoleUtils::getInstance_() { static ConsoleUtils instance; - return instance.breakString_(input, indentation, max_lines); + return instance; } - String ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines) +//erweitern, mit aktueller curser position +// rückgabe: vector von strings +// (OpenMS::StringList) + OpenMS::StringList ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines, const Size curser_pos) { - + + //OpenMS::StringList list; + //list.clear(); // get the line length - const Int line_len = ConsoleUtils::readConsoleSize_(); + Int line_len = ConsoleUtils::readConsoleSize_(); StringList result; Size short_line_len = line_len - indentation; + + /// hier wird linelen - neuer param curpos + line_len -= curser_pos; + + + if (short_line_len < 1) { std::cerr << "INTERNAL ERROR: cannot split lines into empty strings! see breakString_()"; - return input; + result.push_back(input); + return result; } + + for (Size i = 0; i < input.size(); ) { String line = input.substr(i, result.empty() ? line_len : short_line_len); // first line has full length @@ -206,7 +249,316 @@ namespace OpenMS } // remove last " " from last line to prevent automatic line break //if (result.size()>0 && result[result.size()-1].hasSuffix(" ")) result[result.size()-1] = result[result.size()-1].substr(0,result[result.size()-1].size()-1); - return ListUtils::concatenate(result, "\n"); + + return result; + } + +#ifdef OPENMS_WINDOWSPLATTFORM + void ConsoleUtils::resetConsoleColor() + { + setCoutColor(default_cout_); + setCerrColor(default_cerr_); + } + + void setCoutColor(int color_code) + { + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_code); } + void setCerrColor(int color_code) + { + SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), color_code); + } + +#endif + + + +IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) +{ + colorizer.colorStream(*stream_); + this->operator<<(colorizer.getDataAsString()); + + if(colorizer.getReset()) + { + colorizer.resetColor(*stream_); + + } + + return *this; +} + + + + + } + +//////////////////////////////////////////// + +//////////////////////////////////////////// + + +// #include + +// #include +// #include + +// #ifdef OPENMS_WINDOWSPLATTFORM +// #include // for GetConsoleScreenBufferInfo() +// #undef min +// #undef max +// #endif + +// #include +// #include + +// namespace OpenMS +// { + +// ConsoleUtils::ConsoleUtils() : +// console_width_(80) +// { +// // initialize the console width +// readConsoleSize_(); + +// //if operating OS is Windows: save default output color for cour and cerr +// #ifdef OPENMS_WINDOWSPLATTFORM +// CONSOLE_SCREEN_BUFFER_INFO Info; +// HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE); +// HANDLE handle_stderr = GetStdHandle(STD_ERROR_HANDLE); + +// GetConsoleScreenBufferInfo(handle_stdout, &Info); + +// default_cout_ = Info.wAttributes; + +// GetConsoleScreenBufferInfo(handle_stderr, &Info); + +// default_cerr_ = Info.wAttributes; + +// /// get and remember 2 default colors +// #endif +// } + +// ConsoleUtils::~ConsoleUtils() +// { +// #ifdef OPENMS_WINDOWSPLATTFORM +// resetConsoleColor(); +// #endif +// } + +// ConsoleUtils::ConsoleUtils(ConsoleUtils const& other) = default; +// void ConsoleUtils::operator=(const ConsoleUtils& other) = default; +// } + +// OpenMS::StringList ConsoleUtils::breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos) +// { +// return getInstance().breakString_(input, indentation, max_lines, curser_pos); +// } + +// int ConsoleUtils::readConsoleSize_() +// { +// // avoid calling this function more than once +// static bool been_here = false; +// if (been_here) +// { +// return console_width_; +// } + +// been_here = true; + +// // determine column width of current console +// try +// { +// console_width_ = -1; +// char* p_env; +// p_env = getenv("COLUMNS"); +// if (p_env != nullptr) +// { +// console_width_ = String(p_env).toInt(); +// } +// else +// { +// { +// OPENMS_LOG_DEBUG << "output shaping: COLUMNS env does not exist!" << std::endl; +// } + +// #ifdef OPENMS_WINDOWSPLATTFORM +// HANDLE hOut; +// CONSOLE_SCREEN_BUFFER_INFO SBInfo; +// hOut = GetStdHandle(STD_OUTPUT_HANDLE); +// GetConsoleScreenBufferInfo(hOut, &SBInfo); +// console_width_ = SBInfo.dwSize.X; +// #else // Linux / MacOS +// // try "stty size" command +// // don't use QProcess, since stty will not work there +// FILE* fp = popen("stty size", "r"); +// if (fp != nullptr) +// { +// char buff[100]; +// if (fgets(buff, sizeof(buff), fp) != nullptr) +// { +// String output(buff); +// StringList components; +// output.split(' ', components); +// if (components.size() == 2) +// console_width_ = components[1].toInt(); +// } +// else +// { +// // TODO: throw ? +// OPENMS_LOG_DEBUG << "Could not read 100 characters from file." << std::endl; +// } +// pclose(fp); //moved pclose outside of fgets condition - cant move it out of not nullpointer condition because pclose(null pointer is undefined behaviour) +// } +// else +// { +// OPENMS_LOG_DEBUG << "output shaping: stty size command failed." << std::endl; +// } +// #endif +// } +// --console_width_; // to add the \n at the end of each line without forcing another line break on windows +// } +// catch (...) +// { +// } +// // if console_width_ is still -1, we do not use command line reshaping +// if (console_width_ < 10) +// { +// OPENMS_LOG_DEBUG << "Console width could not be determined or is smaller than 10. Not using output shaping!" << std::endl; +// console_width_ = std::numeric_limits::max(); +// } + +// return console_width_; + + +// ConsoleUtils& ConsoleUtils::getInstance_() +// { +// static ConsoleUtils instance; +// return instance; +// } + +// //erweitern, mit aktueller curser position +// // rückgabe: vector von strings +// // (OpenMS::StringList) +// OpenMS::StringList ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines, const Size curser_pos) +// { + +// //OpenMS::StringList list; +// //list.clear(); +// // get the line length +// Int line_len = ConsoleUtils::readConsoleSize_(); + +// StringList result; +// Size short_line_len = line_len - indentation; + +// /// hier wird linelen - neuer param curpos +// line_len -= curser_pos; + + + +// if (short_line_len < 1) +// { +// std::cerr << "INTERNAL ERROR: cannot split lines into empty strings! see breakString_()"; +// result.push_back(input); +// return result; +// } + + +// for (Size i = 0; i < input.size(); ) +// { +// String line = input.substr(i, result.empty() ? line_len : short_line_len); // first line has full length +// Size advance_size = line.size(); +// if (line.hasSubstring("\n")) +// { +// advance_size = 0; +// while (line.hasPrefix("\n")) +// { +// line = line.substr(1); +// ++advance_size; +// } // advance by # of \n's +// if (line.hasSubstring("\n")) +// { +// line = line.prefix('\n'); +// } +// advance_size += line.size(); // + actual chars +// } + +// // check if we are using the full length and split a word at the same time +// // cut a little earlier in that case for nicer looks +// if (line.size() == (result.empty() ? line_len : short_line_len) && short_line_len > 8 && line.rfind(' ') != String::npos) +// { +// String last_word = line.suffix(' '); +// if (last_word.length() < 4) +// { // shorten by last word (will move to the next line) +// line = line.prefix(line.size() - last_word.length()); +// advance_size -= last_word.size(); // + actual chars +// } +// } + +// i += advance_size; +// String s_intend = (result.empty() ? "" : String(indentation, ' ')); // first line no indentation +// String r = s_intend + (result.empty() ? line : line.trim()); // intended lines get trimmed +// result.push_back(r); //(r.fillRight(' ', (UInt) line_len)); +// } +// if (result.size() > max_lines) // remove lines from end if we get too many (but leave the last one)... +// { +// String last = result.back(); +// result.erase(result.begin() + max_lines - 2, result.end()); +// result.push_back((String(indentation, ' ') + String("..."))); //.fillRight(' ',(UInt) line_len)); +// result.push_back(last); +// } +// // remove last " " from last line to prevent automatic line break +// //if (result.size()>0 && result[result.size()-1].hasSuffix(" ")) result[result.size()-1] = result[result.size()-1].substr(0,result[result.size()-1].size()-1); + +// return result; + + +// #ifdef OPENMS_WINDOWSPLATTFORM +// void ConsoleUtils::resetConsoleColor() +// { +// setCoutColor(default_cout_); +// setCerrColor(default_cerr_); +// } + +// void setCoutColor(int color_code) +// { +// SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_code); +// } + +// void setCerrColor(int color_code) +// { +// SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), color_code); +// } + +// #endif + + + +// IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) +// { +// colorizer.colorStream(*stream_); +// this->operator<<(colorizer.getDataAsString()); + +// if(colorizer.getReset()) +// { +// colorizer.resetColor(*stream_); + +// } + +// return *this; +// } + +// } +// } + + + + + + + + + + + diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 6adda1ff6e2..5c4e174023d 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -561,7 +561,7 @@ namespace OpenMS // print warning regarding not shown parameters if (!subsections_.empty() && !verbose) - cerr << ConsoleUtils::breakString("This tool has algorithm parameters that are not shown here! Please check the ini file for a detailed description or use the --helphelp option.", 0, 10) + "\n\n"; + cerr << ConsoleUtils::breakString("This tool has algorithm parameters that are not shown here! Please check the ini file for a detailed description or use the --helphelp option.", 0, 10) << "\n\n"; if (verbose) { From f65e69c643a77f54841f4ef6e7e3e71f5c99ce1a Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 15 Jun 2022 22:22:52 +0200 Subject: [PATCH 11/31] Implemented supressed coloring for Linus when output is fed to a file. There's a problem that now the colorizer testclass doesn't work as is should, working around this --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 6 ++ src/openms/source/CONCEPT/Colorizer.cpp | 12 ++- .../openms/source/Colorizer_test.cpp | 33 ++++++++- .../openms/source/ConsoleUtils_test.cpp | 74 +++++++++++++++++-- 4 files changed, 118 insertions(+), 7 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 8d6ed60101f..eb2f58a4e1b 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -40,6 +40,12 @@ #include #include #include + +////// +#include +#include + +///// // #include diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index e6e0c150944..ea51b9c4e5a 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -73,6 +73,7 @@ namespace OpenMS { #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) + if (&std::cout == &stream) { // set color of output @@ -87,7 +88,16 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) // write coloring escape codes into the string - stream << this->colors_[this->color_]; + + if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + { + stream << this->colors_[this->color_]; + } + + // Problem - in testfiles, STDOUT is always 0 because + //console output is supressed. It should be made an + //exception for colorizer class + #endif } diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 562db89e512..6cc6d1eefb9 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -48,6 +48,8 @@ using namespace OpenMS; using namespace std; + + /* TO-DO 2 - getReset testable? Why is output always 1? - UPDATE OpenMS Version (consult) and Colorizer version @@ -70,7 +72,8 @@ START_TEST(Colorizer(),"$Id$") char test_char = 'a'; int test_int = 15; float test_float = 2094.5892; -string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; +// string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; +string test_string = "ABCDE"; //ANSI codes @@ -283,5 +286,33 @@ START_SECTION(Colorizer& operator()()) } END_SECTION +START_SECTION("See if stream is a tty or a file") +{ + stringstream test_stream; + ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); + + cout << 1; + test_stream << cyan("SOMECYANTEXT"); + TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) + + TEST_EQUAL(isatty(STDIN_FILENO), 1); //is a tty + TEST_EQUAL(isatty(STDOUT_FILENO), 0); //is a tty + TEST_EQUAL(isatty(STDERR_FILENO), 0); //is a tty + + freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", "w", stdout); + cout< + //outputs are written somewhere else and checked, so STDOUT is always 0 + //teste is elsewhere -> make a new file and use colorizer there, or maybe + //use console_utils/colorizer output to generate isatty values in different places +} +END_SECTION + END_TEST diff --git a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp index e334044b197..d44fef25a74 100644 --- a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp +++ b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp @@ -37,7 +37,13 @@ /////////////////////////// #include +#include /////////////////////////// +#include +#include +#include +#include +#include using namespace OpenMS; using namespace std; @@ -60,16 +66,74 @@ START_SECTION(~ConsoleUtils()) } END_SECTION -START_SECTION((static String breakString(const String &input, const Size indentation, const Size max_lines))) +START_SECTION(const int getConsoleSize()) { - // we cannot predict which shape the broken string will have, so testing is rather limited - String test_string = "This is a test string which should be broken up into multiple lines."; - String broken_string = ConsoleUtils::breakString(test_string, 0, 10); + NOT_TESTABLE +} +END_SECTION + +START_SECTION(ConsoleUtils getInstance()) +{ + NOT_TESTABLE +} +END_SECTION + +START_SECTION(void resetCoutColor()) +{ + NOT_TESTABLE +} +END_SECTION - TEST_EQUAL(test_string.length() <= broken_string.length(), true) +START_SECTION(void resetCerrColor()) +{ + NOT_TESTABLE } END_SECTION +START_SECTION(void resetConsoleColor()) +{ + NOT_TESTABLE +} +END_SECTION + +START_SECTION(void setCoutColor()) +{ + NOT_TESTABLE +} +END_SECTION + +START_SECTION(void setCerrColor()) +{ + NOT_TESTABLE +} +END_SECTION + +START_SECTION(OpenMS::StringList breakString_(const String& input, const Size indentation, const Size max_lines, const Size curser_pos)) +{ + NOT_TESTABLE +} +END_SECTION + + + + +// START_SECTION((static String breakString(const String &input, const Size indentation, const Size max_lines))) +// { +// // we cannot predict which shape the broken string will have, so testing is rather limited +// String test_string = "This is a test string which should be broken up into multiple lines."; +// String broken_string = ConsoleUtils::breakString(test_string, 0, 10); + +// TEST_EQUAL(test_string.length() <= broken_string.length(), true) + +// /* +// error: conversion from ‘OpenMS::StringList’ {aka ‘std::vector’} to non-scalar type ‘OpenMS::String’ requested +// 67 | String broken_string = ConsoleUtils::breakString(test_string, 0, 10); + +// */ +// } +// END_SECTION + + ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// From 8db4024f9337984d184a68857d3b470fb3e9a2fc Mon Sep 17 00:00:00 2001 From: tetak94 Date: Fri, 17 Jun 2022 21:38:11 +0200 Subject: [PATCH 12/31] updated consoleutils testclass, still functionality needed --- .../OpenMS/APPLICATIONS/ConsoleUtils.h | 42 +++++--- .../source/APPLICATIONS/ConsoleUtils.cpp | 15 ++- src/openms/source/CONCEPT/Colorizer.cpp | 14 ++- .../openms/source/Colorizer_test.cpp | 4 +- .../openms/source/ConsoleUtils_test.cpp | 99 ++++++++++--------- 5 files changed, 102 insertions(+), 72 deletions(-) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index 8d0a7827e2e..c8818e8790a 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -57,7 +57,19 @@ namespace OpenMS /// @param input String to be split /// @param indentation Number of spaces to use for lines 2 until last line. /// @param max_lines Limit of output lines (all others are removed) - static OpenMS::StringList breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos = 0); + /// C'tor + ConsoleUtils(); + + /// Copy C'tor + ConsoleUtils(const ConsoleUtils&); + + /// Destructor + ~ConsoleUtils(); + + static OpenMS::StringList breakString(const String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos = 0); const int getConsoleSize() { @@ -72,10 +84,10 @@ namespace OpenMS //#ifdef OPENMS_WINDOWSPLATFORM - /// reset the color of the windows output handle - void resetCoutColor(); - /// reset the color of the windows error handle - void resetCerrColor(); + // /// reset the color of the windows output handle + // void resetCoutColor(); + // /// reset the color of the windows error handle + // void resetCerrColor(); /// reset the color of both output streams void resetConsoleColor(); @@ -84,16 +96,15 @@ namespace OpenMS void setCerrColor(int color_code); -//#endif + int getCoutColor(); + int getCerrColor(); - - -/// Destructor - ~ConsoleUtils(); +//#endif private: - /// width of console we are currently in (if not determinable, set to 80 as default) + /// width of console we are currently in + ///(if not determinable, set to 80 as default) int console_width_; /// read console settings for output shaping @@ -103,13 +114,12 @@ namespace OpenMS static ConsoleUtils& getInstance_(); /// returns a console friendly version of input - OpenMS::StringList breakString_(const String& input, const Size indentation, const Size max_lines, const Size curser_pos); + OpenMS::StringList breakString_(const String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos); - /// C'tor - ConsoleUtils(); - /// Copy C'tor - ConsoleUtils(const ConsoleUtils&); // /// Destructor // ~ConsoleUtils(); diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index 34b58c221c9..17576e5321c 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -180,7 +180,10 @@ namespace OpenMS //erweitern, mit aktueller curser position // rückgabe: vector von strings // (OpenMS::StringList) - OpenMS::StringList ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines, const Size curser_pos) + OpenMS::StringList ConsoleUtils::breakString_(const OpenMS::String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos) { //OpenMS::StringList list; @@ -270,6 +273,16 @@ namespace OpenMS SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), color_code); } +int getCoutColor() +{ + return default_cout_; +} + +int getCerrColor() +{ + return default_cerr_; +} + #endif diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index ea51b9c4e5a..888ae5de936 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -89,10 +89,11 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) // write coloring escape codes into the string - if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) - { - stream << this->colors_[this->color_]; - } + // if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + // { + // stream << this->colors_[this->color_]; + // } + stream << this->colors_[this->color_]; // Problem - in testfiles, STDOUT is always 0 because //console output is supressed. It should be made an @@ -119,6 +120,11 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) + + // if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + // { + // stream << this->colors_[8]; + // } stream << this->colors_[8]; #endif } diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 6cc6d1eefb9..4dd8123f585 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -292,7 +292,7 @@ START_SECTION("See if stream is a tty or a file") ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); cout << 1; - test_stream << cyan("SOMECYANTEXT"); + test_stream << cyan("SOMECYANTEXT1"); TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) TEST_EQUAL(isatty(STDIN_FILENO), 1); //is a tty @@ -300,7 +300,7 @@ START_SECTION("See if stream is a tty or a file") TEST_EQUAL(isatty(STDERR_FILENO), 0); //is a tty freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", "w", stdout); - cout<’} to non-scalar type ‘OpenMS::String’ requested + 67 | String broken_string = ConsoleUtils::breakString(test_string, 0, 10); + + */ } END_SECTION - -// START_SECTION((static String breakString(const String &input, const Size indentation, const Size max_lines))) -// { -// // we cannot predict which shape the broken string will have, so testing is rather limited -// String test_string = "This is a test string which should be broken up into multiple lines."; -// String broken_string = ConsoleUtils::breakString(test_string, 0, 10); - -// TEST_EQUAL(test_string.length() <= broken_string.length(), true) - -// /* -// error: conversion from ‘OpenMS::StringList’ {aka ‘std::vector’} to non-scalar type ‘OpenMS::String’ requested -// 67 | String broken_string = ConsoleUtils::breakString(test_string, 0, 10); - -// */ -// } -// END_SECTION - - - ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// END_TEST From 5a63fa3e5a7d1effd36a23826ee15109827664d0 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Sun, 19 Jun 2022 17:38:55 +0200 Subject: [PATCH 13/31] updated STDOUT exclusion functionality --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 1 + .../source/APPLICATIONS/ConsoleUtils.cpp | 19 ++++++++---- src/openms/source/APPLICATIONS/TOPPBase.cpp | 3 +- src/openms/source/CONCEPT/Colorizer.cpp | 31 ++++++++++++------- .../openms/source/Colorizer_test.cpp | 4 +-- .../openms/source/ConsoleUtils_test.cpp | 16 +++++----- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index eb2f58a4e1b..07db3ed17b0 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -45,6 +45,7 @@ #include #include + ///// // #include diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index 17576e5321c..92cd8e08c34 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -90,7 +90,8 @@ namespace OpenMS const Size max_lines, const Size curser_pos) { - return getInstance().breakString_(input, indentation, max_lines, curser_pos); + return getInstance().breakString_(input, indentation, + max_lines, curser_pos); } int ConsoleUtils::readConsoleSize_() @@ -209,7 +210,8 @@ namespace OpenMS for (Size i = 0; i < input.size(); ) { - String line = input.substr(i, result.empty() ? line_len : short_line_len); // first line has full length + String line = input.substr(i, result.empty() ? line_len : short_line_len); + // first line has full length Size advance_size = line.size(); if (line.hasSubstring("\n")) { @@ -239,17 +241,22 @@ namespace OpenMS } i += advance_size; - String s_intend = (result.empty() ? "" : String(indentation, ' ')); // first line no indentation - String r = s_intend + (result.empty() ? line : line.trim()); // intended lines get trimmed + String s_intend = (result.empty() ? "" : String(indentation, ' ')); + // first line no indentation + String r = s_intend + (result.empty() ? line : line.trim()); + // intended lines get trimmed result.push_back(r); //(r.fillRight(' ', (UInt) line_len)); } - if (result.size() > max_lines) // remove lines from end if we get too many (but leave the last one)... + if (result.size() > max_lines) + // remove lines from end if we get too many (but leave the last one)... { String last = result.back(); result.erase(result.begin() + max_lines - 2, result.end()); - result.push_back((String(indentation, ' ') + String("..."))); //.fillRight(' ',(UInt) line_len)); + result.push_back((String(indentation, ' ') + String("..."))); + //.fillRight(' ',(UInt) line_len)); result.push_back(last); } + // remove last " " from last line to prevent automatic line break //if (result.size()>0 && result[result.size()-1].hasSuffix(" ")) result[result.size()-1] = result[result.size()-1].substr(0,result[result.size()-1].size()-1); diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 5c4e174023d..0dd4fe377a8 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -560,8 +560,9 @@ namespace OpenMS << "\n"; // print warning regarding not shown parameters - if (!subsections_.empty() && !verbose) + if (!subsections_.empty() && !verbose){ cerr << ConsoleUtils::breakString("This tool has algorithm parameters that are not shown here! Please check the ini file for a detailed description or use the --helphelp option.", 0, 10) << "\n\n"; + } if (verbose) { diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 888ae5de936..806fc5b2d3f 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -41,6 +41,8 @@ // include in project #include +#define COLORIZER_TEST + @@ -89,11 +91,14 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) // write coloring escape codes into the string - // if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) - // { - // stream << this->colors_[this->color_]; - // } - stream << this->colors_[this->color_]; + #if not defined(COLORIZER_TEST) + if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + { + stream << this->colors_[this->color_]; + } + #else + stream << this->colors_[this->color_]; + #endif // Problem - in testfiles, STDOUT is always 0 because //console output is supressed. It should be made an @@ -117,15 +122,19 @@ namespace OpenMS ConsoleUtils::getInstance().resetCerrColor(); } - - + #elif defined(__linux__) || defined(__OSX__) - // if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) - // { - // stream << this->colors_[8]; - // } + #if not defined(COLORIZER_TEST) + //check if the output is being fed to file or console + //supress output of ANSI codes into the file + if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + { + stream << this->colors_[8]; + } + #else stream << this->colors_[8]; + #endif #endif } diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 4dd8123f585..d4f54f192d0 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -48,7 +48,7 @@ using namespace OpenMS; using namespace std; - +// #define COLORIZER_TEST; /* TO-DO 2 - getReset testable? Why is output always 1? @@ -299,7 +299,7 @@ START_SECTION("See if stream is a tty or a file") TEST_EQUAL(isatty(STDOUT_FILENO), 0); //is a tty TEST_EQUAL(isatty(STDERR_FILENO), 0); //is a tty - freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", "w", stdout); + freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/ANSI.txt", "w", stdout); cout<’} to non-scalar type ‘OpenMS::String’ requested From 511e334cdf5fe6bd271b9bda4ea200136dd5abf9 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Sun, 19 Jun 2022 17:43:36 +0200 Subject: [PATCH 14/31] updated --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 07db3ed17b0..880808a46db 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -177,10 +177,7 @@ namespace OpenMS OPENMS_DLLAPI std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col); -} - - - // namespace OpenMS +} // namespace OpenMS // // -------------------------------------------------------------------------- // // OpenMS -- Open-Source Mass Spectrometry From 18aa20d7a9de882ec882f9796914f7058cec36b9 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Sun, 19 Jun 2022 21:03:47 +0200 Subject: [PATCH 15/31] merging protected colorizer and new consoleutils class --- .../OpenMS/APPLICATIONS/ConsoleUtils.h | 50 ++- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 248 ++--------- .../source/APPLICATIONS/ConsoleUtils.cpp | 10 +- src/openms/source/CONCEPT/Colorizer.cpp | 405 ++---------------- .../openms/source/Colorizer_test.cpp | 109 +++-- 5 files changed, 172 insertions(+), 650 deletions(-) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index c8818e8790a..86a48219967 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -142,26 +142,15 @@ namespace OpenMS //#endif }; - - - - - - - - - - - - - - - - class IndentedStringStream { public: - IndentedStringStream(std::ostream& stream, const Size indentation, const Size max_lines) : stream_(&stream), indentation_(indentation), max_lines_(max_lines), current_column_pos_(0) + IndentedStringStream(std::ostream& stream, + const Size indentation, + const Size max_lines) : stream_(&stream), + indentation_(indentation), + max_lines_(max_lines), + current_column_pos_(0) { max_line_width_ = ConsoleUtils::getInstance().getConsoleSize(); } @@ -177,7 +166,10 @@ namespace OpenMS //wie viele zeilen sind es / viel viele zeichen in letrzter zeile - OpenMS::StringList result = ConsoleUtils::breakString(string_to_print,indentation_,max_lines_,current_column_pos_); + OpenMS::StringList result = ConsoleUtils::breakString(string_to_print, + indentation_, + max_lines_, + current_column_pos_); if (result.size()>=2) { // we completed the previous line, so start counting from the latest incomplete line @@ -198,7 +190,7 @@ namespace OpenMS ///741 = offset ///763 = indent - IndentedStringStream& operator<<(Colorizer& colorizer); + IndentedStringStream& operator<<(ColorizerMethods& colorizer); private: std::ostream* stream_; @@ -208,6 +200,26 @@ namespace OpenMS int current_column_pos_; }; +class ColorizerMethods: public Colorizer + { + + public: + + ///Constructor + ColorizerMethods(const Color color); + + /// Default destructor + ~ColorizerMethods(); + + void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} + + void colorStream_(std::ostream& stream) const{this->colorStream(stream);} + + void resetColor_(std::ostream& stream){this->resetColor(stream);} + + std::string getDataAsString_(){return this->getDataAsString();} + }; + } // namespace OpenMS diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 880808a46db..c68a6f11fea 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -28,8 +28,8 @@ // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // -------------------------------------------------------------------------- -// $Maintainer: Moritz Berger, Tetana Krymovska$ -// $Authors: Moritz Berger, Tetana Krymovska$ +// $Maintainer: Chris Bielow, Moritz Berger, Tetana Krymovska$ +// $Authors: Chris Bielow, Moritz Berger, Tetana Krymovska$ // -------------------------------------------------------------------------- #pragma once @@ -44,25 +44,22 @@ ////// #include #include - - ///// -// #include namespace OpenMS { - /// enum COLOR for easier Object initialisation. - enum class COLOR - { - black, - red, - green, - yellow, - blue, - magenta, - cyan, - white, + /// Text colors for console output + enum class Color + { // internal note: the order is important here! See Colorizer::colors_ + BLACK, + RED, + GREEN, + YELLOW, + BLUE, + MAGENTA, + CYAN, + WHITE, RESET, ///< reset the color to the previous (default?) color }; @@ -71,38 +68,24 @@ namespace OpenMS * */ - - class OPENMS_DLLAPI Colorizer { + +friend class ConsoleUtils; + public: /// Constructor - Colorizer(const COLOR color); + Colorizer(const Color color); - /// Copy constructor - // Colorizer(const Colorizer &rhs); + /// Constructor + Colorizer(); - ///Assignment Operator - + // Copy constructor + Colorizer(const Colorizer &rhs); /// Destructor ~Colorizer(); - /// - void outputToStream(std::ostream& o_stream); - - /// - void colorStream(std::ostream& stream) const; - - /// - void resetColor(std::ostream& stream); - - /// - bool getReset(); - - /// - std::string getDataAsString(); - /// insetrion Operator friend std::ostream& operator<<(std::ostream& o_stream, Colorizer& col); @@ -125,8 +108,25 @@ namespace OpenMS return *this; } -private: + /// + Colorizer& reset(); + +protected: + /// + void outputToStream(std::ostream& o_stream); + + /// + void colorStream(std::ostream& stream) const; + + /// + void resetColor(std::ostream& stream); + + /// + std::string getDataAsString(); + + +private: const int color_; /// input in Colorizer object to be colored @@ -160,7 +160,6 @@ namespace OpenMS #endif }; - // declaration of all colorizer object. extern OPENMS_DLLAPI Colorizer black; extern OPENMS_DLLAPI Colorizer red; @@ -170,175 +169,10 @@ namespace OpenMS extern OPENMS_DLLAPI Colorizer magenta; extern OPENMS_DLLAPI Colorizer cyan; extern OPENMS_DLLAPI Colorizer white; - extern OPENMS_DLLAPI Colorizer reset_color; ///< reset the color to default, alias for 'make_default_color' + // extern OPENMS_DLLAPI Colorizer reset_color; ///< reset the color to default, alias for 'make_default_color' //extern /*OPENMS_DLLAPI*/ Colorizer default_color; ///< reset the color to default, alias for 'reset_color' //Stream operator declaration OPENMS_DLLAPI std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col); +} - -} // namespace OpenMS - -// // -------------------------------------------------------------------------- -// // OpenMS -- Open-Source Mass Spectrometry -// // -------------------------------------------------------------------------- -// // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, -// // ETH Zurich, and Freie Universitaet Berlin 2002-2022. -// // -// // This software is released under a three-clause BSD license: -// // * Redistributions of source code must retain the above copyright -// // notice, this list of conditions and the following disclaimer. -// // * Redistributions in binary form must reproduce the above copyright -// // notice, this list of conditions and the following disclaimer in the -// // documentation and/or other materials provided with the distribution. -// // * Neither the name of any author or any participating institution -// // may be used to endorse or promote products derived from this software -// // without specific prior written permission. -// // For a full list of authors, refer to the file AUTHORS. -// // -------------------------------------------------------------------------- -// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING -// // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // -// // -------------------------------------------------------------------------- -// // $Maintainer: Moritz Berger, Tetana Krymovska$ -// // $Authors: Moritz Berger, Tetana Krymovska$ -// // -------------------------------------------------------------------------- - -// #pragma once - -// //#include - -// #include -// #include -// #include -// //#include - - -// namespace OpenMS -// { -// /// enum COLOR for easier Object initialisation. -// enum class COLOR -// { -// black, -// red, -// green, -// yellow, -// blue, -// magenta, -// cyan, -// white, -// RESET, ///< reset the color to the previous (default?) color -// }; - -// /** -// * @brief A class, that provides options for colored output with the "<<" operator for output streams (cout, cerr) -// * -// */ -// class Colorizer -// { -// public: -// /// Constructor -// Colorizer(const COLOR color); - -// /// Copy constructor -// // Colorizer(const Colorizer &rhs); - -// ///Assignment Operator - -// /// Destructor -// ~Colorizer(); - -// /// -// void outputToStream(std::ostream& o_stream); - -// /// -// void colorStream(std::ostream& stream) const; - -// /// -// void resetColor(std::ostream& stream); - -// /// -// bool getReset(); - -// /// -// std::string getDataAsString(); - -// /// insetrion Operator -// friend std::ostream& operator<<(std::ostream& o_stream, Colorizer& col); - -// /// Bracket Operator -// Colorizer& operator()() -// { -// reset_ = false; -// this->input_.str(""); // clear the stream -// return *this; -// } - -// /// Bracket Operator -// template -// Colorizer& operator()(T s) -// { -// this->input_.str(""); // clear the stringstream -// this->input_ << s; // add new data -// reset_ = true; -// return *this; -// } - -// private: - -// const int color_; - -// /// input in Colorizer object to be colored -// std::stringstream input_; - -// /// -// bool reset_ = true; - - -// /** -// * @brief constant string array which saves the Linux color codes. -// * 0=black -// * 1=red -// * 2=green -// * 3=yellow -// * 4=blue -// * 5=magenta -// * 6=cyan -// * 7=white -// * 8=default console color (reset) -// * -// */ -// #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) -// /// -// inline static constexpr std::array colors_ {16, 12, 10, 14, 9, 13, 11, 15, 15}; - -// #elif defined(__linux__) || defined(__OSX__) -// /// -// inline static constexpr std::array colors_ {"\033[30m", "\033[31m", "\033[32m", "\033[33m", "\033[34m", "\033[35m", "\033[36m", "\033[37m", "\033[0m"}; - -// #endif -// }; - - -// // declaration of all colorizer object. -// extern /*OPENMS_DLLAPI*/ Colorizer black; -// extern /*OPENMS_DLLAPI*/ Colorizer red; -// extern /*OPENMS_DLLAPI*/ Colorizer green; -// extern /*OPENMS_DLLAPI*/ Colorizer yellow; -// extern /*OPENMS_DLLAPI*/ Colorizer blue; -// extern /*OPENMS_DLLAPI*/ Colorizer magenta; -// extern /*OPENMS_DLLAPI*/ Colorizer cyan; -// extern /*OPENMS_DLLAPI*/ Colorizer white; -// extern /*OPENMS_DLLAPI*/ Colorizer reset_color; ///< reset the color to default, alias for 'make_default_color' -// //extern /*OPENMS_DLLAPI*/ Colorizer default_color; ///< reset the color to default, alias for 'reset_color' - -// } // namespace OpenMS diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index 92cd8e08c34..5311146ada5 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -294,14 +294,14 @@ int getCerrColor() -IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) +IndentedStringStream& IndentedStringStream::operator<<(ColorizerMethods& colorizer) { - colorizer.colorStream(*stream_); - this->operator<<(colorizer.getDataAsString()); + colorizer.ColorizerMethods::colorStream_(*stream_); + this->operator<<(colorizer.ColorizerMethods::getDataAsString_()); - if(colorizer.getReset()) + if(colorizer.ColorizerMethods::getReset_()) { - colorizer.resetColor(*stream_); + colorizer.ColorizerMethods::resetColor_(*stream_); } diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 806fc5b2d3f..20b361a4f49 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -32,20 +32,7 @@ // $Authors: Moritz Berger, Tetana Krymovska$ // -------------------------------------------------------------------------- - -// include on FU-server (Linux) -// #include - -// include on Windows PC -//#include - -// include in project #include -#define COLORIZER_TEST - - - - #include #ifdef OPENMS_WINDOWSPLATTFORM @@ -53,11 +40,14 @@ #include #endif +#define COLORIZER_TEST + + namespace OpenMS { - // constructor - Colorizer::Colorizer(const COLOR color) : color_((int)color) // color must be in initializer list, because of const keyword + // Constructor + Colorizer::Colorizer(const Color color) : color_((int)color) // color must be in initializer list, because of const keyword { } @@ -67,6 +57,8 @@ namespace OpenMS // if colorizer object is destroyed, set console color back to def col. #if defined(__linux__) || defined(__OSX__) std::cout << colors_[8]; + // std::cout << resetColor(cout); + // std::cerr << resetColor(cerr); #endif } @@ -75,7 +67,6 @@ namespace OpenMS { #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) - if (&std::cout == &stream) { // set color of output @@ -87,11 +78,10 @@ namespace OpenMS ConsoleUtils::getInstance().setCerrColor(colors_[color_]); } - #elif defined(__linux__) || defined(__OSX__) // write coloring escape codes into the string - #if not defined(COLORIZER_TEST) + #if not defined(COLORIZER_TEST) if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { stream << this->colors_[this->color_]; @@ -103,7 +93,6 @@ namespace OpenMS // Problem - in testfiles, STDOUT is always 0 because //console output is supressed. It should be made an //exception for colorizer class - #endif } @@ -113,7 +102,7 @@ namespace OpenMS #ifdef OPENMS_WINDOWSPLATTFORM if (&std::cout == &stream) { - // reset color of output + ///reset color of output ConsoleUtils::getInstance().resetCoutColor(); } else if (&std::cerr == &stream) @@ -122,12 +111,11 @@ namespace OpenMS ConsoleUtils::getInstance().resetCerrColor(); } - #elif defined(__linux__) || defined(__OSX__) - #if not defined(COLORIZER_TEST) - //check if the output is being fed to file or console - //supress output of ANSI codes into the file + #if not defined(COLORIZER_TEST) + //check if the output is being fed to file or console + //supress output of ANSI codes into the file if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { stream << this->colors_[8]; @@ -135,15 +123,10 @@ namespace OpenMS #else stream << this->colors_[8]; #endif + // stream << this->colors_[(int)Color::RESET]; #endif } - /// - bool Colorizer::getReset() - { - return reset_; - } - /// std::string Colorizer::getDataAsString() { @@ -166,6 +149,13 @@ namespace OpenMS } } + /// + Colorizer& Colorizer::reset() + { + this->input_.str(""); + reset_ = true; + return *this; + } // overload the shift operator (<<) std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) @@ -176,351 +166,14 @@ namespace OpenMS } // Objekte des typs colorizer - OpenMS::Colorizer black(COLOR::black); - OpenMS::Colorizer red(COLOR::red); - OpenMS::Colorizer green(COLOR::green); - OpenMS::Colorizer yellow(COLOR::yellow); - OpenMS::Colorizer blue(COLOR::blue); - OpenMS::Colorizer magenta(COLOR::magenta); - OpenMS::Colorizer cyan(COLOR::cyan); - OpenMS::Colorizer white(COLOR::white); - OpenMS::Colorizer reset_color(COLOR::RESET); - // OpenMS::Colorizer reset_color(COLOR::RESET); - + OpenMS::Colorizer black(Color::BLACK); + OpenMS::Colorizer red(Color::RED); + OpenMS::Colorizer green(Color::GREEN); + OpenMS::Colorizer yellow(Color::YELLOW); + OpenMS::Colorizer blue(Color::BLUE); + OpenMS::Colorizer magenta(Color::MAGENTA); + OpenMS::Colorizer cyan(Color::CYAN); + OpenMS::Colorizer white(Color::WHITE); + // OpenMS::Colorizer reset_color(Color::RESET); } // namespace OpenMS - - - -// // -------------------------------------------------------------------------- -// // OpenMS -- Open-Source Mass Spectrometry -// // -------------------------------------------------------------------------- -// // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, -// // ETH Zurich, and Freie Universitaet Berlin 2002-2022. -// // -// // This software is released under a three-clause BSD license: -// // * Redistributions of source code must retain the above copyright -// // notice, this list of conditions and the following disclaimer. -// // * Redistributions in binary form must reproduce the above copyright -// // notice, this list of conditions and the following disclaimer in the -// // documentation and/or other materials provided with the distribution. -// // * Neither the name of any author or any participating institution -// // may be used to endorse or promote products derived from this software -// // without specific prior written permission. -// // For a full list of authors, refer to the file AUTHORS. -// // -------------------------------------------------------------------------- -// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING -// // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// // WHETHER IN CONTRACT, STRICT LIABILITY, OR TcdORT (INCLUDING NEGLIGENCE OR -// // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // -// // -------------------------------------------------------------------------- -// // $Maintainer: Moritz Berger, Tetana Krymovska $ -// // $Authors: Moritz Berger, Tetana Krymovska$ -// // -------------------------------------------------------------------------- - - -// // include on FU-server (Linux) -// // #include - -// // include on Windows PC -// //#include - -// // include in project -// #include - - - -// #include - -// #ifdef OPENMS_WINDOWSPLATTFORM -// #include -// #include -// #endif - -// namespace OpenMS -// { - -// // constructor -// Colorizer::Colorizer(const COLOR color) : color_((int)color) // color must be in initializer list, because of const keyword -// { -// } - -// /// Default destructor -// Colorizer::~Colorizer() -// { -// // if colorizer object is destroyed, set console color back to def col. -// #if defined(__linux__) || defined(__OSX__) -// std::cout << colors_[8]; -// #endif -// } - -// /// -// void Colorizer::colorStream(std::ostream& stream) const -// { -// #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) - -// if (&std::cout == &stream) -// { -// // set color of output -// ConsoleUtils::getInstance().setCoutColor(colors_[color_]); -// } -// else if (&std::cerr == &stream) -// { -// ///set color of error stream -// ConsoleUtils::getInstance().setCerrColor(colors_[color_]); -// } - - -// #elif defined(__linux__) || defined(__OSX__) -// // write coloring escape codes into the string -// stream << this->colors_[this->color_]; -// #endif -// } - -// /// -// void Colorizer::resetColor(std::ostream& stream) -// { -// #ifdef OPENMS_WINDOWSPLATTFORM -// if (&std::cout == &stream) -// { -// // reset color of output -// ConsoleUtils::getInstance().resetCoutColor(); -// } -// else if (&std::cerr == &stream) -// { -// ///reset color of error stream -// ConsoleUtils::getInstance().resetCerrColor(); -// } - - - -// #elif defined(__linux__) || defined(__OSX__) -// stream << this->colors_[8]; -// #endif -// } - -// /// -// bool Colorizer::getReset() -// { -// return reset_; -// } - -// /// -// std::string Colorizer::getDataAsString() -// { -// return input_.str(); -// } - -// // Helper function, to manipulate the output stream in class. -// void Colorizer::outputToStream(std::ostream& o_stream) -// { -// /// color the stream (or console) -// colorStream(o_stream); - -// // paste text -// o_stream << this->input_.str(); - -// // if flag reset is set: reset comand line. else dont reset. -// if (this->reset_) -// { -// resetColor(o_stream); -// } -// } - - -// // overload the shift operator (<<) -// std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) -// { -// // colorize string with color set in the object -// col.outputToStream(o_stream); -// return o_stream; -// } - -// // Objekte des typs colorizer -// OpenMS::Colorizer black(COLOR::black); -// OpenMS::Colorizer red(COLOR::red); -// OpenMS::Colorizer green(COLOR::green); -// OpenMS::Colorizer yellow(COLOR::yellow); -// OpenMS::Colorizer blue(COLOR::blue); -// OpenMS::Colorizer magenta(COLOR::magenta); -// OpenMS::Colorizer cyan(COLOR::cyan); -// OpenMS::Colorizer white(COLOR::white); -// OpenMS::Colorizer reset_color(COLOR::RESET); -// // OpenMS::Colorizer reset_color(COLOR::RESET); - - -// } // namespace OpenMS -// // -------------------------------------------------------------------------- -// // OpenMS -- Open-Source Mass Spectrometry -// // -------------------------------------------------------------------------- -// // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen, -// // ETH Zurich, and Freie Universitaet Berlin 2002-2022. -// // -// // This software is released under a three-clause BSD license: -// // * Redistributions of source code must retain the above copyright -// // notice, this list of conditions and the following disclaimer. -// // * Redistributions in binary form must reproduce the above copyright -// // notice, this list of conditions and the following disclaimer in the -// // documentation and/or other materials provided with the distribution. -// // * Neither the name of any author or any participating institution -// // may be used to endorse or promote products derived from this software -// // without specific prior written permission. -// // For a full list of authors, refer to the file AUTHORS. -// // -------------------------------------------------------------------------- -// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING -// // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// // -// // -------------------------------------------------------------------------- -// // $Maintainer: Moritz Berger, Tetana Krymovska $ -// // $Authors: Moritz Berger, Tetana Krymovska$ -// // -------------------------------------------------------------------------- - - -// // include on FU-server (Linux) -// // #include - -// // include on Windows PC -// //#include - -// // include in project -// #include - - - -// #include - -// #ifdef OPENMS_WINDOWSPLATTFORM -// #include -// #include -// #endif - -// namespace OpenMS -// { - -// // constructor -// Colorizer::Colorizer(const COLOR color) : color_((int)color) // color must be in initializer list, because of const keyword -// { -// } - -// /// Default destructor -// Colorizer::~Colorizer() -// { -// // if colorizer object is destroyed, set console color back to def col. -// #if defined(__linux__) || defined(__OSX__) -// std::cout << colors_[8]; -// #endif -// } - -// /// -// void Colorizer::colorStream(std::ostream& stream) const -// { -// #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) - -// if (&std::cout == &stream) -// { -// // set color of output -// ConsoleUtils::getInstance().setCoutColor(colors_[color_]); -// } -// else if (&std::cerr == &stream) -// { -// ///set color of error stream -// ConsoleUtils::getInstance().setCerrColor(colors_[color_]); -// } - - -// #elif defined(__linux__) || defined(__OSX__) -// // write coloring escape codes into the string -// stream << this->colors_[this->color_]; -// #endif -// } - -// /// -// void Colorizer::resetColor(std::ostream& stream) -// { -// #ifdef OPENMS_WINDOWSPLATTFORM -// if (&std::cout == &stream) -// { -// // reset color of output -// ConsoleUtils::getInstance().resetCoutColor(); -// } -// else if (&std::cerr == &stream) -// { -// ///reset color of error stream -// ConsoleUtils::getInstance().resetCerrColor(); -// } - - - -// #elif defined(__linux__) || defined(__OSX__) -// stream << this->colors_[8]; -// #endif -// } - -// /// -// bool Colorizer::getReset() -// { -// return reset_; -// } - -// /// -// std::string Colorizer::getDataAsString() -// { -// return input_.str(); -// } - -// // Helper function, to manipulate the output stream in class. -// void Colorizer::outputToStream(std::ostream& o_stream) -// { -// /// color the stream (or console) -// colorStream(o_stream); - -// // paste text -// o_stream << this->input_.str(); - -// // if flag reset is set: reset comand line. else dont reset. -// if (this->reset_) -// { -// resetColor(o_stream); -// } -// } - - -// // overload the shift operator (<<) -// std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) -// { -// // colorize string with color set in the object -// col.outputToStream(o_stream); -// return o_stream; -// } - -// // Objekte des typs colorizer -// OpenMS::Colorizer black(COLOR::black); -// OpenMS::Colorizer red(COLOR::red); -// OpenMS::Colorizer green(COLOR::green); -// OpenMS::Colorizer yellow(COLOR::yellow); -// OpenMS::Colorizer blue(COLOR::blue); -// OpenMS::Colorizer magenta(COLOR::magenta); -// OpenMS::Colorizer cyan(COLOR::cyan); -// OpenMS::Colorizer white(COLOR::white); -// OpenMS::Colorizer reset_color(COLOR::RESET); -// // OpenMS::Colorizer reset_color(COLOR::RESET); - - -// } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index d4f54f192d0..2cc85507abb 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -48,14 +48,6 @@ using namespace OpenMS; using namespace std; -// #define COLORIZER_TEST; - -/* TO-DO 2 -- getReset testable? Why is output always 1? -- UPDATE OpenMS Version (consult) and Colorizer version -- Test background color change test case - DEFINE functionality first -- ConsoleUtils Erweiterung -*/ template //convert any input to string @@ -66,14 +58,35 @@ string convertToString ( T var_input ) return ss.str(); } + +class ColorizerMethodsTester: public Colorizer + { + + public: + + ///Constructor + ColorizerMethodsTester(const Color color); + + /// Default destructor + ~ColorizerMethodsTester(); + + void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} + + void colorStream_(std::ostream& stream) const{this->colorStream(stream);} + + void resetColor_(std::ostream& stream){this->resetColor(stream);} + + std::string getDataAsString_(){return this->getDataAsString();} + }; + + START_TEST(Colorizer(),"$Id$") //Test variables char test_char = 'a'; int test_int = 15; float test_float = 2094.5892; -// string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; -string test_string = "ABCDE"; +string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; //ANSI codes @@ -103,13 +116,14 @@ string test_string = "ABCDE"; #endif + START_SECTION(Colorizer::colorStream(ostream& stream) const) { //without text stringstream test_stream; - Colorizer c(COLOR::black); + ColorizerMethodsTester c(Color::BLACK); - c.colorStream(test_stream); + c.colorStream_(test_stream); TEST_EQUAL(test_stream.str(), blackANSI) //with text @@ -117,9 +131,8 @@ START_SECTION(Colorizer::colorStream(ostream& stream) const) test_stream.clear(); test_stream << c(test_string); - c.colorStream(test_stream); + c.colorStream_(test_stream); TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) - } END_SECTION @@ -127,9 +140,9 @@ START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { //without text stringstream test_stream; - Colorizer c(COLOR::cyan); + ColorizerMethodsTester c(Color::CYAN); - c.outputToStream(test_stream); + c.outputToStream_(test_stream); TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) //with text @@ -137,19 +150,18 @@ START_SECTION(Colorizer::outputToStream(ostream& o_stream)) test_stream.clear(); test_stream << c(test_string); - c.outputToStream(test_stream); + c.outputToStream_(test_stream); TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) - } END_SECTION START_SECTION(Colorizer::resetColor(ostream& stream)) { stringstream test_stream; - Colorizer c(COLOR::green); + ColorizerMethodsTester c(Color::GREEN); test_stream << c(test_string); - c.resetColor(test_stream); + c.resetColor_(test_stream); TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) } END_SECTION @@ -157,23 +169,30 @@ END_SECTION START_SECTION(Colorizer::getDataAsString()) { stringstream test_stream; - Colorizer c(COLOR::red); + ColorizerMethodsTester c(Color::RED); test_stream << c(test_string); - test_stream << c.getDataAsString(); + test_stream << c.getDataAsString_(); TEST_EQUAL(test_stream.str(), redANSI+test_string+resetColorANSI+test_string) } END_SECTION -START_SECTION(Colorizer::getReset()) +START_SECTION(Colorizer::reset()) { - NOT_TESTABLE + stringstream test_stream; + test_stream << green() + << "green text" << 89 << "$" << " " + << green.reset() << "default text" << red() << 11 << red.reset() << "A"; + TEST_EQUAL(test_stream.str(),greenANSI + +"green text89$ " + +greenANSI+resetColorANSI + +"default text" + +redANSI+"11"+redANSI+resetColorANSI+"A") } END_SECTION START_SECTION("Testing Colorizer instances") { - //Check that the colorized input contains the original text and according ASCI codes stringstream colored_stream; @@ -217,9 +236,6 @@ START_SECTION("Testing Colorizer instances") TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) colored_stream.str(string()); colored_stream.clear(); - - // #endif - } END_SECTION @@ -264,36 +280,42 @@ START_SECTION("Testing Colorizer inputs") colored_stream.str(string()); colored_stream.clear(); comparison_string = ""; - } END_SECTION START_SECTION(Colorizer& operator()()) { - stringstream test_stream; - - test_stream << green() << "green text" << 123 << "!" << " " << reset_color(); - TEST_EQUAL(test_stream.str(),greenANSI+"green text123! "+resetColorANSI) - test_stream.str(string()); - test_stream.clear(); - - test_stream << reset_color() << "default text" << magenta() << "magenta text"; - TEST_EQUAL(test_stream.str(),resetColorANSI+"default text"+magentaANSI+"magenta text") - test_stream.str(string()); - test_stream.clear(); + test_stream << green() + << "green text" + << 123 << "!" + << " " + << magenta() + << "magenta text" + << green.reset() + << "default text" + << magenta.reset() + << "default text"; + TEST_EQUAL(test_stream.str(),greenANSI + +"green text123! " + +magentaANSI + +"magenta text" + +greenANSI+resetColorANSI + +"default text" + +magentaANSI+resetColorANSI + +"default text") } END_SECTION START_SECTION("See if stream is a tty or a file") { - stringstream test_stream; - ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); + stringstream test_stream; + ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); cout << 1; test_stream << cyan("SOMECYANTEXT1"); - TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) + TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) TEST_EQUAL(isatty(STDIN_FILENO), 1); //is a tty TEST_EQUAL(isatty(STDOUT_FILENO), 0); //is a tty @@ -316,3 +338,4 @@ END_SECTION END_TEST + \ No newline at end of file From 760a642397a84cca6ffa63f9d0d0be28fefb5455 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Sun, 19 Jun 2022 23:38:48 +0200 Subject: [PATCH 16/31] updated --- src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h | 2 ++ src/openms/include/OpenMS/CONCEPT/Colorizer.h | 1 + src/openms/source/CONCEPT/Colorizer.cpp | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index 86a48219967..10427672cb4 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -217,6 +217,8 @@ class ColorizerMethods: public Colorizer void resetColor_(std::ostream& stream){this->resetColor(stream);} + bool getReset_(){return this->getReset();} + std::string getDataAsString_(){return this->getDataAsString();} }; diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index c68a6f11fea..4ef298b4c10 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -125,6 +125,7 @@ friend class ConsoleUtils; /// std::string getDataAsString(); + bool getReset(); private: const int color_; diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 20b361a4f49..7e89288acf4 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -157,6 +157,13 @@ namespace OpenMS return *this; } + /// + bool Colorizer::getReset() + { + return this->reset_; + } + + // overload the shift operator (<<) std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) { From a77b69928a1cc57fc5a927b2cceaa577d72897c1 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Tue, 21 Jun 2022 15:21:08 +0200 Subject: [PATCH 17/31] non-working merged code with new suggestions --- src/openms/source/APPLICATIONS/ConsoleUtils.cpp | 16 ++++++++-------- src/openms/source/CONCEPT/Colorizer.cpp | 8 ++++---- .../openms/source/ConsoleUtils_test.cpp | 9 ++++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index 5311146ada5..080bf62f914 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -85,13 +85,13 @@ namespace OpenMS // void ConsoleUtils::operator=(const ConsoleUtils& other); - OpenMS::StringList ConsoleUtils::breakString(const String& input, + OpenMS::String ConsoleUtils::breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos) { - return getInstance().breakString_(input, indentation, - max_lines, curser_pos); + return ListUtils::concatenate(getInstance().breakString_(input, indentation, + max_lines, curser_pos),"\n"); } int ConsoleUtils::readConsoleSize_() @@ -294,14 +294,14 @@ int getCerrColor() -IndentedStringStream& IndentedStringStream::operator<<(ColorizerMethods& colorizer) +IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) { - colorizer.ColorizerMethods::colorStream_(*stream_); - this->operator<<(colorizer.ColorizerMethods::getDataAsString_()); + colorizer.colorStream(*stream_); + this->operator<<(colorizer.getDataAsString()); - if(colorizer.ColorizerMethods::getReset_()) + if(colorizer.getReset()) { - colorizer.ColorizerMethods::resetColor_(*stream_); + colorizer.resetColor(*stream_); } diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 7e89288acf4..06525a1db12 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -40,7 +40,7 @@ #include #endif -#define COLORIZER_TEST +// #define COLORIZER_TEST namespace OpenMS @@ -56,7 +56,7 @@ namespace OpenMS { // if colorizer object is destroyed, set console color back to def col. #if defined(__linux__) || defined(__OSX__) - std::cout << colors_[8]; + std::cout << colors_[int(Color::RESET)]; //check // std::cout << resetColor(cout); // std::cerr << resetColor(cerr); #endif @@ -81,7 +81,8 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) // write coloring escape codes into the string - #if not defined(COLORIZER_TEST) + //check cout oder cerr + #if not defined(COLORIZER_TEST) if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { stream << this->colors_[this->color_]; @@ -181,6 +182,5 @@ namespace OpenMS OpenMS::Colorizer magenta(Color::MAGENTA); OpenMS::Colorizer cyan(Color::CYAN); OpenMS::Colorizer white(Color::WHITE); - // OpenMS::Colorizer reset_color(Color::RESET); } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp index 477331c90db..3eb53948b03 100644 --- a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp +++ b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp @@ -117,12 +117,8 @@ static String breakString(const String &input, //String broken_string = ConsoleUtils::breakString(test_string, 0, 10); // freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", "w", stdout); - fstream my_file; - my_file.open("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", ios::out); - string first_string = broken_string[3]; - my_file << first_string; - my_file.close(); + int l = broken_string.size(); //test_string[1].length() <= broken_string.length() @@ -132,6 +128,9 @@ static String breakString(const String &input, error: conversion from ‘OpenMS::StringList’ {aka ‘std::vector’} to non-scalar type ‘OpenMS::String’ requested 67 | String broken_string = ConsoleUtils::breakString(test_string, 0, 10); + 2 breakstring funktionen - string und stringlist zurueckgeben + breakString string - concat + breakStringList StringList */ } END_SECTION From 45a6b98abb6db2b33a2e88ee30af9e33ec2e4359 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Tue, 21 Jun 2022 23:09:52 +0200 Subject: [PATCH 18/31] Working merged new Colorizer and ConsoleUtils classes, minor changes still needed like cerr/cout recognition, CU testclass finalization --- .../OpenMS/APPLICATIONS/ConsoleUtils.h | 74 +++++++++++++------ src/openms/include/OpenMS/CONCEPT/Colorizer.h | 3 +- .../source/APPLICATIONS/ConsoleUtils.cpp | 54 +++++++++++--- src/openms/source/APPLICATIONS/TOPPBase.cpp | 6 +- src/openms/source/CONCEPT/Colorizer.cpp | 7 +- 5 files changed, 102 insertions(+), 42 deletions(-) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index 10427672cb4..884fc4373f3 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -66,20 +66,27 @@ namespace OpenMS /// Destructor ~ConsoleUtils(); - static OpenMS::StringList breakString(const String& input, + static OpenMS::String breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos = 0); + static OpenMS::StringList breakStringList(const String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos = 0); + + +//implement new function breakStringList - returns broken StringList const int getConsoleSize() { return console_width_; } - static ConsoleUtils getInstance() - { - return getInstance_(); - } + static ConsoleUtils getInstance() + { + return getInstance_(); + } //#ifdef OPENMS_WINDOWSPLATFORM @@ -142,6 +149,28 @@ namespace OpenMS //#endif }; + class ColorizerMethods: public Colorizer + { + + public: + + ///Constructor + ColorizerMethods(const Color color); + + /// Default destructor + ~ColorizerMethods(); + + void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} + + void colorStream_(std::ostream& stream) const{this->colorStream(stream);} + + void resetColor_(std::ostream& stream){this->resetColor(stream);} + + bool getReset_(){return this->getReset();} + + std::string getDataAsString_(){return this->getDataAsString();} + }; + class IndentedStringStream { public: @@ -166,7 +195,7 @@ namespace OpenMS //wie viele zeilen sind es / viel viele zeichen in letrzter zeile - OpenMS::StringList result = ConsoleUtils::breakString(string_to_print, + OpenMS::StringList result = ConsoleUtils::breakStringList(string_to_print, indentation_, max_lines_, current_column_pos_); @@ -190,7 +219,8 @@ namespace OpenMS ///741 = offset ///763 = indent - IndentedStringStream& operator<<(ColorizerMethods& colorizer); + + // IndentedStringStream& operator<<(ColorizerMethods& colorizer); private: std::ostream* stream_; @@ -198,29 +228,27 @@ namespace OpenMS int max_lines_; int max_line_width_; int current_column_pos_; - }; - -class ColorizerMethods: public Colorizer - { - - public: + - ///Constructor - ColorizerMethods(const Color color); + IndentedStringStream& operator<<(ColorizerMethods& colorizer) +{ + colorizer.colorStream_(*stream_); + this->operator<<(colorizer.getDataAsString_()); - /// Default destructor - ~ColorizerMethods(); + if(colorizer.getReset_()) + { + colorizer.resetColor_(*stream_); + + } + + return *this; +} - void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} +}; - void colorStream_(std::ostream& stream) const{this->colorStream(stream);} - void resetColor_(std::ostream& stream){this->resetColor(stream);} - bool getReset_(){return this->getReset();} - std::string getDataAsString_(){return this->getDataAsString();} - }; } // namespace OpenMS diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 4ef298b4c10..86e7d2b91b5 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -174,6 +174,7 @@ friend class ConsoleUtils; //extern /*OPENMS_DLLAPI*/ Colorizer default_color; ///< reset the color to default, alias for 'reset_color' //Stream operator declaration - OPENMS_DLLAPI std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col); + OPENMS_DLLAPI std::ostream& operator<<(std::ostream& o_stream, + OpenMS::Colorizer& col); } diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index 080bf62f914..f5ca45146d1 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -90,10 +90,22 @@ namespace OpenMS const Size max_lines, const Size curser_pos) { - return ListUtils::concatenate(getInstance().breakString_(input, indentation, + return ListUtils::concatenate(ConsoleUtils::getInstance().breakString_(input, indentation, max_lines, curser_pos),"\n"); } + OpenMS::StringList ConsoleUtils::breakStringList(const String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos) + { + return ConsoleUtils::getInstance().breakString_(input, indentation, + max_lines, curser_pos); + } + + + + int ConsoleUtils::readConsoleSize_() { // avoid calling this function more than once @@ -294,19 +306,38 @@ int getCerrColor() -IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) -{ - colorizer.colorStream(*stream_); - this->operator<<(colorizer.getDataAsString()); +// IndentedStringStream& IndentedStringStream::operator<<(ColorizerMethods& colorizer) +// { +// colorizer.ColorizerMethods::colorStream_(*stream_); +// this->operator<<(colorizer.ColorizerMethods::getDataAsString_()); - if(colorizer.getReset()) - { - colorizer.resetColor(*stream_); +// if(colorizer.ColorizerMethods::getReset_()) +// { +// colorizer.ColorizerMethods::resetColor_(*stream_); - } +// } - return *this; -} +// return *this; +// } + + + +// IndentedStringStream& IndentedStringStream::operator<<(ColorizerMethods& colorizer) +// { +// colorizer.colorStream_(*stream_); +// this->operator<<(colorizer.getDataAsString_()); + +// if(colorizer.getReset_()) +// { +// colorizer.resetColor_(*stream_); + +// } + +// return *this; +// } + + + @@ -581,4 +612,3 @@ IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) - diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 0dd4fe377a8..59c642d16e1 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -192,7 +192,7 @@ namespace OpenMS addEmptyLine_(); //common section for all tools if (ToolHandler::getTOPPToolList().count(tool_name_)) - addText_("Common TOPP options:"); + addText_("cd options:"); else addText_("Common UTIL options:"); registerStringOption_("ini", "", "", "Use the given TOPP INI file", false); @@ -256,7 +256,7 @@ namespace OpenMS { cout << red(); writeLog_("No options given. Aborting!"); - cout << reset_color(); + cout << red.reset(); printUsage_(); return ILLEGAL_PARAMETERS; } @@ -764,7 +764,7 @@ namespace OpenMS << ConsoleUtils::breakString("You can write an example INI file using the '-write_ini' option.", 0, 10) << "\n" << ConsoleUtils::breakString("Documentation of subsection parameters can be found in the doxygen documentation or the INIFileEditor.", 0, 10) << "\n" << ConsoleUtils::breakString("For more information, please consult the online documentation for this tool:", 0, 10) << "\n" - << ConsoleUtils::breakString(" - " + docurl, 0, 10) << reset_color() << "\n"; + << ConsoleUtils::breakString(" - " + docurl, 0, 10) << blue.reset() << "\n"; } cerr << endl; } diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 06525a1db12..d532f81fb98 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -119,10 +119,10 @@ namespace OpenMS //supress output of ANSI codes into the file if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { - stream << this->colors_[8]; + stream << this->colors_[int(Color::RESET)]; } #else - stream << this->colors_[8]; + stream << this->colors_[int(Color::RESET)]; #endif // stream << this->colors_[(int)Color::RESET]; #endif @@ -166,7 +166,8 @@ namespace OpenMS // overload the shift operator (<<) - std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) + std::ostream& operator<<(std::ostream& o_stream, + OpenMS::Colorizer& col) { // colorize string with color set in the object col.outputToStream(o_stream); From 753989b278ec37f72a0f9e070c3720b5316b4d8c Mon Sep 17 00:00:00 2001 From: tetak94 Date: Tue, 21 Jun 2022 23:35:58 +0200 Subject: [PATCH 19/31] error fixes --- src/openms/source/CONCEPT/Colorizer.cpp | 2 +- src/tests/class_tests/openms/source/Colorizer_test.cpp | 2 ++ src/tests/class_tests/openms/source/ConsoleUtils_test.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index d532f81fb98..2a94418375e 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -40,7 +40,7 @@ #include #endif -// #define COLORIZER_TEST +#define COLORIZER_TEST namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 2cc85507abb..ff47102d4c1 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -67,6 +67,8 @@ class ColorizerMethodsTester: public Colorizer ///Constructor ColorizerMethodsTester(const Color color); + ColorizerMethodsTester(); + /// Default destructor ~ColorizerMethodsTester(); diff --git a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp index 3eb53948b03..5caaa954598 100644 --- a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp +++ b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp @@ -99,7 +99,7 @@ START_SECTION(void setCerrColor()) END_SECTION #endif -START_SECTION((static OpenMS::StringList breakString(const String& input, +START_SECTION((static OpenMS::StringList breakStringList(const String& input, const Size indentation, const Size max_lines, const Size curser_pos = 0))) @@ -113,11 +113,11 @@ static String breakString(const String &input, { // we cannot predict which shape the broken string will have, so testing is rather limited String test_string = "This is a test string which should be broken up into multiple lines."; - OpenMS::StringList broken_string = ConsoleUtils::breakString(test_string, 0, 10); - //String broken_string = ConsoleUtils::breakString(test_string, 0, 10); + // OpenMS::StringList broken_string = ConsoleUtils::breakString(test_string, 0, 10); + String broken_string = ConsoleUtils::breakString(test_string, 0, 10); // freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", "w", stdout); - string first_string = broken_string[3]; + string first_string = broken_string; int l = broken_string.size(); From 16c64b4ddf41305927ec941337bc6862bad05a39 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 22 Jun 2022 16:09:14 +0200 Subject: [PATCH 20/31] updated ConsoleUtils_test functionality, ready for review --- .../OpenMS/APPLICATIONS/ConsoleUtils.h | 8 - .../source/APPLICATIONS/ConsoleUtils.cpp | 308 ------------------ src/openms/source/APPLICATIONS/TOPPBase.cpp | 1 + src/openms/source/CONCEPT/Colorizer.cpp | 50 +-- .../openms/source/Colorizer_test.cpp | 56 ++-- .../openms/source/ConsoleUtils_test.cpp | 51 ++- 6 files changed, 74 insertions(+), 400 deletions(-) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index 884fc4373f3..537c27a4bc3 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -132,10 +132,7 @@ namespace OpenMS // ~ConsoleUtils(); /// Assignment operator - // void operator=(ConsoleUtils const& other); - // void operator=(const ConsoleUtils& other); void operator=(ConsoleUtils const&); - //added "other" here //#ifdef OPENMS_WINDOWSPLATFORM @@ -246,10 +243,5 @@ namespace OpenMS }; - - - - - } // namespace OpenMS diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index f5ca45146d1..e686dc40ce8 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -82,7 +82,6 @@ namespace OpenMS ConsoleUtils::ConsoleUtils(ConsoleUtils const& other) = default; void ConsoleUtils::operator=(const ConsoleUtils& other) {}; // void ConsoleUtils::operator=(const ConsoleUtils& other) = default; - // void ConsoleUtils::operator=(const ConsoleUtils& other); OpenMS::String ConsoleUtils::breakString(const String& input, @@ -104,8 +103,6 @@ namespace OpenMS } - - int ConsoleUtils::readConsoleSize_() { // avoid calling this function more than once @@ -303,312 +300,7 @@ int getCerrColor() } #endif - - - -// IndentedStringStream& IndentedStringStream::operator<<(ColorizerMethods& colorizer) -// { -// colorizer.ColorizerMethods::colorStream_(*stream_); -// this->operator<<(colorizer.ColorizerMethods::getDataAsString_()); - -// if(colorizer.ColorizerMethods::getReset_()) -// { -// colorizer.ColorizerMethods::resetColor_(*stream_); - -// } - -// return *this; -// } - - - -// IndentedStringStream& IndentedStringStream::operator<<(ColorizerMethods& colorizer) -// { -// colorizer.colorStream_(*stream_); -// this->operator<<(colorizer.getDataAsString_()); - -// if(colorizer.getReset_()) -// { -// colorizer.resetColor_(*stream_); - -// } - -// return *this; -// } - - - - - - } -//////////////////////////////////////////// - -//////////////////////////////////////////// - - -// #include - -// #include -// #include - -// #ifdef OPENMS_WINDOWSPLATTFORM -// #include // for GetConsoleScreenBufferInfo() -// #undef min -// #undef max -// #endif - -// #include -// #include - -// namespace OpenMS -// { - -// ConsoleUtils::ConsoleUtils() : -// console_width_(80) -// { -// // initialize the console width -// readConsoleSize_(); - -// //if operating OS is Windows: save default output color for cour and cerr -// #ifdef OPENMS_WINDOWSPLATTFORM -// CONSOLE_SCREEN_BUFFER_INFO Info; -// HANDLE handle_stdout = GetStdHandle(STD_OUTPUT_HANDLE); -// HANDLE handle_stderr = GetStdHandle(STD_ERROR_HANDLE); - -// GetConsoleScreenBufferInfo(handle_stdout, &Info); - -// default_cout_ = Info.wAttributes; - -// GetConsoleScreenBufferInfo(handle_stderr, &Info); - -// default_cerr_ = Info.wAttributes; - -// /// get and remember 2 default colors -// #endif -// } - -// ConsoleUtils::~ConsoleUtils() -// { -// #ifdef OPENMS_WINDOWSPLATTFORM -// resetConsoleColor(); -// #endif -// } - -// ConsoleUtils::ConsoleUtils(ConsoleUtils const& other) = default; -// void ConsoleUtils::operator=(const ConsoleUtils& other) = default; -// } - -// OpenMS::StringList ConsoleUtils::breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos) -// { -// return getInstance().breakString_(input, indentation, max_lines, curser_pos); -// } - -// int ConsoleUtils::readConsoleSize_() -// { -// // avoid calling this function more than once -// static bool been_here = false; -// if (been_here) -// { -// return console_width_; -// } - -// been_here = true; - -// // determine column width of current console -// try -// { -// console_width_ = -1; -// char* p_env; -// p_env = getenv("COLUMNS"); -// if (p_env != nullptr) -// { -// console_width_ = String(p_env).toInt(); -// } -// else -// { -// { -// OPENMS_LOG_DEBUG << "output shaping: COLUMNS env does not exist!" << std::endl; -// } - -// #ifdef OPENMS_WINDOWSPLATTFORM -// HANDLE hOut; -// CONSOLE_SCREEN_BUFFER_INFO SBInfo; -// hOut = GetStdHandle(STD_OUTPUT_HANDLE); -// GetConsoleScreenBufferInfo(hOut, &SBInfo); -// console_width_ = SBInfo.dwSize.X; -// #else // Linux / MacOS -// // try "stty size" command -// // don't use QProcess, since stty will not work there -// FILE* fp = popen("stty size", "r"); -// if (fp != nullptr) -// { -// char buff[100]; -// if (fgets(buff, sizeof(buff), fp) != nullptr) -// { -// String output(buff); -// StringList components; -// output.split(' ', components); -// if (components.size() == 2) -// console_width_ = components[1].toInt(); -// } -// else -// { -// // TODO: throw ? -// OPENMS_LOG_DEBUG << "Could not read 100 characters from file." << std::endl; -// } -// pclose(fp); //moved pclose outside of fgets condition - cant move it out of not nullpointer condition because pclose(null pointer is undefined behaviour) -// } -// else -// { -// OPENMS_LOG_DEBUG << "output shaping: stty size command failed." << std::endl; -// } -// #endif -// } -// --console_width_; // to add the \n at the end of each line without forcing another line break on windows -// } -// catch (...) -// { -// } -// // if console_width_ is still -1, we do not use command line reshaping -// if (console_width_ < 10) -// { -// OPENMS_LOG_DEBUG << "Console width could not be determined or is smaller than 10. Not using output shaping!" << std::endl; -// console_width_ = std::numeric_limits::max(); -// } - -// return console_width_; - - -// ConsoleUtils& ConsoleUtils::getInstance_() -// { -// static ConsoleUtils instance; -// return instance; -// } - -// //erweitern, mit aktueller curser position -// // rückgabe: vector von strings -// // (OpenMS::StringList) -// OpenMS::StringList ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines, const Size curser_pos) -// { - -// //OpenMS::StringList list; -// //list.clear(); -// // get the line length -// Int line_len = ConsoleUtils::readConsoleSize_(); - -// StringList result; -// Size short_line_len = line_len - indentation; - -// /// hier wird linelen - neuer param curpos -// line_len -= curser_pos; - - - -// if (short_line_len < 1) -// { -// std::cerr << "INTERNAL ERROR: cannot split lines into empty strings! see breakString_()"; -// result.push_back(input); -// return result; -// } - - -// for (Size i = 0; i < input.size(); ) -// { -// String line = input.substr(i, result.empty() ? line_len : short_line_len); // first line has full length -// Size advance_size = line.size(); -// if (line.hasSubstring("\n")) -// { -// advance_size = 0; -// while (line.hasPrefix("\n")) -// { -// line = line.substr(1); -// ++advance_size; -// } // advance by # of \n's -// if (line.hasSubstring("\n")) -// { -// line = line.prefix('\n'); -// } -// advance_size += line.size(); // + actual chars -// } - -// // check if we are using the full length and split a word at the same time -// // cut a little earlier in that case for nicer looks -// if (line.size() == (result.empty() ? line_len : short_line_len) && short_line_len > 8 && line.rfind(' ') != String::npos) -// { -// String last_word = line.suffix(' '); -// if (last_word.length() < 4) -// { // shorten by last word (will move to the next line) -// line = line.prefix(line.size() - last_word.length()); -// advance_size -= last_word.size(); // + actual chars -// } -// } - -// i += advance_size; -// String s_intend = (result.empty() ? "" : String(indentation, ' ')); // first line no indentation -// String r = s_intend + (result.empty() ? line : line.trim()); // intended lines get trimmed -// result.push_back(r); //(r.fillRight(' ', (UInt) line_len)); -// } -// if (result.size() > max_lines) // remove lines from end if we get too many (but leave the last one)... -// { -// String last = result.back(); -// result.erase(result.begin() + max_lines - 2, result.end()); -// result.push_back((String(indentation, ' ') + String("..."))); //.fillRight(' ',(UInt) line_len)); -// result.push_back(last); -// } -// // remove last " " from last line to prevent automatic line break -// //if (result.size()>0 && result[result.size()-1].hasSuffix(" ")) result[result.size()-1] = result[result.size()-1].substr(0,result[result.size()-1].size()-1); - -// return result; - - -// #ifdef OPENMS_WINDOWSPLATTFORM -// void ConsoleUtils::resetConsoleColor() -// { -// setCoutColor(default_cout_); -// setCerrColor(default_cerr_); -// } - -// void setCoutColor(int color_code) -// { -// SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_code); -// } - -// void setCerrColor(int color_code) -// { -// SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), color_code); -// } - -// #endif - - - -// IndentedStringStream& IndentedStringStream::operator<<(Colorizer& colorizer) -// { -// colorizer.colorStream(*stream_); -// this->operator<<(colorizer.getDataAsString()); - -// if(colorizer.getReset()) -// { -// colorizer.resetColor(*stream_); - -// } - -// return *this; -// } - -// } -// } - - - - - - - - - - diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 59c642d16e1..bff128368f8 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -765,6 +765,7 @@ namespace OpenMS << ConsoleUtils::breakString("Documentation of subsection parameters can be found in the doxygen documentation or the INIFileEditor.", 0, 10) << "\n" << ConsoleUtils::breakString("For more information, please consult the online documentation for this tool:", 0, 10) << "\n" << ConsoleUtils::breakString(" - " + docurl, 0, 10) << blue.reset() << "\n"; + } cerr << endl; } diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 2a94418375e..8f82c180fb3 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -40,9 +40,6 @@ #include #endif -#define COLORIZER_TEST - - namespace OpenMS { @@ -79,21 +76,23 @@ namespace OpenMS } #elif defined(__linux__) || defined(__OSX__) - // write coloring escape codes into the string - - //check cout oder cerr - #if not defined(COLORIZER_TEST) + //check if the output is being fed to file or console + //supress output of ANSI codes into the file + if (&std::cout == &stream) + { if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { + //write coloring escape codes into the string stream << this->colors_[this->color_]; } - #else - stream << this->colors_[this->color_]; - #endif - - // Problem - in testfiles, STDOUT is always 0 because - //console output is supressed. It should be made an - //exception for colorizer class + } + else if (&std::cerr == &stream) + { + if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + { + stream << this->colors_[this->color_]; + } + } #endif } @@ -113,18 +112,24 @@ namespace OpenMS } #elif defined(__linux__) || defined(__OSX__) + // check if the output is being fed to file or console + // supress output of ANSI codes into the file - #if not defined(COLORIZER_TEST) - //check if the output is being fed to file or console - //supress output of ANSI codes into the file - if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + if (&std::cout == &stream) + { + if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) + { + //write RESET ANSI code to string + stream << this->colors_[int(Color::RESET)]; + } + } + else if (&std::cerr == &stream) + { + if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { stream << this->colors_[int(Color::RESET)]; } - #else - stream << this->colors_[int(Color::RESET)]; - #endif - // stream << this->colors_[(int)Color::RESET]; + } #endif } @@ -164,7 +169,6 @@ namespace OpenMS return this->reset_; } - // overload the shift operator (<<) std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index ff47102d4c1..65eb0d20811 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -67,8 +67,6 @@ class ColorizerMethodsTester: public Colorizer ///Constructor ColorizerMethodsTester(const Color color); - ColorizerMethodsTester(); - /// Default destructor ~ColorizerMethodsTester(); @@ -310,33 +308,33 @@ START_SECTION(Colorizer& operator()()) } END_SECTION -START_SECTION("See if stream is a tty or a file") -{ - stringstream test_stream; - ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); - - cout << 1; - test_stream << cyan("SOMECYANTEXT1"); - TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) - - TEST_EQUAL(isatty(STDIN_FILENO), 1); //is a tty - TEST_EQUAL(isatty(STDOUT_FILENO), 0); //is a tty - TEST_EQUAL(isatty(STDERR_FILENO), 0); //is a tty - - freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/ANSI.txt", "w", stdout); - cout< - //outputs are written somewhere else and checked, so STDOUT is always 0 - //teste is elsewhere -> make a new file and use colorizer there, or maybe - //use console_utils/colorizer output to generate isatty values in different places -} -END_SECTION +// START_SECTION("See if stream is a tty or a file") +// { +// stringstream test_stream; +// ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); + +// cout << 1; +// test_stream << cyan("SOMECYANTEXT1"); +// TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) + +// TEST_EQUAL(isatty(STDIN_FILENO), 1); //is a tty +// TEST_EQUAL(isatty(STDOUT_FILENO), 0); //is a tty +// TEST_EQUAL(isatty(STDERR_FILENO), 0); //is a tty + +// freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/ANSI.txt", "w", stdout); +// cout< +// //outputs are written somewhere else and checked, so STDOUT is always 0 +// //teste is elsewhere -> make a new file and use colorizer there, or maybe +// //use console_utils/colorizer output to generate isatty values in different places +// } +// END_SECTION END_TEST diff --git a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp index 5caaa954598..88f1c737083 100644 --- a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp +++ b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp @@ -53,12 +53,11 @@ START_TEST(ConsoleUtils, "$Id$") ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// -// START_SECTION(const int getConsoleSize()) -// { -// ConsoleUtils c(); -// const int console_size = c.ConsoleUtils::getConsoleSize(); -// } -// END_SECTION +START_SECTION(const int getConsoleSize()) +{ + NOT_TESTABLE +} +END_SECTION START_SECTION(ConsoleUtils getInstance()) { @@ -99,46 +98,34 @@ START_SECTION(void setCerrColor()) END_SECTION #endif -START_SECTION((static OpenMS::StringList breakStringList(const String& input, +START_SECTION((static OpenMS::String breakString(const String& input, const Size indentation, const Size max_lines, const Size curser_pos = 0))) - -/* -static String breakString(const String &input, - const Size indentation, - const Size max_lines)) - -*/ { + // we cannot predict which shape the broken string will have, so testing is rather limited // we cannot predict which shape the broken string will have, so testing is rather limited String test_string = "This is a test string which should be broken up into multiple lines."; - // OpenMS::StringList broken_string = ConsoleUtils::breakString(test_string, 0, 10); String broken_string = ConsoleUtils::breakString(test_string, 0, 10); - // freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt", "w", stdout); - string first_string = broken_string; - - int l = broken_string.size(); - - //test_string[1].length() <= broken_string.length() - TEST_EQUAL(first_string.length() <= l, true) + TEST_EQUAL(test_string.length() <= broken_string.length(), true) - /* - error: conversion from ‘OpenMS::StringList’ {aka ‘std::vector’} to non-scalar type ‘OpenMS::String’ requested - 67 | String broken_string = ConsoleUtils::breakString(test_string, 0, 10); - - 2 breakstring funktionen - string und stringlist zurueckgeben - breakString string - concat - breakStringList StringList - */ } END_SECTION +START_SECTION(static OpenMS::StringList breakStringList(const String& input, + const Size indentation, + const Size max_lines, + const Size curser_pos = 0)) +{ + String test_string = "This is a test string which should be broken up into multiple lines."; + OpenMS::StringList broken_string = ConsoleUtils::breakStringList(test_string, 0, 10); + String broken_string_string = broken_string.StringList::at(0); + TEST_EQUAL(test_string.length() <= broken_string_string.length(), true) +} +END_SECTION -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// END_TEST From 572998797eb2fc89ee32d4b8e476bbbbaec5ced4 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Sun, 25 Sep 2022 22:06:52 +0200 Subject: [PATCH 21/31] coltest constructor not compiling --- src/tests/class_tests/openms/source/Colorizer_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 65eb0d20811..28b99e6cd51 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -65,7 +65,8 @@ class ColorizerMethodsTester: public Colorizer public: ///Constructor - ColorizerMethodsTester(const Color color); + // ColorizerMethodsTester(const Color color); + ColorizerMethodsTester(const Color color): Colorizer(color){}; /// Default destructor ~ColorizerMethodsTester(); From 7df7560c3ea524f03b18eae20baca77d4ab6d787 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Sun, 25 Sep 2022 23:56:24 +0200 Subject: [PATCH 22/31] compiling Colorizer_testclass, test still unsuccessful --- .../openms/source/Colorizer_test.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 28b99e6cd51..4f669b09b07 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -66,10 +66,24 @@ class ColorizerMethodsTester: public Colorizer ///Constructor // ColorizerMethodsTester(const Color color); - ColorizerMethodsTester(const Color color): Colorizer(color){}; + // ColorizerMethodsTester(const Color color): Colorizer(color){}; + + // /// Default destructor + // ~ColorizerMethodsTester(); + + + + ///Constructor + // ColorizerMethodsTester(const Color color); + ColorizerMethodsTester(const Color color) : Colorizer(color){}; /// Default destructor - ~ColorizerMethodsTester(); + ~ColorizerMethodsTester(){ + #if defined(__linux__) || defined(__OSX__) + std::cout << "\e[0m"; //doesn't do anything + #endif + } + void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} From 7ca1e97c4396e8287c65ca43f7cdc26cd0095626 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 28 Sep 2022 00:45:38 +0200 Subject: [PATCH 23/31] dissected Colorizer - problem is in cout, cerr, stream recognition in subclass = no colorisation. --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 4 +- src/openms/source/APPLICATIONS/TOPPBase.cpp | 84 ++++ src/openms/source/CONCEPT/Colorizer.cpp | 11 + .../openms/source/Colorizer_test.cpp | 358 ++++++++++-------- t | 4 + 5 files changed, 292 insertions(+), 169 deletions(-) create mode 100644 t diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 86e7d2b91b5..d784d6a74fc 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -113,6 +113,8 @@ friend class ConsoleUtils; protected: + + const int color_; /// void outputToStream(std::ostream& o_stream); @@ -128,7 +130,7 @@ friend class ConsoleUtils; bool getReset(); private: - const int color_; + // const int color_; /// input in Colorizer object to be colored std::stringstream input_; diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index dc4afcb929f..8d6d1376fea 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -114,6 +114,51 @@ namespace OpenMS return tool_name_ + ":" + instance_number_ + ":"; } + + ///////////////////DETELE THIS!!!!!!!!!!!!//////////////////// + class PleaseWork: public Colorizer + { + // private: + // const int color_; + + + public: + + // //Constructor + // ColorizerMethodsTester(const Color color); + + + PleaseWork(const Color color) : Colorizer(color){}; //old + // PleaseWork(const Color color) : color_((int)color){} + + /// Default destructor + ~PleaseWork(){ + // #if defined(__linux__) || defined(__OSX__) + // std::cout << "\e[0m"; //doesn't do anything + // #endif + } + + // ///Constructor + // PleaseWork(const Color color); + + // /// Default destructor + // ~PleaseWork(); + + + void outputToStream_(std::ostream& o_stream){ + this->outputToStream(o_stream); + } + + void colorStream_(std::ostream& stream) const{this->colorStream(stream);} + + void resetColor_(std::ostream& stream){this->resetColor(stream);} + + std::string getDataAsString_(){return this->getDataAsString();} + }; + + ///////////////////DETELE THIS!!!!!!!!!!!!//////////////////// + + TOPPBase::TOPPBase(const String& tool_name, const String& tool_description, bool official, const std::vector& citations, bool toolhandler_test) : tool_name_(tool_name), tool_description_(tool_description), @@ -252,6 +297,45 @@ namespace OpenMS // test if no options were given if (argc == 1) { + + ////DETELE THIS!!!!!!////////////////////// + //object 1 + stringstream doughnut; + PleaseWork c(Color::BLUE); + c.colorStream_(doughnut); //colorizing blue + writeLog_(doughnut.str()); + doughnut.str(string()); + doughnut.clear(); + + doughnut << c("ABCDE"); //entering text + c.colorStream_(doughnut); //coloring text + writeLog_(doughnut.str()); + doughnut.str(string()); + doughnut.clear(); + + + //make doughnut stream of type cout/cerr + + // object 2 + PleaseWork a(Color::YELLOW); + a.outputToStream_(doughnut); //colorizing red + writeLog_(doughnut.str()); + doughnut.str(string()); + doughnut.clear(); + + doughnut << a("ABCDE"); //entering text + a.outputToStream_(doughnut); //coloring text + doughnut << a("YIHHA"); //entering text + writeLog_(doughnut.str()); + + cout << &doughnut; + + doughnut.str(string()); + doughnut.clear(); + + + ////DETELE THIS!!!!!!////////////////////// + cout << red(); writeLog_("No options given. Aborting!"); cout << red.reset(); diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 4a1becdf361..692c1366790 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -79,19 +79,30 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) //check if the output is being fed to file or console //supress output of ANSI codes into the file + stream << " ...S HOHOHOHO E..." + << " coutNR: " << &std::cout + << " streamNR " << &stream + << " cerrNR: " << &std::cerr; //delete + + if (&std::cout == &stream) { + stream << this->colors_[this->color_]; //delete if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { //write coloring escape codes into the string stream << this->colors_[this->color_]; + // stream << "\033[33m"; //delete } } else if (&std::cerr == &stream) { + stream << this->colors_[this->color_]; //delete if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { stream << this->colors_[this->color_]; + // stream << "\033[35m"; //delete + } } #endif diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 4f669b09b07..e9ff6f04702 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -132,196 +132,218 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY #endif -START_SECTION(Colorizer::colorStream(ostream& stream) const) -{ - //without text - stringstream test_stream; - ColorizerMethodsTester c(Color::BLACK); +// START_SECTION(Colorizer::colorStream(ostream& stream) const) +// { +// //without text +// stringstream test_stream; +// ColorizerMethodsTester c(Color::BLACK); - c.colorStream_(test_stream); - TEST_EQUAL(test_stream.str(), blackANSI) +// c.colorStream_(test_stream); +// TEST_EQUAL(test_stream.str(), blackANSI) - //with text - test_stream.str(string()); - test_stream.clear(); +// //with text +// test_stream.str(string()); +// test_stream.clear(); - test_stream << c(test_string); - c.colorStream_(test_stream); - TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) -} -END_SECTION +// test_stream << c(test_string); +// c.colorStream_(test_stream); +// TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) +// } +// END_SECTION + +// START_SECTION(Colorizer::outputToStream(ostream& o_stream)) +// { +// //without text +// stringstream test_stream; +// ColorizerMethodsTester c(Color::CYAN); + +// c.outputToStream_(test_stream); +// TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) + +// //with text +// test_stream.str(string()); +// test_stream.clear(); + +// test_stream << c(test_string); +// c.outputToStream_(test_stream); +// TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) +// } +// END_SECTION -START_SECTION(Colorizer::outputToStream(ostream& o_stream)) +START_SECTION(Colorizer::outputToStream(ostream& o_stream)) //rewritten with cout as stream { //without text - stringstream test_stream; ColorizerMethodsTester c(Color::CYAN); + stringstream zopa; - c.outputToStream_(test_stream); - TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) + c.outputToStream_(cout); + zopa = cout; + + TEST_EQUAL(cout, cyanANSI+resetColorANSI) //with text - test_stream.str(string()); - test_stream.clear(); + // cout.clear(); - test_stream << c(test_string); - c.outputToStream_(test_stream); - TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) + // cout << c(test_string); + // c.outputToStream_(cout); + TEST_EQUAL(cout,cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) } END_SECTION -START_SECTION(Colorizer::resetColor(ostream& stream)) -{ - stringstream test_stream; - ColorizerMethodsTester c(Color::GREEN); +// START_SECTION(Colorizer::resetColor(ostream& stream)) +// { +// stringstream test_stream; +// ColorizerMethodsTester c(Color::GREEN); - test_stream << c(test_string); - c.resetColor_(test_stream); - TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) -} -END_SECTION +// test_stream << c(test_string); +// c.resetColor_(test_stream); +// TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) +// } +// END_SECTION -START_SECTION(Colorizer::getDataAsString()) -{ - stringstream test_stream; - ColorizerMethodsTester c(Color::RED); +// START_SECTION(Colorizer::getDataAsString()) +// { +// stringstream test_stream; +// ColorizerMethodsTester c(Color::RED); - test_stream << c(test_string); - test_stream << c.getDataAsString_(); - TEST_EQUAL(test_stream.str(), redANSI+test_string+resetColorANSI+test_string) -} -END_SECTION +// test_stream << c(test_string); +// test_stream << c.getDataAsString_(); +// TEST_EQUAL(test_stream.str(), redANSI+test_string+resetColorANSI+test_string) +// } +// END_SECTION -START_SECTION(Colorizer::reset()) -{ - stringstream test_stream; - test_stream << green() - << "green text" << 89 << "$" << " " - << green.reset() << "default text" << red() << 11 << red.reset() << "A"; - TEST_EQUAL(test_stream.str(),greenANSI - +"green text89$ " - +greenANSI+resetColorANSI - +"default text" - +redANSI+"11"+redANSI+resetColorANSI+"A") -} -END_SECTION +// START_SECTION(Colorizer::reset()) +// { +// stringstream test_stream; +// test_stream << green() +// << "green text" << 89 << "$" << " " +// << green.reset() << "default text" << red() << 11 << red.reset() << "A"; +// TEST_EQUAL(test_stream.str(),greenANSI +// +"green text89$ " +// +greenANSI+resetColorANSI +// +"default text" +// +redANSI+"11"+redANSI+resetColorANSI+"A") +// } +// END_SECTION -START_SECTION("Testing Colorizer instances") -{ - //Check that the colorized input contains the original text and according ASCI codes - - stringstream colored_stream; - - colored_stream << black(test_string); - TEST_EQUAL(colored_stream.str(), blackANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << red(test_string); - TEST_EQUAL(colored_stream.str(), redANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << green(test_string); - TEST_EQUAL(colored_stream.str(), greenANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << yellow(test_string); - TEST_EQUAL(colored_stream.str(), yellowANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << blue(test_string); - TEST_EQUAL(colored_stream.str(), blueANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << magenta(test_string); - TEST_EQUAL(colored_stream.str(), magentaANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << cyan(test_string); - TEST_EQUAL(colored_stream.str(), cyanANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); - - colored_stream << white(test_string); - TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) - colored_stream.str(string()); - colored_stream.clear(); -} -END_SECTION +// START_SECTION("Testing Colorizer instances") +// { +// //Check that the colorized input contains the original text and according ASCI codes + +// stringstream colored_stream; + +// colored_stream << black(test_string); +// TEST_EQUAL(colored_stream.str(), blackANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << red(test_string); +// TEST_EQUAL(colored_stream.str(), redANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << green(test_string); +// TEST_EQUAL(colored_stream.str(), greenANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << yellow(test_string); +// TEST_EQUAL(colored_stream.str(), yellowANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << blue(test_string); +// TEST_EQUAL(colored_stream.str(), blueANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << magenta(test_string); +// TEST_EQUAL(colored_stream.str(), magentaANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << cyan(test_string); +// TEST_EQUAL(colored_stream.str(), cyanANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); + +// colored_stream << white(test_string); +// TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) +// colored_stream.str(string()); +// colored_stream.clear(); +// } +// END_SECTION -//testing various inputs for colorizing -START_SECTION("Testing Colorizer inputs") -{ - stringstream colored_stream; - string comparison_string; - - //char//////////////////////////////////// - colored_stream << yellow(test_char); - comparison_string.append(yellowANSI); - comparison_string.append(convertToString(test_char)); - comparison_string.append(resetColorANSI); - TEST_EQUAL(colored_stream.str(), comparison_string) - - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - //int/////////////////////////////// - colored_stream << green(test_int); - comparison_string.append(greenANSI); - comparison_string.append(convertToString(test_int)); - comparison_string.append(resetColorANSI); - TEST_EQUAL(colored_stream.str(), comparison_string) - - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; - - //float/////////////////////////////// - colored_stream << red(test_float); - comparison_string.append(redANSI); - comparison_string.append(convertToString(test_float)); - comparison_string.append(resetColorANSI); - TEST_EQUAL(colored_stream.str(), comparison_string) - - //clearing streams - colored_stream.str(string()); - colored_stream.clear(); - comparison_string = ""; -} -END_SECTION +// //testing various inputs for colorizing +// START_SECTION("Testing Colorizer inputs") +// { +// stringstream colored_stream; +// string comparison_string; + +// //char//////////////////////////////////// +// colored_stream << yellow(test_char); +// comparison_string.append(yellowANSI); +// comparison_string.append(convertToString(test_char)); +// comparison_string.append(resetColorANSI); +// TEST_EQUAL(colored_stream.str(), comparison_string) + +// //clearing streams +// colored_stream.str(string()); +// colored_stream.clear(); +// comparison_string = ""; + +// //int/////////////////////////////// +// colored_stream << green(test_int); +// comparison_string.append(greenANSI); +// comparison_string.append(convertToString(test_int)); +// comparison_string.append(resetColorANSI); +// TEST_EQUAL(colored_stream.str(), comparison_string) + +// //clearing streams +// colored_stream.str(string()); +// colored_stream.clear(); +// comparison_string = ""; + +// //float/////////////////////////////// +// colored_stream << red(test_float); +// comparison_string.append(redANSI); +// comparison_string.append(convertToString(test_float)); +// comparison_string.append(resetColorANSI); +// TEST_EQUAL(colored_stream.str(), comparison_string) + +// //clearing streams +// colored_stream.str(string()); +// colored_stream.clear(); +// comparison_string = ""; +// } +// END_SECTION -START_SECTION(Colorizer& operator()()) -{ - stringstream test_stream; - test_stream << green() - << "green text" - << 123 << "!" - << " " - << magenta() - << "magenta text" - << green.reset() - << "default text" - << magenta.reset() - << "default text"; - TEST_EQUAL(test_stream.str(),greenANSI - +"green text123! " - +magentaANSI - +"magenta text" - +greenANSI+resetColorANSI - +"default text" - +magentaANSI+resetColorANSI - +"default text") +// START_SECTION(Colorizer& operator()()) +// { +// stringstream test_stream; +// test_stream << green() +// << "green text" +// << 123 << "!" +// << " " +// << magenta() +// << "magenta text" +// << green.reset() +// << "default text" +// << magenta.reset() +// << "default text"; +// TEST_EQUAL(test_stream.str(),greenANSI +// +"green text123! " +// +magentaANSI +// +"magenta text" +// +greenANSI+resetColorANSI +// +"default text" +// +magentaANSI+resetColorANSI +// +"default text") -} -END_SECTION +// } +// END_SECTION + +///OLD:DELETE BELOW // START_SECTION("See if stream is a tty or a file") // { diff --git a/t b/t new file mode 100644 index 00000000000..126ade0b604 --- /dev/null +++ b/t @@ -0,0 +1,4 @@ + colorizer_testclass +* consoleutils_testclass + master + remotes/openms_tetak94/colorizer_testclass From de8dfaabbe470ee734884956b9933d3716c06e4f Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 28 Sep 2022 16:08:27 +0200 Subject: [PATCH 24/31] writing ColorizerTester inside Colorizer metavestion --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 58 ++++++++++++++++++- src/openms/source/CONCEPT/Colorizer.cpp | 58 +++++++++++++++++++ .../openms/source/Colorizer_test.cpp | 41 +++++++------ 3 files changed, 135 insertions(+), 22 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index d784d6a74fc..e2d26c9cd0e 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -129,6 +129,8 @@ friend class ConsoleUtils; bool getReset(); + // std::stringstream getInput(); + private: // const int color_; @@ -178,5 +180,59 @@ friend class ConsoleUtils; //Stream operator declaration OPENMS_DLLAPI std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col); -} + + + +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +class ColorizerTester: public Colorizer + + /*only used in Colorizer_test.cpp for testing Colorizer method + functionality. While using Colorizer instances, only cout or cerr + streams are being colorized. + + Methods with underscore "_" at the name end are used to + reveal functionality of protected class functions in the unit test. + + For separate Colorizer method testing, stringstreams are used instead. + This class modified these methods to use Colorizer functionality on + stringstreams instead of cout/cerr streams. Such methods have "Simple" + attached to the method name. + + This class should not be used outside Colorizer_test.cpp + */ +{ + public: + + ///Constructor + ColorizerTester(const Color color); + + /// Default destructor + ~ColorizerTester(); + + //original methods revealing functionality for public use + void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} + + void colorStream_(std::ostream& stream) const{this->colorStream(stream);} + + void resetColor_(std::ostream& stream){this->resetColor(stream);} + + std::string getDataAsString_(){return this->getDataAsString();} + + + //modified methods for stringstream instead of cerr/cout + void outputToStreamSimple(std::ostream& o_stream); + + void colorStreamSimple(std::ostream& stream); + + void resetColorSimple(std::ostream& stream); + + // bool getReset_(); + + std::string getDataAsStringSimple(); +}; + +} diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 692c1366790..59871c54210 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -181,6 +181,10 @@ namespace OpenMS return this->reset_; } + // std::stringstream Colorizer::getInput(){ + // return this->input_; + // } + // overload the shift operator (<<) std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) @@ -190,6 +194,7 @@ namespace OpenMS return o_stream; } + // Objekte des typs colorizer OpenMS::Colorizer black(Color::BLACK); OpenMS::Colorizer red(Color::RED); @@ -200,4 +205,57 @@ namespace OpenMS OpenMS::Colorizer cyan(Color::CYAN); OpenMS::Colorizer white(Color::WHITE); +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////// + +class ColorizerTester: public Colorizer + + /*only used in Colorizer_test.cpp for testing Colorizer method + functionality. While using Colorizer instances, only cout or cerr + streams are being colorized. + + Methods with underscore "_" at the name end are used to + reveal functionality of protected class functions in the unit test. + + For separate Colorizer method testing, stringstreams are used instead. + This class modified these methods to use Colorizer functionality on + stringstreams instead of cout/cerr streams. Such methods have "Simple" + attached to the method name. + + This class should not be used outside Colorizer_test.cpp + */ +{ + public: + + ///Constructor + ColorizerTester(const Color color); + + /// Default destructor + ~ColorizerTester(); + + //original methods revealing functionality for public use + void outputToStream_(std::ostream& o_stream); + + void colorStream_(std::ostream& stream); + + void resetColor_(std::ostream& stream); + + std::string getDataAsString_(); + + + //modified methods for stringstream instead of cerr/cout + void outputToStreamSimple(std::ostream& o_stream); + + void colorStreamSimple(std::ostream& stream); + + void resetColorSimple(std::ostream& stream); + + // bool getReset_(); + + std::string getDataAsStringSimple(); +}; + + } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index e9ff6f04702..c5eb069c657 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -132,11 +132,30 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY #endif +START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified +{ + //without text + stringstream test_stream; + ColorizerTester c(Color::BLACK); + + c.colorStream_(test_stream); + TEST_EQUAL(test_stream.str(), blackANSI) + + //with text + test_stream.str(string()); + test_stream.clear(); + + test_stream << c(test_string); + c.colorStream_(test_stream); + TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) +} +END_SECTION + // START_SECTION(Colorizer::colorStream(ostream& stream) const) // { // //without text // stringstream test_stream; -// ColorizerMethodsTester c(Color::BLACK); +// Colorizer::ColorizerTester c(Color::BLACK); // c.colorStream_(test_stream); // TEST_EQUAL(test_stream.str(), blackANSI) @@ -170,26 +189,6 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY // } // END_SECTION -START_SECTION(Colorizer::outputToStream(ostream& o_stream)) //rewritten with cout as stream -{ - //without text - ColorizerMethodsTester c(Color::CYAN); - stringstream zopa; - - c.outputToStream_(cout); - zopa = cout; - - TEST_EQUAL(cout, cyanANSI+resetColorANSI) - - //with text - // cout.clear(); - - // cout << c(test_string); - // c.outputToStream_(cout); - TEST_EQUAL(cout,cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) -} -END_SECTION - // START_SECTION(Colorizer::resetColor(ostream& stream)) // { // stringstream test_stream; From c30c7bcec669cb830446e2ffa0a1b189c1dff4ce Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 28 Sep 2022 16:44:50 +0200 Subject: [PATCH 25/31] working colorStreamSimple method! --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 14 +++- src/openms/source/APPLICATIONS/TOPPBase.cpp | 6 ++ src/openms/source/CONCEPT/Colorizer.cpp | 77 ++++++++++--------- .../openms/source/Colorizer_test.cpp | 46 +++++------ 4 files changed, 80 insertions(+), 63 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index e2d26c9cd0e..133d4f44146 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -129,7 +129,11 @@ friend class ConsoleUtils; bool getReset(); - // std::stringstream getInput(); + std::stringstream getInput(); + + const char* getColor_(){ + return this->colors_[color_]; + } private: // const int color_; @@ -188,7 +192,7 @@ friend class ConsoleUtils; ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// -class ColorizerTester: public Colorizer +class OPENMS_DLLAPI ColorizerTester: public Colorizer /*only used in Colorizer_test.cpp for testing Colorizer method functionality. While using Colorizer instances, only cout or cerr @@ -208,10 +212,12 @@ class ColorizerTester: public Colorizer public: ///Constructor - ColorizerTester(const Color color); + // ColorizerTester(const Color color); + ColorizerTester(const Color color) : Colorizer(color){}; + /// Default destructor - ~ColorizerTester(); + ~ColorizerTester(){}; //original methods revealing functionality for public use void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 8d6d1376fea..8a3c38bafe5 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -333,6 +333,12 @@ namespace OpenMS doughnut.str(string()); doughnut.clear(); + ColorizerTester hui(Color::CYAN); + hui.colorStreamSimple(doughnut); + doughnut << hui(" UUUUUUUUU "); + writeLog_(doughnut.str()); + + ////DETELE THIS!!!!!!////////////////////// diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 59871c54210..516f39aac5a 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -79,15 +79,15 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) //check if the output is being fed to file or console //supress output of ANSI codes into the file - stream << " ...S HOHOHOHO E..." - << " coutNR: " << &std::cout - << " streamNR " << &stream - << " cerrNR: " << &std::cerr; //delete + // stream << " ...S HOHOHOHO E..." + // << " coutNR: " << &std::cout + // << " streamNR " << &stream + // << " cerrNR: " << &std::cerr; //delete if (&std::cout == &stream) { - stream << this->colors_[this->color_]; //delete + // stream << this->colors_[this->color_]; //delete if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { //write coloring escape codes into the string @@ -97,7 +97,7 @@ namespace OpenMS } else if (&std::cerr == &stream) { - stream << this->colors_[this->color_]; //delete + // stream << this->colors_[this->color_]; //delete if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { stream << this->colors_[this->color_]; @@ -210,52 +210,57 @@ namespace OpenMS ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// -class ColorizerTester: public Colorizer +// class ColorizerTester: public Colorizer - /*only used in Colorizer_test.cpp for testing Colorizer method - functionality. While using Colorizer instances, only cout or cerr - streams are being colorized. +// /*only used in Colorizer_test.cpp for testing Colorizer method +// functionality. While using Colorizer instances, only cout or cerr +// streams are being colorized. - Methods with underscore "_" at the name end are used to - reveal functionality of protected class functions in the unit test. +// Methods with underscore "_" at the name end are used to +// reveal functionality of protected class functions in the unit test. - For separate Colorizer method testing, stringstreams are used instead. - This class modified these methods to use Colorizer functionality on - stringstreams instead of cout/cerr streams. Such methods have "Simple" - attached to the method name. +// For separate Colorizer method testing, stringstreams are used instead. +// This class modified these methods to use Colorizer functionality on +// stringstreams instead of cout/cerr streams. Such methods have "Simple" +// attached to the method name. - This class should not be used outside Colorizer_test.cpp - */ -{ - public: +// This class should not be used outside Colorizer_test.cpp +// */ +// { +// public: + +// ///Constructor +// ColorizerTester(const Color color); - ///Constructor - ColorizerTester(const Color color); +// /// Default destructor +// ~ColorizerTester(); - /// Default destructor - ~ColorizerTester(); +// //original methods revealing functionality for public use +// void outputToStream_(std::ostream& o_stream); - //original methods revealing functionality for public use - void outputToStream_(std::ostream& o_stream); +// void colorStream_(std::ostream& stream); - void colorStream_(std::ostream& stream); +// void resetColor_(std::ostream& stream); - void resetColor_(std::ostream& stream); +// std::string getDataAsString_(); - std::string getDataAsString_(); +// //modified methods for stringstream instead of cerr/cout +// void outputToStreamSimple(std::ostream& o_stream); - //modified methods for stringstream instead of cerr/cout - void outputToStreamSimple(std::ostream& o_stream); +// void colorStreamSimple(std::ostream& stream); - void colorStreamSimple(std::ostream& stream); +// void resetColorSimple(std::ostream& stream); - void resetColorSimple(std::ostream& stream); +// // bool getReset_(); - // bool getReset_(); +// std::string getDataAsStringSimple(); +// }; - std::string getDataAsStringSimple(); -}; +void ColorizerTester::colorStreamSimple(std::ostream& stream) +{ + stream << this->Colorizer::getColor_(); +} } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index c5eb069c657..09e01425cd7 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -59,40 +59,40 @@ string convertToString ( T var_input ) } -class ColorizerMethodsTester: public Colorizer - { +// class ColorizerMethodsTester: public Colorizer +// { - public: +// public: - ///Constructor - // ColorizerMethodsTester(const Color color); - // ColorizerMethodsTester(const Color color): Colorizer(color){}; +// ///Constructor +// // ColorizerMethodsTester(const Color color); +// // ColorizerMethodsTester(const Color color): Colorizer(color){}; - // /// Default destructor - // ~ColorizerMethodsTester(); +// // /// Default destructor +// // ~ColorizerMethodsTester(); - ///Constructor - // ColorizerMethodsTester(const Color color); - ColorizerMethodsTester(const Color color) : Colorizer(color){}; +// ///Constructor +// // ColorizerMethodsTester(const Color color); +// ColorizerMethodsTester(const Color color) : Colorizer(color){}; - /// Default destructor - ~ColorizerMethodsTester(){ - #if defined(__linux__) || defined(__OSX__) - std::cout << "\e[0m"; //doesn't do anything - #endif - } +// /// Default destructor +// ~ColorizerMethodsTester(){ +// #if defined(__linux__) || defined(__OSX__) +// std::cout << "\e[0m"; //doesn't do anything +// #endif +// } - void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} +// void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} - void colorStream_(std::ostream& stream) const{this->colorStream(stream);} +// void colorStream_(std::ostream& stream) const{this->colorStream(stream);} - void resetColor_(std::ostream& stream){this->resetColor(stream);} +// void resetColor_(std::ostream& stream){this->resetColor(stream);} - std::string getDataAsString_(){return this->getDataAsString();} - }; +// std::string getDataAsString_(){return this->getDataAsString();} +// }; START_TEST(Colorizer(),"$Id$") @@ -138,7 +138,7 @@ START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified stringstream test_stream; ColorizerTester c(Color::BLACK); - c.colorStream_(test_stream); + c.colorStreamSimple(test_stream); TEST_EQUAL(test_stream.str(), blackANSI) //with text From 4852574315ee592b0667b4d9c912ee1f58a43d9b Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 28 Sep 2022 17:12:31 +0200 Subject: [PATCH 26/31] updating Simple class functionality, having problems with private input_ variable being accessible --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 17 ++++++++-- src/openms/source/APPLICATIONS/TOPPBase.cpp | 5 +++ src/openms/source/CONCEPT/Colorizer.cpp | 32 +++++++++++++---- .../openms/source/Colorizer_test.cpp | 34 ++++++++++--------- 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 133d4f44146..64195a81352 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -127,14 +127,25 @@ friend class ConsoleUtils; /// std::string getDataAsString(); - bool getReset(); + bool getReset() + { + return this->reset_; + } - std::stringstream getInput(); + std::stringstream getInput() + { + return this->input_; + } - const char* getColor_(){ + const char* getColor_() + { return this->colors_[color_]; } + const char* getResetColor_(){ + return this->colors_[int(Color::RESET)]; + } + private: // const int color_; diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 8a3c38bafe5..b99c8db267f 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -338,6 +338,11 @@ namespace OpenMS doughnut << hui(" UUUUUUUUU "); writeLog_(doughnut.str()); + ColorizerTester mui(Color::GREEN); + hui.outputToStreamSimple(doughnut); + doughnut << hui(" UUUUUUUUU "); + writeLog_(doughnut.str()); + ////DETELE THIS!!!!!!////////////////////// diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 516f39aac5a..9ce0caedc30 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -176,13 +176,9 @@ namespace OpenMS } /// - bool Colorizer::getReset() - { - return this->reset_; - } - - // std::stringstream Colorizer::getInput(){ - // return this->input_; + // bool Colorizer::getReset() + // { + // return this->reset_; // } // overload the shift operator (<<) @@ -262,5 +258,27 @@ void ColorizerTester::colorStreamSimple(std::ostream& stream) stream << this->Colorizer::getColor_(); } +void ColorizerTester::resetColorSimple(std::ostream& stream) +{ + stream << this->Colorizer::getResetColor_(); +} + +void ColorizerTester::outputToStreamSimple(std::ostream& o_stream){ + + /// color the stream (or console) + ColorizerTester::colorStreamSimple(o_stream); + + // paste text + o_stream << this->Colorizer::getInput(); //resolve + + // if flag reset is set: reset comand line. else dont reset. + if (this->Colorizer::getReset()) + { + ColorizerTester::resetColorSimple(o_stream); + } + +} + + } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 09e01425cd7..cab60fcb6d6 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -141,17 +141,17 @@ START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified c.colorStreamSimple(test_stream); TEST_EQUAL(test_stream.str(), blackANSI) - //with text - test_stream.str(string()); - test_stream.clear(); + // //with text + // test_stream.str(string()); + // test_stream.clear(); - test_stream << c(test_string); - c.colorStream_(test_stream); - TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) + // test_stream << c(test_string); + // c.colorStreamSimple(test_stream); + // TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) } END_SECTION -// START_SECTION(Colorizer::colorStream(ostream& stream) const) +// START_SECTION(Colorizer::colorStream(ostream& stream) const) //old of above // { // //without text // stringstream test_stream; @@ -189,16 +189,18 @@ END_SECTION // } // END_SECTION -// START_SECTION(Colorizer::resetColor(ostream& stream)) -// { -// stringstream test_stream; -// ColorizerMethodsTester c(Color::GREEN); +START_SECTION(Colorizer::resetColor(ostream& stream)) +{ + stringstream test_stream; + ColorizerTester c(Color::GREEN); -// test_stream << c(test_string); -// c.resetColor_(test_stream); -// TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) -// } -// END_SECTION + test_stream << c(test_string); + c.resetColorSimple(test_stream); + // TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) + TEST_EQUAL(test_stream.str(), test_string+resetColorANSI) //delete later + +} +END_SECTION // START_SECTION(Colorizer::getDataAsString()) // { From ac7b4a357ea374df0b576ccc457457fed7ca7515 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 28 Sep 2022 22:44:30 +0200 Subject: [PATCH 27/31] ResetColorSimple working but codes are being fed in wrong order --- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 9 ++- src/openms/source/APPLICATIONS/TOPPBase.cpp | 26 +++++- src/openms/source/CONCEPT/Colorizer.cpp | 17 ++-- .../openms/source/Colorizer_test.cpp | 81 ++++++++++--------- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index 64195a81352..f2b93462a82 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -132,9 +132,12 @@ friend class ConsoleUtils; return this->reset_; } - std::stringstream getInput() + std::string getInput() { - return this->input_; + std::stringstream input_out; + input_out << input_.rdbuf(); + + return input_out.str(); } const char* getColor_() @@ -249,7 +252,7 @@ class OPENMS_DLLAPI ColorizerTester: public Colorizer // bool getReset_(); - std::string getDataAsStringSimple(); + // std::string getDataAsStringSimple(); //not needed }; } diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index b99c8db267f..75c6dc325aa 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -337,11 +337,31 @@ namespace OpenMS hui.colorStreamSimple(doughnut); doughnut << hui(" UUUUUUUUU "); writeLog_(doughnut.str()); + + hui.resetColorSimple(doughnut); + doughnut << hui(" RRRRRRRR "); + writeLog_(doughnut.str()); + doughnut.str(string()); + doughnut.clear(); - ColorizerTester mui(Color::GREEN); - hui.outputToStreamSimple(doughnut); - doughnut << hui(" UUUUUUUUU "); + ColorizerTester fui(Color::GREEN); + fui.outputToStreamSimple(doughnut); + writeLog_(doughnut.str()); + doughnut.str(string()); + doughnut.clear(); + + ColorizerTester mui(Color::YELLOW); + mui(); //resets + doughnut << mui(" AAAAAAAAA "); + mui.outputToStreamSimple(doughnut); + writeLog_(doughnut.str()); + doughnut.str(string()); + doughnut.clear(); + + + + diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 9ce0caedc30..4e803d78d85 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -161,9 +161,12 @@ namespace OpenMS o_stream << this->input_.str(); // if flag reset is set: reset comand line. else dont reset. + + // std::cout<< " |Col reset is A " << this->reset_; //delete if (this->reset_) { resetColor(o_stream); + // std::cout<< " |Col reset is B " << this->reset_; //delete } } @@ -269,13 +272,17 @@ void ColorizerTester::outputToStreamSimple(std::ostream& o_stream){ ColorizerTester::colorStreamSimple(o_stream); // paste text - o_stream << this->Colorizer::getInput(); //resolve + o_stream << this->Colorizer::getInput(); + std::cout << " input is: " << this->Colorizer::getInput();//delete + // std::cout<< "reset simple A is " << this->Colorizer::getReset(); //delete // if flag reset is set: reset comand line. else dont reset. - if (this->Colorizer::getReset()) - { - ColorizerTester::resetColorSimple(o_stream); - } + // if (this->Colorizer::getReset()) + // { + + // ColorizerTester::resetColorSimple(o_stream); + // std::cout<< "reset simple B is " << this->Colorizer::getReset(); //delete + // } } diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index cab60fcb6d6..971acaf521e 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -132,76 +132,77 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY #endif -START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified -{ - //without text - stringstream test_stream; - ColorizerTester c(Color::BLACK); - - c.colorStreamSimple(test_stream); - TEST_EQUAL(test_stream.str(), blackANSI) - - // //with text - // test_stream.str(string()); - // test_stream.clear(); - - // test_stream << c(test_string); - // c.colorStreamSimple(test_stream); - // TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) -} -END_SECTION - -// START_SECTION(Colorizer::colorStream(ostream& stream) const) //old of above +// START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified // { // //without text // stringstream test_stream; -// Colorizer::ColorizerTester c(Color::BLACK); +// ColorizerTester c(Color::BLACK); -// c.colorStream_(test_stream); +// c.colorStreamSimple(test_stream); // TEST_EQUAL(test_stream.str(), blackANSI) -// //with text -// test_stream.str(string()); -// test_stream.clear(); +// // //with text +// // test_stream.str(string()); +// // test_stream.clear(); -// test_stream << c(test_string); -// c.colorStream_(test_stream); -// TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) +// // test_stream << c(test_string); +// // c.colorStreamSimple(test_stream); +// // TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) // } // END_SECTION -// START_SECTION(Colorizer::outputToStream(ostream& o_stream)) +// START_SECTION(Colorizer::colorStream(ostream& stream) const) //old of above // { // //without text // stringstream test_stream; -// ColorizerMethodsTester c(Color::CYAN); +// Colorizer::ColorizerTester c(Color::BLACK); -// c.outputToStream_(test_stream); -// TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) +// c.colorStream_(test_stream); +// TEST_EQUAL(test_stream.str(), blackANSI) // //with text // test_stream.str(string()); // test_stream.clear(); // test_stream << c(test_string); -// c.outputToStream_(test_stream); -// TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) +// c.colorStream_(test_stream); +// TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) // } // END_SECTION -START_SECTION(Colorizer::resetColor(ostream& stream)) +START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { + //without text stringstream test_stream; - ColorizerTester c(Color::GREEN); + ColorizerTester c(Color::CYAN); - test_stream << c(test_string); - c.resetColorSimple(test_stream); - // TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) - TEST_EQUAL(test_stream.str(), test_string+resetColorANSI) //delete later + c(); + c.outputToStreamSimple(test_stream); + TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) + + //with text + // test_stream.str(string()); + // test_stream.clear(); + // test_stream << c(test_string); + // c.outputToStream_(test_stream); + // TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) } END_SECTION +// START_SECTION(Colorizer::resetColor(ostream& stream)) +// { +// stringstream test_stream; +// ColorizerTester c(Color::GREEN); + +// test_stream << c(test_string); +// c.resetColorSimple(test_stream); +// // TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) +// TEST_EQUAL(test_stream.str(), test_string+resetColorANSI) //delete later + +// } +// END_SECTION + // START_SECTION(Colorizer::getDataAsString()) // { // stringstream test_stream; From 989e6617e690f94725985a41ad1dc1a4520a7439 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Wed, 28 Sep 2022 23:27:39 +0200 Subject: [PATCH 28/31] FIRST WORKING TEST --- src/openms/source/APPLICATIONS/TOPPBase.cpp | 2 +- src/openms/source/CONCEPT/Colorizer.cpp | 10 +++++----- src/tests/class_tests/openms/source/Colorizer_test.cpp | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 75c6dc325aa..942b6ed6304 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -352,7 +352,7 @@ namespace OpenMS ColorizerTester mui(Color::YELLOW); mui(); //resets - doughnut << mui(" AAAAAAAAA "); + doughnut << mui(" AAAjhjhAAA "); mui.outputToStreamSimple(doughnut); writeLog_(doughnut.str()); diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 4e803d78d85..18b2106e07c 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -273,16 +273,16 @@ void ColorizerTester::outputToStreamSimple(std::ostream& o_stream){ // paste text o_stream << this->Colorizer::getInput(); - std::cout << " input is: " << this->Colorizer::getInput();//delete + // std::cout << " input is: " << this->Colorizer::getInput();//delete // std::cout<< "reset simple A is " << this->Colorizer::getReset(); //delete // if flag reset is set: reset comand line. else dont reset. - // if (this->Colorizer::getReset()) - // { + if (this->Colorizer::getReset()) + { - // ColorizerTester::resetColorSimple(o_stream); + ColorizerTester::resetColorSimple(o_stream); // std::cout<< "reset simple B is " << this->Colorizer::getReset(); //delete - // } + } } diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index 971acaf521e..d80fe1c313b 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -175,17 +175,18 @@ START_SECTION(Colorizer::outputToStream(ostream& o_stream)) //without text stringstream test_stream; ColorizerTester c(Color::CYAN); - - c(); + //c(); c.outputToStreamSimple(test_stream); TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) + TEST_EQUAL(test_stream.str().find(cyanANSI) != std::string::npos,1) + TEST_EQUAL(test_stream.str().find(resetColorANSI) != std::string::npos,1) - //with text + //// with text // test_stream.str(string()); // test_stream.clear(); // test_stream << c(test_string); - // c.outputToStream_(test_stream); + // c.outputToStreamSimple(test_stream); // TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) } END_SECTION From 733d62e70bf9696369785c18d1a40df13d71ad2b Mon Sep 17 00:00:00 2001 From: tetak94 Date: Thu, 29 Sep 2022 00:17:00 +0200 Subject: [PATCH 29/31] Working Colorizer_test apart from instances red() --- src/openms/source/APPLICATIONS/TOPPBase.cpp | 12 +- .../openms/source/Colorizer_test.cpp | 146 ++++++------------ 2 files changed, 56 insertions(+), 102 deletions(-) diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index 942b6ed6304..e2919fe2843 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -351,11 +351,15 @@ namespace OpenMS doughnut.clear(); ColorizerTester mui(Color::YELLOW); - mui(); //resets - doughnut << mui(" AAAjhjhAAA "); - mui.outputToStreamSimple(doughnut); + // mui(); //resets + cout << mui(); + // mui.outputToStreamSimple(doughnut); + // doughnut.str(string()); + // doughnut.clear(); - writeLog_(doughnut.str()); + // writeLog_(doughnut.str()); + writeLog_("bitch"); + doughnut.str(string()); doughnut.clear(); diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index d80fe1c313b..f16414af986 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -58,43 +58,6 @@ string convertToString ( T var_input ) return ss.str(); } - -// class ColorizerMethodsTester: public Colorizer -// { - -// public: - -// ///Constructor -// // ColorizerMethodsTester(const Color color); -// // ColorizerMethodsTester(const Color color): Colorizer(color){}; - -// // /// Default destructor -// // ~ColorizerMethodsTester(); - - - -// ///Constructor -// // ColorizerMethodsTester(const Color color); -// ColorizerMethodsTester(const Color color) : Colorizer(color){}; - -// /// Default destructor -// ~ColorizerMethodsTester(){ -// #if defined(__linux__) || defined(__OSX__) -// std::cout << "\e[0m"; //doesn't do anything -// #endif -// } - - -// void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} - -// void colorStream_(std::ostream& stream) const{this->colorStream(stream);} - -// void resetColor_(std::ostream& stream){this->resetColor(stream);} - -// std::string getDataAsString_(){return this->getDataAsString();} -// }; - - START_TEST(Colorizer(),"$Id$") //Test variables @@ -132,43 +95,25 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY #endif -// START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified -// { -// //without text -// stringstream test_stream; -// ColorizerTester c(Color::BLACK); - -// c.colorStreamSimple(test_stream); -// TEST_EQUAL(test_stream.str(), blackANSI) - -// // //with text -// // test_stream.str(string()); -// // test_stream.clear(); - -// // test_stream << c(test_string); -// // c.colorStreamSimple(test_stream); -// // TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) -// } -// END_SECTION +START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified +{ + //without text + stringstream test_stream; + ColorizerTester c(Color::BLACK); -// START_SECTION(Colorizer::colorStream(ostream& stream) const) //old of above -// { -// //without text -// stringstream test_stream; -// Colorizer::ColorizerTester c(Color::BLACK); + c.colorStreamSimple(test_stream); + TEST_EQUAL(test_stream.str(), blackANSI) -// c.colorStream_(test_stream); -// TEST_EQUAL(test_stream.str(), blackANSI) + //with text + test_stream.str(string()); + test_stream.clear(); -// //with text -// test_stream.str(string()); -// test_stream.clear(); + test_stream << c(test_string); + c.colorStreamSimple(test_stream); + TEST_EQUAL(test_stream.str(),test_string+blackANSI) +} +END_SECTION -// test_stream << c(test_string); -// c.colorStream_(test_stream); -// TEST_EQUAL(test_stream.str(),blackANSI+test_string+resetColorANSI+blackANSI) -// } -// END_SECTION START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { @@ -178,42 +123,47 @@ START_SECTION(Colorizer::outputToStream(ostream& o_stream)) //c(); c.outputToStreamSimple(test_stream); TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) - TEST_EQUAL(test_stream.str().find(cyanANSI) != std::string::npos,1) - TEST_EQUAL(test_stream.str().find(resetColorANSI) != std::string::npos,1) + + + // with text + test_stream.str(string()); + test_stream.clear(); + + test_stream << c(test_string); + c.outputToStreamSimple(test_stream); + + TEST_EQUAL(test_stream.str(),test_string+cyanANSI+test_string+resetColorANSI) //modified TEST_EQUAL + + + TEST_EQUAL(test_stream.str().find(cyanANSI) != std::string::npos,1) //delete + TEST_EQUAL(test_stream.str().find(resetColorANSI) != std::string::npos,1) //delete + TEST_EQUAL(test_stream.str().find(test_string) != std::string::npos,1) //delete - //// with text - // test_stream.str(string()); - // test_stream.clear(); - // test_stream << c(test_string); - // c.outputToStreamSimple(test_stream); - // TEST_EQUAL(test_stream.str(),cyanANSI+test_string+resetColorANSI+cyanANSI+test_string+resetColorANSI) } END_SECTION -// START_SECTION(Colorizer::resetColor(ostream& stream)) -// { -// stringstream test_stream; -// ColorizerTester c(Color::GREEN); - -// test_stream << c(test_string); -// c.resetColorSimple(test_stream); -// // TEST_EQUAL(test_stream.str(), greenANSI+test_string+resetColorANSI+resetColorANSI) -// TEST_EQUAL(test_stream.str(), test_string+resetColorANSI) //delete later +START_SECTION(Colorizer::resetColor(ostream& stream)) +{ + stringstream test_stream; + ColorizerTester c(Color::GREEN); -// } -// END_SECTION + test_stream << c(test_string); + c.resetColorSimple(test_stream); + TEST_EQUAL(test_stream.str(), test_string+resetColorANSI) +} +END_SECTION -// START_SECTION(Colorizer::getDataAsString()) -// { -// stringstream test_stream; -// ColorizerMethodsTester c(Color::RED); +START_SECTION(Colorizer::getDataAsString()) +{ + stringstream test_stream; + ColorizerTester c(Color::RED); -// test_stream << c(test_string); -// test_stream << c.getDataAsString_(); -// TEST_EQUAL(test_stream.str(), redANSI+test_string+resetColorANSI+test_string) -// } -// END_SECTION + test_stream << c(test_string); + test_stream << c.getDataAsString_(); + TEST_EQUAL(test_stream.str(), test_string+test_string) +} +END_SECTION // START_SECTION(Colorizer::reset()) // { From 7c81896e6092ae4f3d98048f1de00f434c94a693 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Fri, 30 Sep 2022 00:51:55 +0200 Subject: [PATCH 30/31] Working Colorizer test with supress coloring, needs code cleaning --- src/openms/source/APPLICATIONS/TOPPBase.cpp | 8 + .../openms/source/Colorizer_test.cpp | 255 +++++++----------- 2 files changed, 108 insertions(+), 155 deletions(-) diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index e2919fe2843..adb976dcea2 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -360,9 +360,17 @@ namespace OpenMS // writeLog_(doughnut.str()); writeLog_("bitch"); + doughnut << mui(); + doughnut << " sometext "; + writeLog_(doughnut.str()); + doughnut.str(string()); doughnut.clear(); + doughnut << mui(" blackshite "); + writeLog_(doughnut.str()); + + diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index f16414af986..d5db7796250 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -95,7 +95,7 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY #endif -START_SECTION(Colorizer::colorStream(ostream& stream) const) //modified +START_SECTION(Colorizer::colorStream(ostream& stream) const) { //without text stringstream test_stream; @@ -133,13 +133,6 @@ START_SECTION(Colorizer::outputToStream(ostream& o_stream)) c.outputToStreamSimple(test_stream); TEST_EQUAL(test_stream.str(),test_string+cyanANSI+test_string+resetColorANSI) //modified TEST_EQUAL - - - TEST_EQUAL(test_stream.str().find(cyanANSI) != std::string::npos,1) //delete - TEST_EQUAL(test_stream.str().find(resetColorANSI) != std::string::npos,1) //delete - TEST_EQUAL(test_stream.str().find(test_string) != std::string::npos,1) //delete - - } END_SECTION @@ -179,153 +172,105 @@ END_SECTION // } // END_SECTION -// START_SECTION("Testing Colorizer instances") -// { -// //Check that the colorized input contains the original text and according ASCI codes - -// stringstream colored_stream; - -// colored_stream << black(test_string); -// TEST_EQUAL(colored_stream.str(), blackANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << red(test_string); -// TEST_EQUAL(colored_stream.str(), redANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << green(test_string); -// TEST_EQUAL(colored_stream.str(), greenANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << yellow(test_string); -// TEST_EQUAL(colored_stream.str(), yellowANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << blue(test_string); -// TEST_EQUAL(colored_stream.str(), blueANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << magenta(test_string); -// TEST_EQUAL(colored_stream.str(), magentaANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << cyan(test_string); -// TEST_EQUAL(colored_stream.str(), cyanANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); - -// colored_stream << white(test_string); -// TEST_EQUAL(colored_stream.str(), whiteANSI+test_string+resetColorANSI) -// colored_stream.str(string()); -// colored_stream.clear(); -// } -// END_SECTION - -// //testing various inputs for colorizing -// START_SECTION("Testing Colorizer inputs") -// { -// stringstream colored_stream; -// string comparison_string; - -// //char//////////////////////////////////// -// colored_stream << yellow(test_char); -// comparison_string.append(yellowANSI); -// comparison_string.append(convertToString(test_char)); -// comparison_string.append(resetColorANSI); -// TEST_EQUAL(colored_stream.str(), comparison_string) - -// //clearing streams -// colored_stream.str(string()); -// colored_stream.clear(); -// comparison_string = ""; - -// //int/////////////////////////////// -// colored_stream << green(test_int); -// comparison_string.append(greenANSI); -// comparison_string.append(convertToString(test_int)); -// comparison_string.append(resetColorANSI); -// TEST_EQUAL(colored_stream.str(), comparison_string) - -// //clearing streams -// colored_stream.str(string()); -// colored_stream.clear(); -// comparison_string = ""; - -// //float/////////////////////////////// -// colored_stream << red(test_float); -// comparison_string.append(redANSI); -// comparison_string.append(convertToString(test_float)); -// comparison_string.append(resetColorANSI); -// TEST_EQUAL(colored_stream.str(), comparison_string) - -// //clearing streams -// colored_stream.str(string()); -// colored_stream.clear(); -// comparison_string = ""; -// } -// END_SECTION - -// START_SECTION(Colorizer& operator()()) -// { -// stringstream test_stream; -// test_stream << green() -// << "green text" -// << 123 << "!" -// << " " -// << magenta() -// << "magenta text" -// << green.reset() -// << "default text" -// << magenta.reset() -// << "default text"; -// TEST_EQUAL(test_stream.str(),greenANSI -// +"green text123! " -// +magentaANSI -// +"magenta text" -// +greenANSI+resetColorANSI -// +"default text" -// +magentaANSI+resetColorANSI -// +"default text") - -// } -// END_SECTION - -///OLD:DELETE BELOW - -// START_SECTION("See if stream is a tty or a file") -// { -// stringstream test_stream; -// ofstream test_file("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/testingthis.txt"); - -// cout << 1; -// test_stream << cyan("SOMECYANTEXT1"); -// TEST_EQUAL(test_stream.str(),cyanANSI+"SOMECYANTEXT"+resetColorANSI) - -// TEST_EQUAL(isatty(STDIN_FILENO), 1); //is a tty -// TEST_EQUAL(isatty(STDOUT_FILENO), 0); //is a tty -// TEST_EQUAL(isatty(STDERR_FILENO), 0); //is a tty - -// freopen("/buffer/ag_bsc/pmsb_22/tetak94/stuff/testclass/ANSI.txt", "w", stdout); -// cout< -// //outputs are written somewhere else and checked, so STDOUT is always 0 -// //teste is elsewhere -> make a new file and use colorizer there, or maybe -// //use console_utils/colorizer output to generate isatty values in different places -// } -// END_SECTION +//testing various inputs for colorizing +START_SECTION("Testing Colorizer inputs") +{ + stringstream colored_stream; + string comparison_string; + + //char//////////////////////////////////// + colored_stream << yellow(test_char); + comparison_string.append(convertToString(test_char)); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //int/////////////////////////////// + colored_stream << green(test_int); + comparison_string.append(convertToString(test_int)); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; + + //float/////////////////////////////// + colored_stream << red(test_float); + comparison_string.append(convertToString(test_float)); + TEST_EQUAL(colored_stream.str(), comparison_string) + + //clearing streams + colored_stream.str(string()); + colored_stream.clear(); + comparison_string = ""; +} +END_SECTION -END_TEST +START_SECTION(Colorizer& operator()()) +{ + stringstream test_stream; + test_stream << green() + << "green text" + << 123 << "!" + << " "; + TEST_EQUAL(test_stream.str(),"green text123! ") +} +END_SECTION - \ No newline at end of file +END_TEST \ No newline at end of file From 97c308cd65f28cc431da28382bdd4462fe060f15 Mon Sep 17 00:00:00 2001 From: tetak94 Date: Fri, 30 Sep 2022 01:24:55 +0200 Subject: [PATCH 31/31] finished Colorizer, ConsoleUtils Unit tests, ready for PR --- .../OpenMS/APPLICATIONS/ConsoleUtils.h | 4 +- src/openms/include/OpenMS/CONCEPT/Colorizer.h | 16 +-- .../source/APPLICATIONS/ConsoleUtils.cpp | 10 -- src/openms/source/APPLICATIONS/TOPPBase.cpp | 127 ------------------ src/openms/source/CONCEPT/Colorizer.cpp | 80 +---------- .../openms/source/Colorizer_test.cpp | 57 ++++---- .../openms/source/ConsoleUtils_test.cpp | 1 - 7 files changed, 41 insertions(+), 254 deletions(-) diff --git a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h index bb2705a8315..abb81fde9f5 100644 --- a/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h +++ b/src/openms/include/OpenMS/APPLICATIONS/ConsoleUtils.h @@ -76,9 +76,7 @@ namespace OpenMS const Size max_lines, const Size curser_pos = 0); - -//implement new function breakStringList - returns broken StringList - const int getConsoleSize() + int getConsoleSize() //deleted const here { return console_width_; } diff --git a/src/openms/include/OpenMS/CONCEPT/Colorizer.h b/src/openms/include/OpenMS/CONCEPT/Colorizer.h index f2b93462a82..51f7e6b6719 100644 --- a/src/openms/include/OpenMS/CONCEPT/Colorizer.h +++ b/src/openms/include/OpenMS/CONCEPT/Colorizer.h @@ -150,7 +150,6 @@ friend class ConsoleUtils; } private: - // const int color_; /// input in Colorizer object to be colored std::stringstream input_; @@ -200,12 +199,6 @@ friend class ConsoleUtils; OpenMS::Colorizer& col); - - -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// class OPENMS_DLLAPI ColorizerTester: public Colorizer /*only used in Colorizer_test.cpp for testing Colorizer method @@ -226,14 +219,12 @@ class OPENMS_DLLAPI ColorizerTester: public Colorizer public: ///Constructor - // ColorizerTester(const Color color); ColorizerTester(const Color color) : Colorizer(color){}; - /// Default destructor ~ColorizerTester(){}; - //original methods revealing functionality for public use + //Colorizer methods encapsulated for unit test void outputToStream_(std::ostream& o_stream){this->outputToStream(o_stream);} void colorStream_(std::ostream& stream) const{this->colorStream(stream);} @@ -243,16 +234,13 @@ class OPENMS_DLLAPI ColorizerTester: public Colorizer std::string getDataAsString_(){return this->getDataAsString();} - //modified methods for stringstream instead of cerr/cout + //modified methods of Colorizer that work for stringstream instead of cerr/cout void outputToStreamSimple(std::ostream& o_stream); void colorStreamSimple(std::ostream& stream); void resetColorSimple(std::ostream& stream); - // bool getReset_(); - - // std::string getDataAsStringSimple(); //not needed }; } diff --git a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp index c6ffd16fbb8..dc94b300024 100644 --- a/src/openms/source/APPLICATIONS/ConsoleUtils.cpp +++ b/src/openms/source/APPLICATIONS/ConsoleUtils.cpp @@ -81,8 +81,6 @@ namespace OpenMS ConsoleUtils::ConsoleUtils(ConsoleUtils const& other) = default; void ConsoleUtils::operator=(const ConsoleUtils& other) {}; - // void ConsoleUtils::operator=(const ConsoleUtils& other) = default; - // void ConsoleUtils::operator=(const ConsoleUtils& other); OpenMS::String ConsoleUtils::breakString(const String& input, const Size indentation, @@ -187,17 +185,12 @@ namespace OpenMS return instance; } -//erweitern, mit aktueller curser position -// rückgabe: vector von strings -// (OpenMS::StringList) OpenMS::StringList ConsoleUtils::breakString_(const OpenMS::String& input, const Size indentation, const Size max_lines, const Size curser_pos) { - //OpenMS::StringList list; - //list.clear(); // get the line length Int line_len = ConsoleUtils::readConsoleSize_(); @@ -216,7 +209,6 @@ namespace OpenMS return result; } - for (Size i = 0; i < input.size(); ) { String line = input.substr(i, result.empty() ? line_len : short_line_len); @@ -300,7 +292,5 @@ int getCerrColor() } #endif - - } diff --git a/src/openms/source/APPLICATIONS/TOPPBase.cpp b/src/openms/source/APPLICATIONS/TOPPBase.cpp index adb976dcea2..dc4afcb929f 100755 --- a/src/openms/source/APPLICATIONS/TOPPBase.cpp +++ b/src/openms/source/APPLICATIONS/TOPPBase.cpp @@ -114,51 +114,6 @@ namespace OpenMS return tool_name_ + ":" + instance_number_ + ":"; } - - ///////////////////DETELE THIS!!!!!!!!!!!!//////////////////// - class PleaseWork: public Colorizer - { - // private: - // const int color_; - - - public: - - // //Constructor - // ColorizerMethodsTester(const Color color); - - - PleaseWork(const Color color) : Colorizer(color){}; //old - // PleaseWork(const Color color) : color_((int)color){} - - /// Default destructor - ~PleaseWork(){ - // #if defined(__linux__) || defined(__OSX__) - // std::cout << "\e[0m"; //doesn't do anything - // #endif - } - - // ///Constructor - // PleaseWork(const Color color); - - // /// Default destructor - // ~PleaseWork(); - - - void outputToStream_(std::ostream& o_stream){ - this->outputToStream(o_stream); - } - - void colorStream_(std::ostream& stream) const{this->colorStream(stream);} - - void resetColor_(std::ostream& stream){this->resetColor(stream);} - - std::string getDataAsString_(){return this->getDataAsString();} - }; - - ///////////////////DETELE THIS!!!!!!!!!!!!//////////////////// - - TOPPBase::TOPPBase(const String& tool_name, const String& tool_description, bool official, const std::vector& citations, bool toolhandler_test) : tool_name_(tool_name), tool_description_(tool_description), @@ -297,88 +252,6 @@ namespace OpenMS // test if no options were given if (argc == 1) { - - ////DETELE THIS!!!!!!////////////////////// - //object 1 - stringstream doughnut; - PleaseWork c(Color::BLUE); - c.colorStream_(doughnut); //colorizing blue - writeLog_(doughnut.str()); - doughnut.str(string()); - doughnut.clear(); - - doughnut << c("ABCDE"); //entering text - c.colorStream_(doughnut); //coloring text - writeLog_(doughnut.str()); - doughnut.str(string()); - doughnut.clear(); - - - //make doughnut stream of type cout/cerr - - // object 2 - PleaseWork a(Color::YELLOW); - a.outputToStream_(doughnut); //colorizing red - writeLog_(doughnut.str()); - doughnut.str(string()); - doughnut.clear(); - - doughnut << a("ABCDE"); //entering text - a.outputToStream_(doughnut); //coloring text - doughnut << a("YIHHA"); //entering text - writeLog_(doughnut.str()); - - cout << &doughnut; - - doughnut.str(string()); - doughnut.clear(); - - ColorizerTester hui(Color::CYAN); - hui.colorStreamSimple(doughnut); - doughnut << hui(" UUUUUUUUU "); - writeLog_(doughnut.str()); - - hui.resetColorSimple(doughnut); - doughnut << hui(" RRRRRRRR "); - writeLog_(doughnut.str()); - doughnut.str(string()); - doughnut.clear(); - - ColorizerTester fui(Color::GREEN); - fui.outputToStreamSimple(doughnut); - writeLog_(doughnut.str()); - doughnut.str(string()); - doughnut.clear(); - - ColorizerTester mui(Color::YELLOW); - // mui(); //resets - cout << mui(); - // mui.outputToStreamSimple(doughnut); - // doughnut.str(string()); - // doughnut.clear(); - - // writeLog_(doughnut.str()); - writeLog_("bitch"); - - doughnut << mui(); - doughnut << " sometext "; - writeLog_(doughnut.str()); - - doughnut.str(string()); - doughnut.clear(); - - doughnut << mui(" blackshite "); - writeLog_(doughnut.str()); - - - - - - - - - ////DETELE THIS!!!!!!////////////////////// - cout << red(); writeLog_("No options given. Aborting!"); cout << red.reset(); diff --git a/src/openms/source/CONCEPT/Colorizer.cpp b/src/openms/source/CONCEPT/Colorizer.cpp index 18b2106e07c..3604cf9bde5 100644 --- a/src/openms/source/CONCEPT/Colorizer.cpp +++ b/src/openms/source/CONCEPT/Colorizer.cpp @@ -54,9 +54,7 @@ namespace OpenMS { // if colorizer object is destroyed, set console color back to def col. #if defined(__linux__) || defined(__OSX__) - std::cout << colors_[int(Color::RESET)]; //check - // std::cout << resetColor(cout); - // std::cerr << resetColor(cerr); + std::cout << colors_[int(Color::RESET)]; #endif } @@ -79,20 +77,13 @@ namespace OpenMS #elif defined(__linux__) || defined(__OSX__) //check if the output is being fed to file or console //supress output of ANSI codes into the file - // stream << " ...S HOHOHOHO E..." - // << " coutNR: " << &std::cout - // << " streamNR " << &stream - // << " cerrNR: " << &std::cerr; //delete - - + if (&std::cout == &stream) { - // stream << this->colors_[this->color_]; //delete if(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)) { //write coloring escape codes into the string stream << this->colors_[this->color_]; - // stream << "\033[33m"; //delete } } else if (&std::cerr == &stream) @@ -178,12 +169,6 @@ namespace OpenMS return *this; } - /// - // bool Colorizer::getReset() - // { - // return this->reset_; - // } - // overload the shift operator (<<) std::ostream& operator<<(std::ostream& o_stream, OpenMS::Colorizer& col) @@ -204,58 +189,8 @@ namespace OpenMS OpenMS::Colorizer cyan(Color::CYAN); OpenMS::Colorizer white(Color::WHITE); -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////// - -// class ColorizerTester: public Colorizer - -// /*only used in Colorizer_test.cpp for testing Colorizer method -// functionality. While using Colorizer instances, only cout or cerr -// streams are being colorized. - -// Methods with underscore "_" at the name end are used to -// reveal functionality of protected class functions in the unit test. - -// For separate Colorizer method testing, stringstreams are used instead. -// This class modified these methods to use Colorizer functionality on -// stringstreams instead of cout/cerr streams. Such methods have "Simple" -// attached to the method name. - -// This class should not be used outside Colorizer_test.cpp -// */ -// { -// public: - -// ///Constructor -// ColorizerTester(const Color color); - -// /// Default destructor -// ~ColorizerTester(); - -// //original methods revealing functionality for public use -// void outputToStream_(std::ostream& o_stream); - -// void colorStream_(std::ostream& stream); - -// void resetColor_(std::ostream& stream); - -// std::string getDataAsString_(); - - -// //modified methods for stringstream instead of cerr/cout -// void outputToStreamSimple(std::ostream& o_stream); - -// void colorStreamSimple(std::ostream& stream); - -// void resetColorSimple(std::ostream& stream); - -// // bool getReset_(); - -// std::string getDataAsStringSimple(); -// }; +//ColorizerTester methods for unit test void ColorizerTester::colorStreamSimple(std::ostream& stream) { stream << this->Colorizer::getColor_(); @@ -273,19 +208,12 @@ void ColorizerTester::outputToStreamSimple(std::ostream& o_stream){ // paste text o_stream << this->Colorizer::getInput(); - // std::cout << " input is: " << this->Colorizer::getInput();//delete - - // std::cout<< "reset simple A is " << this->Colorizer::getReset(); //delete + // if flag reset is set: reset comand line. else dont reset. if (this->Colorizer::getReset()) { - ColorizerTester::resetColorSimple(o_stream); - // std::cout<< "reset simple B is " << this->Colorizer::getReset(); //delete } } - - - } // namespace OpenMS diff --git a/src/tests/class_tests/openms/source/Colorizer_test.cpp b/src/tests/class_tests/openms/source/Colorizer_test.cpp index d5db7796250..14c838f3e53 100644 --- a/src/tests/class_tests/openms/source/Colorizer_test.cpp +++ b/src/tests/class_tests/openms/source/Colorizer_test.cpp @@ -97,6 +97,11 @@ string test_string = " !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY START_SECTION(Colorizer::colorStream(ostream& stream) const) { + /*modified ColorizerTester method used for colorisation + of stringstreams instead of cerr/cour for the purpose of + testing + */ + //without text stringstream test_stream; ColorizerTester c(Color::BLACK); @@ -117,14 +122,17 @@ END_SECTION START_SECTION(Colorizer::outputToStream(ostream& o_stream)) { + /*modified ColorizerTester method used for colorisation + of stringstreams instead of cerr/cour for the purpose of + testing + */ + //without text stringstream test_stream; ColorizerTester c(Color::CYAN); - //c(); c.outputToStreamSimple(test_stream); TEST_EQUAL(test_stream.str(), cyanANSI+resetColorANSI) - // with text test_stream.str(string()); test_stream.clear(); @@ -132,12 +140,17 @@ START_SECTION(Colorizer::outputToStream(ostream& o_stream)) test_stream << c(test_string); c.outputToStreamSimple(test_stream); - TEST_EQUAL(test_stream.str(),test_string+cyanANSI+test_string+resetColorANSI) //modified TEST_EQUAL + TEST_EQUAL(test_stream.str(),test_string+cyanANSI+test_string+resetColorANSI) } END_SECTION START_SECTION(Colorizer::resetColor(ostream& stream)) { + /*modified ColorizerTester method used for colorisation + of stringstreams instead of cerr/cour for the purpose of + testing + */ + stringstream test_stream; ColorizerTester c(Color::GREEN); @@ -158,24 +171,19 @@ START_SECTION(Colorizer::getDataAsString()) } END_SECTION -// START_SECTION(Colorizer::reset()) -// { -// stringstream test_stream; -// test_stream << green() -// << "green text" << 89 << "$" << " " -// << green.reset() << "default text" << red() << 11 << red.reset() << "A"; -// TEST_EQUAL(test_stream.str(),greenANSI -// +"green text89$ " -// +greenANSI+resetColorANSI -// +"default text" -// +redANSI+"11"+redANSI+resetColorANSI+"A") -// } -// END_SECTION +START_SECTION(Colorizer::reset()) +{ + NOT_TESTABLE + //due to cerr/cout output supression in this test file, colorisation is not working +} +END_SECTION START_SECTION("Testing Colorizer instances") -{ - //Check that the colorized input contains the original text and according ASCI codes + /*Check that the colorized input contains the original text. + Insertion of ANSI codes is supressed so only test insertion is testable. + */ +{ stringstream colored_stream; colored_stream << black(test_string); @@ -183,10 +191,6 @@ START_SECTION("Testing Colorizer instances") colored_stream.str(string()); colored_stream.clear(); - // TEST_EQUAL(colored_stream.str().find(blackANSI) != std::string::npos,1) //no - // TEST_EQUAL(colored_stream.str().find(resetColorANSI) != std::string::npos,1) //no - // TEST_EQUAL(colored_stream.str().find(test_string) != std::string::npos,1) //yes delete - colored_stream << red(test_string); TEST_EQUAL(colored_stream.str(), test_string) colored_stream.str(string()); @@ -224,8 +228,11 @@ START_SECTION("Testing Colorizer instances") } END_SECTION -//testing various inputs for colorizing START_SECTION("Testing Colorizer inputs") + /* + Testing various inputs for colorizing + Insertion of ANSI codes is supressed so only test insertion is testable. + */ { stringstream colored_stream; string comparison_string; @@ -263,6 +270,10 @@ START_SECTION("Testing Colorizer inputs") END_SECTION START_SECTION(Colorizer& operator()()) + /* + Testing ()operator for colorising + Insertion of ANSI codes is supressed so only test insertion is testable. + */ { stringstream test_stream; test_stream << green() diff --git a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp index 1120d9005d8..3b33ae08c17 100644 --- a/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp +++ b/src/tests/class_tests/openms/source/ConsoleUtils_test.cpp @@ -103,7 +103,6 @@ START_SECTION((static OpenMS::String breakString(const String& input, const Size max_lines, const Size curser_pos = 0))) { - // we cannot predict which shape the broken string will have, so testing is rather limited // we cannot predict which shape the broken string will have, so testing is rather limited String test_string = "This is a test string which should be broken up into multiple lines."; String broken_string = ConsoleUtils::breakString(test_string, 0, 10);