Skip to content

Commit

Permalink
Merge pull request #67 from ajolma/issue63
Browse files Browse the repository at this point in the history
t/vsistdout.t: return 1 on write success
  • Loading branch information
shawnlaffan authored Nov 23, 2023
2 parents ba5426e + 037f80d commit c6be1b1
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions t/vsistdout.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ use JSON;
sub write {
my $line = shift;
push @output, $line;
return 1;
}
sub close {
push @output, "end";
return 1;
}
sub output {
my $output = join '', @output;
Expand All @@ -33,31 +34,34 @@ use JSON;
# test vsistdout redirection
if(1){
# create a small layer and copy it to vsistdout with redirection
my $layer = GetDriver('Memory')->Create->CreateLayer({GeometryType => 'None'});
my $ds = GetDriver('Memory')->Create;
my $layer = $ds->CreateLayer({GeometryType => 'None'});
$layer->CreateField(value => 'Integer');
$layer->CreateGeomField(geom => 'Point');
my $feature = Geo::GDAL::FFI::Feature->new($layer->GetDefn);
$feature->SetField(value => 12);
$feature->SetGeomField(geom => [WKT => 'POINT(1 1)']);
$layer->CreateFeature($feature);

for my $i (1..2) {
my $feature = Geo::GDAL::FFI::Feature->new($layer->GetDefn);
$feature->SetField(value => 12);
$feature->SetGeomField(geom => [WKT => "POINT(1 $i)"]);
$layer->CreateFeature($feature);
}
$ds->FlushCache;
my $output = Output->new;
my $gdal = Geo::GDAL::FFI->get_instance;
$gdal->SetWriter($output);
GetDriver('GeoJSON')->Create('/vsistdout')->CopyLayer($layer);
$gdal->CloseWriter;

my $ret = $output->output;
ok($ret eq
'{"type": "FeatureCollection",'.
'"features": '.
'[{ "type": "Feature", "id": 0, "properties": '.
'{ "value": 12 }, "geometry": { "type": "Point", '.
'"coordinates": [ 1.0, 1.0 ] } }]}end',
$ret = decode_json $ret;

my $exp = decode_json (get_expected_json_data());

is_deeply ($ret, $exp,
"Redirect vsistdout to write/close methods of a class.");

}


# test Translate
if(1){
my $ds = GetDriver('GTiff')->Create('/vsimem/test.tiff', 10);
Expand All @@ -66,3 +70,38 @@ if(1){
}

done_testing();


sub get_expected_json_data {
my $json = <<'EOJSON'
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"id": 0,
"properties": {
"value": 12
},
"geometry": {
"type": "Point",
"coordinates": [1.0, 1.0]
}
}, {
"type": "Feature",
"id": 1,
"properties": {
"value": 12
},
"geometry": {
"type": "Point",
"coordinates": [1.0, 2.0]
}
}
]
}
EOJSON
;
return $json;
}


0 comments on commit c6be1b1

Please sign in to comment.