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 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636
|
/**********************************************************************
* *
* Unit tests for the HDF5 abstraction layer, to ensure it works as *
* documented and protect against regressions. *
* *
* J.Sloan *
* *
**********************************************************************
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* (the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *
* 02111-1307 USA *
* *
**********************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
* MA 02110-1301 USA *
* *
**********************************************************************
* *
* YOU MAY REDISTRIBUTE THE CBFLIB PACKAGE UNDER THE TERMS OF THE GPL *
* *
* ALTERNATIVELY YOU MAY REDISTRIBUTE THE CBFLIB API UNDER THE TERMS *
* OF THE LGPL *
* *
*********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "cbf.h"
#include "cbf_hdf5.h"
#include "unittest.h"
#ifndef UINT64_MAX
#define NO_UINT64_TYPE
#endif
/*
Call a function unconditionally with the expectation that it should work.
If it fails, print the location & error message, add the error to the pre-defined
'error' variable and increment the number of failures.
*/
#define CBF_CALL(func) \
do { \
const int err = (func); \
if (CBF_SUCCESS!=err) { \
error |= err; \
fprintf(stderr,"%s: Error: %s\n",__WHERE__,cbf_strerror(err)); \
} \
} while (0)
/*
NOTE: this only works with exactly representable 'sentinel' values, do not use with arbitrary numbers
*/
#ifdef CBF_USE_ULP
#define CBFM_cmp_dbl_exact(exp,ext,len,prm) cmp_dbl_exact(exp,ext,len,prm)
int cmp_dbl_exact(const void * expected, const void * existing, size_t length, const void * const params)
#else
#define CBFM_cmp_dbl_exact(exp,ext,len,prm) cmp_dbl_exact(exp,ext,len)
static int cmp_dbl_exact(const void * expected, const void * existing, size_t length)
#endif
{
const double * A = (const double*)expected;
const double * B = (const double*)existing;
while (length && *A++ == *B++) --length;
return length;
}
#ifdef CBF_USE_ULP
#define CBFM_cmp_int_exact(exp,ext,len,prm) cmp_int_exact(exp,ext,len,prm)
int cmp_int_exact(const void * expected, const void * existing, size_t length, const void * const params)
#else
#define CBFM_cmp_int_exact(exp,ext,len,prm) cmp_int_exact(exp,ext,len)
static int cmp_int_exact(const void * expected, const void * existing, size_t length)
#endif
{
const int * A = (const int*)expected;
const int * B = (const int*)existing;
while (length && *A++ == *B++) --length;
return length;
}
#ifdef CBF_USE_ULP
#define CBFM_cmp_hsize_t_exact(exp,ext,len,prm) cmp_hsize_t_exact(exp,ext,len,prm)
int cmp_hsize_t_exact(const void * expected, const void * existing, size_t length, const void * const params)
#else
#define CBFM_cmp_hsize_t_exact(exp,ext,len,prm) cmp_hsize_t_exact(exp,ext,len)
static int cmp_hsize_t_exact(const void * expected, const void * existing, size_t length)
#endif
{
const hsize_t * A = (const hsize_t*)expected;
const hsize_t * B = (const hsize_t*)existing;
while (length && *A++ == *B++) --length;
return length;
}
static testResult_t test_H5Acreate
(const hid_t obj,
hid_t * const attr,
const char * const name,
const hid_t type,
const hid_t space)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/* check parameters */
if (!cbf_H5Ivalid(obj)
|| !attr
|| !name
|| H5I_DATATYPE!=H5Iget_type(type)
|| !cbf_H5Ivalid(space))
error |= CBF_ARGUMENT;
/* check preconditions */
if (CBF_SUCCESS==error && !r.fail) {
/* no attribute should exist with the given name */
const htri_t exists = H5Aexists(obj,name);
if (exists<0) {
error |= CBF_H5ERROR;
} else if (exists) {
error |= CBF_UNDEFINED;
}
}
if (CBF_SUCCESS==error && !r.fail) {
/* verify expected failures */
if (!r.fail) {
hid_t attribute = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Acreate(CBF_H5FAIL, &attribute, name, type, space));
TEST_CBF_FAIL(cbf_H5Acreate(obj, 0, name, type, space));
TEST_CBF_FAIL(cbf_H5Acreate(obj, &attribute, 0, type, space));
TEST_CBF_FAIL(cbf_H5Acreate(obj, &attribute, name, CBF_H5FAIL, space));
TEST_CBF_FAIL(cbf_H5Acreate(obj, &attribute, name, type, CBF_H5FAIL));
/* check that attr is unchanged */
TEST(CBF_H5FAIL==attribute);
}
if (!r.fail) {
/* check I can create an attribute */
TEST_CBF_PASS(cbf_H5Acreate(obj, attr, name, type, space));
TEST(cbf_H5Ivalid(*attr));
}
if (!r.fail) {
/* check I can't create the same attribute and that the argument is unchanged */
hid_t attribute = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Acreate(obj, &attribute, name, type, space));
TEST(CBF_H5FAIL==attribute);
}
} else {
fprintf(stderr,"%s: Skipping attribute/create tests\n",__WHERE__);
++r.skip;
}
return r;
}
static testResult_t test_H5Afree
(const hid_t attr)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/* preconditions/check arguments */
if (!cbf_H5Ivalid(attr)) error |= CBF_ARGUMENT;
if (CBF_SUCCESS==error && !r.fail) {
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Afree(CBF_H5FAIL));
/* check the attribute can be free'd */
TEST_CBF_PASS(cbf_H5Afree(attr));
/* check the attribute can't be free'd again */
TEST_CBF_FAIL(cbf_H5Afree(attr));
} else {
fprintf(stderr,"%s: Skipping attribute/free tests\n",__WHERE__);
++r.skip;
}
return r;
}
static testResult_t test_H5Afind
(const hid_t obj,
const char * const validAttr,
const char * const invalidAttr,
const hid_t type,
const hid_t wrongType,
const hid_t space)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/* check parameters */
if (!cbf_H5Ivalid(obj)
|| !validAttr
|| !invalidAttr
|| H5I_DATATYPE!=H5Iget_type(type)
|| H5I_DATATYPE!=H5Iget_type(wrongType)
|| !cbf_H5Ivalid(space))
error |= CBF_ARGUMENT;
/* check preconditions */
if (CBF_SUCCESS==error && !r.fail) {
const htri_t exists_valid = H5Aexists(obj,validAttr);
const htri_t exists_invalid = H5Aexists(obj,invalidAttr);
/* the 'valid' attribute should exist */
if (exists_valid<0) error |= CBF_H5ERROR;
else if (!exists_valid) error |= CBF_UNDEFINED;
/* the 'invalid' attribute shouldn't exist */
if (exists_invalid<0) error |= CBF_H5ERROR;
else if (exists_invalid) error |= CBF_UNDEFINED;
}
if (CBF_SUCCESS==error && !r.fail) {
/* verify expected failures */
if (!r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Afind(CBF_H5FAIL, &attr, validAttr, type, space));
TEST_CBF_FAIL(cbf_H5Afind(obj, 0, validAttr, type, space));
TEST_CBF_FAIL(cbf_H5Afind(obj, &attr, 0, type, space));
/* check that attr is unchanged */
TEST(CBF_H5FAIL==attr);
}
/* test failure to find a non-existant attribute */
if (!r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_CBF_NOTFOUND(cbf_H5Afind(obj, &attr, invalidAttr, type, space));
/* check that attr is unchanged */
TEST(CBF_H5FAIL==attr);
}
/* test failure to find an existing attribute with a different type */
if (!r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Afind(obj, &attr, validAttr, wrongType, space));
/* check that attr is unchanged */
TEST(CBF_H5FAIL==attr);
}
/* TODO: tests for different dataspaces */
/* test successfully finding an attribute that does exist & has known type */
if (!r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Afind(obj, &attr, validAttr, type, space));
/* check that attr is valid */
TEST(cbf_H5Ivalid(attr));
/* clean up */
cbf_H5Afree(attr);
}
/* test successfully finding an attribute that does exist but has unknown type */
if (!r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Afind(obj, &attr, validAttr, CBF_H5FAIL, space));
/* check that attr is valid */
TEST(cbf_H5Ivalid(attr));
/* clean up */
cbf_H5Afree(attr);
}
/* test successfully finding an attribute that does exist but has unknown space */
if (!r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Afind(obj, &attr, validAttr, type, CBF_H5FAIL));
/* check that attr is valid */
TEST(cbf_H5Ivalid(attr));
/* clean up */
cbf_H5Afree(attr);
}
} else {
fprintf(stderr,"%s: Skipping attribute/find tests\n",__WHERE__);
++r.skip;
}
return r;
}
static testResult_t _test_H5Arequire_cmp
(const hid_t obj,
const char * const attrName,
const int rank,
const hsize_t * const dim,
const hsize_t * const dim_h,
const hsize_t * const dim_l,
const hid_t ftype,
const hid_t ftype_b,
const hid_t mtype,
const void * const attrValue,
const void * const attrValue_b,
void * const buf,
int cmp(const void *, const void *, size_t
#ifdef CBF_USE_ULP
, const void * const
#endif
),const void * const cmp_params)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
CBF_UNUSED( cmp_params );
if (rank<0) {
fprintf(stderr,"%s: Error: test function called incorrectly\n",__WHERE__);
++r.fail;
return r;
}
/* test creation of the attributes */
TEST_CBF_PASS(CBFM_H5Arequire_cmp2(obj,attrName,rank,dim,ftype,mtype,attrValue,buf,cmp,cmp_params));
{ /* check that it actually exists */
hid_t attr = CBF_H5FAIL;
TEST(H5Aexists(obj,attrName)>0);
attr = H5Aopen(obj,attrName,H5P_DEFAULT);
TEST(cbf_H5Ivalid(attr));
{ /* verify type */
const hid_t type = H5Aget_type(attr);
TEST(H5Tequal(type,ftype)>0);
H5Tclose(type);
}
{ /* verify dataspace */
const hid_t expected = rank>0 ? H5Screate_simple(rank,dim,dim) : H5Screate(H5S_SCALAR);
const hid_t existing = H5Aget_space(attr);
TEST(H5Sextent_equal(expected,existing)>0);
H5Sclose(existing);
H5Sclose(expected);
}
H5Aclose(attr);
}
/* test verification of existing attributes */
TEST_CBF_PASS(CBFM_H5Arequire_cmp2(obj,attrName,rank,dim,ftype,mtype,attrValue,buf,cmp,cmp_params));
if (rank>0) { /* test failure to verify differing attribute sizes */
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,rank,dim_h,ftype,mtype,attrValue,buf,cmp,cmp_params));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,rank,dim_l,ftype,mtype,attrValue,buf,cmp,cmp_params));
}
/* test failure to verify differing attribute types */
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,rank,dim,ftype_b,mtype,attrValue,buf,cmp,cmp_params));
/* test failure to verify differing rank */
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,rank+1,dim,ftype,mtype,attrValue,buf,cmp,cmp_params));
/* test failure to verify differing attribute values */
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,rank,dim,ftype,mtype,attrValue_b,buf,cmp,cmp_params));
return r;
}
static testResult_t test_H5Arequire_cmp(const hid_t obj)
{
testResult_t r = {0,0,0};
/*
Test the attribute API on hdf5 object 'obj'.
*/
{ /* verify expected failures */
const char attrName[] = "fail";
int attrValue[] = {0,1,2,3};
int buf[4];
const hsize_t dim[] = {4};
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(CBF_H5FAIL,attrName,1,dim,H5T_STD_I32LE,H5T_NATIVE_INT,attrValue,buf,cmp_int_exact,0));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,0,1,dim,H5T_STD_I32LE,H5T_NATIVE_INT,attrValue,buf,cmp_int_exact,0));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,-1,dim,H5T_STD_I32LE,H5T_NATIVE_INT,attrValue,buf,cmp_int_exact,0));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,1,0,H5T_STD_I32LE,H5T_NATIVE_INT,attrValue,buf,cmp_int_exact,0));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,1,dim,CBF_H5FAIL,H5T_NATIVE_INT,attrValue,buf,cmp_int_exact,0));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,1,dim,H5T_STD_I32LE,CBF_H5FAIL,attrValue,buf,cmp_int_exact,0));
TEST_CBF_FAIL(CBFM_H5Arequire_cmp2(obj,attrName,1,dim,H5T_STD_I32LE,H5T_NATIVE_INT,0,buf,cmp_int_exact,0));
}
{ /* rank 0 */
int attrValue[] = {42};
int attrValue_b[] = {43};
int buf[1];
TEST_COMPONENT(_test_H5Arequire_cmp(obj,"i0",0,0,0,0,H5T_STD_I32LE,H5T_IEEE_F64BE,H5T_NATIVE_INT,attrValue,attrValue_b,0,cmp_int_exact,0));
TEST_COMPONENT(_test_H5Arequire_cmp(obj,"i0_b",0,0,0,0,H5T_STD_I32LE,H5T_IEEE_F64BE,H5T_NATIVE_INT,attrValue,attrValue_b,buf,cmp_int_exact,0));
}
{ /* rank 1 */
const hsize_t dim_l[] = {3};
const hsize_t dim[] = {4};
const hsize_t dim_h[] = {5};
int attrValue[] = {0,1,2,3};
int attrValue_b[] = {0,1,2,4};
int buf[4];
TEST_COMPONENT(_test_H5Arequire_cmp(obj,"i1",1,dim,dim_h,dim_l,H5T_STD_I32LE,H5T_IEEE_F64BE,H5T_NATIVE_INT,attrValue,attrValue_b,0,cmp_int_exact,0));
TEST_COMPONENT(_test_H5Arequire_cmp(obj,"i1_b",1,dim,dim_h,dim_l,H5T_STD_I32LE,H5T_IEEE_F64BE,H5T_NATIVE_INT,attrValue,attrValue_b,buf,cmp_int_exact,0));
}
{ /* rank 2 */
const hsize_t dim_l[] = {3,3};
const hsize_t dim[] = {3,4};
const hsize_t dim_h[] = {3,5};
int attrValue[][4] = {
{0,1,2,3},
{4,5,6,7},
{8,9,10,11}
};
int attrValue_b[][4] = {
{0,1,2,3},
{4,5,6,7},
{8,9,10,12}
};
int buf[12];
TEST_COMPONENT(_test_H5Arequire_cmp(obj,"i2",2,dim,dim_h,dim_l,H5T_STD_I32LE,H5T_IEEE_F64BE,H5T_NATIVE_INT,attrValue,attrValue_b,0,cmp_int_exact,0));
TEST_COMPONENT(_test_H5Arequire_cmp(obj,"i2_b",2,dim,dim_h,dim_l,H5T_STD_I32LE,H5T_IEEE_F64BE,H5T_NATIVE_INT,attrValue,attrValue_b,buf,cmp_int_exact,0));
}
return r;
}
static testResult_t test_H5Arequire_string(const hid_t obj)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/*
Test the attribute API on hdf5 object 'obj'.
*/
const char attrName[] = "attr_r0_str";
const char attrValue[] = "value";
const char attrValue_b[] = "Value";
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Arequire_string(CBF_H5FAIL,attrName,attrValue));
TEST_CBF_FAIL(cbf_H5Arequire_string(obj,0,attrValue));
TEST_CBF_FAIL(cbf_H5Arequire_string(obj,attrName,0));
/* test creation of the attributes */
TEST_CBF_PASS(cbf_H5Arequire_string(obj,attrName,attrValue));
{/* independently verify existance */
hid_t attr = CBF_H5FAIL;
TEST(H5Aexists(obj,attrName)>0);
attr = H5Aopen(obj,attrName,H5P_DEFAULT);
{ /* verify dataspace */
const hid_t expected = H5Screate(H5S_SCALAR);
const hid_t existing = H5Aget_space(attr);
TEST(H5Sextent_equal(expected,existing)>0);
H5Sclose(existing);
H5Sclose(expected);
}
{ /* verify type */
const hid_t type = H5Aget_type(attr);
TEST(H5T_STRING == H5Tget_class(type));
H5Tclose(type);
}
H5Aclose(attr);
}
/* test verification of existing attributes */
TEST_CBF_PASS(cbf_H5Arequire_string(obj,attrName,attrValue));
/* test failure to verify differing attribute values */
TEST_CBF_FAIL(cbf_H5Arequire_string(obj,attrName,attrValue_b));
return r;
}
static testResult_t test_attribute
(const hid_t obj)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/* preconditions/check arguments */
if (!cbf_H5Ivalid(obj)) error |= CBF_ARGUMENT;
if (CBF_SUCCESS==error && !r.fail) {
const char validName[] = "attr";
const char invalidName[] = "attr_invalid";
const hid_t space = H5Screate(H5S_SCALAR);
if (space < 0) error |= CBF_H5ERROR;
/* test create & free functions together */
if (CBF_SUCCESS==error && !r.fail) {
hid_t attr = CBF_H5FAIL;
TEST_COMPONENT(test_H5Acreate(obj, &attr, validName, H5T_STD_I32LE, space));
TEST_COMPONENT(test_H5Afree(attr));
}
/* test some other functions */
TEST_COMPONENT(test_H5Afind(obj, validName, invalidName, H5T_STD_I32LE, H5T_STD_U64BE, space));
TEST_COMPONENT(test_H5Arequire_cmp(obj));
TEST_COMPONENT(test_H5Arequire_string(obj));
H5Sclose(space);
} else {
fprintf(stderr,"%s: Skipping attribute tests\n",__WHERE__);
++r.skip;
}
return r;
}
static testResult_t testDatasetFind(const hid_t grp, hsize_t * const buf)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/*
Test the dataset find function on hdf5 group 'grp', with or without a buffer being set.
*/
const int rank = 2;
const hsize_t dim[] = {0,0};
const hsize_t max[] = {H5S_UNLIMITED,16};
const hsize_t chunk[] = {1,16};
const char name00[] = "dataset_find_nobuf";
const char name01[] = "dataset_find_buf";
const char name10[] = "Dataset_find_nobuf";
const char name11[] = "Dataset_find_buf";
const char * const name1 = 0==buf ? name00 : name01;
const char * const name2 = 0==buf ? name10 : name11;
hid_t validHandle = CBF_H5FAIL;
TEST(H5I_GROUP==H5Iget_type(grp));
/* ensure a suitable test environment exists */
if (CBF_SUCCESS==error) {
if (0!=H5Lexists(grp,name1,H5P_DEFAULT)) error |= CBF_H5ERROR;
CBF_CALL(cbf_H5Dcreate(grp,&validHandle,name1,rank,dim,max,chunk,H5T_NATIVE_INT));
if (!cbf_H5Ivalid(validHandle)) error |= CBF_H5ERROR;
}
/* do the tests? */
if (CBF_SUCCESS==error && !r.fail) {
/* verify expected failures */
hid_t handle = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Dfind2(0,&handle,name1,rank,max,buf,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dfind2(grp,0,name1,rank,max,buf,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dfind2(grp,&handle,0,rank,max,buf,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dfind2(grp,&handle,name1,-1,max,buf,H5T_NATIVE_INT));
{ /* check it can find a match */
hid_t handle = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Dfind2(grp,&handle,name1,rank,max,buf,H5T_NATIVE_INT));
TEST(cbf_H5Ivalid(handle));
cbf_H5Dfree(handle);
}
{ /* check case where match not found (by name), but dataset can be created */
hid_t handle = CBF_H5FAIL;
const hid_t tmpHandle = handle;
TEST_CBF_NOTFOUND(cbf_H5Dfind2(grp,&handle,name2,rank,max,buf,H5T_NATIVE_INT));
TEST(!cbf_H5Ivalid(handle));
TEST(tmpHandle==handle);
cbf_H5Dfree(handle);
}
{ /* test failure when type differs */
hid_t handle = CBF_H5FAIL;
const hid_t tmpHandle = handle;
TEST_CBF_FAIL(cbf_H5Dfind2(grp,&handle,name1,rank,max,buf,H5T_NATIVE_FLOAT));
TEST(!cbf_H5Ivalid(handle));
TEST(tmpHandle==handle);
cbf_H5Dfree(handle);
}
{ /* test no failure when no type given */
hid_t handle = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Dfind2(grp,&handle,name1,rank,max,buf,CBF_H5FAIL));
TEST(cbf_H5Ivalid(handle));
cbf_H5Dfree(handle);
}
{ /* test failure when rank differs */
hid_t handle = CBF_H5FAIL;
const hid_t tmpHandle = handle;
/*
NOTE: max & buf lengths are not (and can't be) tested, just assumed to contain 'rank' elements if used.
Therefore, don't do this test with a higher rank than the number of elements in either of those arrays.
*/
TEST_CBF_FAIL(cbf_H5Dfind2(grp,&handle,name1,rank-1,max,buf,H5T_NATIVE_INT));
TEST(!cbf_H5Ivalid(handle));
TEST(tmpHandle==handle);
cbf_H5Dfree(handle);
}
{ /* test no failure when current max is bigger */
hid_t handle = CBF_H5FAIL;
const hsize_t max2[] = {H5S_UNLIMITED,8};
TEST_CBF_PASS(cbf_H5Dfind2(grp,&handle,name1,rank,max2,buf,H5T_NATIVE_INT));
TEST(cbf_H5Ivalid(handle));
cbf_H5Dfree(handle);
}
{ /* test failure when current max is smaller */
hid_t handle = CBF_H5FAIL;
const hid_t tmpHandle = handle;
const hsize_t max2[] = {H5S_UNLIMITED,32};
TEST_CBF_FAIL(cbf_H5Dfind2(grp,&handle,name1,rank,max2,buf,H5T_NATIVE_INT));
TEST(!cbf_H5Ivalid(handle));
TEST(tmpHandle==handle);
cbf_H5Dfree(handle);
}
} else {
fprintf(stderr,"Failed to set up dataset/find tests\n");
++r.skip;
}
cbf_H5Dfree(validHandle);
return r;
}
static testResult_t test_H5Dcreate(const hid_t grp, hid_t * const dset, const char * name)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
const int rank = 2;
const hsize_t dim[] = {0,0};
const hsize_t max[] = {H5S_UNLIMITED,16};
const hsize_t chunk[] = {1,16};
TEST(H5I_GROUP==H5Iget_type(grp));
/* Ensure it fails at the appropriate times */
TEST_CBF_FAIL(cbf_H5Dcreate(CBF_H5FAIL,dset,name,rank,dim,max,chunk,H5T_NATIVE_INT));
TEST_CBF_PASS(cbf_H5Dcreate(grp,dset,0,rank,dim,max,chunk,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dcreate(grp,dset,name,-1,dim,max,chunk,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dcreate(grp,dset,name,rank,0,max,chunk,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dcreate(grp,dset,name,rank,dim,max,0,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dcreate(grp,dset,name,rank,dim,max,chunk,CBF_H5FAIL));
{ /* pre-conditions: no dataset */
TEST(!cbf_H5Ivalid(*dset));
TEST(0==H5Lexists(grp,name,H5P_DEFAULT));
}
{ /* creation should work */
TEST_CBF_PASS(cbf_H5Dcreate(grp,dset,name,rank,dim,max,chunk,H5T_NATIVE_INT));
}
{ /* post-conditions from previous block, pre-conditions for next block */
hid_t dsetObj = CBF_H5FAIL;
TEST(cbf_H5Ivalid(*dset));
TEST(H5I_DATASET==H5Iget_type(*dset));
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(dsetObj=H5Oopen(grp,name,H5P_DEFAULT)));
TEST(!cbf_H5Ocmp(*dset,dsetObj));
H5Oclose(dsetObj);
}
{ /* dataset exists: ensure 'create' fails, verify the handle is valid, unmodified & the dataset (link, at least) remains */
const hid_t tmpHandle = *dset;
TEST_CBF_FAIL(cbf_H5Dcreate(grp,dset,name,rank,dim,max,chunk,H5T_NATIVE_INT));
TEST(tmpHandle == *dset);
}
{ /* post-conditions from previous block */
hid_t dsetObj = CBF_H5FAIL;
TEST(cbf_H5Ivalid(*dset));
TEST(H5I_DATASET==H5Iget_type(*dset));
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(dsetObj=H5Oopen(grp,name,H5P_DEFAULT)));
TEST(!cbf_H5Ocmp(*dset,dsetObj));
H5Oclose(dsetObj);
}
return r;
}
static testResult_t test_H5Dfree(const hid_t grp, const hid_t dset, const char * name)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
TEST(H5I_GROUP==H5Iget_type(grp));
TEST(H5I_DATASET==H5Iget_type(dset));
{ /* pre-conditions */
hid_t dsetObj = CBF_H5FAIL;
TEST(cbf_H5Ivalid(dset));
TEST(H5I_DATASET==H5Iget_type(dset));
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(dsetObj=H5Oopen(grp,name,H5P_DEFAULT)));
TEST(!cbf_H5Ocmp(dset,dsetObj));
H5Oclose(dsetObj);
}
/* free'ing an invalid handle should fail */
TEST_CBF_FAIL(cbf_H5Dfree(CBF_H5FAIL));
/* Freeing an existing handle should work */
TEST_CBF_PASS(cbf_H5Dfree(dset));
{ /* post-conditions */
const hid_t tmpHandle = dset;
TEST(!cbf_H5Ivalid(dset));
TEST(tmpHandle == dset);
/* the data must remain in the tree */
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
}
/* Freeing a previously free'd handle should fail */
TEST_CBF_FAIL(cbf_H5Dfree(dset));
return r;
}
static testResult_t test_H5Drequire_flstring(const hid_t grp)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
const char name[] = "dataset_require_string";
const char value[] = " value...\n\twith leading/trailing spaces & a newline ";
const char value_b[] = " Value...\n\twith leading/trailing spaces & a newline ";
hid_t handle = CBF_H5FAIL;
TEST(H5I_GROUP==H5Iget_type(grp));
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Drequire_flstring(CBF_H5FAIL,&handle,name,value));
TEST_CBF_FAIL(cbf_H5Drequire_flstring(grp,&handle,0,value));
TEST_CBF_FAIL(cbf_H5Drequire_flstring(grp,&handle,name,0));
/* test creation of the dataset */
TEST_CBF_PASS(cbf_H5Drequire_flstring(grp,&handle,name,value));
{/* independently verify existance */
hid_t dset = CBF_H5FAIL;
/* verify existence of link */
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
/* open it and verify object type & data type */
TEST(cbf_H5Ivalid(dset = H5Oopen(grp,name,H5P_DEFAULT)));
/* check object type */
TEST(H5I_DATASET==H5Iget_type(dset));
{ /* verify dataspace */
hid_t expected = H5Screate(H5S_SCALAR);
const hid_t existing = H5Dget_space(dset);
TEST(H5Sextent_equal(expected,existing)>0);
H5Sclose(existing);
H5Sclose(expected);
}
{ /* verify type class */
const hid_t type = H5Dget_type(dset);
TEST(H5T_STRING == H5Tget_class(type));
TEST(0==H5Tis_variable_str(type));
H5Tclose(type);
}
/* close the object */
H5Oclose(dset);
}
cbf_H5Dfree(handle);
/* test verification of existing datasets */
TEST_CBF_PASS(cbf_H5Drequire_flstring(grp,&handle,name,value));
/* test failure to verify a different dataset */
TEST_CBF_FAIL(cbf_H5Drequire_flstring(grp,&handle,name,value_b));
cbf_H5Dfree(handle);
return r;
}
static testResult_t test_H5Drequire_F64LE(const hid_t grp)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
const char name[] = "dataset_require_F64LE";
hid_t handle = CBF_H5FAIL;
/* exactly representable 'sentinel' values, to avoid approximation/rounding errors & allow exact comparisons */
const double value = 42.;
const double value_b = 1.;
TEST(H5I_GROUP==H5Iget_type(grp));
/* verify expected failures */
TEST_CBF_FAIL(CBFM_H5Drequire_scalar_F64LE2(CBF_H5FAIL,&handle,name,value,cmp_dbl_exact,0));
TEST_CBF_FAIL(CBFM_H5Drequire_scalar_F64LE2(grp,&handle,0,value,cmp_dbl_exact,0));
/* test creation of the dataset */
TEST_CBF_PASS(CBFM_H5Drequire_scalar_F64LE2(grp,&handle,name,value,cmp_dbl_exact,0));
{/* independently verify existance */
hid_t dset = CBF_H5FAIL;
/* verify existence of link */
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
/* open it and verify object type & data type */
TEST(cbf_H5Ivalid(dset = H5Oopen(grp,name,H5P_DEFAULT)));
/* check object type */
TEST(H5I_DATASET==H5Iget_type(dset));
{ /* verify dataspace */
hid_t expected = H5Screate(H5S_SCALAR);
const hid_t existing = H5Dget_space(dset);
TEST(H5Sextent_equal(expected,existing)>0);
H5Sclose(existing);
H5Sclose(expected);
}
{ /* verify type class */
const hid_t type = H5Dget_type(dset);
TEST(H5T_FLOAT == H5Tget_class(type));
H5Tclose(type);
}
/* close the object */
H5Oclose(dset);
}
cbf_H5Dfree(handle);
/* test verification of existing datasets */
TEST_CBF_PASS(CBFM_H5Drequire_scalar_F64LE2(grp,&handle,name,value,cmp_dbl_exact,0));
/* test failure to verify a different dataset */
TEST_CBF_FAIL(CBFM_H5Drequire_scalar_F64LE2(grp,&handle,name,value_b,cmp_dbl_exact,0));
cbf_H5Dfree(handle);
return r;
}
static testResult_t test_H5Dset_extent(const hid_t grp)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
const int rank = 2;
const hsize_t dim[] = {0,0};
const hsize_t dim2[] = {2,16};
const hsize_t max[] = {H5S_UNLIMITED,16};
const hsize_t chunk[] = {1,16};
const char name[] = "dataset_set_extent";
hid_t handle = CBF_H5FAIL;
TEST(H5I_GROUP==H5Iget_type(grp));
/* ensure a suitable test environment exists */
if (0!=H5Lexists(grp,name,H5P_DEFAULT)) error |= CBF_H5ERROR;
CBF_CALL(cbf_H5Dcreate(grp,&handle,name, rank,dim,max, chunk, H5T_NATIVE_INT));
if (!cbf_H5Ivalid(handle)) error |= CBF_H5ERROR;
if (CBF_SUCCESS==error && !r.fail) {
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Dset_extent(CBF_H5FAIL,dim2));
TEST_CBF_FAIL(cbf_H5Dset_extent(handle,0));
{ /* check current extent */
const hid_t dataspace = H5Dget_space(handle);
hsize_t currDims[] = {-1,-1};
hsize_t currMax[] = {0,0};
TEST(rank==H5Sget_simple_extent_dims(dataspace,0,0));
TEST(rank==H5Sget_simple_extent_dims(dataspace,currDims,currMax));
H5Sclose(dataspace);
TEST(dim[0]==currDims[0]);
TEST(dim[1]==currDims[1]);
TEST(max[0]==currMax[0]);
TEST(max[1]==currMax[1]);
}
/* change the extent */
TEST_CBF_PASS(cbf_H5Dset_extent(handle,dim2));
{ /* verify the new extent */
const hid_t dataspace = H5Dget_space(handle);
hsize_t currDims[] = {-1,-1};
hsize_t currMax[] = {0,0};
TEST(rank==H5Sget_simple_extent_dims(dataspace,0,0));
TEST(rank==H5Sget_simple_extent_dims(dataspace,currDims,currMax));
H5Sclose(dataspace);
TEST(dim2[0]==currDims[0]);
TEST(dim2[1]==currDims[1]);
TEST(max[0]==currMax[0]);
TEST(max[1]==currMax[1]);
}
} else {
++r.skip;
fprintf(stderr,"%s: Failed to set up dataset/set_extent tests\n",__WHERE__);
}
if (CBF_SUCCESS!=error)
fprintf(stderr,"%s: Error: %s\n",__WHERE__,cbf_strerror(error));
cbf_H5Dfree(handle);
return r;
}
static void fill_array(int * array, size_t length, const int fill)
{
while (length) {
--length;
*array++ = fill;
}
}
static testResult_t testDataset_read_write(const hid_t grp)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
const char name0[] = "dataset_read_write_rank0";
const char name2[] = "dataset_read_write_rank2";
hid_t handle0 = CBF_H5FAIL;
hid_t handle2 = CBF_H5FAIL;
const int N = 8;
const int N2 = N*2;
int dataWrite0[] = {42};
int dataRead0[] = {0};
int dataWrite2[N2];
int dataRead2[N2];
const int rank = 2;
const hsize_t offset[] = {0,0};
const hsize_t offset_1[] = {1,0};
const hsize_t stride[] = {1,1};
const hsize_t stride_2[] = {1,2};
const hsize_t count[] = {1,N2};
const hsize_t count_2[] = {1,N};
const hsize_t dim[] = {2,N2};
const hsize_t max[] = {H5S_UNLIMITED,N2};
const hsize_t chunk[] = {1,N2};
TEST(H5I_GROUP==H5Iget_type(grp));
{/* populate the data */
int i;
for (i = 0; i < N2; ++i) dataWrite2[i] = i*i;
}
/* ensure a suitable test environment exists */
CBF_CALL(cbf_H5Dcreate(grp,&handle0,name0, 0,0,0, 0, H5T_NATIVE_INT));
if (!cbf_H5Ivalid(handle0)) error |= CBF_H5ERROR;
CBF_CALL(cbf_H5Dcreate(grp,&handle2,name2, rank,dim,max, chunk, H5T_NATIVE_INT));
if (!cbf_H5Ivalid(handle2)) error |= CBF_H5ERROR;
if (CBF_SUCCESS==error && !r.fail) {
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Dwrite2(CBF_H5FAIL,offset,stride,count,dataWrite2,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dwrite2(handle2,0,stride,count,dataWrite2,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dwrite2(handle2,offset,stride,0,dataWrite2,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dwrite2(handle2,offset,stride,count,0,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dwrite2(handle2,offset,stride,count,dataWrite2,CBF_H5FAIL));
{ /* rank 0 */
/* check read/write with null pointers */
TEST_CBF_PASS(cbf_H5Dwrite2(handle0,0,0,0,dataWrite0,H5T_NATIVE_INT));
TEST_CBF_PASS(cbf_H5Dread2(handle0,0,0,0,dataRead0,H5T_NATIVE_INT));
TEST(*dataWrite0 == *dataRead0);
}
/* rank 2: need to check independent changes to offset/stride/count, and allow for null stride */
{ /* Using default ({1,1,...,1}) strides, 4 permutations of (read,write)^(NULL,{1,1,...,1}) */
/* verify writing with {1,1,...,1} stride */
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset,stride,count,dataWrite2,H5T_NATIVE_INT));
/* check I can read the data with the default stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,stride,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N2,0));
/* check I can read the data with the (equivalent) null stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,0,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N2,0));
/* verify writing with null stride */
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset,0,count,dataWrite2,H5T_NATIVE_INT));
/* check I can read the data with the (equivalent) default stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,stride,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N2,0));
/* check I can read the data with the null stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,0,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N2,0));
}
{ /* verify writing with an offset */
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset_1,stride,count,dataWrite2,H5T_NATIVE_INT));
/* check I can read the data with the default stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset_1,stride,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N2,0));
/* check I can read the data with the (equivalent) null stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset_1,0,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N2,0));
}
{ /* verify writing with a non-trivial stride, which uses but doesn't verify that a different count works */
{ /* first set a reasonable 'background' value - later tests will ensure it worked */
int background[16];
fill_array(background,N2,-1);
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset,0,count,background,H5T_NATIVE_INT));
}
/* change settings & do the real write */
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset,stride_2,count_2,dataWrite2,H5T_NATIVE_INT));
/* check I can read the data with the same stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,stride_2,count_2,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(dataWrite2,dataRead2,N,0));
{ /* check the data was embedded correctly */
const int result[16] = {
0,-1,1,-1,4,-1,9,-1,16,-1,25,-1,36,-1,49,-1
};
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,stride,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(result,dataRead2,N2,0));
}
}
{ /* verify writing with a different count */
{ /* first set a reasonable 'background' value - later tests will ensure it worked */
int background[16];
fill_array(background,N2,-2);
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset,0,count,background,H5T_NATIVE_INT));
}
/* do the real write */
TEST_CBF_PASS(cbf_H5Dwrite2(handle2,offset,stride,count_2,dataWrite2,H5T_NATIVE_INT));
{ /* check the results... */
const int result[16] = {
0,1,4,9,16,25,36,49,-2,-2,-2,-2,-2,-2,-2,-2
};
/* ...with the default - null - stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,0,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(result,dataRead2,N2,0));
/* ...with the equivalent - non-null - stride */
fill_array(dataRead2,N2,-1);
TEST_CBF_PASS(cbf_H5Dread2(handle2,offset,stride,count,dataRead2,H5T_NATIVE_INT));
TEST(!CBFM_cmp_int_exact(result,dataRead2,N2,0));
}
}
} else {
++r.skip;
fprintf(stderr,"%s: Failed to set up dataset/read-write tests\n",__WHERE__);
}
if (CBF_SUCCESS!=error)
fprintf(stderr,"%s: Error: %s\n",__WHERE__,cbf_strerror(error));
/* free the handle after using it */
cbf_H5Dfree(handle0);
cbf_H5Dfree(handle2);
return r;
}
/* wrapper for common tests, expected failures checked in calling function */
static testResult_t test_H5Drequire
(const hid_t grp,
const char * const name,
const int rank,
const hsize_t * const max,
const hsize_t * const cnk,
hsize_t * const buf,
const hid_t type)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
hid_t dset = CBF_H5FAIL;
TEST(H5I_GROUP==H5Iget_type(grp));
{ /* pre-conditions: no dataset */
TEST(!cbf_H5Ivalid(dset));
TEST(0==H5Lexists(grp,name,H5P_DEFAULT));
}
/* check it works *without* a previously existing dataset */
TEST_CBF_PASS(cbf_H5Drequire(grp,&dset,name,rank,max,cnk,buf,type));
{ /* post-conditions from previous test, pre-conditions for next test */
hid_t dsetObj = CBF_H5FAIL;
TEST(cbf_H5Ivalid(dset));
TEST(H5I_DATASET==H5Iget_type(dset));
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(dsetObj=H5Oopen(grp,name,H5P_DEFAULT)));
TEST(!cbf_H5Ocmp(dset,dsetObj));
H5Oclose(dsetObj);
}
/* check it works *with* a previously existing dataset */
TEST_CBF_PASS(cbf_H5Drequire(grp,&dset,name,rank,max,cnk,buf,H5T_STD_I32LE));
{ /* post-conditions from previous test */
hid_t dsetObj = CBF_H5FAIL;
TEST(cbf_H5Ivalid(dset));
TEST(H5I_DATASET==H5Iget_type(dset));
TEST(H5Lexists(grp,name,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(dsetObj=H5Oopen(grp,name,H5P_DEFAULT)));
TEST(!cbf_H5Ocmp(dset,dsetObj));
H5Oclose(dsetObj);
}
cbf_H5Dfree(dset);
return r;
}
/* wrapper for common tests, expected failures checked in calling function */
static testResult_t test_H5Dinsert
(const hid_t dset,
const hsize_t * const off,
const hsize_t * const std,
const hsize_t * const cnt,
hsize_t * const buf, /* length = rank */
const void * const val,
void * const valBuf, /* length = nElems */
const hid_t type, /* type of val & valBuf = H5T_NATIVE_SOMETHING */
int (*cmp)(const void * const, const void * const, size_t
#ifdef CBF_USE_ULP
,const void * const
#endif
),
const size_t length,
const void * const cmp_params)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
CBF_UNUSED( cmp_params );
TEST(H5I_DATASET==H5Iget_type(dset));
/* pre-conditions */
TEST(cbf_H5Ivalid(dset));
/* call the function */
TEST_CBF_PASS(cbf_H5Dinsert(dset,off,std,cnt,buf,val,type));
{/* post-conditions */
CBF_CALL(cbf_H5Dread2(dset,off,std,cnt,valBuf,type));
if (CBF_SUCCESS==error) TEST(!cmp(val,valBuf,length
#ifdef CBF_USE_ULP
,cmp_params
#endif
));
}
return r;
}
static testResult_t testDatasets(const hid_t grp)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/*
Test the dataset API on hdf5 group 'grp'.
*/
TEST(H5I_GROUP==H5Iget_type(grp));
if (CBF_SUCCESS==error && !r.fail) {
/* create & free functions */
const char name[] = "dataset_create_free";
hid_t handle = CBF_H5FAIL;
TEST_COMPONENT(test_H5Dcreate(grp,&handle,name));
TEST_COMPONENT(test_H5Dfree(grp,handle,name));
cbf_H5Dfree(handle);
} else {
fprintf(stderr,"%s: Skipping dataset/create&free tests\n",__WHERE__);
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
/* find function */
hsize_t buf[] = {0,0};
TEST_COMPONENT(testDatasetFind(grp,NULL));
TEST_COMPONENT(testDatasetFind(grp,buf));
} else {
fprintf(stderr,"%s: Skipping dataset/find tests\n",__WHERE__);
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
TEST_COMPONENT(test_H5Drequire_flstring(grp));
} else {
fprintf(stderr,"%s: Skipping dataset/require_flstring tests\n",__WHERE__);
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
TEST_COMPONENT(test_H5Drequire_F64LE(grp));
} else {
fprintf(stderr,"%s: Skipping dataset/require_F64LE tests\n",__WHERE__);
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
TEST_COMPONENT(test_H5Dset_extent(grp));
} else {
fprintf(stderr,"Skipping dataset/set_extent tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
TEST_COMPONENT(testDataset_read_write(grp));
} else {
fprintf(stderr,"Skipping dataset/read&write tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
hid_t dset = CBF_H5FAIL;
const hsize_t max[] = {H5S_UNLIMITED,2};
const hsize_t cnk[] = {2,2};
hsize_t buf[] = {0,0};
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Drequire(CBF_H5FAIL,&dset,"name",2,max,cnk,buf,H5T_STD_I32LE));
TEST_CBF_FAIL(cbf_H5Drequire(grp,&dset,0,2,max,cnk,buf,H5T_STD_I32LE));
TEST_CBF_FAIL(cbf_H5Drequire(grp,&dset,"name",-1,max,cnk,buf,H5T_STD_I32LE));
TEST_CBF_FAIL(cbf_H5Drequire(grp,&dset,"name",2,max,0,buf,H5T_STD_I32LE));
TEST_CBF_FAIL(cbf_H5Drequire(grp,&dset,"name",2,max,cnk,buf,CBF_H5FAIL));
/* check if things work */
TEST_CBF_PASS(cbf_H5Drequire(grp,&dset,"dataset_require_0",2,max,cnk,buf,H5T_STD_I32LE));
TEST_COMPONENT(test_H5Drequire(grp,"dataset_require_1",2,max,cnk,buf,H5T_STD_I32LE));
TEST_COMPONENT(test_H5Drequire(grp,"dataset_require_2",2,max,cnk,0,H5T_STD_I32LE));
TEST_COMPONENT(test_H5Drequire(grp,"dataset_require_3",0,0,cnk,buf,H5T_STD_I32LE));
TEST_COMPONENT(test_H5Drequire(grp,"dataset_require_4",0,max,0,buf,H5T_STD_I32LE));
TEST_COMPONENT(test_H5Drequire(grp,"dataset_require_5",0,max,cnk,0,H5T_STD_I32LE));
cbf_H5Dfree(dset);
} else {
fprintf(stderr,"Skipping dataset/require tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
hid_t dset = CBF_H5FAIL;
const hsize_t dim[] = {0,2};
const hsize_t max[] = {H5S_UNLIMITED,2};
const hsize_t cnk[] = {2,2};
const hsize_t off0[] = {0,0};
const hsize_t off1[] = {1,0};
const hsize_t off2[] = {2,0};
const hsize_t std[] = {1,1};
const hsize_t cnt[] = {1,2};
hsize_t buf[] = {0,0};
const int val[2] = {1,2};
CBF_CALL(cbf_H5Dcreate(grp,&dset,"dataset_insert",2,dim,max,cnk,H5T_STD_I32LE));
if (CBF_SUCCESS == error) {
int valBuf[2];
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Dinsert(CBF_H5FAIL,off0,std,cnt,buf,val,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dinsert(dset,0,std,cnt,buf,val,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dinsert(dset,off0,std,0,buf,val,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dinsert(dset,off0,std,cnt,buf,0,H5T_NATIVE_INT));
TEST_CBF_FAIL(cbf_H5Dinsert(dset,off0,std,cnt,buf,val,CBF_H5FAIL));
/* check if things work */
TEST_COMPONENT(test_H5Dinsert(dset,off0,std,cnt,buf,val,valBuf,H5T_NATIVE_INT,cmp_int_exact,2,NULL));
TEST_COMPONENT(test_H5Dinsert(dset,off1,0,cnt,buf,val,valBuf,H5T_NATIVE_INT,cmp_int_exact,2,NULL));
TEST_COMPONENT(test_H5Dinsert(dset,off2,std,cnt,0,val,valBuf,H5T_NATIVE_INT,cmp_int_exact,2,NULL));
}
cbf_H5Dfree(dset);
} else {
fprintf(stderr,"Skipping dataset/insert tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
/* test some of the attribute management API */
hid_t handle = CBF_H5FAIL;
CBF_CALL(cbf_H5Dcreate(grp,&handle,"dataset_attributes", 0,0,0, 0, H5T_STD_I32LE));
/* check for errors */
if (CBF_SUCCESS != error) {
++r.fail;
++r.skip;
fprintf(stderr,"%s: Error: %s\n",__WHERE__,cbf_strerror(error));
return r;
}
TEST_COMPONENT(test_attribute(handle));
/* free the handle after using it */
cbf_H5Dfree(handle);
} else {
fprintf(stderr,"Skipping dataset/attribute tests\n");
++r.skip;
}
return r;
}
/*
Test the group API in hdf5 file or group 'obj'.
*/
static testResult_t testGroups(const hid_t obj)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
const char grpname1[] = "group_1";
const char grpname2[] = "group_2";
if (CBF_SUCCESS==error && !r.fail) {
/*
cbf_H5Gcreate & cbf_H5Gfree:
Verify expected failures,
create a new group,
ensure I can't create a duplicate group,
check that freeing groups works correctly.
*/
hid_t grp = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Gcreate(CBF_H5FAIL, &grp, grpname1));
TEST_CBF_FAIL(cbf_H5Gcreate(obj, 0, grpname1));
TEST_CBF_FAIL(cbf_H5Gcreate(obj, &grp, 0));
{ /* preconditions */
TEST(H5Lexists(obj,grpname1,H5P_DEFAULT)==0);
}
/* check I can create groups */
TEST_CBF_PASS(cbf_H5Gcreate(obj, &grp, grpname1));
{ /* post-conditions */
hid_t testObject = CBF_H5FAIL;
const char * name = grpname1;
TEST(cbf_H5Ivalid(grp));
TEST(H5Lexists(obj,name,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(testObject = H5Oopen(obj,name,H5P_DEFAULT)));
TEST(H5I_GROUP==H5Iget_type(testObject));
H5Oclose(testObject);
}
{ /* ensure another group can't be created with the same name */
hid_t handle = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Gcreate(obj, &handle, grpname1));
TEST(!cbf_H5Ivalid(handle));
}
{ /* free some groups */
const hid_t tmpHandle = grp;
TEST(cbf_H5Ivalid(grp));
TEST_CBF_FAIL(cbf_H5Gfree(CBF_H5FAIL));
TEST_CBF_PASS(cbf_H5Gfree(grp));
TEST(!cbf_H5Ivalid(grp));
TEST_CBF_FAIL(cbf_H5Gfree(grp));
TEST(tmpHandle==grp);
/* the data must remain in the tree */
TEST(H5Lexists(obj,grpname1,H5P_DEFAULT)>0);
}
} else {
fprintf(stderr,"Skipping group/create-free tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
/*
cbf_H5Gfind:
Verify expected failures,
check I can retrieve an existing group,
check failure mode for non-existant group.
*/
hid_t grp = CBF_H5FAIL;
{
/*
Preconditions:
A group with name given by grpname1 exists;
A group with name given by grpname2 doesn't exist.
*/
hid_t testObject = CBF_H5FAIL;
TEST(H5Lexists(obj,grpname1,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(testObject = H5Oopen(obj,grpname1,H5P_DEFAULT)));
TEST(H5I_GROUP==H5Iget_type(testObject));
H5Oclose(testObject);
TEST(H5Lexists(obj,grpname2,H5P_DEFAULT)==0);
}
/* verify expected failures */
TEST_CBF_FAIL(cbf_H5Gfind(CBF_H5FAIL, &grp, grpname1));
TEST_CBF_FAIL(cbf_H5Gfind(obj, 0, grpname1));
TEST_CBF_FAIL(cbf_H5Gfind(obj, &grp, 0));
/* check it can find an existing group */
TEST_CBF_PASS(cbf_H5Gfind(obj, &grp, grpname1));
cbf_H5Gfree(grp);
/* check it doesn't find a non-exstant group correctly */
TEST_CBF_NOTFOUND(cbf_H5Gfind(obj, &grp, grpname2));
} else {
fprintf(stderr,"Skipping group/find tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
/*
cbf_H5Grequire:
Verify expected failures,
check I can retrieve an existing group,
check I can create a new group.
*/
hid_t grp1 = CBF_H5FAIL;
hid_t grp2 = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Grequire(CBF_H5FAIL, &grp1, grpname1));
TEST_CBF_FAIL(cbf_H5Grequire(obj, 0, grpname1));
TEST_CBF_FAIL(cbf_H5Grequire(obj, &grp1, 0));
{ /* preconditions */
hid_t testObject = CBF_H5FAIL;
TEST(H5Lexists(obj,grpname1,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(testObject = H5Oopen(obj,grpname1,H5P_DEFAULT)));
TEST(H5I_GROUP==H5Iget_type(testObject));
H5Oclose(testObject);
TEST(H5Lexists(obj,grpname2,H5P_DEFAULT)==0);
}
/* check I can access existing groups or create new groups */
TEST_CBF_PASS(cbf_H5Grequire(obj, &grp1, grpname1));
TEST_CBF_PASS(cbf_H5Grequire(obj, &grp2, grpname2));
{ /* post-conditions */
hid_t testObject = CBF_H5FAIL;
TEST(cbf_H5Ivalid(grp1));
TEST(cbf_H5Ivalid(grp2));
TEST(H5Lexists(obj,grpname2,H5P_DEFAULT)>0);
TEST(cbf_H5Ivalid(testObject = H5Oopen(obj,grpname2,H5P_DEFAULT)));
TEST(H5I_GROUP==H5Iget_type(grp2));
TEST(!cbf_H5Ocmp(testObject,grp2));
H5Oclose(testObject);
}
cbf_H5Gfree(grp1);
cbf_H5Gfree(grp2);
} else {
fprintf(stderr,"Skipping group/require tests\n");
++r.skip;
}
if (CBF_SUCCESS==error && !r.fail) {
/* test some of the dataset management API */
hid_t grp = CBF_H5FAIL;
CBF_CALL(cbf_H5Grequire(obj,&grp,grpname1));
TEST_COMPONENT(testDatasets(grp));
cbf_H5Gfree(grp);
} else {
++r.skip;
fprintf(stderr,"%s: Skipping dataset tests\n",__WHERE__);
}
if (CBF_SUCCESS==error && !r.fail) {
/* test some of the attribute management API */
hid_t grp = CBF_H5FAIL;
CBF_CALL(cbf_H5Grequire(obj,&grp,grpname1));
TEST_COMPONENT(test_attribute(grp));
cbf_H5Gfree(grp);
} else {
++r.skip;
fprintf(stderr,"%s: Skipping attribute tests\n",__WHERE__);
}
return r;
}
static testResult_t testDatatypes( void )
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/*
Test the datatype API.
*/
{ /* test variable length string type creation */
hid_t type = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Tcreate_string(&type, H5T_VARIABLE));
TEST(cbf_H5Ivalid(type));
TEST(H5I_DATATYPE==H5Iget_type(type));
TEST(H5T_STRING==H5Tget_class(type));
TEST(H5T_STR_NULLTERM==H5Tget_strpad(type));
TEST(H5Tis_variable_str(type)>0);
{ /* test cbf_H5Tfree */
const hid_t tmpType = type;
TEST_CBF_FAIL(cbf_H5Tfree(CBF_H5FAIL));
TEST_CBF_PASS(cbf_H5Tfree(type));
TEST(!cbf_H5Ivalid(type));
TEST_CBF_FAIL(cbf_H5Tfree(type));
TEST(tmpType == type);
}
}
{ /* test fixed length string type creation */
hid_t type = CBF_H5FAIL;
const int len = 42;
TEST_CBF_PASS(cbf_H5Tcreate_string(&type, len));
TEST(cbf_H5Ivalid(type));
TEST(H5I_DATATYPE==H5Iget_type(type));
TEST(H5T_STRING==H5Tget_class(type));
TEST(H5T_STR_NULLTERM==H5Tget_strpad(type));
TEST(H5Tis_variable_str(type)==0);
TEST(H5Tget_size(type)==(size_t)(1+len));
cbf_H5Tfree(type);
}
return r;
}
static testResult_t testDataspaces( void )
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
/*
Test the dataspace API.
*/
{ /* rank -1 */
hid_t space = CBF_H5FAIL;
TEST_CBF_FAIL(cbf_H5Screate(&space,-1,0,0));
}
{ /* rank 0 */
hid_t space = CBF_H5FAIL;
hid_t tmp = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Screate(&space,0,0,0));
TEST(cbf_H5Ivalid(space));
TEST(0==H5Sget_simple_extent_dims(space,0,0));
{ /* test cbf_H5Sfree */
tmp = space;
TEST_CBF_FAIL(cbf_H5Sfree(CBF_H5FAIL));
TEST_CBF_PASS(cbf_H5Sfree(space));
TEST(!cbf_H5Ivalid(space));
TEST_CBF_FAIL(cbf_H5Sfree(space));
TEST(tmp==space);
}
}
{ /* rank 1 */
hid_t space = CBF_H5FAIL;
hsize_t dim[] = {2};
hsize_t max[] = {4};
{ /* dim & max => pass */
hsize_t _dim[] = {0};
hsize_t _max[] = {0};
TEST_CBF_PASS(cbf_H5Screate(&space,1,dim,max));
TEST(cbf_H5Ivalid(space));
TEST(1==H5Sget_simple_extent_dims(space,0,0));
TEST(1==H5Sget_simple_extent_dims(space,_dim,_max));
TEST(!CBFM_cmp_hsize_t_exact(dim,_dim,1,0));
TEST(!CBFM_cmp_hsize_t_exact(max,_max,1,0));
cbf_H5Sfree(space);
}
{ /* dim & !max => pass */
hsize_t _dim[] = {0};
hsize_t _max[] = {0};
TEST_CBF_PASS(cbf_H5Screate(&space,1,dim,0));
TEST(cbf_H5Ivalid(space));
TEST(1==H5Sget_simple_extent_dims(space,0,0));
TEST(1==H5Sget_simple_extent_dims(space,_dim,_max));
TEST(!CBFM_cmp_hsize_t_exact(dim,_dim,1,0));
TEST(!CBFM_cmp_hsize_t_exact(dim,_max,1,0));
cbf_H5Sfree(space);
}
{ /* !dim & max => fail */
const hid_t tmp = space;
TEST_CBF_FAIL(cbf_H5Screate(&space,1,0,max));
TEST(!cbf_H5Ivalid(space));
TEST(tmp==space);
cbf_H5Sfree(space);
}
{ /* !dim & !max => fail */
const hid_t tmp = space;
TEST_CBF_FAIL(cbf_H5Screate(&space,1,0,0));
TEST(!cbf_H5Ivalid(space));
TEST(tmp==space);
cbf_H5Sfree(space);
}
}
{ /* rank 2 */
hid_t space = CBF_H5FAIL;
hsize_t dim[] = {2,4};
hsize_t max[] = {8,16};
{ /* dim & max => pass */
hsize_t _dim[] = {0,0};
hsize_t _max[] = {0,0};
TEST_CBF_PASS(cbf_H5Screate(&space,2,dim,max));
TEST(cbf_H5Ivalid(space));
TEST(2==H5Sget_simple_extent_dims(space,0,0));
TEST(2==H5Sget_simple_extent_dims(space,_dim,_max));
TEST(!CBFM_cmp_hsize_t_exact(dim,_dim,2,0));
TEST(!CBFM_cmp_hsize_t_exact(max,_max,2,0));
cbf_H5Sfree(space);
}
{ /* dim & !max => pass */
hsize_t _dim[] = {0,0};
hsize_t _max[] = {0,0};
TEST_CBF_PASS(cbf_H5Screate(&space,2,dim,0));
TEST(cbf_H5Ivalid(space));
TEST(2==H5Sget_simple_extent_dims(space,0,0));
TEST(2==H5Sget_simple_extent_dims(space,_dim,_max));
TEST(!CBFM_cmp_hsize_t_exact(dim,_dim,2,0));
TEST(!CBFM_cmp_hsize_t_exact(dim,_max,2,0));
cbf_H5Sfree(space);
}
{ /* !dim & max => fail */
const hid_t tmp = space;
TEST_CBF_FAIL(cbf_H5Screate(&space,2,0,max));
TEST(!cbf_H5Ivalid(space));
TEST(tmp==space);
cbf_H5Sfree(space);
}
{ /* !dim & !max => fail */
const hid_t tmp = space;
TEST_CBF_FAIL(cbf_H5Screate(&space,2,0,0));
TEST(!cbf_H5Ivalid(space));
TEST(tmp==space);
cbf_H5Sfree(space);
}
}
return r;
}
int main(int argc, char ** argv)
{
int error = CBF_SUCCESS;
testResult_t r = {0,0,0};
hid_t error_stack;
H5E_auto2_t old_func;
void *old_client_data;
CBF_UNUSED(argc);
CBF_UNUSED(argv);
/* test the test functions a bit */
TEST(1);
TEST_CBF_PASS(CBF_SUCCESS);
TEST_CBF_FAIL(CBF_FORMAT);
TEST_CBF_FAIL(CBF_ARGUMENT);
TEST_CBF_FAIL(CBF_H5ERROR);
TEST_CBF_FAIL(CBF_H5DIFFERENT);
/* check that cbf_H5Ivalid can fail: */
TEST(!cbf_H5Ivalid(CBF_H5FAIL));
TEST(H5I_DATATYPE==H5Iget_type(H5T_STD_I32LE));
{ /* Try opening a file */
const char filename[] = "testfile.h5";
hid_t h5file = CBF_H5FAIL;
TEST_CBF_PASS(cbf_H5Fopen(&h5file, filename));
TEST(cbf_H5Ivalid(h5file));
/* test the API */
error_stack = H5E_DEFAULT;
H5Eget_auto2(error_stack, &old_func, &old_client_data);
H5Eset_auto2(error_stack, NULL, NULL);
TEST_COMPONENT(testGroups(h5file));
H5Eset_auto(error_stack, old_func, old_client_data);
TEST_COMPONENT(testDatatypes());
TEST_COMPONENT(testDataspaces());
{ /* close the file */
const hid_t const_h5file = h5file;
TEST_CBF_PASS(cbf_H5Fclose(const_h5file));
TEST(!cbf_H5Ivalid(h5file));
TEST(CBF_H5FAIL!=h5file);
}
}
printf_results(&r);
return r.fail || r.skip ? 1 : 0;
}
|