LCOV - code coverage report
Current view: top level - tests - catch_username.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 20 20
Test Date: 2025-07-03 19:05:49 Functions: 100.0 % 2 2
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2018-2025  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 username() function works.
      21              :  *
      22              :  * This file implements tests for the username() function.
      23              :  */
      24              : 
      25              : // self
      26              : //
      27              : #include    <snapdev/username.h>
      28              : 
      29              : //#include    <snapdev/file_contents.h>
      30              : //#include    <snapdev/user_groups.h>
      31              : 
      32              : #include    "catch_main.h"
      33              : 
      34              : 
      35              : // C++
      36              : //
      37              : //#include    <set>
      38              : 
      39              : 
      40              : // last include
      41              : //
      42              : #include    <snapdev/poison.h>
      43              : 
      44              : 
      45              : 
      46              : 
      47            1 : CATCH_TEST_CASE("username", "[os]")
      48              : {
      49            1 :     CATCH_START_SECTION("username: convert a UID to a user name")
      50              :     {
      51              :         {
      52            1 :             std::string const root(snapdev::username(0));
      53            1 :             CATCH_REQUIRE(root == "root");
      54            1 :         }
      55              : 
      56              :         {
      57            1 :             char const * user(getenv("USER"));
      58            1 :             if(user != nullptr)
      59              :             {
      60            1 :                 std::string const name(snapdev::username());
      61            1 :                 CATCH_REQUIRE(name == user);
      62            1 :             }
      63              :         }
      64              :     }
      65            1 :     CATCH_END_SECTION()
      66            1 : }
      67              : 
      68              : 
      69            1 : CATCH_TEST_CASE("username_invalid", "[os][error]")
      70              : {
      71            1 :     CATCH_START_SECTION("username: convert a UID to a user name")
      72              :     {
      73            1 :         std::string const non_existant(snapdev::username(999999999));
      74            1 :         CATCH_REQUIRE(errno == ENOENT);
      75            1 :         CATCH_REQUIRE(non_existant.empty());
      76            1 :     }
      77            1 :     CATCH_END_SECTION()
      78            1 : }
      79              : 
      80              : 
      81              : 
      82              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

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