use strict; use vars qw! $dbh !; $^W = 1; require 't/test.lib'; print "1..51\n"; use MyConText; print "ok 1\n"; print "For each test we will drop all _ctx_test% tables.\n"; sub drop_all_tables { for my $tableref (@{$dbh->selectall_arrayref('show tables')}) { next unless $tableref->[0] =~ /^_ctx_test/; print "Dropping $tableref->[0]\n"; $dbh->do("drop table $tableref->[0]"); } } sub test_one_type { my ($testnum, $description, $parameters_arrayref, $result_tables_hashref, $sql_command) = @_; drop_all_tables(); if (defined $sql_command) { if (ref $sql_command eq 'ARRAY') { for my $c (@$sql_command) { $dbh->do($c) or print $dbh->errstr, "\nnot "; print "ok $testnum\n"; $testnum++; } } else { $dbh->do($sql_command) or print $dbh->errstr, "\nnot "; print "ok $testnum\n"; $testnum++; } } print "Creating MyConText with $description\n"; my $ctx = MyConText->create($dbh, '_ctx_test', @$parameters_arrayref) or do { print "$MyConText::errstr\nnot ok $testnum\n"; for (keys %$result_tables_hashref) { $testnum++; print "ok $testnum #skip\n"; } return; }; print "ok $testnum\n"; for my $table (sort keys %$result_tables_hashref) { print "Testing if table $table was created ok\n"; $testnum++; my $info = $dbh->selectall_arrayref("show columns from $table"); if ($info and @$info) { local $^W = 0; my $textinfo = join "\n", (map { join ' ', @{$_}[0 .. 4] } @$info), ''; my $expected = $result_tables_hashref->{$table}; $expected =~ s/\|$//mg; if ($textinfo ne $expected) { print "Got:\n${textinfo}Expected:\n${expected}not "; } } else { print 'not '; } print "ok $testnum\n"; } print "Test if all created tables were tested.\n"; my $ok = 1; for my $tableref (@{$dbh->selectall_arrayref('show tables')}) { next unless $tableref->[0] =~ /^_ctx_test/; if (not defined $result_tables_hashref->{$tableref->[0]}) { print "Strange, a table $tableref->[0] was created that we know nothing about\n"; $ok = 0; } } print 'not ' unless $ok; $testnum++; print "ok $testnum\n"; $ctx->drop; } test_one_type(2, 'default parameters (packed document lists)', [], { '_ctx_test' => < < 'column' ], { '_ctx_test' => < < < 'column', 'doc_id_bits' => 32, 'word_id_bits' => 8, 'count_bits' => 24 ], { '_ctx_test' => < < < 'column', 'frontend' => 'string', 'count_bits' => 16, 'name_length' => 63 ], { '_ctx_test' => < < < < 'blob', 'frontend' => 'string', 'word_length' => 34 ], { '_ctx_test' => < < < 'blob', 'frontend' => 'string', 'word_length' => 20, 'name_length' => 16, 'count_bits' => 0, 'doc_id_bits' => 24 ], { '_ctx_test' => < < < 'column', 'frontend' => 'string', 'word_length' => 20, 'name_length' => 6, 'count_bits' => 0, 'doc_id_bits' => 24 ], { '_ctx_test' => < < < < 'column', 'frontend' => 'table', 'table_name' => '_ctx_test_the_table', 'column_name' => 'data' ], { '_ctx_test' => < < < < 'table', 'table_name' => '_ctx_test_the_table', 'column_name' => 'data', 'word_length' => '48' ], { '_ctx_test' => < < < <