| 1 | # -*- Mode: Perl -*- |
| 2 | # |
| 3 | # test1.t - Redland perl test 1 - RDF::Redland::CORE low level APIs |
| 4 | # |
| 5 | # Copyright (C) 2000-2003 David Beckett - http://www.dajobe.org/ |
| 6 | # Copyright (C) 2000-2003 University of Bristol - http://www.bristol.ac.uk/ |
| 7 | # |
| 8 | # This package is Free Software and part of Redland http://librdf.org/ |
| 9 | # |
| 10 | # It is licensed under the following three licenses as alternatives: |
| 11 | # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version |
| 12 | # 2. GNU General Public License (GPL) V2 or any newer version |
| 13 | # 3. Apache License, V2.0 or any newer version |
| 14 | # |
| 15 | # You may not use this file except in compliance with at least one of |
| 16 | # the above three licenses. |
| 17 | # |
| 18 | # See LICENSE.html or LICENSE.txt at the top of this package for the |
| 19 | # full license terms. |
| 20 | # |
| 21 | # |
| 22 | # |
| 23 | |
| 24 | ######################### We start with some black magic to print on failure. |
| 25 | |
| 26 | BEGIN { $|scip-perl cpan perl-project 0.0.0 main/`$|`. = 1; printscip-perl cpan perl-project 0.0.0 main/print(). "1..6\n"; } |
| 27 | END {printscip-perl cpan perl-project 0.0.0 main/print(). "not ok 1\n" unless $loadedscip-perl cpan perl-project 0.0.0 main/$loaded.;} |
| 28 | use RDF::Redland::COREscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/; |
| 29 | $loadedscip-perl cpan perl-project 0.0.0 main/$loaded. = 1; |
| 30 | printscip-perl cpan perl-project 0.0.0 main/print(). "ok 1\n"; |
| 31 | |
| 32 | ######################### End of black magic. |
| 33 | |
| 34 | use strictscip-perl cpan perl-project 0.0.0 strict/; |
| 35 | |
| 36 | my $test=2; |
| 37 | |
| 38 | # Test using RDF::Redland::CORE module only |
| 39 | |
| 40 | my $debug=definedscip-perl cpan perl-project 0.0.0 main/defined(). $ENVscip-perl cpan perl-project 0.0.0 main/`%ENV`.{'TEST_VERBOSE'}; |
| 41 | |
| 42 | my $world=&RDF::Redland::CORE::librdf_new_worldscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_world().(); |
| 43 | &RDF::Redland::CORE::librdf_world_openscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_world_open().($world); |
| 44 | &RDF::Redland::CORE::librdf_perl_world_initscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_perl_world_init().($world); |
| 45 | |
| 46 | my $storage=&RDF::Redland::CORE::librdf_new_storagescip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_storage().($world, "hashes", "test", "new='yes',hash-type='memory',dir='.'"); |
| 47 | if(!$storage) { |
| 48 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "Redland::librdf_new_storage failed\n"; |
| 49 | printscip-perl cpan perl-project 0.0.0 main/print(). "not ok $test\n"; |
| 50 | exitscip-perl cpan perl-project 0.0.0 main/exit(). 1; |
| 51 | } |
| 52 | printscip-perl cpan perl-project 0.0.0 main/print(). "ok $test\n"; |
| 53 | $test++; |
| 54 | |
| 55 | my $model=&RDF::Redland::CORE::librdf_new_modelscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_model().($world, $storage, ""); |
| 56 | if(!$model) { |
| 57 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "Redland::librdf_new_model failed\n"; |
| 58 | printscip-perl cpan perl-project 0.0.0 main/print(). "not ok $test\n"; |
| 59 | exitscip-perl cpan perl-project 0.0.0 main/exit(). 1; |
| 60 | } |
| 61 | printscip-perl cpan perl-project 0.0.0 main/print(). "ok $test\n"; |
| 62 | $test++; |
| 63 | |
| 64 | my $statement=&RDF::Redland::CORE::librdf_new_statement_from_nodesscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_statement_from_nodes().($world, |
| 65 | &RDF::Redland::CORE::librdf_new_node_from_uri_stringscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_node_from_uri_string().($world, "http://www.dajobe.org/"), |
| 66 | &RDF::Redland::CORE::librdf_new_node_from_uri_stringscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_node_from_uri_string().($world, "http://purl.org/dc/elements/1.1/creator"), |
| 67 | &RDF::Redland::CORE::librdf_new_node_from_literalscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_node_from_literal().($world, "Dave Beckett", "", 0) |
| 68 | ); |
| 69 | if(!$statement) { |
| 70 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "Redland::librdf_new_statement_from_nodes failed\n"; |
| 71 | printscip-perl cpan perl-project 0.0.0 main/print(). "not ok $test\n"; |
| 72 | exitscip-perl cpan perl-project 0.0.0 main/exit(). 1; |
| 73 | } |
| 74 | printscip-perl cpan perl-project 0.0.0 main/print(). "ok $test\n"; |
| 75 | $test++; |
| 76 | |
| 77 | &RDF::Redland::CORE::librdf_model_add_statementscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_model_add_statement().($model, $statement); |
| 78 | &RDF::Redland::CORE::librdf_free_statementscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_statement().($statement); |
| 79 | $statement=undef; |
| 80 | |
| 81 | |
| 82 | $statement=&RDF::Redland::CORE::librdf_new_statementscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_statement().($world); |
| 83 | my $stream=&RDF::Redland::CORE::librdf_model_find_statementsscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_model_find_statements().($model,$statement); |
| 84 | &RDF::Redland::CORE::librdf_free_statementscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_statement().($statement); |
| 85 | $statement=undef; |
| 86 | |
| 87 | my $failed=0; |
| 88 | while(!&RDF::Redland::CORE::librdf_stream_endscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_stream_end().($stream)) { |
| 89 | $statement=&RDF::Redland::CORE::librdf_stream_get_objectscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_stream_get_object().($stream); |
| 90 | my $s=&RDF::Redland::CORE::librdf_statement_to_stringscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_statement_to_string().($statement); |
| 91 | if(!lengthscip-perl cpan perl-project 0.0.0 main/length(). $s) { |
| 92 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "Redland::librdf_new_statement_to_string failed\n"; |
| 93 | printscip-perl cpan perl-project 0.0.0 main/print(). "not ok $test\n"; |
| 94 | $failed=1; |
| 95 | last; |
| 96 | } |
| 97 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "found statement: $s\n" if $debug; |
| 98 | &RDF::Redland::CORE::librdf_stream_nextscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_stream_next().($stream); |
| 99 | } |
| 100 | &RDF::Redland::CORE::librdf_free_streamscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_stream().($stream); |
| 101 | $stream=undef; |
| 102 | last if $failed; |
| 103 | |
| 104 | printscip-perl cpan perl-project 0.0.0 main/print(). "ok $test\n"; |
| 105 | $test++; |
| 106 | |
| 107 | my $source_node=&RDF::Redland::CORE::librdf_new_node_from_uri_stringscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_node_from_uri_string().($world, "http://www.dajobe.org/"); |
| 108 | my $target_node=&RDF::Redland::CORE::librdf_new_node_from_uri_stringscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_new_node_from_uri_string().($world, "http://purl.org/dc/elements/1.1/creator"); |
| 109 | |
| 110 | my $iterator=&RDF::Redland::CORE::librdf_model_get_targetsscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_model_get_targets().($model,$source_node,$target_node); |
| 111 | $failed=0; |
| 112 | while(!&RDF::Redland::CORE::librdf_iterator_endscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_iterator_end().($iterator)) { |
| 113 | my $node=&RDF::Redland::CORE::librdf_iterator_get_objectscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_iterator_get_object().($iterator); |
| 114 | my $n=&RDF::Redland::CORE::librdf_node_to_stringscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_node_to_string().($node); |
| 115 | if(!lengthscip-perl cpan perl-project 0.0.0 main/length(). $n) { |
| 116 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "Redland::librdf_node_to_string failed\n"; |
| 117 | printscip-perl cpan perl-project 0.0.0 main/print(). "not ok $test\n"; |
| 118 | $failed=1; |
| 119 | last; |
| 120 | } |
| 121 | warnscip-perl cpan perl-project 0.0.0 main/warn(). "found node: $n\n" if $debug; |
| 122 | &RDF::Redland::CORE::librdf_iterator_nextscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_iterator_next().($iterator); |
| 123 | } |
| 124 | &RDF::Redland::CORE::librdf_free_iteratorscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_iterator().($iterator); |
| 125 | $iterator=undef; |
| 126 | &RDF::Redland::CORE::librdf_free_nodescip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_node().($source_node); |
| 127 | $source_node=undef; |
| 128 | &RDF::Redland::CORE::librdf_free_nodescip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_node().($target_node); |
| 129 | $target_node=undef; |
| 130 | |
| 131 | unless($failed) { |
| 132 | printscip-perl cpan perl-project 0.0.0 main/print(). "ok $test\n"; |
| 133 | } |
| 134 | |
| 135 | $test++; |
| 136 | |
| 137 | &RDF::Redland::CORE::librdf_free_modelscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_model().($model); |
| 138 | $model=undef; |
| 139 | &RDF::Redland::CORE::librdf_free_storagescip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_free_storage().($storage); |
| 140 | $storage=undef; |
| 141 | |
| 142 | &RDF::Redland::CORE::librdf_perl_world_finishscip-perl cpan perl-project 0.0.0 RDF/Redland/CORE/librdf_perl_world_finish().(); |
| 143 | $world=undef; |
| 144 | |
| 145 | exitscip-perl cpan perl-project 0.0.0 main/exit(). 0; |