/usr/share/perl5/Test/RDF/Trine/Store.pm is in librdf-trine-perl 1.014-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | =head1 NAME
Test::RDF::Trine::Store - A collection of functions to test RDF::Trine::Stores
=head1 VERSION
This document describes RDF::Trine version 1.014
=head1 SYNOPSIS
For example, to test a Memory store, do something like:
use Test::RDF::Trine::Store qw(all_store_tests number_of_tests);
use Test::More tests => 1 + Test::RDF::Trine::Store::number_of_tests;
use RDF::Trine qw(iri variable store literal);
use RDF::Trine::Store;
my $data = Test::RDF::Trine::Store::create_data;
my $store = RDF::Trine::Store::Memory->temporary_store();
isa_ok( $store, 'RDF::Trine::Store::Memory' );
Test::RDF::Trine::Store::all_store_tests($store, $data);
=head1 DESCRIPTION
This module packages a few functions that you can call to test a
L<RDF::Trine::Store>, also if it is outside of the main RDF-Trine
distribution.
There are different functions that will test different parts of the
functionality, but you should run them all at some point, thus for the
most part, you would just like to run the C<all_store_tests> function
for quad stores and C<all_triple_store_tests> for triple stores
(i.e. stores that doesn't support named graphs).
All the below functions are exported.
=cut
package Test::RDF::Trine::Store;
use Test::More;
use Test::Exception;
use strict;
use warnings;
no warnings 'redefine';
use RDF::Trine qw(iri variable store literal statement);
use RDF::Trine::Node;
use RDF::Trine::Statement;
use RDF::Trine::Store::DBI;
use RDF::Trine::Namespace qw(xsd);
our ($VERSION);
BEGIN {
$VERSION = '1.014';
}
use Log::Log4perl;
Log::Log4perl->easy_init if $ENV{TEST_VERBOSE};
our @EXPORT = qw(number_of_tests number_of_triple_tests create_data all_store_tests all_triple_store_tests add_quads add_triples contexts_tests add_statement_tests_simple count_statements_tests_simple count_statements_tests_quads count_statements_tests_triples get_statements_tests_triples get_pattern_tests get_statements_tests_quads remove_statement_tests);
=head1 FUNCTIONS
=over 4
=item C<< number_of_tests >>
Returns the number of tests run with C<all_store_tests>.
=cut
sub number_of_tests {
return 231; # Remember to update whenever adding tests
}
=item C<< number_of_triple_tests >>
Returns the number of tests run with C<all_triple_store_tests>.
=cut
sub number_of_triple_tests {
return 71; # Remember to update whenever adding tests
}
=item C<< create_data >>
Returns a hashref with generated test data nodes to be used by other
tests.
=cut
sub create_data {
my $ex = RDF::Trine::Namespace->new('http://example.com/');
my @names = ('a' .. 'z');
my @triples;
my @quads;
my $nil = RDF::Trine::Node::Nil->new();
foreach my $i (@names[0..2]) {
my $w = $ex->$i();
foreach my $j (@names[0..2]) {
my $x = $ex->$j();
foreach my $k (@names[0..2]) {
my $y = $ex->$k();
my $triple = RDF::Trine::Statement->new($w,$x,$y);
push(@triples, $triple);
foreach my $l (@names[0..2]) {
my $z = $ex->$l();
my $quad = RDF::Trine::Statement::Quad->new($w,$x,$y,$z);
push(@quads, $quad);
}
}
}
}
return { ex => $ex, names => \@names, triples => \@triples, quads => \@quads, nil => $nil };
}
=item C<< all_store_tests ($store, $data, $todo, $args) >>
Will run all available tests for the given store, given the data from
C<create_data>. You may also set a third argument to some true value
to mark all tests as TODO in case the store is in development.
Finally, an C<$args> hashref can be passed. Valid keys are
C<update_sleep> (see the function with the same name below) and
C<suppress_dupe_tests> if the store should skip duplicate detection,
C<quads_unsupported> if the store is a triple store.
=cut
sub all_store_tests {
my ($store, $data, $todo, $args) = @_;
$args ||= {};
my $ex = $data->{ex};
my @names = @{$data->{names}};
my @triples = @{$data->{triples}};
my @quads = @{$data->{quads}};
my $nil = $data->{nil};
note "## Testing store " . ref($store);
isa_ok( $store, 'RDF::Trine::Store' );
TODO: {
local $TODO = ($todo) ? ref($store) . ' functionality is being worked on' : undef;
throws_ok {
my $st = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $ex->c, $ex->d);
$store->add_statement( $st, $ex->e );
} 'RDF::Trine::Error::MethodInvocationError', 'add_statement throws when called with quad and context';
throws_ok {
my $st = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $ex->c, $ex->d);
$store->remove_statement( $st, $ex->e );
} 'RDF::Trine::Error::MethodInvocationError', 'remove_statement throws when called with quad and context';
add_statement_tests_simple( $store, $args, $ex );
update_sleep($args);
bulk_add_statement_tests_simple( $store, $args, $ex );
update_sleep($args);
literals_tests_simple( $store, $args, $ex );
blank_node_tests_quads( $store, $args, $ex );
count_statements_tests_simple( $store, $args, $ex );
add_quads( $store, $args, @quads );
update_sleep($args);
count_statements_tests_quads( $store, $args, $ex );
add_triples( $store, $args, @triples );
update_sleep($args);
count_statements_tests_triples( $store, $args, $ex, $nil );
contexts_tests( $store, $args );
get_statements_tests_triples( $store, $args, $ex );
get_pattern_tests( $store, $args, $ex );
get_statements_tests_quads( $store, $args, $ex, $nil );
remove_statement_tests( $store, $args, $ex, @names );
update_sleep($args);
}
}
=item C<< all_triple_store_tests ($store, $data, $todo, $args) >>
Will run tests for the given B<triple> store, i.e. a store that only
accepts triples, given the data from C<create_data>. You may also set
a third argument to some true value to mark all tests as TODO in case
the store is in development.
For C<$args>, see above.
=cut
sub all_triple_store_tests {
my ($store, $data, $todo, $args) = @_;
$args ||= {};
$args->{quads_unsupported} = 1;
my $ex = $data->{ex};
my @names = @{$data->{names}};
my @triples = @{$data->{triples}};
my @quads = @{$data->{quads}};
my $nil = $data->{nil};
note "## Testing store " . ref($store);
isa_ok( $store, 'RDF::Trine::Store' );
TODO: {
local $TODO = ($todo) ? ref($store) . ' functionality is being worked on' : undef;
lives_ok {
$store->get_contexts;
} 'get_context lives';
# add_statement_tests_simple( $store, $args, $ex );
# update_sleep($args);
#
# bulk_add_statement_tests_simple( $store, $args, $ex );
# update_sleep($args);
literals_tests_simple( $store, $args, $ex );
blank_node_tests_triples( $store, $args, $ex );
# count_statements_tests_simple( $store, $args, $ex );
add_triples( $store, $args, @triples );
update_sleep($args);
# count_statements_tests_triples( $store, $args, $ex, $nil );
get_statements_tests_triples( $store, $args, $ex );
get_pattern_tests( $store, $args, $ex );
}
}
=item C<< add_quads($store, $args, @quads) >>
Helper function to add an array of quads to the given store.
=cut
sub add_quads {
my ($store, $args, @quads) = @_;
foreach my $q (@quads) {
$store->add_statement( $q );
}
}
=item C<< add_triples($store, $args, @triples) >>
Helper function to add an array of triples to the given store.
=cut
sub add_triples {
my ($store, $args, @triples) = @_;
foreach my $t (@triples) {
$store->add_statement( $t );
}
}
=item C<< contexts_tests( $store, $args ) >>
Testing contexts (aka. "graphs")
=cut
sub contexts_tests {
note "contexts tests";
my $store = shift;
my $args = shift;
my $iter = $store->get_contexts();
isa_ok( $iter, 'RDF::Trine::Iterator' );
my %seen;
while (my $c = $iter->next) {
isa_ok( $c, 'RDF::Trine::Node' );
$seen{ $c->as_string }++;
}
my $expect = {
'<http://example.com/a>' => 1,
'<http://example.com/b>' => 1,
'<http://example.com/c>' => 1,
};
is_deeply( \%seen, $expect, 'expected contexts' );
}
=item C<< add_statement_tests_simple( $store, $args, $data->{ex} ) >>
Tests to check add_statement.
=cut
sub add_statement_tests_simple {
note "simple add_statement tests";
my ($store, $args, $ex) = @_;
my $triple = RDF::Trine::Statement->new($ex->a, $ex->b, $ex->c);
my $quad = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $ex->c, $ex->d);
my $etag_before = $store->etag;
update_sleep($args);
$store->add_statement( $triple, $ex->d );
update_sleep($args);
SKIP: {
skip 'It is OK to not support etag', 1 unless defined($etag_before);
isnt($etag_before, $store->etag, 'Etag has changed');
}
is( $store->size, 1, 'store has 1 statement after (triple+context) add' );
TODO: {
local $TODO = 'Duplicate detection is unsupported' if $args->{suppress_dupe_tests};
$store->add_statement( $quad );
update_sleep($args);
is( $store->size, 1, 'store has 1 statement after duplicate (quad) add' );
}
$etag_before = $store->etag;
$store->remove_statement( $triple, $ex->d );
update_sleep($args);
SKIP: {
skip 'It is OK to not support etag', 1 unless defined($etag_before);
isnt($etag_before, $store->etag, 'Etag has changed');
}
is( $store->size, 0, 'store has 0 statements after (triple+context) remove' );
my $quad2 = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $ex->c, iri('graph'));
$store->add_statement( $quad2 );
update_sleep($args);
is( $store->size, 1, 'store has 1 statement after (quad) add' );
my $count = $store->count_statements( undef, undef, undef, iri('graph') );
is( $count, 1, 'expected count of specific-context statements' );
$store->remove_statement( $quad2 );
update_sleep($args);
is( $store->size, 0, 'expected zero size after remove statement' );
}
=item C<< bulk_add_statement_tests_simple( $store, $args, $data->{ex} ) >>
Tests to check add_statement.
=cut
sub bulk_add_statement_tests_simple {
note "bulk add_statement tests";
my ($store, $args, $ex) = @_;
$store->_begin_bulk_ops if ($store->can('_begin_bulk_ops'));
my $triple = RDF::Trine::Statement->new($ex->a, $ex->b, $ex->c);
my $quad = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $ex->c, $ex->d);
$store->add_statement( $triple, $ex->d );
$store->_end_bulk_ops if ($store->can('_end_bulk_ops'));
update_sleep($args);
is( $store->size, 1, 'store has 1 statement after (triple+context) add' ) ;
$store->_begin_bulk_ops if ($store->can('_begin_bulk_ops'));
TODO: {
local $TODO = 'Duplicate detection is unsupported' if $args->{suppress_dupe_tests};
$store->add_statement( $quad );
update_sleep($args);
is( $store->size, 1, 'store has 1 statement after duplicate (quad) add' ) ;
}
$store->_end_bulk_ops if ($store->can('_end_bulk_ops'));
$store->_begin_bulk_ops if ($store->can('_begin_bulk_ops'));
$store->remove_statement( $triple, $ex->d );
is( $store->size, 0, 'store has 0 statements after (triple+context) remove' );
my $quad2 = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $ex->c, iri('graph'));
$store->add_statement( $quad2 );
$store->_end_bulk_ops if ($store->can('_end_bulk_ops'));
update_sleep($args);
is( $store->size, 1, 'store has 1 statement after (quad) add' );
my $count = $store->count_statements( undef, undef, undef, iri('graph') );
is( $count, 1, 'expected count of specific-context statements' );
$store->remove_statement( $quad2 );
update_sleep($args);
is( $store->size, 0, 'expected zero size after remove statement' );
}
=item C<< literals_tests_simple( $store, $args, $data->{ex}) >>
Tests to check literals support.
=cut
sub literals_tests_simple {
note "simple tests with literals";
my ($store, $args, $ex) = @_;
my $litplain = RDF::Trine::Node::Literal->new('dahut');
my $litlang1 = RDF::Trine::Node::Literal->new('dahu', 'fr' );
my $litlang2 = RDF::Trine::Node::Literal->new('dahut', 'en' );
my $litutf8 = RDF::Trine::Node::Literal->new('blåbærsyltetøy', 'nb' );
my $litstring = RDF::Trine::Node::Literal->new('dahut', undef, $xsd->string);
my $litint = RDF::Trine::Node::Literal->new(42, undef, $xsd->integer);
my $triple = RDF::Trine::Statement->new($ex->a, $ex->b, $litplain);
my $quad = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $litplain, $ex->d);
$store->add_statement( $triple, $ex->d );
is( $store->size, 1, 'store has 1 statement after (triple+context) add' );
TODO: {
local $TODO = 'Duplicate detection is unsupported' if $args->{suppress_dupe_tests};
$store->add_statement( $quad );
is( $store->size, 1, 'store has 1 statement after duplicate (quad) add' );
}
$store->remove_statement( $triple, $ex->d );
is( $store->size, 0, 'store has 0 statements after (triple+context) remove' );
$store->add_statement( $quad );
my $quad2 = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $litlang2, $ex->d);
$store->add_statement( $quad2 );
is( $store->size, 2, 'store has 2 statements after (quad) add' );
{
my $count = $store->count_statements( undef, undef, $litplain, undef );
is( $count, 1, 'expected 1 plain literal' );
}
{
my $iter = $store->get_statements( undef, undef, $litplain, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $st = $iter->next;
isa_ok( $st, 'RDF::Trine::Statement' );
my $obj = $st->object;
isa_ok($obj, 'RDF::Trine::Node::Literal');
is($obj->literal_value, 'dahut', 'expected triple get_statements bound object value' );
}
{
my $count = $store->count_statements( undef, undef, $litlang2, undef );
is( $count, 1, 'expected 1 language literal' );
}
{
my $count = $store->count_statements( undef, undef, $litlang1, undef );
is( $count, 0, 'expected 0 language literal' );
}
my $quad3 = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $litlang1, $ex->d);
$store->add_statement( $quad3 );
is( $store->size, 3, 'store has 3 statements after integer literal add' );
{
my $iter = $store->get_statements( undef, undef, $litlang1, undef );
my $st = $iter->next;
is($st->object->literal_value, 'dahu', 'expected triple get_statements bound object value' );
is($st->object->literal_value_language, 'fr', 'expected triple get_statements bound object language' );
is($st->object->literal_datatype, undef, 'expected triple get_statements bound object datatype is undef' );
}
my $triple2 = RDF::Trine::Statement->new($ex->a, $ex->b, $litstring);
$store->add_statement( $triple2 );
is( $store->size, 4, 'store has 4 statements after (triple) add' );
{
my $count = $store->count_statements( undef, undef, $litplain, undef );
is( $count, 1, 'expected 1 plain literal' );
}
{
my $count = $store->count_statements( undef, undef, $litstring, undef );
is( $count, 1, 'expected 1 string literal' );
}
{
my $iter = $store->get_statements( undef, undef, $litstring, undef );
my $st = $iter->next;
is($st->object->literal_value, 'dahut', 'expected triple get_statements bound object value' );
is($st->object->literal_value_language, undef, 'expected triple get_statements bound object language is undef' );
is($st->object->literal_datatype, $xsd->string->value, 'expected triple get_statements bound object datatype is string' );
}
SKIP: {
skip 'Quad-only test', 1 if $args->{quads_unsupported};
my $count = $store->count_statements( undef, undef, $litstring, $ex->d );
is( $count, 0, 'expected 0 string literal with context' );
}
$store->remove_statement($quad);
is( $store->size, 3, 'store has 3 statements after plain literal remove' );
my $quad4 = RDF::Trine::Statement::Quad->new($ex->a, $ex->b, $litint, $ex->d);
$store->add_statement( $quad4 );
is( $store->size, 4, 'store has 4 statements after integer literal add' );
{
my $count = $store->count_statements( $ex->a, $ex->b, undef, undef);
is( $count, 4, 'expected 4 triples with all literals' );
}
{
my $count = $store->count_statements( $ex->a, $ex->b, $litint, undef );
is( $count, 1, 'expected 1 triple with integer literal' );
}
{
my $count = $store->count_statements( $ex->a, undef, $litlang1, undef );
is( $count, 1, 'expected 1 triple with language literal' );
}
$store->remove_statement($triple2);
is( $store->size, 3, 'store has 3 statements after string literal remove' );
$store->remove_statements(undef, undef, $litlang2, undef );
is( $store->size, 2, 'expected 2 statements after language remove statements' );
my $triple3 = RDF::Trine::Statement->new($ex->a, $ex->b, $litutf8);
$store->add_statement( $triple3 );
is( $store->size, 3, 'store has 3 statements after addition of literal with utf8 chars' );
{
my $iter = $store->get_statements( undef, undef, $litutf8, undef );
my $st = $iter->next;
isa_ok( $st, 'RDF::Trine::Statement' );
is($st->object->literal_value, 'blåbærsyltetøy', 'expected triple get_statements bound object value with utf8 chars' );
$store->remove_statement($st);
is( $store->size, 2, 'store has 2 statements after removal of literal with utf8 chars' );
}
$store->remove_statements($ex->a, $ex->b, undef, undef );
is( $store->size, 0, 'expected zero size after remove statements' );
}
=item C<< blank_node_tests_quads( $store, $args, $data->{ex} ) >>
Tests to check blank node support for quads.
=cut
sub blank_node_tests_quads {
note "quad tests with blank nodes";
my ($store, $args, $ex) = @_;
my $blankfoo = RDF::Trine::Node::Blank->new('foo');
my $blankbar = RDF::Trine::Node::Blank->new('bar');
my $triple = RDF::Trine::Statement->new($blankfoo, $ex->b, $ex->c);
my $quad = RDF::Trine::Statement::Quad->new($blankfoo, $ex->b, $ex->c, $ex->d);
$store->add_statement( $triple, $ex->d );
is( $store->size, 1, 'store has 1 statement after (triple+context) add' );
TODO: {
local $TODO = 'Duplicate detection is unsupported' if $args->{suppress_dupe_tests};
$store->add_statement( $quad );
is( $store->size, 1, 'store has 1 statement after duplicate (quad) add' );
}
$store->remove_statement( $triple, $ex->d );
is( $store->size, 0, 'store has 0 statements after (triple+context) remove' );
my $quad2 = RDF::Trine::Statement::Quad->new($blankbar, $ex->b, $ex->c, $ex->d);
$store->add_statement( $quad2 );
is( $store->size, 1, 'store has 1 statement after (quad) add' );
$store->add_statement( $quad );
is( $store->size, 2, 'store has 2 statements after (quad) add' );
my $triple2 = RDF::Trine::Statement->new($ex->a, $ex->b, $blankfoo);
$store->add_statement( $triple2 );
is( $store->size, 3, 'store has 3 statements after (quad) add' );
{
my $count = $store->count_statements( undef, undef, undef, $ex->d );
is( $count, 2, 'expected count of specific-context statements' );
}
{
my $count = $store->count_statements( undef, undef, $blankfoo, $ex->d );
is( $count, 0, 'expected zero of specific-context statements' );
}
{
my $count = $store->count_statements( undef, undef, $blankfoo, undef );
is( $count, 1, 'expected one object blank node' );
}
{
my $count = $store->count_statements( $blankbar, undef, $blankfoo, undef );
is( $count, 0, 'expected zero subject-object blank node' );
}
{
my $count = $store->count_statements( $blankbar, undef, undef, undef );
is( $count, 1, 'expected one subject blank node' );
}
{
my $count = $store->count_statements( $blankfoo, undef, undef, $ex->d );
is( $count, 1, 'expected one subject-context blank node' );
}
{
my $count = $store->count_statements( $blankfoo, $ex->b, undef, undef );
is( $count, 1, 'expected one subject-predicate blank node' );
}
$store->remove_statements( undef, undef, $blankfoo, undef );
is( $store->size, 2, 'expected two triples after remove statements' );
$store->remove_statement( $quad2 );
is( $store->size, 1, 'expected single triples after remove statement' );
$store->remove_statement( $quad );
is( $store->size, 0, 'expected zero size after remove statement' );
}
=item C<< blank_node_tests_triples( $store, $args, $data->{ex} ) >>
Tests to check blank node support for triples.
=cut
sub blank_node_tests_triples {
note "triple tests with blank nodes";
my ($store, $args, $ex) = @_;
my $blankfoo = RDF::Trine::Node::Blank->new('foo');
my $blankbar = RDF::Trine::Node::Blank->new('bar');
my $triple = RDF::Trine::Statement->new($blankfoo, $ex->b, $ex->c);
my $triple2 = RDF::Trine::Statement->new($ex->c, $ex->d, $blankbar);
$store->add_statement( $triple );
is( $store->size, 1, 'store has 1 statement after (triple) add' );
TODO: {
local $TODO = 'Duplicate detection is unsupported' if $args->{suppress_dupe_tests};
$store->add_statement( $triple );
is( $store->size, 1, 'store has 1 statement after duplicate (triple) add' );
}
$store->remove_statement( $triple );
is( $store->size, 0, 'store has 0 statements after (triple) remove' );
$store->add_statement( $triple2 );
is( $store->size, 1, 'store has 1 statement after (triple) add' );
$store->add_statement( $triple );
is( $store->size, 2, 'store has 2 statements after (triple) add' );
my $triple3 = RDF::Trine::Statement->new($ex->a, $ex->b, $blankfoo);
$store->add_statement( $triple3 );
is( $store->size, 3, 'store has 3 statements after (triple) add' );
{
my $count = $store->count_statements( undef, undef, $blankfoo, undef );
is( $count, 1, 'expected one object blank node' );
}
{
my $count = $store->count_statements( $blankbar, undef, $blankfoo, undef );
is( $count, 0, 'expected zero subject-object blank node' );
}
{
my $count = $store->count_statements( $blankfoo, undef, undef, $ex->d );
is( $count, 0, 'expected zero subject-context blank node' );
}
{
my $count = $store->count_statements( $blankfoo, $ex->b, undef, undef );
is( $count, 1, 'expected one subject-predicate blank node' );
}
$store->remove_statements( undef, undef, $blankfoo, undef );
is( $store->size, 2, 'expected two triples after remove statements' );
$store->remove_statement( $triple2 );
is( $store->size, 1, 'expected single triples after remove statement' );
$store->remove_statement( $triple );
is( $store->size, 0, 'expected zero size after remove statement' );
}
=item C<< count_statements_tests_simple( $store, $args, $data->{ex} ) >>
Tests to check that counts are correct.
=cut
sub count_statements_tests_simple {
note " simple count_statements tests";
my ($store, $args, $ex) = @_;
{
is( $store->size, 0, 'expected zero size before add statement' );
my $st = RDF::Trine::Statement::Quad->new( $ex->a, $ex->b, $ex->c, $ex->d );
$store->add_statement( $st );
is( $store->size, 1, 'size' );
is( $store->count_statements(), 1, 'count_statements()' );
is( $store->count_statements(undef, undef, undef), 1, 'count_statements(fff) with undefs' );
is( $store->count_statements(undef, undef, undef, undef), 1, 'count_statements(ffff) with undefs' );
SKIP: {
skip 'Quad-only test', 2 if $args->{quads_unsupported};
is( $store->count_statements(map {variable($_)} qw(s p o)), 1, 'count_statements(fff) with variables' );
is( $store->count_statements(map {variable($_)} qw(s p o g)), 1, 'count_statements(ffff) with variables' );
}
# 1-bound
is( $store->count_statements($ex->a, undef, undef, undef), 1, 'count_statements(bfff)' );
is( $store->count_statements(undef, $ex->b, undef, undef), 1, 'count_statements(fbff)' );
is( $store->count_statements(undef, undef, $ex->c, undef), 1, 'count_statements(ffbf)' );
is( $store->count_statements(undef, undef, undef, $ex->d), 1, 'count_statements(fffb)' );
# 2-bound
# local($::debug) = 1;
is( $store->count_statements($ex->a, $ex->b, undef, undef), 1, 'count_statements(bbff)' );
is( $store->count_statements(undef, $ex->b, $ex->c, undef), 1, 'count_statements(fbbf)' );
is( $store->count_statements(undef, undef, $ex->c, $ex->d), 1, 'count_statements(ffbb)' );
is( $store->count_statements($ex->a, undef, undef, $ex->d), 1, 'count_statements(bffb)' );
$store->remove_statement( $st );
is( $store->size, 0, 'size' );
}
is( $store->count_statements( $ex->z, undef, undef, undef ), 0, 'count_statements(bfff) empty result set' );
is( $store->count_statements( $ex->z, undef, undef, $ex->x ), 0, 'count_statements(bffb) empty result set' );
}
=item C<< count_statements_tests_quads( $store, $args, $data->{ex} ) >>
Count statement tests for quads.
=cut
sub count_statements_tests_quads {
note " quad count_statements tests";
my ($store, $args, $ex) = @_;
{
is( $store->count_statements, 27, 'count_statements()' );
is( $store->count_statements(undef, undef, undef), 27, 'count_statements( fff )' );
is( $store->count_statements(undef, undef, undef, undef), 81, 'count_statements( ffff )' );
is( $store->count_statements( $ex->a, undef, undef ), 9, 'count_statements( bff )' );
is( $store->count_statements( $ex->a, undef, undef, undef ), 27, 'count_statements( bfff )' );
is( $store->count_statements( $ex->a, undef, undef, $ex->a ), 9, 'count_statements( bffb )' );
}
}
=item C<< count_statements_tests_triples( $store, $args, $data->{ex}, $data->{nil} ) >>
More tests for counts, with triples.
=cut
sub count_statements_tests_triples {
note " triple count_statements tests";
my ($store, $args, $ex, $nil) = @_;
{
is( $store->count_statements, 27, 'count_statements() after triples added' );
is( $store->count_statements(undef, undef, undef), 27, 'count_statements( fff ) after triples added' );
is( $store->count_statements( $ex->a, undef, undef ), 9, 'count_statements( bff )' );
is( $store->count_statements( $ex->a, undef, undef, $nil ), 9, 'count_statements( bffb )' );
SKIP: {
skip 'Quad-only test', 2 if $args->{quads_unsupported};
is( $store->count_statements(undef, undef, undef, undef), 108, 'count_statements( ffff ) after triples added' );
is( $store->count_statements( $ex->a, undef, undef, undef ), 27+9, 'count_statements( bfff )' );
}
}
}
=item C<< get_statements_tests_triples( $store, $args, $data->{ex} ) >>
Tests for getting statements using triples.
=cut
sub get_statements_tests_triples {
note " triple get_statements tests";
my ($store, $args, $ex) = @_;
{
my $iter = $store->get_statements( undef, undef, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 27, 'get_statements( fff ) expected result count' );
is( $iter->next, undef, 'triple iterator end-of-stream' );
}
{
my $iter = $store->get_statements( $ex->a, variable('p'), variable('o') );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
ok( $st->subject->equal( $ex->a ), 'expected triple get_statements bound subject' );
$count++;
}
is( $count, 9, 'get_statements( bff ) expected result count' );
}
{
my $iter = $store->get_statements( $ex->d, undef, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 0, 'get_statements( bff ) expected empty results' );
}
}
=item C<< get_statements_tests_quads( $store, $args, $data->{ex}, $data->{nil} ) >>
Tests for getting statements using quads.
=cut
sub get_statements_tests_quads {
note " quad get_statements tests";
my ($store, $args, $ex, $nil) = @_;
{
my $iter = $store->get_statements( undef, undef, undef, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 108, 'get_statements( ffff ) expected result count' );
is( $iter->next, undef, 'quad iterator end-of-stream' );
}
{
my $iter = $store->get_statements( $ex->a, , variable('p'), variable('o'), variable('g') );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
ok( $st->subject->equal( $ex->a ), 'expected triple get_statements bound subject' );
$count++;
}
is( $count, 27+9, 'get_statements( bfff ) expected result count' );
}
{
my $iter = $store->get_statements( $ex->d, undef, undef, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 0, 'get_statements( bfff ) expected empty results' );
}
{
my $iter = $store->get_statements( undef, undef, undef, $nil );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 27, 'get_statements( fffb ) expected result count 1' );
}
{
my $iter = $store->get_statements( undef, undef, undef, $ex->a );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
ok( $st->context->equal( $ex->a ), 'expected triple get_statements bound context' );
$count++;
}
is( $count, 27, 'get_statements( fffb ) expected result count 2' );
}
{
my $iter = $store->get_statements( $ex->a, $ex->b, undef, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
ok( $st->subject->equal( $ex->a ), 'expected triple get_statements bound subject' );
ok( $st->predicate->equal( $ex->b ), 'expected triple get_statements bound predicate' );
$count++;
}
is( $count, 9+3, 'get_statements( bbff ) expected result count' );
}
{
my $iter = $store->get_statements( $ex->a, $ex->z, undef, undef );
isa_ok( $iter, 'RDF::Trine::Iterator' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 0, 'get_statements( bbff ) expected empty result' );
}
}
=item C<< get_pattern_tests( $store, $args, $data->{ex} ) >>
Tests for getting statements using with get_pattern.
=cut
sub get_pattern_tests {
note " get_pattern tests";
my ($store, $args, $ex) = @_;
my $model = RDF::Trine::Model->new($store);
my $nil = RDF::Trine::Node::Nil->new();
{
my $iter = $model->get_pattern( RDF::Trine::Pattern->new(
statement(
$ex->a, $ex->b, variable('o1'), $nil,
),
statement(
$ex->a, $ex->c, variable('o2'), $nil,
),
)
);
isa_ok( $iter, 'RDF::Trine::Iterator::Bindings' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
my $expected = 9;
is( $count, $expected, 'get_pattern( bbf, bbf ) expected result count' );
is( $iter->next, undef, 'pattern iterator end-of-stream' );
}
{
my $iter = $model->get_pattern( RDF::Trine::Pattern->new(
statement(
$ex->a, $ex->b, variable('o1'), $nil,
),
statement(
$ex->a, $ex->c, literal('DAAAAHUUUT'), $nil,
),
)
);
isa_ok( $iter, 'RDF::Trine::Iterator::Bindings' );
my $count = 0;
while (my $st = $iter->next()) {
$count++;
}
is( $count, 0, 'get_pattern( bbf, bbu ) expected result count' );
is( $iter->next, undef, 'pattern iterator end-of-stream' );
}
}
=item C<< remove_statement_tests( $store, $args, $data->{ex}, @{$data->{names}} ); >>
Tests for removing statements.
=cut
sub remove_statement_tests {
note " remove_statement tests";
my ($store, $args, $ex, @names) = @_;
is( $store->count_statements( undef, undef, undef, undef ), 108, 'store size before quad removal' );
foreach my $i (@names[0..2]) {
my $w = $ex->$i();
foreach my $j (@names[0..2]) {
my $x = $ex->$j();
foreach my $k (@names[0..2]) {
my $y = $ex->$k();
foreach my $l (@names[0..2]) {
my $z = $ex->$l();
my $quad = RDF::Trine::Statement::Quad->new($w,$x,$y,$z);
$store->remove_statement( $quad );
}
}
}
}
update_sleep($args);
is( $store->count_statements( undef, undef, undef, undef ), 27, 'quad count after quad removal' );
is( $store->count_statements( undef, undef, undef ), 27, 'triple count after quad removal' );
$store->remove_statements( $ex->a, undef, undef, undef );
update_sleep($args);
is( $store->count_statements( undef, undef, undef ), 18, 'triple count after remove_statements( bfff )' );
foreach my $i (@names[0..2]) {
my $w = $ex->$i();
foreach my $j (@names[0..2]) {
my $x = $ex->$j();
foreach my $k (@names[0..2]) {
my $y = $ex->$k();
my $triple = RDF::Trine::Statement->new($w,$x,$y);
$store->remove_statement( $triple );
}
}
}
update_sleep($args);
is( $store->count_statements( undef, undef, undef, undef ), 0, 'quad count after triple removal' );
}
=item C<< update_sleep ( \%args ) >>
If C<< $args{ update_sleep } >> is defined, sleeps for that many seconds.
This function is called after update operations to aid in testing stores that
perform updates asynchronously.
=cut
sub update_sleep {
my $args = shift;
if (defined($args->{ update_sleep })) {
note ' sleeping ' . $args->{ update_sleep }. ' secs after store update';
sleep($args->{ update_sleep });
}
}
1;
__END__
=back
=head1 BUGS
Please report any bugs or feature requests to through the GitHub web interface
at L<https://github.com/kasei/perlrdf/issues>.
=head1 AUTHOR
Gregory Todd Williams <gwilliams@cpan.org> and Kjetil Kjernsmo <kjetilk@cpan.org>
=cut
|