1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/* This is part of the netCDF package. Copyright 2018 University
Corporation for Atmospheric Research/Unidata See COPYRIGHT file for
conditions of use. See www.unidata.ucar.edu for more info.
Test nc_inq_type
Added in support of https://github.com/Unidata/netcdf/issues/240
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <netcdf.h>
#ifdef USE_PNETCDF
#include <netcdf_par.h>
#endif
#define FILE_NAME "tst_inq_type.nc"
int test_type_should_fail(int ncid, int type, char* tstring) {
printf("\t* Testing Type (Should Fail) %s:\t",tstring);
if(!nc_inq_type(ncid,type,NULL,NULL)) ERR;
else printf("expected failure.\n");
return 0;
}
int test_type(int ncid, int type, char* tstring) {
printf("\t* Testing Type %s:\t",tstring);
if(nc_inq_type(ncid,type,NULL,NULL)) ERR;
else printf("success.\n");
return 0;
}
int main(int argc, char **argv) {
int ncid=0;
printf("\n* Testing nc_inq_type with netcdf-3\n");
{
if(nc_create(FILE_NAME,NC_CLOBBER,&ncid)) ERR;
test_type(ncid, NC_BYTE,"NC_BYTE");
test_type(ncid, NC_CHAR,"NC_CHAR");
test_type(ncid, NC_SHORT,"NC_SHORT");
test_type(ncid, NC_INT,"NC_INT");
test_type(ncid, NC_LONG,"NC_LONG");
test_type(ncid, NC_FLOAT,"NC_FLOAT");
test_type(ncid, NC_DOUBLE,"NC_DOUBLE");
/* Not Valid for Classic */
/* Valid now, see https://github.com/Unidata/netcdf-c/issues/240 for more
information. The types are not valid for use in Classic,
but nc_inq_type should return valid info. */
test_type(ncid, NC_UBYTE,"NC_UBYTE");
test_type(ncid, NC_USHORT,"NC_USHORT");
test_type(ncid, NC_UINT,"NC_UINT");
test_type(ncid, NC_INT64,"NC_INT64");
test_type(ncid, NC_UINT64,"NC_UINT64");
test_type(ncid, NC_STRING,"NC_STRING");
/* Invoke a true negative */
test_type_should_fail(ncid, 9999, "NC_GARBAGE");
test_type_should_fail(ncid, -1, "NC_GARBAGE_NEGATIVE");
if(nc_close(ncid)) ERR;
/* Reopen file to check that we can. */
if (nc_create(FILE_NAME, 0, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_create(FILE_NAME, NC_WRITE, &ncid)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
#ifdef ENABLE_CDF5
printf("\n* Testing nc_inq_type with CDF5\n");
{
if(nc_create(FILE_NAME,NC_CLOBBER|NC_CDF5,&ncid)) ERR;
test_type(ncid, NC_BYTE,"NC_BYTE");
test_type(ncid, NC_CHAR,"NC_CHAR");
test_type(ncid, NC_SHORT,"NC_SHORT");
test_type(ncid, NC_INT,"NC_INT");
test_type(ncid, NC_LONG,"NC_LONG");
test_type(ncid, NC_FLOAT,"NC_FLOAT");
test_type(ncid, NC_DOUBLE,"NC_DOUBLE");
test_type(ncid, NC_UBYTE,"NC_UBYTE");
test_type(ncid, NC_USHORT,"NC_USHORT");
test_type(ncid, NC_UINT,"NC_UINT");
test_type(ncid, NC_INT64,"NC_INT64");
test_type(ncid, NC_UINT64,"NC_UINT64");
test_type(ncid, NC_STRING,"NC_STRING");
if(nc_close(ncid)) ERR;
/* Reopen file to check that we can. */
if (nc_open(FILE_NAME, NC_CDF5, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
#endif /* ENABLE_CDF5 */
#ifdef USE_HDF5
printf("\n* Testing nc_inq_type with netcdf-4 + Classic Model\n");
{
if(nc_create(FILE_NAME,NC_CLOBBER|NC_NETCDF4|NC_CLASSIC_MODEL,&ncid)) ERR;
test_type(ncid, NC_BYTE,"NC_BYTE");
test_type(ncid, NC_CHAR,"NC_CHAR");
test_type(ncid, NC_SHORT,"NC_SHORT");
test_type(ncid, NC_INT,"NC_INT");
test_type(ncid, NC_LONG,"NC_LONG");
test_type(ncid, NC_FLOAT,"NC_FLOAT");
test_type(ncid, NC_DOUBLE,"NC_DOUBLE");
test_type(ncid, NC_UBYTE,"NC_UBYTE");
test_type(ncid, NC_USHORT,"NC_USHORT");
test_type(ncid, NC_UINT,"NC_UINT");
test_type(ncid, NC_INT64,"NC_INT64");
test_type(ncid, NC_UINT64,"NC_UINT64");
test_type(ncid, NC_STRING,"NC_STRING");
if(nc_close(ncid)) ERR;
/* Re-open file to be sure we can. */
if (nc_open(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, NC_CLASSIC_MODEL, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("\n* Testing nc_inq_type with netcdf-4\n");
{
if(nc_create(FILE_NAME,NC_CLOBBER|NC_NETCDF4,&ncid)) ERR;
test_type(ncid, NC_BYTE,"NC_BYTE");
test_type(ncid, NC_CHAR,"NC_CHAR");
test_type(ncid, NC_SHORT,"NC_SHORT");
test_type(ncid, NC_INT,"NC_INT");
test_type(ncid, NC_LONG,"NC_LONG");
test_type(ncid, NC_FLOAT,"NC_FLOAT");
test_type(ncid, NC_DOUBLE,"NC_DOUBLE");
test_type(ncid, NC_UBYTE,"NC_UBYTE");
test_type(ncid, NC_USHORT,"NC_USHORT");
test_type(ncid, NC_UINT,"NC_UINT");
test_type(ncid, NC_INT64,"NC_INT64");
test_type(ncid, NC_UINT64,"NC_UINT64");
test_type(ncid, NC_STRING,"NC_STRING");
if(nc_close(ncid)) ERR;
/* Re-open file to be sure we can. */
if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, 0, &ncid)) ERR;
if (nc_close(ncid)) ERR;
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
#endif /*USE_HDF5*/
printf("* Finished.\n");
FINAL_RESULTS;
}
|