LCOV - code coverage report
Current view: top level - tests - catch_main.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 23.3 % 43 10
Test Date: 2025-06-19 11:28:46 Functions: 75.0 % 4 3
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              : // Tell catch we want it to add the runner code in this file.
      20              : #define CATCH_CONFIG_RUNNER
      21              : 
      22              : // self
      23              : //
      24              : #include    "catch_main.h"
      25              : 
      26              : 
      27              : // prinbee
      28              : //
      29              : #include    <prinbee/version.h>
      30              : 
      31              : 
      32              : // libexcept
      33              : //
      34              : #include    <libexcept/exception.h>
      35              : 
      36              : 
      37              : // snaplogger
      38              : //
      39              : #include    <snaplogger/logger.h>
      40              : 
      41              : 
      42              : // snapdev
      43              : //
      44              : #include    <snapdev/not_used.h>
      45              : 
      46              : 
      47              : // C++
      48              : //
      49              : #include    <fstream>
      50              : 
      51              : 
      52              : // C
      53              : //
      54              : #include    <sys/stat.h>
      55              : #include    <sys/types.h>
      56              : 
      57              : 
      58              : // last include
      59              : //
      60              : #include    <snapdev/poison.h>
      61              : 
      62              : 
      63              : 
      64              : namespace SNAP_CATCH2_NAMESPACE
      65              : {
      66              : 
      67              : 
      68              : 
      69              : 
      70              : 
      71            0 : std::string setup_context(std::string const & sub_path, std::vector<std::string> const & xmls)
      72              : {
      73            0 :     std::string path(g_tmp_dir() + "/" + sub_path);
      74              : 
      75            0 :     if(mkdir(path.c_str(), 0700) != 0)
      76              :     {
      77            0 :         if(errno != EEXIST)
      78              :         {
      79            0 :             CATCH_REQUIRE(!"could not create context path");
      80            0 :             return std::string();
      81              :         }
      82              :     }
      83              : 
      84            0 :     if(mkdir((path + "/tables").c_str(), 0700) != 0)
      85              :     {
      86            0 :         if(errno != EEXIST)
      87              :         {
      88            0 :             CATCH_REQUIRE(!"could not create table path");
      89            0 :             return std::string();
      90              :         }
      91              :     }
      92              : 
      93            0 :     if(mkdir((path + "/database").c_str(), 0700) != 0)
      94              :     {
      95            0 :         if(errno != EEXIST)
      96              :         {
      97            0 :             CATCH_REQUIRE(!"could not create database path");
      98            0 :             return std::string();
      99              :         }
     100              :     }
     101              : 
     102            0 :     for(auto const & x : xmls)
     103              :     {
     104            0 :         char const * s(x.c_str());
     105            0 :         CATCH_REQUIRE((s[0] == '<'
     106              :                     && s[1] == '!'
     107              :                     && s[2] == '-'
     108              :                     && s[3] == '-'
     109              :                     && s[4] == ' '
     110              :                     && s[5] == 'n'
     111              :                     && s[6] == 'a'
     112              :                     && s[7] == 'm'
     113              :                     && s[8] == 'e'
     114              :                     && s[9] == '='));
     115            0 :         s += 10;
     116            0 :         char const * e(s);
     117            0 :         while(*e != ' ')
     118              :         {
     119            0 :             ++e;
     120              :         }
     121            0 :         std::string const name(s, e - s);
     122              : 
     123            0 :         std::string const filename(path + "/tables/" + name + ".xml");
     124              :         {
     125            0 :             std::ofstream o(filename);
     126            0 :             o << x;
     127            0 :         }
     128              : 
     129              :         // the table.xsd must pass so we can make sure that our tests make
     130              :         // use of up to date XML code and that table.xsd is also up to date
     131              :         //
     132            0 :         std::string const verify_table("xmllint --noout --nonet --schema prinbee/data/tables.xsd " + filename);
     133            0 :         std::cout << "running: " << verify_table << std::endl;
     134            0 :         int const r(system(verify_table.c_str()));
     135            0 :         CATCH_REQUIRE(r == 0);
     136            0 :     }
     137              : 
     138            0 :     return path;
     139            0 : }
     140              : 
     141              : 
     142            2 : void init_callback()
     143              : {
     144            2 :     libexcept::set_collect_stack(libexcept::collect_stack_t::COLLECT_STACK_NO);
     145            2 : }
     146              : 
     147              : 
     148            1 : int init_tests(Catch::Session & session)
     149              : {
     150            1 :     snapdev::NOT_USED(session);
     151              : 
     152            1 :     snaplogger::setup_catch2_nested_diagnostics();
     153              : 
     154              :     //snaplogger::logger::pointer_t l(snaplogger::logger::get_instance());
     155              :     //l->add_console_appender();
     156              :     //l->set_severity(snaplogger::severity_t::SEVERITY_ALL);
     157              : 
     158              :     // to test that the logger works as expected
     159              :     //SNAP_LOG_ERROR
     160              :     //    << "This is an error through the logger..."
     161              :     //    << SNAP_LOG_SEND;
     162              : 
     163            1 :     return 0;
     164              : }
     165              : 
     166              : 
     167              : }
     168              : 
     169              : 
     170              : 
     171            2 : int main(int argc, char * argv[])
     172              : {
     173            2 :     return SNAP_CATCH2_NAMESPACE::snap_catch2_main(
     174              :               "prinbee"
     175              :             , PRINBEE_VERSION_STRING
     176              :             , argc
     177              :             , argv
     178              :             , SNAP_CATCH2_NAMESPACE::init_callback
     179              :             , nullptr
     180              :             , SNAP_CATCH2_NAMESPACE::init_tests
     181            2 :         );
     182              : }
     183              : 
     184              : 
     185              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

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