1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
|
/*
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 2013 Oracle and/or its affiliates. All rights reserved.
*
*/
/*
* This compilation unit contains functions related to the generation
* of a test for the generated storage layer.
*/
#include "generation.h"
extern int maxbinsz; /* defined in buildpt.c */
#define CASENUM 19
#define CTYPENUM 4
char * data_set[CASENUM][CTYPENUM] = {
{"\"0\"", "\"zero\"", "0", "0"},
{"\"1\"", "\"one\"", "1", "1.1"},
{"\"2\"", "\"two\"", "2", "2.2"},
{"\"3\"", "\"three\"", "3", "3.3"},
{"\"4\"", "\"four\"", "4", "4.4"},
{"\"5\"", "\"five\"", "5", "5.5"},
{"\"6\"", "\"six\"", "6", "6.6"},
{"\"7\"", "\"seven\"", "7", "7.7"},
{"\"8\"", "\"eight\"", "8", "8.8"},
{"\"9\"", "\"nine\"", "9", "9.9"},
{"\"A\"", "\"eleven\"", "11", "11.1"},
{"\"B\"", "\"twenty-two\"", "22", "22.2"},
{"\"C\"", "\"thirty-three\"", "33", "33.3"},
{"\"D\"", "\"forty-four\"", "44", "44.4"},
{"\"E\"", "\"fifty-five\"", "55", "55.5"},
{"\"F\"", "\"sixty-six\"", "66", "66.6"},
{"\"G\"", "\"seventy-seven\"", "77", "77.7"},
{"\"H\"", "\"eighty-eight\"", "88", "88.8"},
{"\"I\"", "\"ninety-nine\"", "99", "99.9"}};
static FILE *test_file; /* stream for generated test code */
static int round = 0;
static int test_indent_level = 0;
void generate_verification(FILE *, char *);
static void pr_test(char *, ...);
static void pr_test_comment(char *, ...);
static void callback_function_enter_entop(ENTITY *);
static void callback_function_exit_entop(ENTITY *);
static void callback_function_attrop(ENTITY *, ATTRIBUTE *, int, int);
static void declare_record_instances_enter_entop(ENTITY *);
static void define_records_enter_entop(ENTITY *);
static void define_records_exit_entop(ENTITY *);
static void define_records_fields_attrop(ENTITY *, ATTRIBUTE *, int, int);
static void initialize_database_enter_entop(ENTITY *);
static void initialize_index_enter_entop(DB_INDEX *);
static void insertion_test_enter_entop(ENTITY *);
static void insertion_test_exit_entop(ENTITY *);
static void insertion_test_attrop(ENTITY *, ATTRIBUTE *, int, int);
static void retrieval_test_enter_entop(ENTITY *);
static void retrieval_test_exit_entop(ENTITY *);
static void retrieval_test_attrop(ENTITY *, ATTRIBUTE *, int, int);
static void invoke_full_iteration_enter_entop(ENTITY *);
static void invoke_full_iteration_exit_entop(ENTITY *);
static void invoke_query_iteration_idxop(DB_INDEX *);
static void deletion_test_enter_entop(ENTITY *);
static void deletion_test_exit_entop(ENTITY *);
static void close_secondary_test_idxop(DB_INDEX *);
static void close_primary_test_enter_entop(ENTITY *);
static void remove_secondary_test_idxop(DB_INDEX *);
static void remove_primary_test_enter_entop(ENTITY *);
/*
* generate_verification is the test entry point in this module. It
* orchestrates the generation of the C code for tests.
*/
void
generate_verification(vfile, hfilename)
FILE *vfile;
char *hfilename;
{
test_file = vfile;
pr_test_comment(
"Simple test for a Berkeley DB implementation \n\
generated from SQL DDL by db_sql \n\
");
pr_test("#include <assert.h>\n");
pr_test("#include <math.h>\n\n");
pr_test("\n#include \"%s\"\n\n", hfilename);
if (maxbinsz != 0) {
pr_test_comment("Test data for raw binary types");
pr_test("#define MAXBINSZ %d\n\n", maxbinsz);
pr_test("char binary_data[%d][MAXBINSZ];\n", CASENUM);
}
pr_test("int count_iteration;\n\n");
pr_test_comment("Test data for input record");
iterate_over_entities(&define_records_enter_entop,
&define_records_exit_entop,
NULL);
if (maxbinsz != 0) {
pr_test_comment("A very simple binary comparison function");
pr_test(
"int compare_binary(char *p, int len, int dem) \n\
{ \n\
if (memcmp(p, binary_data[dem], len) == 0) { \n\
return 0; \n\
} else { \n\
return 1; \n\
} \n\
} \n\
\n\
");
}
pr_test_comment(
"These are the iteration callback functions. One is defined per \n\
database(table). They are used for both full iterations and for \n\
secondary index queries. When a retrieval returns multiple records, \n\
as in full iteration over an entire database, one of these functions \n\
is called for each record found");
iterate_over_entities(&callback_function_enter_entop,
&callback_function_exit_entop,
&callback_function_attrop);
pr_test(
" \n\
main(int argc, char **argv) \n\
{ \n\
int i; \n\
int j; \n\
int ret; \n\
int occurence; \n\
\n\
");
test_indent_level++;
iterate_over_entities(&declare_record_instances_enter_entop,
NULL,
NULL);
iterate_over_entities(&initialize_database_enter_entop,
NULL,
NULL);
iterate_over_indexes(&initialize_index_enter_entop);
pr_test("\n");
if (maxbinsz != 0) {
pr_test_comment("Fill the binary test data with random values");
pr_test(
"for (i = 0; i < %d; i++) \n\
for (j = 0; j < MAXBINSZ; j++) \n\
binary_data[i][j] = rand(); \n\
\n\
",
CASENUM);
}
pr_test_comment(
"Use the convenience method to initialize the environment. \n\
The initializations for each entity and environment can be \n\
done discretely if you prefer, but this is the easy way.");
pr_test(
"ret = initialize_%s_environment(); \n\
if (ret != 0) { \n\
printf(\"Initialize error\"); \n\
return ret; \n\
} \n\
\n\
",
the_schema.environment.name);
pr_test("\n");
pr_test_comment(
"Now that everything is initialized, insert some records \n\
into each database, retrieve and verify them");
pr_test("for (i = 0; i < %d; i++) {\n", CASENUM);
test_indent_level++;
pr_test_comment(
"First, insert some records into each database using \n\
the ...insert_fields functions. These functions take \n\
each field of the record as a separate argument");
iterate_over_entities(&insertion_test_enter_entop,
&insertion_test_exit_entop,
&insertion_test_attrop);
pr_test("\n");
pr_test_comment(
"Next, retrieve the records just inserted, looking them up \n\
by their key values");
iterate_over_entities(&retrieval_test_enter_entop,
&retrieval_test_exit_entop,
&retrieval_test_attrop);
test_indent_level--;
pr_test("}\n");
pr_test("\n");
pr_test_comment(
"Now try iterating over every record, using the ...full_iteration \n\
functions for each database. For each record found, the \n\
appropriate ...iteration_callback_test function will be invoked \n\
(these are defined above).");
iterate_over_entities(&invoke_full_iteration_enter_entop,
&invoke_full_iteration_exit_entop,
NULL);
pr_test("\n");
pr_test_comment(
"For the secondary indexes, query for the known keys. This also \n\
results in the ...iteration_callback_test function's being called \n\
for each record found.");
iterate_over_indexes(&invoke_query_iteration_idxop);
pr_test("\n");
pr_test_comment(
"Now delete a record from each database using its primary key.");
for (round = 0; round < CASENUM; round++) {
iterate_over_entities(&deletion_test_enter_entop,
&deletion_test_exit_entop,
NULL);
}
pr_test("\n");
test_indent_level--;
pr_test("exit_error:\n");
test_indent_level++;
pr_test_comment("Close the secondary index databases");
iterate_over_indexes(&close_secondary_test_idxop);
pr_test("\n");
pr_test_comment("Close the primary databases");
iterate_over_entities(&close_primary_test_enter_entop,
NULL,
NULL);
pr_test("\n");
pr_test_comment("Delete the secondary index databases");
iterate_over_indexes(&remove_secondary_test_idxop);
pr_test("\n");
pr_test_comment("Delete the primary databases");
iterate_over_entities(&remove_primary_test_enter_entop,
NULL,
NULL);
if (the_schema.environment.transactional) {
pr_test(
" \n\
if (ret != 0) \n\
%s_txnp->abort(%s_txnp); \n\
else \n\
%s_txnp->commit(%s_txnp, 0); \n\
",
the_schema.environment.name,
the_schema.environment.name,
the_schema.environment.name,
the_schema.environment.name);
}
pr_test("\n");
pr_test_comment("Finally, close the environment");
pr_test(
"if (ret = %s_envp->close(%s_envp, 0)) \n\
return ret;\n",
the_schema.environment.name, the_schema.environment.name);
pr_test("\n");
pr_test(
"if (ret == 0) \n\
printf(\"*****WELL DONE!*****\\n\"); \n\
");
pr_test("return ret;\n");
test_indent_level--;
pr_test("}\n");
}
/*
* Emit a printf-formatted string into the test code file.
*/
static void
pr_test(char *fmt, ...)
{
va_list ap;
char *s;
static int enable_indent = 1;
s = prepare_string(fmt,
enable_indent ? test_indent_level : 0,
0);
va_start(ap, fmt);
vfprintf(test_file, s, ap);
va_end(ap);
/*
* If the last char emitted was a newline, enable indentation
* for the next time.
*/
if (s[strlen(s) - 1] == '\n')
enable_indent = 1;
else
enable_indent = 0;
}
/*
* Emit a formatted comment into the test file.
*/
static void
pr_test_comment(char *fmt, ...)
{
va_list ap;
char *s;
s = prepare_string(fmt, test_indent_level, 1);
va_start(ap, fmt);
vfprintf(test_file, s, ap);
va_end(ap);
}
/*
* Return a data literal appropriate for the given type, to use as test value.
* No duplicate values will be got in this function.
*/
static char *
data_value_for_type(ATTR_TYPE *t)
{
char *c_type = t->c_type;
char *bin_array = NULL;
const char *bin_name = "binary_data[";
size_t bin_len = 0;
int count_bit;
int quote;
if (is_string(t)) {
/* If the field is really short, use a tiny string */
if (t->array_dim < 12)
return (data_set[round][0]);
return (data_set[round][1]);
} else if (is_array(t)) {
for (quote = round, count_bit = 1; quote > 0;
quote/=10, count_bit++);
bin_len = strlen(bin_name) + count_bit + 2;
bin_array = (char *)malloc(bin_len);
memset(bin_array, 0, bin_len);
snprintf(bin_array, bin_len, "%s%d%c", bin_name, round, ']');
return (bin_array);
} else if (strcmp(c_type, "char") == 0 ||
strcmp(c_type, "short") == 0 ||
strcmp(c_type, "int") == 0 ||
strcmp(c_type, "long") == 0) {
return (data_set[round][2]);
} else if (strcmp(c_type, "float") == 0 ||
strcmp(c_type, "double") == 0) {
return (data_set[round][3]);
} else {
fprintf(stderr,
"Unexpected C type in schema: %s", c_type);
assert(0);
}
return NULL; /*NOTREACHED*/
}
/*
* This entity operation function is called by the attribute iterator
* when producing test code that defines record instances.
*/
static void
define_records_enter_entop(ENTITY *e)
{
pr_test("%s_data %s_record_array[] = {\n",
e->name, e->name);
test_indent_level++;
for (round = 0; round < CASENUM; round++) {
pr_test("{");
iterate_over_attributes(e, &define_records_fields_attrop);
pr_test("}");
if (round < CASENUM -1)
pr_test(",");
pr_test("\n");
}
test_indent_level--;
}
static void
define_records_exit_entop(ENTITY *e)
{
COMPQUIET(e, NULL);
pr_test("};\n\n");
}
static void
define_records_fields_attrop(ENTITY *e, ATTRIBUTE *a, int first, int last)
{
int get_row_num;
COMPQUIET(first, 0);
if ((e->primary_key != a) && round > 9)
get_row_num = round - 10;
else
get_row_num = round;
if (is_array(a->type) && !is_string(a->type)) {
pr_test("{0}");
} else if (is_string(a->type)) {
if (a->type->array_dim < 12)
pr_test(data_set[get_row_num][0]);
else
pr_test(data_set[get_row_num][1]);
} else if (strcmp(a->type->c_type, "char") == 0 ||
strcmp(a->type->c_type, "short") == 0 ||
strcmp(a->type->c_type, "int") == 0 ||
strcmp(a->type->c_type, "long") == 0) {
pr_test(data_set[get_row_num][2]);
} else if (strcmp(a->type->c_type, "float") == 0 ||
strcmp(a->type->c_type, "double") == 0) {
pr_test(data_set[get_row_num][3]);
} else {
fprintf(stderr,
"Unexpected C type in schema: %s", a->type->c_type);
assert(0);
}
if (!last)
pr_test(", ");
}
/*
* This entity operation function is called by the attribute iterator
* when producing test code that declares record instances.
*/
static void
declare_record_instances_enter_entop(ENTITY *e)
{
pr_test("%s_data %s_record;\n", e->name, e->name);
}
/*
* This entity operation function is called by the attribute iterator
* when producing test code that initialized database handle.
*/
static void
initialize_database_enter_entop(ENTITY *e)
{
pr_test("%s_dbp = NULL;\n", e->name);
}
/*
* This entity operation function is called by the attribute iterator
* when producing test code that initialized index handle.
*/
static void
initialize_index_enter_entop(DB_INDEX *idx)
{
pr_test("%s_dbp = NULL;\n", idx->name);
}
static void
invoke_full_iteration_enter_entop(ENTITY *e)
{
pr_test("count_iteration = 0;\n");
pr_test(
"ret = %s_full_iteration(%s_dbp, %s%s&%s_iteration_callback_test, \n\
\"retrieval of %s record through full iteration\");\n",
e->name, e->name,
e->transactional ? the_schema.environment.name : "",
e->transactional ? "_txnp, " : "",
e->name, e->name);
}
static void
invoke_full_iteration_exit_entop(ENTITY *e)
{
pr_test(
"if (ret != 0) { \n\
printf(\"Full Iteration Error\\n\"); \n\
goto exit_error; \n\
} \n\
printf(\"%s full iteration: %%d\\n\", count_iteration); \n\
assert(count_iteration == %d); \n\
\n\
",
e->name, CASENUM);
}
/*
* This index operation function is called by the attribute iterator
* when producing test code that creates the secondary databases.
*/
static void
invoke_query_iteration_idxop(DB_INDEX *idx)
{
ATTRIBUTE *a = idx->attribute;
pr_test("for (i = 0; i < %d; i++) {\n", CASENUM);
test_indent_level++;
pr_test("count_iteration = 0;\n");
pr_test("%s_query_iteration(%s_dbp, %s%s",
idx->name, idx->name,
idx->primary->transactional ? the_schema.environment.name : "",
idx->primary->transactional ? "_txnp, " : "");
pr_test("%s_record_array[i].%s",
idx->primary->name, a->name);
pr_test(
",\n &%s_iteration_callback_test, \n\
\"retrieval of %s record through %s query\");\n\n",
idx->primary->name, idx->primary->name, idx->name);
pr_test(
"printf(\"%s_record_array[%%d].%s: %%d\\n\", i, count_iteration);\n",
idx->primary->name, a->name,
idx->primary->name, a->name);
if (is_array(a->type) && !is_string(a->type)) {
pr_test("assert(count_iteration == 1);\n");
} else {
pr_test("occurence = 0;\n");
pr_test("for (j = 0; j < %d; j++) {\n", CASENUM);
test_indent_level++;
if (is_string(a->type)) {
pr_test(
"if (strcmp(%s_record_array[j].%s, %s_record_array[i].%s) == 0) {\n",
idx->primary->name, a->name,
idx->primary->name, a->name);
} else if ((strcmp(a->type->c_type, "float") == 0) ||
(strcmp(a->type->c_type, "double") == 0)) {
pr_test(
"if (fabs(%s_record_array[j].%s - %s_record_array[i].%s) <= 0.00001) {\n",
idx->primary->name, a->name,
idx->primary->name, a->name);
} else {
pr_test(
"if (%s_record_array[j].%s == %s_record_array[i].%s) {\n",
idx->primary->name, a->name,
idx->primary->name, a->name);
}
test_indent_level++;
pr_test("occurence++;\n");
test_indent_level--;
pr_test("}\n");
test_indent_level--;
pr_test("}\n");
pr_test("assert(count_iteration == occurence);\n");
}
test_indent_level--;
pr_test("}\n\n");
}
/*
* This next group of entity and attribute operation functions are
* called by the attribute iterator when generating insertion test code.
*/
static void
insertion_test_enter_entop(ENTITY *e)
{
pr_test("ret = %s_insert_fields( %s_dbp, %s%s",
e->name, e->name,
e->transactional ? the_schema.environment.name : "",
e->transactional ? "_txnp, " : "");
}
static void
insertion_test_exit_entop(ENTITY *e)
{
pr_test(
"if (ret != 0) { \n\
printf(\"ERROR IN INSERT NO.%%d record in %s_dbp\\n\", i); \n\
goto exit_error; \n\
} \n\
\n\
",
e->name);
}
static void
insertion_test_attrop(ENTITY *e, ATTRIBUTE *a, int first, int last)
{
if (first)
test_indent_level++;
if (is_array(a->type) && !is_string(a->type))
pr_test("binary_data[i]");
else
pr_test("%s_record_array[i].%s", e->name, a->name);
if (!last)
pr_test(", \n");
else {
pr_test(");\n");
test_indent_level--;
}
}
/*
* This next group of index and attribute operation functions are
* called by the attribute iterator when generating the iteration
* callback function.
*/
static void
callback_function_enter_entop(ENTITY *e)
{
pr_test(
"void %s_iteration_callback_test(void *msg, %s_data *%s_record) \n\
{ \n\
",
e->name, e->name, e->name);
test_indent_level++;
pr_test(
"int i; \n\
int same = 0; \n\
\n\
for (i = 0; i < %d; i++) { \n\
",
CASENUM);
test_indent_level++;
}
static void
callback_function_exit_entop(ENTITY *e)
{
COMPQUIET(e, NULL);
pr_test(") {\n");
test_indent_level--;
pr_test(
"same = 1; \n\
break; \n\
");
test_indent_level--;
pr_test("}\n");
test_indent_level--;
pr_test("}\n\n");
pr_test(
"if (same == 0) \n\
assert(0); \n\
else \n\
count_iteration++; \n\
");
test_indent_level--;
pr_test("}\n\n");
}
static void
callback_function_attrop(ENTITY *e, ATTRIBUTE *a, int first, int last)
{
if (first)
pr_test("if (");
if (is_array(a->type) && !is_string(a->type)) {
pr_test("(compare_binary(%s_record->%s, %s, i) == 0) ",
e->name, a->name, array_dim_name(e, a), a->name);
} else if (is_string(a->type)) {
pr_test(
"(strcmp(%s_record->%s, %s_record_array[i].%s) == 0) ",
e->name, a->name, e->name, a->name);
} else if ((strcmp(a->type->c_type, "float") == 0) ||
(strcmp(a->type->c_type, "double") == 0)) {
pr_test(
"(fabs(%s_record->%s - %s_record_array[i].%s) <= 0.00001) ",
e->name, a->name, e->name, a->name);
} else {
pr_test("(%s_record->%s == %s_record_array[i].%s) ",
e->name, a->name, e->name, a->name);
}
if (!last)
pr_test("&&\n");
if (first)
test_indent_level += 2;
}
/*
* This next group of entity and attribute operation functions are
* called by the attribute iterator when generating retrieval test code
*/
static void
retrieval_test_enter_entop(ENTITY *e)
{
pr_test("ret = get_%s_data( %s_dbp, ", e->name, e->name);
if (e->transactional)
pr_test("%s_txnp, ", the_schema.environment.name);
if (is_array(e->primary_key->type) && !is_string(e->primary_key->type))
pr_test("binary_data[i], ");
else
pr_test("%s_record_array[i].%s, ",
e->name, e->primary_key->name);
pr_test("&%s_record);\n", e->name);
pr_test(
"if (ret != 0) { \n\
printf(\"ERROR IN RETRIEVE NO.%%d record in %s_dbp\\n\", i); \n\
goto exit_error; \n\
} \n\
\n\
",
e->name);
}
static void
retrieval_test_exit_entop(ENTITY *e)
{
COMPQUIET(e, NULL);
pr_test("\n");
}
static void
retrieval_test_attrop(ENTITY *e, ATTRIBUTE *a, int first, int last)
{
COMPQUIET(first, 0);
COMPQUIET(last, 0);
pr_test("assert(");
if (is_array(a->type) && !is_string(a->type)) {
pr_test("compare_binary(%s_record.%s, %s, i) == 0);\n",
e->name, a->name, array_dim_name(e, a));
} else if (is_string(a->type)) {
pr_test(
"strcmp(%s_record.%s, %s_record_array[i].%s) == 0);\n",
e->name, a->name, e->name, a->name);
} else if ((strcmp(a->type->c_type, "float") == 0) ||
(strcmp(a->type->c_type, "double") == 0)) {
pr_test(
"(fabs(%s_record.%s - %s_record_array[i].%s) <= 0.00001));\n",
e->name, a->name, e->name, a->name);
} else {
pr_test("%s_record.%s == %s_record_array[i].%s);\n",
e->name, a->name, e->name, a->name);
}
}
/*
* This entity operation function is
* called by the attribute iterator when generating deletion test code.
*/
static void
deletion_test_enter_entop(ENTITY *e)
{
pr_test("ret = delete_%s_key( %s_dbp, %s%s%s);\n",
e->name, e->name,
e->transactional ? the_schema.environment.name : "",
e->transactional ? "_txnp, " : "",
data_value_for_type(e->primary_key->type));
}
static void
deletion_test_exit_entop(ENTITY *e)
{
ATTRIBUTE *a = e->primary_key;
char *key;
char * return_value;
int i, column;
key = data_value_for_type(a->type);
return_value = "0";
i = 0;
column = 0;
if (is_string(a->type)) {
if (a->type->array_dim < 12)
column = 0;
else
column = 1;
} else if (is_array(a->type)) {
column = CTYPENUM;
} else if (strcmp(a->type->c_type, "char") == 0 ||
strcmp(a->type->c_type, "short") == 0 ||
strcmp(a->type->c_type, "int") == 0 ||
strcmp(a->type->c_type, "long") == 0) {
column = 2;
} else if (strcmp(a->type->c_type, "float") == 0 ||
strcmp(a->type->c_type, "double") == 0) {
column = 3;
} else {
fprintf(stderr,
"Unexpected C type in schema: %s", a->type->c_type);
assert(0);
}
if (column != CTYPENUM) {
while (i < round) {
if (strcmp(data_set[i][column], key) == 0) {
return_value = "DB_NOTFOUND";
break;
}
i++;
}
}
pr_test(
"if (ret == %s) \n\
ret = 0; \n\
else { \n\
printf(\"ERROR IN DELETE NO.%d record in %s_dbp\\n\"); \n\
goto exit_error; \n\
}\n\n",
return_value, round + 1, e->name);
}
/* This entity operation function generates primary database closures. */
static void
close_primary_test_enter_entop(ENTITY *e)
{
pr_test(
"if (%s_dbp != NULL) \n\
%s_dbp->close(%s_dbp, 0); \n\
\n\
",
e->name, e->name, e->name);
}
/* This entity operation function generates secondary database closures. */
static void
close_secondary_test_idxop(DB_INDEX *idx)
{
pr_test(
"if (%s_dbp != NULL) \n\
%s_dbp->close(%s_dbp, 0); \n\
\n\
",
idx->name, idx->name, idx->name);
}
/* This entity operation function generates primary database closures. */
static void
remove_primary_test_enter_entop(ENTITY *e)
{
pr_test("remove_%s_database(%s_envp%s%s%s);\n", e->name,
the_schema.environment.name,
e->transactional ? ", " : "",
e->transactional ? the_schema.environment.name : "",
e->transactional ? "_txnp" : "");
}
/* This entity operation function generates secondary database closures. */
static void
remove_secondary_test_idxop(DB_INDEX *idx)
{
pr_test("remove_%s_index(%s_envp%s%s%s);\n", idx->name,
the_schema.environment.name,
idx->primary->transactional ? ", " : "",
idx->primary->transactional ? the_schema.environment.name : "",
idx->primary->transactional ? "_txnp" : "");
}
|