LCOV - code coverage report
Current view: top level - tests - catch_main.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 46 28.3 %
Date: 2024-02-03 18:59:18 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2019-2024  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             : 
      59             : namespace SNAP_CATCH2_NAMESPACE
      60             : {
      61             : 
      62             : 
      63             : 
      64             : 
      65             : 
      66           0 : std::string setup_context(std::string const & sub_path, std::vector<std::string> const & xmls)
      67             : {
      68           0 :     std::string path(g_tmp_dir() + "/" + sub_path);
      69             : 
      70           0 :     if(mkdir(path.c_str(), 0700) != 0)
      71             :     {
      72           0 :         if(errno != EEXIST)
      73             :         {
      74           0 :             CATCH_REQUIRE(!"could not create context path");
      75           0 :             return std::string();
      76             :         }
      77             :     }
      78             : 
      79           0 :     if(mkdir((path + "/tables").c_str(), 0700) != 0)
      80             :     {
      81           0 :         if(errno != EEXIST)
      82             :         {
      83           0 :             CATCH_REQUIRE(!"could not create table path");
      84           0 :             return std::string();
      85             :         }
      86             :     }
      87             : 
      88           0 :     if(mkdir((path + "/database").c_str(), 0700) != 0)
      89             :     {
      90           0 :         if(errno != EEXIST)
      91             :         {
      92           0 :             CATCH_REQUIRE(!"could not create database path");
      93           0 :             return std::string();
      94             :         }
      95             :     }
      96             : 
      97           0 :     for(auto const & x : xmls)
      98             :     {
      99           0 :         char const * s(x.c_str());
     100           0 :         CATCH_REQUIRE((s[0] == '<'
     101             :                     && s[1] == '!'
     102             :                     && s[2] == '-'
     103             :                     && s[3] == '-'
     104             :                     && s[4] == ' '
     105             :                     && s[5] == 'n'
     106             :                     && s[6] == 'a'
     107             :                     && s[7] == 'm'
     108             :                     && s[8] == 'e'
     109             :                     && s[9] == '='));
     110           0 :         s += 10;
     111           0 :         char const * e(s);
     112           0 :         while(*e != ' ')
     113             :         {
     114           0 :             ++e;
     115             :         }
     116           0 :         std::string const name(s, e - s);
     117             : 
     118           0 :         std::string const filename(path + "/tables/" + name + ".xml");
     119             :         {
     120           0 :             std::ofstream o(filename);
     121           0 :             o << x;
     122           0 :         }
     123             : 
     124             :         // the table.xsd must pass so we can make sure that our tests make
     125             :         // use of up to date XML code and that table.xsd is also up to date
     126             :         //
     127           0 :         std::string const verify_table("xmllint --noout --nonet --schema prinbee/data/tables.xsd " + filename);
     128           0 :         std::cout << "running: " << verify_table << std::endl;
     129           0 :         int const r(system(verify_table.c_str()));
     130           0 :         CATCH_REQUIRE(r == 0);
     131           0 :     }
     132             : 
     133           0 :     return path;
     134           0 : }
     135             : 
     136             : 
     137           2 : void init_callback()
     138             : {
     139           2 :     libexcept::set_collect_stack(libexcept::collect_stack_t::COLLECT_STACK_NO);
     140           2 : }
     141             : 
     142             : 
     143           1 : int init_tests(Catch::Session & session)
     144             : {
     145           1 :     snapdev::NOT_USED(session);
     146             : 
     147           1 :     snaplogger::logger::pointer_t l(snaplogger::logger::get_instance());
     148           1 :     l->add_console_appender();
     149           1 :     l->set_severity(snaplogger::severity_t::SEVERITY_ALL);
     150             : 
     151             :     // to test that the logger works as expected
     152             :     //SNAP_LOG_ERROR
     153             :     //    << "This is an error through the logger..."
     154             :     //    << SNAP_LOG_SEND;
     155             : 
     156           1 :     return 0;
     157           1 : }
     158             : 
     159             : 
     160             : }
     161             : 
     162             : 
     163             : 
     164           2 : int main(int argc, char * argv[])
     165             : {
     166           2 :     return SNAP_CATCH2_NAMESPACE::snap_catch2_main(
     167             :               "prinbee"
     168             :             , PRINBEE_VERSION_STRING
     169             :             , argc
     170             :             , argv
     171             :             , SNAP_CATCH2_NAMESPACE::init_callback
     172             :             , nullptr
     173             :             , SNAP_CATCH2_NAMESPACE::init_tests
     174           2 :         );
     175             : }
     176             : 
     177             : 
     178             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

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