Debian Codegraph @

perl/t/test1.t

raw symbols SCIP
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 { $| = 1; print "1..6\n"; }
27 END {print "not ok 1\n" unless $loaded;}
28 use RDF::Redland::CORE;
29 $loaded = 1;
30 print "ok 1\n";
31
32 ######################### End of black magic.
33
34 use strict;
35
36 my $test=2;
37
38 # Test using RDF::Redland::CORE module only
39
40 my $debug=defined $ENV{'TEST_VERBOSE'};
41
42 my $world=&RDF::Redland::CORE::librdf_new_world();
43 &RDF::Redland::CORE::librdf_world_open($world);
44 &RDF::Redland::CORE::librdf_perl_world_init($world);
45
46 my $storage=&RDF::Redland::CORE::librdf_new_storage($world, "hashes", "test", "new='yes',hash-type='memory',dir='.'");
47 if(!$storage) {
48 warn "Redland::librdf_new_storage failed\n";
49 print "not ok $test\n";
50 exit 1;
51 }
52 print "ok $test\n";
53 $test++;
54
55 my $model=&RDF::Redland::CORE::librdf_new_model($world, $storage, "");
56 if(!$model) {
57 warn "Redland::librdf_new_model failed\n";
58 print "not ok $test\n";
59 exit 1;
60 }
61 print "ok $test\n";
62 $test++;
63
64 my $statement=&RDF::Redland::CORE::librdf_new_statement_from_nodes($world,
65 &RDF::Redland::CORE::librdf_new_node_from_uri_string($world, "http://www.dajobe.org/"),
66 &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_literal($world, "Dave Beckett", "", 0)
68 );
69 if(!$statement) {
70 warn "Redland::librdf_new_statement_from_nodes failed\n";
71 print "not ok $test\n";
72 exit 1;
73 }
74 print "ok $test\n";
75 $test++;
76
77 &RDF::Redland::CORE::librdf_model_add_statement($model, $statement);
78 &RDF::Redland::CORE::librdf_free_statement($statement);
79 $statement=undef;
80
81
82 $statement=&RDF::Redland::CORE::librdf_new_statement($world);
83 my $stream=&RDF::Redland::CORE::librdf_model_find_statements($model,$statement);
84 &RDF::Redland::CORE::librdf_free_statement($statement);
85 $statement=undef;
86
87 my $failed=0;
88 while(!&RDF::Redland::CORE::librdf_stream_end($stream)) {
89 $statement=&RDF::Redland::CORE::librdf_stream_get_object($stream);
90 my $s=&RDF::Redland::CORE::librdf_statement_to_string($statement);
91 if(!length $s) {
92 warn "Redland::librdf_new_statement_to_string failed\n";
93 print "not ok $test\n";
94 $failed=1;
95 last;
96 }
97 warn "found statement: $s\n" if $debug;
98 &RDF::Redland::CORE::librdf_stream_next($stream);
99 }
100 &RDF::Redland::CORE::librdf_free_stream($stream);
101 $stream=undef;
102 last if $failed;
103
104 print "ok $test\n";
105 $test++;
106
107 my $source_node=&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_string($world, "http://purl.org/dc/elements/1.1/creator");
109
110 my $iterator=&RDF::Redland::CORE::librdf_model_get_targets($model,$source_node,$target_node);
111 $failed=0;
112 while(!&RDF::Redland::CORE::librdf_iterator_end($iterator)) {
113 my $node=&RDF::Redland::CORE::librdf_iterator_get_object($iterator);
114 my $n=&RDF::Redland::CORE::librdf_node_to_string($node);
115 if(!length $n) {
116 warn "Redland::librdf_node_to_string failed\n";
117 print "not ok $test\n";
118 $failed=1;
119 last;
120 }
121 warn "found node: $n\n" if $debug;
122 &RDF::Redland::CORE::librdf_iterator_next($iterator);
123 }
124 &RDF::Redland::CORE::librdf_free_iterator($iterator);
125 $iterator=undef;
126 &RDF::Redland::CORE::librdf_free_node($source_node);
127 $source_node=undef;
128 &RDF::Redland::CORE::librdf_free_node($target_node);
129 $target_node=undef;
130
131 unless($failed) {
132 print "ok $test\n";
133 }
134
135 $test++;
136
137 &RDF::Redland::CORE::librdf_free_model($model);
138 $model=undef;
139 &RDF::Redland::CORE::librdf_free_storage($storage);
140 $storage=undef;
141
142 &RDF::Redland::CORE::librdf_perl_world_finish();
143 $world=undef;
144
145 exit 0;