Line data Source code
1 : // Copyright (c) 2019 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/snapdatabase
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 2 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 along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 :
20 : // self
21 : //
22 : #include "main.h"
23 :
24 :
25 : // snapdatabase lib
26 : //
27 : #include <snapdatabase/database/context.h>
28 :
29 :
30 : // advgetopt lib
31 : //
32 : #include <advgetopt/options.h>
33 :
34 :
35 :
36 :
37 3 : CATCH_TEST_CASE("Context", "[centext]")
38 : {
39 2 : CATCH_START_SECTION("create a context")
40 : {
41 : std::vector<std::string> const simple_context =
42 : {
43 : {
44 : "<!-- name=simple-context -->"
45 : "<context>"
46 : "<table name='foo' sparse='sparse'>" // model="..." row-key="..." drop="..." temporary="..." sparse="..." secure="...">
47 : "<block-size>4096</block-size>"
48 : "<description>Create a Context</description>"
49 : "<schema>"
50 : "<column name='c1' type='uint16'>" // limited="..." encrypt="..." required="..." blob="...">
51 : "<description>column 1</description>"
52 : "<external>1Mb</external>"
53 : "<default>55</default>"
54 : "<min-value>0</min-value>"
55 : "<max-value>100</max-value>"
56 : "<min-length>1</min-length>"
57 : "<max-length>10</max-length>"
58 : "<validation>c1 > c2</validation>"
59 : "</column>"
60 : "<column name='c2' type='int16'>" // limited="..." encrypt="..." required="..." blob="...">
61 : "<description>column 2</description>"
62 : "<external>1Mb</external>"
63 : "<default>-37</default>"
64 : "<min-value>-100</min-value>"
65 : "<max-value>100</max-value>"
66 : "<min-length>5</min-length>"
67 : "<max-length>25</max-length>"
68 : "</column>"
69 : "</schema>"
70 : "</table>"
71 : "</context>"
72 : }
73 2 : };
74 :
75 2 : std::string const created(SNAP_CATCH2_NAMESPACE::setup_context("simple-context", simple_context));
76 1 : CATCH_REQUIRE(!created.empty());
77 1 : if(created.empty())
78 : {
79 0 : return;
80 : }
81 :
82 2 : std::string database_path(created + "/database");
83 2 : std::string tables_path(created + "/tables");
84 :
85 1 : advgetopt::option options[] =
86 : {
87 : advgetopt::define_option(
88 : advgetopt::Name("context")
89 : , advgetopt::Flags(advgetopt::standalone_all_flags<
90 : advgetopt::GETOPT_FLAG_GROUP_OPTIONS>())
91 : , advgetopt::Help("context is mandatory")
92 : //, advgetopt::DefaultValue(database_path.c_str())
93 : ),
94 : advgetopt::define_option(
95 : advgetopt::Name("table-schema-path")
96 : , advgetopt::Flags(advgetopt::command_flags<
97 : advgetopt::GETOPT_FLAG_GROUP_OPTIONS
98 : , advgetopt::GETOPT_FLAG_REQUIRED
99 : , advgetopt::GETOPT_FLAG_MULTIPLE>())
100 : , advgetopt::Help("path to the list of table schemas is mandatory")
101 : ),
102 : advgetopt::end_options()
103 : };
104 :
105 1 : options[0].f_default = database_path.c_str();
106 :
107 : // TODO: once we have stdc++20, remove all defaults
108 : #pragma GCC diagnostic push
109 : #pragma GCC diagnostic ignored "-Wpedantic"
110 1 : advgetopt::options_environment const options_environment =
111 : {
112 : .f_project_name = "database",
113 : .f_options = options,
114 1 : };
115 : #pragma GCC diagnostic pop
116 :
117 1 : char const * cargv[] =
118 : {
119 : "/usr/bin/xontext",
120 : "--table-schema-path",
121 1 : tables_path.c_str(),
122 : nullptr
123 1 : };
124 1 : int const argc(sizeof(cargv) / sizeof(cargv[0]) - 1);
125 1 : char ** argv = const_cast<char **>(cargv);
126 :
127 2 : advgetopt::getopt::pointer_t opt(std::make_shared<advgetopt::getopt>(options_environment, argc, argv));
128 1 : snapdatabase::context::pointer_t context(snapdatabase::context::get_context(opt));
129 : }
130 : CATCH_END_SECTION()
131 6 : }
132 :
133 :
134 : // vim: ts=4 sw=4 et
|