1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /***********************************************************
15 *
16 * Test program:  tmeta
17 *
18 * Test the basic meta-data encode/decode macros calls.
19 *
20 *************************************************************/
21 
22 #include "testhdf5.h"
23 #include "H5Fprivate.h"
24 
25 #define TEST_INT16_VALUE    -7641
26 #define TEST_UINT16_VALUE   45002
27 #define TEST_INT32_VALUE    -981236
28 #define TEST_UINT32_VALUE   3476589
29 
30 uint8_t                   compar_buffer[] =
31 {
32     /* Little-endian encoded version of the 16-bit signed integer */
33     (uint8_t) ((TEST_INT16_VALUE) & 0xff), (uint8_t) ((TEST_INT16_VALUE >> 8) & 0xff),
34     /* Little-endian encoded version of the 16-bit unsigned integer */
35     (uint8_t) ((TEST_UINT16_VALUE) & 0xff), (uint8_t) ((TEST_UINT16_VALUE >> 8) & 0xff),
36     /* Little-endian encoded version of the 32-bit signed integer */
37     (uint8_t) ((TEST_INT32_VALUE) & 0xff), (uint8_t) ((TEST_INT32_VALUE >> 8) & 0xff),
38     (uint8_t) ((TEST_INT32_VALUE >> 16) & 0xff), (uint8_t) ((TEST_INT32_VALUE >> 24) & 0xff),
39     /* Little-endian encoded version of the 32-bit unsigned integer */
40     (uint8_t) ((TEST_UINT32_VALUE) & 0xff), (uint8_t) ((TEST_UINT32_VALUE >> 8) & 0xff),
41     (uint8_t) ((TEST_UINT32_VALUE >> 16) & 0xff), (uint8_t) ((TEST_UINT32_VALUE >> 24) & 0xff),
42 };
43 
44 uint8_t                   encode_buffer[sizeof(compar_buffer)];
45 
46 /****************************************************************
47 **
48 **  test_metadata(): Main meta-data encode/decode testing routine.
49 **
50 ****************************************************************/
51 void
test_metadata(void)52 test_metadata(void)
53 {
54     int16_t     ei16 = TEST_INT16_VALUE;    /* variables to hold the values to encode */
55     uint16_t    eu16 = TEST_UINT16_VALUE;
56     int32_t     ei32 = TEST_INT32_VALUE;
57     uint32_t    eu32 = TEST_UINT32_VALUE;
58     int16_t     di16;       /* variables to hold the decoded values */
59     uint16_t    du16;
60     int32_t     di32;
61     uint32_t    du32;
62     uint8_t	*p;  /* pointer into the buffer being en/de-coded */
63 
64     /* Output message about test being performed */
65     MESSAGE(5, ("Testing Metadata Encoding/decoding\n"));
66 
67     /* Start by encoding the values above */
68     p = encode_buffer;
69     INT16ENCODE(p, ei16);       /* Encode the int16 value */
70     UINT16ENCODE(p, eu16);      /* Encode the uint16 value */
71     INT32ENCODE(p, ei32);       /* Encode the int32 value */
72     UINT32ENCODE(p, eu32);      /* Encode the uint32 value */
73 
74     /* Check if we got what we asked for */
75     if (HDmemcmp(encode_buffer, compar_buffer, sizeof(compar_buffer)) != 0) {
76         unsigned                   u;      /* local counting variable */
77 
78         for (u = 0; u < sizeof(compar_buffer); u++) {
79             if (compar_buffer[u] != encode_buffer[u])
80                 TestErrPrintf("Error encoding meta-data at offset %u, wanted: %u, got: %u\n", (unsigned) u, (unsigned) compar_buffer[u], (unsigned) encode_buffer[u]);
81         }                       /* end for */
82     }                           /* end if */
83     /* Test decoding macros */
84     p = encode_buffer;
85     INT16DECODE(p, di16);       /* Decode the int16 value */
86     UINT16DECODE(p, du16);      /* Decode the uint16 value */
87     INT32DECODE(p, di32);       /* Decode the int32 value */
88     UINT32DECODE(p, du32);      /* Decode the uint32 value */
89 
90     /* Check the values decoded */
91     if (di16 != TEST_INT16_VALUE)
92         TestErrPrintf("Error decoding int16 meta-data wanted: %d, got: %d "
93                    "at %s:%d\n", (int) TEST_INT16_VALUE, (int) di16,
94                    __FILE__, __LINE__);
95     if (du16 != TEST_UINT16_VALUE)
96         TestErrPrintf("Error decoding uint16 meta-data wanted: %u, got: %u "
97                    "at %s:%d\n", (unsigned) TEST_UINT16_VALUE, (unsigned) du16,
98                    __FILE__, __LINE__);
99     if (di32 != TEST_INT32_VALUE)
100         TestErrPrintf("Error decoding int32 meta-data wanted: %ld, got: %ld "
101                    "at %s:%d\n", (long) TEST_INT32_VALUE, (long) di32,
102                    __FILE__, __LINE__);
103     if (du32 != TEST_UINT32_VALUE)
104         TestErrPrintf("Error decoding uint32 meta-data wanted: %lu, got: %lu "
105                    "at %s:%d\n", (unsigned long) TEST_UINT32_VALUE, (unsigned long) du32,
106                    __FILE__, __LINE__);
107 }                               /* test_metadata() */
108 
109 
110 /*-------------------------------------------------------------------------
111  * Function:	cleanup_metadata
112  *
113  * Purpose:	Cleanup temporary test files
114  *
115  * Return:	none
116  *
117  * Programmer:	Albert Cheng
118  *              July 2, 1998
119  *
120  * Modifications:
121  *
122  *-------------------------------------------------------------------------
123  */
124 void
cleanup_metadata(void)125 cleanup_metadata(void)
126 {
127     /* no file to clean */
128 }
129 
130