├── .github └── workflows │ ├── coverage_report.yml │ ├── cpp_ubuntu20_04.yml │ └── deploy_coverage_report.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── cmake └── Findglog.cmake ├── docs └── Log++.svg ├── include └── log++.h ├── package.xml ├── src └── demo.cpp └── test ├── common ├── async_tests.h └── test_utils.h ├── default ├── test_common.cc ├── test_default_basic.cc ├── test_default_every_n.cc ├── test_default_first_n.cc ├── test_default_if_every_n.cc ├── test_default_log_string.cc ├── test_default_rosprintf.cc ├── test_default_timed.cc ├── test_default_vlog.cc └── test_severity_conversions.cc ├── glog ├── test_glog_basic.cc ├── test_glog_every_n.cc ├── test_glog_first_n.cc ├── test_glog_if_every_n.cc ├── test_glog_log_string.cc ├── test_glog_rosprintf.cc ├── test_glog_timed.cc └── test_glog_vlog.cc ├── lpp ├── custom │ ├── callback.h │ ├── test_lpp_custom_basic.cc │ ├── test_lpp_custom_every_n.cc │ ├── test_lpp_custom_first_n.cc │ ├── test_lpp_custom_if_every_n.cc │ ├── test_lpp_custom_log_string.cc │ ├── test_lpp_custom_rosprintf.cc │ └── test_lpp_custom_vlog.cc ├── test_lpp_basic.cc ├── test_lpp_every_n.cc ├── test_lpp_first_n.cc ├── test_lpp_if_every_n.cc ├── test_lpp_log_string.cc ├── test_lpp_rosprintf.cc ├── test_lpp_timed.cc └── test_lpp_vlog.cc ├── nolog ├── test_nolog_basic.cc ├── test_nolog_every_n.cc ├── test_nolog_first_n.cc ├── test_nolog_if_every_n.cc ├── test_nolog_log_string.cc ├── test_nolog_rosprintf.cc ├── test_nolog_timed.cc └── test_nolog_vlog.cc ├── roslog ├── test_roslog_basic.cc ├── test_roslog_every_n.cc ├── test_roslog_first_n.cc ├── test_roslog_if_every_n.cc ├── test_roslog_log_string.cc ├── test_roslog_rosprintf.cc ├── test_roslog_timed.cc └── test_roslog_vlog.cc └── test_entry_point.cpp /.github/workflows/coverage_report.yml: -------------------------------------------------------------------------------- 1 | name: Generate coverage report 2 | on: 3 | pull_request: 4 | branches: 5 | - "master" 6 | push: 7 | branches: 8 | - "master" 9 | 10 | jobs: 11 | build: 12 | runs-on: [self-hosted, linux] 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | rosdistro: ['noetic'] 17 | gcc: ['10'] 18 | cxx: ['17'] 19 | container: 20 | image: omavteam/ubuntu-omav-ros:ros-noetic-ros-base 21 | credentials: 22 | username: ${{ secrets.DOCKER_USERNAME }} 23 | password: ${{ secrets.DOCKER_PASSWORD }} 24 | steps: 25 | - uses: actions/checkout@v3 26 | name: Checkout lpp 27 | with: 28 | repository: ethz-asl/lpp 29 | path: catkin_ws/src/lpp 30 | 31 | - name: Install gcovr 32 | run: sudo apt update && sudo apt install -y gcovr 33 | 34 | - name: Build lpp 35 | run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE="Debug" -DENABLE_COVERAGE=1 -DLPP_BUILD_TESTS=1 && make 36 | working-directory: catkin_ws/src/lpp 37 | shell: bash 38 | 39 | - name: Run unittests 40 | run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && ./test_default && ./test_glog && ./test_lpp && ./test_lpp_custom && ./test_nolog && ./test_roslog 41 | working-directory: catkin_ws/src/lpp/build/devel/lib/lpp 42 | shell: bash 43 | 44 | - name: Print coverage 45 | run: gcovr 46 | working-directory: catkin_ws/src/lpp 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /.github/workflows/cpp_ubuntu20_04.yml: -------------------------------------------------------------------------------- 1 | name: lpp 2 | on: 3 | pull_request: 4 | branches: 5 | - "master" 6 | push: 7 | branches: 8 | - "master" 9 | 10 | jobs: 11 | build: 12 | runs-on: [ self-hosted, linux ] 13 | env: 14 | rosdistro: ${{ matrix.ubuntu == '20.04' && 'noetic' || 'one' }} 15 | strategy: 16 | fail-fast: true 17 | matrix: 18 | gcc: [ '8', '9', '10', '11', '12', '13' ] 19 | cxx: [ '11', '14', '17', '20', '23' ] 20 | ubuntu: [ '20.04', '22.04', '24.04'] 21 | exclude: 22 | # Exclude GCC 8 on unsupported Ubuntu versions 23 | - gcc: '8' 24 | ubuntu: '22.04' 25 | - gcc: '8' 26 | ubuntu: '24.04' 27 | # Exclude GCC 12 on unsupported Ubuntu version 28 | - gcc: '12' 29 | ubuntu: '20.04' 30 | # Exclude all combinations of Ubuntu 22.04 or 24.04 with CXX 11 or 14 31 | - ubuntu: '22.04' 32 | cxx: '11' 33 | - ubuntu: '22.04' 34 | cxx: '14' 35 | - ubuntu: '24.04' 36 | cxx: '11' 37 | - ubuntu: '24.04' 38 | cxx: '14' 39 | # Exclude all combinations of CXX 23 with GCC 8, 9, or 10 40 | - gcc: '8' 41 | cxx: '23' 42 | - gcc: '9' 43 | cxx: '23' 44 | - gcc: '10' 45 | cxx: '23' 46 | # Exclude all combinations of CXX 23 with Ubuntu 20.04 47 | - ubuntu: '20.04' 48 | cxx: '23' 49 | container: 50 | image: omavteam/ubuntu-omav-ros:ros-ros-base-${{ matrix.ubuntu }} 51 | credentials: 52 | username: ${{ secrets.DOCKER_USERNAME }} 53 | password: ${{ secrets.DOCKER_PASSWORD }} 54 | name: Ubuntu ${{ matrix.ubuntu }} - GCC ${{ matrix.gcc }} - C++${{ matrix.cxx }} 55 | steps: 56 | - uses: actions/checkout@v4 57 | name: Checkout lpp 58 | with: 59 | repository: ethz-asl/lpp 60 | path: catkin_ws/src/lpp 61 | 62 | - name: Switch GCC version 63 | run: | 64 | update-alternatives --set gcc /usr/bin/gcc-${{ matrix.gcc }} 65 | update-alternatives --set g++ /usr/bin/g++-${{ matrix.gcc}} 66 | gcc --version 67 | g++ --version 68 | 69 | - name: Build lpp 70 | run: source /opt/ros/${{ env.rosdistro }}/setup.bash && catkin build -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_CXX_STANDARD=${{ matrix.cxx }} -DLPP_BUILD_TESTS=1 lpp && source ${GITHUB_WORKSPACE}/catkin_ws/devel/setup.bash 71 | working-directory: catkin_ws 72 | shell: bash 73 | 74 | - name: Run unittests 75 | run: source /opt/ros/${{ env.rosdistro }}/setup.bash && source ${GITHUB_WORKSPACE}/catkin_ws/devel/setup.bash && rosrun lpp test_lpp && rosrun lpp test_glog && rosrun lpp test_lpp_custom && rosrun lpp test_nolog && rosrun lpp test_default && rosrun lpp test_roslog 76 | working-directory: catkin_ws 77 | shell: bash 78 | -------------------------------------------------------------------------------- /.github/workflows/deploy_coverage_report.yml: -------------------------------------------------------------------------------- 1 | name: Coverage report 2 | on: 3 | push: 4 | branches: 5 | - "master" 6 | 7 | jobs: 8 | deploy: 9 | name: Deploy coverage report 10 | environment: 11 | name: github-pages 12 | url: ${{ steps.deployment.outputs.url }} 13 | runs-on: [self-hosted, linux] 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | rosdistro: ['noetic'] 18 | gcc: ['10'] 19 | cxx: ['17'] 20 | container: 21 | image: omavteam/ubuntu-omav-ros:ros-noetic-ros-base 22 | credentials: 23 | username: ${{ secrets.DOCKER_USERNAME }} 24 | password: ${{ secrets.DOCKER_PASSWORD }} 25 | permissions: 26 | pages: write # to deploy to Pages 27 | id-token: write # to verify the deployment originates from an appropriate source 28 | steps: 29 | - uses: actions/checkout@v3 30 | name: Checkout lpp 31 | with: 32 | repository: ethz-asl/lpp 33 | path: catkin_ws/src/lpp 34 | 35 | - name: Install gcovr 36 | run: sudo apt update && sudo apt install -y gcovr 37 | 38 | - name: Build lpp 39 | run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE="Debug" -DENABLE_COVERAGE=1 -DLPP_BUILD_TESTS=1 && make 40 | working-directory: catkin_ws/src/lpp 41 | shell: bash 42 | 43 | - name: Run unittests 44 | run: source /opt/ros/${{ matrix.rosdistro }}/setup.bash && ./test_default && ./test_glog && ./test_lpp && ./test_lpp_custom && ./test_nolog && ./test_roslog 45 | working-directory: catkin_ws/src/lpp/build/devel/lib/lpp 46 | shell: bash 47 | 48 | - name: Generate coverage report 49 | run: make coverage 50 | working-directory: catkin_ws/src/lpp/build 51 | 52 | - name: Upload artifact 53 | uses: actions/upload-pages-artifact@v3 54 | with: 55 | path: ./catkin_ws/src/lpp/build/coverage 56 | 57 | - name: Deploy to Github pages 58 | uses: actions/deploy-pages@v4 59 | id: deployment 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # CLion 2 | cmake-build* 3 | .idea 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright ©2022, Autonomous Systems Lab, ETH Zurich, 4c3y (https://github.com/4c3y) 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /cmake/Findglog.cmake: -------------------------------------------------------------------------------- 1 | if(NOT COMMAND feature_summary) 2 | include(FeatureSummary) 3 | endif() 4 | 5 | find_package(PkgConfig QUIET) 6 | 7 | if(NOT DEFINED GLOG_ROOT) 8 | set(GLOG_ROOT /usr /usr/local) 9 | endif() 10 | 11 | pkg_check_modules(PC_GLOG libglog) 12 | 13 | macro(_FIND_GLOG_LIBRARIES _var) 14 | find_library(${_var} 15 | NAMES ${ARGN} 16 | HINTS ${PC_GLOG_LIBDIR} 17 | PATHS ${LIB_PATHS} 18 | /usr/lib 19 | /usr/lib64 20 | /usr/lib/x86_64-linux-gnu 21 | /usr/lib/i386-linux-gnu 22 | /usr/lib/arm-linux-gnueabihf 23 | /usr/lib/arm-linux-gnueabi 24 | /usr/lib/aarch64-linux-gnu 25 | /usr/lib/mipsel-linux-gnu 26 | /usr/lib/mips-linux-gnu 27 | /usr/lib/mips64el-linux-gnuabi64 28 | /usr/lib/powerpc-linux-gnu 29 | /usr/lib/powerpc64-linux-gnu 30 | /usr/lib/powerpc64le-linux-gnu 31 | /usr/lib/powerpc-linux-gnuspe 32 | /usr/lib/hppa-linux-gnu 33 | /usr/lib/s390x-linux-gnu 34 | /usr/lib/i386-gnu 35 | /usr/lib/hppa-linux-gnu 36 | /usr/lib/x86_64-kfreebsd-gnu 37 | /usr/lib/i386-kfreebsd-gnu 38 | /usr/lib/m68k-linux-gnu 39 | /usr/lib/sh4-linux-gnu 40 | /usr/lib/sparc64-linux-gnu 41 | /usr/lib/x86_64-linux-gnux32 42 | /usr/lib/alpha-linux-gnu 43 | /usr/lib/riscv64-linux-gnu 44 | /usr/local/lib 45 | /usr/local/lib64 46 | /opt/local/lib 47 | ${GLOG_ROOT}/lib 48 | $ENV{GLOG_ROOT}/lib 49 | ${GLOG_ROOT}/lib64 50 | $ENV{GLOG_ROOT}/lib64 51 | PATH_SUFFIXES lib 52 | ) 53 | mark_as_advanced(${_var}) 54 | endmacro() 55 | 56 | _find_glog_libraries(GLOG_LIBRARIES libglog.so) 57 | 58 | include(FindPackageHandleStandardArgs) 59 | find_package_handle_standard_args(glog DEFAULT_MSG GLOG_LIBRARIES) 60 | 61 | if(GLOG_FOUND) 62 | message(STATUS "glog library found at ${GLOG_LIBRARIES}") 63 | if(PC_GLOG_VERSION) 64 | set(GLOG_VERSION ${PC_GLOG_VERSION}) 65 | endif() 66 | endif() 67 | 68 | if(GLOG_FOUND AND GLOG_VERSION) 69 | set_package_properties(GLOG PROPERTIES 70 | DESCRIPTION "C++ implementation of the Google logging module (found: v${GLOG_VERSION})" 71 | ) 72 | else() 73 | set_package_properties(GLOG PROPERTIES 74 | DESCRIPTION "C++ implementation of the Google logging module" 75 | ) 76 | endif() 77 | 78 | set_package_properties(GLOG PROPERTIES 79 | URL "https://github.com/google/glog" 80 | ) 81 | 82 | string(REGEX MATCH libglog.a GLOG_IS_STATIC ${GLOG_LIBRARIES}) 83 | if(GLOG_FOUND AND NOT TARGET Glog::glog) 84 | if(GLOG_IS_STATIC) 85 | add_library(Glog::glog STATIC IMPORTED) 86 | else() 87 | add_library(Glog::glog SHARED IMPORTED) 88 | endif() 89 | set_target_properties(Glog::glog PROPERTIES 90 | IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" 91 | IMPORTED_LOCATION "${GLOG_LIBRARIES}" 92 | INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIRS}" 93 | INTERFACE_LINK_LIBRARIES "${GLOG_LIBRARIES}" 94 | ) 95 | endif() 96 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | lpp 4 | 0.1.0 5 | Log++ Logging framework 6 | 4c3y 7 | BSD 8 | catkin 9 | roscpp 10 | 11 | -------------------------------------------------------------------------------- /src/demo.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 18.08.22. 3 | // 4 | 5 | #include 6 | 7 | int main([[maybe_unused]] int argc, char **argv) { 8 | LOG_INIT(argv[0]); 9 | 10 | int foo = 5; 11 | 12 | LOG(I, "Foo: " << foo); //Log++ syntax 13 | ROS_INFO_STREAM("Foo: " << foo); //ROS syntax 14 | LOG(INFO) << "Foo: " << foo; //Glog syntax 15 | return 0; 16 | } -------------------------------------------------------------------------------- /test/common/async_tests.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 21.09.22. 3 | // 4 | 5 | #ifndef LOG_TEST_COMMON_ASYNC_TESTS_H_ 6 | #define LOG_TEST_COMMON_ASYNC_TESTS_H_ 7 | 8 | #if __cplusplus >= 201703L 9 | #include 10 | #endif 11 | 12 | #include 13 | #include 14 | 15 | #define GET_CLASS_NAME(class_ptr, status) abi::__cxa_demangle(typeid(class_ptr).name(), nullptr, nullptr, status) 16 | 17 | enum CompareType { 18 | EQUAL, 19 | IS_SUBSTRING, 20 | REMOVE_NUMBERS_FROM_STRING 21 | }; 22 | 23 | enum StreamType { 24 | STDOUT, 25 | STDERR 26 | }; 27 | 28 | struct AsyncTest { 29 | std::string class_name; 30 | std::vector expected_output; 31 | std::function fn; 32 | CompareType compare_type; 33 | StreamType stream_type; 34 | }; 35 | 36 | extern std::vector generateTests(); 37 | static std::vector tests = generateTests(); 38 | 39 | class TestResult { 40 | public: 41 | static inline TestResult &getInstance() { 42 | static TestResult instance{}; 43 | return instance; 44 | } 45 | 46 | /** 47 | * Returns test result by test name 48 | * @param test_name 49 | * @return true on success otherwise false 50 | */ 51 | inline bool get(const std::string &test_name) { 52 | #if __cplusplus >= 201703L 53 | std::scoped_lock lock(test_result_mutex_); 54 | #elif __cplusplus >= 201103L 55 | std::lock_guard lock(test_result_mutex_); 56 | #endif 57 | 58 | LOG_INIT(*test_argv); 59 | if (!started_) { 60 | started_ = true; 61 | startAll(); 62 | } 63 | 64 | if (test_results.find(test_name) == test_results.end()) { 65 | return false; 66 | } 67 | 68 | bool res = test_results.at(test_name); 69 | return res; 70 | } 71 | 72 | private: 73 | static inline void startAll() { 74 | std::vector thread_pool{}; 75 | for (const auto &t: tests) { 76 | thread_pool.emplace_back(&TestResult::startTimed, &TestResult::getInstance(), t); 77 | } 78 | 79 | for (auto &t: thread_pool) { 80 | t.join(); 81 | } 82 | } 83 | 84 | static inline void startCapture(StreamType stream_type) { 85 | switch (stream_type) { 86 | case STDOUT: testing::internal::CaptureStdout(); 87 | return; 88 | case STDERR: testing::internal::CaptureStderr(); 89 | return; 90 | } 91 | } 92 | 93 | static inline std::string stopCapture(StreamType stream_type) { 94 | switch (stream_type) { 95 | case STDOUT: return testing::internal::GetCapturedStdout(); 96 | 97 | case STDERR: return testing::internal::GetCapturedStderr(); 98 | } 99 | abort(); 100 | } 101 | 102 | inline void startTimed(const AsyncTest &a) { 103 | bool test_status = true; 104 | 105 | for (int i = 0; i < 30; i++) { 106 | stdout_capture_mutex_.lock(); 107 | startCapture(a.stream_type); 108 | a.fn(); 109 | std::string output = stopCapture(a.stream_type); 110 | stdout_capture_mutex_.unlock(); 111 | 112 | if ((i == 0 || i % 4 == 0)) { 113 | if (!compare(a.compare_type, output, a.expected_output)) { 114 | 115 | std::cout << a.class_name << " failed. Output: " << output << " expected output: " << a.expected_output[0] 116 | << std::endl; 117 | test_status = false; 118 | } 119 | } else if (!compare(a.compare_type, output, {""})) { 120 | std::cout << a.class_name << " failed. Output: " << output << " expected output: " << "\"\"" << std::endl; 121 | test_status = false; 122 | } 123 | usleep(250000.); 124 | } 125 | insert(a.class_name, test_status); 126 | } 127 | 128 | //gtest assertions only work on main thread 129 | static inline bool compare(CompareType compare_type, const std::string &output, const std::vector &expected_output) { 130 | switch (compare_type) { 131 | case EQUAL:return compareEquality(output, expected_output); 132 | case IS_SUBSTRING: return compareSubstring(output, expected_output); 133 | case REMOVE_NUMBERS_FROM_STRING: return compareRemoveNumbersFromString(output, expected_output); 134 | default:return false; 135 | } 136 | } 137 | 138 | static inline bool compareSubstring(const std::string &output, const std::vector &expected_output) { 139 | bool res = false; 140 | for (const auto &eo: expected_output) { 141 | if (isSubstring(output, eo)) { 142 | res = true; 143 | break; 144 | } 145 | } 146 | return res; 147 | }; 148 | 149 | static inline bool compareEquality(const std::string &output, const std::vector &expected_output) { 150 | for (const auto &eo: expected_output) { 151 | if (output == eo) { 152 | return true; 153 | } 154 | } 155 | return false; 156 | }; 157 | 158 | static inline bool compareRemoveNumbersFromString(const std::string &output, const std::vector &expected_output) { 159 | for (const auto &eo: expected_output) { 160 | if (removeNumbersFromString(output) == removeNumbersFromString(eo)) { 161 | return true; 162 | } 163 | } 164 | return false; 165 | } 166 | 167 | inline void insert(const std::string &test_name, bool test_status) { 168 | test_results.insert({test_name, test_status}); 169 | } 170 | 171 | TestResult() = default; 172 | 173 | bool started_{false}; 174 | std::mutex test_result_mutex_; 175 | std::mutex stdout_capture_mutex_; 176 | std::map test_results; 177 | }; 178 | 179 | #endif //LOG_TEST_COMMON_ASYNC_TESTS_H_ 180 | -------------------------------------------------------------------------------- /test/common/test_utils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 23.08.22. 3 | // 4 | 5 | #ifndef LOG_TEST_TEST_UTILS_H_ 6 | #define LOG_TEST_TEST_UTILS_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | extern char **test_argv; 13 | 14 | inline static bool isSubstring(const std::string &string, const std::string &substring) { 15 | if (string.empty() && substring.empty()) { 16 | return true; 17 | } 18 | 19 | bool res = (string.find(substring) != std::string::npos); 20 | 21 | if(!res) { 22 | std::cout << " String: " << string << std::endl; 23 | std::cout << "Substring: " << substring << std::endl; 24 | } 25 | 26 | return res; 27 | } 28 | 29 | inline static std::string removeNumbersFromString(std::string str) { 30 | int current = 0; 31 | for (std::size_t i = 0; i < str.length(); i++) { 32 | if (!isdigit(str[i])) { 33 | str[current] = str[i]; 34 | current++; 35 | } 36 | } 37 | return str.substr(0, current);; 38 | } 39 | 40 | //! Macros to capture stdout and stderr and assign output directly to std::string or suppress output 41 | #define LPP_CAPTURE_STDOUT(x) []() {testing::internal::CaptureStdout(); x; \ 42 | return testing::internal::GetCapturedStdout();}() 43 | 44 | #define LPP_CAPTURE_STDERR(x) []() {testing::internal::CaptureStderr(); x; \ 45 | return testing::internal::GetCapturedStderr();}() 46 | 47 | //! Get file name from __FILE__ macro 48 | #define LPP_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 49 | 50 | inline int ForkAndReap(int *Ws, const std::function &fn) { 51 | pid_t pid = fork(); 52 | if (fork() < 0) { 53 | return -1; 54 | } 55 | 56 | if (pid == 0) { 57 | fn(); 58 | _exit(0); 59 | } 60 | 61 | while (true) { 62 | if (waitpid(pid, Ws, WUNTRACED) < 0) { 63 | if (EINTR == errno) { 64 | continue; 65 | } 66 | 67 | abort(); 68 | } else if (!WIFEXITED(*Ws) && !WIFSIGNALED(*Ws)) { //shouldn't have stopped 69 | if (kill(pid, SIGTERM) < 0 || kill(pid, SIGCONT) < 0) { 70 | abort(); 71 | } 72 | } 73 | break; 74 | } 75 | return 0; 76 | } 77 | 78 | /** 79 | * Checks if function calls abort; 80 | * @param fn 81 | * @return true if function called abort(), otherwise false 82 | */ 83 | 84 | inline bool checkAbort(const std::function &fn) { 85 | int ws; 86 | return ForkAndReap(&ws, fn) >= 0 && WIFSIGNALED(ws) && WTERMSIG(SIGABRT); 87 | } 88 | 89 | //! Ros testing utils 90 | namespace lpp { 91 | namespace testing { 92 | 93 | inline static constexpr const char *ERROR_MESSAGE = "Base angle (%f) is less than the minimum angle (%f)"; 94 | inline static const std::string EXPECTED_ERROR_MESSAGE = "Base angle (3.300000) is less than the minimum angle (5.500000)\n"; 95 | } 96 | 97 | namespace rostest { 98 | inline static const std::string debug = "\x1B[m[DEBUG] [.]: Test\x1B[m\n"; 99 | inline static const std::string info = "\x1B[m[ INFO] [.]: Test\x1B[m\n"; 100 | inline static const std::string warning = "\x1B[m[ WARN] [.]: Test\x1B[m\n"; 101 | inline static const std::string error = "\x1B[m[ERROR] [.]: Test\x1B[m\n"; 102 | inline static const std::string fatal = "\x1B[m[FATAL] [.]: Test\x1B[m\n"; 103 | namespace v2 { 104 | inline static const std::string debug = rostest::debug; 105 | inline static const std::string info = "\x1B[m[INFO] [.]: Test\x1B[m\n"; 106 | inline static const std::string warning = "\x1B[m[WARN] [.]: Test\x1B[m\n"; 107 | inline static const std::string error = rostest::error; 108 | inline static const std::string fatal = rostest::fatal; 109 | } 110 | } 111 | 112 | 113 | namespace rosprintf { 114 | inline static const std::string debug = "\x1B[m[DEBUG] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 115 | inline static const std::string info = "\x1B[m[ INFO] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 116 | inline static const std::string warning = "\x1B[m[ WARN] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 117 | inline static const std::string error = "\x1B[m[ERROR] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 118 | inline static const std::string fatal = "\x1B[m[FATAL] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 119 | namespace v2 { 120 | inline static const std::string debug = rosprintf::debug; 121 | inline static const std::string info = "\x1B[m[INFO] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 122 | inline static const std::string warning = "\x1B[m[WARN] [.]: Base angle (.) is less than the minimum angle (.)\x1B[m\n"; 123 | inline static const std::string error = rosprintf::error; 124 | inline static const std::string fatal = rosprintf::fatal; 125 | } 126 | } 127 | 128 | 129 | namespace logstr { 130 | inline static const std::string info = "\x1B[m[ INFO] [.]: LOG_STRING: collected info\x1B[m\n"; 131 | inline static const std::string warning = "\x1B[m[ WARN] [.]: LOG_STRING: collected warn\x1B[m\n"; 132 | inline static const std::string error = "\x1B[m[ERROR] [.]: LOG_STRING: collected error\x1B[m\n"; 133 | inline static const std::string fatal = "\x1B[m[FATAL] [.]: LOG_STRING: collected fatal\x1B[m\n"; 134 | namespace v2 { 135 | inline static const std::string info = "\x1B[m[INFO] [.]: LOG_STRING: collected info\x1B[m\n"; 136 | inline static const std::string warning = "\x1B[m[WARN] [.]: LOG_STRING: collected warn\x1B[m\n"; 137 | inline static const std::string error = logstr::error; 138 | inline static const std::string fatal = logstr::fatal; 139 | } 140 | } 141 | 142 | namespace custom { 143 | inline static const std::string test123 = "test123\n"; 144 | inline static const std::string debug = "Log++ [debug] "; 145 | inline static const std::string info = "Log++ [info] "; 146 | inline static const std::string warning = "Log++ [warning] "; 147 | inline static const std::string error = "Log++ [error] "; 148 | inline static const std::string fatal = "Log++ [fatal] "; 149 | } 150 | } 151 | 152 | 153 | #endif //LOG_TEST_TEST_UTILS_H_ 154 | -------------------------------------------------------------------------------- /test/default/test_common.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void aborting() { 6 | abort(); 7 | } 8 | 9 | void not_aborting() { 10 | 11 | } 12 | 13 | TEST(common, testCheckAbort) { 14 | ASSERT_TRUE(checkAbort(aborting)); 15 | ASSERT_FALSE(checkAbort(not_aborting)); 16 | } 17 | 18 | TEST(common, fatal_test) { 19 | LOG_INIT(*test_argv); 20 | ASSERT_TRUE(checkAbort([]() { LPP_CAPTURE_STDERR(LOG(FATAL) << "Test"); })); 21 | } 22 | 23 | TEST(common, testRemoveNumbersFromString) { 24 | ASSERT_EQ("Test", removeNumbersFromString("Test123")); 25 | ASSERT_EQ("Test", removeNumbersFromString("Te123st123")); 26 | ASSERT_EQ("Test", removeNumbersFromString("123Te123st123")); 27 | } 28 | -------------------------------------------------------------------------------- /test/default/test_default_basic.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 12.09.22. 3 | // 4 | 5 | #include "test_utils.h" 6 | #include 7 | #include 8 | 9 | using namespace lpp::rostest; 10 | 11 | TEST(default_basic, glog_syntax_severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | std::string output = LPP_CAPTURE_STDERR(DLOG(INFO) << "xyz"); 15 | 16 | ASSERT_TRUE(isSubstring(output, "xyz")); 17 | ASSERT_TRUE(isSubstring(output, "test_default_basic.cc")); 18 | 19 | ASSERT_EQ(output[0], 'I'); 20 | } 21 | 22 | TEST(default_basic, glog_syntax_severity_info) { 23 | LOG_INIT(*test_argv); 24 | 25 | std::string output = LPP_CAPTURE_STDERR(LOG(INFO) << "xyz"); 26 | 27 | ASSERT_TRUE(isSubstring(output, "xyz")); 28 | ASSERT_TRUE(isSubstring(output, "test_default_basic.cc")); 29 | 30 | ASSERT_EQ(output[0], 'I'); 31 | } 32 | 33 | TEST(default_basic, glog_syntax_severity_warning) { 34 | LOG_INIT(*test_argv); 35 | 36 | std::string output = LPP_CAPTURE_STDERR(LOG(WARNING) << "xyz"); 37 | 38 | ASSERT_TRUE(isSubstring(output, "xyz")); 39 | ASSERT_TRUE(isSubstring(output, "test_default_basic.cc")); 40 | ASSERT_EQ(output[0], 'W'); 41 | } 42 | 43 | TEST(default_basic, glog_syntax_severity_error) { 44 | LOG_INIT(*test_argv); 45 | 46 | std::string output = LPP_CAPTURE_STDERR(LOG(ERROR) << "xyz"); 47 | 48 | ASSERT_TRUE(isSubstring(output, "xyz")); 49 | ASSERT_TRUE(isSubstring(output, "test_default_basic.cc")); 50 | ASSERT_EQ(output[0], 'E'); 51 | } 52 | 53 | TEST(default_basic, glog_syntax_severity_fatal) { 54 | LOG_INIT(*test_argv); 55 | ASSERT_TRUE(checkAbort([](){LPP_CAPTURE_STDERR(LOG(FATAL) << "xyz");})); 56 | } 57 | 58 | TEST(default_basic, lpp_syntax_severity_debug) { 59 | LOG_INIT(*test_argv); 60 | 61 | std::string output = LPP_CAPTURE_STDOUT(LOG(D, "Test" << 123)); 62 | ASSERT_EQ(output, "DEBUG Test123\n"); 63 | } 64 | 65 | TEST(default_basic, lpp_syntax_severity_info) { 66 | LOG_INIT(*test_argv); 67 | 68 | std::string output = LPP_CAPTURE_STDOUT(LOG(I, "Test" << 123)); 69 | ASSERT_EQ(output, "INFO Test123\n"); 70 | } 71 | 72 | TEST(default_basic, lpp_syntax_severity_warning) { 73 | LOG_INIT(*test_argv); 74 | 75 | std::string output = LPP_CAPTURE_STDOUT(LOG(W, "Test" << 123)); 76 | ASSERT_EQ(output, "WARN Test123\n"); 77 | } 78 | 79 | TEST(default_basic, lpp_syntax_severity_error) { 80 | LOG_INIT(*test_argv); 81 | 82 | std::string output = LPP_CAPTURE_STDOUT(LOG(E, "Test" << 123)); 83 | ASSERT_EQ(output, "ERROR Test123\n"); 84 | } 85 | 86 | TEST(default_basic, lpp_syntax_severity_fatal) { 87 | LOG_INIT(*test_argv); 88 | 89 | std::string output = LPP_CAPTURE_STDOUT(LOG(F, "Test" << 123)); 90 | ASSERT_EQ(output, "FATAL Test123\n"); 91 | } 92 | 93 | TEST(default_basic, roslog_syntax_severity_debug) { 94 | LOG_INIT(*test_argv); 95 | 96 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG("Test")); 97 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 98 | } 99 | 100 | TEST(default_basic, roslog_syntax_severity_debug_stream) { 101 | LOG_INIT(*test_argv); 102 | 103 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("Test")); 104 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 105 | } 106 | 107 | TEST(default_basic, roslog_syntax_severity_info) { 108 | LOG_INIT(*test_argv); 109 | 110 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO("Test")); 111 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 112 | } 113 | 114 | TEST(default_basic, roslog_syntax_severity_info_stream) { 115 | LOG_INIT(*test_argv); 116 | 117 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("Test")); 118 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 119 | } 120 | 121 | TEST(default_basic, roslog_syntax_severity_warning) { 122 | LOG_INIT(*test_argv); 123 | 124 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN("Test")); 125 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 126 | } 127 | 128 | TEST(default_basic, roslog_syntax_severity_warning_stream) { 129 | LOG_INIT(*test_argv); 130 | 131 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_STREAM("Test")); 132 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 133 | } 134 | 135 | TEST(default_basic, roslog_syntax_severity_error) { 136 | LOG_INIT(*test_argv); 137 | 138 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR("Test")); 139 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 140 | } 141 | 142 | TEST(default_basic, roslog_syntax_severity_error_stream) { 143 | LOG_INIT(*test_argv); 144 | 145 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_STREAM("" << "Test")); 146 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 147 | } 148 | 149 | TEST(default_basic, roslog_syntax_severity_fatal) { 150 | LOG_INIT(*test_argv); 151 | 152 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL("Test")); 153 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 154 | 155 | } 156 | 157 | TEST(default_basic, roslog_syntax_severity_fatal_stream) { 158 | LOG_INIT(*test_argv); 159 | 160 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_STREAM("" << "Test")); 161 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 162 | } 163 | -------------------------------------------------------------------------------- /test/default/test_default_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 12.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_LogEveryN, lpp_syntax_severity_debug) { 10 | for (int i = 0; i < 5; i++) { 11 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(D, 3, "Test" << 123)); 12 | 13 | if (i % 3 == 0) { 14 | ASSERT_EQ(output, "DEBUG Test123\n"); 15 | } else { 16 | ASSERT_EQ(output, ""); 17 | } 18 | } 19 | } 20 | 21 | TEST(default_LogEveryN, lpp_syntax_severity_info) { 22 | for (int i = 0; i < 5; i++) { 23 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(I, 3, "Test" << 123)); 24 | 25 | if (i % 3 == 0) { 26 | ASSERT_EQ(output, "INFO Test123\n"); 27 | } else { 28 | ASSERT_EQ(output, ""); 29 | } 30 | } 31 | } 32 | 33 | TEST(default_LogEveryN, lpp_syntax_severity_warning) { 34 | for (int i = 0; i < 5; i++) { 35 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(W, 3, "Test" << 123)); 36 | 37 | if (i % 3 == 0) { 38 | ASSERT_EQ(output, "WARN Test123\n"); 39 | } else { 40 | ASSERT_EQ(output, ""); 41 | } 42 | } 43 | } 44 | 45 | TEST(default_LogEveryN, lpp_syntax_severity_error) { 46 | for (int i = 0; i < 5; i++) { 47 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(E, 3, "Test" << 123)); 48 | 49 | if (i % 3 == 0) { 50 | ASSERT_EQ(output, "ERROR Test123\n"); 51 | } else { 52 | ASSERT_EQ(output, ""); 53 | } 54 | } 55 | } 56 | 57 | TEST(default_LogEveryN, lpp_syntax_severity_fatal) { 58 | for (int i = 0; i < 5; i++) { 59 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(F, 3, "Test" << 123)); 60 | 61 | if (i % 3 == 0) { 62 | ASSERT_EQ(output, "FATAL Test123\n"); 63 | } else { 64 | ASSERT_EQ(output, ""); 65 | } 66 | } 67 | } 68 | 69 | TEST(default_LogEveryN, glog_syntax_severity_debug) { 70 | LOG_INIT(*test_argv); 71 | 72 | for (int i = 0; i < 5; i++) { 73 | std::string output = LPP_CAPTURE_STDERR(DLOG_EVERY_N(INFO, 3) << "Test" << 123); 74 | 75 | if (i % 3 == 0) { 76 | ASSERT_TRUE(isSubstring(output, "Test123")); 77 | } else { 78 | ASSERT_EQ(output, ""); 79 | } 80 | } 81 | } 82 | 83 | TEST(default_LogEveryN, glog_syntax_severity_info) { 84 | LOG_INIT(*test_argv); 85 | 86 | for (int i = 0; i < 5; i++) { 87 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(INFO, 3) << "Test" << 123); 88 | 89 | if (i % 3 == 0) { 90 | ASSERT_TRUE(isSubstring(output, "Test123")); 91 | } else { 92 | ASSERT_EQ(output, ""); 93 | } 94 | } 95 | } 96 | 97 | TEST(default_LogEveryN, glog_syntax_severity_warning) { 98 | LOG_INIT(*test_argv); 99 | 100 | for (int i = 0; i < 5; i++) { 101 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(WARNING, 3) << "Test" << 123); 102 | 103 | if (i % 3 == 0) { 104 | ASSERT_TRUE(isSubstring(output, "Test123")); 105 | } else { 106 | ASSERT_EQ(output, ""); 107 | } 108 | } 109 | } 110 | 111 | TEST(default_LogEveryN, glog_syntax_severity_error) { 112 | LOG_INIT(*test_argv); 113 | 114 | for (int i = 0; i < 5; i++) { 115 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(ERROR, 3) << "Test" << 123); 116 | 117 | if (i % 3 == 0) { 118 | ASSERT_TRUE(isSubstring(output, "Test123")); 119 | } else { 120 | ASSERT_EQ(output, ""); 121 | } 122 | } 123 | } 124 | 125 | TEST(default_LogEveryN, glog_syntax_severity_fatal) { 126 | LOG_INIT(*test_argv); 127 | 128 | std::function fn = [](){ 129 | for (int i = 0; i < 5; i++) { 130 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(FATAL, 3) << "Test" << 123); 131 | 132 | if (i % 3 == 0) { 133 | ASSERT_TRUE(isSubstring(output, "Test123")); 134 | } else { 135 | ASSERT_EQ(output, ""); 136 | } 137 | } 138 | }; 139 | ASSERT_TRUE(checkAbort(fn)); 140 | } -------------------------------------------------------------------------------- /test/default/test_default_first_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 12.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_LogFirstN, glog_syntax_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | std::string output = LPP_CAPTURE_STDERR(DLOG_FIRST_N(INFO, 3) << "Test" << 123); 14 | 15 | if (i < 3) { 16 | 17 | ASSERT_TRUE(isSubstring(output, "Test123")); 18 | ASSERT_TRUE(isSubstring(output, "test_default_first_n.cc")); 19 | 20 | ASSERT_EQ(output[0], 'I'); 21 | } else { 22 | ASSERT_EQ(output, ""); 23 | } 24 | } 25 | } 26 | 27 | TEST(default_LogFirstN, glog_syntax_severity_info) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(INFO, 3) << "Test" << 123); 32 | 33 | if (i < 3) { 34 | 35 | ASSERT_TRUE(isSubstring(output, "Test123")); 36 | ASSERT_TRUE(isSubstring(output, "test_default_first_n.cc")); 37 | 38 | ASSERT_EQ(output[0], 'I'); 39 | } else { 40 | ASSERT_EQ(output, ""); 41 | } 42 | } 43 | } 44 | 45 | TEST(default_LogFirstN, glog_syntax_severity_warning) { 46 | LOG_INIT(*test_argv); 47 | 48 | for (int i = 0; i < 5; i++) { 49 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(WARNING, 3) << "Test" << 123); 50 | 51 | if (i < 3) { 52 | 53 | ASSERT_TRUE(isSubstring(output, "Test123")); 54 | ASSERT_TRUE(isSubstring(output, "test_default_first_n.cc")); 55 | 56 | ASSERT_EQ(output[0], 'W'); 57 | } else { 58 | ASSERT_EQ(output, ""); 59 | } 60 | } 61 | } 62 | 63 | TEST(default_LogFirstN, glog_syntax_severity_error) { 64 | LOG_INIT(*test_argv); 65 | 66 | for (int i = 0; i < 5; i++) { 67 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(ERROR, 3) << "Test" << 123); 68 | 69 | if (i < 3) { 70 | 71 | ASSERT_TRUE(isSubstring(output, "Test123")); 72 | ASSERT_TRUE(isSubstring(output, "test_default_first_n.cc")); 73 | 74 | ASSERT_EQ(output[0], 'E'); 75 | } else { 76 | ASSERT_EQ(output, ""); 77 | } 78 | } 79 | } 80 | 81 | TEST(default_LogFirstN, glog_syntax_severity_fatal) { 82 | LOG_INIT(*test_argv); 83 | 84 | std::function fn = []() { 85 | for (int i = 0; i < 5; i++) { 86 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(ERROR, 3) << "Test" << 123); 87 | 88 | if (i < 3) { 89 | 90 | ASSERT_TRUE(isSubstring(output, "Test123")); 91 | ASSERT_TRUE(isSubstring(output, "test_default_first_n.cc")); 92 | 93 | ASSERT_EQ(output[0], 'E'); 94 | } else { 95 | ASSERT_EQ(output, ""); 96 | } 97 | } 98 | }; 99 | 100 | checkAbort(fn); 101 | } 102 | 103 | TEST(default_LogFirstN, lpp_syntax_severity_debug) { 104 | for (int i = 0; i < 5; i++) { 105 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(D, 3, "Test" << 123)); 106 | 107 | if (i < 3) { 108 | ASSERT_EQ(output, "DEBUG Test123\n"); 109 | } else { 110 | ASSERT_EQ(output, ""); 111 | } 112 | } 113 | } 114 | 115 | TEST(default_LogFirstN, lpp_syntax_severity_info) { 116 | for (int i = 0; i < 5; i++) { 117 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(I, 3, "Test" << 123)); 118 | 119 | if (i < 3) { 120 | ASSERT_EQ(output, "INFO Test123\n"); 121 | } else { 122 | ASSERT_EQ(output, ""); 123 | } 124 | } 125 | } 126 | 127 | TEST(default_LogFirstN, lpp_syntax_severity_warning) { 128 | for (int i = 0; i < 5; i++) { 129 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(W, 3, "Test" << 123)); 130 | 131 | if (i < 3) { 132 | ASSERT_EQ(output, "WARN Test123\n"); 133 | } else { 134 | ASSERT_EQ(output, ""); 135 | } 136 | } 137 | } 138 | 139 | TEST(default_LogFirstN, lpp_syntax_severity_error) { 140 | for (int i = 0; i < 5; i++) { 141 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(E, 3, "Test" << 123)); 142 | 143 | if (i < 3) { 144 | ASSERT_EQ(output, "ERROR Test123\n"); 145 | } else { 146 | ASSERT_EQ(output, ""); 147 | } 148 | } 149 | } 150 | 151 | TEST(default_LogFirstN, lpp_syntax_severity_fatal) { 152 | for (int i = 0; i < 5; i++) { 153 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(F, 3, "Test" << 123)); 154 | 155 | if (i < 3) { 156 | ASSERT_EQ(output, "FATAL Test123\n"); 157 | } else { 158 | ASSERT_EQ(output, ""); 159 | } 160 | } 161 | } -------------------------------------------------------------------------------- /test/default/test_default_if_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 15.12.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | testing::internal::CaptureStderr(); 14 | DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 15 | std::string output = testing::internal::GetCapturedStderr(); 16 | 17 | if (i <= 3 && i % 3 == 0) { 18 | ASSERT_TRUE(isSubstring(output, "Test123")); 19 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 20 | ASSERT_EQ(output[0], 'I'); 21 | } else { 22 | ASSERT_EQ(output, ""); 23 | } 24 | } 25 | } 26 | 27 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_info) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | testing::internal::CaptureStderr(); 32 | LOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 33 | std::string output = testing::internal::GetCapturedStderr(); 34 | 35 | if (i <= 3 && i % 3 == 0) { 36 | ASSERT_TRUE(isSubstring(output, "Test123")); 37 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 38 | ASSERT_EQ(output[0], 'I'); 39 | } else { 40 | ASSERT_EQ(output, ""); 41 | } 42 | } 43 | } 44 | 45 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_warning) { 46 | LOG_INIT(*test_argv); 47 | 48 | for (int i = 0; i < 5; i++) { 49 | testing::internal::CaptureStderr(); 50 | LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "Test" << 123; 51 | std::string output = testing::internal::GetCapturedStderr(); 52 | 53 | if (i <= 3 && i % 3 == 0) { 54 | ASSERT_TRUE(isSubstring(output, "Test123")); 55 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 56 | ASSERT_EQ(output[0], 'W'); 57 | } else { 58 | ASSERT_EQ(output, ""); 59 | } 60 | } 61 | } 62 | 63 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_error) { 64 | LOG_INIT(*test_argv); 65 | FLAGS_v = 3; 66 | 67 | for (int i = 0; i < 5; i++) { 68 | testing::internal::CaptureStderr(); 69 | LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "Test" << 123; 70 | std::string output = testing::internal::GetCapturedStderr(); 71 | 72 | if (i <= 3 && i % 3 == 0) { 73 | ASSERT_TRUE(isSubstring(output, "Test123")); 74 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 75 | ASSERT_EQ(output[0], 'E'); 76 | } else { 77 | ASSERT_EQ(output, ""); 78 | } 79 | } 80 | } 81 | 82 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_fatal) { 83 | LOG_INIT(*test_argv); 84 | FLAGS_v = 3; 85 | 86 | std::function fn = []() { 87 | for (int i = 0; i < 5; i++) { 88 | testing::internal::CaptureStderr(); 89 | LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "Test" << 123; 90 | std::string output = testing::internal::GetCapturedStderr(); 91 | } 92 | }; 93 | 94 | ASSERT_TRUE(checkAbort(fn)); 95 | } -------------------------------------------------------------------------------- /test/default/test_default_log_string.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 28.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_log_string, severity_info) { 10 | LOG_INIT(*test_argv); 11 | 12 | std::vector errors; 13 | 14 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 15 | testing::internal::CaptureStderr(); 16 | LOG_STRING(INFO, &errors) << "LOG_STRING: " << "collected info"; 17 | std::string output = testing::internal::GetCapturedStderr(); 18 | 19 | ASSERT_EQ(output, ""); 20 | ASSERT_EQ("LOG_STRING: collected info", errors.at(0)); 21 | } 22 | 23 | TEST(default_log_string, severity_info_null) { 24 | LOG_INIT(*test_argv); 25 | 26 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(INFO, nullptr) << "LOG_STRING: " << "collected info"); 27 | 28 | ASSERT_EQ(output[0], 'I'); 29 | ASSERT_TRUE(isSubstring(output, "test_default_log_string.cc")); 30 | ASSERT_TRUE(isSubstring(output, "LOG_STRING: collected info")); 31 | } 32 | 33 | TEST(default_log_string, severity_warning) { 34 | LOG_INIT(*test_argv); 35 | 36 | std::vector errors; 37 | 38 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 39 | testing::internal::CaptureStderr(); 40 | LOG_STRING(WARNING, &errors) << "LOG_STRING: " << "collected warn"; 41 | std::string output = testing::internal::GetCapturedStderr(); 42 | 43 | ASSERT_EQ(output, ""); 44 | ASSERT_EQ("LOG_STRING: collected warn", errors.at(0)); 45 | } 46 | 47 | TEST(default_log_string, severity_warning_null) { 48 | LOG_INIT(*test_argv); 49 | 50 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " << "collected warn"); 51 | 52 | ASSERT_EQ(output[0], 'W'); 53 | ASSERT_TRUE(isSubstring(output, "test_default_log_string.cc")); 54 | ASSERT_TRUE(isSubstring(output, "LOG_STRING: collected warn")); 55 | } 56 | 57 | TEST(default_log_string, severity_error) { 58 | LOG_INIT(*test_argv); 59 | 60 | std::vector errors; 61 | 62 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 63 | testing::internal::CaptureStderr(); 64 | LOG_STRING(ERROR, &errors) << "LOG_STRING: " << "collected error"; 65 | std::string output = testing::internal::GetCapturedStderr(); 66 | 67 | ASSERT_EQ(output, ""); 68 | ASSERT_EQ("LOG_STRING: collected error", errors.at(0)); 69 | } 70 | 71 | TEST(default_log_string, severity_error_null) { 72 | LOG_INIT(*test_argv); 73 | 74 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " << "collected error"); 75 | 76 | ASSERT_EQ(output[0], 'E'); 77 | ASSERT_TRUE(isSubstring(output, "test_default_log_string.cc")); 78 | ASSERT_TRUE(isSubstring(output, "LOG_STRING: collected error")); 79 | } 80 | 81 | TEST(default_log_string, severity_fatal) { 82 | LOG_INIT(*test_argv); 83 | 84 | std::vector errors; 85 | 86 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 87 | testing::internal::CaptureStderr(); 88 | LOG_STRING(FATAL, &errors) << "LOG_STRING: " << "collected fatal"; 89 | std::string output = testing::internal::GetCapturedStderr(); 90 | ASSERT_EQ(output, ""); 91 | 92 | ASSERT_EQ("LOG_STRING: collected fatal", errors.at(0)); 93 | } 94 | 95 | TEST(default_log_string, severity_fatal_null) { 96 | LOG_INIT(*test_argv); 97 | std::function fn = []() { 98 | LPP_CAPTURE_STDERR(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " << "collected fatal"); 99 | }; 100 | 101 | ASSERT_TRUE(checkAbort(fn)); 102 | } -------------------------------------------------------------------------------- /test/default/test_default_rosprintf.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 12.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::rosprintf; 10 | using namespace lpp::testing; 11 | 12 | TEST(default_rosprintf, ros_debug) { 13 | LOG_INIT(*test_argv); 14 | 15 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG(ERROR_MESSAGE, 3.3, 5.5)); 16 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 17 | } 18 | 19 | TEST(default_rosprintf, ros_debug_once) { 20 | LOG_INIT(*test_argv); 21 | 22 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 23 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 24 | } 25 | 26 | TEST(default_rosprintf, ros_debug_throttle) { 27 | LOG_INIT(*test_argv); 28 | 29 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 30 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 31 | } 32 | 33 | TEST(default_rosprintf, ros_info) { 34 | LOG_INIT(*test_argv); 35 | 36 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO(ERROR_MESSAGE, 3.3, 5.5)); 37 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 38 | } 39 | 40 | TEST(default_rosprintf, ros_info_once) { 41 | LOG_INIT(*test_argv); 42 | 43 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 44 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 45 | } 46 | 47 | TEST(default_rosprintf, ros_info_throttle) { 48 | LOG_INIT(*test_argv); 49 | 50 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 51 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 52 | } 53 | 54 | TEST(default_rosprintf, ros_warn) { 55 | LOG_INIT(*test_argv); 56 | 57 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN(ERROR_MESSAGE, 3.3, 5.5)); 58 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 59 | } 60 | 61 | TEST(default_rosprintf, ros_warn_once) { 62 | LOG_INIT(*test_argv); 63 | 64 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 65 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 66 | } 67 | 68 | TEST(default_rosprintf, ros_warn_throttle) { 69 | LOG_INIT(*test_argv); 70 | 71 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 72 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 73 | } 74 | 75 | TEST(default_rosprintf, ros_error) { 76 | LOG_INIT(*test_argv); 77 | 78 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5)); 79 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 80 | } 81 | 82 | TEST(default_rosprintf, ros_error_once) { 83 | LOG_INIT(*test_argv); 84 | 85 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 86 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 87 | } 88 | 89 | TEST(default_rosprintf, ros_error_throttle) { 90 | LOG_INIT(*test_argv); 91 | 92 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 93 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 94 | } 95 | 96 | TEST(default_rosprintf, ros_fatal) { 97 | LOG_INIT(*test_argv); 98 | 99 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL(ERROR_MESSAGE, 3.3, 5.5)); 100 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 101 | } 102 | 103 | TEST(default_rosprintf, ros_fatal_once) { 104 | LOG_INIT(*test_argv); 105 | 106 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 107 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 108 | } 109 | 110 | TEST(default_rosprintf, ros_fatal_throttle) { 111 | LOG_INIT(*test_argv); 112 | 113 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 114 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 115 | } -------------------------------------------------------------------------------- /test/default/test_default_timed.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 16.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef LPP_IS_GLOG_V0_6 11 | #define LPP_UNITTEST_STD_STREAM STDERR 12 | #else 13 | #define LPP_UNITTEST_STD_STREAM STDOUT 14 | #endif 15 | 16 | std::vector generateTests() { 17 | return { 18 | {"default_timed_lpp_syntax_severity_debug_Test",{"DEBUG Test123\n"},[]() { LOG_TIMED(D, 1, "Test" << 123); }, EQUAL, STDOUT}, 19 | {"default_timed_lpp_syntax_severity_info_Test",{"INFO Test123\n"},[]() { LOG_TIMED(I, 1, "Test" << 123); }, EQUAL, STDOUT}, 20 | {"default_timed_lpp_syntax_severity_warning_Test",{"WARN Test123\n"},[]() { LOG_TIMED(W, 1, "Test" << 123); }, EQUAL, STDOUT}, 21 | {"default_timed_lpp_syntax_severity_error_Test",{"ERROR Test123\n"},[]() { LOG_TIMED(E, 1, "Test" << 123); }, EQUAL, STDOUT}, 22 | {"default_timed_lpp_syntax_severity_fatal_Test",{"FATAL Test123\n"},[]() { LOG_TIMED(F, 1, "Test" << 123); }, EQUAL, STDOUT}, 23 | 24 | {"default_timed_glog_syntax_severity_debug_Test",{"Test123"},[]() { DLOG_EVERY_T(INFO, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 25 | 26 | //TODO fix on a ubuntu 24.04 system 27 | //{"default_timed_glog_syntax_severity_info_Test",{"Test123"},[]() { LOG_EVERY_T(INFO, 1) << "Test" << 123; }, IS_SUBSTRING, STDOUT}, 28 | //{"default_timed_glog_syntax_severity_warning_Test",{"Test123"},[]() { LOG_EVERY_T(WARNING, 1) << "Test" << 123; }, IS_SUBSTRING, LPP_UNITTEST_STD_STREAM}, 29 | //{"default_timed_glog_syntax_severity_error_Test",{"Test123"},[]() { LOG_EVERY_T(ERROR, 1) << "Test" << 123; }, IS_SUBSTRING, LPP_UNITTEST_STD_STREAM}, 30 | //{"default_timed_glog_syntax_severity_fatal_Test",{"Test123"},[]() { LOG_EVERY_T(FATAL, 1) << "Test" << 123; }, IS_SUBSTRING, LPP_UNITTEST_STD_STREAM}, 31 | 32 | 33 | {"default_timed_ros_syntax_severity_debug_Test", {"Test123"}, []() {ROS_DEBUG_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 34 | {"default_timed_ros_syntax_severity_debug_stream_Test", {"Test123"}, []() {ROS_DEBUG_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 35 | {"default_timed_ros_syntax_severity_info_Test", {"Test123"}, []() {ROS_INFO_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 36 | {"default_timed_ros_syntax_severity_info_stream_Test", {"Test123"}, []() {ROS_INFO_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 37 | {"default_timed_ros_syntax_severity_warning_Test", {"Test123"}, []() {ROS_WARN_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 38 | {"default_timed_ros_syntax_severity_warning_stream_Test", {"Test123"}, []() {ROS_WARN_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 39 | {"default_timed_ros_syntax_severity_error_Test", {"Test123"}, []() {ROS_ERROR_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 40 | {"default_timed_ros_syntax_severity_error_stream_Test", {"Test123"}, []() {ROS_ERROR_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 41 | {"default_timed_ros_syntax_severity_fatal_Test", {"Test123"}, []() {ROS_FATAL_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 42 | {"default_timed_ros_syntax_severity_fatal_stream_Test", {"Test123"}, []() {ROS_FATAL_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 43 | }; 44 | } 45 | 46 | TEST(default_timed, lpp_syntax_floating_point_time) { 47 | for (int i = 0; i < 5; i++) { 48 | 49 | std::string output = LPP_CAPTURE_STDOUT(LOG_TIMED(I, 0.1, "Test" << 123)); 50 | if (i % 2 == 0) { 51 | ASSERT_TRUE(isSubstring(output, "I")); 52 | ASSERT_TRUE(isSubstring(output, "Test123")); 53 | } 54 | //sleep 0.1s 55 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); 56 | } 57 | } 58 | 59 | TEST(default_timed, lpp_syntax_severity_debug) { 60 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 61 | } 62 | 63 | TEST(default_timed, lpp_syntax_severity_info) { 64 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 65 | } 66 | 67 | TEST(default_timed, lpp_syntax_severity_warning) { 68 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 69 | } 70 | 71 | TEST(default_timed, lpp_syntax_severity_error) { 72 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 73 | } 74 | 75 | TEST(default_timed, lpp_syntax_severity_fatal) { 76 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 77 | } 78 | 79 | TEST(default_timed, glog_syntax_severity_debug) { 80 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 81 | } 82 | 83 | //TEST(default_timed, glog_syntax_severity_info) { 84 | // ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 85 | //} 86 | 87 | //TEST(default_timed, glog_syntax_severity_warning) { 88 | // ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 89 | //} 90 | // 91 | //TEST(default_timed, glog_syntax_severity_error) { 92 | // ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 93 | //} 94 | // 95 | //TEST(default_timed, glog_syntax_severity_fatal) { 96 | // ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 97 | //} 98 | 99 | TEST(default_timed, ros_syntax_severity_debug) { 100 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 101 | } 102 | 103 | TEST(default_timed, ros_syntax_severity_debug_stream) { 104 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 105 | } 106 | 107 | TEST(default_timed, ros_syntax_severity_info) { 108 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 109 | } 110 | 111 | TEST(default_timed, ros_syntax_severity_info_stream) { 112 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 113 | } 114 | 115 | TEST(default_timed, ros_syntax_severity_warning) { 116 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 117 | } 118 | 119 | TEST(default_timed, ros_syntax_severity_warning_stream) { 120 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 121 | } 122 | 123 | TEST(default_timed, ros_syntax_severity_error) { 124 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 125 | } 126 | 127 | TEST(default_timed, ros_syntax_severity_error_stream) { 128 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 129 | } 130 | 131 | TEST(default_timed, ros_syntax_severity_fatal) { 132 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 133 | } 134 | 135 | TEST(default_timed, ros_syntax_severity_fatal_stream) { 136 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 137 | } -------------------------------------------------------------------------------- /test/default/test_default_vlog.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 27.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_vlog, glog_syntax_severity_v1) { 10 | LOG_INIT(*test_argv); 11 | FLAGS_v = 3; 12 | 13 | std::string output = LPP_CAPTURE_STDERR(VLOG(1) << "Test" << 123); 14 | ASSERT_TRUE(isSubstring(output, "Test123")); 15 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 16 | ASSERT_EQ(output[0], 'I'); 17 | } 18 | 19 | TEST(default_vlog, glog_syntax_severity_v3) { 20 | LOG_INIT(*test_argv); 21 | FLAGS_v = 3; 22 | 23 | std::string output = LPP_CAPTURE_STDERR(VLOG(3) << "Test123"); 24 | ASSERT_TRUE(isSubstring(output, "Test123")); 25 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 26 | ASSERT_EQ(output[0], 'I'); 27 | } 28 | 29 | TEST(default_vlog, glog_syntax_severity_v5) { 30 | LOG_INIT(*test_argv); 31 | FLAGS_v = 3; 32 | 33 | std::string output = LPP_CAPTURE_STDERR(VLOG(5) << "Test123"); 34 | ASSERT_EQ(output, ""); 35 | } 36 | 37 | TEST(default_vlog, glog_syntax_severity_if_v1) { 38 | LOG_INIT(*test_argv); 39 | FLAGS_v = 3; 40 | 41 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, true) << "Test123"); 42 | 43 | ASSERT_TRUE(isSubstring(output, "Test123")); 44 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 45 | ASSERT_EQ(output[0], 'I'); 46 | } 47 | 48 | TEST(default_vlog, glog_syntax_severity_if_v3) { 49 | LOG_INIT(*test_argv); 50 | FLAGS_v = 3; 51 | 52 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, true) << "Test123"); 53 | 54 | ASSERT_TRUE(isSubstring(output, "Test123")); 55 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 56 | ASSERT_EQ(output[0], 'I'); 57 | } 58 | 59 | TEST(default_vlog, glog_syntax_if_severity_v5) { 60 | LOG_INIT(*test_argv); 61 | FLAGS_v = 3; 62 | 63 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(5, true) << "Test123"); 64 | ASSERT_EQ(output, ""); 65 | } 66 | 67 | TEST(default_vlog, glog_syntax_ifnot_severity_v1) { 68 | LOG_INIT(*test_argv); 69 | FLAGS_v = 3; 70 | 71 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, false) << "Test123"); 72 | ASSERT_EQ(output, ""); 73 | } 74 | 75 | TEST(default_vlog, glog_syntax_ifnot_severity_v3) { 76 | LOG_INIT(*test_argv); 77 | FLAGS_v = 3; 78 | 79 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(3, false) << "Test123"); 80 | ASSERT_EQ(output, ""); 81 | } 82 | 83 | TEST(default_vlog, glog_syntax_ifnot_severity_v5) { 84 | LOG_INIT(*test_argv); 85 | FLAGS_v = 3; 86 | 87 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(5, false) << "Test123"); 88 | ASSERT_EQ(output, ""); 89 | } 90 | 91 | TEST(default_vlog, glog_syntax_every_n_severity_v1) { 92 | LOG_INIT(*test_argv); 93 | FLAGS_v = 3; 94 | 95 | for (int i = 0; i < 5; i++) { 96 | std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(1, 3) << "Test" << 123); 97 | 98 | if (i % 3 == 0) { 99 | ASSERT_TRUE(isSubstring(output, "Test123")); 100 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 101 | ASSERT_EQ(output[0], 'I'); 102 | } else { 103 | ASSERT_EQ(output, ""); 104 | } 105 | } 106 | } 107 | 108 | TEST(default_vlog, glog_syntax_every_n_severity_v3) { 109 | LOG_INIT(*test_argv); 110 | FLAGS_v = 3; 111 | 112 | for (int i = 0; i < 5; i++) { 113 | std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(3, 3) << "Test" << 123); 114 | 115 | if (i % 3 == 0) { 116 | ASSERT_TRUE(isSubstring(output, "Test123")); 117 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 118 | ASSERT_EQ(output[0], 'I'); 119 | } else { 120 | ASSERT_EQ(output, ""); 121 | } 122 | } 123 | } 124 | 125 | TEST(default_vlog, glog_syntax_every_n_severity_v5) { 126 | LOG_INIT(*test_argv); 127 | FLAGS_v = 3; 128 | 129 | for (int i = 0; i < 5; i++) { 130 | std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(5, 3) << "Test" << 123); 131 | ASSERT_EQ(output, ""); 132 | } 133 | } 134 | 135 | TEST(default_vlog, glog_syntax_if_every_n_severity_v1) { 136 | for (int i = 0; i < 5; i++) { 137 | testing::internal::CaptureStderr(); 138 | VLOG_IF_EVERY_N(1, i <= 3, 3) << "Test" << 123; 139 | std::string output = testing::internal::GetCapturedStderr(); 140 | 141 | 142 | if (i <= 3 && i % 3 == 0) { 143 | ASSERT_TRUE(isSubstring(output, "Test123")); 144 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 145 | ASSERT_EQ(output[0], 'I'); 146 | } else { 147 | ASSERT_EQ(output, ""); 148 | } 149 | } 150 | } 151 | 152 | TEST(default_vlog, glog_syntax_if_every_n_severity_v3) { 153 | for (int i = 0; i < 5; i++) { 154 | testing::internal::CaptureStderr(); 155 | VLOG_IF_EVERY_N(3, i <= 3, 3) << "Test" << 123; 156 | std::string output = testing::internal::GetCapturedStderr(); 157 | 158 | 159 | if (i <= 3 && i % 3 == 0) { 160 | ASSERT_TRUE(isSubstring(output, "Test123")); 161 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 162 | ASSERT_EQ(output[0], 'I'); 163 | } else { 164 | ASSERT_EQ(output, ""); 165 | } 166 | } 167 | } 168 | 169 | TEST(default_vlog, glog_syntax_if_every_n_severity_v5) { 170 | LOG_INIT(*test_argv); 171 | FLAGS_v = 3; 172 | 173 | for (int i = 0; i < 5; i++) { 174 | testing::internal::CaptureStderr(); 175 | VLOG_IF_EVERY_N(5, i <= 3, 3) << "Test" << 123; 176 | std::string output = testing::internal::GetCapturedStderr(); 177 | 178 | ASSERT_EQ(output, ""); 179 | } 180 | } -------------------------------------------------------------------------------- /test/default/test_severity_conversions.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 29.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | 8 | 9 | TEST(default_enum_conversions, LppToBase) { 10 | using namespace lpp::internal; 11 | ASSERT_EQ(toBase(LppSeverity::D), BaseSeverity::DEBUG); 12 | ASSERT_EQ(toBase(LppSeverity::I), BaseSeverity::INFO); 13 | ASSERT_EQ(toBase(LppSeverity::W), BaseSeverity::WARN); 14 | ASSERT_EQ(toBase(LppSeverity::E), BaseSeverity::ERROR); 15 | ASSERT_EQ(toBase(LppSeverity::F), BaseSeverity::FATAL); 16 | } 17 | 18 | TEST(default_enum_conversions, GlogToBase) { 19 | using namespace lpp::internal; 20 | ASSERT_EQ(toBase(GlogSeverity::DEBUG), BaseSeverity::DEBUG); 21 | ASSERT_EQ(toBase(GlogSeverity::INFO), BaseSeverity::INFO); 22 | ASSERT_EQ(toBase(GlogSeverity::WARNING), BaseSeverity::WARN); 23 | ASSERT_EQ(toBase(GlogSeverity::ERROR), BaseSeverity::ERROR); 24 | ASSERT_EQ(toBase(GlogSeverity::FATAL), BaseSeverity::FATAL); 25 | } -------------------------------------------------------------------------------- /test/glog/test_glog_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 08.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(glog_LogEveryN, lpp_syntax_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(D, 3, "Test" << 123)); 14 | 15 | if (i % 3 == 0) { 16 | ASSERT_TRUE(isSubstring(output, "Test123")); 17 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 18 | ASSERT_EQ(output[0], 'I'); 19 | } else { 20 | ASSERT_EQ(output, ""); 21 | } 22 | } 23 | } 24 | 25 | TEST(glog_LogEveryN, lpp_syntax_severity_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(I, 3, "Test" << 123)); 30 | 31 | if (i % 3 == 0) { 32 | ASSERT_TRUE(isSubstring(output, "Test123")); 33 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 34 | ASSERT_EQ(output[0], 'I'); 35 | } else { 36 | ASSERT_EQ(output, ""); 37 | } 38 | } 39 | } 40 | 41 | TEST(glog_LogEveryN, lpp_syntax_severity_warning) { 42 | LOG_INIT(*test_argv); 43 | 44 | for (int i = 0; i < 5; i++) { 45 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(W, 3, "Test" << 123)); 46 | 47 | if (i % 3 == 0) { 48 | ASSERT_TRUE(isSubstring(output, "Test123")); 49 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 50 | ASSERT_EQ(output[0], 'W'); 51 | } else { 52 | ASSERT_EQ(output, ""); 53 | } 54 | } 55 | } 56 | 57 | TEST(glog_LogEveryN, lpp_syntax_severity_error) { 58 | LOG_INIT(*test_argv); 59 | 60 | for (int i = 0; i < 5; i++) { 61 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(E, 3, "Test" << 123)); 62 | 63 | if (i % 3 == 0) { 64 | ASSERT_TRUE(isSubstring(output, "Test123")); 65 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 66 | ASSERT_EQ(output[0], 'E'); 67 | } else { 68 | ASSERT_EQ(output, ""); 69 | } 70 | } 71 | } 72 | 73 | TEST(glog_LogEveryN, glog_syntax_severity_debug) { 74 | LOG_INIT(*test_argv); 75 | 76 | for (int i = 0; i < 5; i++) { 77 | std::string output = LPP_CAPTURE_STDERR(DLOG_EVERY_N(INFO, 3) << "Test" << 123); 78 | 79 | if (i % 3 == 0) { 80 | ASSERT_TRUE(isSubstring(output, "Test123")); 81 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 82 | ASSERT_EQ(output[0], 'I'); 83 | } else { 84 | ASSERT_EQ(output, ""); 85 | } 86 | } 87 | } 88 | 89 | TEST(glog_LogEveryN, glog_syntax_severity_info) { 90 | LOG_INIT(*test_argv); 91 | 92 | for (int i = 0; i < 5; i++) { 93 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(INFO, 3) << "Test" << 123); 94 | 95 | if (i % 3 == 0) { 96 | ASSERT_TRUE(isSubstring(output, "Test123")); 97 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 98 | ASSERT_EQ(output[0], 'I'); 99 | } else { 100 | ASSERT_EQ(output, ""); 101 | } 102 | } 103 | } 104 | 105 | TEST(glog_LogEveryN, glog_syntax_severity_warning) { 106 | LOG_INIT(*test_argv); 107 | 108 | for (int i = 0; i < 5; i++) { 109 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(WARNING, 3) << "Test" << 123); 110 | 111 | if (i % 3 == 0) { 112 | ASSERT_TRUE(isSubstring(output, "Test123")); 113 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 114 | ASSERT_EQ(output[0], 'W'); 115 | } else { 116 | ASSERT_EQ(output, ""); 117 | } 118 | } 119 | } 120 | 121 | TEST(glog_LogEveryN, glog_syntax_severity_error) { 122 | LOG_INIT(*test_argv); 123 | 124 | for (int i = 0; i < 5; i++) { 125 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(ERROR, 3) << "Test" << 123); 126 | 127 | if (i % 3 == 0) { 128 | ASSERT_TRUE(isSubstring(output, "Test123")); 129 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 130 | ASSERT_EQ(output[0], 'E'); 131 | } else { 132 | ASSERT_EQ(output, ""); 133 | } 134 | } 135 | } 136 | 137 | TEST(glog_LogEveryN, glog_syntax_severity_fatal) { 138 | LOG_INIT(*test_argv); 139 | 140 | std::function fn = []() { 141 | for (int i = 0; i < 5; i++) { 142 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(FATAL, 3) << "Test" << 123); 143 | 144 | if (i % 3 == 0) { 145 | ASSERT_TRUE(isSubstring(output, "Test123")); 146 | ASSERT_TRUE(isSubstring(output, "test_glog_every_n.cc")); 147 | ASSERT_EQ(output[0], 'E'); 148 | } else { 149 | ASSERT_EQ(output, ""); 150 | } 151 | } 152 | }; 153 | ASSERT_TRUE(checkAbort(fn)); 154 | } -------------------------------------------------------------------------------- /test/glog/test_glog_first_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 08.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(glog_LogFirstN, lpp_syntax_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(D, 3, "Test" << 123)); 14 | 15 | if (i < 3) { 16 | ASSERT_TRUE(isSubstring(output, "Test123")); 17 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 18 | ASSERT_EQ(output[0], 'I'); 19 | } else { 20 | ASSERT_EQ(output, ""); 21 | } 22 | } 23 | } 24 | 25 | TEST(glog_LogFirstN, lpp_syntax_severity_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(I, 3, "Test" << 123)); 30 | 31 | if (i < 3) { 32 | ASSERT_TRUE(isSubstring(output, "Test123")); 33 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 34 | ASSERT_EQ(output[0], 'I'); 35 | } else { 36 | ASSERT_EQ(output, ""); 37 | } 38 | } 39 | } 40 | 41 | TEST(glog_LogFirstN, lpp_syntax_severity_warning) { 42 | LOG_INIT(*test_argv); 43 | 44 | for (int i = 0; i < 5; i++) { 45 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(W, 3, "Test" << 123)); 46 | 47 | if (i < 3) { 48 | ASSERT_TRUE(isSubstring(output, "Test123")); 49 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 50 | ASSERT_EQ(output[0], 'W'); 51 | } else { 52 | ASSERT_EQ(output, ""); 53 | } 54 | } 55 | } 56 | 57 | TEST(glog_LogFirstN, lpp_syntax_severity_error) { 58 | LOG_INIT(*test_argv); 59 | 60 | for (int i = 0; i < 5; i++) { 61 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(E, 3, "Test" << 123)); 62 | 63 | if (i < 3) { 64 | ASSERT_TRUE(isSubstring(output, "Test123")); 65 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 66 | ASSERT_EQ(output[0], 'E'); 67 | } else { 68 | ASSERT_EQ(output, ""); 69 | } 70 | } 71 | } 72 | 73 | TEST(glog_LogFirstN, glog_syntax_severity_debug) { 74 | LOG_INIT(*test_argv); 75 | 76 | for (int i = 0; i < 5; i++) { 77 | std::string output = LPP_CAPTURE_STDERR(DLOG_FIRST_N(INFO, 3) << "Test" << 123); 78 | 79 | if (i < 3) { 80 | ASSERT_TRUE(isSubstring(output, "Test123")); 81 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 82 | ASSERT_EQ(output[0], 'I'); 83 | } else { 84 | ASSERT_EQ(output, ""); 85 | } 86 | } 87 | } 88 | 89 | TEST(glog_LogFirstN, glog_syntax_severity_info) { 90 | LOG_INIT(*test_argv); 91 | 92 | for (int i = 0; i < 5; i++) { 93 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(INFO, 3) << "Test" << 123); 94 | 95 | if (i < 3) { 96 | ASSERT_TRUE(isSubstring(output, "Test123")); 97 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 98 | ASSERT_EQ(output[0], 'I'); 99 | } else { 100 | ASSERT_EQ(output, ""); 101 | } 102 | } 103 | } 104 | 105 | TEST(glog_LogFirstN, glog_syntax_severity_warning) { 106 | LOG_INIT(*test_argv); 107 | 108 | for (int i = 0; i < 5; i++) { 109 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(WARNING, 3) << "Test" << 123); 110 | 111 | if (i < 3) { 112 | ASSERT_TRUE(isSubstring(output, "Test123")); 113 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 114 | ASSERT_EQ(output[0], 'W'); 115 | } else { 116 | ASSERT_EQ(output, ""); 117 | } 118 | } 119 | } 120 | 121 | TEST(glog_LogFirstN, glog_syntax_severity_error) { 122 | LOG_INIT(*test_argv); 123 | 124 | for (int i = 0; i < 5; i++) { 125 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(ERROR, 3) << "Test" << 123); 126 | 127 | if (i < 3) { 128 | ASSERT_TRUE(isSubstring(output, "Test123")); 129 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 130 | ASSERT_EQ(output[0], 'E'); 131 | } else { 132 | ASSERT_EQ(output, ""); 133 | } 134 | } 135 | } 136 | 137 | TEST(glog_LogFirstN, ros_debug_once) { 138 | LOG_INIT(*test_argv); 139 | 140 | for (int i = 0; i < 5; i++) { 141 | std::string output = LPP_CAPTURE_STDERR(ROS_DEBUG_ONCE("Test123")); 142 | 143 | if (i == 0) { 144 | ASSERT_TRUE(isSubstring(output, "Test123")); 145 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 146 | ASSERT_EQ(output[0], 'I'); 147 | } else { 148 | ASSERT_EQ("", output); 149 | } 150 | } 151 | } 152 | 153 | TEST(glog_LogFirstN, ros_info_once) { 154 | LOG_INIT(*test_argv); 155 | 156 | for (int i = 0; i < 5; i++) { 157 | std::string output = LPP_CAPTURE_STDERR(ROS_INFO_ONCE("Test123")); 158 | 159 | if (i == 0) { 160 | ASSERT_TRUE(isSubstring(output, "Test123")); 161 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 162 | ASSERT_EQ(output[0], 'I'); 163 | } else { 164 | ASSERT_EQ("", output); 165 | } 166 | } 167 | } 168 | 169 | TEST(glog_LogFirstN, ros_warn_once) { 170 | LOG_INIT(*test_argv); 171 | 172 | for (int i = 0; i < 5; i++) { 173 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE("Test123")); 174 | 175 | if (i == 0) { 176 | ASSERT_TRUE(isSubstring(output, "Test123")); 177 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 178 | ASSERT_EQ(output[0], 'W'); 179 | } else { 180 | ASSERT_EQ("", output); 181 | } 182 | } 183 | } 184 | 185 | TEST(glog_LogFirstN, ros_error_once) { 186 | LOG_INIT(*test_argv); 187 | 188 | for (int i = 0; i < 5; i++) { 189 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE("Test123")); 190 | 191 | if (i == 0) { 192 | ASSERT_TRUE(isSubstring(output, "Test123")); 193 | ASSERT_TRUE(isSubstring(output, "test_glog_first_n.cc")); 194 | ASSERT_EQ(output[0], 'E'); 195 | } else { 196 | ASSERT_EQ("", output); 197 | } 198 | } 199 | } -------------------------------------------------------------------------------- /test/glog/test_glog_if_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 15.12.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | testing::internal::CaptureStderr(); 14 | DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 15 | std::string output = testing::internal::GetCapturedStderr(); 16 | 17 | if (i <= 3 && i % 3 == 0) { 18 | ASSERT_TRUE(isSubstring(output, "Test123")); 19 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 20 | ASSERT_EQ(output[0], 'I'); 21 | } else { 22 | ASSERT_EQ(output, ""); 23 | } 24 | } 25 | } 26 | 27 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_info) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | testing::internal::CaptureStderr(); 32 | LOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 33 | std::string output = testing::internal::GetCapturedStderr(); 34 | 35 | if (i <= 3 && i % 3 == 0) { 36 | ASSERT_TRUE(isSubstring(output, "Test123")); 37 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 38 | ASSERT_EQ(output[0], 'I'); 39 | } else { 40 | ASSERT_EQ(output, ""); 41 | } 42 | } 43 | } 44 | 45 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_warning) { 46 | LOG_INIT(*test_argv); 47 | 48 | for (int i = 0; i < 5; i++) { 49 | testing::internal::CaptureStderr(); 50 | LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "Test" << 123; 51 | std::string output = testing::internal::GetCapturedStderr(); 52 | 53 | if (i <= 3 && i % 3 == 0) { 54 | ASSERT_TRUE(isSubstring(output, "Test123")); 55 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 56 | ASSERT_EQ(output[0], 'W'); 57 | } else { 58 | ASSERT_EQ(output, ""); 59 | } 60 | } 61 | } 62 | 63 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_error) { 64 | LOG_INIT(*test_argv); 65 | FLAGS_v = 3; 66 | 67 | for (int i = 0; i < 5; i++) { 68 | testing::internal::CaptureStderr(); 69 | LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "Test" << 123; 70 | std::string output = testing::internal::GetCapturedStderr(); 71 | 72 | if (i <= 3 && i % 3 == 0) { 73 | ASSERT_TRUE(isSubstring(output, "Test123")); 74 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 75 | ASSERT_EQ(output[0], 'E'); 76 | } else { 77 | ASSERT_EQ(output, ""); 78 | } 79 | } 80 | } 81 | 82 | TEST(default_if_every_n, glog_syntax_if_every_n_severity_fatal) { 83 | LOG_INIT(*test_argv); 84 | FLAGS_v = 3; 85 | 86 | std::function fn = []() { 87 | for (int i = 0; i < 5; i++) { 88 | testing::internal::CaptureStderr(); 89 | LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "Test" << 123; 90 | std::string output = testing::internal::GetCapturedStderr(); 91 | } 92 | }; 93 | 94 | ASSERT_TRUE(checkAbort(fn)); 95 | } -------------------------------------------------------------------------------- /test/glog/test_glog_log_string.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 28.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(default_log_string, severity_info) { 10 | LOG_INIT(*test_argv); 11 | 12 | std::vector errors; 13 | 14 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 15 | testing::internal::CaptureStderr(); 16 | LOG_STRING(INFO, &errors) << "LOG_STRING: " << "collected info"; 17 | std::string output = testing::internal::GetCapturedStderr(); 18 | 19 | ASSERT_EQ(output, ""); 20 | ASSERT_EQ("LOG_STRING: collected info", errors.at(0)); 21 | } 22 | 23 | TEST(default_log_string, severity_info_null) { 24 | LOG_INIT(*test_argv); 25 | 26 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(INFO, nullptr) << "LOG_STRING: " << "collected info"); 27 | 28 | ASSERT_EQ(output[0], 'I'); 29 | ASSERT_TRUE(isSubstring(output, "test_glog_log_string.cc")); 30 | ASSERT_TRUE(isSubstring(output, "LOG_STRING: collected info")); 31 | } 32 | 33 | TEST(default_log_string, severity_warning) { 34 | LOG_INIT(*test_argv); 35 | 36 | std::vector errors; 37 | 38 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 39 | testing::internal::CaptureStderr(); 40 | LOG_STRING(WARNING, &errors) << "LOG_STRING: " << "collected warn"; 41 | std::string output = testing::internal::GetCapturedStderr(); 42 | 43 | ASSERT_EQ(output, ""); 44 | ASSERT_EQ("LOG_STRING: collected warn", errors.at(0)); 45 | } 46 | 47 | TEST(default_log_string, severity_warning_null) { 48 | LOG_INIT(*test_argv); 49 | 50 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " << "collected warn"); 51 | 52 | ASSERT_EQ(output[0], 'W'); 53 | ASSERT_TRUE(isSubstring(output, "test_glog_log_string.cc")); 54 | ASSERT_TRUE(isSubstring(output, "LOG_STRING: collected warn")); 55 | } 56 | 57 | TEST(default_log_string, severity_error) { 58 | LOG_INIT(*test_argv); 59 | 60 | std::vector errors; 61 | 62 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 63 | testing::internal::CaptureStderr(); 64 | LOG_STRING(ERROR, &errors) << "LOG_STRING: " << "collected error"; 65 | std::string output = testing::internal::GetCapturedStderr(); 66 | 67 | ASSERT_EQ(output, ""); 68 | ASSERT_EQ("LOG_STRING: collected error", errors.at(0)); 69 | } 70 | 71 | TEST(default_log_string, severity_error_null) { 72 | LOG_INIT(*test_argv); 73 | 74 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " << "collected error"); 75 | 76 | ASSERT_EQ(output[0], 'E'); 77 | ASSERT_TRUE(isSubstring(output, "test_glog_log_string.cc")); 78 | ASSERT_TRUE(isSubstring(output, "LOG_STRING: collected error")); 79 | } 80 | 81 | TEST(default_log_string, severity_fatal) { 82 | LOG_INIT(*test_argv); 83 | 84 | std::vector errors; 85 | 86 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 87 | testing::internal::CaptureStderr(); 88 | LOG_STRING(FATAL, &errors) << "LOG_STRING: " << "collected fatal"; 89 | std::string output = testing::internal::GetCapturedStderr(); 90 | ASSERT_EQ(output, ""); 91 | 92 | ASSERT_EQ("LOG_STRING: collected fatal", errors.at(0)); 93 | } 94 | 95 | TEST(default_log_string, severity_fatal_null) { 96 | LOG_INIT(*test_argv); 97 | std::function fn = []() { 98 | LPP_CAPTURE_STDERR(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " << "collected fatal"); 99 | }; 100 | 101 | ASSERT_TRUE(checkAbort(fn)); 102 | } -------------------------------------------------------------------------------- /test/glog/test_glog_rosprintf.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 08.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(glog_rosprintf, ros_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | std::string c = LPP_CAPTURE_STDERR(ROS_DEBUG("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 13 | 14 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 15 | ASSERT_TRUE(c[0] == 'I'); 16 | } 17 | 18 | TEST(glog_rosprintf, ros_debug_once) { 19 | LOG_INIT(*test_argv); 20 | 21 | std::string c = LPP_CAPTURE_STDERR(ROS_DEBUG_ONCE("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 22 | 23 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 24 | ASSERT_TRUE(c[0] == 'I'); 25 | } 26 | 27 | TEST(glog_rosprintf, ros_info) { 28 | LOG_INIT(*test_argv); 29 | 30 | std::string c = LPP_CAPTURE_STDERR(ROS_INFO("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 31 | 32 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 33 | ASSERT_TRUE(c[0] == 'I'); 34 | } 35 | 36 | TEST(glog_rosprintf, ros_info_once) { 37 | LOG_INIT(*test_argv); 38 | 39 | std::string c = LPP_CAPTURE_STDERR(ROS_INFO_ONCE("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 40 | 41 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 42 | ASSERT_TRUE(c[0] == 'I'); 43 | } 44 | 45 | TEST(glog_rosprintf, ros_warn) { 46 | LOG_INIT(*test_argv); 47 | 48 | std::string c = LPP_CAPTURE_STDERR(ROS_WARN("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 49 | 50 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 51 | ASSERT_TRUE(c[0] == 'W'); 52 | } 53 | 54 | TEST(glog_rosprintf, ros_warn_once) { 55 | LOG_INIT(*test_argv); 56 | 57 | std::string c = LPP_CAPTURE_STDERR(ROS_WARN_ONCE("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 58 | 59 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 60 | ASSERT_TRUE(c[0] == 'W'); 61 | } 62 | 63 | TEST(glog_rosprintf, ros_error) { 64 | LOG_INIT(*test_argv); 65 | 66 | std::string c = LPP_CAPTURE_STDERR(ROS_ERROR("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 67 | 68 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 69 | ASSERT_TRUE(c[0] == 'E'); 70 | } 71 | 72 | TEST(glog_rosprintf, ros_error_once) { 73 | LOG_INIT(*test_argv); 74 | 75 | std::string c = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 76 | 77 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 78 | ASSERT_TRUE(c[0] == 'E'); 79 | } 80 | 81 | TEST(glog_rosprintf, ros_fatal) { 82 | LOG_INIT(*test_argv); 83 | 84 | std::function fn = []() { 85 | std::string c = LPP_CAPTURE_STDERR(ROS_FATAL("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 86 | 87 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 88 | ASSERT_TRUE(c[0] == 'E'); 89 | }; 90 | 91 | ASSERT_TRUE(checkAbort(fn)); 92 | } 93 | 94 | TEST(glog_rosprintf, ros_fatal_once) { 95 | LOG_INIT(*test_argv); 96 | 97 | std::function fn = []() { 98 | std::string c = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE("Base angle (%f) is less than the minimum angle (%f)", 3.3, 5.5)); 99 | 100 | ASSERT_TRUE(isSubstring(c, "Base angle (3.300000) is less than the minimum angle (5.500000)\n")); 101 | ASSERT_TRUE(c[0] == 'E'); 102 | }; 103 | 104 | ASSERT_TRUE(checkAbort(fn)); 105 | } -------------------------------------------------------------------------------- /test/glog/test_glog_timed.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 16.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | std::vector generateTests() { 11 | return { 12 | {"glog_timed_lpp_syntax_severity_debug_Test",{"Test123"},[]() { LOG_TIMED(D, 1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 13 | {"glog_timed_lpp_syntax_severity_info_Test",{"Test123"},[]() { LOG_TIMED(I, 1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 14 | {"glog_timed_lpp_syntax_severity_warning_Test",{"Test123"},[]() { LOG_TIMED(W, 1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 15 | {"glog_timed_lpp_syntax_severity_error_Test",{"Test123"},[]() { LOG_TIMED(E, 1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 16 | //{"glog_timed_lpp_syntax_severity_fatal_Test",{"Test123",[]() { LOG_TIMED(F, 1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 17 | 18 | {"glog_timed_glog_syntax_severity_debug_Test",{"Test123"},[]() { DLOG_EVERY_T(INFO, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 19 | {"glog_timed_glog_syntax_severity_info_Test",{"Test123"},[]() { LOG_EVERY_T(INFO, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 20 | {"glog_timed_glog_syntax_severity_warning_Test",{"Test123"},[]() { LOG_EVERY_T(WARNING, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 21 | {"glog_timed_glog_syntax_severity_error_Test",{"Test123"},[]() { LOG_EVERY_T(ERROR, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 22 | //{"glog_timed_glog_syntax_severity_fatal_Test",{"Test123"},[]() { LOG_EVERY_T(FATAL, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 23 | 24 | {"glog_timed_ros_syntax_severity_debug_Test", {"Test123"}, []() {ROS_DEBUG_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 25 | {"glog_timed_ros_syntax_severity_debug_stream_Test", {"Test123"}, []() {ROS_DEBUG_STREAM_THROTTLE(1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 26 | {"glog_timed_ros_syntax_severity_info_Test", {"Test123"}, []() {ROS_INFO_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 27 | {"glog_timed_ros_syntax_severity_info_stream_Test", {"Test123"}, []() {ROS_INFO_STREAM_THROTTLE(1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 28 | {"glog_timed_ros_syntax_severity_warning_Test", {"Test123"}, []() {ROS_WARN_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 29 | {"glog_timed_ros_syntax_severity_warning_stream_Test", {"Test123"}, []() {ROS_WARN_STREAM_THROTTLE(1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 30 | {"glog_timed_ros_syntax_severity_error_Test", {"Test123"}, []() {ROS_ERROR_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 31 | {"glog_timed_ros_syntax_severity_error_stream_Test", {"Test123"}, []() {ROS_ERROR_STREAM_THROTTLE(1, "Test" << 123); }, IS_SUBSTRING, STDERR}, 32 | //{"glog_timed_ros_syntax_severity_fatal_Test", {"Test123"}, []() {ROS_FATAL_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 33 | //{"glog_timed_ros_syntax_severity_fatal_stream_Test", {"Test123"}, []() {ROS_FATAL_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 34 | }; 35 | } 36 | 37 | TEST(glog_timed, lpp_syntax_floating_point_time) { 38 | LOG_INIT(*test_argv); 39 | for (int i = 0; i < 5; i++) { 40 | 41 | std::string output = LPP_CAPTURE_STDERR(LOG_TIMED(I, 0.1, "Test" << 123)); 42 | if (i % 2 == 0) { 43 | ASSERT_TRUE(isSubstring(output, "I")); 44 | ASSERT_TRUE(isSubstring(output, "Test123")); 45 | } 46 | //sleep 0.1s 47 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); 48 | } 49 | } 50 | 51 | TEST(glog_timed, lpp_syntax_severity_debug) { 52 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 53 | } 54 | 55 | TEST(glog_timed, lpp_syntax_severity_info) { 56 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 57 | } 58 | 59 | TEST(glog_timed, lpp_syntax_severity_warning) { 60 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 61 | } 62 | 63 | TEST(glog_timed, lpp_syntax_severity_error) { 64 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 65 | } 66 | 67 | TEST(glog_timed, lpp_syntax_severity_fatal) { 68 | //ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 69 | } 70 | 71 | TEST(glog_timed, glog_syntax_severity_debug) { 72 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 73 | } 74 | 75 | TEST(glog_timed, glog_syntax_severity_info) { 76 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 77 | } 78 | 79 | TEST(glog_timed, glog_syntax_severity_warning) { 80 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 81 | } 82 | 83 | TEST(glog_timed, glog_syntax_severity_error) { 84 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 85 | } 86 | 87 | TEST(glog_timed, glog_syntax_severity_fatal) { 88 | //ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 89 | } 90 | 91 | TEST(glog_timed, ros_syntax_severity_debug) { 92 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 93 | } 94 | 95 | TEST(glog_timed, ros_syntax_severity_debug_stream) { 96 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 97 | } 98 | 99 | TEST(glog_timed, ros_syntax_severity_info) { 100 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 101 | } 102 | 103 | TEST(glog_timed, ros_syntax_severity_info_stream) { 104 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 105 | } 106 | 107 | TEST(glog_timed, ros_syntax_severity_warning) { 108 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 109 | } 110 | 111 | TEST(glog_timed, ros_syntax_severity_warning_stream) { 112 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 113 | } 114 | 115 | TEST(glog_timed, ros_syntax_severity_error) { 116 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 117 | } 118 | 119 | TEST(glog_timed, ros_syntax_severity_error_stream) { 120 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 121 | } 122 | 123 | TEST(glog_timed, ros_syntax_severity_fatal) { 124 | //ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 125 | } 126 | 127 | TEST(glog_timed, ros_syntax_severity_fatal_stream) { 128 | //ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 129 | } -------------------------------------------------------------------------------- /test/glog/test_glog_vlog.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 27.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(glog_vlog, glog_syntax_severity_v1) { 10 | LOG_INIT(*test_argv); 11 | FLAGS_v = 3; 12 | 13 | std::string output = LPP_CAPTURE_STDERR(VLOG(1) << "Test" << 123); 14 | ASSERT_TRUE(isSubstring(output, "Test123")); 15 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 16 | ASSERT_EQ(output[0], 'I'); 17 | } 18 | 19 | TEST(glog_vlog, glog_syntax_severity_v3) { 20 | LOG_INIT(*test_argv); 21 | FLAGS_v = 3; 22 | 23 | std::string output = LPP_CAPTURE_STDERR(VLOG(3) << "Test123"); 24 | ASSERT_TRUE(isSubstring(output, "Test123")); 25 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 26 | ASSERT_EQ(output[0], 'I'); 27 | } 28 | 29 | TEST(glog_vlog, glog_syntax_severity_v5) { 30 | LOG_INIT(*test_argv); 31 | FLAGS_v = 3; 32 | 33 | std::string output = LPP_CAPTURE_STDERR(VLOG(5) << "Test123"); 34 | ASSERT_EQ(output, ""); 35 | } 36 | 37 | TEST(glog_vlog, glog_syntax_if_severity_v1) { 38 | LOG_INIT(*test_argv); 39 | FLAGS_v = 3; 40 | 41 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, true) << "Test123"); 42 | 43 | ASSERT_TRUE(isSubstring(output, "Test123")); 44 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 45 | ASSERT_EQ(output[0], 'I'); 46 | } 47 | 48 | TEST(glog_vlog, glog_syntax_if_severity_v3) { 49 | LOG_INIT(*test_argv); 50 | FLAGS_v = 3; 51 | 52 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, true) << "Test123"); 53 | 54 | ASSERT_TRUE(isSubstring(output, "Test123")); 55 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 56 | ASSERT_EQ(output[0], 'I'); 57 | } 58 | 59 | TEST(glog_vlog, glog_syntax_if_severity_v5) { 60 | LOG_INIT(*test_argv); 61 | FLAGS_v = 3; 62 | 63 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(5, true) << "Test123"); 64 | ASSERT_EQ(output, ""); 65 | } 66 | 67 | TEST(glog_vlog, glog_syntax_ifnot_severity_v1) { 68 | LOG_INIT(*test_argv); 69 | FLAGS_v = 3; 70 | 71 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(1, false) << "Test123"); 72 | ASSERT_EQ(output, ""); 73 | } 74 | 75 | TEST(glog_vlog, glog_syntax_ifnot_severity_v3) { 76 | LOG_INIT(*test_argv); 77 | FLAGS_v = 3; 78 | 79 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(3, false) << "Test123"); 80 | ASSERT_EQ(output, ""); 81 | } 82 | 83 | TEST(glog_vlog, glog_syntax_ifnot_severity_v5) { 84 | LOG_INIT(*test_argv); 85 | FLAGS_v = 3; 86 | 87 | std::string output = LPP_CAPTURE_STDERR(VLOG_IF(5, false) << "Test123"); 88 | ASSERT_EQ(output, ""); 89 | } 90 | 91 | TEST(default_vlog, glog_syntax_every_n_severity_v1) { 92 | LOG_INIT(*test_argv); 93 | FLAGS_v = 3; 94 | 95 | for (int i = 0; i < 5; i++) { 96 | std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(1, 3) << "Test" << 123); 97 | 98 | if (i % 3 == 0) { 99 | ASSERT_TRUE(isSubstring(output, "Test123")); 100 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 101 | ASSERT_EQ(output[0], 'I'); 102 | } else { 103 | ASSERT_EQ(output, ""); 104 | } 105 | } 106 | } 107 | 108 | TEST(default_vlog, glog_syntax_every_n_severity_v3) { 109 | LOG_INIT(*test_argv); 110 | FLAGS_v = 3; 111 | 112 | for (int i = 0; i < 5; i++) { 113 | std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(3, 3) << "Test" << 123); 114 | 115 | if (i % 3 == 0) { 116 | ASSERT_TRUE(isSubstring(output, "Test123")); 117 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 118 | ASSERT_EQ(output[0], 'I'); 119 | } else { 120 | ASSERT_EQ(output, ""); 121 | } 122 | } 123 | } 124 | 125 | TEST(default_vlog, glog_syntax_every_n_severity_v5) { 126 | LOG_INIT(*test_argv); 127 | FLAGS_v = 3; 128 | 129 | for (int i = 0; i < 5; i++) { 130 | std::string output = LPP_CAPTURE_STDERR(VLOG_EVERY_N(5, 3) << "Test" << 123); 131 | ASSERT_EQ(output, ""); 132 | } 133 | } 134 | 135 | TEST(default_vlog, glog_syntax_if_every_n_severity_v1) { 136 | for (int i = 0; i < 5; i++) { 137 | testing::internal::CaptureStderr(); 138 | VLOG_IF_EVERY_N(1, i <= 3, 3) << "Test" << 123; 139 | std::string output = testing::internal::GetCapturedStderr(); 140 | 141 | 142 | if (i <= 3 && i % 3 == 0) { 143 | ASSERT_TRUE(isSubstring(output, "Test123")); 144 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 145 | ASSERT_EQ(output[0], 'I'); 146 | } else { 147 | ASSERT_EQ(output, ""); 148 | } 149 | } 150 | } 151 | 152 | TEST(default_vlog, glog_syntax_if_every_n_severity_v3) { 153 | for (int i = 0; i < 5; i++) { 154 | testing::internal::CaptureStderr(); 155 | VLOG_IF_EVERY_N(3, i <= 3, 3) << "Test" << 123; 156 | std::string output = testing::internal::GetCapturedStderr(); 157 | 158 | 159 | if (i <= 3 && i % 3 == 0) { 160 | ASSERT_TRUE(isSubstring(output, "Test123")); 161 | ASSERT_TRUE(isSubstring(output, LPP_FILENAME)); 162 | ASSERT_EQ(output[0], 'I'); 163 | } else { 164 | ASSERT_EQ(output, ""); 165 | } 166 | } 167 | } 168 | 169 | TEST(default_vlog, glog_syntax_if_every_n_severity_v5) { 170 | LOG_INIT(*test_argv); 171 | FLAGS_v = 3; 172 | 173 | for (int i = 0; i < 5; i++) { 174 | testing::internal::CaptureStderr(); 175 | VLOG_IF_EVERY_N(5, i <= 3, 3) << "Test" << 123; 176 | std::string output = testing::internal::GetCapturedStderr(); 177 | 178 | ASSERT_EQ(output, ""); 179 | } 180 | } -------------------------------------------------------------------------------- /test/lpp/custom/callback.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #ifndef LOG_TEST_LPP_CUSTOM_CALLBACK_H_ 6 | #define LOG_TEST_LPP_CUSTOM_CALLBACK_H_ 7 | 8 | #include 9 | 10 | namespace lpp{ 11 | namespace custom{ 12 | inline void logCallback(BaseSeverity severity, const std::string& str) { 13 | 14 | std::string severity_str; 15 | switch (severity) { 16 | 17 | case BaseSeverity::DEBUG:severity_str="debug"; break; 18 | case BaseSeverity::INFO:severity_str="info"; break; 19 | case BaseSeverity::WARN:severity_str="warning"; break; 20 | case BaseSeverity::ERROR:severity_str="error"; break; 21 | case BaseSeverity::FATAL:severity_str="fatal"; break; 22 | } 23 | 24 | 25 | std::cout << "Log++ [" << severity_str << "] " << str << std::endl; 26 | } 27 | } 28 | } 29 | 30 | #endif //LOG_TEST_LPP_CUSTOM_CALLBACK_H_ 31 | -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_basic.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | 12 | //! LPP syntax 13 | 14 | TEST(lpp_custom_basic, lpp_syntax_severity_debug) { 15 | LOG_INIT(*test_argv, logCallback); 16 | 17 | std::string output = LPP_CAPTURE_STDOUT(LOG(D, "test" << 123)); 18 | 19 | ASSERT_EQ(output, debug + test123); 20 | } 21 | 22 | TEST(lpp_custom_basic, lpp_syntax_severity_info) { 23 | LOG_INIT(*test_argv, logCallback); 24 | 25 | std::string output = LPP_CAPTURE_STDOUT(LOG(I, "test" << 123)); 26 | 27 | ASSERT_EQ(output, info + test123); 28 | } 29 | 30 | TEST(lpp_custom_basic, lpp_syntax_severity_warning) { 31 | LOG_INIT(*test_argv, logCallback); 32 | 33 | std::string output = LPP_CAPTURE_STDOUT(LOG(W, "test" << 123)); 34 | 35 | ASSERT_EQ(output, warning + test123); 36 | } 37 | 38 | TEST(lpp_custom_basic, lpp_syntax_severity_error) { 39 | LOG_INIT(*test_argv, logCallback); 40 | 41 | std::string output = LPP_CAPTURE_STDOUT(LOG(E, "test" << 123)); 42 | 43 | ASSERT_EQ(output, error + test123); 44 | } 45 | 46 | TEST(lpp_custom_basic, lpp_syntax_severity_fatal) { 47 | LOG_INIT(*test_argv, logCallback); 48 | 49 | std::string output = LPP_CAPTURE_STDOUT(LOG(F, "test" << 123)); 50 | 51 | ASSERT_EQ(output, fatal + test123); 52 | } 53 | 54 | 55 | //! Glog syntax 56 | TEST(lpp_custom_basic, glog_syntax_severity_debug) { 57 | LOG_INIT(*test_argv, logCallback); 58 | 59 | std::string output = LPP_CAPTURE_STDOUT(DLOG(INFO) << "test" << 123;); 60 | 61 | ASSERT_EQ(output, debug + test123); 62 | } 63 | 64 | TEST(lpp_custom_basic, glog_syntax_severity_info) { 65 | LOG_INIT(*test_argv, logCallback); 66 | 67 | std::string output = LPP_CAPTURE_STDOUT(LOG(INFO) << "test" << 123;); 68 | 69 | ASSERT_EQ(output, info + test123); 70 | } 71 | 72 | TEST(lpp_custom_basic, glog_syntax_severity_warning) { 73 | LOG_INIT(*test_argv, logCallback); 74 | 75 | std::string output = LPP_CAPTURE_STDOUT(LOG(WARNING) << "test" << 123;); 76 | 77 | ASSERT_EQ(output, warning + test123); 78 | } 79 | 80 | TEST(lpp_custom_basic, glog_syntax_severity_error) { 81 | LOG_INIT(*test_argv, logCallback); 82 | 83 | std::string output = LPP_CAPTURE_STDOUT(LOG(ERROR) << "test" << 123;); 84 | 85 | ASSERT_EQ(output, error + test123); 86 | } 87 | 88 | TEST(lpp_custom_basic, glog_syntax_severity_fatal) { 89 | LOG_INIT(*test_argv, logCallback); 90 | 91 | std::string output = LPP_CAPTURE_STDOUT(LOG(FATAL) << "test" << 123;); 92 | 93 | ASSERT_EQ(output, fatal + test123); 94 | } 95 | 96 | 97 | //! Roslog syntax 98 | TEST(lpp_custom_basic, roslog_syntax_severity_debug) { 99 | LOG_INIT(*test_argv); 100 | 101 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG("test123")); 102 | ASSERT_EQ(output, debug + test123); 103 | } 104 | 105 | TEST(lpp_custom_basic, roslog_syntax_severity_debug_stream) { 106 | LOG_INIT(*test_argv); 107 | 108 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("test" << 123)); 109 | ASSERT_EQ(output, debug + test123); 110 | } 111 | 112 | TEST(lpp_custom_basic, roslog_syntax_severity_info) { 113 | LOG_INIT(*test_argv); 114 | 115 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO("test123")); 116 | ASSERT_EQ(output, info + test123); 117 | } 118 | 119 | TEST(lpp_custom_basic, roslog_syntax_severity_info_stream) { 120 | LOG_INIT(*test_argv); 121 | 122 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("test" << 123)); 123 | ASSERT_EQ(output, info + test123); 124 | } 125 | 126 | TEST(lpp_custom_basic, roslog_syntax_severity_warning) { 127 | LOG_INIT(*test_argv); 128 | 129 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN("test123")); 130 | ASSERT_EQ(output, warning + test123); 131 | } 132 | 133 | TEST(lpp_custom_basic, roslog_syntax_severity_warning_stream) { 134 | LOG_INIT(*test_argv); 135 | 136 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_STREAM("test" << 123)); 137 | ASSERT_EQ(output, warning + test123); 138 | } 139 | 140 | TEST(lpp_custom_basic, roslog_syntax_severity_error) { 141 | LOG_INIT(*test_argv); 142 | 143 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR("test123")); 144 | ASSERT_EQ(output, error + test123); 145 | } 146 | 147 | TEST(lpp_custom_basic, roslog_syntax_severity_error_stream) { 148 | LOG_INIT(*test_argv); 149 | 150 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_STREAM("test" << 123)); 151 | ASSERT_EQ(output, error + test123); 152 | } 153 | 154 | TEST(lpp_custom_basic, roslog_syntax_severity_fatal) { 155 | LOG_INIT(*test_argv); 156 | 157 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL("test123")); 158 | ASSERT_EQ(output, fatal + test123); 159 | } 160 | 161 | TEST(lpp_custom_basic, roslog_syntax_severity_fatal_stream) { 162 | LOG_INIT(*test_argv); 163 | 164 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_STREAM("test" << 123)); 165 | ASSERT_EQ(output, fatal + test123); 166 | } 167 | 168 | -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | 12 | TEST(lpp_custom_LogEveryN, lpp_syntax_severity_debug) { 13 | LOG_INIT(*test_argv, logCallback); 14 | for (int i = 0; i < 5; i++) { 15 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(D, 3, "test" << 123)); 16 | 17 | if (i % 3 == 0) { 18 | ASSERT_EQ(output, debug + test123); 19 | } else { 20 | ASSERT_EQ(output, ""); 21 | } 22 | } 23 | } 24 | 25 | TEST(lpp_custom_LogEveryN, lpp_syntax_severity_info) { 26 | LOG_INIT(*test_argv, logCallback); 27 | for (int i = 0; i < 5; i++) { 28 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(I, 3, "test" << 123)); 29 | 30 | if (i % 3 == 0) { 31 | ASSERT_EQ(output, info + test123); 32 | } else { 33 | ASSERT_EQ(output, ""); 34 | } 35 | } 36 | } 37 | 38 | TEST(lpp_custom_LogEveryN, lpp_syntax_severity_warning) { 39 | LOG_INIT(*test_argv, logCallback); 40 | for (int i = 0; i < 5; i++) { 41 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(W, 3, "test" << 123)); 42 | 43 | if (i % 3 == 0) { 44 | ASSERT_EQ(output, warning + test123); 45 | } else { 46 | ASSERT_EQ(output, ""); 47 | } 48 | } 49 | } 50 | 51 | TEST(lpp_custom_LogEveryN, lpp_syntax_severity_error) { 52 | LOG_INIT(*test_argv, logCallback); 53 | for (int i = 0; i < 5; i++) { 54 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(E, 3, "test" << 123)); 55 | 56 | if (i % 3 == 0) { 57 | ASSERT_EQ(output, error + test123); 58 | } else { 59 | ASSERT_EQ(output, ""); 60 | } 61 | } 62 | } 63 | 64 | TEST(lpp_custom_LogEveryN, lpp_syntax_severity_fatal) { 65 | LOG_INIT(*test_argv, logCallback); 66 | for (int i = 0; i < 5; i++) { 67 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(F, 3, "test" << 123)); 68 | 69 | if (i % 3 == 0) { 70 | ASSERT_EQ(output, fatal + test123); 71 | } else { 72 | ASSERT_EQ(output, ""); 73 | } 74 | } 75 | } 76 | 77 | TEST(lpp_custom_LogEveryN, glog_syntax_severity_debug) { 78 | LOG_INIT(*test_argv, logCallback); 79 | for (int i = 0; i < 5; i++) { 80 | std::string output = LPP_CAPTURE_STDOUT(DLOG_EVERY_N(INFO, 3) << "test" << 123); 81 | 82 | if (i % 3 == 0) { 83 | ASSERT_EQ(output, debug + test123); 84 | } else { 85 | ASSERT_EQ(output, ""); 86 | } 87 | } 88 | } 89 | 90 | TEST(lpp_custom_LogEveryN, glog_syntax_severity_info) { 91 | LOG_INIT(*test_argv, logCallback); 92 | for (int i = 0; i < 5; i++) { 93 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(INFO, 3) << "test" << 123); 94 | 95 | if (i % 3 == 0) { 96 | ASSERT_EQ(output, info + test123); 97 | } else { 98 | ASSERT_EQ(output, ""); 99 | } 100 | } 101 | } 102 | 103 | TEST(lpp_custom_LogEveryN, glog_syntax_severity_warning) { 104 | LOG_INIT(*test_argv, logCallback); 105 | for (int i = 0; i < 5; i++) { 106 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(WARNING, 3) << "test" << 123); 107 | 108 | if (i % 3 == 0) { 109 | ASSERT_EQ(output, warning + test123); 110 | } else { 111 | ASSERT_EQ(output, ""); 112 | } 113 | } 114 | } 115 | 116 | TEST(lpp_custom_LogEveryN, glog_syntax_severity_error) { 117 | LOG_INIT(*test_argv, logCallback); 118 | for (int i = 0; i < 5; i++) { 119 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(ERROR, 3) << "test" << 123); 120 | 121 | if (i % 3 == 0) { 122 | ASSERT_EQ(output, error + test123); 123 | } else { 124 | ASSERT_EQ(output, ""); 125 | } 126 | } 127 | } 128 | 129 | TEST(lpp_custom_LogEveryN, glog_syntax_severity_fatal) { 130 | LOG_INIT(*test_argv, logCallback); 131 | for (int i = 0; i < 5; i++) { 132 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(FATAL, 3) << "test" << 123); 133 | 134 | if (i % 3 == 0) { 135 | ASSERT_EQ(output, fatal + test123); 136 | } else { 137 | ASSERT_EQ(output, ""); 138 | } 139 | } 140 | } -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_first_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | 12 | TEST(lpp_custom_LogFirstN, lpp_syntax_severity_debug) { 13 | LOG_INIT(*test_argv, logCallback); 14 | for (int i = 0; i < 5; i++) { 15 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(D, 3, "test" << 123)); 16 | 17 | if (i < 3) { 18 | ASSERT_EQ(output, debug + test123); 19 | } else { 20 | ASSERT_EQ(output, ""); 21 | } 22 | } 23 | } 24 | 25 | TEST(lpp_custom_LogFirstN, lpp_syntax_severity_info) { 26 | LOG_INIT(*test_argv, logCallback); 27 | for (int i = 0; i < 5; i++) { 28 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(I, 3, "test" << 123)); 29 | 30 | if (i < 3) { 31 | ASSERT_EQ(output, info + test123); 32 | } else { 33 | ASSERT_EQ(output, ""); 34 | } 35 | } 36 | } 37 | 38 | TEST(lpp_custom_LogFirstN, lpp_syntax_severity_warning) { 39 | LOG_INIT(*test_argv, logCallback); 40 | for (int i = 0; i < 5; i++) { 41 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(W, 3, "test" << 123)); 42 | 43 | if (i < 3) { 44 | ASSERT_EQ(output, warning + test123); 45 | } else { 46 | ASSERT_EQ(output, ""); 47 | } 48 | } 49 | } 50 | 51 | TEST(lpp_custom_LogFirstN, lpp_syntax_severity_error) { 52 | LOG_INIT(*test_argv, logCallback); 53 | for (int i = 0; i < 5; i++) { 54 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(E, 3, "test" << 123)); 55 | 56 | if (i < 3) { 57 | ASSERT_EQ(output, error + test123); 58 | } else { 59 | ASSERT_EQ(output, ""); 60 | } 61 | } 62 | } 63 | 64 | TEST(lpp_custom_LogFirstN, lpp_syntax_severity_fatal) { 65 | LOG_INIT(*test_argv, logCallback); 66 | for (int i = 0; i < 5; i++) { 67 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(F, 3, "test" << 123)); 68 | 69 | if (i < 3) { 70 | ASSERT_EQ(output, fatal + test123); 71 | } else { 72 | ASSERT_EQ(output, ""); 73 | } 74 | } 75 | } 76 | 77 | TEST(lpp_custom_LogFirstN, glog_syntax_severity_debug) { 78 | LOG_INIT(*test_argv, logCallback); 79 | for (int i = 0; i < 5; i++) { 80 | std::string output = LPP_CAPTURE_STDOUT(DLOG_FIRST_N(INFO, 3) << "test" << 123); 81 | 82 | if (i < 3) { 83 | ASSERT_EQ(output, debug + test123); 84 | } else { 85 | ASSERT_EQ(output, ""); 86 | } 87 | } 88 | } 89 | 90 | TEST(lpp_custom_LogFirstN, glog_syntax_severity_info) { 91 | LOG_INIT(*test_argv, logCallback); 92 | for (int i = 0; i < 5; i++) { 93 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(INFO, 3) << "test" << 123); 94 | 95 | if (i < 3) { 96 | ASSERT_EQ(output, info + test123); 97 | } else { 98 | ASSERT_EQ(output, ""); 99 | } 100 | } 101 | } 102 | 103 | TEST(lpp_custom_LogFirstN, glog_syntax_severity_warning) { 104 | LOG_INIT(*test_argv, logCallback); 105 | for (int i = 0; i < 5; i++) { 106 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(WARNING, 3) << "test" << 123); 107 | 108 | if (i < 3) { 109 | ASSERT_EQ(output, warning + test123); 110 | } else { 111 | ASSERT_EQ(output, ""); 112 | } 113 | } 114 | } 115 | 116 | TEST(lpp_custom_LogFirstN, glog_syntax_severity_error) { 117 | LOG_INIT(*test_argv, logCallback); 118 | for (int i = 0; i < 5; i++) { 119 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(ERROR, 3) << "test" << 123); 120 | 121 | if (i < 3) { 122 | ASSERT_EQ(output, error + test123); 123 | } else { 124 | ASSERT_EQ(output, ""); 125 | } 126 | } 127 | } 128 | 129 | TEST(lpp_custom_LogFirstN, glog_syntax_severity_fatal) { 130 | LOG_INIT(*test_argv, logCallback); 131 | for (int i = 0; i < 5; i++) { 132 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(FATAL, 3) << "test" << 123); 133 | 134 | if (i < 3) { 135 | ASSERT_EQ(output, fatal + test123); 136 | } else { 137 | ASSERT_EQ(output, ""); 138 | } 139 | } 140 | } 141 | 142 | TEST(lpp_custom_LogFirstN, ros_debug_once) { 143 | LOG_INIT(*test_argv, logCallback); 144 | 145 | for (int i = 0; i < 5; i++) { 146 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE("test123")); 147 | 148 | if (i == 0) { 149 | ASSERT_EQ(output, debug + test123); 150 | } else { 151 | ASSERT_EQ("", output); 152 | } 153 | } 154 | } 155 | 156 | TEST(lpp_custom_LogFirstN, ros_info_once) { 157 | LOG_INIT(*test_argv, logCallback); 158 | 159 | for (int i = 0; i < 5; i++) { 160 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE("test123")); 161 | 162 | if (i == 0) { 163 | ASSERT_EQ(output, info + test123); 164 | } else { 165 | ASSERT_EQ("", output); 166 | } 167 | } 168 | } 169 | 170 | TEST(lpp_custom_LogFirstN, ros_warn_once) { 171 | LOG_INIT(*test_argv, logCallback); 172 | 173 | for (int i = 0; i < 5; i++) { 174 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_ONCE("test123")); 175 | 176 | if (i == 0) { 177 | ASSERT_EQ(output, warning + test123); 178 | } else { 179 | ASSERT_EQ("", output); 180 | } 181 | } 182 | } 183 | 184 | TEST(lpp_custom_LogFirstN, ros_error_once) { 185 | LOG_INIT(*test_argv, logCallback); 186 | 187 | for (int i = 0; i < 5; i++) { 188 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_ONCE("test123")); 189 | 190 | if (i == 0) { 191 | ASSERT_EQ(output, error + test123); 192 | } else { 193 | ASSERT_EQ("", output); 194 | } 195 | } 196 | } 197 | 198 | TEST(lpp_custom_LogFirstN, ros_fatal_once) { 199 | LOG_INIT(*test_argv, logCallback); 200 | 201 | for (int i = 0; i < 5; i++) { 202 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_ONCE("test123")); 203 | 204 | if (i == 0) { 205 | ASSERT_EQ(output, fatal + test123); 206 | } else { 207 | ASSERT_EQ("", output); 208 | } 209 | } 210 | } -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_if_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 15.12.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | 12 | TEST(lpp_custom_if_every_n, glog_syntax_if_every_n_severity_debug) { 13 | LOG_INIT(*test_argv, logCallback); 14 | 15 | for (int i = 0; i < 5; i++) { 16 | testing::internal::CaptureStdout(); 17 | DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "test" << 123; 18 | std::string output = testing::internal::GetCapturedStdout(); 19 | 20 | if (i <= 3 && i % 3 == 0) { 21 | ASSERT_EQ(output, debug + test123); 22 | } else { 23 | ASSERT_EQ(output, ""); 24 | } 25 | } 26 | } 27 | 28 | TEST(lpp_custom_if_every_n, glog_syntax_if_every_n_severity_info) { 29 | LOG_INIT(*test_argv, logCallback); 30 | 31 | for (int i = 0; i < 5; i++) { 32 | testing::internal::CaptureStdout(); 33 | LOG_IF_EVERY_N(INFO, i <= 3, 3) << "test" << 123; 34 | std::string output = testing::internal::GetCapturedStdout(); 35 | 36 | if (i <= 3 && i % 3 == 0) { 37 | ASSERT_EQ(output, info + test123); 38 | } else { 39 | ASSERT_EQ(output, ""); 40 | } 41 | } 42 | } 43 | 44 | TEST(lpp_custom_if_every_n, glog_syntax_if_every_n_severity_warning) { 45 | LOG_INIT(*test_argv, logCallback); 46 | 47 | for (int i = 0; i < 5; i++) { 48 | testing::internal::CaptureStdout(); 49 | LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "test" << 123; 50 | std::string output = testing::internal::GetCapturedStdout(); 51 | 52 | if (i <= 3 && i % 3 == 0) { 53 | ASSERT_EQ(output, warning + test123); 54 | } else { 55 | ASSERT_EQ(output, ""); 56 | } 57 | } 58 | 59 | } 60 | 61 | TEST(lpp_custom_if_every_n, glog_syntax_if_every_n_severity_error) { 62 | LOG_INIT(*test_argv, logCallback); 63 | 64 | for (int i = 0; i < 5; i++) { 65 | testing::internal::CaptureStdout(); 66 | LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "test" << 123; 67 | std::string output = testing::internal::GetCapturedStdout(); 68 | 69 | if (i <= 3 && i % 3 == 0) { 70 | ASSERT_EQ(output, error + test123); 71 | } else { 72 | ASSERT_EQ(output, ""); 73 | } 74 | } 75 | } 76 | 77 | TEST(lpp_custom_if_every_n, glog_syntax_if_every_n_severity_fatal) { 78 | LOG_INIT(*test_argv, logCallback); 79 | 80 | for (int i = 0; i < 5; i++) { 81 | testing::internal::CaptureStdout(); 82 | LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "test" << 123; 83 | std::string output = testing::internal::GetCapturedStdout(); 84 | 85 | if (i <= 3 && i % 3 == 0) { 86 | ASSERT_EQ(output, fatal + test123); 87 | } else { 88 | ASSERT_EQ(output, ""); 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_log_string.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | 12 | TEST(lpp_log_string, severity_info) { 13 | LOG_INIT(*test_argv, logCallback); 14 | 15 | std::vector errors; 16 | 17 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 18 | testing::internal::CaptureStdout(); 19 | LOG_STRING(INFO, &errors) << "test" << 123; 20 | std::string output = testing::internal::GetCapturedStdout(); 21 | 22 | ASSERT_EQ(output, ""); 23 | ASSERT_EQ("test123", errors.at(0)); 24 | } 25 | 26 | TEST(lpp_log_string, severity_info_null) { 27 | LOG_INIT(*test_argv, logCallback); 28 | 29 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "test" << 123); 30 | ASSERT_EQ(output, info + test123); 31 | } 32 | 33 | TEST(lpp_log_string, severity_warning) { 34 | LOG_INIT(*test_argv, logCallback); 35 | 36 | std::vector errors; 37 | 38 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 39 | testing::internal::CaptureStdout(); 40 | LOG_STRING(WARNING, &errors) << "test" << 123; 41 | std::string output = testing::internal::GetCapturedStdout(); 42 | 43 | ASSERT_EQ(output, ""); 44 | ASSERT_EQ("test123", errors.at(0)); 45 | } 46 | 47 | TEST(lpp_log_string, severity_warning_null) { 48 | LOG_INIT(*test_argv, logCallback); 49 | 50 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(WARNING, nullptr) << "test" << 123); 51 | ASSERT_EQ(output, warning + test123); 52 | } 53 | 54 | TEST(lpp_log_string, severity_error) { 55 | LOG_INIT(*test_argv, logCallback); 56 | 57 | std::vector errors; 58 | 59 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 60 | testing::internal::CaptureStdout(); 61 | LOG_STRING(ERROR, &errors) << "test" << 123; 62 | std::string output = testing::internal::GetCapturedStdout(); 63 | 64 | ASSERT_EQ(output, ""); 65 | ASSERT_EQ("test123", errors.at(0)); 66 | } 67 | 68 | TEST(lpp_log_string, severity_error_null) { 69 | LOG_INIT(*test_argv, logCallback); 70 | 71 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(ERROR, nullptr) << "test" << 123); 72 | ASSERT_EQ(output, error + test123); 73 | } 74 | 75 | TEST(lpp_log_string, severity_fatal) { 76 | LOG_INIT(*test_argv, logCallback); 77 | 78 | std::vector errors; 79 | 80 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 81 | testing::internal::CaptureStdout(); 82 | LOG_STRING(FATAL, &errors) << "test" << 123; 83 | std::string output = testing::internal::GetCapturedStdout(); 84 | ASSERT_EQ(output, ""); 85 | 86 | ASSERT_EQ("test123", errors.at(0)); 87 | } 88 | 89 | TEST(lpp_log_string, severity_fatal_null) { 90 | LOG_INIT(*test_argv, logCallback); 91 | 92 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(FATAL, nullptr) << "test" << 123); 93 | ASSERT_EQ(output, fatal + test123); 94 | } -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_rosprintf.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | using namespace lpp::testing; 12 | 13 | TEST(lpp_rosprintf, ros_info) { 14 | LOG_INIT(*test_argv, logCallback); 15 | 16 | testing::internal::CaptureStdout(); 17 | ROS_INFO(ERROR_MESSAGE, 3.3, 5.5); 18 | std::string c = testing::internal::GetCapturedStdout(); 19 | 20 | ASSERT_EQ(c, info + EXPECTED_ERROR_MESSAGE); 21 | } 22 | 23 | TEST(lpp_rosprintf, ros_info_once) { 24 | LOG_INIT(*test_argv, logCallback); 25 | 26 | testing::internal::CaptureStdout(); 27 | ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5); 28 | std::string c = testing::internal::GetCapturedStdout(); 29 | 30 | ASSERT_EQ(c, info + EXPECTED_ERROR_MESSAGE); 31 | } 32 | 33 | TEST(lpp_rosprintf, ros_warn) { 34 | LOG_INIT(*test_argv, logCallback); 35 | 36 | testing::internal::CaptureStdout(); 37 | ROS_WARN(ERROR_MESSAGE, 3.3, 5.5); 38 | std::string c = testing::internal::GetCapturedStdout(); 39 | 40 | ASSERT_EQ(c, warning + EXPECTED_ERROR_MESSAGE); 41 | } 42 | 43 | TEST(lpp_rosprintf, ros_warn_once) { 44 | LOG_INIT(*test_argv, logCallback); 45 | 46 | testing::internal::CaptureStdout(); 47 | ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5); 48 | std::string c = testing::internal::GetCapturedStdout(); 49 | 50 | ASSERT_EQ(c, warning + EXPECTED_ERROR_MESSAGE); 51 | } 52 | 53 | TEST(lpp_rosprintf, ros_error) { 54 | LOG_INIT(*test_argv, logCallback); 55 | 56 | testing::internal::CaptureStdout(); 57 | ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5); 58 | std::string c = testing::internal::GetCapturedStdout(); 59 | 60 | ASSERT_EQ(c, error + EXPECTED_ERROR_MESSAGE); 61 | } 62 | 63 | TEST(lpp_rosprintf, ros_error_once) { 64 | LOG_INIT(*test_argv, logCallback); 65 | 66 | testing::internal::CaptureStdout(); 67 | ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5); 68 | std::string c = testing::internal::GetCapturedStdout(); 69 | 70 | ASSERT_EQ(c, error + EXPECTED_ERROR_MESSAGE); 71 | } -------------------------------------------------------------------------------- /test/lpp/custom/test_lpp_custom_vlog.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 24.11.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include "callback.h" 9 | 10 | using namespace lpp::custom; 11 | 12 | TEST(lpp_vlog, glog_syntax_severity_v1) { 13 | LOG_INIT(*test_argv, logCallback); 14 | FLAGS_v = 3; 15 | 16 | std::string output = LPP_CAPTURE_STDOUT(VLOG(1) << "test" << 123); 17 | ASSERT_EQ(output, debug + test123); 18 | } 19 | 20 | TEST(lpp_vlog, glog_syntax_severity_v3) { 21 | LOG_INIT(*test_argv, logCallback); 22 | FLAGS_v = 3; 23 | 24 | std::string output = LPP_CAPTURE_STDOUT(VLOG(3) << "test123"); 25 | ASSERT_EQ(output, debug + test123); 26 | } 27 | 28 | TEST(lpp_vlog, glog_syntax_severity_v5) { 29 | LOG_INIT(*test_argv, logCallback); 30 | FLAGS_v = 3; 31 | 32 | std::string output = LPP_CAPTURE_STDOUT(VLOG(5) << "test123"); 33 | ASSERT_EQ(output, ""); 34 | } 35 | 36 | TEST(lpp_vlog, glog_syntax_severity_if_v1) { 37 | LOG_INIT(*test_argv, logCallback); 38 | FLAGS_v = 3; 39 | 40 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "test123"); 41 | ASSERT_EQ(output, debug + test123); 42 | } 43 | 44 | TEST(lpp_vlog, glog_syntax_severity_if_v3) { 45 | LOG_INIT(*test_argv, logCallback); 46 | FLAGS_v = 3; 47 | 48 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "test123"); 49 | ASSERT_EQ(output, debug + test123); 50 | } 51 | 52 | TEST(lpp_vlog, glog_syntax_severity_if_v5) { 53 | LOG_INIT(*test_argv, logCallback); 54 | FLAGS_v = 3; 55 | 56 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, true) << "test123"); 57 | ASSERT_EQ(output, ""); 58 | } 59 | 60 | TEST(lpp_vlog, glog_syntax_severity_ifnot_v1) { 61 | LOG_INIT(*test_argv, logCallback); 62 | FLAGS_v = 3; 63 | 64 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, false) << "test123"); 65 | ASSERT_EQ(output, ""); 66 | } 67 | 68 | TEST(lpp_vlog, glog_syntax_severity_ifnot_v3) { 69 | LOG_INIT(*test_argv, logCallback); 70 | FLAGS_v = 3; 71 | 72 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(3, false) << "test123"); 73 | ASSERT_EQ(output, ""); 74 | } 75 | 76 | TEST(lpp_vlog, glog_syntax_severity_ifnot_v5) { 77 | LOG_INIT(*test_argv, logCallback); 78 | FLAGS_v = 3; 79 | 80 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, false) << "test123"); 81 | ASSERT_EQ(output, ""); 82 | } 83 | 84 | TEST(lpp_vlog, glog_syntax_every_n_severity_v1) { 85 | LOG_INIT(*test_argv, logCallback); 86 | FLAGS_v = 3; 87 | 88 | for (int i = 0; i < 5; i++) { 89 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(1, 3) << "test" << 123); 90 | 91 | if (i % 3 == 0) { 92 | ASSERT_EQ(output, debug + test123); 93 | } else { 94 | ASSERT_EQ(output, ""); 95 | } 96 | } 97 | } 98 | 99 | TEST(lpp_vlog, glog_syntax_every_n_severity_v3) { 100 | LOG_INIT(*test_argv, logCallback); 101 | FLAGS_v = 3; 102 | 103 | for (int i = 0; i < 5; i++) { 104 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(3, 3) << "test" << 123); 105 | 106 | if (i % 3 == 0) { 107 | ASSERT_EQ(output, debug + test123); 108 | } else { 109 | ASSERT_EQ(output, ""); 110 | } 111 | } 112 | } 113 | 114 | TEST(lpp_vlog, glog_syntax_every_n_severity_v5) { 115 | LOG_INIT(*test_argv, logCallback); 116 | FLAGS_v = 3; 117 | 118 | for (int i = 0; i < 5; i++) { 119 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(5, 3) << "test" << 123); 120 | ASSERT_EQ(output, ""); 121 | } 122 | } 123 | 124 | TEST(lpp_vlog, glog_syntax_if_every_n_severity_v1) { 125 | for (int i = 0; i < 5; i++) { 126 | testing::internal::CaptureStdout(); 127 | VLOG_IF_EVERY_N(1, i <= 3, 3) << "test" << 123; 128 | std::string output = testing::internal::GetCapturedStdout(); 129 | 130 | if (i <= 3 && i % 3 == 0) { 131 | ASSERT_EQ(output, debug + test123); 132 | } else { 133 | ASSERT_EQ(output, ""); 134 | } 135 | } 136 | } 137 | 138 | TEST(lpp_vlog, glog_syntax_if_every_n_severity_v3) { 139 | for (int i = 0; i < 5; i++) { 140 | testing::internal::CaptureStdout(); 141 | VLOG_IF_EVERY_N(3, i <= 3, 3) << "test" << 123; 142 | std::string output = testing::internal::GetCapturedStdout(); 143 | 144 | if (i <= 3 && i % 3 == 0) { 145 | ASSERT_EQ(output, debug + test123); 146 | } else { 147 | ASSERT_EQ(output, ""); 148 | } 149 | } 150 | } 151 | 152 | TEST(lpp_vlog, glog_syntax_if_every_n_severity_v5) { 153 | LOG_INIT(*test_argv, logCallback); 154 | FLAGS_v = 3; 155 | 156 | for (int i = 0; i < 5; i++) { 157 | testing::internal::CaptureStdout(); 158 | VLOG_IF_EVERY_N(5, i <= 3, 3) << "test" << 123; 159 | std::string output = testing::internal::GetCapturedStdout(); 160 | 161 | ASSERT_EQ(output, ""); 162 | } 163 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_basic.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 06.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | //! LPP syntax 10 | 11 | TEST(lpp_basic, lpp_syntax_severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | std::string output = LPP_CAPTURE_STDOUT(LOG(D, "Test" << 123)); 15 | ASSERT_EQ(output, "DEBUG Test123\n"); 16 | } 17 | 18 | TEST(lpp_basic, lpp_syntax_severity_info) { 19 | LOG_INIT(*test_argv); 20 | 21 | std::string output = LPP_CAPTURE_STDOUT(LOG(I, "Test" << 123)); 22 | ASSERT_EQ(output, "INFO Test123\n"); 23 | } 24 | 25 | TEST(lpp_basic, lpp_syntax_severity_warning) { 26 | LOG_INIT(*test_argv); 27 | 28 | std::string output = LPP_CAPTURE_STDOUT(LOG(W, "Test" << 123)); 29 | ASSERT_EQ(output, "WARN Test123\n"); 30 | } 31 | 32 | TEST(lpp_basic, lpp_syntax_severity_error) { 33 | LOG_INIT(*test_argv); 34 | 35 | std::string output = LPP_CAPTURE_STDOUT(LOG(E, "Test" << 123)); 36 | ASSERT_EQ(output, "ERROR Test123\n"); 37 | } 38 | 39 | TEST(lpp_basic, lpp_syntax_severity_fatal) { 40 | LOG_INIT(*test_argv); 41 | 42 | std::string output = LPP_CAPTURE_STDOUT(LOG(F, "Test" << 123)); 43 | ASSERT_EQ(output, "FATAL Test123\n"); 44 | } 45 | 46 | 47 | //! Glog syntax 48 | TEST(lpp_basic, glog_syntax_severity_debug) { 49 | LOG_INIT(*test_argv); 50 | 51 | std::string output = LPP_CAPTURE_STDOUT(DLOG(INFO) << "Test" << 123); 52 | ASSERT_EQ(output, "DEBUG Test123\n"); 53 | } 54 | 55 | TEST(lpp_basic, glog_syntax_severity_info) { 56 | LOG_INIT(*test_argv); 57 | 58 | std::string output = LPP_CAPTURE_STDOUT(LOG(INFO) << "Test" << 123); 59 | ASSERT_EQ(output, "INFO Test123\n"); 60 | } 61 | 62 | TEST(lpp_basic, glog_syntax_severity_warning) { 63 | LOG_INIT(*test_argv); 64 | 65 | std::string output = LPP_CAPTURE_STDOUT(LOG(WARNING) << "Test" << 123); 66 | ASSERT_EQ(output, "WARN Test123\n"); 67 | } 68 | 69 | TEST(lpp_basic, glog_syntax_severity_error) { 70 | LOG_INIT(*test_argv); 71 | 72 | std::string output = LPP_CAPTURE_STDOUT(LOG(ERROR) << "Test" << 123); 73 | ASSERT_EQ(output, "ERROR Test123\n"); 74 | } 75 | 76 | TEST(lpp_basic, glog_syntax_severity_fatal) { 77 | LOG_INIT(*test_argv); 78 | 79 | std::string output = LPP_CAPTURE_STDOUT(LOG(FATAL) << "Test" << 123); 80 | ASSERT_EQ(output, "FATAL Test123\n"); 81 | } 82 | 83 | 84 | //! Roslog syntax 85 | TEST(lpp_basic, roslog_syntax_severity_debug) { 86 | LOG_INIT(*test_argv); 87 | 88 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG("Test123")); 89 | ASSERT_EQ(output, "DEBUG Test123\n"); 90 | } 91 | 92 | TEST(lpp_basic, roslog_syntax_severity_debug_stream) { 93 | LOG_INIT(*test_argv); 94 | 95 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("Test" << 123)); 96 | ASSERT_EQ(output, "DEBUG Test123\n"); 97 | } 98 | 99 | TEST(lpp_basic, roslog_syntax_severity_info) { 100 | LOG_INIT(*test_argv); 101 | 102 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO("Test123")); 103 | ASSERT_EQ(output, "INFO Test123\n"); 104 | } 105 | 106 | TEST(lpp_basic, roslog_syntax_severity_info_stream) { 107 | LOG_INIT(*test_argv); 108 | 109 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("Test" << 123)); 110 | ASSERT_EQ(output, "INFO Test123\n"); 111 | } 112 | 113 | TEST(lpp_basic, roslog_syntax_severity_warning) { 114 | LOG_INIT(*test_argv); 115 | 116 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN("Test123")); 117 | ASSERT_EQ(output, "WARN Test123\n"); 118 | } 119 | 120 | TEST(lpp_basic, roslog_syntax_severity_warning_stream) { 121 | LOG_INIT(*test_argv); 122 | 123 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_STREAM("Test" << 123)); 124 | ASSERT_EQ(output, "WARN Test123\n"); 125 | } 126 | 127 | TEST(lpp_basic, roslog_syntax_severity_error) { 128 | LOG_INIT(*test_argv); 129 | 130 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR("Test123")); 131 | ASSERT_EQ(output, "ERROR Test123\n"); 132 | } 133 | 134 | TEST(lpp_basic, roslog_syntax_severity_error_stream) { 135 | LOG_INIT(*test_argv); 136 | 137 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_STREAM("Test" << 123)); 138 | ASSERT_EQ(output, "ERROR Test123\n"); 139 | } 140 | 141 | TEST(lpp_basic, roslog_syntax_severity_fatal) { 142 | LOG_INIT(*test_argv); 143 | 144 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL("Test123")); 145 | ASSERT_EQ(output, "FATAL Test123\n"); 146 | } 147 | 148 | TEST(lpp_basic, roslog_syntax_severity_fatal_stream) { 149 | LOG_INIT(*test_argv); 150 | 151 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_STREAM("Test" << 123)); 152 | ASSERT_EQ(output, "FATAL Test123\n"); 153 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 06.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(lpp_LogEveryN, lpp_syntax_severity_debug) { 10 | for (int i = 0; i < 5; i++) { 11 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(D, 3, "Test" << 123)); 12 | 13 | if (i % 3 == 0) { 14 | ASSERT_EQ(output, "DEBUG Test123\n"); 15 | } else { 16 | ASSERT_EQ(output, ""); 17 | } 18 | } 19 | } 20 | 21 | TEST(lpp_LogEveryN, lpp_syntax_severity_info) { 22 | for (int i = 0; i < 5; i++) { 23 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(I, 3, "Test" << 123)); 24 | 25 | if (i % 3 == 0) { 26 | ASSERT_EQ(output, "INFO Test123\n"); 27 | } else { 28 | ASSERT_EQ(output, ""); 29 | } 30 | } 31 | } 32 | 33 | TEST(lpp_LogEveryN, lpp_syntax_severity_warning) { 34 | for (int i = 0; i < 5; i++) { 35 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(W, 3, "Test" << 123)); 36 | 37 | if (i % 3 == 0) { 38 | ASSERT_EQ(output, "WARN Test123\n"); 39 | } else { 40 | ASSERT_EQ(output, ""); 41 | } 42 | } 43 | } 44 | 45 | TEST(lpp_LogEveryN, lpp_syntax_severity_error) { 46 | for (int i = 0; i < 5; i++) { 47 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(E, 3, "Test" << 123)); 48 | 49 | if (i % 3 == 0) { 50 | ASSERT_EQ(output, "ERROR Test123\n"); 51 | } else { 52 | ASSERT_EQ(output, ""); 53 | } 54 | } 55 | } 56 | 57 | TEST(lpp_LogEveryN, lpp_syntax_severity_fatal) { 58 | for (int i = 0; i < 5; i++) { 59 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(F, 3, "Test" << 123)); 60 | 61 | if (i % 3 == 0) { 62 | ASSERT_EQ(output, "FATAL Test123\n"); 63 | } else { 64 | ASSERT_EQ(output, ""); 65 | } 66 | } 67 | } 68 | 69 | TEST(lpp_LogEveryN, glog_syntax_severity_debug) { 70 | for (int i = 0; i < 5; i++) { 71 | std::string output = LPP_CAPTURE_STDOUT(DLOG_EVERY_N(INFO, 3) << "Test" << 123); 72 | 73 | if (i % 3 == 0) { 74 | ASSERT_EQ(output, "DEBUG Test123\n"); 75 | } else { 76 | ASSERT_EQ(output, ""); 77 | } 78 | } 79 | } 80 | 81 | TEST(lpp_LogEveryN, glog_syntax_severity_info) { 82 | for (int i = 0; i < 5; i++) { 83 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(INFO, 3) << "Test" << 123); 84 | 85 | if (i % 3 == 0) { 86 | ASSERT_EQ(output, "INFO Test123\n"); 87 | } else { 88 | ASSERT_EQ(output, ""); 89 | } 90 | } 91 | } 92 | 93 | TEST(lpp_LogEveryN, glog_syntax_severity_warning) { 94 | for (int i = 0; i < 5; i++) { 95 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(WARNING, 3) << "Test" << 123); 96 | 97 | if (i % 3 == 0) { 98 | ASSERT_EQ(output, "WARN Test123\n"); 99 | } else { 100 | ASSERT_EQ(output, ""); 101 | } 102 | } 103 | } 104 | 105 | TEST(lpp_LogEveryN, glog_syntax_severity_error) { 106 | for (int i = 0; i < 5; i++) { 107 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(ERROR, 3) << "Test" << 123); 108 | 109 | if (i % 3 == 0) { 110 | ASSERT_EQ(output, "ERROR Test123\n"); 111 | } else { 112 | ASSERT_EQ(output, ""); 113 | } 114 | } 115 | } 116 | 117 | TEST(lpp_LogEveryN, glog_syntax_severity_fatal) { 118 | for (int i = 0; i < 5; i++) { 119 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(FATAL, 3) << "Test" << 123); 120 | 121 | if (i % 3 == 0) { 122 | ASSERT_EQ(output, "FATAL Test123\n"); 123 | } else { 124 | ASSERT_EQ(output, ""); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_first_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 06.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(lpp_LogFirstN, lpp_syntax_severity_debug) { 10 | for (int i = 0; i < 5; i++) { 11 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(D, 3, "Test" << 123)); 12 | 13 | if (i < 3) { 14 | ASSERT_EQ(output, "DEBUG Test123\n"); 15 | } else { 16 | ASSERT_EQ(output, ""); 17 | } 18 | } 19 | } 20 | 21 | TEST(lpp_LogFirstN, lpp_syntax_severity_info) { 22 | for (int i = 0; i < 5; i++) { 23 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(I, 3, "Test" << 123)); 24 | 25 | if (i < 3) { 26 | ASSERT_EQ(output, "INFO Test123\n"); 27 | } else { 28 | ASSERT_EQ(output, ""); 29 | } 30 | } 31 | } 32 | 33 | TEST(lpp_LogFirstN, lpp_syntax_severity_warning) { 34 | for (int i = 0; i < 5; i++) { 35 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(W, 3, "Test" << 123)); 36 | 37 | if (i < 3) { 38 | ASSERT_EQ(output, "WARN Test123\n"); 39 | } else { 40 | ASSERT_EQ(output, ""); 41 | } 42 | } 43 | } 44 | 45 | TEST(lpp_LogFirstN, lpp_syntax_severity_error) { 46 | for (int i = 0; i < 5; i++) { 47 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(E, 3, "Test" << 123)); 48 | 49 | if (i < 3) { 50 | ASSERT_EQ(output, "ERROR Test123\n"); 51 | } else { 52 | ASSERT_EQ(output, ""); 53 | } 54 | } 55 | } 56 | 57 | TEST(lpp_LogFirstN, lpp_syntax_severity_fatal) { 58 | for (int i = 0; i < 5; i++) { 59 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(F, 3, "Test" << 123)); 60 | 61 | if (i < 3) { 62 | ASSERT_EQ(output, "FATAL Test123\n"); 63 | } else { 64 | ASSERT_EQ(output, ""); 65 | } 66 | } 67 | } 68 | 69 | TEST(lpp_LogFirstN, glog_syntax_severity_debug) { 70 | for (int i = 0; i < 5; i++) { 71 | std::string output = LPP_CAPTURE_STDOUT(DLOG_FIRST_N(INFO, 3) << "Test" << 123); 72 | 73 | if (i < 3) { 74 | ASSERT_EQ(output, "DEBUG Test123\n"); 75 | } else { 76 | ASSERT_EQ(output, ""); 77 | } 78 | } 79 | } 80 | 81 | TEST(lpp_LogFirstN, glog_syntax_severity_info) { 82 | for (int i = 0; i < 5; i++) { 83 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(INFO, 3) << "Test" << 123); 84 | 85 | if (i < 3) { 86 | ASSERT_EQ(output, "INFO Test123\n"); 87 | } else { 88 | ASSERT_EQ(output, ""); 89 | } 90 | } 91 | } 92 | 93 | TEST(lpp_LogFirstN, glog_syntax_severity_warning) { 94 | for (int i = 0; i < 5; i++) { 95 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(WARNING, 3) << "Test" << 123); 96 | 97 | if (i < 3) { 98 | ASSERT_EQ(output, "WARN Test123\n"); 99 | } else { 100 | ASSERT_EQ(output, ""); 101 | } 102 | } 103 | } 104 | 105 | TEST(lpp_LogFirstN, glog_syntax_severity_error) { 106 | for (int i = 0; i < 5; i++) { 107 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(ERROR, 3) << "Test" << 123); 108 | 109 | if (i < 3) { 110 | ASSERT_EQ(output, "ERROR Test123\n"); 111 | } else { 112 | ASSERT_EQ(output, ""); 113 | } 114 | } 115 | } 116 | 117 | TEST(lpp_LogFirstN, glog_syntax_severity_fatal) { 118 | for (int i = 0; i < 5; i++) { 119 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(FATAL, 3) << "Test" << 123); 120 | 121 | if (i < 3) { 122 | ASSERT_EQ(output, "FATAL Test123\n"); 123 | } else { 124 | ASSERT_EQ(output, ""); 125 | } 126 | } 127 | } 128 | 129 | TEST(lpp_LogFirstN, ros_debug_once) { 130 | LOG_INIT(*test_argv); 131 | 132 | for (int i = 0; i < 5; i++) { 133 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE("Test123")); 134 | 135 | if (i == 0) { 136 | ASSERT_EQ(output, "DEBUG Test123\n"); 137 | } else { 138 | ASSERT_EQ("", output); 139 | } 140 | } 141 | } 142 | 143 | TEST(lpp_LogFirstN, ros_info_once) { 144 | LOG_INIT(*test_argv); 145 | 146 | for (int i = 0; i < 5; i++) { 147 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE("Test123")); 148 | 149 | if (i == 0) { 150 | ASSERT_EQ(output, "INFO Test123\n"); 151 | } else { 152 | ASSERT_EQ("", output); 153 | } 154 | } 155 | } 156 | 157 | TEST(lpp_LogFirstN, ros_warn_once) { 158 | LOG_INIT(*test_argv); 159 | 160 | for (int i = 0; i < 5; i++) { 161 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_ONCE("Test123")); 162 | 163 | if (i == 0) { 164 | ASSERT_EQ(output, "WARN Test123\n"); 165 | } else { 166 | ASSERT_EQ("", output); 167 | } 168 | } 169 | } 170 | 171 | TEST(lpp_LogFirstN, ros_error_once) { 172 | LOG_INIT(*test_argv); 173 | 174 | for (int i = 0; i < 5; i++) { 175 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_ONCE("Test123")); 176 | 177 | if (i == 0) { 178 | ASSERT_EQ(output, "ERROR Test123\n"); 179 | } else { 180 | ASSERT_EQ("", output); 181 | } 182 | } 183 | } 184 | 185 | TEST(lpp_LogFirstN, ros_fatal_once) { 186 | LOG_INIT(*test_argv); 187 | 188 | for (int i = 0; i < 5; i++) { 189 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_ONCE("Test123")); 190 | 191 | if (i == 0) { 192 | ASSERT_EQ(output, "FATAL Test123\n"); 193 | } else { 194 | ASSERT_EQ("", output); 195 | } 196 | } 197 | } 198 | 199 | -------------------------------------------------------------------------------- /test/lpp/test_lpp_if_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 15.12.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(lpp_if_every_n, glog_syntax_if_every_n_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | testing::internal::CaptureStdout(); 14 | DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 15 | std::string output = testing::internal::GetCapturedStdout(); 16 | 17 | if (i <= 3 && i % 3 == 0) { 18 | ASSERT_EQ(output, "DEBUG Test123\n"); 19 | } else { 20 | ASSERT_EQ(output, ""); 21 | } 22 | } 23 | } 24 | 25 | TEST(lpp_if_every_n, glog_syntax_if_every_n_severity_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | testing::internal::CaptureStdout(); 30 | LOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 31 | std::string output = testing::internal::GetCapturedStdout(); 32 | 33 | if (i <= 3 && i % 3 == 0) { 34 | ASSERT_EQ(output, "INFO Test123\n"); 35 | } else { 36 | ASSERT_EQ(output, ""); 37 | } 38 | } 39 | } 40 | 41 | TEST(lpp_if_every_n, glog_syntax_if_every_n_severity_warning) { 42 | LOG_INIT(*test_argv); 43 | 44 | for (int i = 0; i < 5; i++) { 45 | testing::internal::CaptureStdout(); 46 | LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "Test" << 123; 47 | std::string output = testing::internal::GetCapturedStdout(); 48 | 49 | if (i <= 3 && i % 3 == 0) { 50 | ASSERT_EQ(output, "WARN Test123\n"); 51 | } else { 52 | ASSERT_EQ(output, ""); 53 | } 54 | } 55 | 56 | } 57 | 58 | TEST(lpp_if_every_n, glog_syntax_if_every_n_severity_error) { 59 | LOG_INIT(*test_argv); 60 | 61 | for (int i = 0; i < 5; i++) { 62 | testing::internal::CaptureStdout(); 63 | LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "Test" << 123; 64 | std::string output = testing::internal::GetCapturedStdout(); 65 | 66 | if (i <= 3 && i % 3 == 0) { 67 | ASSERT_EQ(output, "ERROR Test123\n"); 68 | } else { 69 | ASSERT_EQ(output, ""); 70 | } 71 | } 72 | } 73 | 74 | TEST(lpp_if_every_n, glog_syntax_if_every_n_severity_fatal) { 75 | LOG_INIT(*test_argv); 76 | 77 | for (int i = 0; i < 5; i++) { 78 | testing::internal::CaptureStdout(); 79 | LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "Test" << 123; 80 | std::string output = testing::internal::GetCapturedStdout(); 81 | 82 | if (i <= 3 && i % 3 == 0) { 83 | ASSERT_EQ(output, "FATAL Test123\n"); 84 | } else { 85 | ASSERT_EQ(output, ""); 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_log_string.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 28.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(lpp_log_string, severity_info) { 10 | LOG_INIT(*test_argv); 11 | 12 | std::vector errors; 13 | 14 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 15 | testing::internal::CaptureStdout(); 16 | LOG_STRING(INFO, &errors) << "LOG_STRING: " << "collected info"; 17 | std::string output = testing::internal::GetCapturedStdout(); 18 | 19 | ASSERT_EQ(output, ""); 20 | ASSERT_EQ("LOG_STRING: collected info", errors.at(0)); 21 | } 22 | 23 | TEST(lpp_log_string, severity_info_null) { 24 | LOG_INIT(*test_argv); 25 | 26 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "LOG_STRING: " << "collected info"); 27 | ASSERT_EQ(output, "INFO LOG_STRING: collected info\n"); 28 | } 29 | 30 | TEST(lpp_log_string, severity_warning) { 31 | LOG_INIT(*test_argv); 32 | 33 | std::vector errors; 34 | 35 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 36 | testing::internal::CaptureStdout(); 37 | LOG_STRING(WARNING, &errors) << "LOG_STRING: " << "collected warn"; 38 | std::string output = testing::internal::GetCapturedStdout(); 39 | 40 | ASSERT_EQ(output, ""); 41 | ASSERT_EQ("LOG_STRING: collected warn", errors.at(0)); 42 | } 43 | 44 | TEST(lpp_log_string, severity_warning_null) { 45 | LOG_INIT(*test_argv); 46 | 47 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " << "collected warn"); 48 | ASSERT_EQ(output, "WARN LOG_STRING: collected warn\n"); 49 | } 50 | 51 | TEST(lpp_log_string, severity_error) { 52 | LOG_INIT(*test_argv); 53 | 54 | std::vector errors; 55 | 56 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 57 | testing::internal::CaptureStdout(); 58 | LOG_STRING(ERROR, &errors) << "LOG_STRING: " << "collected error"; 59 | std::string output = testing::internal::GetCapturedStdout(); 60 | 61 | ASSERT_EQ(output, ""); 62 | ASSERT_EQ("LOG_STRING: collected error", errors.at(0)); 63 | } 64 | 65 | TEST(lpp_log_string, severity_error_null) { 66 | LOG_INIT(*test_argv); 67 | 68 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " << "collected error"); 69 | ASSERT_EQ(output, "ERROR LOG_STRING: collected error\n"); 70 | } 71 | 72 | TEST(lpp_log_string, severity_fatal) { 73 | LOG_INIT(*test_argv); 74 | 75 | std::vector errors; 76 | 77 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 78 | testing::internal::CaptureStdout(); 79 | LOG_STRING(FATAL, &errors) << "LOG_STRING: " << "collected fatal"; 80 | std::string output = testing::internal::GetCapturedStdout(); 81 | ASSERT_EQ(output, ""); 82 | 83 | ASSERT_EQ("LOG_STRING: collected fatal", errors.at(0)); 84 | } 85 | 86 | TEST(lpp_log_string, severity_fatal_null) { 87 | LOG_INIT(*test_argv); 88 | 89 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " << "collected error"); 90 | ASSERT_EQ(output, "FATAL LOG_STRING: collected error\n"); 91 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_rosprintf.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 08.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::testing; 10 | 11 | TEST(lpp_rosprintf, ros_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG(ERROR_MESSAGE, 3.3, 5.5)); 15 | ASSERT_EQ(output, "DEBUG " + EXPECTED_ERROR_MESSAGE); 16 | } 17 | 18 | TEST(lpp_rosprintf, ros_debug_once) { 19 | LOG_INIT(*test_argv); 20 | 21 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 22 | ASSERT_EQ(output, "DEBUG " + EXPECTED_ERROR_MESSAGE); 23 | } 24 | 25 | TEST(lpp_rosprintf, ros_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO(ERROR_MESSAGE, 3.3, 5.5)); 29 | ASSERT_EQ(output, "INFO " + EXPECTED_ERROR_MESSAGE); 30 | } 31 | 32 | TEST(lpp_rosprintf, ros_info_once) { 33 | LOG_INIT(*test_argv); 34 | 35 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 36 | ASSERT_EQ(output, "INFO " + EXPECTED_ERROR_MESSAGE); 37 | } 38 | 39 | TEST(lpp_rosprintf, ros_warn) { 40 | LOG_INIT(*test_argv); 41 | 42 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN(ERROR_MESSAGE, 3.3, 5.5)); 43 | ASSERT_EQ(output, "WARN " + EXPECTED_ERROR_MESSAGE); 44 | } 45 | 46 | TEST(lpp_rosprintf, ros_warn_once) { 47 | LOG_INIT(*test_argv); 48 | 49 | std::string output = LPP_CAPTURE_STDOUT(ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 50 | ASSERT_EQ(output, "WARN " + EXPECTED_ERROR_MESSAGE); 51 | } 52 | 53 | TEST(lpp_rosprintf, ros_error) { 54 | LOG_INIT(*test_argv); 55 | 56 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5)); 57 | ASSERT_EQ(output, "ERROR " + EXPECTED_ERROR_MESSAGE); 58 | } 59 | 60 | TEST(lpp_rosprintf, ros_error_once) { 61 | LOG_INIT(*test_argv); 62 | 63 | std::string output = LPP_CAPTURE_STDOUT(ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 64 | ASSERT_EQ(output, "ERROR " + EXPECTED_ERROR_MESSAGE); 65 | } 66 | 67 | TEST(lpp_rosprintf, ros_fatal) { 68 | LOG_INIT(*test_argv); 69 | 70 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL(ERROR_MESSAGE, 3.3, 5.5)); 71 | ASSERT_EQ(output, "FATAL " + EXPECTED_ERROR_MESSAGE); 72 | } 73 | 74 | TEST(lpp_rosprintf, ros_fatal_once) { 75 | LOG_INIT(*test_argv); 76 | 77 | std::string output = LPP_CAPTURE_STDOUT(ROS_FATAL_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 78 | ASSERT_EQ(output, "FATAL " + EXPECTED_ERROR_MESSAGE); 79 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_timed.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 16.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | std::vector generateTests() { 11 | return { 12 | {"lpp_timed_lpp_syntax_severity_debug_Test",{"DEBUG Test123\n"},[]() { LOG_TIMED(D, 1, "Test" << 123); }, EQUAL, STDOUT}, 13 | {"lpp_timed_lpp_syntax_severity_info_Test",{"INFO Test123\n"},[]() { LOG_TIMED(I, 1, "Test" << 123); }, EQUAL, STDOUT}, 14 | {"lpp_timed_lpp_syntax_severity_warning_Test",{"WARN Test123\n"},[]() { LOG_TIMED(W, 1, "Test" << 123); }, EQUAL, STDOUT}, 15 | {"lpp_timed_lpp_syntax_severity_error_Test",{"ERROR Test123\n"},[]() { LOG_TIMED(E, 1, "Test" << 123); }, EQUAL, STDOUT}, 16 | {"lpp_timed_lpp_syntax_severity_fatal_Test",{"FATAL Test123\n"},[]() { LOG_TIMED(F, 1, "Test" << 123); }, EQUAL, STDOUT}, 17 | 18 | {"lpp_timed_glog_syntax_severity_debug_Test",{"DEBUG Test123\n"},[]() { DLOG_EVERY_T(INFO, 1) << "Test" << 123; }, EQUAL, STDOUT}, 19 | {"lpp_timed_glog_syntax_severity_info_Test",{"INFO Test123\n"},[]() { LOG_EVERY_T(INFO, 1) << "Test" << 123; }, EQUAL, STDOUT}, 20 | {"lpp_timed_glog_syntax_severity_warning_Test",{"WARN Test123\n"},[]() { LOG_EVERY_T(WARNING, 1) << "Test" << 123; }, EQUAL, STDOUT}, 21 | {"lpp_timed_glog_syntax_severity_error_Test",{"ERROR Test123\n"},[]() { LOG_EVERY_T(ERROR, 1) << "Test" << 123; }, EQUAL, STDOUT}, 22 | {"lpp_timed_glog_syntax_severity_fatal_Test",{"FATAL Test123\n"},[]() { LOG_EVERY_T(FATAL, 1) << "Test" << 123; }, EQUAL, STDOUT}, 23 | 24 | {"lpp_timed_ros_syntax_severity_debug_Test", {"DEBUG Test123\n"}, []() {ROS_DEBUG_THROTTLE(1, "Test123"); }, EQUAL, STDOUT}, 25 | {"lpp_timed_ros_syntax_severity_debug_stream_Test", {"DEBUG Test123\n"}, []() {ROS_DEBUG_STREAM_THROTTLE(1, "Test" << 123); }, EQUAL, STDOUT}, 26 | {"lpp_timed_ros_syntax_severity_info_Test", {"INFO Test123\n"}, []() {ROS_INFO_THROTTLE(1, "Test123"); }, EQUAL, STDOUT}, 27 | {"lpp_timed_ros_syntax_severity_info_stream_Test", {"INFO Test123\n"}, []() {ROS_INFO_STREAM_THROTTLE(1, "Test" << 123); }, EQUAL, STDOUT}, 28 | {"lpp_timed_ros_syntax_severity_warning_Test", {"WARN Test123\n"}, []() {ROS_WARN_THROTTLE(1, "Test123"); }, EQUAL, STDOUT}, 29 | {"lpp_timed_ros_syntax_severity_warning_stream_Test", {"WARN Test123\n"}, []() {ROS_WARN_STREAM_THROTTLE(1, "Test" << 123); }, EQUAL, STDOUT}, 30 | {"lpp_timed_ros_syntax_severity_error_Test", {"ERROR Test123\n"}, []() {ROS_ERROR_THROTTLE(1, "Test123"); }, EQUAL, STDOUT}, 31 | {"lpp_timed_ros_syntax_severity_error_stream_Test", {"ERROR Test123\n"}, []() {ROS_ERROR_STREAM_THROTTLE(1, "Test" << 123); }, EQUAL, STDOUT}, 32 | {"lpp_timed_ros_syntax_severity_fatal_Test", {"FATAL Test123\n"}, []() {ROS_FATAL_THROTTLE(1, "Test123"); }, EQUAL, STDOUT}, 33 | {"lpp_timed_ros_syntax_severity_fatal_stream_Test", {"FATAL Test123\n"}, []() {ROS_FATAL_STREAM_THROTTLE(1, "Test123"); }, EQUAL, STDOUT}, 34 | }; 35 | } 36 | 37 | TEST(lpp_timed, lpp_syntax_floating_point_time) { 38 | LOG_INIT(*test_argv); 39 | for (int i = 0; i < 5; i++) { 40 | std::string output = LPP_CAPTURE_STDOUT(LOG_TIMED(I, 0.1, "Test" << 123)); 41 | if (i % 2 == 0) { 42 | ASSERT_EQ(output, "INFO Test123\n"); 43 | } 44 | //sleep 0.1s 45 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); 46 | } 47 | } 48 | 49 | TEST(lpp_timed, lpp_syntax_severity_debug) { 50 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 51 | } 52 | 53 | TEST(lpp_timed, lpp_syntax_severity_info) { 54 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 55 | } 56 | 57 | TEST(lpp_timed, lpp_syntax_severity_warning) { 58 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 59 | } 60 | 61 | TEST(lpp_timed, lpp_syntax_severity_error) { 62 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 63 | } 64 | 65 | TEST(lpp_timed, lpp_syntax_severity_fatal) { 66 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 67 | } 68 | 69 | TEST(lpp_timed, glog_syntax_severity_debug) { 70 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 71 | } 72 | 73 | TEST(lpp_timed, glog_syntax_severity_info) { 74 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 75 | } 76 | 77 | TEST(lpp_timed, glog_syntax_severity_warning) { 78 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 79 | } 80 | 81 | TEST(lpp_timed, glog_syntax_severity_error) { 82 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 83 | } 84 | 85 | TEST(lpp_timed, glog_syntax_severity_fatal) { 86 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 87 | } 88 | 89 | TEST(lpp_timed, ros_syntax_severity_debug) { 90 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 91 | } 92 | 93 | TEST(lpp_timed, ros_syntax_severity_debug_stream) { 94 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 95 | } 96 | 97 | TEST(lpp_timed, ros_syntax_severity_info) { 98 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 99 | } 100 | 101 | TEST(lpp_timed, ros_syntax_severity_info_stream) { 102 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 103 | } 104 | 105 | TEST(lpp_timed, ros_syntax_severity_warning) { 106 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 107 | } 108 | 109 | TEST(lpp_timed, ros_syntax_severity_warning_stream) { 110 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 111 | } 112 | 113 | TEST(lpp_timed, ros_syntax_severity_error) { 114 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 115 | } 116 | 117 | TEST(lpp_timed, ros_syntax_severity_error_stream) { 118 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 119 | } 120 | 121 | TEST(lpp_timed, ros_syntax_severity_fatal) { 122 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 123 | } 124 | 125 | TEST(lpp_timed, ros_syntax_severity_fatal_stream) { 126 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 127 | } -------------------------------------------------------------------------------- /test/lpp/test_lpp_vlog.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 27.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(lpp_vlog, glog_syntax_severity_v1) { 10 | LOG_INIT(*test_argv); 11 | FLAGS_v = 3; 12 | 13 | std::string output = LPP_CAPTURE_STDOUT(VLOG(1) << "Test" << 123); 14 | ASSERT_EQ(output, "DEBUG Test123\n"); 15 | } 16 | 17 | TEST(lpp_vlog, glog_syntax_severity_v3) { 18 | LOG_INIT(*test_argv); 19 | FLAGS_v = 3; 20 | 21 | std::string output = LPP_CAPTURE_STDOUT(VLOG(3) << "Test123"); 22 | ASSERT_EQ(output, "DEBUG Test123\n"); 23 | } 24 | 25 | TEST(lpp_vlog, glog_syntax_severity_v5) { 26 | LOG_INIT(*test_argv); 27 | FLAGS_v = 3; 28 | 29 | std::string output = LPP_CAPTURE_STDOUT(VLOG(5) << "Test123"); 30 | ASSERT_EQ(output, ""); 31 | } 32 | 33 | TEST(lpp_vlog, glog_syntax_severity_if_v1) { 34 | LOG_INIT(*test_argv); 35 | FLAGS_v = 3; 36 | 37 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "Test123"); 38 | ASSERT_EQ(output, "DEBUG Test123\n"); 39 | } 40 | 41 | TEST(lpp_vlog, glog_syntax_severity_if_v3) { 42 | LOG_INIT(*test_argv); 43 | FLAGS_v = 3; 44 | 45 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "Test123"); 46 | ASSERT_EQ(output, "DEBUG Test123\n"); 47 | } 48 | 49 | TEST(lpp_vlog, glog_syntax_severity_if_v5) { 50 | LOG_INIT(*test_argv); 51 | FLAGS_v = 3; 52 | 53 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, true) << "Test123"); 54 | ASSERT_EQ(output, ""); 55 | } 56 | 57 | TEST(lpp_vlog, glog_syntax_severity_ifnot_v1) { 58 | LOG_INIT(*test_argv); 59 | FLAGS_v = 3; 60 | 61 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, false) << "Test123"); 62 | ASSERT_EQ(output, ""); 63 | } 64 | 65 | TEST(lpp_vlog, glog_syntax_severity_ifnot_v3) { 66 | LOG_INIT(*test_argv); 67 | FLAGS_v = 3; 68 | 69 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(3, false) << "Test123"); 70 | ASSERT_EQ(output, ""); 71 | } 72 | 73 | TEST(lpp_vlog, glog_syntax_severity_ifnot_v5) { 74 | LOG_INIT(*test_argv); 75 | FLAGS_v = 3; 76 | 77 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, false) << "Test123"); 78 | ASSERT_EQ(output, ""); 79 | } 80 | 81 | 82 | TEST(lpp_vlog, glog_syntax_every_n_severity_v1) { 83 | LOG_INIT(*test_argv); 84 | FLAGS_v = 3; 85 | 86 | for (int i = 0; i < 5; i++) { 87 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(1, 3) << "Test" << 123); 88 | 89 | if (i % 3 == 0) { 90 | ASSERT_EQ(output, "DEBUG Test123\n"); 91 | } else { 92 | ASSERT_EQ(output, ""); 93 | } 94 | } 95 | } 96 | 97 | TEST(lpp_vlog, glog_syntax_every_n_severity_v3) { 98 | LOG_INIT(*test_argv); 99 | FLAGS_v = 3; 100 | 101 | for (int i = 0; i < 5; i++) { 102 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(3, 3) << "Test" << 123); 103 | 104 | if (i % 3 == 0) { 105 | ASSERT_EQ(output, "DEBUG Test123\n"); 106 | } else { 107 | ASSERT_EQ(output, ""); 108 | } 109 | } 110 | } 111 | 112 | TEST(lpp_vlog, glog_syntax_every_n_severity_v5) { 113 | LOG_INIT(*test_argv); 114 | FLAGS_v = 3; 115 | 116 | for (int i = 0; i < 5; i++) { 117 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(5, 3) << "Test" << 123); 118 | ASSERT_EQ(output, ""); 119 | } 120 | } 121 | 122 | TEST(lpp_vlog, glog_syntax_if_every_n_severity_v1) { 123 | LOG_INIT(*test_argv); 124 | FLAGS_v = 3; 125 | 126 | for (int i = 0; i < 5; i++) { 127 | testing::internal::CaptureStdout(); 128 | VLOG_IF_EVERY_N(1, i <= 3, 3) << "Test" << 123; 129 | std::string output = testing::internal::GetCapturedStdout(); 130 | 131 | if (i <= 3 && i % 3 == 0) { 132 | ASSERT_EQ(output, "DEBUG Test123\n"); 133 | } else { 134 | ASSERT_EQ(output, ""); 135 | } 136 | } 137 | } 138 | 139 | TEST(lpp_vlog, glog_syntax_if_every_n_severity_v3) { 140 | LOG_INIT(*test_argv); 141 | FLAGS_v = 3; 142 | 143 | for (int i = 0; i < 5; i++) { 144 | testing::internal::CaptureStdout(); 145 | VLOG_IF_EVERY_N(3, i <= 3, 3) << "Test" << 123; 146 | std::string output = testing::internal::GetCapturedStdout(); 147 | 148 | if (i <= 3 && i % 3 == 0) { 149 | ASSERT_EQ(output, "DEBUG Test123\n"); 150 | } else { 151 | ASSERT_EQ(output, ""); 152 | } 153 | } 154 | } 155 | 156 | TEST(lpp_vlog, glog_syntax_if_every_n_severity_v5) { 157 | LOG_INIT(*test_argv); 158 | FLAGS_v = 3; 159 | 160 | for (int i = 0; i < 5; i++) { 161 | testing::internal::CaptureStdout(); 162 | VLOG_IF_EVERY_N(5, i <= 3, 3) << "Test" << 123; 163 | std::string output = testing::internal::GetCapturedStdout(); 164 | 165 | ASSERT_EQ(output, ""); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /test/nolog/test_nolog_basic.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 06.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(nolog_basic, glog_syntax_severity_debug){ 10 | LOG_INIT(*test_argv); 11 | DLOG(INFO) << "TEst"; 12 | 13 | std::string output = LPP_CAPTURE_STDOUT(DLOG(INFO) << "Test"); 14 | ASSERT_EQ("", output); 15 | } 16 | 17 | TEST(nolog_basic, glog_syntax_severity_info){ 18 | LOG_INIT(*test_argv); 19 | 20 | std::string output = LPP_CAPTURE_STDOUT(LOG(INFO) << "Test123"); 21 | ASSERT_EQ("", output); 22 | } 23 | 24 | TEST(nolog_basic, glog_syntax_severity_warning){ 25 | LOG_INIT(*test_argv); 26 | 27 | std::string output = LPP_CAPTURE_STDERR(LOG(WARNING) << "Test"); 28 | ASSERT_EQ("", output); 29 | } 30 | 31 | TEST(nolog_basic, glog_syntax_severity_error){ 32 | LOG_INIT(*test_argv); 33 | 34 | std::string output = LPP_CAPTURE_STDERR(LOG(ERROR) << "Test"); 35 | ASSERT_EQ("", output); 36 | } 37 | 38 | TEST(nolog_basic, glog_syntax_severity_fatal){ 39 | LOG_INIT(*test_argv); 40 | 41 | std::string output = LPP_CAPTURE_STDERR(LOG(FATAL) << "Test"); 42 | ASSERT_EQ("", output); 43 | } 44 | 45 | //! ################ lpp ################ 46 | TEST(nolog_basic, lpp_syntax_severity_debug){ 47 | LOG_INIT(*test_argv); 48 | 49 | std::string output = LPP_CAPTURE_STDOUT(LOG(D, "" << "Test")); 50 | ASSERT_EQ("", output); 51 | } 52 | 53 | TEST(nolog_basic, lpp_syntax_severity_info){ 54 | LOG_INIT(*test_argv); 55 | 56 | std::string output = LPP_CAPTURE_STDOUT(LOG(I, "" << "Test")); 57 | ASSERT_EQ("", output); 58 | } 59 | 60 | TEST(nolog_basic, lpp_syntax_severity_warning){ 61 | LOG_INIT(*test_argv); 62 | 63 | std::string output = LPP_CAPTURE_STDERR(LOG(W, "" << "Test")); 64 | ASSERT_EQ("", output); 65 | } 66 | 67 | TEST(nolog_basic, lpp_syntax_severity_error){ 68 | LOG_INIT(*test_argv); 69 | 70 | std::string output = LPP_CAPTURE_STDERR(LOG(E, "" << "Test")); 71 | ASSERT_EQ("", output); 72 | } 73 | 74 | //! ################ Roslog ################ 75 | TEST(nolog_basic, roslog_syntax_severity_debug){ 76 | LOG_INIT(*test_argv); 77 | 78 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("Test")); 79 | ASSERT_EQ("", output); 80 | } 81 | 82 | TEST(nolog_basic, roslog_syntax_severity_info){ 83 | LOG_INIT(*test_argv); 84 | 85 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("Test")); 86 | ASSERT_EQ("", output); 87 | } 88 | 89 | TEST(nolog_basic, roslog_syntax_severity_warning){ 90 | LOG_INIT(*test_argv); 91 | 92 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_STREAM("Test")); 93 | ASSERT_EQ("", output); 94 | } 95 | 96 | TEST(nolog_basic, roslog_syntax_severity_error){ 97 | LOG_INIT(*test_argv); 98 | 99 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_STREAM("Test")); 100 | ASSERT_EQ("", output); 101 | } 102 | 103 | TEST(nolog_basic, roslog_syntax_severity_fatal){ 104 | LOG_INIT(*test_argv); 105 | 106 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_STREAM("Test")); 107 | ASSERT_EQ("", output); 108 | } -------------------------------------------------------------------------------- /test/nolog/test_nolog_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 06.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(nolog_LogEveryN, lpp_syntax_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(D, 3, "Test" << 123)); 14 | ASSERT_EQ(output, ""); 15 | } 16 | } 17 | 18 | TEST(nolog_LogEveryN, lpp_syntax_severity_info) { 19 | LOG_INIT(*test_argv); 20 | 21 | for (int i = 0; i < 5; i++) { 22 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(I, 3, "Test" << 123)); 23 | ASSERT_EQ(output, ""); 24 | } 25 | } 26 | 27 | TEST(nolog_LogEveryN, lpp_syntax_severity_warning) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(W, 3, "Test" << 123)); 32 | ASSERT_EQ(output, ""); 33 | } 34 | } 35 | 36 | TEST(nolog_LogEveryN, lpp_syntax_severity_error) { 37 | LOG_INIT(*test_argv); 38 | 39 | for (int i = 0; i < 5; i++) { 40 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(E, 3, "Test" << 123)); 41 | ASSERT_EQ(output, ""); 42 | } 43 | } 44 | 45 | TEST(nolog_LogEveryN, lpp_syntax_severity_fatal) { 46 | LOG_INIT(*test_argv); 47 | 48 | for (int i = 0; i < 5; i++) { 49 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(F, 3, "Test" << 123)); 50 | ASSERT_EQ(output, ""); 51 | } 52 | } 53 | 54 | TEST(nolog_LogEveryN, glog_syntax_severity_debug) { 55 | LOG_INIT(*test_argv); 56 | 57 | for (int i = 0; i < 5; i++) { 58 | std::string output = 59 | LPP_CAPTURE_STDOUT(DLOG_EVERY_N(INFO, 3) << "Test" << 123); 60 | ASSERT_EQ(output, ""); 61 | } 62 | } 63 | 64 | TEST(nolog_LogEveryN, glog_syntax_severity_info) { 65 | LOG_INIT(*test_argv); 66 | 67 | for (int i = 0; i < 5; i++) { 68 | std::string output = 69 | LPP_CAPTURE_STDOUT(LOG_EVERY_N(INFO, 3) << "Test" << 123); 70 | ASSERT_EQ(output, ""); 71 | } 72 | } 73 | 74 | TEST(nolog_LogEveryN, glog_syntax_severity_warning) { 75 | LOG_INIT(*test_argv); 76 | 77 | for (int i = 0; i < 5; i++) { 78 | std::string output = 79 | LPP_CAPTURE_STDERR(LOG_EVERY_N(WARNING, 3) << "Test" << 123); 80 | ASSERT_EQ(output, ""); 81 | } 82 | } 83 | 84 | TEST(nolog_LogEveryN, glog_syntax_severity_error) { 85 | LOG_INIT(*test_argv); 86 | 87 | for (int i = 0; i < 5; i++) { 88 | std::string output = 89 | LPP_CAPTURE_STDERR(LOG_EVERY_N(ERROR, 3) << "Test" << 123); 90 | ASSERT_EQ(output, ""); 91 | } 92 | } 93 | 94 | TEST(nolog_LogEveryN, glog_syntax_severity_fatal) { 95 | LOG_INIT(*test_argv); 96 | 97 | for (int i = 0; i < 5; i++) { 98 | std::string output = 99 | LPP_CAPTURE_STDERR(LOG_EVERY_N(FATAL, 3) << "Test" << 123); 100 | ASSERT_EQ(output, ""); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /test/nolog/test_nolog_first_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 07.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(nolog_LogFirstN, lpp_syntax_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(D, 3, "Test" << 123)); 14 | ASSERT_EQ(output, ""); 15 | } 16 | } 17 | 18 | TEST(nolog_LogFirstN, lpp_syntax_severity_info) { 19 | LOG_INIT(*test_argv); 20 | 21 | for (int i = 0; i < 5; i++) { 22 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(I, 3, "Test" << 123)); 23 | ASSERT_EQ(output, ""); 24 | } 25 | } 26 | 27 | TEST(nolog_LogFirstN, lpp_syntax_severity_warning) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(W, 3, "Test" << 123)); 32 | ASSERT_EQ(output, ""); 33 | } 34 | } 35 | 36 | TEST(nolog_LogFirstN, lpp_syntax_severity_error) { 37 | LOG_INIT(*test_argv); 38 | 39 | for (int i = 0; i < 5; i++) { 40 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(E, 3, "Test" << 123)); 41 | ASSERT_EQ(output, ""); 42 | } 43 | } 44 | 45 | TEST(nolog_LogFirstN, lpp_syntax_severity_fatal) { 46 | LOG_INIT(*test_argv); 47 | 48 | for (int i = 0; i < 5; i++) { 49 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(F, 3, "Test" << 123)); 50 | ASSERT_EQ(output, ""); 51 | } 52 | } 53 | 54 | TEST(nolog_LogFirstN, glog_syntax_severity_debug) { 55 | LOG_INIT(*test_argv); 56 | 57 | for (int i = 0; i < 5; i++) { 58 | std::string output = 59 | LPP_CAPTURE_STDOUT(DLOG_FIRST_N(INFO, 3) << "Test" << 123); 60 | ASSERT_EQ(output, ""); 61 | } 62 | } 63 | 64 | TEST(nolog_LogFirstN, glog_syntax_severity_info) { 65 | LOG_INIT(*test_argv); 66 | 67 | for (int i = 0; i < 5; i++) { 68 | std::string output = 69 | LPP_CAPTURE_STDOUT(LOG_FIRST_N(INFO, 3) << "Test" << 123); 70 | ASSERT_EQ(output, ""); 71 | } 72 | } 73 | 74 | TEST(nolog_LogFirstN, glog_syntax_severity_warning) { 75 | LOG_INIT(*test_argv); 76 | 77 | for (int i = 0; i < 5; i++) { 78 | std::string output = 79 | LPP_CAPTURE_STDERR(LOG_FIRST_N(WARNING, 3) << "Test" << 123); 80 | ASSERT_EQ(output, ""); 81 | } 82 | } 83 | 84 | TEST(nolog_LogFirstN, glog_syntax_severity_error) { 85 | LOG_INIT(*test_argv); 86 | 87 | for (int i = 0; i < 5; i++) { 88 | std::string output = 89 | LPP_CAPTURE_STDERR(LOG_FIRST_N(ERROR, 3) << "Test" << 123); 90 | ASSERT_EQ(output, ""); 91 | } 92 | } 93 | 94 | TEST(nolog_LogFirstN, glog_syntax_severity_fatal) { 95 | LOG_INIT(*test_argv); 96 | 97 | for (int i = 0; i < 5; i++) { 98 | std::string output = 99 | LPP_CAPTURE_STDERR(LOG_FIRST_N(FATAL, 3) << "Test" << 123); 100 | ASSERT_EQ(output, ""); 101 | } 102 | } 103 | 104 | TEST(nolog_LogFirstN, ros_debug_once) { 105 | LOG_INIT(*test_argv); 106 | 107 | for (int i = 0; i < 5; i++) { 108 | std::string output = LPP_CAPTURE_STDERR(ROS_DEBUG_ONCE("Test123")); 109 | ASSERT_EQ(output, ""); 110 | } 111 | } 112 | 113 | TEST(nolog_LogFirstN, ros_info_once) { 114 | LOG_INIT(*test_argv); 115 | 116 | for (int i = 0; i < 5; i++) { 117 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE("Test123")); 118 | ASSERT_EQ(output, ""); 119 | } 120 | } 121 | 122 | TEST(nolog_LogFirstN, ros_warn_once) { 123 | LOG_INIT(*test_argv); 124 | 125 | for (int i = 0; i < 5; i++) { 126 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE("Test123")); 127 | ASSERT_EQ(output, ""); 128 | } 129 | } 130 | 131 | TEST(nolog_LogFirstN, ros_error_once) { 132 | LOG_INIT(*test_argv); 133 | 134 | for (int i = 0; i < 5; i++) { 135 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE("Test123")); 136 | ASSERT_EQ(output, ""); 137 | } 138 | } 139 | 140 | TEST(nolog_LogFirstN, ros_fatal_once) { 141 | LOG_INIT(*test_argv); 142 | 143 | for (int i = 0; i < 5; i++) { 144 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE("Test123")); 145 | ASSERT_EQ(output, ""); 146 | } 147 | } -------------------------------------------------------------------------------- /test/nolog/test_nolog_if_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 07.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_debug) { 10 | LOG_INIT(*test_argv); 11 | 12 | for (int i = 0; i < 5; i++) { 13 | std::string output = LPP_CAPTURE_STDOUT(DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 12); 14 | ASSERT_EQ("", output); 15 | } 16 | } 17 | 18 | TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_info) { 19 | LOG_INIT(*test_argv); 20 | 21 | for (int i = 0; i < 5; i++) { 22 | std::string output = LPP_CAPTURE_STDOUT(LOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 12); 23 | ASSERT_EQ("", output); 24 | } 25 | } 26 | 27 | TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_warning) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | std::string output = LPP_CAPTURE_STDERR(LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "Test" << 12); 32 | ASSERT_EQ("", output); 33 | } 34 | } 35 | 36 | TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_error) { 37 | LOG_INIT(*test_argv); 38 | 39 | for (int i = 0; i < 5; i++) { 40 | std::string output = LPP_CAPTURE_STDERR(LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "Test" << 12); 41 | ASSERT_EQ("", output); 42 | } 43 | } 44 | 45 | TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_fatal) { 46 | LOG_INIT(*test_argv); 47 | 48 | for (int i = 0; i < 5; i++) { 49 | std::string output = LPP_CAPTURE_STDERR(LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "Test" << 12); 50 | ASSERT_EQ("", output); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /test/nolog/test_nolog_log_string.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 07.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(nolog_log_string, severity_info) { 10 | LOG_INIT(*test_argv); 11 | 12 | std::vector errors; 13 | 14 | LOG_STRING(INFO, &errors) << "LOG_STRING: " 15 | << "collected info"; 16 | ASSERT_TRUE(errors.empty()); 17 | } 18 | 19 | TEST(nolog_log_string, severity_info_null) { 20 | LOG_INIT(*test_argv); 21 | 22 | std::string output = 23 | LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "LOG_STRING: " 24 | << "collected info"); 25 | ASSERT_EQ(output, ""); 26 | } 27 | 28 | TEST(nolog_log_string, severity_warning) { 29 | LOG_INIT(*test_argv); 30 | 31 | std::vector errors; 32 | 33 | LOG_STRING(WARNING, &errors) << "LOG_STRING: " 34 | << "collected warn"; 35 | ASSERT_TRUE(errors.empty()); 36 | } 37 | 38 | TEST(nolog_log_string, severity_warning_null) { 39 | LOG_INIT(*test_argv); 40 | 41 | std::string output = 42 | LPP_CAPTURE_STDOUT(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " 43 | << "collected warn"); 44 | ASSERT_EQ(output, ""); 45 | } 46 | 47 | TEST(nolog_log_string, severity_error) { 48 | LOG_INIT(*test_argv); 49 | 50 | std::vector errors; 51 | 52 | LOG_STRING(ERROR, &errors) << "LOG_STRING: " 53 | << "collected error"; 54 | ASSERT_TRUE(errors.empty()); 55 | } 56 | 57 | TEST(nolog_log_string, severity_error_null) { 58 | LOG_INIT(*test_argv); 59 | 60 | std::string output = 61 | LPP_CAPTURE_STDOUT(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " 62 | << "collected error"); 63 | ASSERT_EQ(output, ""); 64 | } 65 | 66 | TEST(nolog_log_string, severity_fatal) { 67 | LOG_INIT(*test_argv); 68 | 69 | std::vector errors; 70 | 71 | LOG_STRING(ERROR, &errors) << "LOG_STRING: " 72 | << "collected error"; 73 | ASSERT_TRUE(errors.empty()); 74 | } 75 | 76 | TEST(nolog_log_string, severity_fatal_null) { 77 | LOG_INIT(*test_argv); 78 | 79 | std::string output = 80 | LPP_CAPTURE_STDOUT(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " 81 | << "collected fatal"); 82 | ASSERT_EQ(output, ""); 83 | } 84 | -------------------------------------------------------------------------------- /test/nolog/test_nolog_rosprintf.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 07.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::testing; 10 | 11 | TEST(nolog_rosprintf, severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG(ERROR_MESSAGE, 3.3, 5.5)); 15 | ASSERT_EQ("", output); 16 | } 17 | 18 | TEST(nolog_rosprintf, severity_debug_once) { 19 | LOG_INIT(*test_argv); 20 | 21 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 22 | ASSERT_EQ("", output); 23 | } 24 | 25 | TEST(nolog_rosprintf, severity_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO(ERROR_MESSAGE, 3.3, 5.5)); 29 | ASSERT_EQ("", output); 30 | } 31 | 32 | TEST(nolog_rosprintf, severity_info_once) { 33 | LOG_INIT(*test_argv); 34 | 35 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 36 | ASSERT_EQ("", output); 37 | } 38 | 39 | TEST(nolog_rosprintf, severity_warn) { 40 | LOG_INIT(*test_argv); 41 | 42 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN(ERROR_MESSAGE, 3.3, 5.5)); 43 | ASSERT_EQ("", output); 44 | } 45 | 46 | TEST(nolog_rosprintf, severity_warn_once) { 47 | LOG_INIT(*test_argv); 48 | 49 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 50 | ASSERT_EQ("", output); 51 | } 52 | 53 | TEST(nolog_rosprintf, severity_error) { 54 | LOG_INIT(*test_argv); 55 | 56 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5)); 57 | ASSERT_EQ("", output); 58 | } 59 | 60 | TEST(nolog_rosprintf, severity_error_once) { 61 | LOG_INIT(*test_argv); 62 | 63 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 64 | ASSERT_EQ("", output); 65 | } 66 | 67 | TEST(nolog_rosprintf, severity_fatal) { 68 | LOG_INIT(*test_argv); 69 | 70 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL(ERROR_MESSAGE, 3.3, 5.5)); 71 | ASSERT_EQ("", output); 72 | } 73 | 74 | TEST(nolog_rosprintf, severity_fatal_once) { 75 | LOG_INIT(*test_argv); 76 | 77 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 78 | ASSERT_EQ("", output); 79 | } 80 | -------------------------------------------------------------------------------- /test/nolog/test_nolog_timed.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 07.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | std::vector generateTests() { 11 | return { 12 | {"nolog_timed_lpp_syntax_severity_debug_Test", {""},[]() { LOG_TIMED(D, 1, "Test" << 123); }, EQUAL, STDOUT}, 13 | {"nolog_timed_lpp_syntax_severity_info_Test",{""},[]() { LOG_TIMED(I, 1, "Test" << 123); }, EQUAL, STDOUT}, 14 | {"nolog_timed_lpp_syntax_severity_warning_Test",{""},[]() { LOG_TIMED(W, 1, "Test" << 123); }, EQUAL, STDOUT}, 15 | {"nolog_timed_lpp_syntax_severity_error_Test",{""},[]() { LOG_TIMED(E, 1, "Test" << 123); }, EQUAL, STDOUT}, 16 | {"nolog_timed_lpp_syntax_severity_fatal_Test",{""},[]() { LOG_TIMED(F, 1, "Test" << 123); }, EQUAL, STDOUT}, 17 | 18 | {"nolog_timed_glog_syntax_severity_debug_Test",{""},[]() { DLOG_EVERY_T(INFO, 1) << "Test" << 123; }, IS_SUBSTRING, STDERR}, 19 | {"nolog_timed_glog_syntax_severity_info_Test",{""},[]() { LOG_EVERY_T(INFO, 1) << "Test" << 123; }, IS_SUBSTRING, STDOUT}, 20 | {"nolog_timed_glog_syntax_severity_warning_Test",{""},[]() { LOG_EVERY_T(WARNING, 1) << "Test" << 123; }, IS_SUBSTRING, STDOUT}, 21 | {"nolog_timed_glog_syntax_severity_error_Test",{""},[]() { LOG_EVERY_T(ERROR, 1) << "Test" << 123; }, IS_SUBSTRING, STDOUT}, 22 | {"nolog_timed_glog_syntax_severity_fatal_Test",{""},[]() { LOG_EVERY_T(FATAL, 1) << "Test" << 123; }, IS_SUBSTRING, STDOUT}, 23 | 24 | {"nolog_timed_ros_syntax_severity_debug_Test", {""}, []() {ROS_DEBUG_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 25 | {"nolog_timed_ros_syntax_severity_debug_stream_Test", {""}, []() {ROS_DEBUG_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 26 | {"nolog_timed_ros_syntax_severity_info_Test", {""}, []() {ROS_INFO_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 27 | {"nolog_timed_ros_syntax_severity_info_stream_Test", {""}, []() {ROS_INFO_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDOUT}, 28 | {"nolog_timed_ros_syntax_severity_warning_Test", {""}, []() {ROS_WARN_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 29 | {"nolog_timed_ros_syntax_severity_warning_stream_Test", {""}, []() {ROS_WARN_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 30 | {"nolog_timed_ros_syntax_severity_error_Test", {""}, []() {ROS_ERROR_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 31 | {"nolog_timed_ros_syntax_severity_error_stream_Test", {""}, []() {ROS_ERROR_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 32 | {"nolog_timed_ros_syntax_severity_fatal_Test", {""}, []() {ROS_FATAL_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 33 | {"nolog_timed_ros_syntax_severity_fatal_stream_Test", {""}, []() {ROS_FATAL_STREAM_THROTTLE(1, "Test123"); }, IS_SUBSTRING, STDERR}, 34 | }; 35 | } 36 | 37 | TEST(nolog_timed, lpp_syntax_severity_debug) { 38 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 39 | } 40 | 41 | TEST(nolog_timed, lpp_syntax_severity_info) { 42 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 43 | } 44 | 45 | TEST(nolog_timed, lpp_syntax_severity_warning) { 46 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 47 | } 48 | 49 | TEST(nolog_timed, lpp_syntax_severity_error) { 50 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 51 | } 52 | 53 | TEST(nolog_timed, lpp_syntax_severity_fatal) { 54 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 55 | } 56 | 57 | TEST(nolog_timed, glog_syntax_severity_debug) { 58 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 59 | } 60 | 61 | TEST(nolog_timed, glog_syntax_severity_info) { 62 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 63 | } 64 | 65 | TEST(nolog_timed, glog_syntax_severity_warning) { 66 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 67 | } 68 | 69 | TEST(nolog_timed, glog_syntax_severity_error) { 70 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 71 | } 72 | 73 | TEST(nolog_timed, glog_syntax_severity_fatal) { 74 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 75 | } 76 | 77 | TEST(nolog_timed, ros_syntax_severity_debug) { 78 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 79 | } 80 | 81 | TEST(nolog_timed, ros_syntax_severity_debug_stream) { 82 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 83 | } 84 | 85 | TEST(nolog_timed, ros_syntax_severity_info) { 86 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 87 | } 88 | 89 | TEST(nolog_timed, ros_syntax_severity_info_stream) { 90 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 91 | } 92 | 93 | TEST(nolog_timed, ros_syntax_severity_warning) { 94 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 95 | } 96 | 97 | TEST(nolog_timed, ros_syntax_severity_warning_stream) { 98 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 99 | } 100 | 101 | TEST(nolog_timed, ros_syntax_severity_error) { 102 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 103 | } 104 | 105 | TEST(nolog_timed, ros_syntax_severity_error_stream) { 106 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 107 | } 108 | 109 | TEST(nolog_timed, ros_syntax_severity_fatal) { 110 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 111 | } 112 | 113 | TEST(nolog_timed, ros_syntax_severity_fatal_stream) { 114 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 115 | } -------------------------------------------------------------------------------- /test/nolog/test_nolog_vlog.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 07.09.23. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | TEST(nolog_vlog, glog_syntax_severity_v1) { 10 | LOG_INIT(*test_argv); 11 | FLAGS_v = 3; 12 | 13 | std::string output = LPP_CAPTURE_STDOUT(VLOG(1) << "Test" << 123); 14 | ASSERT_EQ(output, ""); 15 | } 16 | 17 | TEST(nolog_vlog, glog_syntax_severity_v3) { 18 | LOG_INIT(*test_argv); 19 | FLAGS_v = 3; 20 | 21 | std::string output = LPP_CAPTURE_STDOUT(VLOG(3) << "Test123"); 22 | ASSERT_EQ(output, ""); 23 | } 24 | 25 | TEST(nolog_vlog, glog_syntax_severity_v5) { 26 | LOG_INIT(*test_argv); 27 | FLAGS_v = 3; 28 | 29 | std::string output = LPP_CAPTURE_STDOUT(VLOG(5) << "Test123"); 30 | ASSERT_EQ(output, ""); 31 | } 32 | 33 | TEST(nolog_vlog, glog_syntax_severity_if_v1) { 34 | LOG_INIT(*test_argv); 35 | FLAGS_v = 3; 36 | 37 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "Test123"); 38 | ASSERT_EQ(output, ""); 39 | } 40 | 41 | TEST(nolog_vlog, glog_syntax_severity_if_v3) { 42 | LOG_INIT(*test_argv); 43 | FLAGS_v = 3; 44 | 45 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(3, true) << "Test123"); 46 | ASSERT_EQ(output, ""); 47 | } 48 | 49 | TEST(nolog_vlog, glog_syntax_severity_if_v5) { 50 | LOG_INIT(*test_argv); 51 | FLAGS_v = 3; 52 | 53 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, true) << "Test123"); 54 | ASSERT_EQ(output, ""); 55 | } 56 | 57 | TEST(nolog_vlog, glog_syntax_severity_ifnot_v1) { 58 | LOG_INIT(*test_argv); 59 | FLAGS_v = 3; 60 | 61 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, false) << "Test123"); 62 | ASSERT_EQ(output, ""); 63 | } 64 | 65 | TEST(nolog_vlog, glog_syntax_severity_ifnot_v3) { 66 | LOG_INIT(*test_argv); 67 | FLAGS_v = 3; 68 | 69 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(3, false) << "Test123"); 70 | ASSERT_EQ(output, ""); 71 | } 72 | 73 | TEST(nolog_vlog, glog_syntax_severity_ifnot_v5) { 74 | LOG_INIT(*test_argv); 75 | FLAGS_v = 3; 76 | 77 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, false) << "Test123"); 78 | ASSERT_EQ(output, ""); 79 | } 80 | 81 | TEST(nolog_vlog, glog_syntax_every_n_severity_v1) { 82 | LOG_INIT(*test_argv); 83 | FLAGS_v = 3; 84 | 85 | for (int i = 0; i < 5; i++) { 86 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(1, 3) << "Test" << 123); 87 | ASSERT_EQ(output, ""); 88 | } 89 | } 90 | 91 | TEST(nolog_vlog, glog_syntax_every_n_severity_v3) { 92 | LOG_INIT(*test_argv); 93 | FLAGS_v = 3; 94 | 95 | for (int i = 0; i < 5; i++) { 96 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(3, 3) << "Test" << 123); 97 | ASSERT_EQ(output, ""); 98 | } 99 | } 100 | 101 | TEST(nolog_vlog, glog_syntax_every_n_severity_v5) { 102 | LOG_INIT(*test_argv); 103 | FLAGS_v = 3; 104 | 105 | for (int i = 0; i < 5; i++) { 106 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(5, 3) << "Test" << 123); 107 | ASSERT_EQ(output, ""); 108 | } 109 | } 110 | 111 | TEST(nolog_vlog, glog_syntax_if_every_n_severity_v1) { 112 | LOG_INIT(*test_argv); 113 | FLAGS_v = 3; 114 | 115 | for (int i = 0; i < 5; i++) { 116 | testing::internal::CaptureStdout(); 117 | VLOG_IF_EVERY_N(1, i <= 3, 3) << "Test" << 123; 118 | std::string output = testing::internal::GetCapturedStdout(); 119 | 120 | ASSERT_EQ("", output); 121 | } 122 | } 123 | 124 | TEST(nolog_vlog, glog_syntax_if_every_n_severity_v3) { 125 | LOG_INIT(*test_argv); 126 | FLAGS_v = 3; 127 | 128 | for (int i = 0; i < 5; i++) { 129 | testing::internal::CaptureStdout(); 130 | VLOG_IF_EVERY_N(3, i <= 3, 3) << "Test" << 123; 131 | std::string output = testing::internal::GetCapturedStdout(); 132 | 133 | ASSERT_EQ("", output); 134 | } 135 | } 136 | 137 | TEST(nolog_vlog, glog_syntax_if_every_n_severity_v5) { 138 | LOG_INIT(*test_argv); 139 | FLAGS_v = 3; 140 | 141 | for (int i = 0; i < 5; i++) { 142 | testing::internal::CaptureStdout(); 143 | VLOG_IF_EVERY_N(5, i <= 3, 3) << "Test" << 123; 144 | std::string output = testing::internal::GetCapturedStdout(); 145 | 146 | ASSERT_EQ("", output); 147 | } 148 | } 149 | 150 | 151 | -------------------------------------------------------------------------------- /test/roslog/test_roslog_basic.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by acey on 30.08.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::rostest; 10 | 11 | TEST(roslog_basic, glog_syntax_severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | std::string output = LPP_CAPTURE_STDOUT(DLOG(INFO) << "Test"); 15 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 16 | } 17 | 18 | TEST(roslog_basic, glog_syntax_severity_info) { 19 | LOG_INIT(*test_argv); 20 | 21 | std::string output = LPP_CAPTURE_STDOUT(LOG(INFO) << "Test123"); 22 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 23 | } 24 | 25 | TEST(roslog_basic, glog_syntax_severity_warning) { 26 | LOG_INIT(*test_argv); 27 | 28 | std::string output = LPP_CAPTURE_STDERR(LOG(WARNING) << "Test"); 29 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 30 | } 31 | 32 | TEST(roslog_basic, glog_syntax_severity_error) { 33 | LOG_INIT(*test_argv); 34 | 35 | std::string output = LPP_CAPTURE_STDERR(LOG(ERROR) << "Test"); 36 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 37 | } 38 | 39 | TEST(roslog_basic, glog_syntax_severity_fatal) { 40 | LOG_INIT(*test_argv); 41 | 42 | std::string output = LPP_CAPTURE_STDERR(LOG(FATAL) << "Test"); 43 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 44 | } 45 | 46 | //! ################ lpp ################ 47 | TEST(roslog_basic, lpp_syntax_severity_debug) { 48 | LOG_INIT(*test_argv); 49 | 50 | std::string output = LPP_CAPTURE_STDOUT(LOG(D, "" << "Test")); 51 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 52 | } 53 | 54 | TEST(roslog_basic, lpp_syntax_severity_info) { 55 | LOG_INIT(*test_argv); 56 | 57 | std::string output = LPP_CAPTURE_STDOUT(LOG(I, "" << "Test")); 58 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 59 | } 60 | 61 | TEST(roslog_basic, lpp_syntax_severity_warning) { 62 | LOG_INIT(*test_argv); 63 | 64 | std::string output = LPP_CAPTURE_STDERR(LOG(W, "" << "Test")); 65 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 66 | } 67 | 68 | TEST(roslog_basic, lpp_syntax_severity_error) { 69 | LOG_INIT(*test_argv); 70 | 71 | std::string output = LPP_CAPTURE_STDERR(LOG(E, "" << "Test")); 72 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 73 | } 74 | 75 | TEST(roslog_basic, lpp_syntax_severity_fatal) { 76 | LOG_INIT(*test_argv); 77 | 78 | std::string output = LPP_CAPTURE_STDERR(LOG(F, "" << "Test")); 79 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 80 | } 81 | 82 | //! ################ Roslog ################ 83 | TEST(roslog_basic, roslog_syntax_severity_debug) { 84 | LOG_INIT(*test_argv); 85 | 86 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG("Test")); 87 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 88 | } 89 | 90 | TEST(roslog_basic, roslog_syntax_severity_debug_stream) { 91 | LOG_INIT(*test_argv); 92 | 93 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_STREAM("Test")); 94 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 95 | } 96 | 97 | TEST(roslog_basic, roslog_syntax_severity_info) { 98 | LOG_INIT(*test_argv); 99 | 100 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO("Test")); 101 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 102 | } 103 | 104 | TEST(roslog_basic, roslog_syntax_severity_info_stream) { 105 | LOG_INIT(*test_argv); 106 | 107 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_STREAM("" << "Test")); 108 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 109 | } 110 | 111 | TEST(roslog_basic, roslog_syntax_severity_warn) { 112 | LOG_INIT(*test_argv); 113 | 114 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN("Test")); 115 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 116 | } 117 | 118 | TEST(roslog_basic, roslog_syntax_severity_warn_stream) { 119 | LOG_INIT(*test_argv); 120 | 121 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_STREAM("" << "Test")); 122 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 123 | } 124 | 125 | TEST(roslog_basic, roslog_syntax_severity_error) { 126 | LOG_INIT(*test_argv); 127 | 128 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR("Test")); 129 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 130 | } 131 | 132 | TEST(roslog_basic, roslog_syntax_severity_error_stream) { 133 | LOG_INIT(*test_argv); 134 | 135 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_STREAM("" << "Test")); 136 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 137 | } 138 | 139 | TEST(roslog_basic, roslog_syntax_severity_fatal) { 140 | LOG_INIT(*test_argv); 141 | 142 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL("Test")); 143 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 144 | } 145 | 146 | TEST(roslog_basic, roslog_syntax_severity_fatal_stream) { 147 | LOG_INIT(*test_argv); 148 | 149 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_STREAM("" << "Test")); 150 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 151 | } 152 | -------------------------------------------------------------------------------- /test/roslog/test_roslog_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 08.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::rostest; 10 | 11 | TEST(roslog_LogEveryN, lpp_syntax_severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | for (int i = 0; i < 5; i++) { 15 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(D, 3, "Test")); 16 | 17 | if (i % 3 == 0) { 18 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 19 | } else { 20 | ASSERT_EQ("", removeNumbersFromString(output)); 21 | } 22 | } 23 | } 24 | 25 | TEST(roslog_LogEveryN, lpp_syntax_severity_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY(I, 3, "Test")); 30 | 31 | if (i % 3 == 0) { 32 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 33 | } else { 34 | ASSERT_EQ("", removeNumbersFromString(output)); 35 | } 36 | } 37 | } 38 | 39 | TEST(roslog_LogEveryN, lpp_syntax_severity_warning) { 40 | LOG_INIT(*test_argv); 41 | 42 | for (int i = 0; i < 5; i++) { 43 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(W, 3, "Test")); 44 | 45 | if (i % 3 == 0) { 46 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 47 | } else { 48 | ASSERT_EQ("", removeNumbersFromString(output)); 49 | } 50 | } 51 | } 52 | 53 | TEST(roslog_LogEveryN, lpp_syntax_severity_error) { 54 | LOG_INIT(*test_argv); 55 | 56 | for (int i = 0; i < 5; i++) { 57 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(E, 3, "Test")); 58 | 59 | if (i % 3 == 0) { 60 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 61 | } else { 62 | ASSERT_EQ("", removeNumbersFromString(output)); 63 | } 64 | } 65 | } 66 | 67 | TEST(roslog_LogEveryN, lpp_syntax_severity_fatal) { 68 | LOG_INIT(*test_argv); 69 | 70 | for (int i = 0; i < 5; i++) { 71 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY(F, 3, "Test")); 72 | 73 | if (i % 3 == 0) { 74 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 75 | } else { 76 | ASSERT_EQ("", removeNumbersFromString(output)); 77 | } 78 | } 79 | } 80 | 81 | TEST(roslog_LogEveryN, glog_syntax_severity_debug) { 82 | LOG_INIT(*test_argv); 83 | 84 | for (int i = 0; i < 5; i++) { 85 | std::string output = LPP_CAPTURE_STDOUT(DLOG_EVERY_N(INFO, 3) << "Test"); 86 | 87 | if (i % 3 == 0) { 88 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 89 | } else { 90 | ASSERT_EQ("", removeNumbersFromString(output)); 91 | } 92 | } 93 | } 94 | 95 | TEST(roslog_LogEveryN, glog_syntax_severity_info) { 96 | LOG_INIT(*test_argv); 97 | 98 | for (int i = 0; i < 5; i++) { 99 | std::string output = LPP_CAPTURE_STDOUT(LOG_EVERY_N(INFO, 3) << "Test"); 100 | 101 | if (i % 3 == 0) { 102 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 103 | } else { 104 | ASSERT_EQ("", removeNumbersFromString(output)); 105 | } 106 | } 107 | } 108 | 109 | TEST(roslog_LogEveryN, glog_syntax_severity_warning) { 110 | LOG_INIT(*test_argv); 111 | 112 | for (int i = 0; i < 5; i++) { 113 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(WARNING, 3) << "Test"); 114 | 115 | if (i % 3 == 0) { 116 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 117 | } else { 118 | ASSERT_EQ("", removeNumbersFromString(output)); 119 | } 120 | } 121 | } 122 | 123 | TEST(roslog_LogEveryN, glog_syntax_severity_error) { 124 | LOG_INIT(*test_argv); 125 | 126 | for (int i = 0; i < 5; i++) { 127 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(ERROR, 3) << "Test"); 128 | 129 | if (i % 3 == 0) { 130 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 131 | } else { 132 | ASSERT_EQ("", removeNumbersFromString(output)); 133 | } 134 | } 135 | } 136 | 137 | TEST(roslog_LogEveryN, glog_syntax_severity_fatal) { 138 | LOG_INIT(*test_argv); 139 | 140 | for (int i = 0; i < 5; i++) { 141 | std::string output = LPP_CAPTURE_STDERR(LOG_EVERY_N(FATAL, 3) << "Test"); 142 | 143 | if (i % 3 == 0) { 144 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 145 | } else { 146 | ASSERT_EQ("", removeNumbersFromString(output)); 147 | } 148 | } 149 | } -------------------------------------------------------------------------------- /test/roslog/test_roslog_first_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 08.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::rostest; 10 | 11 | TEST(roslog_LogFirstN, lpp_syntax_severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | for (int i = 0; i < 5; i++) { 15 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(D, 3, "Test")); 16 | 17 | if (i < 3) { 18 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 19 | } else { 20 | ASSERT_EQ("", removeNumbersFromString(output)); 21 | } 22 | } 23 | } 24 | 25 | TEST(roslog_LogFirstN, lpp_syntax_severity_info) { 26 | LOG_INIT(*test_argv); 27 | 28 | for (int i = 0; i < 5; i++) { 29 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST(I, 3, "Test")); 30 | 31 | if (i < 3) { 32 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 33 | } else { 34 | ASSERT_EQ("", removeNumbersFromString(output)); 35 | } 36 | } 37 | } 38 | 39 | TEST(roslog_LogFirstN, lpp_syntax_severity_warning) { 40 | LOG_INIT(*test_argv); 41 | 42 | for (int i = 0; i < 5; i++) { 43 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(W, 3, "Test")); 44 | 45 | if (i < 3) { 46 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 47 | } else { 48 | ASSERT_EQ("", removeNumbersFromString(output)); 49 | } 50 | } 51 | } 52 | 53 | TEST(roslog_LogFirstN, lpp_syntax_severity_error) { 54 | LOG_INIT(*test_argv); 55 | 56 | for (int i = 0; i < 5; i++) { 57 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(E, 3, "Test")); 58 | 59 | if (i < 3) { 60 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 61 | } else { 62 | ASSERT_EQ("", removeNumbersFromString(output)); 63 | } 64 | } 65 | } 66 | 67 | TEST(roslog_LogFirstN, lpp_syntax_severity_fatal) { 68 | LOG_INIT(*test_argv); 69 | 70 | for (int i = 0; i < 5; i++) { 71 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST(F, 3, "Test")); 72 | 73 | if (i < 3) { 74 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 75 | } else { 76 | ASSERT_EQ("", removeNumbersFromString(output)); 77 | } 78 | } 79 | } 80 | 81 | TEST(roslog_LogFirstN, glog_syntax_severity_debug) { 82 | LOG_INIT(*test_argv); 83 | 84 | for (int i = 0; i < 5; i++) { 85 | std::string output = LPP_CAPTURE_STDOUT(DLOG_FIRST_N(INFO, 3) << "Test"); 86 | 87 | if (i < 3) { 88 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 89 | } else { 90 | ASSERT_EQ("", removeNumbersFromString(output)); 91 | } 92 | } 93 | } 94 | 95 | TEST(roslog_LogFirstN, glog_syntax_severity_info) { 96 | LOG_INIT(*test_argv); 97 | 98 | for (int i = 0; i < 5; i++) { 99 | std::string output = LPP_CAPTURE_STDOUT(LOG_FIRST_N(INFO, 3) << "Test"); 100 | 101 | if (i < 3) { 102 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 103 | } else { 104 | ASSERT_EQ("", removeNumbersFromString(output)); 105 | } 106 | } 107 | } 108 | 109 | TEST(roslog_LogFirstN, glog_syntax_severity_warning) { 110 | LOG_INIT(*test_argv); 111 | 112 | for (int i = 0; i < 5; i++) { 113 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(WARNING, 3) << "Test"); 114 | 115 | if (i < 3) { 116 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 117 | } else { 118 | ASSERT_EQ("", removeNumbersFromString(output)); 119 | } 120 | } 121 | } 122 | 123 | TEST(roslog_LogFirstN, glog_syntax_severity_error) { 124 | LOG_INIT(*test_argv); 125 | 126 | for (int i = 0; i < 5; i++) { 127 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(ERROR, 3) << "Test"); 128 | 129 | if (i < 3) { 130 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 131 | } else { 132 | ASSERT_EQ("", removeNumbersFromString(output)); 133 | } 134 | } 135 | } 136 | 137 | TEST(roslog_LogFirstN, glog_syntax_severity_fatal) { 138 | LOG_INIT(*test_argv); 139 | 140 | for (int i = 0; i < 5; i++) { 141 | std::string output = LPP_CAPTURE_STDERR(LOG_FIRST_N(FATAL, 3) << "Test"); 142 | 143 | if (i < 3) { 144 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 145 | } else { 146 | ASSERT_EQ("", removeNumbersFromString(output)); 147 | } 148 | } 149 | } 150 | 151 | TEST(roslog_LogFirstN, ros_debug_once) { 152 | LOG_INIT(*test_argv); 153 | 154 | for (int i = 0; i < 5; i++) { 155 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE("Test123")); 156 | 157 | if (i == 0) { 158 | ASSERT_EQ(debug, removeNumbersFromString(output)); 159 | } else { 160 | ASSERT_EQ("", removeNumbersFromString(output)); 161 | } 162 | } 163 | } 164 | 165 | TEST(roslog_LogFirstN, ros_info_once) { 166 | LOG_INIT(*test_argv); 167 | 168 | for (int i = 0; i < 5; i++) { 169 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE("Test123")); 170 | 171 | if (i == 0) { 172 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 173 | } else { 174 | ASSERT_EQ("", removeNumbersFromString(output)); 175 | } 176 | } 177 | } 178 | 179 | TEST(roslog_LogFirstN, ros_warn_once) { 180 | LOG_INIT(*test_argv); 181 | 182 | for (int i = 0; i < 5; i++) { 183 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE("Test123")); 184 | 185 | if (i == 0) { 186 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 187 | } else { 188 | ASSERT_EQ("", removeNumbersFromString(output)); 189 | } 190 | } 191 | } 192 | 193 | TEST(roslog_LogFirstN, ros_error_once) { 194 | LOG_INIT(*test_argv); 195 | 196 | for (int i = 0; i < 5; i++) { 197 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE("Test123")); 198 | 199 | if (i == 0) { 200 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 201 | } else { 202 | ASSERT_EQ("", removeNumbersFromString(output)); 203 | } 204 | } 205 | } 206 | 207 | TEST(roslog_LogFirstN, ros_fatal_once) { 208 | LOG_INIT(*test_argv); 209 | 210 | for (int i = 0; i < 5; i++) { 211 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE("Test123")); 212 | 213 | if (i == 0) { 214 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 215 | } else { 216 | ASSERT_EQ("", removeNumbersFromString(output)); 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /test/roslog/test_roslog_if_every_n.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 15.12.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::rostest; 10 | 11 | TEST(roslog_if_every_n, glog_syntax_if_every_n_severity_debug) { 12 | LOG_INIT(*test_argv); 13 | 14 | for (int i = 0; i < 5; i++) { 15 | testing::internal::CaptureStdout(); 16 | DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 17 | std::string output = testing::internal::GetCapturedStdout(); 18 | 19 | if (i <= 3 && i % 3 == 0) { 20 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 21 | } else { 22 | ASSERT_EQ(output, ""); 23 | } 24 | } 25 | } 26 | 27 | TEST(roslog_if_every_n, glog_syntax_if_every_n_severity_info) { 28 | LOG_INIT(*test_argv); 29 | 30 | for (int i = 0; i < 5; i++) { 31 | testing::internal::CaptureStdout(); 32 | LOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 123; 33 | std::string output = testing::internal::GetCapturedStdout(); 34 | 35 | if (i <= 3 && i % 3 == 0) { 36 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 37 | } else { 38 | ASSERT_EQ(output, ""); 39 | } 40 | } 41 | } 42 | 43 | TEST(roslog_if_every_n, glog_syntax_if_every_n_severity_warning) { 44 | LOG_INIT(*test_argv); 45 | 46 | for (int i = 0; i < 5; i++) { 47 | testing::internal::CaptureStderr(); 48 | LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "Test" << 123; 49 | std::string output = testing::internal::GetCapturedStderr(); 50 | 51 | if (i <= 3 && i % 3 == 0) { 52 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 53 | } else { 54 | ASSERT_EQ(output, ""); 55 | } 56 | } 57 | 58 | } 59 | 60 | TEST(roslog_if_every_n, glog_syntax_if_every_n_severity_error) { 61 | LOG_INIT(*test_argv); 62 | 63 | for (int i = 0; i < 5; i++) { 64 | testing::internal::CaptureStderr(); 65 | LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "Test" << 123; 66 | std::string output = testing::internal::GetCapturedStderr(); 67 | 68 | if (i <= 3 && i % 3 == 0) { 69 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 70 | } else { 71 | ASSERT_EQ(output, ""); 72 | } 73 | } 74 | } 75 | 76 | TEST(roslog_if_every_n, glog_syntax_if_every_n_severity_fatal) { 77 | LOG_INIT(*test_argv); 78 | 79 | for (int i = 0; i < 5; i++) { 80 | testing::internal::CaptureStderr(); 81 | LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "Test" << 123; 82 | std::string output = testing::internal::GetCapturedStderr(); 83 | 84 | if (i <= 3 && i % 3 == 0) { 85 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 86 | } else { 87 | ASSERT_EQ(output, ""); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /test/roslog/test_roslog_log_string.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 28.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace lpp::logstr; 10 | 11 | TEST(roslog_log_string, severity_info) { 12 | LOG_INIT(*test_argv); 13 | 14 | std::vector errors; 15 | 16 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 17 | testing::internal::CaptureStdout(); 18 | LOG_STRING(INFO, &errors) << "LOG_STRING: " << "collected info"; 19 | std::string output = testing::internal::GetCapturedStdout(); 20 | 21 | ASSERT_EQ(output, ""); 22 | ASSERT_EQ("LOG_STRING: collected info", errors.at(0)); 23 | } 24 | 25 | TEST(roslog_log_string, severity_info_null) { 26 | LOG_INIT(*test_argv); 27 | 28 | std::string output = LPP_CAPTURE_STDOUT(LOG_STRING(INFO, nullptr) << "LOG_STRING: " << "collected info"); 29 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 30 | } 31 | 32 | TEST(roslog_log_string, severity_warning) { 33 | LOG_INIT(*test_argv); 34 | 35 | std::vector errors; 36 | 37 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 38 | testing::internal::CaptureStderr(); 39 | LOG_STRING(WARNING, &errors) << "LOG_STRING: " << "collected warn"; 40 | std::string output = testing::internal::GetCapturedStderr(); 41 | 42 | ASSERT_EQ(output, ""); 43 | ASSERT_EQ("LOG_STRING: collected warn", errors.at(0)); 44 | } 45 | 46 | TEST(roslog_log_string, severity_warning_null) { 47 | LOG_INIT(*test_argv); 48 | 49 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(WARNING, nullptr) << "LOG_STRING: " << "collected warn"); 50 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 51 | } 52 | 53 | TEST(roslog_log_string, severity_error) { 54 | LOG_INIT(*test_argv); 55 | 56 | std::vector errors; 57 | 58 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 59 | testing::internal::CaptureStderr(); 60 | LOG_STRING(ERROR, &errors) << "LOG_STRING: " << "collected error"; 61 | std::string output = testing::internal::GetCapturedStderr(); 62 | 63 | ASSERT_EQ(output, ""); 64 | ASSERT_EQ("LOG_STRING: collected error", errors.at(0)); 65 | } 66 | 67 | TEST(roslog_log_string, severity_error_null) { 68 | LOG_INIT(*test_argv); 69 | 70 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(ERROR, nullptr) << "LOG_STRING: " << "collected error"); 71 | ASSERT_EQ(removeNumbersFromString(output), error); 72 | } 73 | 74 | TEST(roslog_log_string, severity_fatal) { 75 | LOG_INIT(*test_argv); 76 | 77 | std::vector errors; 78 | 79 | //Can't capture variables in lambda with LPP_CAPTURE_STDERR() 80 | testing::internal::CaptureStderr(); 81 | LOG_STRING(FATAL, &errors) << "LOG_STRING: " << "collected fatal"; 82 | std::string output = testing::internal::GetCapturedStderr(); 83 | ASSERT_EQ(output, ""); 84 | 85 | ASSERT_EQ("LOG_STRING: collected fatal", errors.at(0)); 86 | } 87 | 88 | TEST(roslog_log_string, severity_fatal_null) { 89 | LOG_INIT(*test_argv); 90 | 91 | std::string output = LPP_CAPTURE_STDERR(LOG_STRING(FATAL, nullptr) << "LOG_STRING: " << "collected fatal"); 92 | ASSERT_EQ(removeNumbersFromString(output), fatal); 93 | } -------------------------------------------------------------------------------- /test/roslog/test_roslog_rosprintf.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace lpp::rosprintf; 6 | using namespace lpp::testing; 7 | 8 | TEST(roslog_rosprintf, ros_debug) { 9 | LOG_INIT(*test_argv); 10 | 11 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG(ERROR_MESSAGE, 3.3, 5.5)); 12 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 13 | } 14 | 15 | TEST(roslog_rosprintf, ros_debug_once) { 16 | LOG_INIT(*test_argv); 17 | 18 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 19 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 20 | } 21 | 22 | TEST(roslog_rosprintf, ros_debug_throttle) { 23 | LOG_INIT(*test_argv); 24 | 25 | std::string output = LPP_CAPTURE_STDOUT(ROS_DEBUG_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 26 | EXPECT_TRUE(debug == removeNumbersFromString(output) || v2::debug == removeNumbersFromString(output)); 27 | } 28 | 29 | TEST(roslog_rosprintf, ros_info) { 30 | LOG_INIT(*test_argv); 31 | 32 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO(ERROR_MESSAGE, 3.3, 5.5)); 33 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 34 | } 35 | 36 | TEST(roslog_rosprintf, ros_info_once) { 37 | LOG_INIT(*test_argv); 38 | 39 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 40 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 41 | } 42 | 43 | TEST(roslog_rosprintf, ros_info_throttle) { 44 | LOG_INIT(*test_argv); 45 | 46 | std::string output = LPP_CAPTURE_STDOUT(ROS_INFO_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 47 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 48 | } 49 | 50 | TEST(roslog_rosprintf, ros_warn) { 51 | LOG_INIT(*test_argv); 52 | 53 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN(ERROR_MESSAGE, 3.3, 5.5)); 54 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 55 | } 56 | 57 | TEST(roslog_rosprintf, ros_warn_once) { 58 | LOG_INIT(*test_argv); 59 | 60 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 61 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 62 | } 63 | 64 | TEST(roslog_rosprintf, ros_warn_throttle) { 65 | LOG_INIT(*test_argv); 66 | 67 | std::string output = LPP_CAPTURE_STDERR(ROS_WARN_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 68 | EXPECT_TRUE(warning == removeNumbersFromString(output) || v2::warning == removeNumbersFromString(output)); 69 | } 70 | 71 | TEST(roslog_rosprintf, ros_error) { 72 | LOG_INIT(*test_argv); 73 | 74 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR(ERROR_MESSAGE, 3.3, 5.5)); 75 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 76 | } 77 | 78 | TEST(roslog_rosprintf, ros_error_once) { 79 | LOG_INIT(*test_argv); 80 | 81 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 82 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 83 | } 84 | 85 | TEST(roslog_rosprintf, ros_error_throttle) { 86 | LOG_INIT(*test_argv); 87 | 88 | std::string output = LPP_CAPTURE_STDERR(ROS_ERROR_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 89 | EXPECT_TRUE(error == removeNumbersFromString(output) || v2::error == removeNumbersFromString(output)); 90 | } 91 | 92 | TEST(roslog_rosprintf, ros_fatal) { 93 | LOG_INIT(*test_argv); 94 | 95 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL(ERROR_MESSAGE, 3.3, 5.5)); 96 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 97 | } 98 | 99 | TEST(roslog_rosprintf, ros_fatal_once) { 100 | LOG_INIT(*test_argv); 101 | 102 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_ONCE(ERROR_MESSAGE, 3.3, 5.5)); 103 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 104 | } 105 | 106 | TEST(roslog_rosprintf, ros_fatal_throttle) { 107 | LOG_INIT(*test_argv); 108 | 109 | std::string output = LPP_CAPTURE_STDERR(ROS_FATAL_THROTTLE(1, ERROR_MESSAGE, 3.3, 5.5)); 110 | EXPECT_TRUE(fatal == removeNumbersFromString(output) || v2::fatal == removeNumbersFromString(output)); 111 | } -------------------------------------------------------------------------------- /test/roslog/test_roslog_timed.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 16.09.22. 3 | // 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace lpp::rostest; 11 | 12 | std::vector generateTests() { 13 | return { 14 | {"roslog_timed_lpp_syntax_severity_debug_Test", {debug},[]() { LOG_TIMED(D, 1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 15 | {"roslog_timed_lpp_syntax_severity_info_Test", {info, v2::info},[]() { LOG_TIMED(I, 1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 16 | {"roslog_timed_lpp_syntax_severity_warning_Test", {warning, v2::warning},[]() { LOG_TIMED(W, 1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 17 | {"roslog_timed_lpp_syntax_severity_error_Test",{error},[]() { LOG_TIMED(E, 1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 18 | {"roslog_timed_lpp_syntax_severity_fatal_Test",{fatal},[]() { LOG_TIMED(F, 1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 19 | 20 | {"roslog_timed_glog_syntax_severity_debug_Test",{debug},[]() { DLOG_EVERY_T(INFO, 1) << "Test" << 123; }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 21 | {"roslog_timed_glog_syntax_severity_info_Test", {info, v2::info},[]() { LOG_EVERY_T(INFO, 1) << "Test" << 123; }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 22 | {"roslog_timed_glog_syntax_severity_warning_Test", {warning, v2::warning},[]() { LOG_EVERY_T(WARNING, 1) << "Test" << 123; }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 23 | {"roslog_timed_glog_syntax_severity_error_Test",{error},[]() { LOG_EVERY_T(ERROR, 1) << "Test" << 123; }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 24 | {"roslog_timed_glog_syntax_severity_fatal_Test",{fatal},[]() { LOG_EVERY_T(FATAL, 1) << "Test" << 123; }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 25 | 26 | {"roslog_timed_ros_syntax_severity_debug_Test", {debug}, []() {ROS_DEBUG_THROTTLE(1, "Test123"); }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 27 | {"roslog_timed_ros_syntax_severity_debug_stream_Test", {debug}, []() {ROS_DEBUG_STREAM_THROTTLE(1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 28 | {"roslog_timed_ros_syntax_severity_info_Test", {info, v2::info}, []() {ROS_INFO_THROTTLE(1, "Test123"); }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 29 | {"roslog_timed_ros_syntax_severity_info_stream_Test", {info, v2::info}, []() {ROS_INFO_STREAM_THROTTLE(1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDOUT}, 30 | {"roslog_timed_ros_syntax_severity_warning_Test", {warning, v2::warning}, []() {ROS_WARN_THROTTLE(1, "Test123"); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 31 | {"roslog_timed_ros_syntax_severity_warning_stream_Test", {warning, v2::warning}, []() {ROS_WARN_STREAM_THROTTLE(1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 32 | {"roslog_timed_ros_syntax_severity_error_Test", {error}, []() {ROS_ERROR_THROTTLE(1, "Test123"); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 33 | {"roslog_timed_ros_syntax_severity_error_stream_Test", {error}, []() {ROS_ERROR_STREAM_THROTTLE(1, "Test" << 123); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 34 | {"roslog_timed_ros_syntax_severity_fatal_Test", {fatal}, []() {ROS_FATAL_THROTTLE(1, "Test123"); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 35 | {"roslog_timed_ros_syntax_severity_fatal_stream_Test", {fatal}, []() {ROS_FATAL_STREAM_THROTTLE(1, "Test123"); }, REMOVE_NUMBERS_FROM_STRING, STDERR}, 36 | }; 37 | } 38 | 39 | TEST(roslog_timed, lpp_syntax_floating_point_time) { 40 | LOG_INIT(*test_argv); 41 | for (int i = 0; i < 5; i++) { 42 | std::string output = LPP_CAPTURE_STDOUT(LOG_TIMED(I, 0.1, "Test" << 123)); 43 | if (i % 2 == 0) { 44 | EXPECT_TRUE(info == removeNumbersFromString(output) || v2::info == removeNumbersFromString(output)); 45 | } 46 | //sleep 0.1s 47 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); 48 | } 49 | } 50 | 51 | TEST(roslog_timed, lpp_syntax_severity_debug) { 52 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 53 | } 54 | 55 | TEST(roslog_timed, lpp_syntax_severity_info) { 56 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 57 | } 58 | 59 | TEST(roslog_timed, lpp_syntax_severity_warning) { 60 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 61 | } 62 | 63 | TEST(roslog_timed, lpp_syntax_severity_error) { 64 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 65 | } 66 | 67 | TEST(roslog_timed, lpp_syntax_severity_fatal) { 68 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 69 | } 70 | 71 | TEST(roslog_timed, glog_syntax_severity_debug) { 72 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 73 | } 74 | 75 | TEST(roslog_timed, glog_syntax_severity_info) { 76 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 77 | } 78 | 79 | TEST(roslog_timed, glog_syntax_severity_warning) { 80 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 81 | } 82 | 83 | TEST(roslog_timed, glog_syntax_severity_error) { 84 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 85 | } 86 | 87 | TEST(roslog_timed, glog_syntax_severity_fatal) { 88 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 89 | } 90 | 91 | TEST(roslog_timed, ros_syntax_severity_debug) { 92 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 93 | } 94 | 95 | TEST(roslog_timed, ros_syntax_severity_debug_stream) { 96 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 97 | } 98 | 99 | TEST(roslog_timed, ros_syntax_severity_info) { 100 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 101 | } 102 | 103 | TEST(roslog_timed, ros_syntax_severity_info_stream) { 104 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 105 | } 106 | 107 | TEST(roslog_timed, ros_syntax_severity_warning) { 108 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 109 | } 110 | 111 | TEST(roslog_timed, ros_syntax_severity_warning_stream) { 112 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 113 | } 114 | 115 | TEST(roslog_timed, ros_syntax_severity_error) { 116 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 117 | } 118 | 119 | TEST(roslog_timed, ros_syntax_severity_error_stream) { 120 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 121 | } 122 | 123 | TEST(roslog_timed, ros_syntax_severity_fatal) { 124 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 125 | } 126 | 127 | TEST(roslog_timed, ros_syntax_severity_fatal_stream) { 128 | ASSERT_TRUE(TestResult::getInstance().get(GET_CLASS_NAME(*this, nullptr))); 129 | } -------------------------------------------------------------------------------- /test/roslog/test_roslog_vlog.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y (acey) on 27.09.22. 3 | // 4 | 5 | #include 6 | #include "log++.h" 7 | #include "test_utils.h" 8 | 9 | using namespace lpp::rostest; 10 | 11 | TEST(roslog_vlog, glog_syntax_severity_v1) { 12 | LOG_INIT(*test_argv); 13 | FLAGS_v = 3; 14 | 15 | std::string output = LPP_CAPTURE_STDOUT(VLOG(1) << "Test" << 123); 16 | ASSERT_EQ(debug, removeNumbersFromString(output)); 17 | } 18 | 19 | TEST(roslog_vlog, glog_syntax_severity_v3) { 20 | LOG_INIT(*test_argv); 21 | FLAGS_v = 3; 22 | 23 | std::string output = LPP_CAPTURE_STDOUT(VLOG(3) << "Test123"); 24 | ASSERT_EQ(debug, removeNumbersFromString(output)); 25 | } 26 | 27 | TEST(roslog_vlog, glog_syntax_severity_v5) { 28 | LOG_INIT(*test_argv); 29 | FLAGS_v = 3; 30 | 31 | std::string output = LPP_CAPTURE_STDOUT(VLOG(5) << "Test123"); 32 | ASSERT_EQ(output, ""); 33 | } 34 | 35 | TEST(roslog_vlog, glog_syntax_severity_if_v1) { 36 | LOG_INIT(*test_argv); 37 | FLAGS_v = 3; 38 | 39 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "Test123"); 40 | ASSERT_EQ(debug, removeNumbersFromString(output)); 41 | } 42 | 43 | TEST(roslog_vlog, glog_syntax_severity_if_v3) { 44 | LOG_INIT(*test_argv); 45 | FLAGS_v = 3; 46 | 47 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, true) << "Test123"); 48 | ASSERT_EQ(debug, removeNumbersFromString(output)); 49 | } 50 | 51 | TEST(roslog_vlog, glog_syntax_severity_if_v5) { 52 | LOG_INIT(*test_argv); 53 | FLAGS_v = 3; 54 | 55 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, true) << "Test123"); 56 | ASSERT_EQ(output, ""); 57 | } 58 | 59 | TEST(roslog_vlog, glog_syntax_severity_ifnot_v1) { 60 | LOG_INIT(*test_argv); 61 | FLAGS_v = 3; 62 | 63 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(1, false) << "Test123"); 64 | ASSERT_EQ(output, ""); 65 | } 66 | 67 | TEST(roslog_vlog, glog_syntax_severity_ifnot_v3) { 68 | LOG_INIT(*test_argv); 69 | FLAGS_v = 3; 70 | 71 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(3, false) << "Test123"); 72 | ASSERT_EQ(output, ""); 73 | } 74 | 75 | TEST(roslog_vlog, glog_syntax_severity_ifnot_v5) { 76 | LOG_INIT(*test_argv); 77 | FLAGS_v = 3; 78 | 79 | std::string output = LPP_CAPTURE_STDOUT(VLOG_IF(5, false) << "Test123"); 80 | ASSERT_EQ(output, ""); 81 | } 82 | 83 | TEST(roslog_vlog, glog_syntax_every_n_severity_v1) { 84 | LOG_INIT(*test_argv); 85 | FLAGS_v = 3; 86 | 87 | for (int i = 0; i < 5; i++) { 88 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(1, 3) << "Test" << 123); 89 | 90 | if (i % 3 == 0) { 91 | ASSERT_EQ(debug, removeNumbersFromString(output)); 92 | } else { 93 | ASSERT_EQ(output, ""); 94 | } 95 | } 96 | } 97 | 98 | TEST(roslog_vlog, glog_syntax_every_n_severity_v3) { 99 | LOG_INIT(*test_argv); 100 | FLAGS_v = 3; 101 | 102 | for (int i = 0; i < 5; i++) { 103 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(3, 3) << "Test" << 123); 104 | 105 | if (i % 3 == 0) { 106 | ASSERT_EQ(debug, removeNumbersFromString(output)); 107 | } else { 108 | ASSERT_EQ(output, ""); 109 | } 110 | } 111 | } 112 | 113 | TEST(roslog_vlog, glog_syntax_every_n_severity_v5) { 114 | LOG_INIT(*test_argv); 115 | FLAGS_v = 3; 116 | 117 | for (int i = 0; i < 5; i++) { 118 | std::string output = LPP_CAPTURE_STDOUT(VLOG_EVERY_N(5, 3) << "Test" << 123); 119 | ASSERT_EQ(output, ""); 120 | } 121 | } 122 | 123 | TEST(roslog_vlog, glog_syntax_if_every_n_severity_v1) { 124 | for (int i = 0; i < 5; i++) { 125 | testing::internal::CaptureStdout(); 126 | VLOG_IF_EVERY_N(1, i <= 3, 3) << "Test" << 123; 127 | std::string output = testing::internal::GetCapturedStdout(); 128 | 129 | if (i <= 3 && i % 3 == 0) { 130 | ASSERT_EQ(debug, removeNumbersFromString(output)); 131 | } else { 132 | ASSERT_EQ(output, ""); 133 | } 134 | } 135 | } 136 | 137 | TEST(roslog_vlog, glog_syntax_if_every_n_severity_v3) { 138 | for (int i = 0; i < 5; i++) { 139 | testing::internal::CaptureStdout(); 140 | VLOG_IF_EVERY_N(3, i <= 3, 3) << "Test" << 123; 141 | std::string output = testing::internal::GetCapturedStdout(); 142 | 143 | if (i <= 3 && i % 3 == 0) { 144 | ASSERT_EQ(debug, removeNumbersFromString(output)); 145 | } else { 146 | ASSERT_EQ(output, ""); 147 | } 148 | } 149 | } 150 | 151 | TEST(roslog_vlog, glog_syntax_if_every_n_severity_v5) { 152 | LOG_INIT(*test_argv); 153 | FLAGS_v = 3; 154 | 155 | for (int i = 0; i < 5; i++) { 156 | testing::internal::CaptureStdout(); 157 | VLOG_IF_EVERY_N(5, i <= 3, 3) << "Test" << 123; 158 | std::string output = testing::internal::GetCapturedStdout(); 159 | 160 | ASSERT_EQ(output, ""); 161 | } 162 | } 163 | 164 | -------------------------------------------------------------------------------- /test/test_entry_point.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 4c3y on 23.08.22. 3 | // 4 | 5 | #include 6 | #include 7 | 8 | char** test_argv; 9 | 10 | int main(int argc, char **argv) { 11 | testing::InitGoogleTest(&argc, argv); 12 | test_argv = argv; 13 | ros::Time::init(); 14 | return RUN_ALL_TESTS(); 15 | } --------------------------------------------------------------------------------