Merge lp:~pblokus/drizzle/unittests-plugin-interfaces into lp:~drizzle-trunk/drizzle/development
- unittests-plugin-interfaces
- Merge into development
Proposed by
Paul Blokus
Status: | Work in progress |
---|---|
Proposed branch: | lp:~pblokus/drizzle/unittests-plugin-interfaces |
Merge into: | lp:~drizzle-trunk/drizzle/development |
Diff against target: |
5361 lines (+4432/-323) 43 files modified
drizzled/charset.h (+0/-29) drizzled/plugin/error_message.cc (+2/-0) drizzled/plugin/event_observer.h (+6/-3) drizzled/plugin/listen.cc (+5/-0) drizzled/plugin/schema_engine.cc (+0/-5) drizzled/plugin/storage_engine.cc (+3/-12) drizzled/plugin/storage_engine.h (+1/-2) drizzled/plugin/table_function.h (+0/-4) drizzled/plugin/xa_resource_manager.cc (+1/-1) drizzled/plugin/xa_resource_manager.h (+4/-0) drizzled/table_proto_write.cc (+60/-97) drizzled/table_share.cc (+19/-22) drizzled/table_share.h (+2/-1) unittests/generator.cc (+61/-0) unittests/generator.h (+48/-0) unittests/include.am (+45/-20) unittests/plugin/authentication_test.cc (+7/-13) unittests/plugin/authorization_test.cc (+155/-0) unittests/plugin/error_message_test.cc (+47/-0) unittests/plugin/event_observer_test.cc (+306/-0) unittests/plugin/function_test.cc (+84/-0) unittests/plugin/listen_tcp_test.cc (+1/-0) unittests/plugin/listen_test.cc (+86/-0) unittests/plugin/logging_test.cc (+91/-0) unittests/plugin/plugin_stubs.h (+553/-100) unittests/plugin/query_cache_test.cc (+138/-0) unittests/plugin/query_rewrite_test.cc (+47/-0) unittests/plugin/scheduler_test.cc (+103/-0) unittests/plugin/schema_engine_test.cc (+152/-0) unittests/plugin/storage_engine_test.cc (+215/-0) unittests/plugin/table_function_test.cc (+242/-0) unittests/plugin/transaction_applier_test.cc (+1/-0) unittests/plugin/transaction_replicator_test.cc (+1/-0) unittests/plugin/transactional_storage_engine_test.cc (+68/-0) unittests/plugin/xa_resource_manager_test.cc (+97/-0) unittests/plugin/xa_storage_engine_test.cc (+1/-0) unittests/stubs.cc (+31/-0) unittests/stubs.h (+46/-0) unittests/table_identifier_test.cc (+415/-0) unittests/table_list_test.cc (+404/-0) unittests/table_share_test.cc (+872/-0) unittests/temporal_generator.h (+5/-5) unittests/temporal_interval_test.cc (+7/-9) |
To merge this branch: | bzr merge lp:~pblokus/drizzle/unittests-plugin-interfaces |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Monty Taylor | Needs Fixing | ||
Drizzle Merge Team | Pending | ||
Review via email: mp+32727@code.launchpad.net |
Commit message
Description of the change
Second portion of unit tests, last during GSoC.
I left some fails after the latest merge tests because I didn't know whether they were fixes or unintended changes.
To post a comment you must log in.
Unmerged revisions
- 1490. By Paweł Blokus <pawel@pawel-desktop>
-
fixes after merge to obvious test fails, the rest is left unchanged
- 1489. By Paweł Blokus <pawel@pawel-desktop>
-
merged latest trunk
- 1488. By Paweł Blokus <pawel@pawel-desktop>
-
added missing files
- 1487. By Paweł Blokus <pawel@pawel-desktop>
-
fixed some tests failing after last merge, left those which I was not sure about
- 1486. By Paweł Blokus <pawel@pawel-desktop>
-
fixed style of assign operator usages
moved stubs to seperate file - 1485. By Paweł Blokus <pawel@pawel-desktop>
-
fieldInPrimaryKey tests
setIdentifier test
getShare* tests
release tests - 1484. By Paweł Blokus <pawel@pawel-desktop>
-
parse_table_proto last tests
- 1483. By Paweł Blokus <pawel@pawel-desktop>
-
parse_table_
proto_IndexKeyP arts_ShouldCopy ParametersTo_ KeyPartInfo - 1482. By Paweł Blokus <pawel@pawel-desktop>
-
parse_table_proto tests for automatic primary key choice
- 1481. By Paweł Blokus <pawel@pawel-desktop>
-
parse_table_proto null bits test
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'drizzled/charset.h' |
2 | --- drizzled/charset.h 2010-02-04 08:14:46 +0000 |
3 | +++ drizzled/charset.h 2010-08-15 23:41:09 +0000 |
4 | @@ -60,35 +60,6 @@ |
5 | extern size_t escape_quotes_for_drizzle(const CHARSET_INFO *charset_info, |
6 | char *to, size_t to_length, |
7 | const char *from, size_t length); |
8 | -/* character sets */ |
9 | -void *cs_alloc(size_t size); |
10 | - |
11 | -extern uint32_t get_charset_number(const char *cs_name, uint32_t cs_flags); |
12 | -extern uint32_t get_collation_number(const char *name); |
13 | -extern const char *get_charset_name(uint32_t cs_number); |
14 | - |
15 | -extern const CHARSET_INFO *get_charset(uint32_t cs_number); |
16 | -extern const CHARSET_INFO *get_charset_by_name(const char *cs_name); |
17 | -extern const CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint32_t cs_flags); |
18 | - |
19 | -extern bool resolve_charset(const char *cs_name, |
20 | - const CHARSET_INFO *default_cs, |
21 | - const CHARSET_INFO **cs); |
22 | -extern bool resolve_collation(const char *cl_name, |
23 | - const CHARSET_INFO *default_cl, |
24 | - const CHARSET_INFO **cl); |
25 | - |
26 | -extern void free_charsets(void); |
27 | -extern char *get_charsets_dir(char *buf); |
28 | -extern bool my_charset_same(const CHARSET_INFO *cs1, const CHARSET_INFO *cs2); |
29 | -extern bool init_compiled_charsets(myf flags); |
30 | -extern void add_compiled_collation(CHARSET_INFO *cs); |
31 | -extern size_t escape_string_for_drizzle(const CHARSET_INFO *charset_info, |
32 | - char *to, size_t to_length, |
33 | - const char *from, size_t length); |
34 | -extern size_t escape_quotes_for_drizzle(const CHARSET_INFO *charset_info, |
35 | - char *to, size_t to_length, |
36 | - const char *from, size_t length); |
37 | |
38 | } /* namespace drizzled */ |
39 | |
40 | |
41 | === modified file 'drizzled/plugin/error_message.cc' |
42 | --- drizzled/plugin/error_message.cc 2010-06-04 02:43:34 +0000 |
43 | +++ drizzled/plugin/error_message.cc 2010-08-15 23:41:09 +0000 |
44 | @@ -46,6 +46,8 @@ |
45 | { |
46 | all_errmsg_handler.erase(find(all_errmsg_handler.begin(), |
47 | all_errmsg_handler.end(), handler)); |
48 | + if (all_errmsg_handler.size() == 0) |
49 | + errmsg_has = false; |
50 | } |
51 | |
52 | |
53 | |
54 | === modified file 'drizzled/plugin/event_observer.h' |
55 | --- drizzled/plugin/event_observer.h 2010-06-21 23:07:24 +0000 |
56 | +++ drizzled/plugin/event_observer.h 2010-08-15 23:41:09 +0000 |
57 | @@ -44,6 +44,7 @@ |
58 | #define DRIZZLED_PLUGIN_EVENT_OBSERVER_H |
59 | |
60 | #include "drizzled/plugin/plugin.h" |
61 | +#include "drizzled/table.h" |
62 | |
63 | #include <string> |
64 | |
65 | @@ -52,6 +53,8 @@ |
66 | |
67 | class Table; |
68 | class TableShare; |
69 | +class Session; |
70 | +class TableIdentifier; |
71 | |
72 | namespace plugin |
73 | { |
74 | @@ -198,7 +201,7 @@ |
75 | |
76 | /*==========================================================*/ |
77 | /* Static meathods called by drizzle to notify interested plugins |
78 | - * of a schema an event, |
79 | + * of a schema event, |
80 | */ |
81 | static bool beforeDropTable(Session &session, const drizzled::TableIdentifier &table); |
82 | static bool afterDropTable(Session &session, const drizzled::TableIdentifier &table, int err); |
83 | @@ -207,7 +210,7 @@ |
84 | |
85 | /*==========================================================*/ |
86 | /* Static meathods called by drizzle to notify interested plugins |
87 | - * of a table an event, |
88 | + * of a table event, |
89 | */ |
90 | static bool beforeInsertRecord(Table &table, unsigned char *buf); |
91 | static bool afterInsertRecord(Table &table, const unsigned char *buf, int err); |
92 | @@ -218,7 +221,7 @@ |
93 | |
94 | /*==========================================================*/ |
95 | /* Static meathods called by drizzle to notify interested plugins |
96 | - * of a table an event, |
97 | + * of a session event, |
98 | */ |
99 | static bool beforeCreateDatabase(Session &session, const std::string &db); |
100 | static bool afterCreateDatabase(Session &session, const std::string &db, int err); |
101 | |
102 | === modified file 'drizzled/plugin/listen.cc' |
103 | --- drizzled/plugin/listen.cc 2009-12-21 09:40:31 +0000 |
104 | +++ drizzled/plugin/listen.cc 2010-08-15 23:41:09 +0000 |
105 | @@ -145,6 +145,11 @@ |
106 | /* wakeup_pipe[0] was closed in the for loop above. */ |
107 | (void) close(wakeup_pipe[1]); |
108 | |
109 | + listen_list.clear(); |
110 | + listen_fd_list.clear(); |
111 | + fd_list.clear(); |
112 | + fd_count= 0; |
113 | + |
114 | return NULL; |
115 | } |
116 | |
117 | |
118 | === modified file 'drizzled/plugin/schema_engine.cc' |
119 | --- drizzled/plugin/schema_engine.cc 2010-07-20 02:17:09 +0000 |
120 | +++ drizzled/plugin/schema_engine.cc 2010-08-15 23:41:09 +0000 |
121 | @@ -84,11 +84,6 @@ |
122 | /* |
123 | Return value is "if parsed" |
124 | */ |
125 | -bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::Schema &proto) |
126 | -{ |
127 | - return StorageEngine::getSchemaDefinition(identifier, proto); |
128 | -} |
129 | - |
130 | bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::Schema &proto) |
131 | { |
132 | proto.Clear(); |
133 | |
134 | === modified file 'drizzled/plugin/storage_engine.cc' |
135 | --- drizzled/plugin/storage_engine.cc 2010-08-05 17:51:54 +0000 |
136 | +++ drizzled/plugin/storage_engine.cc 2010-08-15 23:41:09 +0000 |
137 | @@ -55,10 +55,6 @@ |
138 | #include <drizzled/table_proto.h> |
139 | #include <drizzled/plugin/event_observer.h> |
140 | |
141 | -#include <boost/algorithm/string/compare.hpp> |
142 | - |
143 | -static bool shutdown_has_begun= false; // Once we put in the container for the vector/etc for engines this will go away. |
144 | - |
145 | using namespace std; |
146 | |
147 | namespace drizzled |
148 | @@ -181,13 +177,8 @@ |
149 | |
150 | void StorageEngine::removePlugin(StorageEngine *) |
151 | { |
152 | - if (shutdown_has_begun == false) |
153 | - { |
154 | - vector_of_engines.clear(); |
155 | - vector_of_schema_engines.clear(); |
156 | - |
157 | - shutdown_has_begun= true; |
158 | - } |
159 | + vector_of_engines.clear(); |
160 | + vector_of_schema_engines.clear(); |
161 | } |
162 | |
163 | class FindEngineByName |
164 | @@ -970,7 +961,7 @@ |
165 | str.append(STRING_WITH_LEN("...")); |
166 | } |
167 | my_printf_error(ER_DUP_ENTRY, msg, |
168 | - MYF(0), str.c_ptr(), table.key_info[key_nr].name); |
169 | + MYF(0), str.c_ptr(), table.key_info[key_nr].name); |
170 | } |
171 | } |
172 | |
173 | |
174 | === modified file 'drizzled/plugin/storage_engine.h' |
175 | --- drizzled/plugin/storage_engine.h 2010-08-03 04:19:05 +0000 |
176 | +++ drizzled/plugin/storage_engine.h 2010-08-15 23:41:09 +0000 |
177 | @@ -271,7 +271,7 @@ |
178 | element - data file extention. This order is assumed by |
179 | prepare_for_repair() when REPAIR Table ... USE_FRM is issued. |
180 | */ |
181 | - virtual const char **bas_ext() const =0; |
182 | + virtual const char **bas_ext() const= 0; |
183 | |
184 | protected: |
185 | virtual int doCreateTable(Session &session, |
186 | @@ -334,7 +334,6 @@ |
187 | |
188 | // @note All schema methods defined here |
189 | static void getIdentifiers(Session &session, SchemaIdentifiers &schemas); |
190 | - static bool getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::Schema &proto); |
191 | static bool getSchemaDefinition(const drizzled::SchemaIdentifier &identifier, message::Schema &proto); |
192 | static bool doesSchemaExist(const drizzled::SchemaIdentifier &identifier); |
193 | static const CHARSET_INFO *getSchemaCollation(const drizzled::SchemaIdentifier &identifier); |
194 | |
195 | === modified file 'drizzled/plugin/table_function.h' |
196 | --- drizzled/plugin/table_function.h 2010-07-28 22:40:44 +0000 |
197 | +++ drizzled/plugin/table_function.h 2010-08-15 23:41:09 +0000 |
198 | @@ -167,10 +167,6 @@ |
199 | virtual Generator *generator(Field **arg); |
200 | |
201 | void add_field(const char *label, |
202 | - message::Table::Field::FieldType type, |
203 | - uint32_t length= 0); |
204 | - |
205 | - void add_field(const char *label, |
206 | uint32_t field_length= MAXIMUM_IDENTIFIER_LENGTH); |
207 | |
208 | void add_field(const char *label, |
209 | |
210 | === modified file 'drizzled/plugin/xa_resource_manager.cc' |
211 | --- drizzled/plugin/xa_resource_manager.cc 2010-04-16 05:36:53 +0000 |
212 | +++ drizzled/plugin/xa_resource_manager.cc 2010-08-15 23:41:09 +0000 |
213 | @@ -48,7 +48,7 @@ |
214 | |
215 | int XaResourceManager::commitOrRollbackXID(XID *xid, bool commit) |
216 | { |
217 | - vector<int> results; |
218 | + vector<int> results(xa_resource_managers.size()); |
219 | |
220 | if (commit) |
221 | transform(xa_resource_managers.begin(), xa_resource_managers.end(), results.begin(), |
222 | |
223 | === modified file 'drizzled/plugin/xa_resource_manager.h' |
224 | --- drizzled/plugin/xa_resource_manager.h 2010-03-03 20:21:57 +0000 |
225 | +++ drizzled/plugin/xa_resource_manager.h 2010-08-15 23:41:09 +0000 |
226 | @@ -21,10 +21,14 @@ |
227 | #ifndef DRIZZLED_PLUGIN_XA_RESOURCE_MANAGER_H |
228 | #define DRIZZLED_PLUGIN_XA_RESOURCE_MANAGER_H |
229 | |
230 | +#include <cstddef> |
231 | + |
232 | namespace drizzled |
233 | { |
234 | |
235 | class XID; |
236 | +typedef struct st_hash HASH; |
237 | +class Session; |
238 | |
239 | namespace plugin |
240 | { |
241 | |
242 | === modified file 'drizzled/table_proto_write.cc' |
243 | --- drizzled/table_proto_write.cc 2010-08-05 22:57:47 +0000 |
244 | +++ drizzled/table_proto_write.cc 2010-08-15 23:41:09 +0000 |
245 | @@ -60,7 +60,7 @@ |
246 | } |
247 | |
248 | assert(strcmp(table_proto.engine().name().c_str(), |
249 | - create_info->db_type->getName().c_str())==0); |
250 | + create_info->db_type->getName().c_str())==0); |
251 | |
252 | int field_number= 0; |
253 | bool use_existing_fields= table_proto.field_size() > 0; |
254 | @@ -161,7 +161,7 @@ |
255 | |
256 | enumeration_options->add_field_value(src); |
257 | } |
258 | - enumeration_options->set_collation_id(field_arg->charset->number); |
259 | + enumeration_options->set_collation_id(field_arg->charset->number); |
260 | enumeration_options->set_collation(field_arg->charset->name); |
261 | break; |
262 | } |
263 | @@ -188,17 +188,17 @@ |
264 | { |
265 | uint32_t tmp_len; |
266 | tmp_len= system_charset_info->cset->charpos(system_charset_info, |
267 | - field_arg->comment.str, |
268 | - field_arg->comment.str + |
269 | - field_arg->comment.length, |
270 | - COLUMN_COMMENT_MAXLEN); |
271 | + field_arg->comment.str, |
272 | + field_arg->comment.str + |
273 | + field_arg->comment.length, |
274 | + COLUMN_COMMENT_MAXLEN); |
275 | |
276 | if (tmp_len < field_arg->comment.length) |
277 | { |
278 | - my_error(ER_WRONG_STRING_LENGTH, MYF(0), |
279 | - field_arg->comment.str,"COLUMN COMMENT", |
280 | - (uint32_t) COLUMN_COMMENT_MAXLEN); |
281 | - return(1); |
282 | + my_error(ER_WRONG_STRING_LENGTH, MYF(0), |
283 | + field_arg->comment.str,"COLUMN COMMENT", |
284 | + (uint32_t) COLUMN_COMMENT_MAXLEN); |
285 | + return(1); |
286 | } |
287 | |
288 | if (! use_existing_fields) |
289 | @@ -244,83 +244,46 @@ |
290 | |
291 | if (field_arg->def->is_null()) |
292 | { |
293 | - field_options->set_default_null(true); |
294 | + field_options->set_default_null(true); |
295 | } |
296 | else |
297 | { |
298 | - String d; |
299 | - String *default_value= field_arg->def->val_str(&d); |
300 | - |
301 | - assert(default_value); |
302 | - |
303 | - if ((field_arg->sql_type==DRIZZLE_TYPE_VARCHAR |
304 | - || field_arg->sql_type==DRIZZLE_TYPE_BLOB) |
305 | - && ((field_arg->length / field_arg->charset->mbmaxlen) |
306 | - < default_value->length())) |
307 | - { |
308 | - my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name); |
309 | - return 1; |
310 | - } |
311 | - |
312 | - if (field_arg->sql_type == DRIZZLE_TYPE_DATE |
313 | - || field_arg->sql_type == DRIZZLE_TYPE_DATETIME |
314 | - || field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP) |
315 | - { |
316 | - DRIZZLE_TIME ltime; |
317 | - |
318 | - if (field_arg->def->get_date(<ime, TIME_FUZZY_DATE)) |
319 | - { |
320 | - my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), |
321 | - default_value->c_str()); |
322 | - return 1; |
323 | - } |
324 | - |
325 | - /* We now do the casting down to the appropriate type. |
326 | - |
327 | - Yes, this implicit casting is balls. |
328 | - It was previously done on reading the proto back in, |
329 | - but we really shouldn't store the bogus things in the proto, |
330 | - and instead do the casting behaviour here. |
331 | - |
332 | - the timestamp errors are taken care of elsewhere. |
333 | - */ |
334 | - |
335 | - if (field_arg->sql_type == DRIZZLE_TYPE_DATETIME) |
336 | - { |
337 | - Item *typecast= new Item_datetime_typecast(field_arg->def); |
338 | - typecast->quick_fix_field(); |
339 | - typecast->val_str(default_value); |
340 | - } |
341 | - else if (field_arg->sql_type == DRIZZLE_TYPE_DATE) |
342 | - { |
343 | - Item *typecast= new Item_date_typecast(field_arg->def); |
344 | - typecast->quick_fix_field(); |
345 | - typecast->val_str(default_value); |
346 | - } |
347 | - } |
348 | - |
349 | - if ((field_arg->sql_type==DRIZZLE_TYPE_VARCHAR |
350 | - && field_arg->charset==&my_charset_bin) |
351 | - || (field_arg->sql_type==DRIZZLE_TYPE_BLOB |
352 | - && field_arg->charset==&my_charset_bin)) |
353 | - { |
354 | - string bin_default; |
355 | - bin_default.assign(default_value->c_ptr(), |
356 | - default_value->length()); |
357 | - field_options->set_default_bin_value(bin_default); |
358 | - } |
359 | - else |
360 | - { |
361 | - field_options->set_default_value(default_value->c_ptr()); |
362 | - } |
363 | + String d; |
364 | + String *default_value= field_arg->def->val_str(&d); |
365 | + |
366 | + assert(default_value); |
367 | + |
368 | + if ((field_arg->sql_type==DRIZZLE_TYPE_VARCHAR |
369 | + || field_arg->sql_type==DRIZZLE_TYPE_BLOB) |
370 | + && ((field_arg->length / field_arg->charset->mbmaxlen) |
371 | + < default_value->length())) |
372 | + { |
373 | + my_error(ER_INVALID_DEFAULT, MYF(0), field_arg->field_name); |
374 | + return 1; |
375 | + } |
376 | + |
377 | + if ((field_arg->sql_type==DRIZZLE_TYPE_VARCHAR |
378 | + && field_arg->charset==&my_charset_bin) |
379 | + || (field_arg->sql_type==DRIZZLE_TYPE_BLOB |
380 | + && field_arg->charset==&my_charset_bin)) |
381 | + { |
382 | + string bin_default; |
383 | + bin_default.assign(default_value->c_ptr(), |
384 | + default_value->length()); |
385 | + field_options->set_default_bin_value(bin_default); |
386 | + } |
387 | + else |
388 | + { |
389 | + field_options->set_default_value(default_value->c_ptr()); |
390 | + } |
391 | } |
392 | } |
393 | |
394 | assert(field_arg->unireg_check == Field::NONE |
395 | - || field_arg->unireg_check == Field::NEXT_NUMBER |
396 | - || field_arg->unireg_check == Field::TIMESTAMP_DN_FIELD |
397 | - || field_arg->unireg_check == Field::TIMESTAMP_UN_FIELD |
398 | - || field_arg->unireg_check == Field::TIMESTAMP_DNUN_FIELD); |
399 | + || field_arg->unireg_check == Field::NEXT_NUMBER |
400 | + || field_arg->unireg_check == Field::TIMESTAMP_DN_FIELD |
401 | + || field_arg->unireg_check == Field::TIMESTAMP_UN_FIELD |
402 | + || field_arg->unireg_check == Field::TIMESTAMP_DNUN_FIELD); |
403 | |
404 | } |
405 | |
406 | @@ -353,7 +316,7 @@ |
407 | if (create_info->default_table_charset) |
408 | { |
409 | table_options->set_collation_id( |
410 | - create_info->default_table_charset->number); |
411 | + create_info->default_table_charset->number); |
412 | table_options->set_collation(create_info->default_table_charset->name); |
413 | } |
414 | |
415 | @@ -428,17 +391,17 @@ |
416 | { |
417 | uint32_t tmp_len; |
418 | tmp_len= system_charset_info->cset->charpos(system_charset_info, |
419 | - key_info[i].comment.str, |
420 | - key_info[i].comment.str + |
421 | - key_info[i].comment.length, |
422 | - TABLE_COMMENT_MAXLEN); |
423 | + key_info[i].comment.str, |
424 | + key_info[i].comment.str + |
425 | + key_info[i].comment.length, |
426 | + TABLE_COMMENT_MAXLEN); |
427 | |
428 | if (tmp_len < key_info[i].comment.length) |
429 | { |
430 | - my_error(ER_WRONG_STRING_LENGTH, MYF(0), |
431 | - key_info[i].comment.str,"Index COMMENT", |
432 | - (uint32_t) TABLE_COMMENT_MAXLEN); |
433 | - return(1); |
434 | + my_error(ER_WRONG_STRING_LENGTH, MYF(0), |
435 | + key_info[i].comment.str,"Index COMMENT", |
436 | + (uint32_t) TABLE_COMMENT_MAXLEN); |
437 | + return(1); |
438 | } |
439 | |
440 | idx->set_comment(key_info[i].comment.str); |
441 | @@ -512,14 +475,14 @@ |
442 | |
443 | SYNOPSIS |
444 | rea_create_table() |
445 | - session Thread handler |
446 | - path Name of file (including database, without .frm) |
447 | - db Data base name |
448 | - table_name Table name |
449 | - create_info create info parameters |
450 | - create_fields Fields to create |
451 | - keys number of keys to create |
452 | - key_info Keys to create |
453 | + session Thread handler |
454 | + path Name of file (including database, without .frm) |
455 | + db Data base name |
456 | + table_name Table name |
457 | + create_info create info parameters |
458 | + create_fields Fields to create |
459 | + keys number of keys to create |
460 | + key_info Keys to create |
461 | |
462 | RETURN |
463 | 0 ok |
464 | |
465 | === modified file 'drizzled/table_share.cc' |
466 | --- drizzled/table_share.cc 2010-08-07 17:38:08 +0000 |
467 | +++ drizzled/table_share.cc 2010-08-15 23:41:09 +0000 |
468 | @@ -256,7 +256,7 @@ |
469 | |
470 | return NULL; |
471 | } |
472 | - share->ref_count++; // Mark in use |
473 | + share->ref_count++;// Mark in use |
474 | |
475 | plugin::EventObserver::registerTableEvents(*share); |
476 | |
477 | @@ -1399,14 +1399,14 @@ |
478 | |
479 | for (int valnr= 0; valnr < fo.field_value_size(); valnr++) |
480 | { |
481 | - if (fo.field_value(valnr).length() > field_length) |
482 | - { |
483 | - field_length= charset->cset->numchars(charset, |
484 | - fo.field_value(valnr).c_str(), |
485 | - fo.field_value(valnr).c_str() |
486 | - + fo.field_value(valnr).length()) |
487 | - * charset->mbmaxlen; |
488 | - } |
489 | + uint32_t length; |
490 | + length= charset->cset->numchars(charset, |
491 | + fo.field_value(valnr).c_str(), |
492 | + fo.field_value(valnr).c_str() |
493 | + + fo.field_value(valnr).length()) |
494 | + * charset->mbmaxlen; |
495 | + if (length > field_length) |
496 | + field_length= length; |
497 | } |
498 | } |
499 | break; |
500 | @@ -1565,6 +1565,7 @@ |
501 | } |
502 | } |
503 | |
504 | + keyinfo->extra_length= 0; |
505 | for (uint32_t i= 0 ; i < keyinfo->key_parts ; key_part++,i++) |
506 | { |
507 | Field *local_field; |
508 | @@ -1756,10 +1757,8 @@ |
509 | int TableShare::open_table_def(Session& session, TableIdentifier &identifier) |
510 | { |
511 | int local_error; |
512 | - bool error_given; |
513 | |
514 | local_error= 1; |
515 | - error_given= 0; |
516 | |
517 | message::Table table; |
518 | |
519 | @@ -1775,19 +1774,17 @@ |
520 | else |
521 | { |
522 | if (not table.IsInitialized()) |
523 | - { |
524 | local_error= 4; |
525 | - } |
526 | } |
527 | - goto err_not_open; |
528 | - } |
529 | - |
530 | - local_error= parse_table_proto(session, table); |
531 | - |
532 | - setTableCategory(TABLE_CATEGORY_USER); |
533 | - |
534 | -err_not_open: |
535 | - if (local_error && !error_given) |
536 | + } |
537 | + else |
538 | + { |
539 | + local_error= parse_table_proto(session, table); |
540 | + |
541 | + setTableCategory(TABLE_CATEGORY_USER); |
542 | + } |
543 | + |
544 | + if (local_error) |
545 | { |
546 | error= local_error; |
547 | open_table_error(error, (open_errno= errno), 0); |
548 | |
549 | === modified file 'drizzled/table_share.h' |
550 | --- drizzled/table_share.h 2010-08-06 00:16:27 +0000 |
551 | +++ drizzled/table_share.h 2010-08-15 23:41:09 +0000 |
552 | @@ -31,6 +31,7 @@ |
553 | #include <boost/unordered_map.hpp> |
554 | |
555 | #include "drizzled/typelib.h" |
556 | +#include "drizzled/identifier.h" |
557 | #include "drizzled/memory/root.h" |
558 | #include "drizzled/message/table.pb.h" |
559 | #include "drizzled/util/string.h" |
560 | @@ -183,7 +184,7 @@ |
561 | |
562 | private: |
563 | std::vector<std::string> _keynames; |
564 | - |
565 | +protected: |
566 | void addKeyName(std::string arg) |
567 | { |
568 | std::transform(arg.begin(), arg.end(), |
569 | |
570 | === added file 'unittests/generator.cc' |
571 | --- unittests/generator.cc 1970-01-01 00:00:00 +0000 |
572 | +++ unittests/generator.cc 2010-08-15 23:41:09 +0000 |
573 | @@ -0,0 +1,61 @@ |
574 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
575 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
576 | +* |
577 | +* Copyright (C) 2010 Pawel Blokus |
578 | +* |
579 | +* This program is free software; you can redistribute it and/or modify |
580 | +* it under the terms of the GNU General Public License as published by |
581 | +* the Free Software Foundation; either version 2 of the License, or |
582 | +* (at your option) any later version. |
583 | +* |
584 | +* This program is distributed in the hope that it will be useful, |
585 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
586 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
587 | +* GNU General Public License for more details. |
588 | +* |
589 | +* You should have received a copy of the GNU General Public License |
590 | +* along with this program; if not, write to the Free Software |
591 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
592 | +*/ |
593 | + |
594 | +#include "config.h" |
595 | + |
596 | +#include <drizzled/drizzled.h> |
597 | +#include <drizzled/item.h> |
598 | +#include <drizzled/plugin/listen.h> |
599 | +#include <drizzled/session.h> |
600 | +#include <drizzled/sql_lex.h> |
601 | + |
602 | +#include "generator.h" |
603 | + |
604 | +using namespace drizzled; |
605 | + |
606 | +Session *Generator::SessionGenerator::make_fake_session() |
607 | +{ |
608 | + Session *fake_session; |
609 | + |
610 | + plugin::Client *fake_client; |
611 | + fake_client= plugin::Listen::getNullClient(); |
612 | + fake_session= new Session(fake_client); |
613 | + fake_session->thread_stack= (char*) &fake_session; |
614 | + init_thread_environment(); |
615 | + fake_session->initGlobals(); |
616 | + |
617 | + return fake_session; |
618 | +} |
619 | + |
620 | +void Generator::SelectLexGenerator::make_Select_Lex_empty_for_print(Select_Lex *select_lex) |
621 | +{ |
622 | + select_lex->options= 0; |
623 | + select_lex->set_braces(false); |
624 | + select_lex->table_list.elements= NULL; |
625 | + select_lex->where= NULL; |
626 | + select_lex->group_list.elements= NULL; |
627 | + select_lex->olap= CUBE_TYPE; |
628 | + select_lex->having= NULL; |
629 | + select_lex->join= NULL; |
630 | + select_lex->order_list.elements= NULL; |
631 | + select_lex->explicit_limit= NULL; |
632 | + select_lex->cond_value= Item::COND_UNDEF; |
633 | + select_lex->having_value= Item::COND_UNDEF; |
634 | +} |
635 | |
636 | === added file 'unittests/generator.h' |
637 | --- unittests/generator.h 1970-01-01 00:00:00 +0000 |
638 | +++ unittests/generator.h 2010-08-15 23:41:09 +0000 |
639 | @@ -0,0 +1,48 @@ |
640 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
641 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
642 | +* |
643 | +* Copyright (C) 2010 Pawel Blokus |
644 | +* |
645 | +* This program is free software; you can redistribute it and/or modify |
646 | +* it under the terms of the GNU General Public License as published by |
647 | +* the Free Software Foundation; either version 2 of the License, or |
648 | +* (at your option) any later version. |
649 | +* |
650 | +* This program is distributed in the hope that it will be useful, |
651 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
652 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
653 | +* GNU General Public License for more details. |
654 | +* |
655 | +* You should have received a copy of the GNU General Public License |
656 | +* along with this program; if not, write to the Free Software |
657 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
658 | +*/ |
659 | + |
660 | +#ifndef UNITTESTS_GENERATOR_H |
661 | +#define UNITTESTS_GENERATOR_H |
662 | + |
663 | +#include "drizzled/message/table.pb.h" |
664 | + |
665 | +namespace drizzled |
666 | +{ |
667 | + class Session; |
668 | + class Select_Lex; |
669 | +} |
670 | + |
671 | +class Generator |
672 | +{ |
673 | +public: |
674 | + class SessionGenerator |
675 | + { |
676 | + public: |
677 | + static drizzled::Session *make_fake_session(); |
678 | + }; |
679 | + |
680 | + class SelectLexGenerator |
681 | + { |
682 | + public: |
683 | + static void make_Select_Lex_empty_for_print(drizzled::Select_Lex *select_lex); |
684 | + }; |
685 | +}; |
686 | + |
687 | +#endif |
688 | |
689 | === modified file 'unittests/include.am' |
690 | --- unittests/include.am 2010-07-07 06:52:54 +0000 |
691 | +++ unittests/include.am 2010-08-15 23:41:09 +0000 |
692 | @@ -8,32 +8,57 @@ |
693 | |
694 | noinst_HEADERS += \ |
695 | unittests/plugin/plugin_stubs.h \ |
696 | + unittests/stubs.h \ |
697 | unittests/temporal_generator.h |
698 | |
699 | unit: unittests/unittests |
700 | unittests/unittests |
701 | |
702 | unittests_unittests_SOURCES = \ |
703 | - unittests/atomics_test.cc \ |
704 | - unittests/calendar_test.cc \ |
705 | - unittests/date_test.cc \ |
706 | - unittests/date_time_test.cc \ |
707 | - unittests/generators.cc \ |
708 | - unittests/main.cc \ |
709 | - unittests/micro_timestamp_test.cc \ |
710 | - unittests/nano_timestamp_test.cc \ |
711 | - unittests/option_context.cc \ |
712 | - unittests/plugin/authentication_test.cc \ |
713 | - unittests/plugin/client_test.cc \ |
714 | - unittests/plugin/error_message_test.cc \ |
715 | - unittests/pthread_atomics_test.cc \ |
716 | - unittests/table_identifier.cc \ |
717 | - unittests/temporal_format_test.cc \ |
718 | - unittests/temporal_generator.cc \ |
719 | - unittests/temporal_interval_test.cc \ |
720 | - unittests/time_test.cc \ |
721 | - unittests/timestamp_test.cc \ |
722 | - unittests/utf8_test.cc |
723 | + unittests/atomics_test.cc \ |
724 | + unittests/calendar_test.cc \ |
725 | + unittests/date_test.cc \ |
726 | + unittests/date_time_test.cc \ |
727 | + unittests/generator.cc \ |
728 | + unittests/generators.cc \ |
729 | + unittests/main.cc \ |
730 | + unittests/micro_timestamp_test.cc \ |
731 | + unittests/nano_timestamp_test.cc \ |
732 | + unittests/option_context.cc \ |
733 | + unittests/plugin/authentication_test.cc \ |
734 | + unittests/plugin/authorization_test.cc \ |
735 | + unittests/plugin/client_test.cc \ |
736 | + unittests/plugin/error_message_test.cc \ |
737 | + unittests/plugin/event_observer_test.cc \ |
738 | + unittests/plugin/function_test.cc \ |
739 | + unittests/plugin/listen_test.cc \ |
740 | + unittests/plugin/listen_tcp_test.cc \ |
741 | + unittests/plugin/logging_test.cc \ |
742 | + unittests/plugin/query_cache_test.cc \ |
743 | + unittests/plugin/query_rewrite_test.cc \ |
744 | + unittests/plugin/scheduler_test.cc \ |
745 | + unittests/plugin/schema_engine_test.cc \ |
746 | + unittests/plugin/storage_engine_test.cc \ |
747 | + unittests/plugin/table_function_test.cc \ |
748 | + unittests/plugin/transactional_storage_engine_test.cc \ |
749 | + unittests/plugin/transaction_applier_test.cc \ |
750 | + unittests/plugin/transaction_replicator_test.cc \ |
751 | + unittests/plugin/xa_resource_manager_test.cc \ |
752 | + unittests/plugin/xa_storage_engine_test.cc \ |
753 | + unittests/pthread_atomics_test.cc \ |
754 | + unittests/stubs.cc \ |
755 | + unittests/table_identifier.cc \ |
756 | + unittests/table_identifier_test.cc \ |
757 | + unittests/table_list_test.cc \ |
758 | + unittests/table_proto_write_test.cc \ |
759 | + unittests/table_share_test.cc \ |
760 | + unittests/temporal_format_test.cc \ |
761 | + unittests/temporal_generator.cc \ |
762 | + unittests/temporal_interval_test.cc \ |
763 | + unittests/time_test.cc \ |
764 | + unittests/timestamp_test.cc \ |
765 | + unittests/utf8_test.cc |
766 | + |
767 | |
768 | unittests_unittests_LDADD= \ |
769 | $(filter-out drizzled/main.$(OBJEXT), ${am_drizzled_drizzled_OBJECTS}) \ |
770 | |
771 | === modified file 'unittests/plugin/authentication_test.cc' |
772 | --- unittests/plugin/authentication_test.cc 2010-06-10 20:26:28 +0000 |
773 | +++ unittests/plugin/authentication_test.cc 2010-08-15 23:41:09 +0000 |
774 | @@ -27,16 +27,10 @@ |
775 | #include <string> |
776 | |
777 | #include "plugin_stubs.h" |
778 | +#include "../stubs.h" |
779 | |
780 | using namespace drizzled; |
781 | |
782 | -static void error_handler_func_stub(uint32_t my_err, const char *str, myf MyFlags) |
783 | -{ |
784 | - (void)my_err; |
785 | - (void)str; |
786 | - (void)MyFlags; |
787 | -} |
788 | - |
789 | class AuthenticationTest : public ::testing::Test |
790 | { |
791 | public: |
792 | @@ -52,7 +46,7 @@ |
793 | |
794 | virtual void SetUp () |
795 | { |
796 | - error_handler_hook = error_handler_func_stub; |
797 | + error_handler_hook= error_handler_func_stub; |
798 | } |
799 | |
800 | void addOnePlugin() |
801 | @@ -81,7 +75,7 @@ |
802 | |
803 | TEST_F(AuthenticationTest, isAuthenticated_noPluginsLoaded_shouldReturn_True) |
804 | { |
805 | - bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd); |
806 | + bool authenticated= plugin::Authentication::isAuthenticated(sctx, passwd); |
807 | |
808 | ASSERT_TRUE(authenticated); |
809 | } |
810 | @@ -90,7 +84,7 @@ |
811 | { |
812 | |
813 | addOnePlugin(); |
814 | - bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd); |
815 | + bool authenticated= plugin::Authentication::isAuthenticated(sctx, passwd); |
816 | removeOnePlugin(); |
817 | |
818 | ASSERT_FALSE(authenticated); |
819 | @@ -102,7 +96,7 @@ |
820 | stub1.set_authenticate_return(true); |
821 | |
822 | addOnePlugin(); |
823 | - bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd); |
824 | + bool authenticated= plugin::Authentication::isAuthenticated(sctx, passwd); |
825 | removeOnePlugin(); |
826 | |
827 | ASSERT_TRUE(authenticated); |
828 | @@ -112,7 +106,7 @@ |
829 | { |
830 | |
831 | addTwoPlugins(); |
832 | - bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd); |
833 | + bool authenticated= plugin::Authentication::isAuthenticated(sctx, passwd); |
834 | removeTwoPlugins(); |
835 | |
836 | ASSERT_FALSE(authenticated); |
837 | @@ -123,7 +117,7 @@ |
838 | stub2.set_authenticate_return(true); |
839 | |
840 | addTwoPlugins(); |
841 | - bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd); |
842 | + bool authenticated= plugin::Authentication::isAuthenticated(sctx, passwd); |
843 | removeTwoPlugins(); |
844 | |
845 | ASSERT_TRUE(authenticated); |
846 | |
847 | === added file 'unittests/plugin/authorization_test.cc' |
848 | --- unittests/plugin/authorization_test.cc 1970-01-01 00:00:00 +0000 |
849 | +++ unittests/plugin/authorization_test.cc 2010-08-15 23:41:09 +0000 |
850 | @@ -0,0 +1,155 @@ |
851 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
852 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
853 | +* |
854 | +* Copyright (C) 2010 Pawel Blokus |
855 | +* |
856 | +* This program is free software; you can redistribute it and/or modify |
857 | +* it under the terms of the GNU General Public License as published by |
858 | +* the Free Software Foundation; either version 2 of the License, or |
859 | +* (at your option) any later version. |
860 | +* |
861 | +* This program is distributed in the hope that it will be useful, |
862 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
863 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
864 | +* GNU General Public License for more details. |
865 | +* |
866 | +* You should have received a copy of the GNU General Public License |
867 | +* along with this program; if not, write to the Free Software |
868 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
869 | +*/ |
870 | + |
871 | +#include "config.h" |
872 | + |
873 | +#include <drizzled/plugin/authorization.h> |
874 | +#include <gtest/gtest.h> |
875 | + |
876 | +#include "plugin_stubs.h" |
877 | +#include "../generator.h" |
878 | + |
879 | +using namespace drizzled; |
880 | + |
881 | +class AuthorizationTest : public ::testing::Test |
882 | +{ |
883 | +protected: |
884 | + AuthorizationStub plugin1, plugin2; |
885 | + SecurityContext user_ctx; |
886 | + SchemaIdentifier schema_identifier; |
887 | + TableIdentifier *table_identifier; |
888 | + Session *fake_session; |
889 | + bool result; |
890 | + SchemaIdentifiers schema_identifier_list; |
891 | +public: |
892 | + AuthorizationTest() |
893 | + : plugin1("AuthorizationStub1"), |
894 | + plugin2("AuthorizationStub2"), |
895 | + schema_identifier("stubArg") |
896 | + {} |
897 | + |
898 | + virtual void SetUp() |
899 | + { |
900 | + plugin::Authorization::addPlugin(&plugin1); |
901 | + plugin::Authorization::addPlugin(&plugin2); |
902 | + |
903 | + table_identifier= new TableIdentifier("SchemaNameStub", |
904 | + "TableNameStub", |
905 | + "PathStub"); |
906 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
907 | + } |
908 | + |
909 | + virtual void TearDown() |
910 | + { |
911 | + delete table_identifier; |
912 | + |
913 | + plugin::Authorization::removePlugin(&plugin1); |
914 | + plugin::Authorization::removePlugin(&plugin2); |
915 | + |
916 | + schema_identifier_list.clear(); |
917 | + } |
918 | + |
919 | + void populate_schema_identifier_list_with_3_ids() |
920 | + { |
921 | + schema_identifier_list.push_back(SchemaIdentifier("StubArg1")); |
922 | + schema_identifier_list.push_back(SchemaIdentifier("StubArg2")); |
923 | + schema_identifier_list.push_back(SchemaIdentifier("StubArg3")); |
924 | + } |
925 | +}; |
926 | + |
927 | +TEST_F(AuthorizationTest, isAuthorized_schema_twoPluginsAdded_bothAuthorizing_shouldReturn_True) |
928 | +{ |
929 | + result= plugin::Authorization::isAuthorized(user_ctx, schema_identifier, false); |
930 | + |
931 | + ASSERT_TRUE(result); |
932 | +} |
933 | + |
934 | +TEST_F(AuthorizationTest, isAuthorized_schema_twoPluginsAdded_oneNotAuthorizing_shouldReturn_False) |
935 | +{ |
936 | + plugin2.setRestrictSchemaReturnCount(1); |
937 | + |
938 | + result= plugin::Authorization::isAuthorized(user_ctx, schema_identifier, false); |
939 | + |
940 | + ASSERT_FALSE(result); |
941 | +} |
942 | + |
943 | + |
944 | +TEST_F(AuthorizationTest, isAuthorized_table_twoPluginsAdded_bothAuthorizing_shouldReturn_True) |
945 | +{ |
946 | + result= plugin::Authorization::isAuthorized(user_ctx, *table_identifier, false); |
947 | + |
948 | + ASSERT_TRUE(result); |
949 | +} |
950 | + |
951 | +TEST_F(AuthorizationTest, isAuthorized_table_twoPluginsAdded_oneNotAuthorizing_shouldReturn_False) |
952 | +{ |
953 | + plugin2.setRestrictTableReturn(true); |
954 | + |
955 | + result= plugin::Authorization::isAuthorized(user_ctx, *table_identifier, false); |
956 | + |
957 | + ASSERT_FALSE(result); |
958 | +} |
959 | + |
960 | + |
961 | +TEST_F(AuthorizationTest, isAuthorized_process_twoPluginsAdded_bothAuthorizing_shouldReturn_True) |
962 | +{ |
963 | + result= plugin::Authorization::isAuthorized(user_ctx, fake_session, false); |
964 | + |
965 | + ASSERT_TRUE(result); |
966 | +} |
967 | + |
968 | +TEST_F(AuthorizationTest, isAuthorized_process_twoPluginsAdded_oneNotAuthorizing_shouldReturn_False) |
969 | +{ |
970 | + plugin2.setRestrictProcessReturn(true); |
971 | + |
972 | + result= plugin::Authorization::isAuthorized(user_ctx, fake_session, false); |
973 | + |
974 | + ASSERT_FALSE(result); |
975 | +} |
976 | + |
977 | +TEST_F(AuthorizationTest, pruneSchemaNames_allSchemasAuthorized_shouldLeaveListUnchanged) |
978 | +{ |
979 | + populate_schema_identifier_list_with_3_ids(); |
980 | + |
981 | + plugin::Authorization::pruneSchemaNames(user_ctx, schema_identifier_list); |
982 | + |
983 | + ASSERT_EQ(3, schema_identifier_list.size()); |
984 | +} |
985 | + |
986 | +TEST_F(AuthorizationTest, pruneSchemaNames_notAllSchemasAuthorized_shouldPruneListAppropiately) |
987 | +{ |
988 | + populate_schema_identifier_list_with_3_ids(); |
989 | + plugin2.setRestrictSchemaReturnCount(2); |
990 | + |
991 | + plugin::Authorization::pruneSchemaNames(user_ctx, schema_identifier_list); |
992 | + |
993 | + ASSERT_EQ(1, schema_identifier_list.size()); |
994 | +} |
995 | + |
996 | +TEST_F(AuthorizationTest, pruneSchemaNames_AllSchemasNotAuthorized_shouldClearList) |
997 | +{ |
998 | + populate_schema_identifier_list_with_3_ids(); |
999 | + plugin2.setRestrictSchemaReturnCount(3); |
1000 | + |
1001 | + plugin::Authorization::pruneSchemaNames(user_ctx, schema_identifier_list); |
1002 | + |
1003 | + ASSERT_EQ(0, schema_identifier_list.size()); |
1004 | +} |
1005 | + |
1006 | |
1007 | === modified file 'unittests/plugin/error_message_test.cc' |
1008 | --- unittests/plugin/error_message_test.cc 2010-06-09 21:37:15 +0000 |
1009 | +++ unittests/plugin/error_message_test.cc 2010-08-15 23:41:09 +0000 |
1010 | @@ -27,3 +27,50 @@ |
1011 | |
1012 | using namespace drizzled; |
1013 | |
1014 | +class ErrorMessageTest : public ::testing::Test |
1015 | +{ |
1016 | +protected: |
1017 | + bool result; |
1018 | + ErrorMessageStub plugin1, plugin2; |
1019 | +public: |
1020 | + ErrorMessageTest() |
1021 | + : plugin1("ErrorMessageStub1"), |
1022 | + plugin2("ErrorMessageStub2") |
1023 | + {} |
1024 | + |
1025 | + virtual void SetUp() |
1026 | + { |
1027 | + plugin::ErrorMessage::addPlugin(&plugin1); |
1028 | + plugin::ErrorMessage::addPlugin(&plugin2); |
1029 | + } |
1030 | + |
1031 | + virtual void TearDown() |
1032 | + { |
1033 | + plugin::ErrorMessage::removePlugin(&plugin1); |
1034 | + plugin::ErrorMessage::removePlugin(&plugin2); |
1035 | + } |
1036 | +}; |
1037 | + |
1038 | +TEST_F(ErrorMessageTest, vprintf_twoPLuginsAdded_shouldReturn_False) |
1039 | +{ |
1040 | + result= plugin::ErrorMessage::vprintf(NULL, 0, "ErrorMessage", NULL); |
1041 | + |
1042 | + ASSERT_FALSE(result); |
1043 | +} |
1044 | + |
1045 | +TEST_F(ErrorMessageTest, vprintf_twoPLuginsAdded_oneFails_shouldReturn_True) |
1046 | +{ |
1047 | + plugin2.setErrmsgReturn(true); |
1048 | + |
1049 | + result= plugin::ErrorMessage::vprintf(NULL, 0, "ErrorMessage", NULL); |
1050 | + |
1051 | + ASSERT_TRUE(result); |
1052 | +} |
1053 | + |
1054 | +TEST_F(ErrorMessageTest, vprintf_twoPLuginsAdded_shouldCall_errmsg_onBoth) |
1055 | +{ |
1056 | + plugin::ErrorMessage::vprintf(NULL, 0, "ErrorMessage", NULL); |
1057 | + |
1058 | + ASSERT_TRUE(plugin1.getErrmsgCalled()); |
1059 | + ASSERT_TRUE(plugin2.getErrmsgCalled()); |
1060 | +} |
1061 | |
1062 | === added file 'unittests/plugin/event_observer_test.cc' |
1063 | --- unittests/plugin/event_observer_test.cc 1970-01-01 00:00:00 +0000 |
1064 | +++ unittests/plugin/event_observer_test.cc 2010-08-15 23:41:09 +0000 |
1065 | @@ -0,0 +1,306 @@ |
1066 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1067 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1068 | +* |
1069 | +* Copyright (C) 2010 Pawel Blokus |
1070 | +* |
1071 | +* This program is free software; you can redistribute it and/or modify |
1072 | +* it under the terms of the GNU General Public License as published by |
1073 | +* the Free Software Foundation; either version 2 of the License, or |
1074 | +* (at your option) any later version. |
1075 | +* |
1076 | +* This program is distributed in the hope that it will be useful, |
1077 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
1078 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1079 | +* GNU General Public License for more details. |
1080 | +* |
1081 | +* You should have received a copy of the GNU General Public License |
1082 | +* along with this program; if not, write to the Free Software |
1083 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1084 | +*/ |
1085 | + |
1086 | +#include "config.h" |
1087 | + |
1088 | +#include <drizzled/plugin/event_observer.h> |
1089 | +#include <drizzled/session.h> |
1090 | +#include <gtest/gtest.h> |
1091 | + |
1092 | +#include "plugin_stubs.h" |
1093 | +#include "../generator.h" |
1094 | + |
1095 | +using namespace drizzled; |
1096 | +using namespace std; |
1097 | + |
1098 | +class EventObserverTest |
1099 | +{ |
1100 | + public: |
1101 | + bool observer1Called, observer2Called; |
1102 | + EventObserverStub observer1; |
1103 | + EventObserverStub observer2; |
1104 | + Session *fake_session; |
1105 | + string db; |
1106 | + TableShare *table_share; |
1107 | + TableIdentifier *id; |
1108 | + Table table; |
1109 | + |
1110 | + |
1111 | + EventObserverTest() : |
1112 | + observer1("EventObserverStub1"), |
1113 | + observer2("EventObserverStub2"), |
1114 | + db("") |
1115 | + { |
1116 | + |
1117 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
1118 | + id= new TableIdentifier("SchemaNamestub", |
1119 | + "TableNameStub", |
1120 | + "PathStub"); |
1121 | + table_share= new TableShare(*id); |
1122 | + table.s= table_share; |
1123 | + |
1124 | + plugin::EventObserver::addPlugin(&observer1); |
1125 | + plugin::EventObserver::addPlugin(&observer2); |
1126 | + } |
1127 | + |
1128 | + ~EventObserverTest() |
1129 | + { |
1130 | + plugin::EventObserver::removePlugin(&observer1); |
1131 | + plugin::EventObserver::removePlugin(&observer2); |
1132 | + |
1133 | + //TODO: if we delete this the next make_fake_session call will fail |
1134 | + //delete fake_session; |
1135 | + delete table_share; |
1136 | + delete id; |
1137 | + } |
1138 | + |
1139 | +}; |
1140 | + |
1141 | +class EventObserverRegisterTest : public EventObserverTest, public ::testing::Test |
1142 | +{ |
1143 | +}; |
1144 | + |
1145 | +TEST_F(EventObserverRegisterTest, registerTableEvents_twoPluginsAdded_shouldCall_registerTableEventsDo_onBoth) |
1146 | +{ |
1147 | + plugin::EventObserver::registerTableEvents(*table_share); |
1148 | + |
1149 | + observer1Called= observer1.getRegisterTableEventsDoCalled(); |
1150 | + observer2Called= observer2.getRegisterTableEventsDoCalled(); |
1151 | + |
1152 | + EXPECT_TRUE(observer1Called); |
1153 | + EXPECT_TRUE(observer2Called); |
1154 | +} |
1155 | + |
1156 | +TEST_F(EventObserverRegisterTest, registerSchemaEvents_twoPluginsAdded_shouldCall_registerSchemaEventsDo_onBoth) |
1157 | +{ |
1158 | + |
1159 | + plugin::EventObserver::registerSchemaEvents(*fake_session, db); |
1160 | + |
1161 | + observer1Called= observer1.getRegisterSchemaEventsDoCalled(); |
1162 | + observer2Called= observer2.getRegisterSchemaEventsDoCalled(); |
1163 | + |
1164 | + EXPECT_TRUE(observer1Called); |
1165 | + EXPECT_TRUE(observer2Called); |
1166 | +} |
1167 | + |
1168 | +TEST_F(EventObserverRegisterTest, registerSessionEvents_twoPluginsAdded_shouldCall_registerSessionEventsDo_onBoth) |
1169 | +{ |
1170 | + plugin::EventObserver::registerSessionEvents(*fake_session); |
1171 | + |
1172 | + observer1Called= observer1.getRegisterSessionEventsDoCalled(); |
1173 | + observer2Called= observer2.getRegisterSessionEventsDoCalled(); |
1174 | + |
1175 | + EXPECT_TRUE(observer1Called); |
1176 | + EXPECT_TRUE(observer2Called); |
1177 | +} |
1178 | + |
1179 | +class EventObserverEventTest : public ::testing::TestWithParam<bool>, public EventObserverTest |
1180 | +{ |
1181 | + public: |
1182 | + bool expected; |
1183 | + EventObserverEventTest() |
1184 | + { |
1185 | + expected= GetParam(); |
1186 | + observer1.setRegisterAll(expected); |
1187 | + observer2.setRegisterAll(expected); |
1188 | + } |
1189 | +}; |
1190 | + |
1191 | +testing::internal::ParamGenerator<bool> gtest_twoPluginsAddedWithEventsRegistered_shouldCall_observeEventDo_onBothEventObserverEventTest_EvalGenerator_(); |
1192 | +INSTANTIATE_TEST_CASE_P(twoPluginsAddedWithEventsRegistered_shouldCall_observeEventDo_onBoth, |
1193 | + EventObserverEventTest, |
1194 | + ::testing::Values(true)); |
1195 | + |
1196 | +testing::internal::ParamGenerator<bool> gtest_twoPluginsAddedWith_No_EventsRegistered_shouldNotCall_observeEventDo_onAnyEventObserverEventTest_EvalGenerator_(); |
1197 | +INSTANTIATE_TEST_CASE_P(twoPluginsAddedWith_No_EventsRegistered_shouldNotCall_observeEventDo_onAny, |
1198 | + EventObserverEventTest, |
1199 | + ::testing::Values(false)); |
1200 | + |
1201 | +TEST_P(EventObserverEventTest, beforeDropTable) |
1202 | +{ |
1203 | + plugin::EventObserver::registerSchemaEvents(*fake_session, db); |
1204 | + |
1205 | + plugin::EventObserver::beforeDropTable(*fake_session, *id); |
1206 | + observer1Called= observer1.getObserveEventDoCalled(); |
1207 | + observer2Called= observer2.getObserveEventDoCalled(); |
1208 | + |
1209 | + EXPECT_EQ(expected, observer1Called); |
1210 | + EXPECT_EQ(expected, observer2Called); |
1211 | +} |
1212 | + |
1213 | +TEST_P(EventObserverEventTest, afterDropTable) |
1214 | +{ |
1215 | + plugin::EventObserver::registerSchemaEvents(*fake_session, db); |
1216 | + |
1217 | + plugin::EventObserver::afterDropTable(*fake_session, *id, 0); |
1218 | + observer1Called= observer1.getObserveEventDoCalled(); |
1219 | + observer2Called= observer2.getObserveEventDoCalled(); |
1220 | + |
1221 | + EXPECT_EQ(expected, observer1Called); |
1222 | + EXPECT_EQ(expected, observer2Called); |
1223 | +} |
1224 | + |
1225 | +TEST_P(EventObserverEventTest, beforeRenameTable) |
1226 | +{ |
1227 | + plugin::EventObserver::registerSchemaEvents(*fake_session, db); |
1228 | + |
1229 | + plugin::EventObserver::beforeRenameTable(*fake_session, *id, *id); |
1230 | + observer1Called= observer1.getObserveEventDoCalled(); |
1231 | + observer2Called= observer2.getObserveEventDoCalled(); |
1232 | + |
1233 | + EXPECT_EQ(expected, observer1Called); |
1234 | + EXPECT_EQ(expected, observer2Called); |
1235 | +} |
1236 | + |
1237 | +TEST_P(EventObserverEventTest, afterRenameTable) |
1238 | +{ |
1239 | + plugin::EventObserver::registerSchemaEvents(*fake_session, db); |
1240 | + |
1241 | + plugin::EventObserver::afterRenameTable(*fake_session, *id, *id, 0); |
1242 | + observer1Called= observer1.getObserveEventDoCalled(); |
1243 | + observer2Called= observer2.getObserveEventDoCalled(); |
1244 | + |
1245 | + EXPECT_EQ(expected, observer1Called); |
1246 | + EXPECT_EQ(expected, observer2Called); |
1247 | +} |
1248 | + |
1249 | + |
1250 | + |
1251 | +TEST_P(EventObserverEventTest, beforeInsertRecord) |
1252 | +{ |
1253 | + plugin::EventObserver::registerTableEvents(*table_share); |
1254 | + |
1255 | + plugin::EventObserver::beforeInsertRecord(table, NULL); |
1256 | + observer1Called= observer1.getObserveEventDoCalled(); |
1257 | + observer2Called= observer2.getObserveEventDoCalled(); |
1258 | + |
1259 | + EXPECT_EQ(expected, observer1Called); |
1260 | + EXPECT_EQ(expected, observer2Called); |
1261 | +} |
1262 | + |
1263 | +TEST_P(EventObserverEventTest, afterInsertRecord) |
1264 | +{ |
1265 | + plugin::EventObserver::registerTableEvents(*table_share); |
1266 | + |
1267 | + plugin::EventObserver::afterInsertRecord(table, NULL, 0); |
1268 | + observer1Called= observer1.getObserveEventDoCalled(); |
1269 | + observer2Called= observer2.getObserveEventDoCalled(); |
1270 | + |
1271 | + EXPECT_EQ(expected, observer1Called); |
1272 | + EXPECT_EQ(expected, observer2Called); |
1273 | +} |
1274 | + |
1275 | +TEST_P(EventObserverEventTest, beforeDeleteRecord) |
1276 | +{ |
1277 | + plugin::EventObserver::registerTableEvents(*table_share); |
1278 | + |
1279 | + plugin::EventObserver::beforeDeleteRecord(table, NULL); |
1280 | + observer1Called= observer1.getObserveEventDoCalled(); |
1281 | + observer2Called= observer2.getObserveEventDoCalled(); |
1282 | + |
1283 | + EXPECT_EQ(expected, observer1Called); |
1284 | + EXPECT_EQ(expected, observer2Called); |
1285 | +} |
1286 | + |
1287 | +TEST_P(EventObserverEventTest, afterDeleteRecord) |
1288 | +{ |
1289 | + plugin::EventObserver::registerTableEvents(*table_share); |
1290 | + |
1291 | + plugin::EventObserver::afterDeleteRecord(table, NULL, 0); |
1292 | + observer1Called= observer1.getObserveEventDoCalled(); |
1293 | + observer2Called= observer2.getObserveEventDoCalled(); |
1294 | + |
1295 | + EXPECT_EQ(expected, observer1Called); |
1296 | + EXPECT_EQ(expected, observer2Called); |
1297 | +} |
1298 | + |
1299 | +TEST_P(EventObserverEventTest, beforeUpdateRecord) |
1300 | +{ |
1301 | + plugin::EventObserver::registerTableEvents(*table_share); |
1302 | + |
1303 | + plugin::EventObserver::beforeUpdateRecord(table, NULL, NULL); |
1304 | + observer1Called= observer1.getObserveEventDoCalled(); |
1305 | + observer2Called= observer2.getObserveEventDoCalled(); |
1306 | + |
1307 | + EXPECT_EQ(expected, observer1Called); |
1308 | + EXPECT_EQ(expected, observer2Called); |
1309 | +} |
1310 | + |
1311 | +TEST_P(EventObserverEventTest, afterUpdateRecord) |
1312 | +{ |
1313 | + plugin::EventObserver::registerTableEvents(*table_share); |
1314 | + |
1315 | + plugin::EventObserver::afterUpdateRecord(table, NULL, NULL, 0); |
1316 | + observer1Called= observer1.getObserveEventDoCalled(); |
1317 | + observer2Called= observer2.getObserveEventDoCalled(); |
1318 | + |
1319 | + EXPECT_EQ(expected, observer1Called); |
1320 | + EXPECT_EQ(expected, observer2Called); |
1321 | +} |
1322 | + |
1323 | + |
1324 | + |
1325 | +TEST_P(EventObserverEventTest, beforeCreateDatabase) |
1326 | +{ |
1327 | + plugin::EventObserver::registerSessionEvents(*fake_session); |
1328 | + |
1329 | + plugin::EventObserver::beforeCreateDatabase(*fake_session, db); |
1330 | + observer1Called= observer1.getObserveEventDoCalled(); |
1331 | + observer2Called= observer2.getObserveEventDoCalled(); |
1332 | + |
1333 | + EXPECT_EQ(expected, observer1Called); |
1334 | + EXPECT_EQ(expected, observer2Called); |
1335 | +} |
1336 | + |
1337 | +TEST_P(EventObserverEventTest, afterCreateDatabase) |
1338 | +{ |
1339 | + plugin::EventObserver::registerSessionEvents(*fake_session); |
1340 | + |
1341 | + plugin::EventObserver::afterCreateDatabase(*fake_session, db, 0); |
1342 | + observer1Called= observer1.getObserveEventDoCalled(); |
1343 | + observer2Called= observer2.getObserveEventDoCalled(); |
1344 | + |
1345 | + EXPECT_EQ(expected, observer1Called); |
1346 | + EXPECT_EQ(expected, observer2Called); |
1347 | +} |
1348 | + |
1349 | +TEST_P(EventObserverEventTest, beforeDropDatabase) |
1350 | +{ |
1351 | + plugin::EventObserver::registerSessionEvents(*fake_session); |
1352 | + |
1353 | + plugin::EventObserver::beforeDropDatabase(*fake_session, db); |
1354 | + observer1Called= observer1.getObserveEventDoCalled(); |
1355 | + observer2Called= observer2.getObserveEventDoCalled(); |
1356 | + |
1357 | + EXPECT_EQ(expected, observer1Called); |
1358 | + EXPECT_EQ(expected, observer2Called); |
1359 | +} |
1360 | + |
1361 | +TEST_P(EventObserverEventTest, afterDropDatabase) |
1362 | +{ |
1363 | + plugin::EventObserver::registerSessionEvents(*fake_session); |
1364 | + |
1365 | + plugin::EventObserver::afterDropDatabase(*fake_session, db, 0); |
1366 | + observer1Called= observer1.getObserveEventDoCalled(); |
1367 | + observer2Called= observer2.getObserveEventDoCalled(); |
1368 | + |
1369 | + EXPECT_EQ(expected, observer1Called); |
1370 | + EXPECT_EQ(expected, observer2Called); |
1371 | +} |
1372 | |
1373 | === added file 'unittests/plugin/function_test.cc' |
1374 | --- unittests/plugin/function_test.cc 1970-01-01 00:00:00 +0000 |
1375 | +++ unittests/plugin/function_test.cc 2010-08-15 23:41:09 +0000 |
1376 | @@ -0,0 +1,84 @@ |
1377 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1378 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1379 | +* |
1380 | +* Copyright (C) 2010 Pawel Blokus |
1381 | +* |
1382 | +* This program is free software; you can redistribute it and/or modify |
1383 | +* it under the terms of the GNU General Public License as published by |
1384 | +* the Free Software Foundation; either version 2 of the License, or |
1385 | +* (at your option) any later version. |
1386 | +* |
1387 | +* This program is distributed in the hope that it will be useful, |
1388 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
1389 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1390 | +* GNU General Public License for more details. |
1391 | +* |
1392 | +* You should have received a copy of the GNU General Public License |
1393 | +* along with this program; if not, write to the Free Software |
1394 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1395 | +*/ |
1396 | + |
1397 | +#include "config.h" |
1398 | + |
1399 | +#include <cstring> |
1400 | +#include <drizzled/plugin/function.h> |
1401 | +#include <gtest/gtest.h> |
1402 | + |
1403 | +#include "plugin_stubs.h" |
1404 | + |
1405 | +using namespace drizzled; |
1406 | + |
1407 | +TEST(FunctionTest, addPlugin_shouldReturn_False) |
1408 | +{ |
1409 | + bool result; |
1410 | + FunctionStub *function= new FunctionStub("Function"); |
1411 | + |
1412 | + result= plugin::Function::addPlugin(function); |
1413 | + |
1414 | + plugin::Function::removePlugin(function); |
1415 | + delete function; |
1416 | + |
1417 | + ASSERT_FALSE(result); |
1418 | +} |
1419 | + |
1420 | +TEST(FunctionTest, addPlugin_addSecondPluginWithIdenticalName_shouldReturn_True) |
1421 | +{ |
1422 | + bool result; |
1423 | + FunctionStub *function= new FunctionStub("Function"); |
1424 | + FunctionStub *function2= new FunctionStub("Function"); |
1425 | + |
1426 | + plugin::Function::addPlugin(function); |
1427 | + result= plugin::Function::addPlugin(function2); |
1428 | + |
1429 | + plugin::Function::removePlugin(function); |
1430 | + delete function; |
1431 | + delete function2; |
1432 | + |
1433 | + ASSERT_TRUE(result); |
1434 | +} |
1435 | + |
1436 | +TEST(FunctionTest, get_addedFunctionPlugin_shouldReturn_pointerToPlugin) |
1437 | +{ |
1438 | + const plugin::Function *function_ptr; |
1439 | + const char name[]= "Function"; |
1440 | + FunctionStub *function= new FunctionStub(name); |
1441 | + plugin::Function::addPlugin(function); |
1442 | + |
1443 | + function_ptr= plugin::Function::get(name, strlen(name)); |
1444 | + |
1445 | + plugin::Function::removePlugin(function); |
1446 | + delete function; |
1447 | + |
1448 | + ASSERT_EQ(function, function_ptr); |
1449 | +} |
1450 | + |
1451 | +TEST(FunctionTest, get_notAddedFunctionPlugin_shouldReturn_NULL) |
1452 | +{ |
1453 | + const plugin::Function *function_ptr; |
1454 | + const char name[]= "Function"; |
1455 | + |
1456 | + function_ptr= plugin::Function::get(name, strlen(name)); |
1457 | + |
1458 | + ASSERT_EQ(NULL, function_ptr); |
1459 | +} |
1460 | + |
1461 | \ No newline at end of file |
1462 | |
1463 | === added file 'unittests/plugin/listen_tcp_test.cc' |
1464 | --- unittests/plugin/listen_tcp_test.cc 1970-01-01 00:00:00 +0000 |
1465 | +++ unittests/plugin/listen_tcp_test.cc 2010-08-15 23:41:09 +0000 |
1466 | @@ -0,0 +1,1 @@ |
1467 | + |
1468 | |
1469 | === added file 'unittests/plugin/listen_test.cc' |
1470 | --- unittests/plugin/listen_test.cc 1970-01-01 00:00:00 +0000 |
1471 | +++ unittests/plugin/listen_test.cc 2010-08-15 23:41:09 +0000 |
1472 | @@ -0,0 +1,86 @@ |
1473 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1474 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1475 | +* |
1476 | +* Copyright (C) 2010 Pawel Blokus |
1477 | +* |
1478 | +* This program is free software; you can redistribute it and/or modify |
1479 | +* it under the terms of the GNU General Public License as published by |
1480 | +* the Free Software Foundation; either version 2 of the License, or |
1481 | +* (at your option) any later version. |
1482 | +* |
1483 | +* This program is distributed in the hope that it will be useful, |
1484 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
1485 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1486 | +* GNU General Public License for more details. |
1487 | +* |
1488 | +* You should have received a copy of the GNU General Public License |
1489 | +* along with this program; if not, write to the Free Software |
1490 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1491 | +*/ |
1492 | + |
1493 | +#include "config.h" |
1494 | + |
1495 | +#include <drizzled/plugin/listen.h> |
1496 | +#include <gtest/gtest.h> |
1497 | +#include <unistd.h> |
1498 | + |
1499 | +#include "plugin_stubs.h" |
1500 | + |
1501 | +using namespace drizzled; |
1502 | + |
1503 | +TEST(ListenTest, setup_onePluginAdded_noFileDescriptorsRegistered_shouldReturn_True) |
1504 | +{ |
1505 | + bool result; |
1506 | + ListenStub pluginStub("ListenStub"); |
1507 | + plugin::Listen::addPlugin(&pluginStub); |
1508 | + |
1509 | + result= plugin::Listen::setup(); |
1510 | + |
1511 | + ASSERT_TRUE(result); |
1512 | + |
1513 | + plugin::Listen::removePlugin(&pluginStub); |
1514 | +} |
1515 | + |
1516 | +TEST(ListenTest, setup_onePluginAdded_oneFileDescriptorRegistered_shouldReturn_False) |
1517 | +{ |
1518 | + bool result; |
1519 | + ListenStub pluginStub("ListenStub"); |
1520 | + pluginStub.setFileDescriptorToSet(111);/* some rubbish number, not an actual file descriptor*/ |
1521 | + plugin::Listen::addPlugin(&pluginStub); |
1522 | + |
1523 | + result= plugin::Listen::setup(); |
1524 | + |
1525 | + ASSERT_FALSE(result); |
1526 | + |
1527 | + plugin::Listen::removePlugin(&pluginStub); |
1528 | + plugin::Listen::shutdown(); |
1529 | + plugin::Listen::getClient(); |
1530 | +} |
1531 | + |
1532 | +TEST(ListenTest, getClient_onePluginAdded_oneFileDescriptorRegisteredAndWrittenTo_shouldReturn_setClientPointer) |
1533 | +{ |
1534 | + ListenStub pluginStub("ListenStub"); |
1535 | + int sample_pipe[2]; |
1536 | + ssize_t bytes; |
1537 | + plugin::Client *returnedClient; |
1538 | + int ret; |
1539 | + |
1540 | + /* the necessary setup */ |
1541 | + ret= pipe(sample_pipe); |
1542 | + pluginStub.setFileDescriptorToSet(sample_pipe[0]); |
1543 | + pluginStub.setClientPointerToReturn((plugin::Client *) 123456); |
1544 | + plugin::Listen::addPlugin(&pluginStub); |
1545 | + plugin::Listen::setup(); |
1546 | + |
1547 | + /* need to write first becasue the internal reads are blocking */ |
1548 | + bytes= write(sample_pipe[1], "\0", 1); |
1549 | + ASSERT_EQ(1, bytes); |
1550 | + returnedClient= plugin::Listen::getClient(); |
1551 | + |
1552 | + ASSERT_EQ(123456, (size_t) returnedClient); |
1553 | + |
1554 | + plugin::Listen::removePlugin(&pluginStub); |
1555 | + plugin::Listen::shutdown(); |
1556 | + plugin::Listen::getClient(); |
1557 | +} |
1558 | + |
1559 | |
1560 | === added file 'unittests/plugin/logging_test.cc' |
1561 | --- unittests/plugin/logging_test.cc 1970-01-01 00:00:00 +0000 |
1562 | +++ unittests/plugin/logging_test.cc 2010-08-15 23:41:09 +0000 |
1563 | @@ -0,0 +1,91 @@ |
1564 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
1565 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
1566 | + * |
1567 | + * Copyright (C) 2010 Pawel Blokus |
1568 | + * |
1569 | + * This program is free software; you can redistribute it and/or modify |
1570 | + * it under the terms of the GNU General Public License as published by |
1571 | + * the Free Software Foundation; either version 2 of the License, or |
1572 | + * (at your option) any later version. |
1573 | + * |
1574 | + * This program is distributed in the hope that it will be useful, |
1575 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1576 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1577 | + * GNU General Public License for more details. |
1578 | + * |
1579 | + * You should have received a copy of the GNU General Public License |
1580 | + * along with this program; if not, write to the Free Software |
1581 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1582 | + */ |
1583 | + |
1584 | +#include "config.h" |
1585 | + |
1586 | +#include <drizzled/plugin/logging.h> |
1587 | +#include <gtest/gtest.h> |
1588 | + |
1589 | +#include "plugin_stubs.h" |
1590 | +#include "../generator.h" |
1591 | + |
1592 | +using namespace drizzled; |
1593 | + |
1594 | +class LoggingTest : public ::testing::Test |
1595 | +{ |
1596 | +protected: |
1597 | + LoggingStub plugin1, plugin2; |
1598 | +public: |
1599 | + LoggingTest() |
1600 | + : plugin1("LoggingStub1"), |
1601 | + plugin2("LoggingStub2") |
1602 | + {} |
1603 | + |
1604 | + virtual void SetUp() |
1605 | + { |
1606 | + plugin::Logging::addPlugin(&plugin1); |
1607 | + plugin::Logging::addPlugin(&plugin2); |
1608 | + } |
1609 | + |
1610 | + virtual void TearDown() |
1611 | + { |
1612 | + plugin::Logging::removePlugin(&plugin1); |
1613 | + plugin::Logging::removePlugin(&plugin2); |
1614 | + } |
1615 | +}; |
1616 | + |
1617 | +TEST_F(LoggingTest, preDo_twoPluginsAdded_shouldCall_pre_only_OnBothPlugins) |
1618 | +{ |
1619 | + plugin::Logging::preDo(NULL); |
1620 | + |
1621 | + EXPECT_TRUE(plugin1.getPreCalled()); |
1622 | + EXPECT_FALSE(plugin1.getPostCalled()); |
1623 | + EXPECT_FALSE(plugin1.getPostEndCalled()); |
1624 | + |
1625 | + EXPECT_TRUE(plugin2.getPreCalled()); |
1626 | + EXPECT_FALSE(plugin2.getPostCalled()); |
1627 | + EXPECT_FALSE(plugin2.getPostEndCalled()); |
1628 | +} |
1629 | + |
1630 | +TEST_F(LoggingTest, postDo_twoPluginsAdded_shouldCall_post_only_OnBothPlugins) |
1631 | +{ |
1632 | + plugin::Logging::postDo(NULL); |
1633 | + |
1634 | + EXPECT_FALSE(plugin1.getPreCalled()); |
1635 | + EXPECT_TRUE(plugin1.getPostCalled()); |
1636 | + EXPECT_FALSE(plugin1.getPostEndCalled()); |
1637 | + |
1638 | + EXPECT_FALSE(plugin2.getPreCalled()); |
1639 | + EXPECT_TRUE(plugin2.getPostCalled()); |
1640 | + EXPECT_FALSE(plugin2.getPostEndCalled()); |
1641 | +} |
1642 | + |
1643 | +TEST_F(LoggingTest, postEndDo_twoPluginsAdded_shouldCall_postEnd_only_OnBothPlugins) |
1644 | +{ |
1645 | + plugin::Logging::postEndDo(NULL); |
1646 | + |
1647 | + EXPECT_FALSE(plugin1.getPreCalled()); |
1648 | + EXPECT_FALSE(plugin1.getPostCalled()); |
1649 | + EXPECT_TRUE(plugin1.getPostEndCalled()); |
1650 | + |
1651 | + EXPECT_FALSE(plugin2.getPreCalled()); |
1652 | + EXPECT_FALSE(plugin2.getPostCalled()); |
1653 | + EXPECT_TRUE(plugin2.getPostEndCalled()); |
1654 | +} |
1655 | |
1656 | === modified file 'unittests/plugin/plugin_stubs.h' |
1657 | --- unittests/plugin/plugin_stubs.h 2010-06-10 20:26:28 +0000 |
1658 | +++ unittests/plugin/plugin_stubs.h 2010-08-15 23:41:09 +0000 |
1659 | @@ -26,11 +26,22 @@ |
1660 | |
1661 | #include <cstring> |
1662 | #include <drizzled/plugin/authentication.h> |
1663 | -#include <drizzled/plugin/client.h> |
1664 | +#include <drizzled/plugin/authorization.h> |
1665 | #include <drizzled/plugin/error_message.h> |
1666 | +#include <drizzled/plugin/event_observer.h> |
1667 | +#include <drizzled/plugin/function.h> |
1668 | +#include <drizzled/plugin/listen.h> |
1669 | +#include <drizzled/plugin/logging.h> |
1670 | +#include <drizzled/plugin/null_client.h> |
1671 | +#include <drizzled/plugin/query_cache.h> |
1672 | +#include <drizzled/plugin/query_rewrite.h> |
1673 | +#include <drizzled/plugin/scheduler.h> |
1674 | +#include <drizzled/plugin/storage_engine.h> |
1675 | +#include <drizzled/plugin/transactional_storage_engine.h> |
1676 | +#include <drizzled/plugin/xa_resource_manager.h> |
1677 | #include <string> |
1678 | - |
1679 | -class ClientStub : public drizzled::plugin::Client |
1680 | + |
1681 | +class ClientStub : public drizzled::plugin::NullClient |
1682 | { |
1683 | protected: |
1684 | bool store_ret_val; |
1685 | @@ -53,94 +64,6 @@ |
1686 | last_call_char_ptr= ptr; |
1687 | } |
1688 | |
1689 | - virtual ~ClientStub() {} |
1690 | - |
1691 | - /** |
1692 | - * Get attached session from the client object. |
1693 | - * @retval Session object that is attached, NULL if none. |
1694 | - */ |
1695 | - virtual drizzled::Session *getSession(void) |
1696 | - { |
1697 | - return Client::getSession(); |
1698 | - } |
1699 | - |
1700 | - /** |
1701 | - * Attach session to the client object. |
1702 | - * @param[in] session_arg Session object to attach, or NULL to clear. |
1703 | - */ |
1704 | - virtual void setSession(drizzled::Session *session_arg) |
1705 | - { |
1706 | - Client::setSession(session_arg); |
1707 | - } |
1708 | - |
1709 | - /** |
1710 | - * Get file descriptor associated with client object. |
1711 | - * @retval File descriptor that is attached, -1 if none. |
1712 | - */ |
1713 | - virtual int getFileDescriptor(void) { return 0; }; |
1714 | - |
1715 | - /** |
1716 | - * Check to see if the client is currently connected. |
1717 | - * @retval Boolean value representing connected state. |
1718 | - */ |
1719 | - virtual bool isConnected(void) { return false; }; |
1720 | - |
1721 | - /** |
1722 | - * Check to see if the client is actively reading. |
1723 | - * @retval Boolean value representing reading state. |
1724 | - */ |
1725 | - virtual bool isReading(void) { return false; }; |
1726 | - |
1727 | - /** |
1728 | - * Check to see if the client is actively writing. |
1729 | - * @retval Boolean value representing writing state. |
1730 | - */ |
1731 | - virtual bool isWriting(void) { return false; }; |
1732 | - |
1733 | - /** |
1734 | - * Flush all data that has been buffered with store() methods. |
1735 | - * @retval Boolean indicating success or failure. |
1736 | - */ |
1737 | - virtual bool flush(void) { return false; }; |
1738 | - |
1739 | - /** |
1740 | - * Close the client object. |
1741 | - */ |
1742 | - virtual void close(void) {}; |
1743 | - |
1744 | - /** |
1745 | - * Perform handshake and authorize client if needed. |
1746 | - */ |
1747 | - virtual bool authenticate(void) { return false; }; |
1748 | - |
1749 | - /** |
1750 | - * Read command from client. |
1751 | - */ |
1752 | - virtual bool readCommand(char **packet, uint32_t *packet_length) |
1753 | - { |
1754 | - (void)packet; |
1755 | - (void)packet_length; |
1756 | - return false; |
1757 | - }; |
1758 | - |
1759 | - /* Send responses. */ |
1760 | - virtual void sendOK(void) {}; |
1761 | - virtual void sendEOF(void) {}; |
1762 | - virtual void sendError(uint32_t sql_errno, const char *err) |
1763 | - { |
1764 | - (void)sql_errno; |
1765 | - (void)err; |
1766 | - }; |
1767 | - |
1768 | - /** |
1769 | - * Send field list for result set. |
1770 | - */ |
1771 | - virtual bool sendFields(drizzled::List<drizzled::Item> *list) |
1772 | - { |
1773 | - (void)list; |
1774 | - return false; |
1775 | - }; |
1776 | - |
1777 | /* Send result fields in various forms. */ |
1778 | virtual bool store(drizzled::Field *from) |
1779 | { |
1780 | @@ -192,18 +115,20 @@ |
1781 | { |
1782 | return Client::store(from); |
1783 | } |
1784 | - |
1785 | - /* Try to remove these. */ |
1786 | - virtual bool haveMoreData(void) { return false; }; |
1787 | - virtual bool haveError(void) { return false; }; |
1788 | - virtual bool wasAborted(void) { return false;}; |
1789 | }; |
1790 | |
1791 | class ErrorMessageStub : public drizzled::plugin::ErrorMessage |
1792 | { |
1793 | - |
1794 | + bool errmsgCalled, errmsgReturn; |
1795 | public: |
1796 | - ErrorMessageStub() : ErrorMessage("ErrorMessageStub") {} |
1797 | + ErrorMessageStub(std::string name_arg) |
1798 | + : ErrorMessage(name_arg), |
1799 | + errmsgCalled(false), |
1800 | + errmsgReturn(false) |
1801 | + {} |
1802 | + |
1803 | + void setErrmsgReturn(bool ret) { errmsgReturn= ret; }; |
1804 | + bool getErrmsgCalled() { return errmsgCalled; }; |
1805 | |
1806 | virtual bool errmsg(drizzled::Session *session, int priority, const char *format, va_list ap) |
1807 | { |
1808 | @@ -211,7 +136,8 @@ |
1809 | (void)priority; |
1810 | (void)format; |
1811 | (void)ap; |
1812 | - return false; |
1813 | + errmsgCalled= true; |
1814 | + return errmsgReturn; |
1815 | } |
1816 | }; |
1817 | |
1818 | @@ -228,7 +154,7 @@ |
1819 | |
1820 | void set_authenticate_return(bool value) |
1821 | { |
1822 | - authenticate_return = value; |
1823 | + authenticate_return= value; |
1824 | } |
1825 | |
1826 | virtual bool authenticate(const drizzled::SecurityContext &sctx, const std::string &passwd) |
1827 | @@ -239,4 +165,531 @@ |
1828 | }; |
1829 | }; |
1830 | |
1831 | +class SchedulerStub : public drizzled::plugin::Scheduler |
1832 | +{ |
1833 | + public: |
1834 | + SchedulerStub(std::string name_arg) |
1835 | + : Scheduler(name_arg) |
1836 | + {} |
1837 | + |
1838 | + /** |
1839 | + * Add a session to the scheduler. When the scheduler is ready to run the |
1840 | + * session, it should call session->run(). |
1841 | + */ |
1842 | + virtual bool addSession(drizzled::Session *) { return true; } |
1843 | +}; |
1844 | + |
1845 | +class EventObserverStub : public drizzled::plugin::EventObserver |
1846 | +{ |
1847 | +private: |
1848 | + bool registerTableEventsDoCalled; |
1849 | + bool registerSchemaEventsDoCalled; |
1850 | + bool registerSessionEventsDoCalled; |
1851 | + bool observeEventDoCalled; |
1852 | + bool registerAll; |
1853 | +public: |
1854 | + EventObserverStub(std::string name_arg) |
1855 | + : EventObserver(name_arg), |
1856 | + registerTableEventsDoCalled(false), |
1857 | + registerSchemaEventsDoCalled(false), |
1858 | + registerSessionEventsDoCalled(false), |
1859 | + observeEventDoCalled(false), |
1860 | + registerAll(false) |
1861 | + {} |
1862 | + |
1863 | + bool getRegisterTableEventsDoCalled() { return registerTableEventsDoCalled; }; |
1864 | + bool getRegisterSchemaEventsDoCalled() { return registerSchemaEventsDoCalled; }; |
1865 | + bool getRegisterSessionEventsDoCalled() { return registerSessionEventsDoCalled; }; |
1866 | + bool getObserveEventDoCalled() { return observeEventDoCalled; }; |
1867 | + |
1868 | + void setRegisterAll(bool reg) { registerAll= reg; }; |
1869 | + |
1870 | + virtual bool observeEventDo(drizzled::plugin::EventData &) |
1871 | + { |
1872 | + observeEventDoCalled= true; |
1873 | + return false; |
1874 | + }; |
1875 | + virtual void registerTableEventsDo(drizzled::TableShare &, drizzled::plugin::EventObserverList &observers) |
1876 | + { |
1877 | + if (registerAll) |
1878 | + { |
1879 | + registerEvent(observers, BEFORE_INSERT_RECORD); |
1880 | + registerEvent(observers, AFTER_INSERT_RECORD); |
1881 | + registerEvent(observers, BEFORE_UPDATE_RECORD); |
1882 | + registerEvent(observers, AFTER_UPDATE_RECORD); |
1883 | + registerEvent(observers, BEFORE_DELETE_RECORD); |
1884 | + registerEvent(observers, AFTER_DELETE_RECORD); |
1885 | + } |
1886 | + registerTableEventsDoCalled= true; |
1887 | + } |
1888 | + virtual void registerSchemaEventsDo(const std::string &/*db*/, drizzled::plugin::EventObserverList &observers) |
1889 | + { |
1890 | + if (registerAll) |
1891 | + { |
1892 | + registerEvent(observers, BEFORE_DROP_TABLE); |
1893 | + registerEvent(observers, AFTER_DROP_TABLE); |
1894 | + registerEvent(observers, BEFORE_RENAME_TABLE); |
1895 | + registerEvent(observers, AFTER_RENAME_TABLE); |
1896 | + } |
1897 | + registerSchemaEventsDoCalled= true; |
1898 | + } |
1899 | + virtual void registerSessionEventsDo(drizzled::Session &, drizzled::plugin::EventObserverList &observers) |
1900 | + { |
1901 | + if (registerAll) |
1902 | + { |
1903 | + registerEvent(observers, BEFORE_CREATE_DATABASE); |
1904 | + registerEvent(observers, AFTER_CREATE_DATABASE); |
1905 | + registerEvent(observers, BEFORE_DROP_DATABASE); |
1906 | + registerEvent(observers, AFTER_DROP_DATABASE); |
1907 | + } |
1908 | + registerSessionEventsDoCalled= true; |
1909 | + } |
1910 | +}; |
1911 | + |
1912 | +class FunctionStub : public drizzled::plugin::Function |
1913 | +{ |
1914 | +public: |
1915 | + FunctionStub(std::string in_name) |
1916 | + : Function(in_name) |
1917 | + {} |
1918 | + |
1919 | + virtual result_type operator()(argument_type root) const |
1920 | + { |
1921 | + (void)root; |
1922 | + return result_type(); |
1923 | + } |
1924 | +}; |
1925 | + |
1926 | +class ListenStub : public drizzled::plugin::Listen |
1927 | +{ |
1928 | + int fileDescriptorToSet; |
1929 | + drizzled::plugin::Client *clientPointerToReturn; |
1930 | +public: |
1931 | + ListenStub(std::string name_arg) : |
1932 | + Listen(name_arg), |
1933 | + fileDescriptorToSet(0), |
1934 | + clientPointerToReturn(NULL) |
1935 | + {} |
1936 | + |
1937 | + void setFileDescriptorToSet(int file_descriptor) { fileDescriptorToSet= file_descriptor; }; |
1938 | + void setClientPointerToReturn(drizzled::plugin::Client *pointer) |
1939 | + { |
1940 | + clientPointerToReturn= pointer; |
1941 | + }; |
1942 | + |
1943 | + virtual bool getFileDescriptors(std::vector<int> &fds) |
1944 | + { |
1945 | + if (fileDescriptorToSet != 0) |
1946 | + fds.push_back(fileDescriptorToSet); |
1947 | + return false; |
1948 | + }; |
1949 | + virtual drizzled::plugin::Client *getClient(int fd) |
1950 | + { |
1951 | + (void)fd; |
1952 | + return clientPointerToReturn; |
1953 | + }; |
1954 | +}; |
1955 | + |
1956 | +class LoggingStub : public drizzled::plugin::Logging |
1957 | +{ |
1958 | + bool preCalled, postCalled, postEndCalled; |
1959 | +public: |
1960 | + LoggingStub(std::string name_arg) |
1961 | + : Logging(name_arg), |
1962 | + preCalled(false), |
1963 | + postCalled(false), |
1964 | + postEndCalled(false) |
1965 | + {} |
1966 | + |
1967 | + bool getPreCalled() { return preCalled; }; |
1968 | + bool getPostCalled() { return postCalled; }; |
1969 | + bool getPostEndCalled() { return postEndCalled; }; |
1970 | + |
1971 | + virtual bool pre(drizzled::Session *) |
1972 | + { |
1973 | + preCalled= true; |
1974 | + return false; |
1975 | + } |
1976 | + virtual bool post(drizzled::Session *) |
1977 | + { |
1978 | + postCalled= true; |
1979 | + return false; |
1980 | + } |
1981 | + virtual bool postEnd(drizzled::Session*) |
1982 | + { |
1983 | + postEndCalled= true; |
1984 | + return false; |
1985 | + } |
1986 | +}; |
1987 | + |
1988 | +class QueryCacheStub : public drizzled::plugin::QueryCache |
1989 | +{ |
1990 | + bool tryFetchAndSendCalled, setCalled, invalidateTableCalled, invalidateDbCalled, flushCalled; |
1991 | +public: |
1992 | + QueryCacheStub(std::string name_arg) |
1993 | + : QueryCache(name_arg), |
1994 | + tryFetchAndSendCalled(false), |
1995 | + setCalled(false), |
1996 | + invalidateTableCalled(false), |
1997 | + invalidateDbCalled(false), |
1998 | + flushCalled(false) |
1999 | + {} |
2000 | + |
2001 | + bool getTryFetchAndSendCalled() { return tryFetchAndSendCalled; }; |
2002 | + bool getSetCalled() { return setCalled; }; |
2003 | + bool getInvalidateTableCalled() { return invalidateTableCalled; }; |
2004 | + bool getInvalidateDbCalled() { return invalidateDbCalled; }; |
2005 | + bool getFlushCalled() { return flushCalled; }; |
2006 | + |
2007 | + virtual bool tryFetchAndSend(drizzled::Session *session, bool is_transactional) |
2008 | + { |
2009 | + (void)session; |
2010 | + (void)is_transactional; |
2011 | + tryFetchAndSendCalled= true; |
2012 | + return false; |
2013 | + } |
2014 | + |
2015 | + virtual bool set(drizzled::Session *session, bool is_transactional) |
2016 | + { |
2017 | + (void)session; |
2018 | + (void)is_transactional; |
2019 | + setCalled= true; |
2020 | + return false; |
2021 | + } |
2022 | + virtual bool invalidateTable(drizzled::Session *session, bool is_transactional) |
2023 | + { |
2024 | + (void)session; |
2025 | + (void)is_transactional; |
2026 | + invalidateTableCalled= true; |
2027 | + return false; |
2028 | + } |
2029 | + virtual bool invalidateDb(drizzled::Session *session, const char *db_name, bool is_transactional) |
2030 | + { |
2031 | + (void)session; |
2032 | + (void)db_name; |
2033 | + (void)is_transactional; |
2034 | + invalidateDbCalled= true; |
2035 | + return false; |
2036 | + } |
2037 | + virtual bool flush(drizzled::Session *session) |
2038 | + { |
2039 | + (void)session; |
2040 | + flushCalled= true; |
2041 | + return false; |
2042 | + } |
2043 | +}; |
2044 | + |
2045 | +class QueryRewriterStub : public drizzled::plugin::QueryRewriter |
2046 | +{ |
2047 | + bool rewriteCalled; |
2048 | +public: |
2049 | + QueryRewriterStub(std::string name_arg) |
2050 | + : QueryRewriter(name_arg), |
2051 | + rewriteCalled(false) |
2052 | + {} |
2053 | + |
2054 | + bool getRewriteCalled() { return rewriteCalled; }; |
2055 | + |
2056 | + virtual void rewrite(const std::string &schema, std::string &to_rewrite) |
2057 | + { |
2058 | + (void)schema; |
2059 | + (void)to_rewrite; |
2060 | + rewriteCalled= true; |
2061 | + } |
2062 | + |
2063 | +}; |
2064 | + |
2065 | +class AuthorizationStub : public drizzled::plugin::Authorization |
2066 | +{ |
2067 | + int restrictSchemaReturnCount;/** This many first schemas will be restricted */ |
2068 | + bool restrictTableReturn, restrictProcessReturn; |
2069 | +public: |
2070 | + AuthorizationStub(std::string name_arg) |
2071 | + : Authorization(name_arg), |
2072 | + restrictSchemaReturnCount(0), |
2073 | + restrictTableReturn(false), |
2074 | + restrictProcessReturn(false) |
2075 | + {} |
2076 | + |
2077 | + void setRestrictSchemaReturnCount(int ret) { restrictSchemaReturnCount= ret; }; |
2078 | + void setRestrictTableReturn(bool ret) { restrictTableReturn= ret; }; |
2079 | + void setRestrictProcessReturn(bool ret) { restrictProcessReturn= ret; }; |
2080 | + |
2081 | + virtual bool restrictSchema(const drizzled::SecurityContext &user_ctx, |
2082 | + drizzled::SchemaIdentifier &schema) |
2083 | + { |
2084 | + (void)user_ctx; |
2085 | + (void)schema; |
2086 | + return restrictSchemaReturnCount-- > 0; |
2087 | + } |
2088 | + virtual bool restrictTable(const drizzled::SecurityContext &user_ctx, |
2089 | + drizzled::TableIdentifier &table) |
2090 | + { |
2091 | + (void)user_ctx; |
2092 | + (void)table; |
2093 | + return restrictTableReturn; |
2094 | + } |
2095 | + virtual bool restrictProcess(const drizzled::SecurityContext &user_ctx, |
2096 | + const drizzled::SecurityContext &session_ctx) |
2097 | + { |
2098 | + (void)user_ctx; |
2099 | + (void)session_ctx; |
2100 | + return restrictProcessReturn; |
2101 | + } |
2102 | + |
2103 | +}; |
2104 | + |
2105 | +class StorageEngineStub : public drizzled::plugin::StorageEngine |
2106 | +{ |
2107 | + bool doGetSchemaIdentifiersCalled, doGetSchemaDefinitionCalled, doCreateSchemaCalled; |
2108 | + bool doAlterSchemaCalled, doDropSchemaCalled, closeConnectionCalled, flushLogsCalled; |
2109 | + bool doRenameTableCalled, doGetTableDefinitionCalled, doDropTableCalled, doCanCreateTableCalled; |
2110 | + bool doDoesTableExistCalled; |
2111 | + bool dropSchemaReturn, alterSchemaReturn, doesTableExistReturn; |
2112 | + int doGetTableDefinitionReturn; |
2113 | + std::string engineNameToSet; |
2114 | + drizzled::message::Table *tableMessageToSet; |
2115 | +public: |
2116 | + StorageEngineStub(std::string name_arg, |
2117 | + const std::bitset<drizzled::HTON_BIT_SIZE> &flags_arg= drizzled::HTON_HAS_SCHEMA_DICTIONARY) |
2118 | + : drizzled::plugin::StorageEngine(name_arg, flags_arg), |
2119 | + doGetSchemaIdentifiersCalled(false), |
2120 | + doGetSchemaDefinitionCalled(false), |
2121 | + doCreateSchemaCalled(false), |
2122 | + doAlterSchemaCalled(false), |
2123 | + doDropSchemaCalled(false), |
2124 | + closeConnectionCalled (false), |
2125 | + flushLogsCalled(false), |
2126 | + doRenameTableCalled(false), |
2127 | + doGetTableDefinitionCalled(false), |
2128 | + doDropTableCalled(false), |
2129 | + doCanCreateTableCalled(false), |
2130 | + doDoesTableExistCalled(false), |
2131 | + dropSchemaReturn(false), |
2132 | + alterSchemaReturn(false), |
2133 | + doesTableExistReturn(false), |
2134 | + doGetTableDefinitionReturn(ENOENT), |
2135 | + tableMessageToSet(NULL) |
2136 | + {} |
2137 | + |
2138 | + bool getDoGetSchemaIdentifiersCalled() { return doGetSchemaIdentifiersCalled; } |
2139 | + bool getDoGetSchemaDefinitionCalled() { return doGetSchemaDefinitionCalled; } |
2140 | + bool getDoCreateSchemaCalled() { return doCreateSchemaCalled; } |
2141 | + bool getDoAlterSchemaCalled() { return doAlterSchemaCalled; } |
2142 | + bool getDoDropSchemaCalled() { return doDropSchemaCalled; } |
2143 | + bool getCloseConnectionCalled() { return closeConnectionCalled; } |
2144 | + bool getFlushLogsCalled() { return flushLogsCalled; } |
2145 | + bool getDoRenameTable() { return doRenameTableCalled; } |
2146 | + bool getDoGetTableDefinitionCalled() { return doGetTableDefinitionCalled; } |
2147 | + bool getDoDropTableCalled() { return doDropTableCalled; } |
2148 | + bool getDoCanCreateTableCalled() { return doCanCreateTableCalled; } |
2149 | + bool getDoDoesTableExistCalled() { return doDoesTableExistCalled; } |
2150 | + |
2151 | + void setDropSchemaReturn(bool val) { dropSchemaReturn= val; } |
2152 | + void setAlterSchemaReturn(bool val) { alterSchemaReturn= val; } |
2153 | + void setEngineNameToSet(const std::string &nameToSet) { engineNameToSet= nameToSet; } |
2154 | + void setDoGetTableDefinitionReturn(int ret) { doGetTableDefinitionReturn= ret; } |
2155 | + void setDoesTableExistReturn(bool ret) { doesTableExistReturn= ret; } |
2156 | + void setTableMessageToSet(drizzled::message::Table *message) { tableMessageToSet= message; } |
2157 | + |
2158 | + /* parameter names are intentionally ommited, so we don't get parameter not used warnings */ |
2159 | + virtual drizzled::Cursor *create(drizzled::TableShare &) |
2160 | + { |
2161 | + return NULL; |
2162 | + }; |
2163 | + virtual int doCreateTable(drizzled::Session &, drizzled::Table &, |
2164 | + const drizzled::TableIdentifier &, |
2165 | + drizzled::message::Table &) { return 0; } |
2166 | + virtual int doRenameTable(drizzled::Session &, const drizzled::TableIdentifier &, |
2167 | + const drizzled::TableIdentifier &) |
2168 | + { |
2169 | + doRenameTableCalled= true; |
2170 | + return 0; |
2171 | + } |
2172 | + virtual void doGetTableNames(drizzled::CachedDirectory &, const drizzled::SchemaIdentifier &, |
2173 | + drizzled::plugin::TableNameList &) {} |
2174 | + virtual void doGetTableIdentifiers(drizzled::CachedDirectory &, |
2175 | + const drizzled::SchemaIdentifier &, |
2176 | + drizzled::TableIdentifiers &) {} |
2177 | + virtual int doDropTable(drizzled::Session &, const drizzled::TableIdentifier &) |
2178 | + { |
2179 | + doDropTableCalled= true; |
2180 | + return 0; |
2181 | + }; |
2182 | + virtual const char **bas_ext() const { return NULL; } |
2183 | + |
2184 | + |
2185 | + virtual void doGetSchemaIdentifiers(drizzled::SchemaIdentifiers&) |
2186 | + { |
2187 | + doGetSchemaIdentifiersCalled= true; |
2188 | + } |
2189 | + |
2190 | + virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::Schema&) |
2191 | + { |
2192 | + doGetSchemaDefinitionCalled= true; |
2193 | + return false; |
2194 | + } |
2195 | + |
2196 | + virtual bool doCreateSchema(const drizzled::message::Schema&) |
2197 | + { |
2198 | + doCreateSchemaCalled= true; |
2199 | + return false; |
2200 | + } |
2201 | + |
2202 | + virtual bool doAlterSchema(const drizzled::message::Schema&) |
2203 | + { |
2204 | + doAlterSchemaCalled= true; |
2205 | + return alterSchemaReturn; |
2206 | + } |
2207 | + |
2208 | + virtual bool doDropSchema(const drizzled::SchemaIdentifier&) |
2209 | + { |
2210 | + doDropSchemaCalled= true; |
2211 | + return dropSchemaReturn; |
2212 | + } |
2213 | + |
2214 | + virtual int close_connection(drizzled::Session *) |
2215 | + { |
2216 | + closeConnectionCalled= true; |
2217 | + return 0; |
2218 | + } |
2219 | + |
2220 | + virtual bool flush_logs() |
2221 | + { |
2222 | + flushLogsCalled= true; |
2223 | + return false; |
2224 | + } |
2225 | + |
2226 | + virtual int doGetTableDefinition(drizzled::Session &session, |
2227 | + const drizzled::TableIdentifier &identifier, |
2228 | + drizzled::message::Table &table_message) |
2229 | + { |
2230 | + (void)session; |
2231 | + (void)identifier; |
2232 | + |
2233 | + if (tableMessageToSet != NULL) |
2234 | + table_message= *tableMessageToSet; |
2235 | + else if (!engineNameToSet.empty()) |
2236 | + table_message.mutable_engine()->set_name(engineNameToSet.c_str()); |
2237 | + |
2238 | + doGetTableDefinitionCalled= true; |
2239 | + return doGetTableDefinitionReturn; |
2240 | + } |
2241 | + |
2242 | + virtual bool doCanCreateTable(const drizzled::TableIdentifier &) |
2243 | + { |
2244 | + doCanCreateTableCalled= true; |
2245 | + return true; |
2246 | + } |
2247 | + |
2248 | + virtual bool doDoesTableExist(drizzled::Session&, const drizzled::TableIdentifier &) |
2249 | + { |
2250 | + doDoesTableExistCalled= true; |
2251 | + return doesTableExistReturn; |
2252 | + } |
2253 | + |
2254 | +}; |
2255 | + |
2256 | +class TransactionalStorageEngineStub : public drizzled::plugin::TransactionalStorageEngine |
2257 | +{ |
2258 | + bool startTransactionCalled, doReleaseTemporaryLatchesCalled; |
2259 | +public: |
2260 | + TransactionalStorageEngineStub(std::string name_arg) |
2261 | + : drizzled::plugin::TransactionalStorageEngine(name_arg, 0), |
2262 | + startTransactionCalled(false), |
2263 | + doReleaseTemporaryLatchesCalled(false) |
2264 | + {} |
2265 | + |
2266 | + bool getStartTransactionCalled() { return startTransactionCalled; }; |
2267 | + bool getDoReleaseTemporaryLatchesCalled() { return doReleaseTemporaryLatchesCalled; }; |
2268 | + |
2269 | + /* parameter names are intentionally ommited, so we don't get parameter not used warnings */ |
2270 | + virtual drizzled::Cursor *create(drizzled::TableShare &) |
2271 | + { |
2272 | + return NULL; |
2273 | + }; |
2274 | + virtual int doCreateTable(drizzled::Session &, drizzled::Table &, |
2275 | + const drizzled::TableIdentifier &, |
2276 | + drizzled::message::Table &) { return 0; } |
2277 | + virtual int doRenameTable(drizzled::Session &, const drizzled::TableIdentifier &, |
2278 | + const drizzled::TableIdentifier &) { return 0; } |
2279 | + virtual void doGetTableNames(drizzled::CachedDirectory &, const drizzled::SchemaIdentifier &, |
2280 | + drizzled::plugin::TableNameList &) {} |
2281 | + virtual void doGetTableIdentifiers(drizzled::CachedDirectory &, |
2282 | + const drizzled::SchemaIdentifier &, |
2283 | + drizzled::TableIdentifiers &) {} |
2284 | + virtual int doDropTable(drizzled::Session &, const drizzled::TableIdentifier &) { return 0; }; |
2285 | + virtual const char **bas_ext() const { return NULL; } |
2286 | + |
2287 | + |
2288 | + virtual int startTransaction(drizzled::Session *session, |
2289 | + drizzled::start_transaction_option_t options) |
2290 | + { |
2291 | + (void)session; |
2292 | + (void)options; |
2293 | + startTransactionCalled= true; |
2294 | + return 0; |
2295 | + } |
2296 | + |
2297 | + virtual int doReleaseTemporaryLatches(drizzled::Session *session) |
2298 | + { |
2299 | + (void)session; |
2300 | + doReleaseTemporaryLatchesCalled= true; |
2301 | + return 0; |
2302 | + } |
2303 | + |
2304 | + /* parameter names are intentionally ommited, so we don't get parameter not used warnings */ |
2305 | + virtual int doSetSavepoint(drizzled::Session *, drizzled::NamedSavepoint &) { return 0;} |
2306 | + virtual int doRollbackToSavepoint(drizzled::Session *, drizzled::NamedSavepoint &) { return 0; } |
2307 | + virtual int doReleaseSavepoint(drizzled::Session *, drizzled::NamedSavepoint &) { return 0; } |
2308 | + virtual int doCommit(drizzled::Session *, bool) { return 0; } |
2309 | + virtual int doRollback(drizzled::Session *, bool ) { return 0; } |
2310 | + |
2311 | +}; |
2312 | + |
2313 | +class XaResourceManagerStub : public drizzled::plugin::XaResourceManager |
2314 | +{ |
2315 | + bool doXaRollbackXidCalled, doXaCommitXidCalled, xaRecoverCalled; |
2316 | + int commitRollbackReturn; |
2317 | + |
2318 | + virtual int doXaCommit(drizzled::Session *, bool) { return 0; } |
2319 | + virtual int doXaRollback(drizzled::Session *, bool) { return 0; } |
2320 | + virtual int doXaPrepare(drizzled::Session *, bool) { return 0; } |
2321 | + |
2322 | + virtual int doXaRollbackXid(drizzled::XID *xid) |
2323 | + { |
2324 | + (void)xid; |
2325 | + doXaRollbackXidCalled= true; |
2326 | + return commitRollbackReturn; |
2327 | + } |
2328 | + |
2329 | + virtual int doXaCommitXid(drizzled::XID *xid) |
2330 | + { |
2331 | + (void)xid; |
2332 | + doXaCommitXidCalled= true; |
2333 | + return commitRollbackReturn; |
2334 | + } |
2335 | + |
2336 | + virtual int doXaRecover(drizzled::XID *append_to, size_t len) |
2337 | + { |
2338 | + (void)append_to; |
2339 | + (void)len; |
2340 | + xaRecoverCalled= true; |
2341 | + return 0; |
2342 | + } |
2343 | +public: |
2344 | + XaResourceManagerStub() |
2345 | + : doXaRollbackXidCalled(false), |
2346 | + doXaCommitXidCalled(false), |
2347 | + xaRecoverCalled(false), |
2348 | + commitRollbackReturn(0) |
2349 | + {} |
2350 | + |
2351 | + bool getDoXaRollbackXidCalled() { return doXaRollbackXidCalled; } |
2352 | + bool getDoXaCommitXidCalled() { return doXaCommitXidCalled; } |
2353 | + bool getXaRecoverCalled() { return xaRecoverCalled; } |
2354 | + |
2355 | + void setCommitRollbackReturn(int value) { commitRollbackReturn= value; } |
2356 | +}; |
2357 | + |
2358 | #endif /* UNITTESTS_STUB_PLUGIN_STUBS_H */ |
2359 | |
2360 | === added file 'unittests/plugin/query_cache_test.cc' |
2361 | --- unittests/plugin/query_cache_test.cc 1970-01-01 00:00:00 +0000 |
2362 | +++ unittests/plugin/query_cache_test.cc 2010-08-15 23:41:09 +0000 |
2363 | @@ -0,0 +1,138 @@ |
2364 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2365 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2366 | +* |
2367 | +* Copyright (C) 2010 Pawel Blokus |
2368 | +* |
2369 | +* This program is free software; you can redistribute it and/or modify |
2370 | +* it under the terms of the GNU General Public License as published by |
2371 | +* the Free Software Foundation; either version 2 of the License, or |
2372 | +* (at your option) any later version. |
2373 | +* |
2374 | +* This program is distributed in the hope that it will be useful, |
2375 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2376 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2377 | +* GNU General Public License for more details. |
2378 | +* |
2379 | +* You should have received a copy of the GNU General Public License |
2380 | +* along with this program; if not, write to the Free Software |
2381 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2382 | +*/ |
2383 | + |
2384 | +#include "config.h" |
2385 | + |
2386 | +#include <drizzled/plugin/query_cache.h> |
2387 | +#include <gtest/gtest.h> |
2388 | + |
2389 | +#include "plugin_stubs.h" |
2390 | + |
2391 | +using namespace drizzled; |
2392 | + |
2393 | + |
2394 | +class QueryCacheTest : public ::testing::Test |
2395 | +{ |
2396 | + protected: |
2397 | + QueryCacheStub plugin1, plugin2; |
2398 | + public: |
2399 | + QueryCacheTest() |
2400 | + : plugin1("QueryCacheStub1"), |
2401 | + plugin2("QueryCacheStub2") |
2402 | + {} |
2403 | + |
2404 | + virtual void SetUp() |
2405 | + { |
2406 | + plugin::QueryCache::addPlugin(&plugin1); |
2407 | + plugin::QueryCache::addPlugin(&plugin2); |
2408 | + } |
2409 | + |
2410 | + virtual void TearDown() |
2411 | + { |
2412 | + plugin::QueryCache::removePlugin(&plugin1); |
2413 | + plugin::QueryCache::removePlugin(&plugin2); |
2414 | + } |
2415 | +}; |
2416 | + |
2417 | +TEST_F(QueryCacheTest, tryFetchAndSendDo_twoPluginAdded_shouldCall_tryFetchAndSend_only_onBoth) |
2418 | +{ |
2419 | + plugin::QueryCache::tryFetchAndSendDo(NULL, false); |
2420 | + |
2421 | + EXPECT_TRUE(plugin1.getTryFetchAndSendCalled()); |
2422 | + EXPECT_FALSE(plugin1.getSetCalled()); |
2423 | + EXPECT_FALSE(plugin1.getInvalidateTableCalled()); |
2424 | + EXPECT_FALSE(plugin1.getInvalidateDbCalled()); |
2425 | + EXPECT_FALSE(plugin1.getFlushCalled()); |
2426 | + |
2427 | + EXPECT_TRUE(plugin2.getTryFetchAndSendCalled()); |
2428 | + EXPECT_FALSE(plugin2.getSetCalled()); |
2429 | + EXPECT_FALSE(plugin2.getInvalidateTableCalled()); |
2430 | + EXPECT_FALSE(plugin2.getInvalidateDbCalled()); |
2431 | + EXPECT_FALSE(plugin2.getFlushCalled()); |
2432 | +} |
2433 | + |
2434 | +TEST_F(QueryCacheTest, setDo_twoPluginAdded_shouldCall_set_only_onBoth) |
2435 | +{ |
2436 | + plugin::QueryCache::setDo(NULL, false); |
2437 | + |
2438 | + EXPECT_FALSE(plugin1.getTryFetchAndSendCalled()); |
2439 | + EXPECT_TRUE(plugin1.getSetCalled()); |
2440 | + EXPECT_FALSE(plugin1.getInvalidateTableCalled()); |
2441 | + EXPECT_FALSE(plugin1.getInvalidateDbCalled()); |
2442 | + EXPECT_FALSE(plugin1.getFlushCalled()); |
2443 | + |
2444 | + EXPECT_FALSE(plugin2.getTryFetchAndSendCalled()); |
2445 | + EXPECT_TRUE(plugin2.getSetCalled()); |
2446 | + EXPECT_FALSE(plugin2.getInvalidateTableCalled()); |
2447 | + EXPECT_FALSE(plugin2.getInvalidateDbCalled()); |
2448 | + EXPECT_FALSE(plugin2.getFlushCalled()); |
2449 | +} |
2450 | + |
2451 | +TEST_F(QueryCacheTest, invalidateTableDo_twoPluginAdded_shouldCall_invalidateTable_only_onBoth) |
2452 | +{ |
2453 | + plugin::QueryCache::invalidateTableDo(NULL, false); |
2454 | + |
2455 | + EXPECT_FALSE(plugin1.getTryFetchAndSendCalled()); |
2456 | + EXPECT_FALSE(plugin1.getSetCalled()); |
2457 | + EXPECT_TRUE(plugin1.getInvalidateTableCalled()); |
2458 | + EXPECT_FALSE(plugin1.getInvalidateDbCalled()); |
2459 | + EXPECT_FALSE(plugin1.getFlushCalled()); |
2460 | + |
2461 | + EXPECT_FALSE(plugin2.getTryFetchAndSendCalled()); |
2462 | + EXPECT_FALSE(plugin2.getSetCalled()); |
2463 | + EXPECT_TRUE(plugin2.getInvalidateTableCalled()); |
2464 | + EXPECT_FALSE(plugin2.getInvalidateDbCalled()); |
2465 | + EXPECT_FALSE(plugin2.getFlushCalled()); |
2466 | +} |
2467 | + |
2468 | +TEST_F(QueryCacheTest, invalidateDbDo_twoPluginAdded_shouldCall_invalidateDb_only_onBoth) |
2469 | +{ |
2470 | + plugin::QueryCache::invalidateDbDo(NULL, NULL, false); |
2471 | + |
2472 | + EXPECT_FALSE(plugin1.getTryFetchAndSendCalled()); |
2473 | + EXPECT_FALSE(plugin1.getSetCalled()); |
2474 | + EXPECT_FALSE(plugin1.getInvalidateTableCalled()); |
2475 | + EXPECT_TRUE(plugin1.getInvalidateDbCalled()); |
2476 | + EXPECT_FALSE(plugin1.getFlushCalled()); |
2477 | + |
2478 | + EXPECT_FALSE(plugin2.getTryFetchAndSendCalled()); |
2479 | + EXPECT_FALSE(plugin2.getSetCalled()); |
2480 | + EXPECT_FALSE(plugin2.getInvalidateTableCalled()); |
2481 | + EXPECT_TRUE(plugin2.getInvalidateDbCalled()); |
2482 | + EXPECT_FALSE(plugin2.getFlushCalled()); |
2483 | +} |
2484 | + |
2485 | +TEST_F(QueryCacheTest, flushDo_twoPluginAdded_shouldCall_flush_only_onBoth) |
2486 | +{ |
2487 | + plugin::QueryCache::flushDo(NULL); |
2488 | + |
2489 | + EXPECT_FALSE(plugin1.getTryFetchAndSendCalled()); |
2490 | + EXPECT_FALSE(plugin1.getSetCalled()); |
2491 | + EXPECT_FALSE(plugin1.getInvalidateTableCalled()); |
2492 | + EXPECT_FALSE(plugin1.getInvalidateDbCalled()); |
2493 | + EXPECT_TRUE(plugin1.getFlushCalled()); |
2494 | + |
2495 | + EXPECT_FALSE(plugin2.getTryFetchAndSendCalled()); |
2496 | + EXPECT_FALSE(plugin2.getSetCalled()); |
2497 | + EXPECT_FALSE(plugin2.getInvalidateTableCalled()); |
2498 | + EXPECT_FALSE(plugin2.getInvalidateDbCalled()); |
2499 | + EXPECT_TRUE(plugin2.getFlushCalled()); |
2500 | +} |
2501 | + |
2502 | |
2503 | === added file 'unittests/plugin/query_rewrite_test.cc' |
2504 | --- unittests/plugin/query_rewrite_test.cc 1970-01-01 00:00:00 +0000 |
2505 | +++ unittests/plugin/query_rewrite_test.cc 2010-08-15 23:41:09 +0000 |
2506 | @@ -0,0 +1,47 @@ |
2507 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2508 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2509 | +* |
2510 | +* Copyright (C) 2010 Pawel Blokus |
2511 | +* |
2512 | +* This program is free software; you can redistribute it and/or modify |
2513 | +* it under the terms of the GNU General Public License as published by |
2514 | +* the Free Software Foundation; either version 2 of the License, or |
2515 | +* (at your option) any later version. |
2516 | +* |
2517 | +* This program is distributed in the hope that it will be useful, |
2518 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2519 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2520 | +* GNU General Public License for more details. |
2521 | +* |
2522 | +* You should have received a copy of the GNU General Public License |
2523 | +* along with this program; if not, write to the Free Software |
2524 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2525 | +*/ |
2526 | + |
2527 | +#include "config.h" |
2528 | + |
2529 | +#include <drizzled/plugin/query_rewrite.h> |
2530 | +#include <gtest/gtest.h> |
2531 | +#include <string> |
2532 | + |
2533 | +#include "plugin_stubs.h" |
2534 | + |
2535 | +using namespace drizzled; |
2536 | +using namespace std; |
2537 | + |
2538 | +TEST(QueryRewriteTest, rewriteQuery_twoPluginsAdded_shouldCall_rewrite_onBoth) |
2539 | +{ |
2540 | + QueryRewriterStub plugin1("QueryCacheStub1"); |
2541 | + QueryRewriterStub plugin2("QueryCacheStub2"); |
2542 | + plugin::QueryRewriter::addPlugin(&plugin1); |
2543 | + plugin::QueryRewriter::addPlugin(&plugin2); |
2544 | + string stubString; |
2545 | + |
2546 | + plugin::QueryRewriter::rewriteQuery(stubString, stubString); |
2547 | + |
2548 | + EXPECT_TRUE(plugin1.getRewriteCalled()); |
2549 | + EXPECT_TRUE(plugin2.getRewriteCalled()); |
2550 | + |
2551 | + plugin::QueryRewriter::removePlugin(&plugin1); |
2552 | + plugin::QueryRewriter::removePlugin(&plugin2); |
2553 | +} |
2554 | |
2555 | === added file 'unittests/plugin/scheduler_test.cc' |
2556 | --- unittests/plugin/scheduler_test.cc 1970-01-01 00:00:00 +0000 |
2557 | +++ unittests/plugin/scheduler_test.cc 2010-08-15 23:41:09 +0000 |
2558 | @@ -0,0 +1,103 @@ |
2559 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2560 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2561 | +* |
2562 | +* Copyright (C) 2010 Pawel Blokus |
2563 | +* |
2564 | +* This program is free software; you can redistribute it and/or modify |
2565 | +* it under the terms of the GNU General Public License as published by |
2566 | +* the Free Software Foundation; either version 2 of the License, or |
2567 | +* (at your option) any later version. |
2568 | +* |
2569 | +* This program is distributed in the hope that it will be useful, |
2570 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2571 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2572 | +* GNU General Public License for more details. |
2573 | +* |
2574 | +* You should have received a copy of the GNU General Public License |
2575 | +* along with this program; if not, write to the Free Software |
2576 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2577 | +*/ |
2578 | + |
2579 | +#include "config.h" |
2580 | + |
2581 | +#include <drizzled/plugin/scheduler.h> |
2582 | +#include <gtest/gtest.h> |
2583 | + |
2584 | +#include "plugin_stubs.h" |
2585 | + |
2586 | +using namespace drizzled; |
2587 | + |
2588 | +class SchedulerTest : public ::testing::Test |
2589 | +{ |
2590 | +public: |
2591 | + bool result; |
2592 | + SchedulerStub sched1; |
2593 | + SchedulerStub sched2; |
2594 | + |
2595 | + SchedulerTest() : sched1("SchedulerStub1"), sched2("SchedulerStub2") {} |
2596 | + |
2597 | + virtual void SetUp() |
2598 | + { |
2599 | + plugin::Scheduler::addPlugin(&sched1); |
2600 | + plugin::Scheduler::addPlugin(&sched2); |
2601 | + } |
2602 | + |
2603 | + virtual void TearDown() |
2604 | + { |
2605 | + plugin::Scheduler::removePlugin(&sched1); |
2606 | + plugin::Scheduler::removePlugin(&sched2); |
2607 | + } |
2608 | + |
2609 | +}; |
2610 | + |
2611 | + |
2612 | +TEST(SchedulerAddPluginTest, addPlugin_shouldReturn_False) |
2613 | +{ |
2614 | + bool result; |
2615 | + SchedulerStub sched1("SchedulerStub1"); |
2616 | + |
2617 | + result= plugin::Scheduler::addPlugin(&sched1); |
2618 | + |
2619 | + ASSERT_FALSE(result); |
2620 | + |
2621 | + plugin::Scheduler::removePlugin(&sched1); |
2622 | +} |
2623 | + |
2624 | +TEST_F(SchedulerTest, addPlugin_registerTwoSchedulersWithIdenticalName_shouldReturn_True) |
2625 | +{ |
2626 | + SchedulerStub sched3("SchedulerStub1"); |
2627 | + |
2628 | + result= plugin::Scheduler::addPlugin(&sched3); |
2629 | + |
2630 | + ASSERT_TRUE(result); |
2631 | +} |
2632 | + |
2633 | +TEST_F(SchedulerTest, setPlugin_twoPluginsAdded_setPluginShouldBeActivated) |
2634 | +{ |
2635 | + result= plugin::Scheduler::setPlugin("SchedulerStub2"); |
2636 | + |
2637 | + ASSERT_FALSE(result); |
2638 | + ASSERT_TRUE(sched2.isActive()); |
2639 | +} |
2640 | + |
2641 | +TEST_F(SchedulerTest, setPlugin_twoPluginsAdded_previoslySetPluginShouldBeDeactivated) |
2642 | +{ |
2643 | + |
2644 | + |
2645 | + plugin::Scheduler::setPlugin("SchedulerStub1"); |
2646 | + |
2647 | + result= plugin::Scheduler::setPlugin("SchedulerStub2"); |
2648 | + |
2649 | + ASSERT_FALSE(result); |
2650 | + ASSERT_FALSE(sched1.isActive()); |
2651 | +} |
2652 | + |
2653 | +TEST_F(SchedulerTest, setPlugin_twoPluginsAdded_useWrongName_shouldReturn_True) |
2654 | +{ |
2655 | + plugin::Scheduler::addPlugin(&sched1); |
2656 | + plugin::Scheduler::addPlugin(&sched2); |
2657 | + |
2658 | + result= plugin::Scheduler::setPlugin("WrongName"); |
2659 | + |
2660 | + ASSERT_TRUE(result); |
2661 | +} |
2662 | |
2663 | === added file 'unittests/plugin/schema_engine_test.cc' |
2664 | --- unittests/plugin/schema_engine_test.cc 1970-01-01 00:00:00 +0000 |
2665 | +++ unittests/plugin/schema_engine_test.cc 2010-08-15 23:41:09 +0000 |
2666 | @@ -0,0 +1,152 @@ |
2667 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2668 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2669 | +* |
2670 | +* Copyright (C) 2010 Pawel Blokus |
2671 | +* |
2672 | +* This program is free software; you can redistribute it and/or modify |
2673 | +* it under the terms of the GNU General Public License as published by |
2674 | +* the Free Software Foundation; either version 2 of the License, or |
2675 | +* (at your option) any later version. |
2676 | +* |
2677 | +* This program is distributed in the hope that it will be useful, |
2678 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2679 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2680 | +* GNU General Public License for more details. |
2681 | +* |
2682 | +* You should have received a copy of the GNU General Public License |
2683 | +* along with this program; if not, write to the Free Software |
2684 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2685 | +*/ |
2686 | + |
2687 | +#include "config.h" |
2688 | + |
2689 | +#include <drizzled/plugin/storage_engine.h> |
2690 | +#include <drizzled/table.h> |
2691 | +#include <gtest/gtest.h> |
2692 | + |
2693 | +#include "../generator.h" |
2694 | +#include "plugin_stubs.h" |
2695 | + |
2696 | +using namespace drizzled; |
2697 | + |
2698 | +class SchemaEngineTest : public ::testing::Test |
2699 | +{ |
2700 | +protected: |
2701 | + StorageEngineStub plugin1, plugin2; |
2702 | + Session *fake_session; |
2703 | + SchemaIdentifier schema_identifier; |
2704 | + bool result; |
2705 | + message::Schema proto; |
2706 | + |
2707 | +public: |
2708 | + SchemaEngineTest() |
2709 | + : plugin1("StorageEngineStub1"), |
2710 | + plugin2("StorageEngineStub2"), |
2711 | + schema_identifier("stubArg") |
2712 | + {} |
2713 | + |
2714 | + virtual void SetUp() |
2715 | + { |
2716 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
2717 | + plugin::StorageEngine::addPlugin(&plugin1); |
2718 | + plugin::StorageEngine::addPlugin(&plugin2); |
2719 | + } |
2720 | + |
2721 | + virtual void TearDown() |
2722 | + { |
2723 | + plugin::StorageEngine::removePlugin(&plugin1); |
2724 | + plugin::StorageEngine::removePlugin(&plugin2); |
2725 | + } |
2726 | +}; |
2727 | + |
2728 | +TEST_F(SchemaEngineTest, getIdentifiers_twoPluginsAdded_ShouldCall_doGetSchemaIdentifiers_onBoth) |
2729 | +{ |
2730 | + SchemaIdentifiers shema_id_list; |
2731 | + plugin::StorageEngine::getIdentifiers(*fake_session, shema_id_list); |
2732 | + |
2733 | + ASSERT_TRUE(plugin1.getDoGetSchemaIdentifiersCalled()); |
2734 | + ASSERT_TRUE(plugin2.getDoGetSchemaIdentifiersCalled()); |
2735 | +} |
2736 | + |
2737 | +TEST_F(SchemaEngineTest, getSchemaDefinition_TableIdentifier_twoPluginsAdded_ShouldCall_doGetSchemaDefinition_onBoth) |
2738 | +{ |
2739 | + TableIdentifier identifier("SchemaNameStub", |
2740 | + "TableNameStub", |
2741 | + "PathStub"); |
2742 | + TableShare table_share(identifier); |
2743 | + plugin::StorageEngine::getSchemaDefinition(identifier, proto); |
2744 | + |
2745 | + ASSERT_TRUE(plugin1.getDoGetSchemaDefinitionCalled()); |
2746 | + ASSERT_TRUE(plugin2.getDoGetSchemaDefinitionCalled()); |
2747 | +} |
2748 | + |
2749 | +TEST_F(SchemaEngineTest, getSchemaDefinition_SchemaIdentifier_twoPluginsAdded_ShouldCall_doGetSchemaDefinition_onBoth) |
2750 | +{ |
2751 | + plugin::StorageEngine::getSchemaDefinition(schema_identifier, proto); |
2752 | + |
2753 | + ASSERT_TRUE(plugin1.getDoGetSchemaDefinitionCalled()); |
2754 | + ASSERT_TRUE(plugin2.getDoGetSchemaDefinitionCalled()); |
2755 | +} |
2756 | + |
2757 | +TEST_F(SchemaEngineTest, createSchema_twoPluginsAdded_ShouldCall_doCreateSchemaCalled_onBoth) |
2758 | +{ |
2759 | + plugin::StorageEngine::createSchema(proto); |
2760 | + |
2761 | + ASSERT_TRUE(plugin1.getDoCreateSchemaCalled()); |
2762 | + ASSERT_TRUE(plugin2.getDoCreateSchemaCalled()); |
2763 | +} |
2764 | + |
2765 | +TEST_F(SchemaEngineTest, dropSchema_twoPluginsAdded_ShouldCall_doDropSchemaCalled_onBoth) |
2766 | +{ |
2767 | + plugin::StorageEngine::dropSchema(schema_identifier); |
2768 | + |
2769 | + ASSERT_TRUE(plugin1.getDoDropSchemaCalled()); |
2770 | + ASSERT_TRUE(plugin2.getDoDropSchemaCalled()); |
2771 | +} |
2772 | + |
2773 | +TEST_F(SchemaEngineTest, dropSchema_twoPluginsAdded_bothReturningFalse_shouldReturn_False) |
2774 | +{ |
2775 | + result= plugin::StorageEngine::dropSchema(schema_identifier); |
2776 | + |
2777 | + ASSERT_FALSE(result); |
2778 | +} |
2779 | + |
2780 | +TEST_F(SchemaEngineTest, dropSchema_twoPluginsAdded_oneReturningTrue_shouldReturn_True) |
2781 | +{ |
2782 | + plugin1.setDropSchemaReturn(true); |
2783 | + result= plugin::StorageEngine::dropSchema(schema_identifier); |
2784 | + |
2785 | + ASSERT_TRUE(result); |
2786 | +} |
2787 | + |
2788 | + |
2789 | +TEST_F(SchemaEngineTest, alterSchema_twoPluginsAdded_ShouldCall_doAlterSchemaCalled_onBoth) |
2790 | +{ |
2791 | + plugin::StorageEngine::alterSchema(proto); |
2792 | + |
2793 | + ASSERT_TRUE(plugin1.getDoAlterSchemaCalled()); |
2794 | + ASSERT_TRUE(plugin2.getDoAlterSchemaCalled()); |
2795 | +} |
2796 | + |
2797 | +TEST_F(SchemaEngineTest, alterSchema_SchemaIdentifier_twoPluginsAdded_bothReturningFalse_shouldReturn_False) |
2798 | +{ |
2799 | + result= plugin::StorageEngine::alterSchema(proto); |
2800 | + |
2801 | + ASSERT_FALSE(result); |
2802 | +} |
2803 | + |
2804 | +TEST_F(SchemaEngineTest, alterSchema_twoPluginsAdded_oneReturningTrue_shouldReturn_True) |
2805 | +{ |
2806 | + plugin1.setAlterSchemaReturn(true); |
2807 | + result= plugin::StorageEngine::alterSchema(proto); |
2808 | + |
2809 | + ASSERT_TRUE(result); |
2810 | +} |
2811 | + |
2812 | +TEST_F(SchemaEngineTest, getSchemaCollation_twoPluginsAdded_bothDoingNothing_shouldReturn_default_charset_info) |
2813 | +{ |
2814 | + const CHARSET_INFO *charset_info; |
2815 | + charset_info= plugin::StorageEngine::getSchemaCollation(schema_identifier); |
2816 | + |
2817 | + ASSERT_EQ(charset_info, default_charset_info); |
2818 | +} |
2819 | |
2820 | === added file 'unittests/plugin/storage_engine_test.cc' |
2821 | --- unittests/plugin/storage_engine_test.cc 1970-01-01 00:00:00 +0000 |
2822 | +++ unittests/plugin/storage_engine_test.cc 2010-08-15 23:41:09 +0000 |
2823 | @@ -0,0 +1,215 @@ |
2824 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
2825 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
2826 | +* |
2827 | +* Copyright (C) 2010 Pawel Blokus |
2828 | +* |
2829 | +* This program is free software; you can redistribute it and/or modify |
2830 | +* it under the terms of the GNU General Public License as published by |
2831 | +* the Free Software Foundation; either version 2 of the License, or |
2832 | +* (at your option) any later version. |
2833 | +* |
2834 | +* This program is distributed in the hope that it will be useful, |
2835 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2836 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2837 | +* GNU General Public License for more details. |
2838 | +* |
2839 | +* You should have received a copy of the GNU General Public License |
2840 | +* along with this program; if not, write to the Free Software |
2841 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
2842 | +*/ |
2843 | + |
2844 | +#include "config.h" |
2845 | + |
2846 | +#include <drizzled/error.h> |
2847 | +#include <drizzled/plugin/storage_engine.h> |
2848 | +#include <drizzled/table.h> |
2849 | +#include <gtest/gtest.h> |
2850 | + |
2851 | +#include "../generator.h" |
2852 | +#include "plugin_stubs.h" |
2853 | +#include "../stubs.h" |
2854 | + |
2855 | +using namespace drizzled; |
2856 | +using namespace std; |
2857 | + |
2858 | +class StorageEngineTest : public ::testing::Test |
2859 | +{ |
2860 | + protected: |
2861 | + StorageEngineStub plugin1, plugin2; |
2862 | + Session *fake_session; |
2863 | + SchemaIdentifier schema_identifier; |
2864 | + TableIdentifier table_id_stub; |
2865 | + bool result; |
2866 | + |
2867 | + public: |
2868 | + StorageEngineTest() |
2869 | + : plugin1("StorageEngineStub1", HTON_HAS_CHECKSUM), |
2870 | + plugin2("StorageEngineStub2"), |
2871 | + schema_identifier("stubArg"), |
2872 | + table_id_stub("Arg1Stub", "Arg2Stub", "Arg3Stub") |
2873 | + {} |
2874 | + |
2875 | + virtual void SetUp() |
2876 | + { |
2877 | + error_handler_hook= error_handler_func_stub; |
2878 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
2879 | + plugin::StorageEngine::addPlugin(&plugin1); |
2880 | + plugin::StorageEngine::addPlugin(&plugin2); |
2881 | + } |
2882 | + |
2883 | + virtual void TearDown() |
2884 | + { |
2885 | + plugin::StorageEngine::removePlugin(&plugin1); |
2886 | + plugin::StorageEngine::removePlugin(&plugin2); |
2887 | + } |
2888 | +}; |
2889 | + |
2890 | +TEST_F(StorageEngineTest, check_flag_CheckingSetFlag_ShouldReturn_True) |
2891 | +{ |
2892 | + result= plugin1.check_flag(HTON_BIT_HAS_CHECKSUM); |
2893 | + EXPECT_TRUE(result); |
2894 | +} |
2895 | + |
2896 | +TEST_F(StorageEngineTest, check_flag_CheckingUnsetFlag_ShouldReturn_False) |
2897 | +{ |
2898 | + result= plugin1.check_flag(HTON_BIT_NO_AUTO_INCREMENT); |
2899 | + EXPECT_FALSE(result); |
2900 | +} |
2901 | + |
2902 | +TEST_F(StorageEngineTest, findByName_findExistingName_shouldReturn_Pointer) |
2903 | +{ |
2904 | + plugin::StorageEngine *found; |
2905 | + string name_to_find= "StorageEngineStub2"; |
2906 | + |
2907 | + found= plugin::StorageEngine::findByName(name_to_find); |
2908 | + |
2909 | + ASSERT_EQ(&plugin2, found); |
2910 | +} |
2911 | + |
2912 | +TEST_F(StorageEngineTest, findByName_findNonExistingName_shouldReturn_NULL) |
2913 | +{ |
2914 | + plugin::StorageEngine *found; |
2915 | + string name_to_find= "NonExisting"; |
2916 | + |
2917 | + found= plugin::StorageEngine::findByName(name_to_find); |
2918 | + |
2919 | + ASSERT_EQ(NULL, found); |
2920 | +} |
2921 | + |
2922 | +TEST_F(StorageEngineTest, findByName_withSessionArg_findExistingName_shouldReturn_Pointer) |
2923 | +{ |
2924 | + plugin::StorageEngine *found; |
2925 | + string name_to_find= "StorageEngineStub1"; |
2926 | + |
2927 | + found= plugin::StorageEngine::findByName(*fake_session, name_to_find); |
2928 | + |
2929 | + ASSERT_EQ(&plugin1, found); |
2930 | +} |
2931 | + |
2932 | +TEST_F(StorageEngineTest, findByName_withSessionArg_findNonExistingName_shouldReturn_NULL) |
2933 | +{ |
2934 | + plugin::StorageEngine *found; |
2935 | + string name_to_find= "NonExisting"; |
2936 | + |
2937 | + found= plugin::StorageEngine::findByName(*fake_session, name_to_find); |
2938 | + |
2939 | + ASSERT_EQ(NULL, found); |
2940 | +} |
2941 | + |
2942 | +TEST_F(StorageEngineTest, DISABLED_closeConnection_twoPluginsAdded_shouldCall_close_connection_onBoth) |
2943 | +{ |
2944 | + plugin::StorageEngine::closeConnection(fake_session); |
2945 | + |
2946 | + ASSERT_TRUE(plugin1.getCloseConnectionCalled()); |
2947 | + ASSERT_TRUE(plugin2.getCloseConnectionCalled()); |
2948 | +} |
2949 | + |
2950 | +TEST_F(StorageEngineTest, flushLogs_twoPluginsAdded_shouldCall_flush_logs_onBoth) |
2951 | +{ |
2952 | + plugin::StorageEngine::flushLogs(NULL); |
2953 | + |
2954 | + ASSERT_TRUE(plugin1.getFlushLogsCalled()); |
2955 | + ASSERT_TRUE(plugin2.getFlushLogsCalled()); |
2956 | +} |
2957 | + |
2958 | +TEST_F(StorageEngineTest, getTableDefinition_twoPluginsAdded_shouldCall_doGetTableDefinition_onBoth) |
2959 | +{ |
2960 | + message::Table proto; |
2961 | + plugin::StorageEngine::getTableDefinition(*fake_session, table_id_stub, proto, 0); |
2962 | + |
2963 | + ASSERT_TRUE(plugin1.getDoGetTableDefinitionCalled()); |
2964 | + ASSERT_TRUE(plugin2.getDoGetTableDefinitionCalled()); |
2965 | +} |
2966 | + |
2967 | +TEST_F(StorageEngineTest, dropTable_twoPluginsAdded_shouldCall_doDropTableCalled_onPluginAssociatedWithIdentifier) |
2968 | +{ |
2969 | + int error; |
2970 | + |
2971 | + plugin1.setEngineNameToSet("StorageEngineStub1");//this is served to an internally performed search |
2972 | + error= plugin::StorageEngine::dropTable(*fake_session, table_id_stub); |
2973 | + |
2974 | + ASSERT_EQ(0, error); |
2975 | + ASSERT_TRUE(plugin1.getDoDropTableCalled()); |
2976 | +} |
2977 | + |
2978 | +TEST_F(StorageEngineTest, dropTable_EngineForTableCantBeFound_shouldReturn_ER_CORRUPT_TABLE_DEFINITION) |
2979 | +{ |
2980 | + int error; |
2981 | + |
2982 | + |
2983 | + plugin1.setEngineNameToSet("NonExisting");//this is served to an internally performed search |
2984 | + error= plugin::StorageEngine::dropTable(*fake_session, table_id_stub); |
2985 | + |
2986 | + ASSERT_EQ(ER_CORRUPT_TABLE_DEFINITION, error); |
2987 | +} |
2988 | + |
2989 | +TEST_F(StorageEngineTest, dropTable_NonExistingTable_shouldReturn_ER_CORRUPT_TABLE_DEFINITION) |
2990 | +{ |
2991 | + int error; |
2992 | + |
2993 | + plugin1.setDoGetTableDefinitionReturn(ER_CORRUPT_TABLE_DEFINITION); |
2994 | + error= plugin::StorageEngine::dropTable(*fake_session, table_id_stub); |
2995 | + |
2996 | + ASSERT_EQ(ER_CORRUPT_TABLE_DEFINITION, error); |
2997 | +} |
2998 | + |
2999 | +TEST_F(StorageEngineTest, dropTable_nonExistingTable_shouldReturn_ER_CORRUPT_TABLE_DEFINITION) |
3000 | +{ |
3001 | + int error; |
3002 | + |
3003 | + plugin1.setEngineNameToSet("NonExisting");//this is served to an internally performed search |
3004 | + error= plugin::StorageEngine::dropTable(*fake_session, table_id_stub); |
3005 | + |
3006 | + ASSERT_EQ(ER_CORRUPT_TABLE_DEFINITION, error); |
3007 | +} |
3008 | + |
3009 | +TEST_F(StorageEngineTest, canCreateTable_twoPluginsAdded_shouldCall_doCanCreateTable_onBoth) |
3010 | +{ |
3011 | + plugin::StorageEngine::canCreateTable(table_id_stub); |
3012 | + |
3013 | + ASSERT_TRUE(plugin1.getDoCanCreateTableCalled()); |
3014 | + ASSERT_TRUE(plugin2.getDoCanCreateTableCalled()); |
3015 | +} |
3016 | + |
3017 | +TEST_F(StorageEngineTest, doesTableExist_twoPluginsAdded_shouldCall_doDoesTableExist_onBoth) |
3018 | +{ |
3019 | + plugin::StorageEngine::doesTableExist(*fake_session, table_id_stub); |
3020 | + |
3021 | + ASSERT_TRUE(plugin1.getDoDoesTableExistCalled()); |
3022 | + ASSERT_TRUE(plugin2.getDoDoesTableExistCalled()); |
3023 | +} |
3024 | + |
3025 | +TEST_F(StorageEngineTest, doesTableExist_twoPluginsAdded_bothReturningFalse_should_returnFalse) |
3026 | +{ |
3027 | + result= plugin::StorageEngine::doesTableExist(*fake_session, table_id_stub); |
3028 | + |
3029 | + ASSERT_FALSE(result); |
3030 | +} |
3031 | + |
3032 | +TEST_F(StorageEngineTest, doesTableExist_twoPluginsAdded_oneReturningTrue_should_returnTrue) |
3033 | +{ |
3034 | + plugin2.setDoesTableExistReturn(true); |
3035 | + plugin::StorageEngine::doesTableExist(*fake_session, table_id_stub); |
3036 | + |
3037 | + ASSERT_TRUE(result); |
3038 | +} |
3039 | |
3040 | === added file 'unittests/plugin/table_function_test.cc' |
3041 | --- unittests/plugin/table_function_test.cc 1970-01-01 00:00:00 +0000 |
3042 | +++ unittests/plugin/table_function_test.cc 2010-08-15 23:41:09 +0000 |
3043 | @@ -0,0 +1,242 @@ |
3044 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3045 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3046 | +* |
3047 | +* Copyright (C) 2010 Pawel Blokus |
3048 | +* |
3049 | +* This program is free software; you can redistribute it and/or modify |
3050 | +* it under the terms of the GNU General Public License as published by |
3051 | +* the Free Software Foundation; either version 2 of the License, or |
3052 | +* (at your option) any later version. |
3053 | +* |
3054 | +* This program is distributed in the hope that it will be useful, |
3055 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3056 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3057 | +* GNU General Public License for more details. |
3058 | +* |
3059 | +* You should have received a copy of the GNU General Public License |
3060 | +* along with this program; if not, write to the Free Software |
3061 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3062 | +*/ |
3063 | + |
3064 | +#include "config.h" |
3065 | + |
3066 | +#include <drizzled/field/int64_t.h> |
3067 | +#include <drizzled/field/varstring.h> |
3068 | +#include <drizzled/global_charset_info.h> |
3069 | +#include <drizzled/plugin/table_function.h> |
3070 | +#include <drizzled/session.h> |
3071 | +#include <drizzled/sql_string.h> |
3072 | +#include <drizzled/table.h> |
3073 | +#include <drizzled/table_share.h> |
3074 | +#include <gtest/gtest.h> |
3075 | +#include <string> |
3076 | + |
3077 | +#include "drizzled/message/table.pb.h" |
3078 | +#include "../generator.h" |
3079 | + |
3080 | +using namespace drizzled; |
3081 | +using namespace std; |
3082 | + |
3083 | +class TableFunctionTest : public ::testing::Test |
3084 | +{ |
3085 | +protected: |
3086 | + plugin::TableFunction plugin; |
3087 | + message::Table proto; |
3088 | +public: |
3089 | + TableFunctionTest() |
3090 | + : plugin("SchemaArgStub", "TableArgStub") |
3091 | + {} |
3092 | +}; |
3093 | + |
3094 | +TEST_F(TableFunctionTest, getIdentifierTableName_shouldReturn_lowerCase_table_arg) |
3095 | +{ |
3096 | + string table_name= plugin.getIdentifierTableName(); |
3097 | + |
3098 | + ASSERT_EQ("tableargstub", table_name); |
3099 | +} |
3100 | + |
3101 | +TEST_F(TableFunctionTest, getSchemaHome_shouldReturn_lowerCase_schema_arg) |
3102 | +{ |
3103 | + string schema_name= plugin.getSchemaHome(); |
3104 | + |
3105 | + ASSERT_EQ("schemaargstub", schema_name); |
3106 | +} |
3107 | + |
3108 | +TEST_F(TableFunctionTest, getPath_shouldReturn_joined_schema_arg_and_table_arg) |
3109 | +{ |
3110 | + string path= plugin.getPath(); |
3111 | + |
3112 | + ASSERT_EQ("schemaargstub/tableargstub", path); |
3113 | +} |
3114 | + |
3115 | +TEST_F(TableFunctionTest, add_field_shouldAddFieldToProto) |
3116 | +{ |
3117 | + drizzled::message::Table::Field *field; |
3118 | + |
3119 | + plugin.add_field("FieldLabel", plugin::TableFunction::BOOLEAN, true); |
3120 | + plugin.define(proto); |
3121 | + field= proto.mutable_field(0); |
3122 | + |
3123 | + ASSERT_EQ(1, proto.field_size()); |
3124 | +} |
3125 | + |
3126 | +TEST_F(TableFunctionTest, add_field_type_BOOLEAN_shouldSetProtoFieldsProperly) |
3127 | +{ |
3128 | + drizzled::message::Table::Field *field; |
3129 | + |
3130 | + plugin.add_field("FieldLabel", plugin::TableFunction::BOOLEAN, 0, true); |
3131 | + plugin.define(proto); |
3132 | + field= proto.mutable_field(0); |
3133 | + |
3134 | + EXPECT_EQ("FieldLabel", field->name()); |
3135 | + EXPECT_EQ(drizzled::message::Table::Field::VARCHAR, field->type()); |
3136 | + EXPECT_EQ(false, field->options().default_null()); |
3137 | + EXPECT_EQ(false, field->constraints().is_nullable()); |
3138 | + EXPECT_EQ(5, field->string_options().length()); |
3139 | +} |
3140 | + |
3141 | +TEST_F(TableFunctionTest, add_field_type_STRING_shouldSetProtoFieldsProperly) |
3142 | +{ |
3143 | + drizzled::message::Table::Field *field; |
3144 | + |
3145 | + plugin.add_field("FieldLabel", plugin::TableFunction::STRING, 10, true); |
3146 | + plugin.define(proto); |
3147 | + field= proto.mutable_field(0); |
3148 | + |
3149 | + EXPECT_EQ("FieldLabel", field->name()); |
3150 | + EXPECT_EQ(drizzled::message::Table::Field::VARCHAR, field->type()); |
3151 | + EXPECT_EQ(true, field->options().default_null()); |
3152 | + EXPECT_EQ(true, field->constraints().is_nullable()); |
3153 | + EXPECT_EQ(10, field->string_options().length()); |
3154 | +} |
3155 | + |
3156 | +TEST_F(TableFunctionTest, add_field_type_VARBINARY_shouldSetProtoFieldsProperly) |
3157 | +{ |
3158 | + drizzled::message::Table::Field *field; |
3159 | + |
3160 | + plugin.add_field("FieldLabel", plugin::TableFunction::VARBINARY, 10, true); |
3161 | + plugin.define(proto); |
3162 | + field= proto.mutable_field(0); |
3163 | + |
3164 | + EXPECT_EQ("FieldLabel", field->name()); |
3165 | + EXPECT_EQ(drizzled::message::Table::Field::VARCHAR, field->type()); |
3166 | + EXPECT_EQ(true, field->options().default_null()); |
3167 | + EXPECT_EQ(true, field->constraints().is_nullable()); |
3168 | + EXPECT_EQ(10, field->string_options().length()); |
3169 | + EXPECT_EQ(my_charset_bin.csname, field->string_options().collation()); |
3170 | + EXPECT_EQ(my_charset_bin.number, field->string_options().collation_id()); |
3171 | +} |
3172 | + |
3173 | +TEST_F(TableFunctionTest, add_field_type_NUMBER_shouldSetProtoFieldsProperly) |
3174 | +{ |
3175 | + drizzled::message::Table::Field *field; |
3176 | + |
3177 | + plugin.add_field("FieldLabel", plugin::TableFunction::NUMBER, 10, true); |
3178 | + plugin.define(proto); |
3179 | + field= proto.mutable_field(0); |
3180 | + |
3181 | + EXPECT_EQ("FieldLabel", field->name()); |
3182 | + EXPECT_EQ(drizzled::message::Table::Field::BIGINT, field->type()); |
3183 | + EXPECT_EQ(false, field->options().default_null()); |
3184 | + EXPECT_EQ(false, field->constraints().is_nullable()); |
3185 | +} |
3186 | + |
3187 | +class TableFunctionGeneratorTest : public ::testing::Test |
3188 | +{ |
3189 | +protected: |
3190 | + unsigned char buf[100]; |
3191 | + unsigned char buf2[100]; |
3192 | + TableShare table_share; |
3193 | + Table table; |
3194 | + Session *fake_session; |
3195 | + Field_int64_t field_int64_t; |
3196 | + Field_varstring field_varstring; |
3197 | + Field *field_ptr[2]; |
3198 | + plugin::TableFunction::Generator generator; |
3199 | + String string_buf; |
3200 | +public: |
3201 | + TableFunctionGeneratorTest() |
3202 | + : table_share(message::Table::STANDARD), |
3203 | + field_int64_t(buf, 0, NULL, 0, Field::NONE, "FieldName", 0, true), |
3204 | + field_varstring(buf2, 100, 1, NULL, 0, "FieldName", &table_share, default_charset_info), |
3205 | + generator(&field_ptr[0]) |
3206 | + { |
3207 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
3208 | + table.resetTable(fake_session, &table_share, 0); |
3209 | + field_int64_t.init(&table); |
3210 | + field_varstring.init(&table); |
3211 | + system_charset_info= default_charset_info; |
3212 | + generator.sub_populate(0); |
3213 | + } |
3214 | +}; |
3215 | + |
3216 | +TEST_F(TableFunctionGeneratorTest, push_uint64_t_FieldShouldGetPopulated) |
3217 | +{ |
3218 | + field_ptr[0]= &field_int64_t; |
3219 | + |
3220 | + generator.push((uint64_t)20); |
3221 | + |
3222 | + ASSERT_EQ(20, field_ptr[0]->val_int()); |
3223 | +} |
3224 | + |
3225 | +TEST_F(TableFunctionGeneratorTest, push_int64_t_FieldShouldGetPopulated) |
3226 | +{ |
3227 | + field_ptr[0]= &field_int64_t; |
3228 | + |
3229 | + generator.push((int64_t)20); |
3230 | + |
3231 | + ASSERT_EQ(20, field_ptr[0]->val_int()); |
3232 | +} |
3233 | + |
3234 | +TEST_F(TableFunctionGeneratorTest, push_cstring_FieldShouldGetPopulated) |
3235 | +{ |
3236 | + field_ptr[0]= &field_varstring; |
3237 | + char pushed_string[]= {"Pushed String"}; |
3238 | + |
3239 | + generator.push(pushed_string); |
3240 | + |
3241 | + ASSERT_STREQ(pushed_string, field_ptr[0]->val_str(&string_buf)->c_str()); |
3242 | +} |
3243 | + |
3244 | +TEST_F(TableFunctionGeneratorTest, push_string_FieldShouldGetPopulated) |
3245 | +{ |
3246 | + field_ptr[0]= &field_varstring; |
3247 | + string pushed_string("Pushed String"); |
3248 | + |
3249 | + generator.push(pushed_string); |
3250 | + |
3251 | + ASSERT_STREQ(pushed_string.c_str(), field_ptr[0]->val_str(&string_buf)->c_str()); |
3252 | +} |
3253 | + |
3254 | +TEST_F(TableFunctionGeneratorTest, push_bool_true_FieldShouldGetPopulated) |
3255 | +{ |
3256 | + field_ptr[0]= &field_varstring; |
3257 | + string true_string("YES"); |
3258 | + |
3259 | + generator.push(true); |
3260 | + |
3261 | + ASSERT_STREQ(true_string.c_str(), field_ptr[0]->val_str(&string_buf)->c_str()); |
3262 | +} |
3263 | + |
3264 | +TEST_F(TableFunctionGeneratorTest, push_bool_false_FieldShouldGetPopulated) |
3265 | +{ |
3266 | + field_ptr[0]= &field_varstring; |
3267 | + string true_string("NO"); |
3268 | + |
3269 | + generator.push(false); |
3270 | + |
3271 | + ASSERT_STREQ(true_string.c_str(), field_ptr[0]->val_str(&string_buf)->c_str()); |
3272 | +} |
3273 | + |
3274 | +TEST_F(TableFunctionGeneratorTest, push_twoValues_bothFieldsShouldGetPopulated) |
3275 | +{ |
3276 | + field_ptr[0]= &field_int64_t; |
3277 | + field_ptr[1]= &field_varstring; |
3278 | + char pushed_string[]= {"Pushed String"}; |
3279 | + |
3280 | + generator.push((uint64_t)20); |
3281 | + generator.push(pushed_string); |
3282 | + |
3283 | + ASSERT_EQ(20, field_ptr[0]->val_int()); |
3284 | + ASSERT_STREQ(pushed_string, field_ptr[1]->val_str(&string_buf)->c_str()); |
3285 | +} |
3286 | |
3287 | === added file 'unittests/plugin/transaction_applier_test.cc' |
3288 | --- unittests/plugin/transaction_applier_test.cc 1970-01-01 00:00:00 +0000 |
3289 | +++ unittests/plugin/transaction_applier_test.cc 2010-08-15 23:41:09 +0000 |
3290 | @@ -0,0 +1,1 @@ |
3291 | + |
3292 | |
3293 | === added file 'unittests/plugin/transaction_replicator_test.cc' |
3294 | --- unittests/plugin/transaction_replicator_test.cc 1970-01-01 00:00:00 +0000 |
3295 | +++ unittests/plugin/transaction_replicator_test.cc 2010-08-15 23:41:09 +0000 |
3296 | @@ -0,0 +1,1 @@ |
3297 | + |
3298 | |
3299 | === added file 'unittests/plugin/transactional_storage_engine_test.cc' |
3300 | --- unittests/plugin/transactional_storage_engine_test.cc 1970-01-01 00:00:00 +0000 |
3301 | +++ unittests/plugin/transactional_storage_engine_test.cc 2010-08-15 23:41:09 +0000 |
3302 | @@ -0,0 +1,68 @@ |
3303 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3304 | + * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3305 | + * |
3306 | + * Copyright (C) 2010 Pawel Blokus |
3307 | + * |
3308 | + * This program is free software; you can redistribute it and/or modify |
3309 | + * it under the terms of the GNU General Public License as published by |
3310 | + * the Free Software Foundation; either version 2 of the License, or |
3311 | + * (at your option) any later version. |
3312 | + * |
3313 | + * This program is distributed in the hope that it will be useful, |
3314 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3315 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3316 | + * GNU General Public License for more details. |
3317 | + * |
3318 | + * You should have received a copy of the GNU General Public License |
3319 | + * along with this program; if not, write to the Free Software |
3320 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3321 | + */ |
3322 | + |
3323 | +#include "config.h" |
3324 | + |
3325 | +#include <drizzled/plugin/transactional_storage_engine.h> |
3326 | +#include <gtest/gtest.h> |
3327 | + |
3328 | +#include "plugin_stubs.h" |
3329 | + |
3330 | +using namespace drizzled; |
3331 | + |
3332 | +class TransactionalStorageEngineTest : public ::testing::Test |
3333 | +{ |
3334 | +protected: |
3335 | + TransactionalStorageEngineStub plugin1, plugin2; |
3336 | +public: |
3337 | + TransactionalStorageEngineTest() |
3338 | + : plugin1("TransactionalStorageEngineStub1"), |
3339 | + plugin2("TransactionalStorageEngineStub2") |
3340 | + {} |
3341 | + |
3342 | + virtual void SetUp() |
3343 | + { |
3344 | + plugin::TransactionalStorageEngine::addPlugin(&plugin1); |
3345 | + plugin::TransactionalStorageEngine::addPlugin(&plugin2); |
3346 | + } |
3347 | + |
3348 | + virtual void TearDown() |
3349 | + { |
3350 | + plugin::TransactionalStorageEngine::removePlugin(&plugin1); |
3351 | + plugin::TransactionalStorageEngine::removePlugin(&plugin2); |
3352 | + } |
3353 | + |
3354 | +}; |
3355 | + |
3356 | +TEST_F(TransactionalStorageEngineTest, notifyStartTransaction_twoPluginsAdded_shouldCall_startTransaction_onBoth) |
3357 | +{ |
3358 | + plugin::TransactionalStorageEngine::notifyStartTransaction(NULL, START_TRANS_NO_OPTIONS); |
3359 | + |
3360 | + EXPECT_TRUE(plugin1.getStartTransactionCalled()); |
3361 | + EXPECT_TRUE(plugin2.getStartTransactionCalled()); |
3362 | +} |
3363 | + |
3364 | +TEST_F(TransactionalStorageEngineTest, releaseTemporaryLatches_twoPluginsAdded_shouldCall_doReleaseTemporaryLatches_onBoth) |
3365 | +{ |
3366 | + plugin::TransactionalStorageEngine::releaseTemporaryLatches(NULL); |
3367 | + |
3368 | + EXPECT_TRUE(plugin1.getDoReleaseTemporaryLatchesCalled()); |
3369 | + EXPECT_TRUE(plugin2.getDoReleaseTemporaryLatchesCalled()); |
3370 | +} |
3371 | \ No newline at end of file |
3372 | |
3373 | === added file 'unittests/plugin/xa_resource_manager_test.cc' |
3374 | --- unittests/plugin/xa_resource_manager_test.cc 1970-01-01 00:00:00 +0000 |
3375 | +++ unittests/plugin/xa_resource_manager_test.cc 2010-08-15 23:41:09 +0000 |
3376 | @@ -0,0 +1,97 @@ |
3377 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3378 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3379 | +* |
3380 | +* Copyright (C) 2010 Pawel Blokus |
3381 | +* |
3382 | +* This program is free software; you can redistribute it and/or modify |
3383 | +* it under the terms of the GNU General Public License as published by |
3384 | +* the Free Software Foundation; either version 2 of the License, or |
3385 | +* (at your option) any later version. |
3386 | +* |
3387 | +* This program is distributed in the hope that it will be useful, |
3388 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3389 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3390 | +* GNU General Public License for more details. |
3391 | +* |
3392 | +* You should have received a copy of the GNU General Public License |
3393 | +* along with this program; if not, write to the Free Software |
3394 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3395 | +*/ |
3396 | + |
3397 | +#include "config.h" |
3398 | + |
3399 | +#include <drizzled/plugin/xa_resource_manager.h> |
3400 | +#include <gtest/gtest.h> |
3401 | + |
3402 | +#include "plugin_stubs.h" |
3403 | + |
3404 | +using namespace drizzled; |
3405 | + |
3406 | +class XaResourceManagerTest : public ::testing::Test |
3407 | +{ |
3408 | +protected: |
3409 | + XaResourceManagerStub plugin1, plugin2; |
3410 | + XID xid; |
3411 | + int returned; |
3412 | +public: |
3413 | + |
3414 | + virtual void SetUp() |
3415 | + { |
3416 | + plugin::XaResourceManager::addPlugin(&plugin1); |
3417 | + plugin::XaResourceManager::addPlugin(&plugin2); |
3418 | + } |
3419 | + |
3420 | + virtual void TearDown() |
3421 | + { |
3422 | + plugin::XaResourceManager::removePlugin(&plugin1); |
3423 | + plugin::XaResourceManager::removePlugin(&plugin2); |
3424 | + } |
3425 | +}; |
3426 | + |
3427 | +TEST_F(XaResourceManagerTest, commitOrRollbackXID_commit_pluginsReturning_0_shouldReturn_0) |
3428 | +{ |
3429 | + returned= plugin::XaResourceManager::commitOrRollbackXID(&xid, true); |
3430 | + |
3431 | + ASSERT_EQ(0, returned); |
3432 | +} |
3433 | + |
3434 | +TEST_F(XaResourceManagerTest, commitOrRollbackXID_commit_pluginsReturning_1_shouldReturn_1) |
3435 | +{ |
3436 | + plugin1.setCommitRollbackReturn(1); |
3437 | + plugin2.setCommitRollbackReturn(1); |
3438 | + returned= plugin::XaResourceManager::commitOrRollbackXID(&xid, true); |
3439 | + |
3440 | + ASSERT_EQ(1, returned); |
3441 | +} |
3442 | + |
3443 | +TEST_F(XaResourceManagerTest, commitOrRollbackXID_commit_onlyOnePluginReturning_0_shouldReturn_0) |
3444 | +{ |
3445 | + plugin1.setCommitRollbackReturn(1); |
3446 | + returned= plugin::XaResourceManager::commitOrRollbackXID(&xid, true); |
3447 | + |
3448 | + ASSERT_EQ(0, returned); |
3449 | +} |
3450 | + |
3451 | +TEST_F(XaResourceManagerTest, commitOrRollbackXID_commit_twoPluginsAdded_doXaCommit_shouldBeCalledOnBoth) |
3452 | +{ |
3453 | + plugin::XaResourceManager::commitOrRollbackXID(&xid, true); |
3454 | + |
3455 | + ASSERT_TRUE(plugin1.getDoXaCommitXidCalled()); |
3456 | + ASSERT_TRUE(plugin2.getDoXaCommitXidCalled()); |
3457 | +} |
3458 | + |
3459 | +TEST_F(XaResourceManagerTest, commitOrRollbackXID_rollback_twoPluginsAdded_doXaRollback_shouldBeCalledOnBoth) |
3460 | +{ |
3461 | + plugin::XaResourceManager::commitOrRollbackXID(&xid, false); |
3462 | + |
3463 | + ASSERT_TRUE(plugin1.getDoXaRollbackXidCalled()); |
3464 | + ASSERT_TRUE(plugin2.getDoXaRollbackXidCalled()); |
3465 | +} |
3466 | + |
3467 | +TEST_F(XaResourceManagerTest, recoverAllXids_twoPluginsAdded_doXaRecover_shouldBeCalledOnBoth) |
3468 | +{ |
3469 | + plugin::XaResourceManager::recoverAllXids(NULL); |
3470 | + |
3471 | + ASSERT_TRUE(plugin1.getXaRecoverCalled()); |
3472 | + ASSERT_TRUE(plugin2.getXaRecoverCalled()); |
3473 | +} |
3474 | |
3475 | === added file 'unittests/plugin/xa_storage_engine_test.cc' |
3476 | --- unittests/plugin/xa_storage_engine_test.cc 1970-01-01 00:00:00 +0000 |
3477 | +++ unittests/plugin/xa_storage_engine_test.cc 2010-08-15 23:41:09 +0000 |
3478 | @@ -0,0 +1,1 @@ |
3479 | + |
3480 | |
3481 | === added file 'unittests/stubs.cc' |
3482 | --- unittests/stubs.cc 1970-01-01 00:00:00 +0000 |
3483 | +++ unittests/stubs.cc 2010-08-15 23:41:09 +0000 |
3484 | @@ -0,0 +1,31 @@ |
3485 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3486 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3487 | +* |
3488 | +* Copyright (C) 2010 Pawel Blokus |
3489 | +* |
3490 | +* This program is free software; you can redistribute it and/or modify |
3491 | +* it under the terms of the GNU General Public License as published by |
3492 | +* the Free Software Foundation; either version 2 of the License, or |
3493 | +* (at your option) any later version. |
3494 | +* |
3495 | +* This program is distributed in the hope that it will be useful, |
3496 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3497 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3498 | +* GNU General Public License for more details. |
3499 | +* |
3500 | +* You should have received a copy of the GNU General Public License |
3501 | +* along with this program; if not, write to the Free Software |
3502 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3503 | +*/ |
3504 | + |
3505 | +#include "stubs.h" |
3506 | + |
3507 | + |
3508 | +using namespace drizzled; |
3509 | + |
3510 | +void error_handler_func_stub(uint32_t my_err, const char *str, drizzled::myf MyFlags) |
3511 | +{ |
3512 | + (void)my_err; |
3513 | + (void)str; |
3514 | + (void)MyFlags; |
3515 | +} |
3516 | \ No newline at end of file |
3517 | |
3518 | === added file 'unittests/stubs.h' |
3519 | --- unittests/stubs.h 1970-01-01 00:00:00 +0000 |
3520 | +++ unittests/stubs.h 2010-08-15 23:41:09 +0000 |
3521 | @@ -0,0 +1,46 @@ |
3522 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3523 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3524 | +* |
3525 | +* Copyright (C) 2010 Pawel Blokus |
3526 | +* |
3527 | +* This program is free software; you can redistribute it and/or modify |
3528 | +* it under the terms of the GNU General Public License as published by |
3529 | +* the Free Software Foundation; either version 2 of the License, or |
3530 | +* (at your option) any later version. |
3531 | +* |
3532 | +* This program is distributed in the hope that it will be useful, |
3533 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3534 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3535 | +* GNU General Public License for more details. |
3536 | +* |
3537 | +* You should have received a copy of the GNU General Public License |
3538 | +* along with this program; if not, write to the Free Software |
3539 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3540 | +*/ |
3541 | + |
3542 | +#ifndef UNITTESTS_STUBS_H |
3543 | +#define UNITTESTS_STUBS_H |
3544 | + |
3545 | +#include "config.h" |
3546 | + |
3547 | +#include <drizzled/definitions.h> |
3548 | +#include <drizzled/table.h> |
3549 | +#include <string> |
3550 | + |
3551 | +void error_handler_func_stub(uint32_t my_err, const char *str, drizzled::myf MyFlags); |
3552 | + |
3553 | +class TableShareStub : public drizzled::TableShare |
3554 | +{ |
3555 | + public: |
3556 | + TableShareStub(drizzled::message::Table::TableType type= |
3557 | + drizzled::message::Table::STANDARD) |
3558 | + : drizzled::TableShare(type) |
3559 | + {} |
3560 | + |
3561 | + void addKeyName(std::string arg) |
3562 | + { |
3563 | + drizzled::TableShare::addKeyName(arg); |
3564 | + } |
3565 | +}; |
3566 | + |
3567 | +#endif |
3568 | \ No newline at end of file |
3569 | |
3570 | === added file 'unittests/table_identifier_test.cc' |
3571 | --- unittests/table_identifier_test.cc 1970-01-01 00:00:00 +0000 |
3572 | +++ unittests/table_identifier_test.cc 2010-08-15 23:41:09 +0000 |
3573 | @@ -0,0 +1,415 @@ |
3574 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3575 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3576 | +* |
3577 | +* Copyright (C) 2010 Pawel Blokus |
3578 | +* |
3579 | +* This program is free software; you can redistribute it and/or modify |
3580 | +* it under the terms of the GNU General Public License as published by |
3581 | +* the Free Software Foundation; either version 2 of the License, or |
3582 | +* (at your option) any later version. |
3583 | +* |
3584 | +* This program is distributed in the hope that it will be useful, |
3585 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
3586 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3587 | +* GNU General Public License for more details. |
3588 | +* |
3589 | +* You should have received a copy of the GNU General Public License |
3590 | +* along with this program; if not, write to the Free Software |
3591 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3592 | +*/ |
3593 | + |
3594 | +#include "config.h" |
3595 | + |
3596 | +#include <gtest/gtest.h> |
3597 | + |
3598 | +#include <drizzled/data_home.h> |
3599 | +#include <drizzled/definitions.h> |
3600 | +#include <drizzled/set_var.h> |
3601 | +#include <drizzled/table.h> |
3602 | +#include <drizzled/message/table.pb.h> |
3603 | +#include <iostream> |
3604 | +#include <sstream> |
3605 | +#include <string> |
3606 | + |
3607 | +using namespace drizzled; |
3608 | +using namespace std; |
3609 | + |
3610 | +TEST(TableIdentifierTest, operator_ostream_type_STANDARD) |
3611 | +{ |
3612 | + size_t hash; |
3613 | + string expected = "TableIdentifier:(DatabaseArg, TableNameArg, standard, databasearg/tablenamearg, "; |
3614 | + ostringstream oss(ostringstream::out); |
3615 | + istringstream iss(istringstream::in); |
3616 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3617 | + |
3618 | + oss << table_identifier; |
3619 | + |
3620 | + EXPECT_EQ(expected, oss.str().substr(0, expected.size())); |
3621 | + EXPECT_EQ(')', oss.str().c_str()[oss.str().size() - 1]); |
3622 | + iss.str(oss.str().substr(expected.size(), oss.str().size() - expected.size() - 1)); |
3623 | + iss >> hash; |
3624 | + EXPECT_FALSE(iss.fail()); |
3625 | +} |
3626 | + |
3627 | +TEST(TableIdentifierTest, operator_ostream_with_pathArg) |
3628 | +{ |
3629 | + size_t hash; |
3630 | + string expected = "TableIdentifier:(DatabaseArg, TableNameArg, temporary, PathArg, "; |
3631 | + ostringstream oss(ostringstream::out); |
3632 | + istringstream iss(istringstream::in); |
3633 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", "PathArg"); |
3634 | + |
3635 | + oss << table_identifier; |
3636 | + |
3637 | + EXPECT_EQ(expected, oss.str().substr(0, expected.size())); |
3638 | + EXPECT_EQ(')', oss.str().c_str()[oss.str().size() - 1]); |
3639 | + iss.str(oss.str().substr(expected.size(), oss.str().size() - expected.size() - 1)); |
3640 | + iss >> hash; |
3641 | + EXPECT_FALSE(iss.fail()); |
3642 | +} |
3643 | + |
3644 | +TEST(TableIdentifierTest, operator_equal_comparingEqualTableIdentifiers_shouldReturn_True) |
3645 | +{ |
3646 | + ostringstream oss(ostringstream::out); |
3647 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3648 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3649 | + |
3650 | + ASSERT_EQ(table_identifier1, table_identifier2); |
3651 | +} |
3652 | + |
3653 | +TEST(TableIdentifierTest, operator_equal_comparingTableIdentifiers_WithDifferentTypes_shouldReturn_False) |
3654 | +{ |
3655 | + ostringstream oss(ostringstream::out); |
3656 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3657 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg", message::Table::TEMPORARY); |
3658 | + |
3659 | + ASSERT_FALSE(table_identifier1 == table_identifier2); |
3660 | +} |
3661 | + |
3662 | +TEST(TableIdentifierTest, operator_equal_comparingTableIdentifiers_WithDifferentTableNames_shouldReturn_False) |
3663 | +{ |
3664 | + ostringstream oss(ostringstream::out); |
3665 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3666 | + TableIdentifier table_identifier2("DatabaseArg", "OtherTableNameArg", message::Table::STANDARD); |
3667 | + |
3668 | + ASSERT_FALSE(table_identifier1 == table_identifier2); |
3669 | +} |
3670 | + |
3671 | +TEST(TableIdentifierTest, operator_equal_comparingTableIdentifiers_WithDifferentDatabases_shouldReturn_False) |
3672 | +{ |
3673 | + ostringstream oss(ostringstream::out); |
3674 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3675 | + TableIdentifier table_identifier2("DifferentDatabaseArg", "TableNameArg", message::Table::STANDARD); |
3676 | + |
3677 | + ASSERT_FALSE(table_identifier1 == table_identifier2); |
3678 | +} |
3679 | + |
3680 | +TEST(TableIdentifierTest, operator_lessThan_comparingEqualTableIdentifiers_shouldReturn_False) |
3681 | +{ |
3682 | + ostringstream oss(ostringstream::out); |
3683 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3684 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3685 | + |
3686 | + ASSERT_FALSE(table_identifier1 < table_identifier2); |
3687 | +} |
3688 | + |
3689 | +TEST(TableIdentifierTest, operator_lessThan_comparingWithTableIdentifier_WithSmallerDatabaseArg_shouldReturn_False) |
3690 | +{ |
3691 | + ostringstream oss(ostringstream::out); |
3692 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3693 | + TableIdentifier table_identifier2("AAADatabaseArg", "TableNameArg", message::Table::STANDARD); |
3694 | + |
3695 | + ASSERT_FALSE(table_identifier1 < table_identifier2); |
3696 | +} |
3697 | + |
3698 | +TEST(TableIdentifierTest, operator_lessThan_comparingWithTableIdentifier_WithBiggerDatabaseArg_shouldReturn_True) |
3699 | +{ |
3700 | + ostringstream oss(ostringstream::out); |
3701 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3702 | + TableIdentifier table_identifier2("ZZZDatabaseArg", "TableNameArg", message::Table::STANDARD); |
3703 | + |
3704 | + ASSERT_TRUE(table_identifier1 < table_identifier2); |
3705 | +} |
3706 | + |
3707 | +TEST(TableIdentifierTest, operator_lessThan_comparingWithTableIdentifier_WithSmallerTableNameArg_shouldReturn_False) |
3708 | +{ |
3709 | + ostringstream oss(ostringstream::out); |
3710 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3711 | + TableIdentifier table_identifier2("DatabaseArg", "AAATableNameArg", message::Table::STANDARD); |
3712 | + |
3713 | + ASSERT_FALSE(table_identifier1 < table_identifier2); |
3714 | +} |
3715 | + |
3716 | +TEST(TableIdentifierTest, operator_lessThan_comparingWithTableIdentifier_WithBiggerTableNameArg_shouldReturn_True) |
3717 | +{ |
3718 | + ostringstream oss(ostringstream::out); |
3719 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3720 | + TableIdentifier table_identifier2("DatabaseArg", "ZZZTableNameArg", message::Table::STANDARD); |
3721 | + |
3722 | + ASSERT_TRUE(table_identifier1 < table_identifier2); |
3723 | +} |
3724 | + |
3725 | +TEST(TableIdentifierTest, operator_lessThan_comparingWithTableIdentifier_WithSmallerTypeArg_shouldReturn_False) |
3726 | +{ |
3727 | + ostringstream oss(ostringstream::out); |
3728 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::TEMPORARY); |
3729 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3730 | + |
3731 | + ASSERT_FALSE(table_identifier1 < table_identifier2); |
3732 | +} |
3733 | + |
3734 | +TEST(TableIdentifierTest, operator_lessThan_comparingWithTableIdentifier_WithBiggerTypeArg_shouldReturn_True) |
3735 | +{ |
3736 | + ostringstream oss(ostringstream::out); |
3737 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3738 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg", message::Table::TEMPORARY); |
3739 | + |
3740 | + ASSERT_TRUE(table_identifier1 < table_identifier2); |
3741 | +} |
3742 | + |
3743 | +TEST(TableIdentifierTest, filename_to_tablename_fromTemporaryTableFileName_shouldJustCopy) |
3744 | +{ |
3745 | + char from[]= TMP_FILE_PREFIX"Filename"; |
3746 | + char to[sizeof(from) / sizeof(from[0])]; |
3747 | + to[sizeof(from) / sizeof(from[0]) - 1]= '\0'; |
3748 | + |
3749 | + TableIdentifier::filename_to_tablename(from, to, sizeof(to) / sizeof(to[0]) - 1); |
3750 | + |
3751 | + ASSERT_STREQ(from, to); |
3752 | +} |
3753 | + |
3754 | +TEST(TableIdentifierTest, filename_to_tablename_fromTemporaryTableFileName_LengthNotSufficent_shouldCopyAndTrim) |
3755 | +{ |
3756 | + char from[]= TMP_FILE_PREFIX"Filename"; |
3757 | + char to[TMP_FILE_PREFIX_LENGTH + 3]; |
3758 | + to[TMP_FILE_PREFIX_LENGTH + 2]= '\0'; |
3759 | + |
3760 | + TableIdentifier::filename_to_tablename(from, to, TMP_FILE_PREFIX_LENGTH + 2); |
3761 | + |
3762 | + ASSERT_STREQ(TMP_FILE_PREFIX"Fi", to); |
3763 | +} |
3764 | + |
3765 | +TEST(TableIdentifierTest, filename_to_tablename_fromNormalTableFileName_shouldJustCopy) |
3766 | +{ |
3767 | + char from[]= "Filename"; |
3768 | + char to[sizeof(from) / sizeof(from[0])]; |
3769 | + to[sizeof(from) / sizeof(from[0]) - 1]= '\0'; |
3770 | + |
3771 | + TableIdentifier::filename_to_tablename(from, to, sizeof(to) / sizeof(to[0]) - 1); |
3772 | + |
3773 | + ASSERT_STREQ(from, to); |
3774 | +} |
3775 | + |
3776 | +TEST(TableIdentifierTest, filename_to_tablename_fromNormalTableFileName_LengthNotSufficent_shouldCopyAndTrim) |
3777 | +{ |
3778 | + char from[]= "Filename"; |
3779 | + char to[3]; |
3780 | + to[2]= '\0'; |
3781 | + |
3782 | + TableIdentifier::filename_to_tablename(from, to, 2); |
3783 | + |
3784 | + ASSERT_STREQ("Fi", to); |
3785 | +} |
3786 | + |
3787 | +TEST(TableIdentifierTest, filename_to_tablename_fromNormalTableFileName_WithEscapedChars_shouldJustCopy) |
3788 | +{ |
3789 | + char from[]= "Filen@21ame@26"; |
3790 | + char expected[]= "Filen!ame&"; |
3791 | + char to[sizeof(expected) / sizeof(expected[0])]; |
3792 | + to[sizeof(expected) / sizeof(expected[0]) - 1]= '\0'; |
3793 | + |
3794 | + TableIdentifier::filename_to_tablename(from, to, sizeof(to) / sizeof(to[0]) - 1); |
3795 | + |
3796 | + ASSERT_STREQ(expected, to); |
3797 | +} |
3798 | + |
3799 | +TEST(TableIdentifierTest, filename_to_tablename_fromNormalTableFileName_WithEscapedChars_LengthNotSufficent_shouldCopyAndTrim) |
3800 | +{ |
3801 | + char from[]= "Filen@21ame@26"; |
3802 | + char to[7]; |
3803 | + to[6]= '\0'; |
3804 | + |
3805 | + TableIdentifier::filename_to_tablename(from, to, 6); |
3806 | + |
3807 | + ASSERT_STREQ("Filen!", to); |
3808 | +} |
3809 | + |
3810 | +static char home_stub[]= "homestub/"; |
3811 | +static char tmpdir_stub[]= "tmpdirstub"; |
3812 | + |
3813 | +class TableIdentifierGlobalDirsSetTest : public ::testing::Test |
3814 | +{ |
3815 | +protected: |
3816 | + string old_tmpdir; |
3817 | + char *old_data_home; |
3818 | +public: |
3819 | + virtual void SetUp() |
3820 | + { |
3821 | + old_data_home= data_home; |
3822 | + data_home= home_stub; |
3823 | + |
3824 | + old_tmpdir= drizzle_tmpdir; |
3825 | + drizzle_tmpdir= tmpdir_stub; |
3826 | + } |
3827 | + |
3828 | + virtual void TearDown() |
3829 | + { |
3830 | + data_home= old_data_home; |
3831 | + drizzle_tmpdir= old_tmpdir; |
3832 | + } |
3833 | +}; |
3834 | + |
3835 | +TEST_F(TableIdentifierGlobalDirsSetTest, build_table_filename_date_home_set) |
3836 | +{ |
3837 | + char my_home_stub[]= "homestub"; |
3838 | + data_home= my_home_stub; |
3839 | + string path; |
3840 | + int len; |
3841 | + |
3842 | + len= TableIdentifier::build_table_filename(path, "DatabaseArg", "TableNameArg", false); |
3843 | + |
3844 | + EXPECT_EQ(strlen("homestub/databasearg/tablenamearg"), len); |
3845 | + EXPECT_EQ("homestub/databasearg/tablenamearg", path); |
3846 | +} |
3847 | + |
3848 | +TEST_F(TableIdentifierGlobalDirsSetTest, build_table_filename_data_home_has_FN_ROOTDIR_alreadyInItself) |
3849 | +{ |
3850 | + string path; |
3851 | + int len; |
3852 | + |
3853 | + len= TableIdentifier::build_table_filename(path, "DatabaseArg", "TableNameArg", false); |
3854 | + |
3855 | + EXPECT_EQ(strlen("homestub/databasearg/tablenamearg"), len); |
3856 | + EXPECT_EQ("homestub/databasearg/tablenamearg", path); |
3857 | +} |
3858 | + |
3859 | +TEST_F(TableIdentifierGlobalDirsSetTest, build_table_filename_ArgsHaveSpecialChars_whichShouldBeEscaped) |
3860 | +{ |
3861 | + string path; |
3862 | + int len; |
3863 | + |
3864 | + len= TableIdentifier::build_table_filename(path, "Database%Arg", "Tab!!leNameArg", false); |
3865 | + |
3866 | + EXPECT_EQ(strlen("homestub/database@25arg/tab@21@21lenamearg"), len); |
3867 | + EXPECT_EQ("homestub/database@25arg/tab@21@21lenamearg", path); |
3868 | +} |
3869 | + |
3870 | +TEST_F(TableIdentifierGlobalDirsSetTest, build_table_filename_isTemp_TableNameArgShouldBeLeftUnchanged) |
3871 | +{ |
3872 | + string path; |
3873 | + int len; |
3874 | + |
3875 | + len= TableIdentifier::build_table_filename(path, "Database%Arg", "Tab!!leNameArg", true); |
3876 | + |
3877 | + EXPECT_EQ(strlen("homestub/database@25arg/Tab!!leNameArg"), len); |
3878 | + EXPECT_EQ("homestub/database@25arg/Tab!!leNameArg", path); |
3879 | +} |
3880 | + |
3881 | +TEST_F(TableIdentifierGlobalDirsSetTest, getPath_type_STANDARD) |
3882 | +{ |
3883 | + string path; |
3884 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3885 | + |
3886 | + path= table_identifier.getPath(); |
3887 | + EXPECT_EQ("homestub/databasearg/tablenamearg", path); |
3888 | +} |
3889 | + |
3890 | +TEST_F(TableIdentifierGlobalDirsSetTest, getPath_type_INTERNAL) |
3891 | +{ |
3892 | + string path; |
3893 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::INTERNAL); |
3894 | + |
3895 | + path= table_identifier.getPath(); |
3896 | + EXPECT_EQ("homestub/databasearg/tablenamearg", path); |
3897 | +} |
3898 | + |
3899 | +TEST_F(TableIdentifierGlobalDirsSetTest, getPath_type_TEMPORARY_ShouldHaveProperPrefix) |
3900 | +{ |
3901 | + string path; |
3902 | + string expected_prefix= "tmpdirstub/"TMP_FILE_PREFIX; |
3903 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::TEMPORARY); |
3904 | + |
3905 | + path= table_identifier.getPath(); |
3906 | + EXPECT_EQ(expected_prefix, path.substr(0, expected_prefix.size())); |
3907 | + drizzle_tmpdir= ""; |
3908 | +} |
3909 | + |
3910 | +TEST_F(TableIdentifierGlobalDirsSetTest, getPath_type_TEMPORARY_ShouldProduceUniqueNames) |
3911 | +{ |
3912 | + string path1, path2; |
3913 | + TableIdentifier table_identifier1("DatabaseArg", "TableNameArg1", message::Table::TEMPORARY); |
3914 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg2", message::Table::TEMPORARY); |
3915 | + |
3916 | + path1= table_identifier1.getPath(); |
3917 | + path2= table_identifier2.getPath(); |
3918 | + EXPECT_NE(path1, path2); |
3919 | +} |
3920 | + |
3921 | +TEST(TableIdentifierTest, getPath_type_FUNCTION) |
3922 | +{ |
3923 | + string path; |
3924 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::FUNCTION); |
3925 | + |
3926 | + path= table_identifier.getPath(); |
3927 | + EXPECT_EQ("DatabaseArg.TableNameArg", path); |
3928 | +} |
3929 | + |
3930 | +TEST(TableIdentifierTest, compare_identicalValues_shouldReturn_True) |
3931 | +{ |
3932 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3933 | + TableIdentifier table_identifier2("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3934 | + |
3935 | + ASSERT_TRUE(table_identifier == table_identifier2); |
3936 | +} |
3937 | + |
3938 | +TEST(TableIdentifierTest, compare_differentDatabaseValue_shouldReturn_False) |
3939 | +{ |
3940 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3941 | + TableIdentifier table_identifier2("DifferentDatabaseArg", "TableNameArg", message::Table::STANDARD); |
3942 | + |
3943 | + ASSERT_FALSE(table_identifier == table_identifier2); |
3944 | +} |
3945 | + |
3946 | +TEST(TableIdentifierTest, compare_differentTableNameValue_shouldReturn_False) |
3947 | +{ |
3948 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3949 | + TableIdentifier table_identifier2("DatabaseArg", "DifferentTableNameArg", message::Table::STANDARD); |
3950 | + |
3951 | + ASSERT_FALSE(table_identifier == table_identifier2); |
3952 | +} |
3953 | + |
3954 | +TEST(TableIdentifierTest, getSQLPath_type_FUNCTION) |
3955 | +{ |
3956 | + string path; |
3957 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::FUNCTION); |
3958 | + |
3959 | + path= table_identifier.getSQLPath(); |
3960 | + EXPECT_EQ("databasearg.TableNameArg", path); |
3961 | +} |
3962 | + |
3963 | +TEST(TableIdentifierTest, getSQLPath_type_STANDARD) |
3964 | +{ |
3965 | + string path; |
3966 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::STANDARD); |
3967 | + |
3968 | + path= table_identifier.getSQLPath(); |
3969 | + EXPECT_EQ("databasearg.TableNameArg", path); |
3970 | +} |
3971 | + |
3972 | +TEST(TableIdentifierTest, getSQLPath_type_INTERNAL) |
3973 | +{ |
3974 | + string path; |
3975 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::INTERNAL); |
3976 | + |
3977 | + path= table_identifier.getSQLPath(); |
3978 | + EXPECT_EQ("temporary.TableNameArg", path); |
3979 | +} |
3980 | + |
3981 | +TEST(TableIdentifierTest, getSQLPath_type_TEMPORARY) |
3982 | +{ |
3983 | + string path; |
3984 | + TableIdentifier table_identifier("DatabaseArg", "TableNameArg", message::Table::TEMPORARY); |
3985 | + |
3986 | + path= table_identifier.getSQLPath(); |
3987 | + EXPECT_EQ("databasearg.#TableNameArg", path); |
3988 | +} |
3989 | |
3990 | === added file 'unittests/table_list_test.cc' |
3991 | --- unittests/table_list_test.cc 1970-01-01 00:00:00 +0000 |
3992 | +++ unittests/table_list_test.cc 2010-08-15 23:41:09 +0000 |
3993 | @@ -0,0 +1,404 @@ |
3994 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
3995 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
3996 | +* |
3997 | +* Copyright (C) 2010 Pawel Blokus |
3998 | +* |
3999 | +* This program is free software; you can redistribute it and/or modify |
4000 | +* it under the terms of the GNU General Public License as published by |
4001 | +* the Free Software Foundation; either version 2 of the License, or |
4002 | +* (at your option) any later version. |
4003 | +* |
4004 | +* This program is distributed in the hope that it will be useful, |
4005 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4006 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4007 | +* GNU General Public License for more details. |
4008 | +* |
4009 | +* You should have received a copy of the GNU General Public License |
4010 | +* along with this program; if not, write to the Free Software |
4011 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4012 | +*/ |
4013 | + |
4014 | +#include "config.h" |
4015 | + |
4016 | +#include <gtest/gtest.h> |
4017 | + |
4018 | +#include <drizzled/error.h> |
4019 | +#include <drizzled/global_charset_info.h> |
4020 | +#include <drizzled/nested_join.h> |
4021 | +#include <drizzled/session.h> |
4022 | +#include <drizzled/sql_string.h> |
4023 | +#include <drizzled/table.h> |
4024 | +#include <drizzled/table_share.h> |
4025 | +#include <drizzled/table_list.h> |
4026 | + |
4027 | +#include "generator.h" |
4028 | +#include "stubs.h" |
4029 | + |
4030 | +using namespace drizzled; |
4031 | + |
4032 | +class TableListTest : public ::testing::Test |
4033 | +{ |
4034 | +protected: |
4035 | + TableList table_list_lvl0, table_list_lvl1_1, table_list_lvl1_2, table_list_lvl2_1, table_list_lvl2_2,; |
4036 | + nested_join_st nested_join_lvl0, nested_join_lvl1; |
4037 | + TableList *table_list_ptr; |
4038 | + Session *fake_session; |
4039 | + Table table; |
4040 | + TableShareStub table_share; |
4041 | + List<Index_hint> index_hints; |
4042 | + int retval; |
4043 | +public: |
4044 | + |
4045 | + virtual void SetUp() |
4046 | + { |
4047 | + error_handler_hook= error_handler_func_stub; |
4048 | + |
4049 | + table_list_lvl0.index_hints= &index_hints; |
4050 | + |
4051 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
4052 | + nested_join_lvl0.join_list.push_front(&table_list_lvl1_1); |
4053 | + nested_join_lvl0.join_list.push_front(&table_list_lvl1_2); |
4054 | + |
4055 | + table_list_lvl1_1.setJoinList(&nested_join_lvl0.join_list); |
4056 | + table_list_lvl1_2.setJoinList(&nested_join_lvl0.join_list); |
4057 | + |
4058 | + nested_join_lvl1.join_list.push_front(&table_list_lvl2_1); |
4059 | + nested_join_lvl1.join_list.push_front(&table_list_lvl2_2); |
4060 | + |
4061 | + table_list_lvl2_1.setJoinList(&nested_join_lvl1.join_list); |
4062 | + table_list_lvl2_2.setJoinList(&nested_join_lvl1.join_list); |
4063 | + |
4064 | + table_alias_charset= default_charset_info; |
4065 | + system_charset_info= default_charset_info; |
4066 | + |
4067 | + table.s= &table_share; |
4068 | + } |
4069 | + |
4070 | + void constructRightChildPath() |
4071 | + { |
4072 | + table_list_lvl0.setNestedJoin(&nested_join_lvl0); |
4073 | + table_list_lvl1_2.setNestedJoin(&nested_join_lvl1); |
4074 | + } |
4075 | + |
4076 | + void constructLeftChildPath() |
4077 | + { |
4078 | + table_list_lvl0.setNestedJoin(&nested_join_lvl0); |
4079 | + table_list_lvl1_1.setNestedJoin(&nested_join_lvl1); |
4080 | + } |
4081 | + |
4082 | + void setRightJoin() |
4083 | + { |
4084 | + table_list_lvl1_1.outer_join= JOIN_TYPE_RIGHT; |
4085 | + table_list_lvl1_2.outer_join= JOIN_TYPE_RIGHT; |
4086 | + table_list_lvl2_1.outer_join= JOIN_TYPE_RIGHT; |
4087 | + table_list_lvl2_2.outer_join= JOIN_TYPE_RIGHT; |
4088 | + } |
4089 | + |
4090 | + void addIndexHint(Index_hint *hint) |
4091 | + { |
4092 | + index_hints.push_back(hint); |
4093 | + if (hint->key_name.str) |
4094 | + table_share.addKeyName(hint->key_name.str); |
4095 | + } |
4096 | + |
4097 | + virtual void TearDown() |
4098 | + { |
4099 | + table_alias_charset= NULL; |
4100 | + system_charset_info= NULL; |
4101 | + //delete fake_session;TODO: this causes problems |
4102 | + } |
4103 | +}; |
4104 | + |
4105 | +TEST_F(TableListTest, last_leaf_for_name_resolution_IsALeafItself_shouldReturnItself) |
4106 | +{ |
4107 | + table_list_ptr= table_list_lvl0.last_leaf_for_name_resolution(); |
4108 | + |
4109 | + ASSERT_EQ(&table_list_lvl0, table_list_ptr); |
4110 | +} |
4111 | + |
4112 | +TEST_F(TableListTest, last_leaf_for_name_resolution) |
4113 | +{ |
4114 | + constructRightChildPath(); |
4115 | + table_list_ptr= table_list_lvl0.last_leaf_for_name_resolution(); |
4116 | + |
4117 | + ASSERT_EQ(&table_list_lvl2_2, table_list_ptr); |
4118 | +} |
4119 | + |
4120 | +TEST_F(TableListTest, first_leaf_for_name_resolution) |
4121 | +{ |
4122 | + constructLeftChildPath(); |
4123 | + table_list_ptr= table_list_lvl0.first_leaf_for_name_resolution(); |
4124 | + |
4125 | + ASSERT_EQ(&table_list_lvl2_1, table_list_ptr); |
4126 | +} |
4127 | + |
4128 | +TEST_F(TableListTest, last_leaf_for_name_resolution_RightJoin) |
4129 | +{ |
4130 | + constructLeftChildPath(); |
4131 | + setRightJoin(); |
4132 | + table_list_ptr= table_list_lvl0.last_leaf_for_name_resolution(); |
4133 | + |
4134 | + ASSERT_EQ(&table_list_lvl2_1, table_list_ptr); |
4135 | +} |
4136 | + |
4137 | +TEST_F(TableListTest, first_leaf_for_name_resolution_RightJoin) |
4138 | +{ |
4139 | + constructRightChildPath(); |
4140 | + setRightJoin(); |
4141 | + table_list_ptr= table_list_lvl0.first_leaf_for_name_resolution(); |
4142 | + |
4143 | + ASSERT_EQ(&table_list_lvl2_2, table_list_ptr); |
4144 | +} |
4145 | + |
4146 | +TEST_F(TableListTest, print_NormalTable) |
4147 | +{ |
4148 | + char table_name_stub[]= "TableNameStub"; |
4149 | + char db_stub[]= "DBStub"; |
4150 | + char alias_stub[]= "AliasStub"; |
4151 | + String expected("`DBStub`.`TableNameStub` `aliasstub`", default_charset_info); |
4152 | + String printed; |
4153 | + |
4154 | + table_list_lvl0.table_name= table_name_stub; |
4155 | + table_list_lvl0.table_name_length= sizeof(table_name_stub) - 1; |
4156 | + table_list_lvl0.db= db_stub; |
4157 | + table_list_lvl0.db_length= sizeof(db_stub) - 1; |
4158 | + table_list_lvl0.alias= alias_stub; |
4159 | + |
4160 | + table_list_lvl0.print(NULL, &printed, QT_ORDINARY); |
4161 | + |
4162 | + EXPECT_TRUE(printed == expected); |
4163 | +} |
4164 | + |
4165 | +TEST_F(TableListTest, print_WithIndexHints_ShouldPrintIndexHintToo) |
4166 | +{ |
4167 | + char table_name_stub[]= ""; |
4168 | + char index_hint_name_stub[]= "IndexHintNameStub"; |
4169 | + Index_hint index_hint_stub(INDEX_HINT_IGNORE, 0, index_hint_name_stub, sizeof(index_hint_name_stub) - 1); |
4170 | + char alias_stub[]= "AliasStub"; |
4171 | + String expected("``.`` `aliasstub` IGN (`IndexHintNameStub`)", default_charset_info); |
4172 | + String printed; |
4173 | + addIndexHint(&index_hint_stub); |
4174 | + |
4175 | + table_list_lvl0.table_name= table_name_stub; |
4176 | + table_list_lvl0.table_name_length= sizeof(table_name_stub) - 1; |
4177 | + table_list_lvl0.alias= alias_stub; |
4178 | + |
4179 | + table_list_lvl0.print(NULL, &printed, QT_ORDINARY); |
4180 | + |
4181 | + EXPECT_TRUE(printed == expected); |
4182 | +} |
4183 | + |
4184 | +TEST_F(TableListTest, print_NestedJoin_ShouldReplaceNestedJoinsWithTheirChildrenPrinted) |
4185 | +{ |
4186 | + char table_name_stub[]= ""; |
4187 | + String expected("(``.`` `aliasstub1_1` join (``.`` `aliasstub2_1` join ``.`` `aliasstub2_2`))", default_charset_info); |
4188 | + String printed; |
4189 | + |
4190 | + table_list_lvl1_1.table_name= table_name_stub; |
4191 | + table_list_lvl1_1.table_name_length= sizeof(table_name_stub) - 1; |
4192 | + table_list_lvl1_1.alias= "AliasStub1_1"; |
4193 | + |
4194 | + table_list_lvl2_1.table_name= table_name_stub; |
4195 | + table_list_lvl2_1.table_name_length= sizeof(table_name_stub) - 1; |
4196 | + table_list_lvl2_1.alias= "AliasStub2_1"; |
4197 | + |
4198 | + table_list_lvl2_2.table_name= table_name_stub; |
4199 | + table_list_lvl2_2.table_name_length= sizeof(table_name_stub) - 1; |
4200 | + table_list_lvl2_2.alias= "AliasStub2_2"; |
4201 | + |
4202 | + constructRightChildPath(); |
4203 | + |
4204 | + table_list_lvl0.print(fake_session, &printed, QT_ORDINARY); |
4205 | + |
4206 | + EXPECT_TRUE(printed == expected); |
4207 | +} |
4208 | + |
4209 | +class Select_Lex_Unit_Stub : public Select_Lex_Unit |
4210 | +{ |
4211 | +public: |
4212 | + void setSlave(Select_Lex *select_lex_node) |
4213 | + { |
4214 | + slave= select_lex_node; |
4215 | + } |
4216 | +}; |
4217 | + |
4218 | +class Select_Lex_Stub : public Select_Lex |
4219 | +{ |
4220 | + public: |
4221 | + Select_Lex_Stub() |
4222 | + { |
4223 | + next= NULL; |
4224 | + } |
4225 | + void setMaster(Select_Lex_Node *select_lex_master) |
4226 | + { |
4227 | + master= select_lex_master; |
4228 | + } |
4229 | +}; |
4230 | + |
4231 | +TEST_F(TableListTest, print_DerivedTable) |
4232 | +{ |
4233 | + char table_name_stub[]= ""; |
4234 | + char alias_stub[]= "AliasStub"; |
4235 | + String expected("(select ) `aliasstub`", default_charset_info); |
4236 | + String printed; |
4237 | + Select_Lex_Unit_Stub select_lex_unit; |
4238 | + Select_Lex_Stub select_lex_node1; |
4239 | + Generator::SelectLexGenerator::make_Select_Lex_empty_for_print(&select_lex_node1); |
4240 | + select_lex_unit.setSlave(&select_lex_node1); |
4241 | + select_lex_unit.session= fake_session; |
4242 | + select_lex_unit.item= NULL; |
4243 | + select_lex_node1.setMaster(&select_lex_unit); |
4244 | + |
4245 | + table_list_lvl0.derived= &select_lex_unit; |
4246 | + table_list_lvl0.table_name= table_name_stub; |
4247 | + table_list_lvl0.table_name_length= sizeof(table_name_stub) - 1; |
4248 | + table_list_lvl0.alias= alias_stub; |
4249 | + |
4250 | + table_list_lvl0.print(fake_session, &printed, QT_ORDINARY); |
4251 | + |
4252 | + EXPECT_TRUE(printed == expected); |
4253 | +} |
4254 | + |
4255 | + |
4256 | +TEST_F(TableListTest, process_index_hints_UseIndexIsEmpty_shouldReset_keys_in_use) |
4257 | +{ |
4258 | + Index_hint join_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_JOIN, NULL, 0); |
4259 | + addIndexHint(&join_index_hint_stub); |
4260 | + Index_hint group_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_GROUP, NULL, 0); |
4261 | + addIndexHint(&group_index_hint_stub); |
4262 | + Index_hint order_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_ORDER, NULL, 0); |
4263 | + addIndexHint(&order_index_hint_stub); |
4264 | + table.keys_in_use_for_query.set(4); |
4265 | + table.keys_in_use_for_group_by.set(4); |
4266 | + table.keys_in_use_for_order_by.set(4); |
4267 | + |
4268 | + table_list_lvl0.process_index_hints(&table); |
4269 | + |
4270 | + EXPECT_FALSE(table.keys_in_use_for_query[4]); |
4271 | + EXPECT_FALSE(table.keys_in_use_for_group_by[4]); |
4272 | + EXPECT_FALSE(table.keys_in_use_for_order_by[4]); |
4273 | +} |
4274 | + |
4275 | +TEST_F(TableListTest, process_index_hints_UseNonExistingKey_ShouldReturn_1) |
4276 | +{ |
4277 | + char index_hint_name_stub[]= "IndexHintNameStub"; |
4278 | + Index_hint index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_JOIN, index_hint_name_stub, sizeof(index_hint_name_stub) - 1); |
4279 | + index_hints.push_back(&index_hint_stub); |
4280 | + |
4281 | + retval= table_list_lvl0.process_index_hints(&table); |
4282 | + |
4283 | + ASSERT_EQ(1, retval); |
4284 | +} |
4285 | + |
4286 | +TEST_F(TableListTest, process_index_hints_UseBoth_UseIndex_And_ForceIndex_shouldReturn_1) |
4287 | +{ |
4288 | + char index_hint_name_stub[]= "IndexHintNameStub"; |
4289 | + Index_hint use_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_JOIN, index_hint_name_stub, sizeof(index_hint_name_stub) - 1); |
4290 | + index_hints.push_back(&use_index_hint_stub); |
4291 | + Index_hint force_index_hint_stub(INDEX_HINT_FORCE, INDEX_HINT_MASK_JOIN, index_hint_name_stub, sizeof(index_hint_name_stub) - 1); |
4292 | + index_hints.push_back(&force_index_hint_stub); |
4293 | + |
4294 | + retval= table_list_lvl0.process_index_hints(&table); |
4295 | + |
4296 | + ASSERT_EQ(1, retval); |
4297 | +} |
4298 | + |
4299 | +TEST_F(TableListTest, process_index_hints_UseIndex_ShouldSet_keys_in_use_Properly) |
4300 | +{ |
4301 | + char index_hint_name_stub1[]= "IndexHintNameStub1"; |
4302 | + char index_hint_name_stub2[]= "IndexHintNameStub2"; |
4303 | + char index_hint_name_stub3[]= "IndexHintNameStub3"; |
4304 | + Index_hint join_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_JOIN, index_hint_name_stub1, sizeof(index_hint_name_stub1) - 1); |
4305 | + addIndexHint(&join_index_hint_stub); |
4306 | + Index_hint group_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_GROUP, index_hint_name_stub2, sizeof(index_hint_name_stub2) - 1); |
4307 | + addIndexHint(&group_index_hint_stub); |
4308 | + Index_hint order_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_ORDER, index_hint_name_stub3, sizeof(index_hint_name_stub3) - 1); |
4309 | + addIndexHint(&order_index_hint_stub); |
4310 | + table_share.keys_in_use.set(0); |
4311 | + table_share.keys_in_use.set(1); |
4312 | + table_share.keys_in_use.set(2); |
4313 | + |
4314 | + table_list_lvl0.process_index_hints(&table); |
4315 | + |
4316 | + EXPECT_TRUE(table.keys_in_use_for_query[0]); |
4317 | + EXPECT_TRUE(table.keys_in_use_for_group_by[1]); |
4318 | + EXPECT_TRUE(table.keys_in_use_for_order_by[2]); |
4319 | +} |
4320 | + |
4321 | +TEST_F(TableListTest, process_index_hints_ForceIndex_ShouldSet_keys_in_use_Properly) |
4322 | +{ |
4323 | + char index_hint_name_stub1[]= "IndexHintNameStub1"; |
4324 | + char index_hint_name_stub2[]= "IndexHintNameStub2"; |
4325 | + char index_hint_name_stub3[]= "IndexHintNameStub3"; |
4326 | + Index_hint join_index_hint_stub(INDEX_HINT_FORCE, INDEX_HINT_MASK_JOIN, index_hint_name_stub1, sizeof(index_hint_name_stub1) - 1); |
4327 | + addIndexHint(&join_index_hint_stub); |
4328 | + Index_hint group_index_hint_stub(INDEX_HINT_FORCE, INDEX_HINT_MASK_GROUP, index_hint_name_stub2, sizeof(index_hint_name_stub2) - 1); |
4329 | + addIndexHint(&group_index_hint_stub); |
4330 | + Index_hint order_index_hint_stub(INDEX_HINT_FORCE, INDEX_HINT_MASK_ORDER, index_hint_name_stub3, sizeof(index_hint_name_stub3) - 1); |
4331 | + addIndexHint(&order_index_hint_stub); |
4332 | + table_share.keys_in_use.set(0); |
4333 | + table_share.keys_in_use.set(1); |
4334 | + table_share.keys_in_use.set(2); |
4335 | + |
4336 | + table_list_lvl0.process_index_hints(&table); |
4337 | + |
4338 | + EXPECT_TRUE(table.force_index); |
4339 | + EXPECT_TRUE(table.keys_in_use_for_query[0]); |
4340 | + EXPECT_TRUE(table.keys_in_use_for_group_by[1]); |
4341 | + EXPECT_TRUE(table.keys_in_use_for_order_by[2]); |
4342 | +} |
4343 | + |
4344 | +TEST_F(TableListTest, process_index_hints_IgnoreIndex_ShouldReset_keys_in_use_Properly) |
4345 | +{ |
4346 | + char index_hint_name_stub1[]= "IndexHintNameStub1"; |
4347 | + char index_hint_name_stub2[]= "IndexHintNameStub2"; |
4348 | + char index_hint_name_stub3[]= "IndexHintNameStub3"; |
4349 | + Index_hint join_index_hint_stub(INDEX_HINT_IGNORE, INDEX_HINT_MASK_JOIN, index_hint_name_stub1, sizeof(index_hint_name_stub1) - 1); |
4350 | + addIndexHint(&join_index_hint_stub); |
4351 | + Index_hint group_index_hint_stub(INDEX_HINT_IGNORE, INDEX_HINT_MASK_GROUP, index_hint_name_stub2, sizeof(index_hint_name_stub2) - 1); |
4352 | + addIndexHint(&group_index_hint_stub); |
4353 | + Index_hint order_index_hint_stub(INDEX_HINT_IGNORE, INDEX_HINT_MASK_ORDER, index_hint_name_stub3, sizeof(index_hint_name_stub3) - 1); |
4354 | + addIndexHint(&order_index_hint_stub); |
4355 | + table_share.keys_in_use.set(0); |
4356 | + table_share.keys_in_use.set(1); |
4357 | + table_share.keys_in_use.set(2); |
4358 | + table_share.keys_in_use.set(4); |
4359 | + |
4360 | + |
4361 | + table_list_lvl0.process_index_hints(&table); |
4362 | + |
4363 | + EXPECT_FALSE(table.keys_in_use_for_query[0]); |
4364 | + EXPECT_FALSE(table.keys_in_use_for_group_by[1]); |
4365 | + EXPECT_FALSE(table.keys_in_use_for_order_by[2]); |
4366 | + EXPECT_TRUE(table.keys_in_use_for_query[4]); |
4367 | + EXPECT_TRUE(table.keys_in_use_for_group_by[4]); |
4368 | + EXPECT_TRUE(table.keys_in_use_for_order_by[4]); |
4369 | +} |
4370 | + |
4371 | +TEST_F(TableListTest, process_index_hints_IgnoreIndex_ShouldReset_covering_keys_Too) |
4372 | +{ |
4373 | + char index_hint_name_stub[]= "IndexHintNameStub"; |
4374 | + |
4375 | + Index_hint join_index_hint_stub(INDEX_HINT_IGNORE, INDEX_HINT_MASK_JOIN, index_hint_name_stub, sizeof(index_hint_name_stub) - 1); |
4376 | + addIndexHint(&join_index_hint_stub); |
4377 | + table_share.keys_in_use.set(0); |
4378 | + table_share.keys_in_use.set(5); |
4379 | + table.covering_keys.set(0); |
4380 | + table.covering_keys.set(5); |
4381 | + |
4382 | + table_list_lvl0.process_index_hints(&table); |
4383 | + |
4384 | + EXPECT_FALSE(table.covering_keys[0]); |
4385 | + EXPECT_TRUE(table.covering_keys[5]); |
4386 | +} |
4387 | + |
4388 | +TEST_F(TableListTest, process_index_hints_ProperInput_shouldReturn_0) |
4389 | +{ |
4390 | + char index_hint_name_stub[]= "IndexHintNameStub"; |
4391 | + Index_hint use_index_hint_stub(INDEX_HINT_USE, INDEX_HINT_MASK_JOIN, index_hint_name_stub, sizeof(index_hint_name_stub) - 1); |
4392 | + addIndexHint(&use_index_hint_stub); |
4393 | + |
4394 | + retval= table_list_lvl0.process_index_hints(&table); |
4395 | + |
4396 | + ASSERT_EQ(0, retval); |
4397 | +} |
4398 | |
4399 | === added file 'unittests/table_proto_write_test.cc' |
4400 | === added file 'unittests/table_share_test.cc' |
4401 | --- unittests/table_share_test.cc 1970-01-01 00:00:00 +0000 |
4402 | +++ unittests/table_share_test.cc 2010-08-15 23:41:09 +0000 |
4403 | @@ -0,0 +1,872 @@ |
4404 | +/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- |
4405 | +* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: |
4406 | +* |
4407 | +* Copyright (C) 2010 Pawel Blokus |
4408 | +* |
4409 | +* This program is free software; you can redistribute it and/or modify |
4410 | +* it under the terms of the GNU General Public License as published by |
4411 | +* the Free Software Foundation; either version 2 of the License, or |
4412 | +* (at your option) any later version. |
4413 | +* |
4414 | +* This program is distributed in the hope that it will be useful, |
4415 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4416 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4417 | +* GNU General Public License for more details. |
4418 | +* |
4419 | +* You should have received a copy of the GNU General Public License |
4420 | +* along with this program; if not, write to the Free Software |
4421 | +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4422 | +*/ |
4423 | + |
4424 | +#include "config.h" |
4425 | + |
4426 | +#include <drizzled/definitions.h> |
4427 | +#include <drizzled/error.h> |
4428 | +#include <drizzled/field/enum.h> |
4429 | +#include <drizzled/field/null.h> |
4430 | +#include <drizzled/global_charset_info.h> |
4431 | +#include <drizzled/message/table.pb.h> |
4432 | +#include <drizzled/sql_base.h> |
4433 | +#include <drizzled/table.h> |
4434 | +#include <gtest/gtest.h> |
4435 | +#include <sstream> |
4436 | +#include <stdlib.h> |
4437 | +#include <string> |
4438 | + |
4439 | +#include "generator.h" |
4440 | +#include "plugin/plugin_stubs.h" |
4441 | +#include "stubs.h" |
4442 | + |
4443 | +using namespace drizzled; |
4444 | +using namespace std; |
4445 | + |
4446 | +class TableShareTest : public ::testing::Test |
4447 | +{ |
4448 | +protected: |
4449 | + TableShareStub table_share; |
4450 | + bool retval; |
4451 | + int retval_int; |
4452 | + TableShare *returned_share; |
4453 | + uint32_t position; |
4454 | + string str; |
4455 | + StorageEngineStub storage_engine; |
4456 | + TableIdentifier table_id; |
4457 | + Session *fake_session; |
4458 | + message::Table table_proto; |
4459 | + int error_num; |
4460 | +public: |
4461 | + |
4462 | + TableShareTest() |
4463 | + : storage_engine("StorageEngineStub"), |
4464 | + table_id("SchemaNameArg", "TableNameArg", "PathArg") |
4465 | + {} |
4466 | + |
4467 | + void prepareFilledIndexProto(bool with_key_parts= false, bool unique= true, int key_length= 6, |
4468 | + bool is_primary= false) |
4469 | + { |
4470 | + message::Table::Index *index= table_proto.add_indexes(); |
4471 | + message::Table::Index::IndexPart *index_part; |
4472 | + message::Table::Index::Options *index_options= index->mutable_options(); |
4473 | + |
4474 | + if (with_key_parts) |
4475 | + { |
4476 | + index_part= index->add_index_part(); |
4477 | + index_part->set_fieldnr(0); |
4478 | + index_part->set_compare_length(5); |
4479 | + index_part= index->add_index_part(); |
4480 | + index_part->set_fieldnr(1); |
4481 | + index_part->set_compare_length(5); |
4482 | + prepareTableVarcharFieldProto(); |
4483 | + prepareTableVarcharFieldProto(); |
4484 | + } |
4485 | + |
4486 | + index->set_name("KeyName"); |
4487 | + index->set_is_primary(is_primary); |
4488 | + index->set_is_unique(unique); |
4489 | + index->set_type(message::Table_Index_IndexType_BTREE); |
4490 | + index->set_key_length(key_length); |
4491 | + |
4492 | + index_options->set_pack_key(true); |
4493 | + index_options->set_var_length_key(true); |
4494 | + index_options->set_null_part_key(true); |
4495 | + index_options->set_binary_pack_key(true); |
4496 | + index_options->set_has_partial_segments(true); |
4497 | + index_options->set_auto_generated_key(true); |
4498 | + index_options->set_key_block_size(5); |
4499 | + } |
4500 | + |
4501 | + void prepareIndexComment() |
4502 | + { |
4503 | + table_proto.mutable_indexes(0)->set_comment("Comment"); |
4504 | + } |
4505 | + |
4506 | + void prepareTableOptionsProto() |
4507 | + { |
4508 | + message::Table::TableOptions *table_options= table_proto.mutable_options(); |
4509 | + table_options->set_collation_id(default_charset_info->number); |
4510 | + table_options->set_pack_record(true); |
4511 | + table_options->set_block_size(10); |
4512 | + } |
4513 | + |
4514 | + void prepareTableTimestampFieldProto(const char *default_expression= NULL, |
4515 | + const char *update_expression= NULL) |
4516 | + { |
4517 | + message::Table::Field *field= table_proto.add_field(); |
4518 | + |
4519 | + field->set_type(message::Table_Field_FieldType_TIMESTAMP); |
4520 | + field->set_name("TimestampField"); |
4521 | + if (default_expression != NULL) |
4522 | + field->mutable_options()->set_default_expression(default_expression); |
4523 | + if (update_expression != NULL) |
4524 | + field->mutable_options()->set_update_expression(update_expression); |
4525 | + } |
4526 | + |
4527 | + void prepareTableVarcharFieldProto() |
4528 | + { |
4529 | + message::Table::Field *field= table_proto.add_field(); |
4530 | + message::Table::Field::StringFieldOptions *field_options= field->mutable_string_options(); |
4531 | + |
4532 | + field->set_type(message::Table_Field_FieldType_VARCHAR); |
4533 | + field->set_name("VarcharField"); |
4534 | + field_options->set_length(20); |
4535 | + } |
4536 | + |
4537 | + void prepareTableDecimalFieldProto(bool autoincrement= false, int scale= 10, int precision= 10) |
4538 | + { |
4539 | + message::Table::Field *field= table_proto.add_field(); |
4540 | + message::Table::Field::NumericFieldOptions *field_options= field->mutable_numeric_options(); |
4541 | + |
4542 | + field->set_type(message::Table_Field_FieldType_DECIMAL); |
4543 | + field->set_name("DecimalField"); |
4544 | + field_options->set_is_autoincrement(autoincrement); |
4545 | + field_options->set_scale(scale); |
4546 | + field_options->set_precision(precision); |
4547 | + field->mutable_constraints()->set_is_nullable(false); |
4548 | + } |
4549 | + |
4550 | + void prepareTableIntegerFieldProto(bool autoincrement= false) |
4551 | + { |
4552 | + message::Table::Field *field= table_proto.add_field(); |
4553 | + message::Table::Field::NumericFieldOptions *field_options= field->mutable_numeric_options(); |
4554 | + |
4555 | + field->set_type(message::Table_Field_FieldType_INTEGER); |
4556 | + field->set_name("IntegerField"); |
4557 | + field_options->set_is_autoincrement(autoincrement); |
4558 | + field->mutable_constraints()->set_is_nullable(false); |
4559 | + } |
4560 | + |
4561 | + void prepareTableEnumFieldProto(bool with_comment= false, const char *default_value= NULL, |
4562 | + const string field_name= "", bool is_nullable= true) |
4563 | + { |
4564 | + message::Table::Field *field= table_proto.add_field(); |
4565 | + message::Table::Field::EnumerationValues *field_options= field->mutable_enumeration_values(); |
4566 | + |
4567 | + field->set_type(message::Table_Field_FieldType_ENUM); |
4568 | + field->set_name("EnumField"); |
4569 | + field_options->add_field_value("Value0"); |
4570 | + field_options->add_field_value("Value1"); |
4571 | + field_options->add_field_value("LongerValue2"); |
4572 | + field->mutable_constraints()->set_is_nullable(is_nullable); |
4573 | + if (field_name != "") |
4574 | + field->set_name(field_name); |
4575 | + if (with_comment) |
4576 | + field->set_comment("FieldComment"); |
4577 | + if (default_value != NULL) |
4578 | + field->mutable_options()->set_default_value(default_value); |
4579 | + } |
4580 | + |
4581 | + void prepareTableEnumFieldProto(int number) |
4582 | + { |
4583 | + std::stringstream sin; |
4584 | + for (int i= 0; i < number; ++i) |
4585 | + { |
4586 | + sin.str("FieldName"); |
4587 | + sin.seekp(9); |
4588 | + sin << i; |
4589 | + prepareTableEnumFieldProto(false, NULL, sin.str()); |
4590 | + } |
4591 | + } |
4592 | + |
4593 | + void prepareTableProto() |
4594 | + { |
4595 | + table_proto.mutable_engine()->set_name("StorageEngineStub"); |
4596 | + table_proto.set_name("TableName"); |
4597 | + table_proto.set_schema("TableSchema"); |
4598 | + table_proto.set_type(message::Table::STANDARD); |
4599 | + table_proto.set_creation_timestamp(100); |
4600 | + table_proto.set_update_timestamp(100); |
4601 | + |
4602 | + prepareTableOptionsProto(); |
4603 | + } |
4604 | + |
4605 | + virtual void SetUp() |
4606 | + { |
4607 | + TableShare::cacheStart(); |
4608 | + system_charset_info= default_charset_info; |
4609 | + error_handler_hook= error_handler_func_stub; |
4610 | + fake_session= Generator::SessionGenerator::make_fake_session(); |
4611 | + plugin::StorageEngine::addPlugin(&storage_engine); |
4612 | + prepareTableProto(); |
4613 | + } |
4614 | + |
4615 | + virtual void TearDown() |
4616 | + { |
4617 | + system_charset_info= NULL; |
4618 | + plugin::StorageEngine::removePlugin(&storage_engine); |
4619 | + } |
4620 | +}; |
4621 | + |
4622 | +TEST_F(TableShareTest, doesKeyNameExist_cstring_NonExistingKey_shouldReturn_False) |
4623 | +{ |
4624 | + retval= table_share.doesKeyNameExist("KeyName", 7, position); |
4625 | + |
4626 | + EXPECT_FALSE(retval); |
4627 | +} |
4628 | + |
4629 | +TEST_F(TableShareTest, doesKeyNameExist_cstring_ExistingKey_shouldReturn_True) |
4630 | +{ |
4631 | + table_share.addKeyName("KeyName"); |
4632 | + |
4633 | + retval= table_share.doesKeyNameExist("KeyName", 7, position); |
4634 | + |
4635 | + EXPECT_TRUE(retval); |
4636 | +} |
4637 | + |
4638 | +TEST_F(TableShareTest, doesKeyNameExist_cstring_ExistingKey_shouldReturn_ProperPosition) |
4639 | +{ |
4640 | + table_share.addKeyName("KeyName1"); |
4641 | + table_share.addKeyName("KeyName2"); |
4642 | + |
4643 | + table_share.doesKeyNameExist("KeyName2", 8, position); |
4644 | + |
4645 | + EXPECT_EQ(1, position); |
4646 | +} |
4647 | + |
4648 | +TEST_F(TableShareTest, doesKeyNameExist_string_NonExistingKey_shouldReturn_False) |
4649 | +{ |
4650 | + retval= table_share.doesKeyNameExist("KeyName", position); |
4651 | + |
4652 | + EXPECT_FALSE(retval); |
4653 | +} |
4654 | + |
4655 | +TEST_F(TableShareTest, doesKeyNameExist_string_ExistingKey_shouldReturn_True) |
4656 | +{ |
4657 | + table_share.addKeyName("KeyName"); |
4658 | + |
4659 | + retval= table_share.doesKeyNameExist("KeyName", position); |
4660 | + |
4661 | + EXPECT_TRUE(retval); |
4662 | +} |
4663 | + |
4664 | +TEST_F(TableShareTest, doesKeyNameExist_string_ExistingKey_shouldReturn_ProperPosition) |
4665 | +{ |
4666 | + table_share.addKeyName("KeyName1"); |
4667 | + table_share.addKeyName("KeyName2"); |
4668 | + |
4669 | + table_share.doesKeyNameExist("KeyName2", position); |
4670 | + |
4671 | + EXPECT_EQ(1, position); |
4672 | +} |
4673 | + |
4674 | + |
4675 | +TEST_F(TableShareTest, operator_outputStream) |
4676 | +{ |
4677 | + char key[]= "SchemaNameArg\0TableNameArg"; |
4678 | + char path[]= "PathArg"; |
4679 | + TableShare table_share_from_id(table_id, TableIdentifier::Key(key, key + sizeof(key)/sizeof(*key))); |
4680 | + table_share_from_id.setPath(path, sizeof(path)/sizeof(path[0])); |
4681 | + message::Table *proto= new message::Table(); |
4682 | + |
4683 | + ostringstream oss (ostringstream::out); |
4684 | + string expected("TableShare:(SchemaNameArg, TableNameArg, STANDARD, PathArg)"); |
4685 | + table_share_from_id.setTableProto(proto); |
4686 | + proto->set_type(message::Table::STANDARD); |
4687 | + |
4688 | + oss << table_share_from_id; |
4689 | + |
4690 | + EXPECT_EQ(expected, oss.str()); |
4691 | +} |
4692 | + |
4693 | +TEST_F(TableShareTest, open_table_def_storageEngineReturnsError_ShouldFailAnd_Return_1) |
4694 | +{ |
4695 | + storage_engine.setDoGetTableDefinitionReturn(ENOENT); |
4696 | + |
4697 | + retval_int= table_share.open_table_def(*fake_session, table_id); |
4698 | + |
4699 | + EXPECT_EQ(1, retval_int); |
4700 | +} |
4701 | + |
4702 | +TEST_F(TableShareTest, parse_table_proto_ValidInput_shouldReturn_0) |
4703 | +{ |
4704 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4705 | + |
4706 | + EXPECT_EQ(0, retval_int); |
4707 | +} |
4708 | + |
4709 | +TEST_F(TableShareTest, parse_table_proto_ShouldCopyRelevant_TableOptions) |
4710 | +{ |
4711 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4712 | + |
4713 | + ASSERT_EQ(0, retval_int); |
4714 | + EXPECT_EQ(default_charset_info, table_share.table_charset); |
4715 | + EXPECT_EQ(HA_OPTION_PACK_RECORD, table_share.db_create_options); |
4716 | + EXPECT_EQ(HA_OPTION_PACK_RECORD, table_share.db_options_in_use); |
4717 | + EXPECT_EQ(10, table_share.block_size); |
4718 | +} |
4719 | + |
4720 | +TEST_F(TableShareTest, parse_table_proto_table_charsetNotSet_ShouldReturn_ER_CORRUPT_TABLE_DEFINITION) |
4721 | +{ |
4722 | + table_proto.mutable_options()->set_collation_id(-1); |
4723 | + |
4724 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4725 | + |
4726 | + ASSERT_EQ(ER_CORRUPT_TABLE_DEFINITION, retval_int); |
4727 | +} |
4728 | + |
4729 | +TEST_F(TableShareTest, parse_table_proto_Index_ShouldCopy_Parameters) |
4730 | +{ |
4731 | + prepareFilledIndexProto(); |
4732 | + |
4733 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4734 | + |
4735 | + ASSERT_EQ(0, retval_int); |
4736 | + EXPECT_EQ(HA_KEY_ALG_BTREE, table_share.getKeyInfo(0).algorithm); |
4737 | + EXPECT_EQ(6, table_share.getKeyInfo(0).key_length); |
4738 | + EXPECT_STREQ("KeyName", table_share.getKeyInfo(0).name); |
4739 | +} |
4740 | + |
4741 | +TEST_F(TableShareTest, parse_table_proto_IndexesWithKeyParts) |
4742 | +{ |
4743 | + prepareFilledIndexProto(true); |
4744 | + prepareFilledIndexProto(true); |
4745 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4746 | + |
4747 | + ASSERT_EQ(0, retval_int); |
4748 | + EXPECT_EQ(2, table_share.keys); |
4749 | + EXPECT_EQ(2 * 2, table_share.key_parts); |
4750 | + EXPECT_EQ(2, table_share.getKeyInfo(0).key_parts); |
4751 | + EXPECT_EQ(2, table_share.getKeyInfo(1).key_parts); |
4752 | +} |
4753 | + |
4754 | +TEST_F(TableShareTest, parse_table_proto_IndexFlags) |
4755 | +{ |
4756 | + prepareFilledIndexProto(); |
4757 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4758 | + |
4759 | + ASSERT_EQ(0, retval_int); |
4760 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_NOSAME); |
4761 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_PACK_KEY); |
4762 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_VAR_LENGTH_PART); |
4763 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_NULL_PART_KEY); |
4764 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_BINARY_PACK_KEY); |
4765 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_KEY_HAS_PART_KEY_SEG); |
4766 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_GENERATED_KEY); |
4767 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_USES_BLOCK_SIZE); |
4768 | + EXPECT_EQ(5, table_share.getKeyInfo(0).block_size); |
4769 | +} |
4770 | + |
4771 | +TEST_F(TableShareTest, parse_table_proto_Index_KeyInfo_ValuesFromKeyParts) |
4772 | +{ |
4773 | + prepareFilledIndexProto(true); |
4774 | + table_proto.mutable_field(0)->mutable_constraints()->set_is_nullable(true); |
4775 | + |
4776 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4777 | + |
4778 | + ASSERT_EQ(0, retval_int); |
4779 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_NULL_PART_KEY); |
4780 | + EXPECT_EQ(2 * (HA_KEY_NULL_LENGTH + HA_KEY_BLOB_LENGTH), table_share.getKeyInfo(0).extra_length); |
4781 | + EXPECT_EQ(6 + 2 *(HA_KEY_NULL_LENGTH + HA_KEY_BLOB_LENGTH), table_share.getKeyInfo(0).key_length); |
4782 | + EXPECT_EQ(2, table_share.getKeyInfo(0).usable_key_parts); |
4783 | +} |
4784 | + |
4785 | +TEST_F(TableShareTest, parse_table_proto_Index_Field_ValuesFromKeyParts) |
4786 | +{ |
4787 | + prepareFilledIndexProto(true); |
4788 | + table_proto.mutable_field(0)->mutable_constraints()->set_is_nullable(true); |
4789 | + |
4790 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4791 | + |
4792 | + ASSERT_EQ(0, retval_int); |
4793 | + EXPECT_TRUE(table_share.getFields().at(0)->flags & MULTIPLE_KEY_FLAG); |
4794 | + EXPECT_TRUE(table_share.getFields().at(0)->key_start.test(0)); |
4795 | + EXPECT_TRUE(table_share.getFields().at(0)->flags & PART_KEY_FLAG); |
4796 | +} |
4797 | + |
4798 | +TEST_F(TableShareTest, parse_table_proto_Index_Field_ValuesFromKeyParts_PrimaryKey) |
4799 | +{ |
4800 | + prepareFilledIndexProto(); |
4801 | + table_proto.mutable_indexes(0)->add_index_part()->set_fieldnr(0); |
4802 | + table_proto.mutable_indexes(0)->mutable_index_part(0)->set_compare_length(4); |
4803 | + prepareTableIntegerFieldProto(true); |
4804 | + |
4805 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4806 | + |
4807 | + ASSERT_EQ(0, retval_int); |
4808 | + EXPECT_TRUE(table_share.getFields().at(0)->flags & PRI_KEY_FLAG); |
4809 | +} |
4810 | + |
4811 | +TEST_F(TableShareTest, parse_table_proto_NoIndexComment_ShouldSetStringTo_NULL) |
4812 | +{ |
4813 | + prepareFilledIndexProto(); |
4814 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4815 | + |
4816 | + ASSERT_EQ(0, retval_int); |
4817 | + ASSERT_EQ(0, table_share.getKeyInfo(0).comment.length); |
4818 | + ASSERT_EQ(NULL, table_share.getKeyInfo(0).comment.str); |
4819 | +} |
4820 | + |
4821 | +TEST_F(TableShareTest, parse_table_proto_IndexHasComment_ShouldSetString) |
4822 | +{ |
4823 | + prepareFilledIndexProto(); |
4824 | + prepareIndexComment(); |
4825 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4826 | + |
4827 | + ASSERT_EQ(0, retval_int); |
4828 | + EXPECT_TRUE(table_share.getKeyInfo(0).flags & HA_USES_COMMENT); |
4829 | + ASSERT_EQ(strlen("Comment"), table_share.getKeyInfo(0).comment.length); |
4830 | + ASSERT_STREQ("Comment", table_share.getKeyInfo(0).comment.str); |
4831 | +} |
4832 | + |
4833 | +TEST_F(TableShareTest, parse_table_proto_KeyName_ShouldBeAdded) |
4834 | +{ |
4835 | + prepareFilledIndexProto(); |
4836 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4837 | + |
4838 | + ASSERT_EQ(0, retval_int); |
4839 | + EXPECT_TRUE(table_share.doesKeyNameExist("KeyName", position)); |
4840 | +} |
4841 | + |
4842 | +TEST_F(TableShareTest, parse_table_proto_IndexKeyParts_ShouldCompute_offset) |
4843 | +{ |
4844 | + prepareFilledIndexProto(true); |
4845 | + table_proto.mutable_field(0)->mutable_constraints()->set_is_nullable(true); |
4846 | + |
4847 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4848 | + |
4849 | + ASSERT_EQ(0, retval_int); |
4850 | + EXPECT_EQ(1, table_share.getKeyInfo(0).key_part[0].offset); |
4851 | + EXPECT_EQ(20 * default_charset_info->mbmaxlen + 2, table_share.getKeyInfo(0).key_part[1].offset); |
4852 | +} |
4853 | + |
4854 | +TEST_F(TableShareTest, parse_table_proto_IndexKeyParts_ShouldCopyParametersTo_KeyPartInfo) |
4855 | +{ |
4856 | + prepareFilledIndexProto(true); |
4857 | + table_proto.mutable_field(0)->mutable_constraints()->set_is_nullable(true); |
4858 | + |
4859 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4860 | + |
4861 | + ASSERT_EQ(0, retval_int); |
4862 | + EXPECT_EQ(HA_KEYTYPE_VARTEXT1, table_share.getKeyInfo(0).key_part[0].type); |
4863 | + EXPECT_EQ(1, table_share.getKeyInfo(0).key_part[0].null_bit); |
4864 | + EXPECT_EQ(0, table_share.getKeyInfo(0).key_part[0].null_offset); |
4865 | + EXPECT_EQ(5 * default_charset_info->mbmaxlen + HA_KEY_NULL_LENGTH + HA_KEY_BLOB_LENGTH, |
4866 | + table_share.getKeyInfo(0).key_part[0].store_length); |
4867 | + EXPECT_TRUE(table_share.getKeyInfo(0).key_part[0].key_part_flag & HA_VAR_LENGTH_PART); |
4868 | + EXPECT_TRUE(table_share.getKeyInfo(0).key_part[0].key_part_flag & HA_PART_KEY_SEG); |
4869 | +} |
4870 | + |
4871 | +TEST_F(TableShareTest, parse_table_proto_multipleFields_ShouldSet_fields_toFieldNumber) |
4872 | +{ |
4873 | + prepareTableEnumFieldProto(3); |
4874 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4875 | + |
4876 | + ASSERT_EQ(0, retval_int); |
4877 | + EXPECT_EQ(3, table_share.fields); |
4878 | +} |
4879 | + |
4880 | +TEST_F(TableShareTest, parse_table_proto_multipleFields_ShouldSet_null_fields) |
4881 | +{ |
4882 | + prepareTableEnumFieldProto(3); |
4883 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4884 | + |
4885 | + ASSERT_EQ(0, retval_int); |
4886 | + EXPECT_EQ(3, table_share.null_fields); |
4887 | +} |
4888 | + |
4889 | +TEST_F(TableShareTest, parse_table_proto_singleField_ShouldSet_RecordLength_and_stored_rec_length) |
4890 | +{ |
4891 | + prepareTableEnumFieldProto(); |
4892 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4893 | + |
4894 | + ASSERT_EQ(0, retval_int); |
4895 | + EXPECT_EQ(2, table_share.getRecordLength()); |
4896 | + EXPECT_EQ(2, table_share.stored_rec_length); |
4897 | +} |
4898 | + |
4899 | +TEST_F(TableShareTest, parse_table_proto_multipleFields_ShouldSet_RecordLength_and_stored_rec_length) |
4900 | +{ |
4901 | + prepareTableEnumFieldProto(3); |
4902 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4903 | + |
4904 | + ASSERT_EQ(0, retval_int); |
4905 | + EXPECT_EQ(4, table_share.getRecordLength()); |
4906 | + EXPECT_EQ(4, table_share.stored_rec_length); |
4907 | +} |
4908 | + |
4909 | +TEST_F(TableShareTest, parse_table_proto_noFields_fields_ShouldHaveSize_1) |
4910 | +{ |
4911 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4912 | + |
4913 | + ASSERT_EQ(0, retval_int); |
4914 | + ASSERT_EQ(1, table_share.getFields().size()); |
4915 | + ASSERT_EQ(NULL, table_share.getFields().at(0)); |
4916 | +} |
4917 | + |
4918 | +TEST_F(TableShareTest, parse_table_proto_multipleFields_ShouldSet_fields) |
4919 | +{ |
4920 | + prepareTableEnumFieldProto(3); |
4921 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4922 | + |
4923 | + ASSERT_EQ(0, retval_int); |
4924 | + ASSERT_EQ(4, table_share.getFields().size()); |
4925 | + ASSERT_EQ(NULL, table_share.getFields().at(3)); |
4926 | +} |
4927 | + |
4928 | +TEST_F(TableShareTest, parse_table_proto_singleEnumField_ShouldSet_TYPELIB) |
4929 | +{ |
4930 | + prepareTableEnumFieldProto(); |
4931 | + TYPELIB *typelib; |
4932 | + |
4933 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4934 | + typelib= ((Field_enum*)table_share.getFields().at(0))->typelib; |
4935 | + |
4936 | + ASSERT_EQ(0, retval_int); |
4937 | + EXPECT_EQ(3, typelib->count); |
4938 | + EXPECT_STREQ("Value0", typelib->type_names[0]); |
4939 | + EXPECT_STREQ("Value1", typelib->type_names[1]); |
4940 | + EXPECT_STREQ("LongerValue2", typelib->type_names[2]); |
4941 | + EXPECT_EQ(strlen("Value0"), typelib->type_lengths[0]); |
4942 | + EXPECT_EQ(strlen("Value1"), typelib->type_lengths[1]); |
4943 | + EXPECT_EQ(strlen("LongerValue2"), typelib->type_lengths[2]); |
4944 | +} |
4945 | + |
4946 | +TEST_F(TableShareTest, parse_table_proto_FieldWithComment) |
4947 | +{ |
4948 | + prepareTableEnumFieldProto(true); |
4949 | + |
4950 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4951 | + |
4952 | + ASSERT_EQ(0, retval_int); |
4953 | + EXPECT_EQ(strlen("FieldComment"), table_share.getFields().at(0)->comment.length); |
4954 | + EXPECT_STREQ("FieldComment", table_share.getFields().at(0)->comment.str); |
4955 | +} |
4956 | + |
4957 | +TEST_F(TableShareTest, parse_table_proto_FieldWithDefaultValue) |
4958 | +{ |
4959 | + String string_buf; |
4960 | + Table table; |
4961 | + Field *field; |
4962 | + prepareTableEnumFieldProto(false, "Value1"); |
4963 | + |
4964 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4965 | + table.resetTable(fake_session, &table_share, 0); |
4966 | + field= table_share.getFields().at(0); |
4967 | + field->setTable(&table); |
4968 | + |
4969 | + ASSERT_EQ(0, retval_int); |
4970 | + EXPECT_STREQ("Value1", field->val_str(&string_buf)->c_str()); |
4971 | +} |
4972 | + |
4973 | +TEST_F(TableShareTest, parse_table_proto_FieldWith_Invalid_DefaultValue_shouldReturn_1) |
4974 | +{ |
4975 | + String string_buf; |
4976 | + prepareTableEnumFieldProto(false, "InvalidValue"); |
4977 | + |
4978 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4979 | + |
4980 | + ASSERT_EQ(1, retval_int); |
4981 | +} |
4982 | + |
4983 | +TEST_F(TableShareTest, parse_table_proto_singleEnumField_ShouldCompute_field_length_fromLongestValue) |
4984 | +{ |
4985 | + prepareTableEnumFieldProto(); |
4986 | + |
4987 | + retval_int= table_share.parse_table_proto(*fake_session, table_proto); |
4988 | + |
4989 | + ASSERT_EQ(0, retval_int); |
4990 | + EXPECT_EQ(strlen("LongerValue2") * default_charset_info->mbmaxlen, |
4991 | + table_share.getFields().at(0)->field_length); |
4992 | +} |
4993 | + |
4994 | +TEST_F(TableShareTest, parse_table_proto_singleField_noDefaultValue_ShouldSet_NO_DEFAULT_VALUE_FLAG) |
4995 | +{ |
4996 | + prepareTableEnumFieldProto(false, NULL, "", false); |
4997 | + table_share.resizeDefaultValues(1); |
4998 | + *(table_share.getDefaultValues())= 0; |
4999 | + table_proto.mutable_options()->set_pack_record(true); |
5000 | + |
The diff has been truncated for viewing.
In merging this, we hit some failing normal test cases.
http:// hudson. drizzle. org/job/ drizzle- build-ubuntu910 -64bit/ 554/
I've pushed up a branch with some other changes/fixes to the branch here:
lp:~mordred/drizzle/plugin-unittests-merge
If you could merge that in and then see why the test cases are breaking, that would be stellar.