[svn-r3532] Purpose:

Adding tests to the C++ API
Description:
    The C++ API has no formal testing yet.
Solution:
    Added tests for file and dataset interfaces.  I'm still working on
    other tests.
Platforms tested:
    Linux (gcc version egcs-2.91.66)
    I temporarily modified the Makefile on my local Linux machine and these
    tests work.  I need Bill to help adding them permanently before I can
    test on an NCSA machine.  I checked the files in now so Bill can do that.
This commit is contained in:
Binh-Minh Ribler 2001-03-01 13:07:25 -05:00
parent 0cb43aefd9
commit 6e7877db5e
3 changed files with 1692 additions and 0 deletions

1048
c++/test/dsets.cpp Normal file

File diff suppressed because it is too large Load Diff

312
c++/test/testhdf5.cpp Normal file
View File

@ -0,0 +1,312 @@
/****************************************************************************
* NCSA HDF *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* hdf/COPYING file. *
* *
****************************************************************************/
/*
FILE
testhdf5.c - HDF5 testing framework main file.
REMARKS
General test wrapper for HDF5 base library test programs
DESIGN
Each test function should be implemented as function having no
parameters and returning void (i.e. no return value). They should be put
into the list of InitTest() calls in main() below. Functions which depend
on other functionality should be placed below the InitTest() call for the
base functionality testing.
Each test module should include testhdf5.h and define a unique set of
names for test files they create.
BUGS/LIMITATIONS
EXPORTED ROUTINES/VARIABLES:
Two variables are exported: num_errs, and Verbosity.
*/
#if defined __MWERKS__
#include <console.h>
#endif
#include <stdarg.h>
#define MAXNUMOFTESTS 30
#define HDF5_TEST_MASTER
/* Internal Variables */
static int Index = 0;
/* Global variables */
int num_errs = 0;
int Verbosity;
// Use C version of the header file testhdf5.h instead of re-coding it
#include <testhdf5.h>
#include <H5Cpp.h>
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
struct TestStruct {
int NumErrors;
char Description[64];
int SkipFlag;
char Name[16];
void (*Call) (void);
void (*Cleanup) (void);
} Test[MAXNUMOFTESTS];
static void InitTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr);
static void usage(void);
static void
InitTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr)
{
if (Index >= MAXNUMOFTESTS) {
print_func("Uh-oh, too many tests added, increase MAXNUMOFTEST!\n");
exit(-1);
} /* end if */
HDstrcpy(Test[Index].Description, TheDescr);
HDstrcpy(Test[Index].Name, TheName);
Test[Index].Call = TheCall;
Test[Index].Cleanup = Cleanup;
Test[Index].NumErrors = -1;
Test[Index].SkipFlag = 0;
Index++;
}
static void
usage(void)
{
intn i;
print_func("Usage: testhdf5 [-v[erbose] (l[ow]|m[edium]|h[igh]|0-10)] \n");
print_func(" [-[e]x[clude] name+] \n");
print_func(" [-o[nly] name+] \n");
print_func(" [-b[egin] name] \n");
print_func(" [-s[ummary]] \n");
print_func(" [-c[leanoff]] \n");
print_func(" [-n[ocaching]] \n");
print_func(" [-h[elp]] \n");
print_func("\n\n");
print_func("verbose controls the amount of information displayed\n");
print_func("exclude to exclude tests by name\n");
print_func("only to name tests which should be run\n");
print_func("begin start at the name of the test givin\n");
print_func("summary prints a summary of test results at the end\n");
print_func("cleanoff does not delete *.hdf files after execution of tests\n");
print_func("nocaching do not turn on low-level DD caching\n");
print_func("help print out this information\n");
print_func("\n\n");
print_func("This program currently tests the following: \n\n");
print_func("%16s %s\n", "Name", "Description");
print_func("%16s %s\n", "----", "-----------");
for (i = 0; i < Index; i++)
print_func("%16s %s\n", Test[i].Name, Test[i].Description);
print_func("\n\n");
} /* end usage() */
/*
* This routine is designed to provide equivalent functionality to 'printf'
* and allow easy replacement for environments which don't have stdin/stdout
* available. (i.e. Windows & the Mac)
*/
int
print_func(const char *format,...)
{
va_list arglist;
int ret_value;
va_start(arglist, format);
ret_value = vprintf(format, arglist);
va_end(arglist);
return (ret_value);
}
void
test_tbbt(void)
{ }
int
main(int argc, char *argv[])
{
int CLLoop; /* Command Line Loop */
int Loop, Loop1;
int Summary = 0;
int CleanUp = 1;
int Cache = 1;
#if defined __MWERKS__
argc = ccommand(&argv);
#endif
#if !(defined MAC || defined __MWERKS__ || defined SYMANTEC_C)
/* Un-buffer the stdout and stderr */
setbuf(stderr, NULL);
setbuf(stdout, NULL);
#endif
/*
* Turn off automatic error reporting since we do it ourselves. Besides,
* half the functions this test calls are private, so automatic error
* reporting wouldn't do much good since it's triggered at the API layer.
*/
Exception::dontPrint();
// Tests are generally arranged from least to most complexity...
//InitTest("metadata", test_metadata, cleanup_metadata, "Encode/decode metadata code");
// C++ API doesn't need this test */
InitTest("tbbt", test_tbbt, NULL, "Threaded, Balanced, Binary Trees - not tested");
// testing file creation and opening in tfile.cpp
InitTest("file", test_file, cleanup_file, "Low-Level File I/O");
// Comment out tests that are not done yet. - BMR, Feb 2001
//InitTest("h5s", test_h5s, cleanup_h5s, "Dataspaces");
//InitTest("attr", test_attr, cleanup_attr, "Attributes");
//InitTest("select", test_select, cleanup_select, "Selections");
//InitTest("time", test_time, cleanup_time, "Time Datatypes");
//InitTest("reference", test_reference, cleanup_reference, "References");
//InitTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes");
//InitTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings");
//InitTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration");
//InitTest("array", test_array, cleanup_array, "Array Datatypes");
//InitTest("genprop", test_genprop, cleanup_genprop, "Generic Properties");
Verbosity = 4; /* Default Verbosity is Low */
uintn major, minor, release;
H5Library::getLibVersion( major, minor, release);
print_func("\nFor help use: testhdf5 -help\n");
print_func("Linked with hdf5 version %u.%u release %u\n",
(unsigned)major, (unsigned)minor, (unsigned)release);
for (CLLoop = 1; CLLoop < argc; CLLoop++) {
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-verbose") == 0) ||
(HDstrcmp(argv[CLLoop], "-v") == 0))) {
if (argv[CLLoop + 1][0] == 'l')
Verbosity = 4;
else if (argv[CLLoop + 1][0] == 'm')
Verbosity = 6;
else if (argv[CLLoop + 1][0] == 'h')
Verbosity = 10;
else
Verbosity = atoi(argv[CLLoop + 1]);
} /* end if */
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-summary") == 0) ||
(HDstrcmp(argv[CLLoop], "-s") == 0)))
Summary = 1;
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-help") == 0) ||
(HDstrcmp(argv[CLLoop], "-h") == 0))) {
usage();
exit(0);
}
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-cleanoff") == 0) ||
(HDstrcmp(argv[CLLoop], "-c") == 0)))
CleanUp = 0;
if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-nocache") == 0) ||
(HDstrcmp(argv[CLLoop], "-n") == 0))) {
Cache = 0;
printf ("Cache = %d\n", Cache);
}
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-exclude") == 0) ||
(HDstrcmp(argv[CLLoop], "-x") == 0))) {
Loop = CLLoop + 1;
while ((Loop < argc) && (argv[Loop][0] != '-')) {
for (Loop1 = 0; Loop1 < Index; Loop1++)
if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
Test[Loop1].SkipFlag = 1;
Loop++;
} /* end while */
} /* end if */
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-begin") == 0) ||
(HDstrcmp(argv[CLLoop], "-b") == 0))) {
Loop = CLLoop + 1;
while ((Loop < argc) && (argv[Loop][0] != '-')) {
for (Loop1 = 0; Loop1 < Index; Loop1++) {
if (HDstrcmp(argv[Loop], Test[Loop1].Name) != 0)
Test[Loop1].SkipFlag = 1;
if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
Loop1 = Index;
} /* end for */
Loop++;
} /* end while */
} /* end if */
if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-only") == 0) ||
(HDstrcmp(argv[CLLoop], "-o") == 0))) {
for (Loop = 0; Loop < Index; Loop++)
Test[Loop].SkipFlag = 1;
Loop = CLLoop + 1;
while ((Loop < argc) && (argv[Loop][0] != '-')) {
for (Loop1 = 0; Loop1 < Index; Loop1++)
if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
Test[Loop1].SkipFlag = 0;
Loop++;
} /* end while */
} /* end if */
} /* end for */
#ifdef NOT_YET
if (Cache) /* turn on caching, unless we were instucted not to */
Hcache(CACHE_ALL_FILES, TRUE);
#endif /* NOT_YET */
for (Loop = 0; Loop < Index; Loop++) {
if (Test[Loop].SkipFlag) {
MESSAGE(2, ("Skipping -- %s \n", Test[Loop].Description));
} else {
MESSAGE(2, ("Testing -- %s (%s) \n", Test[Loop].Description,
Test[Loop].Name));
MESSAGE(5, ("===============================================\n"));
Test[Loop].NumErrors = num_errs;
(*Test[Loop].Call) ();
Test[Loop].NumErrors = num_errs - Test[Loop].NumErrors;
MESSAGE(5, ("===============================================\n"));
MESSAGE(5, ("There were %d errors detected.\n\n", (int) Test[Loop].NumErrors));
} /* end else */
} /* end for */
MESSAGE(2, ("\n\n"))
if (num_errs)
print_func("!!! %d Error(s) were detected !!!\n\n", (int) num_errs);
else
print_func("All tests were successful. \n\n");
if (Summary) {
print_func("Summary of Test Results:\n");
print_func("Name of Test Errors Description of Test\n");
print_func("---------------- ------ --------------------------------------\n");
for (Loop = 0; Loop < Index; Loop++) {
if (Test[Loop].NumErrors == -1)
print_func("%16s %6s %s\n", Test[Loop].Name, "N/A", Test[Loop].Description);
else
print_func("%16s %6d %s\n", Test[Loop].Name, (int) Test[Loop].NumErrors,
Test[Loop].Description);
} /* end for */
print_func("\n\n");
} /* end if */
if (CleanUp && !getenv("HDF5_NOCLEANUP")) {
MESSAGE(2, ("\nCleaning Up temp files...\n\n"));
/* call individual cleanup routines in each source module */
for (Loop = 0; Loop < Index; Loop++)
if (!Test[Loop].SkipFlag && Test[Loop].Cleanup!=NULL)
(*Test[Loop].Cleanup) ();
}
return (num_errs);
} /* end main() */

