netcdf-c/nc_test/tst_byterange.c
Dennis Heimbigner f587654670 Make the dap4 code resistant to various server errors.
Some versions of some servers are returning malformed responses.
Make the library either handle them or gracefully fail.
The three server errors "fixed" here are as follows.
1. The attribute _NCProperties sometimes has a trailing nul character
   in its value. Soln is to elide the nul(s).
2. Sometimes a DAP response has no data part, only a DMR.
   Soln is to detect and return an error code instead of crashing.
3. Sometimes a server returns a redirection, but our current
   openmagic() function was not following the redirect. Soln
   is to follow redirects.
Also because of #2, I am temporarily making --disable-dap-remote-tests
be the default.
2020-01-08 15:18:31 -07:00

91 lines
2.0 KiB
C

/*********************************************************************
* Copyright 1996-2018, UCAR/Unidata
* See COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include "unistd.h"
#endif
#ifdef _WIN32
#include <io.h>
#endif
#include "netcdf.h"
/*
https://github.com/Unidata/netcdf-c/issues/1251
*/
struct TESTURLS {
int format; /* instance of NC_FORMATX_XXX */
const char* url;
} testurls[] = {
{NC_FORMAT_CLASSIC,"http://remotetest.unidata.ucar.edu/thredds/fileServer/testdata/2004050300_eta_211.nc#bytes"},
#ifdef USE_NETCDF4
{NC_FORMAT_NETCDF4,"http://noaa-goes16.s3.amazonaws.com/ABI-L1b-RadC/2017/059/03/OR_ABI-L1b-RadC-M3C13_G16_s20170590337505_e20170590340289_c20170590340316.nc#mode=bytes"},
#endif
{0,NULL}
};
static int lineno = 0;
static int
fail(int ret)
{
if(ret != NC_NOERR) {
fprintf(stderr,"*** Fail: line: %d: (%d) %s\n", lineno, ret, nc_strerror(ret));
fflush(stderr);
}
return ret;
}
static int
dotest(struct TESTURLS* test)
{
int ret = NC_NOERR;
int ncid;
int format = -1;
fprintf(stderr,"Test: url=%s\n",test->url);
/* First, try to open the url */
if((ret = nc_open(test->url,0,&ncid))) return fail(ret);
/* Verify format */
if((ret = nc_inq_format(ncid,&format))) return fail(ret);
if(format != test->format) {
printf("%s: format mismatch: expected %d received %d\n",__FILE__,test->format,format);
return fail(NC_EINVAL);
}
if((ret = nc_close(ncid))) return fail(ret);
return ret;
}
int
main()
{
int ret = NC_NOERR;
struct TESTURLS* test = NULL;
for(test=testurls;test->format;test++) {
if((ret=dotest(test))) goto done;
}
done:
return ret;
}