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
|
/*********************************************************************
* Copyright 1993-2018, UCAR/Unidata
* See COPYRIGHT file for copying and redistribution conditions.
*
* Test driver for netCDF implementation. This program performs tests
* against the netCDF specification for all user-level functions in an
* implementation of the netCDF library. Must be invoked from a
* directory in which the invoker has write permission.
*
* Glenn Davis, Russ Rew, Ed Hartnett
*********************************************************************/
#include <config.h>
#include <stdlib.h>
#include <netcdf.h>
#include <stdio.h>
#include <string.h>
#include "testcdf.h" /* defines in-memory test netcdf structure */
#include "tests.h"
#define MAX_NUM_FORMATS 5
int current_format = 0;
/* Determine how many formats are available, and what they are. */
void
determine_test_formats(int *num_formats, int *format)
{
int ind = 0;
int num;
/* We always have classic and 64-bit offset */
num = 2;
format[ind++] = NC_FORMAT_CLASSIC;
format[ind++] = NC_FORMAT_64BIT_OFFSET;
/* Do we have netCDF-4 and netCDF-4 classic? */
#ifdef USE_HDF5
num += 2;
format[ind++] = NC_FORMAT_NETCDF4_CLASSIC;
format[ind++] = NC_FORMAT_NETCDF4;
#endif /* USE_HDF5 */
/* Do we have CDF5? */
#ifdef ENABLE_CDF5
num++;
format[ind++] = NC_FORMAT_CDF5;
#endif /* ENABLE_CDF5 */
*num_formats = num;
}
int
main(int argc, char **argv)
{
/*EXTERNL int ncopts; */ /* netCDF error options */
char *format_name[MAX_NUM_FORMATS] = {"classic", "64bit_offset", "netcdf4_classic",
"netcdf4", "CDF5"};
char testfile[NC_MAX_NAME];
int format[MAX_NUM_FORMATS];
int num_formats;
int i, nerrs = 0;
ncopts &= ~NC_FATAL; /* make errors nonfatal */
ncopts &= ~NC_VERBOSE; /* turn off error messages */
/* How many formats are we testing? */
determine_test_formats(&num_formats, format);
printf("Testing V2 API with %d different netCDF formats.\n", num_formats);
for (i = 0; i < num_formats; i++)
{
current_format = format[i];
/* Skip netCDF-4 - only netCDF-4 classic will work. */
if (format[i] == NC_FORMAT_NETCDF4)
continue;
/* Come up with a test file name. */
sprintf(testfile, "nctest_%s.nc", format_name[i]);
printf("Testing %s with file %s.\n", format_name[i], testfile);
/* Set the default format. */
nc_set_default_format(format[i], NULL);
/* Run all the tests for this format. */
nerrs += test_nccreate(testfile);
nerrs += test_ncopen(testfile);
nerrs += test_ncredef(testfile);
nerrs += test_ncendef(testfile);
nerrs += test_ncclose(testfile);
nerrs += test_ncinquire(testfile);
nerrs += test_ncsync(testfile);
nerrs += test_ncabort(testfile);
nerrs += test_ncdimdef(testfile);
nerrs += test_ncdimid(testfile);
nerrs += test_ncdiminq(testfile);
nerrs += test_ncdimrename(testfile);
nerrs += test_ncvardef(testfile);
nerrs += test_ncvarid(testfile);
nerrs += test_ncvarinq(testfile);
nerrs += test_ncvarputg(testfile);
nerrs += test_ncvarput1(testfile);
nerrs += test_ncvarget1(testfile);
nerrs += test_ncvarput(testfile);
nerrs += test_ncvarget(testfile);
nerrs += test_ncvarputg(testfile);
nerrs += test_ncvargetg(testfile);
nerrs += test_ncrecinq(testfile);
nerrs += test_ncrecput(testfile);
nerrs += test_ncrecget(testfile);
nerrs += test_ncvarrename(testfile);
nerrs += test_ncattput(testfile);
nerrs += test_ncattinq(testfile);
nerrs += test_ncattget(testfile);
nerrs += test_ncattcopy(testfile, "test2.nc");
nerrs += test_ncattname(testfile);
nerrs += test_ncattrename(testfile);
nerrs += test_ncattdel(testfile);
nerrs += test_nctypelen();
/* Clean up in-memory struct. */
{
int i;
for (i = 0; i < test.ndims; i++)
free(test.dims[i].name);
for (i = 0; i < test.nvars; i++)
{
free(test.vars[i].name);
free(test.vars[i].dims);
}
for (i = 0; i < test.natts; i++)
free(test.atts[i].name);
}
}
fprintf(stderr, "\nTotal number of failures: %d\n", nerrs);
if (nerrs)
{
fprintf(stderr, "nctest FAILURE!!!\n");
return 2;
}
else
fprintf(stderr, "nctest SUCCESS!!!\n");
return 0;
}
|