1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF. The full HDF copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Tests for vgroup's and vdata's name and class name.
*/
#include "hdf.h"
#include "hfile_priv.h"
#include "tproto.h"
#include "tutils.h"
#define LONGNAMES "tlongnames.hdf"
#define NONAMECLASS "tundefined.hdf"
#define VGROUP1 "VGROUP1"
#define VG_LONGNAME "Vgroup with more than 64 characters in length, 74 characters to be exact!"
#define VG_LONGCLASS "Very long class name to classify all Vgroups with more than 64 characters in name"
static void test_vglongnames(void);
static void
test_vglongnames(void)
{
int32 file_id; /* File ID */
int32 vg1; /* Vdata ID */
int32 ref; /* Vdata ref */
uint16 name_len; /* Length of a vgroup's name or class name */
char *vgname, *vgclass;
intn is_internal;
int32 status; /* Status values from routines */
/* Open the HDF file. */
file_id = Hopen(LONGNAMES, DFACC_CREATE, 0);
CHECK_VOID(file_id, FAIL, "Hopen");
/* Initialize HDF for subsequent vgroup/vdata access. */
status = Vstart(file_id);
CHECK_VOID(status, FAIL, "Vstart");
/* Create a new vgroup. */
vg1 = Vattach(file_id, -1, "w");
CHECK_VOID(vg1, FAIL, "VSattach");
status = Vsetname(vg1, VG_LONGNAME);
CHECK_VOID(status, FAIL, "VSsetname");
status = Vsetclass(vg1, VG_LONGCLASS);
CHECK_VOID(status, FAIL, "VSsetname");
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
/* Create another vgroup of the same class. */
vg1 = Vattach(file_id, -1, "w");
CHECK_VOID(vg1, FAIL, "VSattach");
status = Vsetname(vg1, VGROUP1);
CHECK_VOID(status, FAIL, "VSsetname");
status = Vsetclass(vg1, VG_LONGCLASS);
CHECK_VOID(status, FAIL, "VSsetname");
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
status = Vend(file_id);
CHECK_VOID(status, FAIL, "Vend");
status = Hclose(file_id);
CHECK_VOID(status, FAIL, "Hclose");
/* Re-open the HDF file. */
file_id = Hopen(LONGNAMES, DFACC_RDWR, 0);
CHECK_VOID(file_id, FAIL, "Hopen");
/* Initialize HDF for subsequent vgroup/vdata access. */
status = Vstart(file_id);
CHECK_VOID(status, FAIL, "Vstart");
/* Find the long name vgroup. */
ref = Vfind(file_id, VG_LONGNAME);
CHECK_VOID(ref, FAIL, "VSfind");
vg1 = Vattach(file_id, ref, "r");
CHECK_VOID(vg1, FAIL, "VSattach");
/* Test Vgisinternal */
is_internal = Vgisinternal(vg1);
CHECK_VOID(is_internal, FAIL, "Vgisinternal");
VERIFY_VOID(is_internal, FALSE, "Vgisinternal");
/* get the vgroup's name */
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");
status = Vgetname(vg1, vgname);
CHECK_VOID(status, FAIL, "VSgetname");
VERIFY_CHAR_VOID(vgname, VG_LONGNAME, "Vgetname");
free(vgname);
/* get the vgroup's class */
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");
status = Vgetclass(vg1, vgclass);
CHECK_VOID(status, FAIL, "VSgetclass");
VERIFY_CHAR_VOID(vgclass, VG_LONGCLASS, "Vgetclass");
free(vgclass);
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
/* Find the vgroup VGROUP1. */
ref = Vfind(file_id, VGROUP1);
CHECK_VOID(ref, FAIL, "VSfind");
vg1 = Vattach(file_id, ref, "r");
CHECK_VOID(vg1, FAIL, "VSattach");
/* get the vgroup's name */
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");
status = Vgetname(vg1, vgname);
CHECK_VOID(status, FAIL, "VSgetname");
if (strcmp(vgname, VGROUP1)) {
num_errs++;
printf(">>> Got bogus Vgroup name : %s\n", vgname);
}
free(vgname);
/* get the vgroup's class */
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");
status = Vgetclass(vg1, vgclass);
CHECK_VOID(status, FAIL, "VSgetclass");
if (strcmp(vgclass, VG_LONGCLASS)) {
num_errs++;
printf(">>> Got bogus Vgroup class : %s\n", vgclass);
}
free(vgclass);
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
status = Vend(file_id);
CHECK_VOID(status, FAIL, "Vend");
status = Hclose(file_id);
CHECK_VOID(status, FAIL, "Hclose");
} /* test_vglongnames() */
static void
test_undefined(void)
{
int32 status; /* Status values from routines */
int32 file_id; /* File ID */
int32 vg1; /* Vdata ID */
int32 ref; /* Vdata ref */
intn is_internal; /* to test Vgisinternal */
uint16 name_len; /* Length of a vgroup's name or class name */
/* to simulate calls to Vgetclass/Vgetname in older applications */
char vgname[VGNAMELENMAX + 1], vgclass[VGNAMELENMAX + 1];
/* Open the HDF file. */
file_id = Hopen(NONAMECLASS, DFACC_CREATE, 0);
CHECK_VOID(file_id, FAIL, "Hopen");
/* Initialize HDF for subsequent vgroup/vdata access. */
status = Vstart(file_id);
CHECK_VOID(status, FAIL, "Vstart");
/* Create a vgroup which will have name set but not class */
vg1 = Vattach(file_id, -1, "w");
CHECK_VOID(vg1, FAIL, "VSattach");
status = Vsetname(vg1, VG_LONGNAME);
CHECK_VOID(status, FAIL, "VSsetname");
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
/* Create another vgroup which will have class but not name */
vg1 = Vattach(file_id, -1, "w");
CHECK_VOID(vg1, FAIL, "VSattach");
status = Vsetclass(vg1, VG_LONGCLASS);
CHECK_VOID(status, FAIL, "VSsetname");
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
status = Vend(file_id);
CHECK_VOID(status, FAIL, "Vend");
status = Hclose(file_id);
CHECK_VOID(status, FAIL, "Hclose");
/* Re-open the HDF file. */
file_id = Hopen(NONAMECLASS, DFACC_RDWR, 0);
CHECK_VOID(file_id, FAIL, "Hopen");
/* Initialize HDF for subsequent vgroup/vdata access. */
status = Vstart(file_id);
CHECK_VOID(status, FAIL, "Vstart");
/* Find the long name vgroup. */
ref = Vfind(file_id, VG_LONGNAME);
CHECK_VOID(ref, FAIL, "VSfind");
vg1 = Vattach(file_id, ref, "r");
CHECK_VOID(vg1, FAIL, "VSattach");
/* Test Vgisinternal */
is_internal = Vgisinternal(vg1);
CHECK_VOID(is_internal, FAIL, "Vgisinternal");
VERIFY_VOID(is_internal, FALSE, "Vgisinternal");
/* Try getting the vgroup's class without calling first Vgetclassnamelen.
This shows that bug HDFFR-1288 is fixed. */
status = Vgetclass(vg1, vgclass);
CHECK_VOID(status, FAIL, "Vgetclass");
VERIFY_VOID(strlen(vgclass), 0, "VSgetclass");
/* The length of the class name should be 0 */
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetclassnamelen");
VERIFY_VOID(name_len, 0, "VSgetclassnamelen");
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
/* Find the vgroup with class VG_LONGCLASS. This vgroup doesn't have a name */
ref = Vfindclass(file_id, VG_LONGCLASS);
CHECK_VOID(ref, FAIL, "VSfindclass");
vg1 = Vattach(file_id, ref, "r");
CHECK_VOID(vg1, FAIL, "VSattach");
/* Try getting the vgroup's name without calling first Vgetclassnamelen.
Similar to class name in bug HDFFR-1288. */
status = Vgetname(vg1, vgname);
CHECK_VOID(status, FAIL, "Vgetname");
VERIFY_VOID(strlen(vgname), 0, "VSgetname");
/* The length of the name should be 0 */
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");
VERIFY_VOID(name_len, 0, "VSgetnamelen");
status = Vdetach(vg1);
CHECK_VOID(status, FAIL, "Vdetach");
status = Vend(file_id);
CHECK_VOID(status, FAIL, "Vend");
status = Hclose(file_id);
CHECK_VOID(status, FAIL, "Hclose");
} /* test_undefined() */
/****************************************************************************
* test_vgisinternal - tests the API function Vgisinternal
* - Use an existing GR file created during the period when GR vgroup had no
* class name, and had name set to GR_NAME
* - Get each vgroup, verify that it is internal or not
* Jan 6, 2012 -BMR
****************************************************************************/
#define GR_FILE "test_files/grtdfui83.hdf"
static void
test_vgisinternal()
{
int32 fid, vgroup_id;
intn is_internal = FALSE;
int32 vref = -1;
intn ii, status;
const char *testfile = get_srcdir_filename(GR_FILE);
char internal_array2[2] = {TRUE, TRUE};
/* Use a GR file to test Vgisinternal on internal vgroups */
/* Open the old GR file and initialize the V interface */
fid = Hopen(testfile, DFACC_READ, 0);
CHECK_VOID(fid, FAIL, "Hopen: grtdfui83.hdf");
status = Vstart(fid);
CHECK_VOID(status, FAIL, "Vstart");
ii = 0;
while ((vref = Vgetid(fid, vref)) != FAIL) { /* until no more vgroups */
vgroup_id = Vattach(fid, vref, "r"); /* attach to vgroup */
/* Test that the current vgroup is or is not internal as specified
in the array internal_array2 */
is_internal = Vgisinternal(vgroup_id);
CHECK_VOID(is_internal, FAIL, "Vgisinternal");
VERIFY_VOID(is_internal, internal_array2[ii], "Vgisinternal");
status = Vdetach(vgroup_id);
CHECK_VOID(status, FAIL, "Vdetach");
ii++; /* increment vgroup index */
}
/* Terminate access to the V interface and close the file */
status = Vend(fid);
CHECK_VOID(status, FAIL, "Vend");
status = Hclose(fid);
CHECK_VOID(status, FAIL, "Hclose");
} /* test_vgisinternal */
void
test_vnameclass(void)
{
/* test Vgroups with name and class that have more than 64 characters */
test_vglongnames();
/* test Vgetname and Vgetclass when either name or class is not defined. */
test_undefined();
/* test Vgisinternal when there is no class name */
test_vgisinternal();
} /* test_vnameclass */
|