2003-04-01 01:59:04 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
1997-07-31 05:17:56 +08:00
|
|
|
|
|
|
|
/***********************************************************
|
2020-09-30 22:27:10 +08:00
|
|
|
*
|
|
|
|
* Test program: tmeta
|
|
|
|
*
|
|
|
|
* Test the basic meta-data encode/decode macros calls.
|
|
|
|
*
|
|
|
|
*************************************************************/
|
1997-07-31 05:17:56 +08:00
|
|
|
|
2001-04-04 02:09:16 +08:00
|
|
|
#include "testhdf5.h"
|
|
|
|
#include "H5Fprivate.h"
|
1997-07-31 05:17:56 +08:00
|
|
|
|
2021-08-24 05:14:53 +08:00
|
|
|
#define TEST_INT16_VALUE (-7641)
|
2020-09-30 22:27:10 +08:00
|
|
|
#define TEST_UINT16_VALUE 45002
|
2021-08-24 05:14:53 +08:00
|
|
|
#define TEST_INT32_VALUE (-981236)
|
2020-09-30 22:27:10 +08:00
|
|
|
#define TEST_UINT32_VALUE 3476589
|
1997-07-31 05:17:56 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
uint8_t compar_buffer[] = {
|
1997-07-31 05:17:56 +08:00
|
|
|
/* Little-endian encoded version of the 16-bit signed integer */
|
2020-09-30 22:27:10 +08:00
|
|
|
(uint8_t)((TEST_INT16_VALUE)&0xff),
|
|
|
|
(uint8_t)((TEST_INT16_VALUE >> 8) & 0xff),
|
1997-07-31 05:17:56 +08:00
|
|
|
/* Little-endian encoded version of the 16-bit unsigned integer */
|
2020-09-30 22:27:10 +08:00
|
|
|
(uint8_t)((TEST_UINT16_VALUE)&0xff),
|
|
|
|
(uint8_t)((TEST_UINT16_VALUE >> 8) & 0xff),
|
1997-07-31 05:17:56 +08:00
|
|
|
/* Little-endian encoded version of the 32-bit signed integer */
|
2020-09-30 22:27:10 +08:00
|
|
|
(uint8_t)((TEST_INT32_VALUE)&0xff),
|
|
|
|
(uint8_t)((TEST_INT32_VALUE >> 8) & 0xff),
|
|
|
|
(uint8_t)((TEST_INT32_VALUE >> 16) & 0xff),
|
|
|
|
(uint8_t)((TEST_INT32_VALUE >> 24) & 0xff),
|
1997-07-31 05:17:56 +08:00
|
|
|
/* Little-endian encoded version of the 32-bit unsigned integer */
|
2020-09-30 22:27:10 +08:00
|
|
|
(uint8_t)((TEST_UINT32_VALUE)&0xff),
|
|
|
|
(uint8_t)((TEST_UINT32_VALUE >> 8) & 0xff),
|
|
|
|
(uint8_t)((TEST_UINT32_VALUE >> 16) & 0xff),
|
|
|
|
(uint8_t)((TEST_UINT32_VALUE >> 24) & 0xff),
|
1998-01-17 06:23:43 +08:00
|
|
|
};
|
1997-07-31 05:17:56 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
uint8_t encode_buffer[sizeof(compar_buffer)];
|
1997-07-31 05:17:56 +08:00
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
**
|
|
|
|
** test_metadata(): Main meta-data encode/decode testing routine.
|
2005-08-14 04:53:35 +08:00
|
|
|
**
|
1997-07-31 05:17:56 +08:00
|
|
|
****************************************************************/
|
2005-08-14 04:53:35 +08:00
|
|
|
void
|
1998-01-17 06:23:43 +08:00
|
|
|
test_metadata(void)
|
1997-07-31 05:17:56 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int16_t ei16 = TEST_INT16_VALUE; /* variables to hold the values to encode */
|
|
|
|
uint16_t eu16 = TEST_UINT16_VALUE;
|
|
|
|
int32_t ei32 = TEST_INT32_VALUE;
|
|
|
|
uint32_t eu32 = TEST_UINT32_VALUE;
|
|
|
|
int16_t di16; /* variables to hold the decoded values */
|
|
|
|
uint16_t du16;
|
|
|
|
int32_t di32;
|
|
|
|
uint32_t du32;
|
|
|
|
uint8_t *p; /* pointer into the buffer being en/de-coded */
|
1997-07-31 05:17:56 +08:00
|
|
|
|
|
|
|
/* Output message about test being performed */
|
2006-08-22 07:27:11 +08:00
|
|
|
MESSAGE(5, ("Testing Metadata Encoding/decoding\n"));
|
1997-07-31 05:17:56 +08:00
|
|
|
|
|
|
|
/* Start by encoding the values above */
|
1998-01-17 06:23:43 +08:00
|
|
|
p = encode_buffer;
|
2020-09-30 22:27:10 +08:00
|
|
|
INT16ENCODE(p, ei16); /* Encode the int16 value */
|
|
|
|
UINT16ENCODE(p, eu16); /* Encode the uint16 value */
|
|
|
|
INT32ENCODE(p, ei32); /* Encode the int32 value */
|
|
|
|
UINT32ENCODE(p, eu32); /* Encode the uint32 value */
|
1997-07-31 05:17:56 +08:00
|
|
|
|
|
|
|
/* Check if we got what we asked for */
|
1998-01-17 06:23:43 +08:00
|
|
|
if (HDmemcmp(encode_buffer, compar_buffer, sizeof(compar_buffer)) != 0) {
|
2020-09-30 22:27:10 +08:00
|
|
|
unsigned u; /* local counting variable */
|
1997-07-31 05:17:56 +08:00
|
|
|
|
1998-01-17 06:23:43 +08:00
|
|
|
for (u = 0; u < sizeof(compar_buffer); u++) {
|
2004-01-10 09:41:13 +08:00
|
|
|
if (compar_buffer[u] != encode_buffer[u])
|
2020-09-30 22:27:10 +08:00
|
|
|
TestErrPrintf("Error encoding meta-data at offset %u, wanted: %u, got: %u\n", (unsigned)u,
|
|
|
|
(unsigned)compar_buffer[u], (unsigned)encode_buffer[u]);
|
|
|
|
} /* end for */
|
|
|
|
} /* end if */
|
1997-07-31 05:17:56 +08:00
|
|
|
/* Test decoding macros */
|
1998-01-17 06:23:43 +08:00
|
|
|
p = encode_buffer;
|
2020-09-30 22:27:10 +08:00
|
|
|
INT16DECODE(p, di16); /* Decode the int16 value */
|
|
|
|
UINT16DECODE(p, du16); /* Decode the uint16 value */
|
|
|
|
INT32DECODE(p, di32); /* Decode the int32 value */
|
|
|
|
UINT32DECODE(p, du32); /* Decode the uint32 value */
|
1997-07-31 05:17:56 +08:00
|
|
|
|
|
|
|
/* Check the values decoded */
|
2004-01-10 09:41:13 +08:00
|
|
|
if (di16 != TEST_INT16_VALUE)
|
|
|
|
TestErrPrintf("Error decoding int16 meta-data wanted: %d, got: %d "
|
2020-09-30 22:27:10 +08:00
|
|
|
"at %s:%d\n",
|
|
|
|
(int)TEST_INT16_VALUE, (int)di16, __FILE__, __LINE__);
|
2004-01-10 09:41:13 +08:00
|
|
|
if (du16 != TEST_UINT16_VALUE)
|
|
|
|
TestErrPrintf("Error decoding uint16 meta-data wanted: %u, got: %u "
|
2020-09-30 22:27:10 +08:00
|
|
|
"at %s:%d\n",
|
|
|
|
(unsigned)TEST_UINT16_VALUE, (unsigned)du16, __FILE__, __LINE__);
|
2004-01-10 09:41:13 +08:00
|
|
|
if (di32 != TEST_INT32_VALUE)
|
|
|
|
TestErrPrintf("Error decoding int32 meta-data wanted: %ld, got: %ld "
|
2020-09-30 22:27:10 +08:00
|
|
|
"at %s:%d\n",
|
|
|
|
(long)TEST_INT32_VALUE, (long)di32, __FILE__, __LINE__);
|
2004-01-10 09:41:13 +08:00
|
|
|
if (du32 != TEST_UINT32_VALUE)
|
|
|
|
TestErrPrintf("Error decoding uint32 meta-data wanted: %lu, got: %lu "
|
2020-09-30 22:27:10 +08:00
|
|
|
"at %s:%d\n",
|
|
|
|
(unsigned long)TEST_UINT32_VALUE, (unsigned long)du32, __FILE__, __LINE__);
|
|
|
|
} /* test_metadata() */
|
1998-07-03 08:57:00 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: cleanup_metadata
|
|
|
|
*
|
|
|
|
* Purpose: Cleanup temporary test files
|
|
|
|
*
|
|
|
|
* Return: none
|
|
|
|
*
|
|
|
|
* Programmer: Albert Cheng
|
|
|
|
* July 2, 1998
|
|
|
|
*
|
|
|
|
* Modifications:
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2019-06-28 22:10:43 +08:00
|
|
|
void
|
1998-07-03 08:57:00 +08:00
|
|
|
cleanup_metadata(void)
|
|
|
|
{
|
|
|
|
/* no file to clean */
|
|
|
|
}
|