LCOV - code coverage report
Current view: top level - tests - catch_context.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-02-03 18:59:18 Functions: 1 1 100.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             : // self
      20             : //
      21             : #include    "catch_main.h"
      22             : 
      23             : 
      24             : // prinbee
      25             : //
      26             : #include    <prinbee/database/context.h>
      27             : #include    <prinbee/database/row.h>
      28             : 
      29             : 
      30             : // advgetopt
      31             : //
      32             : #include    <advgetopt/options.h>
      33             : 
      34             : 
      35             : // C
      36             : //
      37             : #include    <grp.h>
      38             : #include    <pwd.h>
      39             : 
      40             : 
      41             : 
      42           1 : CATCH_TEST_CASE("Context", "[centext]")
      43             : {
      44             : // TODO: fix this test at some point
      45             : 
      46           1 : std::cerr << "error: ... test not working at the moment ...\n";
      47             : 
      48           1 :     CATCH_REQUIRE(true);
      49             : 
      50             : //    CATCH_START_SECTION("create a context")
      51             : //    {
      52             : //        std::vector<std::string> const simple_context =
      53             : //            {
      54             : //                {
      55             : //                    "<!-- name=simple-context -->\n"
      56             : //                    "<context>\n"
      57             : //                      "<table name='foo' sparse='sparse' model='queue' row-key='c2,c1'>\n" // drop="..." temporary="..." secure="...">
      58             : //                        "<block-size>4096</block-size>\n"
      59             : //                        "<description>Create a Context</description>\n"
      60             : //                        "<schema>\n"
      61             : //                          "<column name='c1' type='uint16'>\n" // limited="..." encrypt="..." required="..." blob="...">
      62             : //                            "<description>column 1</description>\n"
      63             : //                            "<external>1Mb</external>\n"
      64             : //                            "<default>55</default>\n"
      65             : //                            "<min-value>0</min-value>\n"
      66             : //                            "<max-value>100</max-value>\n"
      67             : //                            "<min-length>1</min-length>\n"
      68             : //                            "<max-length>10</max-length>\n"
      69             : //                            "<validation>c1 &gt; c2</validation>\n"
      70             : //                          "</column>\n"
      71             : //                          "<column name='c2' type='int16' required='required'>\n" // limited="..." encrypt="..." blob="...">
      72             : //                            "<description>column 2</description>\n"
      73             : //                            "<external>1Mb</external>\n"
      74             : //                            "<default>-37</default>\n"
      75             : //                            "<min-value>-100</min-value>\n"
      76             : //                            "<max-value>100</max-value>\n"
      77             : //                            "<min-length>5</min-length>\n"
      78             : //                            "<max-length>25</max-length>\n"
      79             : //                          "</column>\n"
      80             : //                          "<column name='c3' type='uint64'>\n" // limited="..." encrypt="..." required="..." blob="...">
      81             : //                            "<description>column 3</description>\n"
      82             : //                            "<default>0</default>\n"
      83             : //                          "</column>\n"
      84             : //                        "</schema>\n"
      85             : //                        "<secondary-index name='created_on'>\n"
      86             : //                          "<order>\n"
      87             : //                            "<column-name name='_created_on' direction='desc'/>\n"
      88             : //                            "<column-name name='c2'>c2 * 16 + rand() % 16</column-name>\n"
      89             : //                            "<column-name name='c1' not-null='not-null'/>\n"
      90             : //                          "</order>\n"
      91             : //                          "<filter>c3 > 100</filter>\n"
      92             : //                        "</secondary-index>\n"
      93             : //                        "<secondary-index name='priority'>\n"
      94             : //                          "<order>\n"
      95             : //                            "<column-name name='c3'/>\n"
      96             : //                            "<column-name name='_created_on' direction='desc'>_created_on + c2</column-name>\n"
      97             : //                            "<column-name name='_deleted_on' not-null='null'/>\n"
      98             : //                          "</order>\n"
      99             : //                          "<filter>c3 &gt; 100</filter>\n"
     100             : //                        "</secondary-index>\n"
     101             : //                      "</table>\n"
     102             : //                    "</context>\n"
     103             : //                }
     104             : //            };
     105             : //
     106             : //        std::string const created(SNAP_CATCH2_NAMESPACE::setup_context("simple-context", simple_context));
     107             : //        CATCH_REQUIRE_FALSE(created.empty());
     108             : //        if(created.empty())
     109             : //        {
     110             : //            return;
     111             : //        }
     112             : //
     113             : //        std::string database_path(created + "/database");
     114             : //        std::string tables_path(created + "/tables");
     115             : //
     116             : //        // for the tests the default user/group name is the running user
     117             : //        //
     118             : //        struct passwd const * user(getpwuid(getuid()));
     119             : //        struct group const * group(getgrgid(getgid()));
     120             : //
     121             : //        advgetopt::option options[] =
     122             : //        {
     123             : //            advgetopt::define_option(
     124             : //                  advgetopt::Name("context")
     125             : //                , advgetopt::Flags(advgetopt::standalone_all_flags<
     126             : //                              advgetopt::GETOPT_FLAG_GROUP_OPTIONS>())
     127             : //                , advgetopt::Help("context is mandatory")
     128             : //                //, advgetopt::DefaultValue(database_path.c_str())
     129             : //            ),
     130             : //            advgetopt::define_option(
     131             : //                  advgetopt::Name("user")
     132             : //                , advgetopt::Flags(advgetopt::standalone_all_flags<
     133             : //                              advgetopt::GETOPT_FLAG_GROUP_OPTIONS>())
     134             : //                , advgetopt::Help("user name for the database directory")
     135             : //                , advgetopt::DefaultValue(user->pw_name)
     136             : //            ),
     137             : //            advgetopt::define_option(
     138             : //                  advgetopt::Name("group")
     139             : //                , advgetopt::Flags(advgetopt::standalone_all_flags<
     140             : //                              advgetopt::GETOPT_FLAG_GROUP_OPTIONS>())
     141             : //                , advgetopt::Help("group name for the database directory")
     142             : //                , advgetopt::DefaultValue(group->gr_name)
     143             : //            ),
     144             : //            advgetopt::define_option(
     145             : //                  advgetopt::Name("table-schema-path")
     146             : //                , advgetopt::Flags(advgetopt::command_flags<
     147             : //                              advgetopt::GETOPT_FLAG_GROUP_OPTIONS
     148             : //                            , advgetopt::GETOPT_FLAG_REQUIRED
     149             : //                            , advgetopt::GETOPT_FLAG_MULTIPLE>())
     150             : //                , advgetopt::Help("path to the list of table schemata is mandatory")
     151             : //            ),
     152             : //            advgetopt::end_options()
     153             : //        };
     154             : //
     155             : //        options[0].f_default = database_path.c_str();
     156             : //
     157             : //        // TODO: once we have stdc++20, remove all defaults
     158             : //#pragma GCC diagnostic push
     159             : //#pragma GCC diagnostic ignored "-Wpedantic"
     160             : //        advgetopt::options_environment const options_environment =
     161             : //        {
     162             : //            .f_project_name = "database",
     163             : //            .f_group_name = nullptr,
     164             : //            .f_options = options,
     165             : //        };
     166             : //#pragma GCC diagnostic pop
     167             : //
     168             : //        char const * cargv[] =
     169             : //        {
     170             : //            "/usr/bin/xontext",
     171             : //            "--table-schema-path",
     172             : //            tables_path.c_str(),
     173             : //            nullptr
     174             : //        };
     175             : //        int const argc(sizeof(cargv) / sizeof(cargv[0]) - 1);
     176             : //        char ** argv = const_cast<char **>(cargv);
     177             : //
     178             : //        advgetopt::getopt::pointer_t opt(std::make_shared<advgetopt::getopt>(options_environment, argc, argv));
     179             : //        prinbee::context::pointer_t context(prinbee::context::create_context(opt));
     180             : //
     181             : //        // make sure to reset before creating a new version otherwise
     182             : //        // we would have two contexts open simultaneously
     183             : //        //
     184             : //        context.reset();
     185             : //
     186             : //        // try again, this time we hit the schema compare functionality
     187             : //        // (i.e. the file already exists)
     188             : //        //
     189             : //        context = prinbee::context::create_context(opt);
     190             : //
     191             : //        prinbee::table::pointer_t table(context->get_table("wrong_name"));
     192             : //        CATCH_REQUIRE(table == nullptr);
     193             : //
     194             : //        table = context->get_table("foo");
     195             : //        CATCH_REQUIRE(table != nullptr);
     196             : //
     197             : //        struct row_data_t
     198             : //        {
     199             : //            typedef std::vector<row_data_t> vector_t;
     200             : //
     201             : //            std::uint16_t       f_c1 = 0;
     202             : //            std::int16_t        f_c2 = 0;
     203             : //            std::uint64_t       f_c3 = 0;
     204             : //        };
     205             : //        row_data_t::vector_t row_data;
     206             : //
     207             : //        //for(int count(0); count < 580; ++count)
     208             : //        //for(int count(0); count < 163; ++count)
     209             : //        for(int count(0); count < 31; ++count)
     210             : //        {
     211             : //std::cerr << "+++ row count = " << count << "\n";
     212             : //            prinbee::row::pointer_t row(table->row_new());
     213             : //
     214             : //            prinbee::cell::pointer_t c1(row->get_cell("c1", true));
     215             : //            std::uint16_t const c1_value(rand() & 0xFFFF);
     216             : //            c1->set_uint16(c1_value);
     217             : //
     218             : //            prinbee::cell::pointer_t c2(row->get_cell("c2", true));
     219             : //            std::int16_t const c2_value(rand() & 0xFFFF);
     220             : //            c2->set_int16(c2_value);
     221             : //
     222             : //            prinbee::cell::pointer_t c3(row->get_cell("c3", true));
     223             : //            std::uint64_t c3_value(static_cast<std::uint64_t>(rand()) ^ (static_cast<std::uint64_t>(rand()) << 32));
     224             : //            c3_value &= -256;
     225             : //            c3_value |= count + 1;
     226             : //            c3->set_uint64(c3_value);
     227             : //
     228             : //            row_data_t data;
     229             : //            data.f_c1 = c1_value;
     230             : //            data.f_c2 = c2_value;
     231             : //            data.f_c3 = c3_value;
     232             : //            row_data.push_back(data);
     233             : //
     234             : //std::cerr << "---------------------- INSERT ROW\n";
     235             : //            table->row_insert(row);
     236             : //
     237             : //            // now verify that this and all the previous inserts worked
     238             : //            // and all the data is still accessible
     239             : //            //
     240             : //            // the indexes vector is used to search for each row in a
     241             : //            // random order instead of first to last
     242             : //            //
     243             : //            std::vector<int> indexes;
     244             : //            for(size_t p(0); p < row_data.size(); ++p)
     245             : //            {
     246             : //                indexes.push_back(p);
     247             : //            }
     248             : //            for(size_t p(0); p < row_data.size(); ++p)
     249             : //            {
     250             : //                size_t const q(rand() % row_data.size());
     251             : //                std::swap(indexes[p], indexes[q]);
     252             : //            }
     253             : //std::cerr << "---------------------- VERIFY " << row_data.size() << " ROWS\n";
     254             : //            for(size_t p(0); p < row_data.size(); ++p)
     255             : //            {
     256             : //                row_data_t & d(row_data[indexes[p]]);
     257             : //
     258             : //                prinbee::conditions cond;
     259             : //                cond.set_columns({"c1", "c2", "c3"});
     260             : //                prinbee::row::pointer_t key(table->row_new());
     261             : //                prinbee::cell::pointer_t c2_key(key->get_cell("c2", true));
     262             : //                c2_key->set_int16(d.f_c2);
     263             : //                prinbee::cell::pointer_t c1_key(key->get_cell("c1", true));
     264             : //                c1_key->set_uint16(d.f_c1);
     265             : //                cond.set_key("primary", key, prinbee::row::pointer_t());
     266             : //
     267             : //std::cerr << "---------------------- READ ROW: " << d.f_c2 << ", " << d.f_c1 << "\n";
     268             : //                prinbee::cursor::pointer_t cursor(table->row_select(cond));
     269             : //                prinbee::row::pointer_t r(cursor->next_row());
     270             : //                CATCH_REQUIRE(r != nullptr);
     271             : //                prinbee::cell::pointer_t c1_data(r->get_cell("c1", false));
     272             : //                CATCH_REQUIRE(c1_data != nullptr);
     273             : //                CATCH_REQUIRE(c1_data->get_uint16() == d.f_c1);
     274             : //                prinbee::cell::pointer_t c2_data(r->get_cell("c2", false));
     275             : //                CATCH_REQUIRE(c2_data != nullptr);
     276             : //                CATCH_REQUIRE(c2_data->get_int16() == d.f_c2);
     277             : //                prinbee::cell::pointer_t c3_data(r->get_cell("c3", false));
     278             : //                CATCH_REQUIRE(c3_data != nullptr);
     279             : //                CATCH_REQUIRE(c3_data->get_uint64() == d.f_c3);
     280             : //
     281             : //                // only one primary row with a specific key
     282             : //                //
     283             : //std::cerr << "---------------------- VERIFY UNIQUE ROW\n";
     284             : //                int const max(rand() % 3 + 1);
     285             : //                for(int i(0); i < max; ++i)
     286             : //                {
     287             : //                    CATCH_REQUIRE(cursor->next_row() == nullptr);
     288             : //                }
     289             : //            }
     290             : //        }
     291             : //
     292             : //        context.reset();
     293             : //    }
     294             : //    CATCH_END_SECTION()
     295           1 : }
     296             : 
     297             : 
     298             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.14

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