Source
6
6
* This file is part of HDF5. The full HDF5 copyright notice, including *
7
7
* terms governing use, modification, and redistribution, is contained in *
8
8
* the COPYING file, which can be found at the root of the source code *
9
9
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10
10
* If you do not have access to either file, you may request a copy from *
11
11
* help@hdfgroup.org. *
12
12
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
13
14
14
/***********************************************************
15
15
*
16
-
* Test program: tvlstr
16
+
* Test program: tvlstr
17
17
*
18
18
* Test the Variable-Length String functionality
19
19
*
20
20
*************************************************************/
21
21
22
22
#include "testhdf5.h"
23
23
24
-
#include "hdf5.h"
25
-
26
24
#define DATAFILE "tvlstr.h5"
27
25
#define DATAFILE2 "tvlstr2.h5"
28
26
29
27
/* 1-D dataset with fixed dimensions */
30
-
#define SPACE1_RANK 1
31
-
#define SPACE1_DIM1 4
28
+
#define SPACE1_RANK 1
29
+
#define SPACE1_DIM1 4
32
30
33
-
#define VLSTR_TYPE "vl_string_type"
31
+
#define VLSTR_TYPE "vl_string_type"
34
32
35
33
/* Definitions for the VL re-writing test */
36
34
#define REWRITE_NDATASETS 32
37
35
38
36
/* String for testing attributes */
39
37
static const char *string_att = "This is the string for the attribute";
40
38
static char *string_att_write=NULL;
41
39
42
40
void *test_vlstr_alloc_custom(size_t size, void *info);
43
41
void test_vlstr_free_custom(void *mem, void *info);
85
83
size_t extra; /* Extra space needed */
86
84
87
85
/*
88
86
* This weird contortion is required on the DEC Alpha to keep the
89
87
* alignment correct - QAK
90
88
*/
91
89
extra=MAX(sizeof(void *),sizeof(size_t));
92
90
93
91
if(_mem!=NULL) {
94
92
mem=((unsigned char *)_mem)-extra;
95
-
*mem_used-=*(size_t *)mem;
93
+
*mem_used-=*(size_t *)((void *)mem);
96
94
HDfree(mem);
97
95
} /* end if */
98
96
}
99
97
100
98
/****************************************************************
101
99
**
102
100
** test_vlstrings_basic(): Test basic VL string code.
103
101
** Tests simple VL string I/O
104
102
**
105
103
****************************************************************/
108
106
{
109
107
const char *wdata[SPACE1_DIM1]= {
110
108
"Four score and seven years ago our forefathers brought forth on this continent a new nation,",
111
109
"conceived in liberty and dedicated to the proposition that all men are created equal.",
112
110
"Now we are engaged in a great civil war,",
113
111
"testing whether that nation or any nation so conceived and so dedicated can long endure."
114
112
}; /* Information to write */
115
113
char *rdata[SPACE1_DIM1]; /* Information read in */
116
114
char *wdata2;
117
115
hid_t dataspace, dataset2;
118
-
hid_t fid1; /* HDF5 File IDs */
119
-
hid_t dataset; /* Dataset ID */
120
-
hid_t sid1; /* Dataspace ID */
121
-
hid_t tid1; /* Datatype ID */
116
+
hid_t fid1; /* HDF5 File IDs */
117
+
hid_t dataset; /* Dataset ID */
118
+
hid_t sid1; /* Dataspace ID */
119
+
hid_t tid1; /* Datatype ID */
122
120
hid_t xfer_pid; /* Dataset transfer property list ID */
123
-
hsize_t dims1[] = {SPACE1_DIM1};
121
+
hsize_t dims1[] = {SPACE1_DIM1};
124
122
hsize_t size; /* Number of bytes which will be used */
125
123
unsigned i; /* counting variable */
126
124
size_t str_used; /* String data in memory */
127
125
size_t mem_used=0; /* Memory used during allocation */
128
-
herr_t ret; /* Generic return value */
126
+
herr_t ret; /* Generic return value */
129
127
130
128
/* Output message about test being performed */
131
129
MESSAGE(5, ("Testing Basic VL String Functionality\n"));
132
130
133
131
/* Create file */
134
132
fid1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
135
133
CHECK(fid1, FAIL, "H5Fcreate");
136
134
137
135
/* Create dataspace for datasets */
138
136
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
174
172
175
173
ret=H5Pset_vlen_mem_manager(xfer_pid,test_vlstr_alloc_custom,&mem_used,test_vlstr_free_custom,&mem_used);
176
174
CHECK(ret, FAIL, "H5Pset_vlen_mem_manager");
177
175
178
176
/* Make certain the correct amount of memory will be used */
179
177
ret=H5Dvlen_get_buf_size(dataset,tid1,sid1,&size);
180
178
CHECK(ret, FAIL, "H5Dvlen_get_buf_size");
181
179
182
180
/* Count the actual number of bytes used by the strings */
183
181
for(i=0,str_used=0; i<SPACE1_DIM1; i++)
184
-
str_used+=HDstrlen(wdata[i])+1;
182
+
str_used += HDstrlen(wdata[i])+1;
185
183
186
184
/* Compare against the strings actually written */
187
185
VERIFY(size,(hsize_t)str_used,"H5Dvlen_get_buf_size");
188
186
189
187
/* Read dataset from disk */
190
188
ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, xfer_pid, rdata);
191
189
CHECK(ret, FAIL, "H5Dread");
192
190
193
191
/* Make certain the correct amount of memory has been used */
194
192
VERIFY(mem_used,str_used,"H5Dread");
195
193
196
194
/* Compare data read in */
197
195
for(i = 0; i < SPACE1_DIM1; i++) {
198
196
if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) {
199
-
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
197
+
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)HDstrlen(rdata[i]));
200
198
continue;
201
199
} /* end if */
202
200
if(HDstrcmp(wdata[i], rdata[i]) != 0 ) {
203
201
TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]);
204
202
continue;
205
203
} /* end if */
206
204
} /* end for */
207
205
208
206
/* Reclaim the read VL data */
209
207
ret = H5Dvlen_reclaim(tid1,sid1,xfer_pid,rdata);
240
238
** string cases, nil and zero-sized.
241
239
**
242
240
****************************************************************/
243
241
static void
244
242
test_vlstrings_special(void)
245
243
{
246
244
const char *wdata[SPACE1_DIM1] = {"", "two", "three", "\0"};
247
245
const char *wdata2[SPACE1_DIM1] = {NULL, NULL, NULL, NULL};
248
246
char *rdata[SPACE1_DIM1]; /* Information read in */
249
247
char *fill; /* Fill value */
250
-
hid_t fid1; /* HDF5 File IDs */
251
-
hid_t dataset; /* Dataset ID */
252
-
hid_t sid1; /* Dataspace ID */
253
-
hid_t tid1; /* Datatype ID */
254
-
hid_t dcpl; /* Dataset creation property list ID */
255
-
hsize_t dims1[] = {SPACE1_DIM1};
248
+
hid_t fid1; /* HDF5 File IDs */
249
+
hid_t dataset; /* Dataset ID */
250
+
hid_t sid1; /* Dataspace ID */
251
+
hid_t tid1; /* Datatype ID */
252
+
hid_t dcpl; /* Dataset creation property list ID */
253
+
hsize_t dims1[] = {SPACE1_DIM1};
256
254
unsigned i; /* counting variable */
257
-
herr_t ret; /* Generic return value */
255
+
herr_t ret; /* Generic return value */
258
256
259
257
/* Output message about test being performed */
260
258
MESSAGE(5, ("Testing Special VL Strings\n"));
261
259
262
260
/* Create file */
263
261
fid1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
264
262
CHECK(fid1, FAIL, "H5Fcreate");
265
263
266
264
/* Create dataspace for datasets */
267
265
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
291
289
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
292
290
CHECK(ret, FAIL, "H5Dwrite");
293
291
294
292
/* Read dataset from disk */
295
293
ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
296
294
CHECK(ret, FAIL, "H5Dread");
297
295
298
296
/* Compare data read in */
299
297
for(i = 0; i < SPACE1_DIM1; i++) {
300
298
if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) {
301
-
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
299
+
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)HDstrlen(rdata[i]));
302
300
continue;
303
301
} /* end if */
304
302
if((wdata[i] == NULL && rdata[i] != NULL) || (rdata[i] == NULL && wdata[i] != NULL)) {
305
303
TestErrPrintf("VL data values don't match!\n");
306
304
continue;
307
305
} /* end if */
308
306
if(HDstrcmp(wdata[i], rdata[i]) != 0 ) {
309
307
TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]);
310
308
continue;
311
309
} /* end if */
470
468
**
471
469
** test_compact_vlstring(): Test code for storing VL strings in
472
470
** compact datasets.
473
471
**
474
472
****************************************************************/
475
473
static void
476
474
test_compact_vlstring(void)
477
475
{
478
476
const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"};
479
477
char *rdata[SPACE1_DIM1]; /* Information read in */
480
-
hid_t fid1; /* HDF5 File IDs */
481
-
hid_t dataset; /* Dataset ID */
482
-
hid_t sid1; /* Dataspace ID */
483
-
hid_t tid1; /* Datatype ID */
484
-
hid_t plist; /* Dataset creation property list */
485
-
hsize_t dims1[] = {SPACE1_DIM1};
478
+
hid_t fid1; /* HDF5 File IDs */
479
+
hid_t dataset; /* Dataset ID */
480
+
hid_t sid1; /* Dataspace ID */
481
+
hid_t tid1; /* Datatype ID */
482
+
hid_t plist; /* Dataset creation property list */
483
+
hsize_t dims1[] = {SPACE1_DIM1};
486
484
unsigned i; /* counting variable */
487
-
herr_t ret; /* Generic return value */
485
+
herr_t ret; /* Generic return value */
488
486
489
487
/* Output message about test being performed */
490
488
MESSAGE(5, ("Testing VL Strings in compact dataset\n"));
491
489
492
490
/* Create file */
493
491
fid1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
494
492
CHECK(fid1, FAIL, "H5Fcreate");
495
493
496
494
/* Create dataspace for datasets */
497
495
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
518
516
ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
519
517
CHECK(ret, FAIL, "H5Dwrite");
520
518
521
519
/* Read dataset from disk */
522
520
ret = H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
523
521
CHECK(ret, FAIL, "H5Dread");
524
522
525
523
/* Compare data read in */
526
524
for(i = 0; i < SPACE1_DIM1; i++) {
527
525
if(HDstrlen(wdata[i]) != HDstrlen(rdata[i])) {
528
-
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
526
+
TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)HDstrlen(rdata[i]));
529
527
continue;
530
528
} /* end if */
531
529
if(HDstrcmp(wdata[i], rdata[i]) != 0) {
532
530
TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]);
533
531
continue;
534
532
} /* end if */
535
533
} /* end for */
536
534
537
535
/* Reclaim the read VL data */
538
536
ret = H5Dvlen_reclaim(tid1, sid1, H5P_DEFAULT, rdata);
753
751
754
752
ret = H5Dread(dset, type, space, space, H5P_DEFAULT, &data_read);
755
753
CHECK(ret, FAIL, "H5Dread");
756
754
757
755
ret = H5Dclose(dset);
758
756
CHECK(ret, FAIL, "H5Dclose");
759
757
760
758
if(HDstrcmp(data, data_read))
761
759
TestErrPrintf("Expected %s for dataset %s but read %s\n", data, name, data_read);
762
760
763
-
HDfree(data_read);
761
+
ret = H5Dvlen_reclaim(type, space, H5P_DEFAULT, &data_read);
762
+
CHECK(ret, FAIL, "H5Dvlen_reclaim");
764
763
}
765
764
766
765
/****************************************************************
767
766
**
768
767
** test_vl_rewrite(): Test basic VL string code.
769
768
** Tests I/O on VL strings when lots of objects in the file
770
769
** have been linked/unlinked.
771
770
**
772
771
****************************************************************/
773
772
static void test_vl_rewrite(void)
792
791
793
792
/* Open the files */
794
793
file1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
795
794
CHECK(file1, FAIL, "H5Fcreate");
796
795
797
796
file2 = H5Fcreate(DATAFILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
798
797
CHECK(file1, FAIL, "H5Fcreate");
799
798
800
799
/* Create in file 1 */
801
800
for(i=0; i<REWRITE_NDATASETS; i++) {
802
-
sprintf(name, "/set_%d", i);
801
+
HDsprintf(name, "/set_%d", i);
803
802
write_scalar_dset(file1, type, space, name, name);
804
803
}
805
804
806
805
/* Effectively copy data from file 1 to 2 */
807
806
for(i=0; i<REWRITE_NDATASETS; i++) {
808
-
sprintf(name, "/set_%d", i);
807
+
HDsprintf(name, "/set_%d", i);
809
808
read_scalar_dset(file1, type, space, name, name);
810
809
write_scalar_dset(file2, type, space, name, name);
811
810
}
812
811
813
812
/* Read back from file 2 */
814
813
for(i = 0; i < REWRITE_NDATASETS; i++) {
815
-
sprintf(name, "/set_%d", i);
814
+
HDsprintf(name, "/set_%d", i);
816
815
read_scalar_dset(file2, type, space, name, name);
817
816
} /* end for */
818
817
819
818
/* Remove from file 2. */
820
819
for(i = 0; i < REWRITE_NDATASETS; i++) {
821
-
sprintf(name, "/set_%d", i);
820
+
HDsprintf(name, "/set_%d", i);
822
821
ret = H5Ldelete(file2, name, H5P_DEFAULT);
823
822
CHECK(ret, FAIL, "H5Ldelete");
824
823
} /* end for */
825
824
826
825
/* Effectively copy from file 1 to file 2 */
827
826
for(i = 0; i < REWRITE_NDATASETS; i++) {
828
-
sprintf(name, "/set_%d", i);
827
+
HDsprintf(name, "/set_%d", i);
829
828
read_scalar_dset(file1, type, space, name, name);
830
829
write_scalar_dset(file2, type, space, name, name);
831
830
} /* end for */
832
831
833
832
/* Close everything */
834
833
ret = H5Tclose(type);
835
834
CHECK(ret, FAIL, "H5Tclose");
836
835
837
836
ret = H5Sclose(space);
838
837
CHECK(ret, FAIL, "H5Sclose");
865
864
test_compact_vlstring();
866
865
867
866
/* Test using VL strings in attributes */
868
867
test_write_vl_string_attribute();
869
868
test_read_vl_string_attribute();
870
869
871
870
/* Test writing VL datasets in files with lots of unlinking */
872
871
test_vl_rewrite();
873
872
} /* test_vlstrings() */
874
873
875
-
•
876
874
/*-------------------------------------------------------------------------
877
-
* Function: cleanup_vlstrings
875
+
* Function: cleanup_vlstrings
878
876
*
879
-
* Purpose: Cleanup temporary test files
877
+
* Purpose: Cleanup temporary test files
880
878
*
881
-
* Return: none
879
+
* Return: none
882
880
*
883
-
* Programmer: Quincey Koziol
881
+
* Programmer: Quincey Koziol
884
882
* September 10, 1999
885
883
*
886
884
* Modifications:
887
885
*
888
886
*-------------------------------------------------------------------------
889
887
*/
890
888
void
891
889
cleanup_vlstrings(void)
892
890
{
893
891
HDremove(DATAFILE);