LCOV - code coverage report
Current view: top level - tests - locked_node.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 30 70.0 %
Date: 2023-07-29 22:00:24 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2011-2023  Made to Order Software Corp.  All Rights Reserved
       2             : //
       3             : // https://snapwebsites.org/project/as2js
       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             : // as2js
      20             : //
      21             : #include    <as2js/node.h>
      22             : 
      23             : 
      24             : // snapdev
      25             : //
      26             : #include    <snapdev/not_used.h>
      27             : 
      28             : 
      29             : // C++
      30             : //
      31             : #include    <cstring>
      32             : 
      33             : 
      34             : // C
      35             : //
      36             : #include    <signal.h>
      37             : #include    <unistd.h>
      38             : 
      39             : 
      40             : // last include
      41             : //
      42             : #include    <snapdev/poison.h>
      43             : 
      44             : 
      45             : 
      46             : 
      47           1 : void sig_abort(int sig)
      48             : {
      49           1 :     snapdev::NOT_USED(sig);
      50             : 
      51             :     // printing inside a signal is often asking for trouble...
      52             :     // but since this process is really simple I do it anyway
      53           1 :     std::cerr << "as2js: node lock/unlock aborted\n";
      54           1 :     exit(1);
      55             : }
      56             : 
      57             : 
      58           2 : int main(int argc, char * argv[])
      59             : {
      60           2 :     bool do_unlock(true);
      61           3 :     for(int i(1); i < argc; ++i)
      62             :     {
      63           1 :         if(argv[i][0] == '-')
      64             :         {
      65           1 :             std::size_t const max(strlen(argv[i]));
      66           2 :             for(std::size_t j(1); j < max; ++j)
      67             :             {
      68           1 :                 if(argv[i][j] == 'h')
      69             :                 {
      70             :                     std::cout << "Usage: locked-node [-h | -u]\n"
      71             :                                  "where:\n"
      72             :                                  "  -h     prints out this help screen.\n"
      73           0 :                                  "  -u     create a node, lock it and then delete it which must fail; without -u, make sure to unlock first.\n";
      74           0 :                     exit(1);
      75             :                 }
      76           1 :                 else if(argv[i][j] == 'u')
      77             :                 {
      78           1 :                     do_unlock = false;
      79             :                 }
      80             :                 else
      81             :                 {
      82             :                     std::cerr << "error: unsupported command line parameter \"-"
      83           0 :                         << argv[i][j]
      84           0 :                         << "\", try -h.\n";
      85           0 :                     exit(1);
      86             :                 }
      87             :             }
      88             :         }
      89             :         else
      90             :         {
      91             :             std::cerr << "error: unsupported command line parameter \""
      92           0 :                 << argv[i]
      93           0 :                 << "\", try -h.\n";
      94           0 :             exit(1);
      95             :         }
      96             :     }
      97             : 
      98           2 :     signal(SIGABRT, sig_abort);
      99             : 
     100             :     // TODO: give user a way to set the node type
     101             :     //
     102           2 :     as2js::node::pointer_t node(std::make_shared<as2js::node>(as2js::node_t::NODE_INTEGER));
     103           2 :     node->lock();
     104           2 :     if(do_unlock)
     105             :     {
     106           1 :         node->unlock();
     107             :     }
     108             : 
     109             :     // without the unlock this calls std::terminate()
     110             :     //
     111           2 :     node.reset();
     112             : 
     113           1 :     std::cout << "as2js: node lock/unlock success" << std::endl;
     114           1 :     exit(0);
     115           0 : }
     116             : 
     117             : 
     118             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14