332
c++/test/tfile.cpp Normal file
View File

@ -0,0 +1,332 @@
/****************************************************************************
* NCSA HDF *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* hdf/COPYING file. *
* *
****************************************************************************/
/***********************************************************
*
* Test program: tfile
*
* Test the low-level file I/O features.
*
*************************************************************/
#include <testhdf5.h>
#include <H5Cpp.h>
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
#include <H5private.h>
#include <H5Bprivate.h>
#include <H5Pprivate.h>
#define F1_USERBLOCK_SIZE (hsize_t)0
#define F1_OFFSET_SIZE sizeof(haddr_t)
#define F1_LENGTH_SIZE sizeof(hsize_t)
#define F1_SYM_LEAF_K 4
#define F1_SYM_INTERN_K 16
#define FILE1 "tfile1.h5"
#define F2_USERBLOCK_SIZE (hsize_t)512
#define F2_OFFSET_SIZE 8
#define F2_LENGTH_SIZE 8
#define F2_SYM_LEAF_K 8
#define F2_SYM_INTERN_K 32
#define FILE2 "tfile2.h5"
#define F3_USERBLOCK_SIZE (hsize_t)0
#define F3_OFFSET_SIZE F2_OFFSET_SIZE
#define F3_LENGTH_SIZE F2_LENGTH_SIZE
#define F3_SYM_LEAF_K F2_SYM_LEAF_K
#define F3_SYM_INTERN_K F2_SYM_INTERN_K
#define FILE3 "tfile3.h5"
/*-------------------------------------------------------------------------
* Function: test_file_create
*
* Purpose: Test file and template creations
*
* Return: None
*
* Programmer: Binh-Minh Ribler
* January, 2001
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
test_file_create(void)
{
hid_t tmpl1, tmpl2; /*file creation templates */
int iparm, iparm2;
herr_t ret; /*generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File Creation I/O\n"));
/* Test create with various sequences of H5F_ACC_EXCL and */
/* H5F_ACC_TRUNC flags */
/* Create with H5F_ACC_EXCL */
/* First ensure the file does not exist */
//remove(FILE1);
try {
H5File* fid1 = new H5File (FILE1, H5F_ACC_EXCL);
/*
* try to create the same file with H5F_ACC_TRUNC. This should fail
* because fid1 is the same file and is currently open.
*/
try { H5File fid2 (FILE1, H5F_ACC_TRUNC); }
catch( FileIException error ) {
// cannot use fid2 here (out of scope), but the exception was
// thrown only if file id was < 0, so -1 is used to verify - 1/15/01
VERIFY(-1, FAIL, "H5File constructor");
}
// Close file fid1
delete fid1;
/*
* Try again with H5F_ACC_EXCL. This should fail because the file already
* exists from the previous steps.
*/
try { fid1 = new H5File( FILE1, H5F_ACC_EXCL ); }
catch( FileIException error ){ VERIFY(-1, FAIL, "H5File constructor"); }
// Test create with H5F_ACC_TRUNC. This will truncate the existing file.
fid1 = new H5File (FILE1, H5F_ACC_TRUNC);
/*
* Try to truncate first file again. This should fail because fid1 is the
* same file and is currently open.
*/
try { H5File fid2 (FILE1, H5F_ACC_TRUNC); }
catch( FileIException error ) { VERIFY(-1, FAIL, "H5File constructor"); }
/*
* Try with H5F_ACC_EXCL. This should fail too because the file already
* exists.
*/
try { H5File fid3 (FILE1, H5F_ACC_EXCL); }
catch( FileIException error ) { VERIFY(-1, FAIL, "H5File constructor"); }
/* Get the file-creation template */
FileCreatPropList tmpl1 = fid1->getCreatePlist();
hsize_t ublock = tmpl1.getUserblock();
VERIFY(ublock, F1_USERBLOCK_SIZE, "FileCreatPropList::H5Pget_userblock");
size_t parm1, parm2; /*file-creation parameters */
tmpl1.getSizes( parm1, parm2);
VERIFY(parm1, F1_OFFSET_SIZE, "FileCreatPropList::getSizes");
VERIFY(parm2, F1_LENGTH_SIZE, "FileCreatPropList::getSizes");
int iparm1, iparm2; /*file-creation parameters */
tmpl1.getSymk( iparm1, iparm2);
VERIFY(iparm1, F1_SYM_INTERN_K, "FileCreatPropList::getSymk");
VERIFY(iparm2, F1_SYM_LEAF_K, "FileCreatPropList::getSymk");
// tmpl1 is automatically closed; if error occurs, it'll be
// caught in the catch block
/* Close first file */
delete fid1;
}
catch( PropListIException error ) {
CHECK(-1, FAIL, error.getCDetailMesg());
}
catch( FileIException error ) {
CHECK(-1, FAIL, error.getCDetailMesg());
}
try
{
/* Create a new file with a non-standard file-creation template */
FileCreatPropList* tmpl1 = new FileCreatPropList;
/* Set the new file-creation parameters */
tmpl1->setUserblock (F2_USERBLOCK_SIZE);
tmpl1->setSizes( F2_OFFSET_SIZE, F2_LENGTH_SIZE );
tmpl1->setSymk( F2_SYM_INTERN_K, F2_SYM_LEAF_K );
/*
* Try to create second file, with non-standard file-creation template
* params.
*/
H5File fid2( FILE2, H5F_ACC_TRUNC, *tmpl1 );
/* Release file-creation template */
delete tmpl1;
/* Get the file-creation template */
tmpl1 = new FileCreatPropList (fid2.getCreatePlist());
/* Get the file-creation parameters */
hsize_t ublock = tmpl1->getUserblock();
VERIFY(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock");
size_t parm1, parm2; /*file-creation parameters */
tmpl1->getSizes( parm1, parm2);
VERIFY(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes");
VERIFY(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes");
int iparm1, iparm2; /*file-creation parameters */
tmpl1->getSymk( iparm1, iparm2);
VERIFY(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk");
VERIFY(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk");
/* Clone the file-creation template */
FileCreatPropList tmpl2;
tmpl2.copy (*tmpl1);
/* Dynamically release file-creation template */
delete tmpl1;
/* Set the new file-creation parameter */
tmpl2.setUserblock( F3_USERBLOCK_SIZE );
/*
* Try to create second file, with non-standard file-creation template
* params
*/
H5File fid3( FILE3, H5F_ACC_TRUNC, tmpl2 );
/* Get the file-creation template */
tmpl1 = new FileCreatPropList (fid3.getCreatePlist());
/* Get the file-creation parameters */
ublock = tmpl1->getUserblock();
VERIFY(ublock, F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock");
tmpl1->getSizes( parm1, parm2);
VERIFY(parm1, F3_OFFSET_SIZE, "FileCreatPropList::getSizes");
VERIFY(parm2, F3_LENGTH_SIZE, "FileCreatPropList::getSizes");
tmpl1->getSymk( iparm1, iparm2);
VERIFY(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk");
VERIFY(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk");
/* Dynamically release file-creation template */
delete tmpl1;
}
catch( PropListIException error ) {
CHECK(-1, FAIL, error.getCDetailMesg());
}
catch( FileIException error ) {
CHECK(-1, FAIL, error.getCDetailMesg());
}
} /* test_file_create() */
/*-------------------------------------------------------------------------
* Function: test_file_open
*
* Purpose: Test file accesses
*
* Return: None
*
* Programmer: Binh-Minh Ribler
* January, 2001
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
test_file_open(void)
{
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File Opening I/O\n"));
try {
/* Open first file */
H5File fid1 (FILE2, H5F_ACC_RDWR );
/* Get the file-creation template */
//FileCreatPropList tmpl1;
FileCreatPropList tmpl1 = fid1.getCreatePlist();
/* Get the file-creation parameters */
hsize_t ublock = tmpl1.getUserblock();
VERIFY(ublock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock");
size_t parm1, parm2; /*file-creation parameters */
tmpl1.getSizes( parm1, parm2);
VERIFY(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes");
VERIFY(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes");
int iparm1, iparm2; /*file-creation parameters */
tmpl1.getSymk( iparm1, iparm2);
VERIFY(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk");
VERIFY(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk");
} // end of try block
catch( FileIException error ) {
CHECK(FAIL, FAIL, error.getCDetailMesg());
}
catch( PropListIException error ) {
CHECK(FAIL, FAIL, error.getCDetailMesg());
}
} /* test_file_open() */
/*-------------------------------------------------------------------------
* Function: test_file
*
* Purpose: Main program
*
* Return: None
*
* Programmer: Binh-Minh Ribler
* January, 2001
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
test_file(void)
{
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File I/O\n"));
test_file_create(); /* Test file creation (also creation templates) */
test_file_open(); /* Test file opening */
} /* test_file() */
/*-------------------------------------------------------------------------
* Function: cleanup_file
*
* Purpose: Cleanup temporary test files
*
* Return: none
*
* Programmer: Albert Cheng
* July 2, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
cleanup_file(void)
{
remove(FILE1);
remove(FILE2);
remove(FILE3);
}