LCOV - code coverage report
Current view: top level - tests - catch_pbql_location.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 43 43
Test Date: 2025-06-19 11:28:46 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2019-2025  Made to Order Software Corp.  All Rights Reserved
       2              : //
       3              : // https://snapwebsites.org/project/prinbee
       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              : // prinbee
      20              : //
      21              : #include    <prinbee/pbql/location.h>
      22              : 
      23              : 
      24              : 
      25              : // self
      26              : //
      27              : #include    "catch_main.h"
      28              : 
      29              : 
      30              : // snaplogger
      31              : //
      32              : #include    <snaplogger/message.h>
      33              : 
      34              : 
      35              : // last include
      36              : //
      37              : #include    <snapdev/poison.h>
      38              : 
      39              : 
      40              : 
      41            3 : CATCH_TEST_CASE("location", "[location] [pbql]")
      42              : {
      43            5 :     CATCH_START_SECTION("location: verify defaults")
      44              :     {
      45            1 :         prinbee::pbql::location l;
      46              : 
      47            1 :         CATCH_REQUIRE(l.get_filename() == std::string());
      48            1 :         CATCH_REQUIRE(l.get_column() == 1);
      49            1 :         CATCH_REQUIRE(l.get_line() == 1);
      50              : 
      51            1 :         CATCH_REQUIRE(l.get_location() == "1:1: ");
      52            1 :     }
      53            4 :     CATCH_END_SECTION()
      54              : 
      55            5 :     CATCH_START_SECTION("location: verify filename")
      56              :     {
      57            1 :         prinbee::pbql::location l;
      58              : 
      59            1 :         CATCH_REQUIRE(l.get_filename() == std::string());
      60           11 :         for(int i(0); i < 10; ++i)
      61              :         {
      62           10 :             std::string const filename(SNAP_CATCH2_NAMESPACE::random_string(1, 25));
      63           10 :             l.set_filename(filename);
      64           10 :             CATCH_REQUIRE(l.get_filename() == filename);
      65           10 :             CATCH_REQUIRE(l.get_location() == filename + ":1:1: ");
      66           10 :         }
      67            1 :     }
      68            4 :     CATCH_END_SECTION()
      69              : 
      70            5 :     CATCH_START_SECTION("location: verify columns & lines")
      71              :     {
      72           11 :         for(int i(0); i < 10; ++i)
      73              :         {
      74           10 :             prinbee::pbql::location l;
      75           10 :             std::string const filename(SNAP_CATCH2_NAMESPACE::random_string(1, 25));
      76           10 :             l.set_filename(filename);
      77              : 
      78           10 :             unsigned int lines(0);
      79           10 :             SNAP_CATCH2_NAMESPACE::random(lines);
      80           10 :             lines = (lines % 1000) + 10;
      81         5352 :             for(unsigned int y(0); y < lines; ++y)
      82              :             {
      83         5342 :                 unsigned int columns(0);
      84         5342 :                 SNAP_CATCH2_NAMESPACE::random(columns);
      85         5342 :                 columns = (columns % 1000) + 10;
      86      2778470 :                 for(unsigned int x(0); x < columns; ++x)
      87              :                 {
      88      2773128 :                     l.next_column();
      89      2773128 :                     CATCH_REQUIRE(l.get_column() == static_cast<int>(x + 2));
      90              : 
      91      2773128 :                     CATCH_REQUIRE(l.get_location() == filename + ":" + std::to_string(y + 1) + ":" + std::to_string(x + 2) + ": ");
      92              :                 }
      93         5342 :                 l.next_line();
      94         5342 :                 CATCH_REQUIRE(l.get_line() == static_cast<int>(y + 2));
      95         5342 :                 CATCH_REQUIRE(l.get_column() == 1);
      96              : 
      97         5342 :                 CATCH_REQUIRE(l.get_location() == filename + ":" + std::to_string(y + 2) + ":1: ");
      98              :             }
      99           10 :         }
     100              :     }
     101            4 :     CATCH_END_SECTION()
     102            3 : }
     103              : 
     104              : 
     105              : 
     106              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

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