LCOV - code coverage report
Current view: top level - tests - catch_safe_tcattr.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.9 % 28 19
Test Date: 2026-08-02 20:00:41 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2026  Made to Order Software Corp.  All Rights Reserved
       2              : //
       3              : // https://snapwebsites.org/project/snapdev
       4              : // contact@m2osw.com
       5              : //
       6              : // This program is free software: you can redistribute it and/or modify
       7              : // it under the terms of the GNU General Public License as published by
       8              : // the Free Software Foundation, either version 3 of the License, or
       9              : // (at your option) any later version.
      10              : //
      11              : // This program is distributed in the hope that it will be useful,
      12              : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : // GNU General Public License for more details.
      15              : //
      16              : // You should have received a copy of the GNU General Public License
      17              : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18              : 
      19              : /** \file
      20              :  * \brief Verify that the safe_tcattr object works.
      21              :  *
      22              :  * This file implements tests for the safe_tcattr template to make sure that
      23              :  * it works as expected.
      24              :  */
      25              : 
      26              : // self
      27              : //
      28              : #include    <snapdev/safe_tcattr.h>
      29              : 
      30              : #include    "catch_main.h"
      31              : 
      32              : 
      33              : // snapdev
      34              : //
      35              : //#include    <snapdev/not_reached.h>
      36              : 
      37              : 
      38              : // last include
      39              : //
      40              : #include    <snapdev/poison.h>
      41              : 
      42              : 
      43              : namespace
      44              : {
      45              : 
      46              : 
      47              : 
      48              : 
      49              : } // no name namespace
      50              : 
      51              : 
      52            1 : CATCH_TEST_CASE("safe_tcattr", "[raii][terminal]")
      53              : {
      54            1 :     CATCH_START_SECTION("safe_tcattr: remove/restore ECHO")
      55              :     {
      56            1 :         snapdev::safe_tcattr safe;
      57            1 :         termios attr = {};
      58            1 :         safe.get_original_attributes(attr);
      59            1 :         termios const original_attr(attr);
      60            1 :         if((original_attr.c_lflag & ECHO) != 0)
      61              :         {
      62            1 :             attr.c_lflag &= ~ECHO;
      63            1 :             safe.set_attributes(TCSANOW, attr);
      64              : 
      65            1 :             termios new_attr = {};
      66            1 :             safe.get_attributes(new_attr);
      67            1 :             CATCH_REQUIRE((new_attr.c_lflag & ECHO) == 0);
      68              : 
      69            1 :             safe.restore_attributes();
      70              : 
      71            1 :             termios restored_attr = {};
      72            1 :             safe.get_attributes(restored_attr);
      73            1 :             CATCH_REQUIRE((restored_attr.c_lflag & ECHO) != 0);
      74              :         }
      75              :         else
      76              :         {
      77              :             // you can test that case as a programmer using ./mk -l -t safe_tcattr
      78              :             //
      79            0 :             attr.c_lflag |= ECHO;
      80            0 :             safe.set_attributes(TCSANOW, attr);
      81              : 
      82            0 :             termios new_attr = {};
      83            0 :             safe.get_attributes(new_attr);
      84            0 :             CATCH_REQUIRE((new_attr.c_lflag & ECHO) != 0);
      85              : 
      86            0 :             safe.restore_attributes();
      87              : 
      88            0 :             termios restored_attr = {};
      89            0 :             safe.get_attributes(restored_attr);
      90            0 :             CATCH_REQUIRE((restored_attr.c_lflag & ECHO) == 0);
      91              :         }
      92            1 :     }
      93            1 :     CATCH_END_SECTION()
      94            1 : }
      95              : 
      96              : 
      97              : 
      98              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

Snap C++ | List of projects | List of versions