Skip to content

Commit

Permalink
Test null shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
voegelas committed May 15, 2023
1 parent 6d2d19c commit 3dd9a3b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(tests
byteorder
dbase2
dbf
null
point
pointm
pointz
Expand Down
24 changes: 24 additions & 0 deletions tests/create_data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,30 @@ sub strptime {
]
);

#
# null.shp
#

write_dbf(
file => catfile(qw(data null.dbf)),
header => {
fields => [
{ name => 'id',
type => 'N',
length => 10,
},
],
},
records => [[q{ }, 1], [q{ }, 2]]
);

write_shp_and_shx(
shp_file => catfile(qw(data null.shp)),
shx_file => catfile(qw(data null.shx)),
header => {type => $SHP_TYPE_NULL},
shapes => [{type => $SHP_TYPE_NULL}, {type => $SHP_TYPE_NULL}]
);

#
# point.shp
#
Expand Down
Binary file added tests/data/null.dbf
Binary file not shown.
Binary file added tests/data/null.shp
Binary file not shown.
Binary file added tests/data/null.shx
Binary file not shown.
77 changes: 77 additions & 0 deletions tests/test_null.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "../shapereader.h"
#include "tap.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>

int tests_planned = 0;
int tests_run = 0;
int tests_failed = 0;

const shp_header_t *shp_header;
const shp_record_t *shp_record;

static int
test_header_shape_type(void)
{
return shp_header->type == SHP_TYPE_NULL;
}

static int
test_record_shape_type(void)
{
return shp_record->type == SHP_TYPE_NULL;
}

static int
test_record_size(void)
{
return shp_record->record_size == 4;
}

static int
handle_shp_header(shp_file_t *fh, const shp_header_t *h)
{
shp_header = h;
ok(test_header_shape_type, "shape type is null");
return 1;
}

static int
handle_shp_record(shp_file_t *fh, const shp_header_t *h,
const shp_record_t *r, size_t offset)
{
shp_header = h;
shp_record = r;
ok(test_record_shape_type, "shape type is null");
ok(test_record_size, "record size is 4");
return 1;
}

int
main(int argc, char *argv[])
{
const char *shp_filename = "null.shp";
FILE *shp_stream;
shp_file_t shp_fh;

plan(5);

shp_stream = fopen(shp_filename, "rb");
if (shp_stream == NULL) {
fprintf(stderr, "# Cannot open file \"%s\": %s\n", shp_filename,
strerror(errno));
return 1;
}

shp_init_file(&shp_fh, shp_stream, NULL);

if (shp_read(&shp_fh, handle_shp_header, handle_shp_record) == -1) {
fprintf(stderr, "# Cannot read file \"%s\": %s\n", shp_filename,
shp_fh.error);
}

fclose(shp_stream);

done_testing();
}

0 comments on commit 3dd9a3b

Please sign in to comment.