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 : // self
20 : //
21 : #include "catch_main.h"
22 :
23 :
24 : // prinbee
25 : //
26 : #include <prinbee/exception.h>
27 : #include <prinbee/data/dbtype.h>
28 :
29 :
30 : //// snapdev
31 : ////
32 : //#include <snapdev/hexadecimal_string.h>
33 : //#include <snapdev/math.h>
34 : //#include <snapdev/ostream_int128.h>
35 :
36 :
37 : //// C++
38 : ////
39 : //#include <fstream>
40 : //#include <iomanip>
41 :
42 :
43 : //// C
44 : ////
45 : //#include <sys/stat.h>
46 : //#include <sys/types.h>
47 :
48 :
49 : // last include
50 : //
51 : #include <snapdev/poison.h>
52 :
53 :
54 :
55 : namespace
56 : {
57 :
58 :
59 100 : bool is_valid_type(prinbee::dbtype_t type)
60 : {
61 100 : switch(type)
62 : {
63 0 : case prinbee::dbtype_t::DBTYPE_UNKNOWN:
64 : case prinbee::dbtype_t::FILE_TYPE_TABLE:
65 : case prinbee::dbtype_t::FILE_TYPE_INDEX:
66 : case prinbee::dbtype_t::FILE_TYPE_BLOOM_FILTER:
67 : case prinbee::dbtype_t::FILE_TYPE_SCHEMA:
68 : case prinbee::dbtype_t::FILE_TYPE_PRIMARY_INDEX:
69 : case prinbee::dbtype_t::FILE_TYPE_COMPLEX_TYPE:
70 : case prinbee::dbtype_t::BLOCK_TYPE_BLOB:
71 : case prinbee::dbtype_t::BLOCK_TYPE_DATA:
72 : case prinbee::dbtype_t::BLOCK_TYPE_ENTRY_INDEX:
73 : case prinbee::dbtype_t::BLOCK_TYPE_FREE_BLOCK:
74 : case prinbee::dbtype_t::BLOCK_TYPE_FREE_SPACE:
75 : case prinbee::dbtype_t::BLOCK_TYPE_INDEX_POINTERS:
76 : case prinbee::dbtype_t::BLOCK_TYPE_INDIRECT_INDEX:
77 : case prinbee::dbtype_t::BLOCK_TYPE_SECONDARY_INDEX:
78 : case prinbee::dbtype_t::BLOCK_TYPE_SCHEMA_LIST:
79 : case prinbee::dbtype_t::BLOCK_TYPE_TOP_INDEX:
80 : case prinbee::dbtype_t::BLOCK_TYPE_TOP_INDIRECT_INDEX:
81 0 : return true;
82 :
83 : }
84 :
85 100 : return false;
86 : }
87 :
88 :
89 :
90 : } // no name namespace
91 :
92 :
93 :
94 3 : CATCH_TEST_CASE("dbfile_dbtype", "[dbfile] [valid]")
95 : {
96 5 : CATCH_START_SECTION("dbfile_dbtype: to_name()")
97 : {
98 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::DBTYPE_UNKNOWN)) == "Unknown");
99 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::FILE_TYPE_TABLE)) == "Prinbee Table (PTBL)");
100 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::FILE_TYPE_INDEX)) == "Index (INDX)");
101 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::FILE_TYPE_BLOOM_FILTER)) == "Bloom Filter (BLMF)");
102 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::FILE_TYPE_PRIMARY_INDEX)) == "Primary Index (PIDX)");
103 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::FILE_TYPE_SCHEMA)) == "Schema (SCHM)");
104 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::FILE_TYPE_COMPLEX_TYPE)) == "Complex Type (CXTP)");
105 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_BLOB)) == "Blob (BLOB)");
106 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_DATA)) == "Data (DATA)");
107 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_ENTRY_INDEX)) == "Entry Index (EIDX)");
108 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_FREE_BLOCK)) == "Free Block (FREE)");
109 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_FREE_SPACE)) == "Free Space (FSPC)");
110 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_INDEX_POINTERS)) == "Index Pointer (IDXP)");
111 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_INDIRECT_INDEX)) == "Indirect Index (INDR)");
112 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_SECONDARY_INDEX)) == "Secondary Index (SIDX)");
113 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_SCHEMA_LIST)) == "Schema List (SCHL)");
114 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_TOP_INDEX)) == "Top Index (TIDX)");
115 3 : CATCH_REQUIRE(std::string(prinbee::to_name(prinbee::dbtype_t::BLOCK_TYPE_TOP_INDIRECT_INDEX)) == "Top Indirect Index (TIND)");
116 : }
117 4 : CATCH_END_SECTION()
118 :
119 5 : CATCH_START_SECTION("dbfile_dbtype: to_string()")
120 : {
121 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::DBTYPE_UNKNOWN)) == "????");
122 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::FILE_TYPE_TABLE)) == "PTBL");
123 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::FILE_TYPE_INDEX)) == "INDX");
124 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::FILE_TYPE_BLOOM_FILTER)) == "BLMF");
125 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::FILE_TYPE_PRIMARY_INDEX)) == "PIDX");
126 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::FILE_TYPE_SCHEMA)) == "SCHM");
127 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::FILE_TYPE_COMPLEX_TYPE)) == "CXTP");
128 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_BLOB)) == "BLOB");
129 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_DATA)) == "DATA");
130 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_ENTRY_INDEX)) == "EIDX");
131 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_FREE_BLOCK)) == "FREE");
132 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_FREE_SPACE)) == "FSPC");
133 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_INDEX_POINTERS)) == "IDXP");
134 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_INDIRECT_INDEX)) == "INDR");
135 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_SECONDARY_INDEX)) == "SIDX");
136 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_SCHEMA_LIST)) == "SCHL");
137 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_TOP_INDEX)) == "TIDX");
138 3 : CATCH_REQUIRE(std::string(prinbee::to_string(prinbee::dbtype_t::BLOCK_TYPE_TOP_INDIRECT_INDEX)) == "TIND");
139 : }
140 4 : CATCH_END_SECTION()
141 :
142 5 : CATCH_START_SECTION("dbfile_dbtype: to_string() -- invalid types")
143 : {
144 : // anything else is an invalid type
145 : //
146 101 : for(int i(0); i < 100; ++i)
147 : {
148 100 : prinbee::dbtype_t type(prinbee::dbtype_t::DBTYPE_UNKNOWN);
149 : do
150 : {
151 100 : type = static_cast<prinbee::dbtype_t>(SNAP_CATCH2_NAMESPACE::rand32());
152 : }
153 100 : while(is_valid_type(type));
154 :
155 300 : CATCH_REQUIRE(std::string(prinbee::to_name(type)) == "Invalid");
156 300 : CATCH_REQUIRE(std::string(prinbee::to_string(type)) == "INVL");
157 : }
158 : }
159 4 : CATCH_END_SECTION()
160 3 : }
161 :
162 :
163 :
164 :
165 : // vim: ts=4 sw=4 et
|