mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
more unit tests, this time for nc4internal.c
This commit is contained in:
parent
fb371d3c3e
commit
e4ef7b1a65
@ -341,6 +341,7 @@ int nc4_file_list_add(int ncid, const char *path, int mode,
|
||||
int nc4_file_list_get(int ncid, char **path, int *mode,
|
||||
void **dispatchdata);
|
||||
int nc4_file_list_del(int ncid);
|
||||
int nc4_file_change_ncid(int ncid, int new_ncid);
|
||||
int nc4_var_list_add(NC_GRP_INFO_T* grp, const char* name, int ndims,
|
||||
NC_VAR_INFO_T **var);
|
||||
int nc4_var_list_add2(NC_GRP_INFO_T* grp, const char* name,
|
||||
|
@ -68,10 +68,11 @@ free_NC(NC *ncp)
|
||||
/**
|
||||
* Create and initialize a new NC struct. The ncid is assigned later.
|
||||
*
|
||||
* @param dispatcher
|
||||
* @param dispatcher An pointer to the NC_Dispatch table that should
|
||||
* be used by this NC.
|
||||
* @param path The name of the file.
|
||||
* @param mode The open or create mode.
|
||||
* @param model
|
||||
* @param model An NCmodel instance, provided by NC_infermodel().
|
||||
* @param ncpp A pointer that gets a pointer to the newlly allocacted
|
||||
* and initialized NC struct.
|
||||
*
|
||||
|
@ -89,7 +89,7 @@ nc4_check_name(const char *name, char *norm_name)
|
||||
* nc4_nc4f_list_add(), except it takes an ncid instead of an NC *,
|
||||
* and also passes back the dispatchdata pointer.
|
||||
*
|
||||
* @param ncid The ncid of the file (aka ext_ncid).
|
||||
* @param ncid The (already-assigned) ncid of the file (aka ext_ncid).
|
||||
* @param path The file name of the new file.
|
||||
* @param mode The mode flag.
|
||||
* @param dispatchdata Void * that gets pointer to dispatch data,
|
||||
@ -125,6 +125,31 @@ nc4_file_list_add(int ncid, const char *path, int mode, void **dispatchdata)
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Change the ncid of an open file. This is needed for PIO
|
||||
* integration.
|
||||
*
|
||||
* @param ncid The ncid of the file (aka ext_ncid).
|
||||
* @param new_ncid The new ncid to use.
|
||||
*
|
||||
* @return ::NC_NOERR No error.
|
||||
* @return ::NC_EBADID No NC struct with this ext_ncid.
|
||||
* @return ::NC_ENOMEM Out of memory.
|
||||
* @author Ed Hartnett
|
||||
*/
|
||||
int
|
||||
nc4_file_change_ncid(int ncid, int new_ncid)
|
||||
{
|
||||
NC *nc;
|
||||
int ret;
|
||||
|
||||
/* Find NC pointer for this file. */
|
||||
if ((ret = NC_check_id(ncid, &nc)))
|
||||
return ret;
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Get info about a file on the list of libsrc4 open files. This is
|
||||
* used by dispatch layers that wish to use the libsrc4 metadata
|
||||
|
@ -14,8 +14,8 @@ include $(top_srcdir)/lib_flags.am
|
||||
# Find and link to the netcdf-c library.
|
||||
LDADD = ${top_builddir}/liblib/libnetcdf.la
|
||||
|
||||
check_PROGRAMS = tst_nclist
|
||||
TESTS = tst_nclist
|
||||
check_PROGRAMS = tst_nclist tst_nc4internal
|
||||
TESTS = tst_nclist tst_nc4internal
|
||||
|
||||
# If valgrind is present, add valgrind targets.
|
||||
@VALGRIND_CHECK_RULES@
|
||||
|
90
unit_test/tst_nc4internal.c
Normal file
90
unit_test/tst_nc4internal.c
Normal file
@ -0,0 +1,90 @@
|
||||
/* This is part of the netCDF package. Copyright 2005-2019 University
|
||||
Corporation for Atmospheric Research/Unidata. See COPYRIGHT file
|
||||
for conditions of use.
|
||||
|
||||
Test list functions in nc4internal.c.
|
||||
|
||||
Ed Hartnett, 8/21/19
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <nc_tests.h>
|
||||
#include "nc.h"
|
||||
#include "nc4internal.h"
|
||||
#include "ncdispatch.h"
|
||||
#include "err_macros.h"
|
||||
|
||||
/* An integer value to use in testing. */
|
||||
#define TEST_VAL_42 42
|
||||
|
||||
#define FILE_NAME "tst_nc4internal.nc"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
printf("\n*** Testing netcdf nc4internal functions.\n");
|
||||
printf("Testing adding new file to nc4internal file lists...");
|
||||
{
|
||||
NC *ncp;
|
||||
NCmodel model;
|
||||
|
||||
/* This won't work because there is no NC in the NC list which
|
||||
* has an ncid of TEST_VAL_42. */
|
||||
if (nc4_file_list_add(TEST_VAL_42, FILE_NAME, 0, NULL) != NC_EBADID) ERR;
|
||||
|
||||
/* Create the NC* instance and insert its dispatcher and
|
||||
* model. The NC3_dispatch_table is defined in
|
||||
* ncdispatch.h. */
|
||||
if(new_NC(NC3_dispatch_table, FILE_NAME, 0, &model, &ncp)) ERR;
|
||||
|
||||
/* Add to list of known open files and define ext_ncid. */
|
||||
add_to_NCList(ncp);
|
||||
|
||||
/* Create the NC_FILE_INFO_T instance associated empty lists
|
||||
* to hold dims, types, groups, and the root group. */
|
||||
if (nc4_file_list_add(ncp->ext_ncid, FILE_NAME, 0, NULL)) ERR;
|
||||
|
||||
/* Delete the NC_FILE_INFO_T and related storage. */
|
||||
if (nc4_file_list_del(ncp->ext_ncid)) ERR;
|
||||
|
||||
/* Delete the ncp from the list. (In fact, just null out its
|
||||
* entry in the array of file slots. */
|
||||
del_from_NCList(ncp); /* Will free empty list. */
|
||||
|
||||
/* Now free the NC struct. */
|
||||
free_NC(ncp);
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
/* printf("Testing changing ncid..."); */
|
||||
/* { */
|
||||
/* NC *ncp, *ncp2; */
|
||||
/* int mode = 0; */
|
||||
/* NCmodel model; */
|
||||
/* int ret; */
|
||||
|
||||
/* /\* Create the NC* instance and insert its dispatcher and model. *\/ */
|
||||
/* if ((ret = new_NC(NULL, FILE_NAME, mode, &model, &ncp))) ERR; */
|
||||
|
||||
/* /\* Add to list of known open files and define ext_ncid. *\/ */
|
||||
/* add_to_NCList(ncp); */
|
||||
|
||||
/* /\* Find it in the list. *\/ */
|
||||
/* if (!(ncp2 = find_in_NCList(ncp->ext_ncid))) ERR; */
|
||||
/* if (!(ncp2 = find_in_NCList_by_name(FILE_NAME))) ERR; */
|
||||
/* if ((ret = iterate_NCList(1, &ncp2))) ERR; */
|
||||
/* if (count_NCList() != 1) ERR; */
|
||||
|
||||
/* /\* Change the ncid. *\/ */
|
||||
/* if (nc4_file_change_ncid(ncp->ext_ncid, TEST_VAL_42)) ERR; */
|
||||
|
||||
/* /\* Delete it. *\/ */
|
||||
/* del_from_NCList(ncp); /\* Will free empty list. *\/ */
|
||||
/* free_NC(ncp); */
|
||||
|
||||
/* /\* Ensure it is no longer in list. *\/ */
|
||||
/* /\* if (find_in_NCList(ncp->ext_ncid)) ERR; *\/ */
|
||||
|
||||
/* } */
|
||||
/* SUMMARIZE_ERR; */
|
||||
FINAL_RESULTS;
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
/* An integer value to use in testing. */
|
||||
#define TEST_VAL_42 42
|
||||
|
||||
#define FILE_NAME "tst_nclist.nc"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -36,11 +38,10 @@ main(int argc, char **argv)
|
||||
NC *ncp, *ncp2;
|
||||
int mode = 0;
|
||||
NCmodel model;
|
||||
char path[] = {"file.nc"};
|
||||
int ret;
|
||||
|
||||
/* Create the NC* instance and insert its dispatcher and model. */
|
||||
if ((ret = new_NC(NULL, path, mode, &model, &ncp))) ERR;
|
||||
if ((ret = new_NC(NULL, FILE_NAME, mode, &model, &ncp))) ERR;
|
||||
|
||||
/* Nothing to find yet. */
|
||||
if (find_in_NCList(TEST_VAL_42)) ERR;
|
||||
@ -55,7 +56,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* Find it in the list. */
|
||||
if (!(ncp2 = find_in_NCList(ncp->ext_ncid))) ERR;
|
||||
if (!(ncp2 = find_in_NCList_by_name(path))) ERR;
|
||||
if (!(ncp2 = find_in_NCList_by_name(FILE_NAME))) ERR;
|
||||
if ((ret = iterate_NCList(1, &ncp2))) ERR;
|
||||
if (count_NCList() != 1) ERR;
|
||||
|
||||
@ -66,6 +67,8 @@ main(int argc, char **argv)
|
||||
ncid = ncp->ext_ncid;
|
||||
del_from_NCList(ncp); /* Will free empty list. */
|
||||
free_NC(ncp);
|
||||
|
||||
/* Ensure it is no longer in list. */
|
||||
if (find_in_NCList(ncid)) ERR;
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
@ -76,7 +79,6 @@ main(int argc, char **argv)
|
||||
NC *ncp;
|
||||
int mode = 0;
|
||||
NCmodel model;
|
||||
char path[] = {"file.nc"};
|
||||
int max_num_nc = 65535;
|
||||
int i;
|
||||
int ret;
|
||||
@ -84,7 +86,7 @@ main(int argc, char **argv)
|
||||
/* Fill the NC list. */
|
||||
for (i = 0; i < max_num_nc; i++)
|
||||
{
|
||||
if ((ret = new_NC(NULL, path, mode, &model, &ncp))) ERR;
|
||||
if ((ret = new_NC(NULL, FILE_NAME, mode, &model, &ncp))) ERR;
|
||||
if (add_to_NCList(ncp)) ERR;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user