summaryrefslogtreecommitdiffstats
path: root/test/links.c
blob: 1ad35af64ec27bdf54eb47c9712a8412f40d267c (plain)
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Programmer:  Robb Matzke <matzke@llnl.gov>
 *              Friday, April 10, 1998
 *
 * Purpose:	Tests hard and soft (symbolic) links.
 */

#define H5G_PACKAGE		/*suppress error about including H5Gpkg	  */

/* Define this macro to indicate that the testing APIs should be available */
#define H5G_TESTING

#include "h5test.h"
#include "H5Gpkg.h"		/* Groups				*/

const char *FILENAME[] = {
    "links0",
    "links1",
    "links2",
    "links3",
    "links4",
    "links5",
    "links6",
    "links7",
    "links8",
    "links9",
    "links10",
    "links11",
    "links12",
    "links13",
    "links14",
    "links15",
    NULL
};

#define LINK_BUF_SIZE   1024
#define NAME_BUF_SIZE   1024
#define MAX_NAME_LEN    ((64*1024)+1024)

#define H5L_DIM1 100
#define H5L_DIM2 100


/*-------------------------------------------------------------------------
 * Function:	mklinks
 *
 * Purpose:	Build a file with assorted links.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Robb Matzke
 *              Friday, August 14, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
mklinks(hid_t fapl)
{
    hid_t		file, scalar, grp, d1;
    hsize_t	        size[1] = {1};
    char		filename[NAME_BUF_SIZE];

    TESTING("link creation");

    /* Create a file */
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;
    if ((scalar=H5Screate_simple (1, size, size))<0) TEST_ERROR;

    /* Create a group */
    if ((grp=H5Gcreate (file, "grp1", (size_t)0))<0) TEST_ERROR;
    if (H5Gclose (grp)<0) TEST_ERROR;

    /* Create a dataset */
    if ((d1=H5Dcreate (file, "d1", H5T_NATIVE_INT, scalar, H5P_DEFAULT))<0) TEST_ERROR;
    if (H5Dclose (d1)<0) TEST_ERROR;

    /* Create a hard link */
    if (H5Lcreate_hard (file, "d1", H5L_SAME_LOC, "grp1/hard", H5P_DEFAULT)<0) TEST_ERROR;

    /* Create a symbolic link */
    if (H5Lcreate_soft ("/d1", file, "grp1/soft", H5P_DEFAULT)<0) TEST_ERROR;

    /* Create a symbolic link to something that doesn't exist */
    if (H5Lcreate_soft ("foobar", file, "grp1/dangle", H5P_DEFAULT)<0) TEST_ERROR;

    /* Create a recursive symbolic link */
    if (H5Lcreate_soft ("/grp1/recursive", file, "/grp1/recursive", H5P_DEFAULT)<0) TEST_ERROR;

    /* Close */
    if (H5Sclose (scalar)<0) TEST_ERROR;
    if (H5Fclose (file)<0) TEST_ERROR;

    PASSED();
    return 0;

 error:
    return -1;
}


/*-------------------------------------------------------------------------
 * Function:    new_links
 *
 * Purpose:     Build a file with assorted links for different locations.
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              Friday, April 19, 2002
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
new_links(hid_t fapl)
{
    hid_t		file_a, file_b=(-1);
    hid_t		grp1_a=(-1), grp1_b=(-1), grp2_a=(-1), grp2_b=(-1);
    hid_t		scalar=(-1);
    hid_t		dset1=(-1), dset2=(-1);
    char		filename[NAME_BUF_SIZE];
    hsize_t             size[1] = {1};

    TESTING("H5Lcreate functions");

    /* Create two files */
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if ((file_a=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
    if ((file_b=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    if ((scalar=H5Screate_simple (1, size, size))<0) TEST_ERROR;

    /* Create two groups in each file */
    if ((grp1_a=H5Gcreate (file_a, "grp1", (size_t)0))<0) TEST_ERROR;
    if ((grp2_a=H5Gcreate (file_a, "grp2", (size_t)0))<0) TEST_ERROR;
    if ((grp1_b=H5Gcreate (file_b, "grp1", (size_t)0))<0) TEST_ERROR;
    if ((grp2_b=H5Gcreate (file_b, "grp2", (size_t)0))<0) TEST_ERROR;

    /* Create datasets */
    if((dset1=H5Dcreate(file_a, "dataset1", H5T_NATIVE_INT, scalar, H5P_DEFAULT))<0) TEST_ERROR;
    if((dset2=H5Dcreate(grp1_a, "dataset2", H5T_NATIVE_INT, scalar, H5P_DEFAULT))<0) TEST_ERROR;

    /* Create links within a file.  Both of source and destination use
     * H5L_SAME_LOC.  Both hard and soft links should fail. */
    H5E_BEGIN_TRY {
        if(H5Lcreate_hard(H5L_SAME_LOC, "dataset1", H5L_SAME_LOC, "hard", H5P_DEFAULT)!=FAIL) TEST_ERROR;
    } H5E_END_TRY;
    H5E_BEGIN_TRY {
        if(H5Lcreate_soft("dataset1", H5L_SAME_LOC, "soft", H5P_DEFAULT)!=FAIL) TEST_ERROR;
    } H5E_END_TRY;

    /* Create links across files with hard link.  Should fail. */
    H5E_BEGIN_TRY {
        if(H5Lcreate_hard(file_a, "dataset1", file_b, "hard", H5P_DEFAULT)!=FAIL) TEST_ERROR;
    } H5E_END_TRY;

    /* Create hard link to test H5L_SAME_LOC */
    if(H5Lcreate_hard(grp1_a, "dataset2", H5L_SAME_LOC, "hard1", H5P_DEFAULT)<0) TEST_ERROR;

    /* Create links to test hard links across different locations */
    if(H5Lcreate_hard(grp1_a, "dataset2", grp2_a, "hard2", H5P_DEFAULT)<0) TEST_ERROR;

    /* Close dataspace and files */
    if (H5Sclose (scalar)<0) TEST_ERROR;
    if (H5Dclose(dset1)<0) TEST_ERROR;
    if (H5Dclose(dset2)<0) TEST_ERROR;
    if (H5Gclose (grp1_a)<0) TEST_ERROR;
    if (H5Gclose (grp2_a)<0) TEST_ERROR;
    if (H5Gclose (grp1_b)<0) TEST_ERROR;
    if (H5Gclose (grp2_b)<0) TEST_ERROR;
    if (H5Fclose (file_a)<0) TEST_ERROR;
    if (H5Fclose (file_b)<0) TEST_ERROR;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
    	H5Sclose (scalar);
    	H5Dclose (dset1);
    	H5Dclose (dset2);
    	H5Gclose (grp1_a);
    	H5Gclose (grp2_a);
    	H5Gclose (grp1_b);
    	H5Gclose (grp2_b);
    	H5Fclose (file_a);
    	H5Fclose (file_b);
    } H5E_END_TRY;
    return -1;
}


/*-------------------------------------------------------------------------
 * Function:	cklinks
 *
 * Purpose:	Open the file created in the first step and check that the
 *		links look correct.
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Robb Matzke
 *              Friday, August 14, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
cklinks(hid_t fapl)
{
    hid_t		file;
    H5G_stat_t		sb1, sb2;
    char		linkval[LINK_BUF_SIZE];
    char		filename[NAME_BUF_SIZE];
    herr_t		status;

    TESTING("link queries");

    /* Open the file */
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) TEST_ERROR;

    /* Hard link */
    if (H5Gget_objinfo(file, "d1", TRUE, &sb1)<0) TEST_ERROR;
    if (H5Gget_objinfo(file, "grp1/hard", TRUE, &sb2)<0) TEST_ERROR;
    if (H5G_DATASET!=sb2.type) {
	H5_FAILED();
	printf("    %d: Unexpected object type should have been a dataset\n", __LINE__);
	TEST_ERROR;
    }
    if (HDmemcmp(&sb1.objno, &sb2.objno, sizeof(sb1.objno))) {
	H5_FAILED();
	puts("    Hard link test failed. Link seems not to point to the ");
	puts("    expected file location.");
	TEST_ERROR;
    }

    /* Symbolic link */
    if (H5Gget_objinfo(file, "grp1/soft", TRUE, &sb2)<0) TEST_ERROR;
    if (H5G_DATASET!=sb2.type) {
	H5_FAILED();
	printf("    %d: Unexpected object type should have been a dataset\n", __LINE__);
	TEST_ERROR;
    }
    if (HDmemcmp(&sb1.objno, &sb2.objno, sizeof(sb1.objno))) {
	H5_FAILED();
	puts("    Soft link test failed. Link seems not to point to the ");
	puts("    expected file location.");
	TEST_ERROR;
    }
    if (H5Gget_linkval(file, "grp1/soft", sizeof linkval, linkval)<0) TEST_ERROR;
    if (HDstrcmp(linkval, "/d1")) {
	H5_FAILED();
	puts("    Soft link test failed. Wrong link value");
	TEST_ERROR;
    }

    /* Dangling link */
    H5E_BEGIN_TRY {
	status = H5Gget_objinfo(file, "grp1/dangle", TRUE, &sb2);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	puts("    H5Gget_objinfo() should have failed for a dangling link.");
	TEST_ERROR;
    }
    if (H5Gget_objinfo(file, "grp1/dangle", FALSE, &sb2)<0) TEST_ERROR;
    if (H5G_LINK!=sb2.type) {
	H5_FAILED();
	printf("    %d: Unexpected object type should have been a symbolic link\n", __LINE__);
	TEST_ERROR;
    }
    if (H5Gget_linkval(file, "grp1/dangle", sizeof linkval, linkval)<0) {
	H5_FAILED();
	printf("    %d: Can't retrieve link value\n", __LINE__);
	TEST_ERROR;
    }
    if (HDstrcmp(linkval, "foobar")) {
	H5_FAILED();
	puts("    Dangling link test failed. Wrong link value");
	TEST_ERROR;
    }

    /* Recursive link */
    H5E_BEGIN_TRY {
	status = H5Gget_objinfo(file, "grp1/recursive", TRUE, &sb2);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	puts("    H5Gget_objinfo() should have failed for a recursive link.");
	TEST_ERROR;
    }
    if (H5Gget_objinfo(file, "grp1/recursive", FALSE, &sb2)<0) TEST_ERROR;
    if (H5G_LINK!=sb2.type) {
	H5_FAILED();
	printf("    %d: Unexpected object type should have been a symbolic link\n", __LINE__);
	TEST_ERROR;
    }
    if (H5Gget_linkval(file, "grp1/recursive", sizeof linkval, linkval)<0) {
	H5_FAILED();
	printf("    %d: Can't retrieve link value\n", __LINE__);
	TEST_ERROR;
    }
    if (HDstrcmp(linkval, "/grp1/recursive")) {
	H5_FAILED();
	puts("   Recursive link test failed. Wrong link value");
	TEST_ERROR;
    }

    /* Cleanup */
    if (H5Fclose(file)<0) TEST_ERROR;
    PASSED();
    return 0;

 error:
    return -1;
}


/*-------------------------------------------------------------------------
 * Function:    ck_new_links
 *
 * Purpose:     Open the file created in the first step and check that the
 *              links look correct.
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Raymond Lu
 *              Thursday, April 25, 2002
 *
 *-------------------------------------------------------------------------
 */
static int
ck_new_links(hid_t fapl)
{
    hid_t 		file;
    H5G_stat_t		sb_dset, sb_hard1, sb_hard2;
    char 		filename[NAME_BUF_SIZE];

    TESTING("new link queries");

    /* Open the file */
    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) TEST_ERROR;

    /* Get hard link info */
    if(H5Gget_objinfo(file, "/grp1/dataset2", TRUE, &sb_dset)<0)
	TEST_ERROR;
    if(H5Gget_objinfo(file, "/grp1/hard1", TRUE, &sb_hard1)<0)
	TEST_ERROR;
    if(H5Gget_objinfo(file, "/grp2/hard2", TRUE, &sb_hard2)<0)
	TEST_ERROR;

    /* Check hard links */
    if(H5G_DATASET!=sb_hard1.type || H5G_DATASET!=sb_hard2.type) {
	H5_FAILED();
	printf("    %d: Unexpected object type should have been a dataset\n", __LINE__);
	TEST_ERROR;
    }
    if(HDmemcmp(&sb_dset.objno, &sb_hard1.objno, sizeof(sb_dset.objno)) || HDmemcmp(&sb_dset.objno, &sb_hard2.objno, sizeof(sb_dset.objno))) {
	H5_FAILED();
	puts("    Hard link test failed.  Link seems not to point to the ");
	puts("    expected file location.");
	TEST_ERROR;
    }

    /* Cleanup */
    if(H5Fclose(file)<0) TEST_ERROR;
    PASSED();
    return 0;

  error:
    return -1;
}


/*-------------------------------------------------------------------------
 * Function:    long_links
 *
 * Purpose:     Build a file with long names
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Quincey Koziol
 *              Saturday, April 16, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
long_links(hid_t fapl)
{
    hid_t		fid = (-1);     /* File ID */
    hid_t		gid = (-1);     /* Group ID */
    hid_t		gid2 = (-1);    /* Datatype ID */
    char               *objname = NULL; /* Name of object [Long] */
    size_t              u;              /* Local index variable */
    char		filename[NAME_BUF_SIZE];

    TESTING("long names for objects & links");

    /* Create files */
    h5_fixname(FILENAME[13], fapl, filename, sizeof filename);
    if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    /* Create group with short name in file (used as target for hard links) */
    if((gid=H5Gcreate (fid, "grp1", (size_t)0))<0) TEST_ERROR;

    /* Construct very long file name */
    if((objname = HDmalloc((size_t)(MAX_NAME_LEN + 1))) == NULL) TEST_ERROR;
    for(u = 0; u < MAX_NAME_LEN; u++)
        objname[u] = 'a';
    objname[MAX_NAME_LEN] = '\0';

    /* Create hard link to existing object */
    if(H5Lcreate_hard(fid, "grp1", fid, objname, H5P_DEFAULT) < 0) TEST_ERROR;

    /* Create soft link to existing object */
    objname[0] = 'b';
    if(H5Lcreate_soft("grp1", fid, objname, H5P_DEFAULT) < 0) TEST_ERROR;

    /* Create group with long name in existing group */
    if((gid2=H5Gcreate(gid, objname, (size_t)0))<0) TEST_ERROR;

    /* Close objects */
    if(H5Gclose(gid2)<0) TEST_ERROR;
    if(H5Gclose(gid)<0) TEST_ERROR;
    if(H5Fclose(fid)<0) TEST_ERROR;

    /* Release memory */
    HDfree(objname);

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
    	H5Gclose (gid2);
    	H5Gclose (gid);
    	H5Fclose (fid);
    } H5E_END_TRY;
    HDfree(objname);
    return -1;
}


/*-------------------------------------------------------------------------
 * Function:    toomany
 *
 * Purpose:     Build a file with too many symbolic links
 *
 * Return:      Success:        0
 *
 *              Failure:        -1
 *
 * Programmer:  Quincey Koziol
 *              Tuesday, August 9, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
toomany(hid_t fapl)
{
    hid_t		fid = (-1);     /* File ID */
    hid_t		gid = (-1);     /* Group ID */
    hid_t		gid2 = (-1);    /* Datatype ID */
    char                objname[NAME_BUF_SIZE];         /* Object name */
    ssize_t             name_len;       /* Length of object name */
    char		filename[NAME_BUF_SIZE];

    TESTING("too many links");

    /* Make certain test is valid */
    /* XXX: should probably make a "generic" test that creates the proper
     *          # of links based on this value - QAK
     */
    HDassert(H5G_NLINKS == 16);

    /* Create files */
    h5_fixname(FILENAME[14], fapl, filename, sizeof filename);
    if((fid=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    /* Create group with short name in file (used as target for hard links) */
    if((gid=H5Gcreate (fid, "final", (size_t)0))<0) TEST_ERROR;

    /* Create chain of hard links to existing object (no limit on #) */
    if(H5Lcreate_hard(fid, "final", fid, "hard1", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard1", fid, "hard2", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard2", fid, "hard3", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard3", fid, "hard4", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard4", fid, "hard5", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard5", fid, "hard6", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard6", fid, "hard7", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard7", fid, "hard8", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard8", fid, "hard9", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard9", fid, "hard10", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard10", fid, "hard11", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard11", fid, "hard12", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard12", fid, "hard13", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard13", fid, "hard14", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard14", fid, "hard15", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard15", fid, "hard16", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard16", fid, "hard17", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard17", fid, "hard18", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard18", fid, "hard19", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard19", fid, "hard20", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_hard(fid, "hard20", fid, "hard21", H5P_DEFAULT) < 0) TEST_ERROR;

    /* Create chain of soft links to existing object (limited) */
    if(H5Lcreate_soft("final", fid, "soft1", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft1", fid, "soft2", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft2", fid, "soft3", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft3", fid, "soft4", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft4", fid, "soft5", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft5", fid, "soft6", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft6", fid, "soft7", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft7", fid, "soft8", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft8", fid, "soft9", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft9", fid, "soft10", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft10", fid, "soft11", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft11", fid, "soft12", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft12", fid, "soft13", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft13", fid, "soft14", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft14", fid, "soft15", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft15", fid, "soft16", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate_soft("soft16", fid, "soft17", H5P_DEFAULT) < 0) TEST_ERROR;

    /* Close objects */
    if(H5Gclose(gid)<0) TEST_ERROR;
    if(H5Fclose(fid)<0) TEST_ERROR;

    /* Open file */
    if((fid=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0) TEST_ERROR;

    /* Open object through last hard link */
    if((gid = H5Gopen(fid, "hard21")) < 0) TEST_ERROR;

    /* Check name */
    if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
    if(HDstrcmp(objname, "/hard21")) TEST_ERROR

    /* Create object in hard-linked group */
    if((gid2 = H5Gcreate(gid, "new_hard", (size_t)0)) < 0) TEST_ERROR

    /* Close group in hard-linked group */
    if(H5Gclose(gid2) < 0) TEST_ERROR

    /* Close hard-linked object */
    if(H5Gclose(gid) < 0) TEST_ERROR;

    /* Open object through too deep soft link */
    H5E_BEGIN_TRY {
        gid = H5Gopen(fid, "soft17");
    } H5E_END_TRY;
    if (gid >= 0) {
	H5_FAILED();
	puts("    Should have failed for sequence of too many nested links.");
	TEST_ERROR;
    }

    /* Open object through lesser soft link */
    if((gid = H5Gopen(fid, "soft16")) < 0) TEST_ERROR;

    /* Check name */
    if((name_len = H5Iget_name( gid, objname, (size_t)NAME_BUF_SIZE )) < 0) TEST_ERROR
    if(HDstrcmp(objname, "/soft16")) TEST_ERROR

    /* Create object in external file */
    if((gid2 = H5Gcreate(gid, "new_soft", (size_t)0)) < 0) TEST_ERROR

    /* Close group in external file */
    if(H5Gclose(gid2) < 0) TEST_ERROR

    /* Close external object */
    if(H5Gclose(gid) < 0) TEST_ERROR;

    /* Close first file */
    if(H5Fclose(fid)<0) TEST_ERROR;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
    	H5Gclose(gid2);
    	H5Gclose(gid);
    	H5Fclose(fid);
    } H5E_END_TRY;
    return -1;
} /* end toomany() */


#ifdef H5_GROUP_REVISION
/*-------------------------------------------------------------------------
 * Function:    test_h5l_create
 *
 * Purpose:     Tests H5Lcreate
 *
 * Return:      Success:        0
 *              Failure:        number of errors
 *
 * Programmer:  James Laird
 *              Monday, January 30, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_h5l_create(hid_t fapl)
{
    hid_t fapl_id=-1;
    hid_t file_id=-1;
    hid_t group_id=-1;
    hid_t space_id=-1;
    hid_t dset_id=-1;
    hid_t type_id=-1;
    hid_t lcpl_id=-1;
    char filename[1024];
    hsize_t dims[2];
    int i, n, j;
    int wdata[H5L_DIM1][H5L_DIM2];
    int rdata[H5L_DIM1][H5L_DIM2];
    TESTING("H5Lcreate");

    /* Create file */
    fapl_id = h5_fileaccess();
    h5_fixname(FILENAME[3], fapl_id, filename, sizeof filename);

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id))<0) TEST_ERROR;

    /* Create and commit a datatype with no name */
    if((type_id =H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR;
    if(H5Tcommit_expand(file_id, type_id, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR;
    if(! H5Tcommitted(type_id)) TEST_ERROR;

    /* Create the dataspace */
    dims[0] = H5L_DIM1;
    dims[1] = H5L_DIM2;
    if((space_id=H5Screate_simple(2 ,dims, NULL))<0) TEST_ERROR;
    /* Create a dataset with no name using the committed datatype*/
    if ((dset_id = H5Dcreate_expand(file_id, type_id, space_id, H5P_DEFAULT)) <0) TEST_ERROR;

    /* Verify that we can write to and read from the dataset */
    /* Initialize the dataset */
    for (i = n = 0; i < H5L_DIM1; i++)
        for (j = 0; j < H5L_DIM2; j++)
          wdata[i][j] = n++;

    /* Write the data to the dataset */
    if (H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata)<0) TEST_ERROR;

    /* Read the data back */
    if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata)<0) TEST_ERROR;
    
    /* Verify the data */
    for (i = 0; i < H5L_DIM1; i++) {
	for (j = 0; j < H5L_DIM2; j++) {
	    if (wdata[i][j] != rdata[i][j])
            {
              TEST_ERROR;
            }
    }}

    /* Create a group with no name*/
    if((group_id = H5Gcreate_expand(file_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;

    /* Link nameless datatype into nameless group */
    if(H5Lcreate(group_id, "datatype", type_id, H5P_DEFAULT)<0) TEST_ERROR;

    /* Create LCPL with intermediate group creation flag set */
    if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) <0) TEST_ERROR;
    if(H5Pset_create_intermediate_group(lcpl_id, TRUE) <0) TEST_ERROR;

    /* Link nameless dataset into nameless group with intermediate group */
    if(H5Lcreate(group_id, "inter_group/dataset", dset_id, lcpl_id)<0) TEST_ERROR;

    /* Close IDs for dataset and datatype */
    if(H5Dclose(dset_id)<0) TEST_ERROR;
    if(H5Tclose(type_id)<0) TEST_ERROR;

    /* Re-open datatype using new link */
    if((type_id = H5Topen(group_id, "datatype"))<0) TEST_ERROR;

    /* Link nameless group to root group and close the group ID*/
    if(H5Lcreate(file_id, "/group", group_id, H5P_DEFAULT)<0) TEST_ERROR;
    if(H5Gclose(group_id)<0) TEST_ERROR;

    /* Open dataset through root group and verify its data */
    if((dset_id = H5Dopen(file_id, "/group/inter_group/dataset"))<0) TEST_ERROR;

    /* Read data from dataset */
    if (H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata)<0) TEST_ERROR;
    for (i = 0; i < H5L_DIM1; i++) {
	for (j = 0; j < H5L_DIM2; j++) {
	    if (wdata[i][j] != rdata[i][j])
            {
              TEST_ERROR;
            }
    }}
        
    /* Close open IDs */
    if(H5Dclose(dset_id)<0) TEST_ERROR;
    if(H5Tclose(type_id)<0) TEST_ERROR;
    if(H5Pclose(lcpl_id)<0) TEST_ERROR;
    if(H5Sclose(space_id)<0) TEST_ERROR;
    if(H5Fclose(file_id)<0) TEST_ERROR;
    if(H5Pclose(fapl_id)<0) TEST_ERROR;
    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
    H5Gclose(group_id);
    H5Dclose(dset_id);
    H5Tclose(type_id);
    H5Pclose(lcpl_id);
    H5Sclose(space_id);
    H5Fclose(file_id);
    H5Pclose(fapl_id);
    } H5E_END_TRY;
    return 1;
} /* end test_h5l_create() */


/*-------------------------------------------------------------------------
 * Function:    test_lcpl
 *
 * Purpose:     Tests Link Creation Property Lists
 *
 * Return:      Success:        0
 *              Failure:        number of errors
 *
 * Programmer:  James Laird
 *              Monday, January 30, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_lcpl(hid_t fapl)
{
    hid_t fapl_id=-1;
    hid_t file_id=-1;
    hid_t group_id=-1;
    hid_t space_id=-1;
    hid_t dset_id=-1;
    hid_t type_id=-1;
    hid_t lcpl_id=-1;
    H5L_linkinfo_t linfo;
    char filename[1024];
    hsize_t dims[2];

    TESTING("link creation property lists");
    /* Actually, intermediate group creation is tested elsewhere (tmisc).
     * Here we only need to test the character encoding property */

    /* Create file */
    fapl_id = h5_fileaccess();
    h5_fixname(FILENAME[12], fapl_id, filename, sizeof filename);

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id))<0) TEST_ERROR;

    /* Create and link a group with the default LCPL */
    if((group_id = H5Gcreate_expand(file_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if(H5Lcreate(file_id, "/group", group_id, H5P_DEFAULT)<0) TEST_ERROR;
    if(H5Gclose(group_id)<0) TEST_ERROR;

    /* Check that its character encoding is the default */
    if(H5Lget_linkinfo(file_id, "group", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5F_CRT_DEFAULT_CSET) TEST_ERROR;

    /* Create and commit a datatype with the default LCPL */
    if((type_id =H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR;
    if(H5Tcommit_expand(file_id, type_id, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate(file_id, "/type", type_id, H5P_DEFAULT)<0) TEST_ERROR;
    if(H5Tclose(type_id)<0) TEST_ERROR;    

    /* Check that its character encoding is the default */
    if(H5Lget_linkinfo(file_id, "type", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5F_CRT_DEFAULT_CSET) TEST_ERROR;

    /* Create a dataspace */
    dims[0] = H5L_DIM1;
    dims[1] = H5L_DIM2;
    if((space_id=H5Screate_simple(2 ,dims, NULL))<0) TEST_ERROR;

    /* Create a dataset using the default LCPL */
    if ((dset_id = H5Dcreate_expand(file_id, H5T_NATIVE_INT, space_id, H5P_DEFAULT)) <0) TEST_ERROR;
    if(H5Lcreate(file_id, "/dataset", dset_id, H5P_DEFAULT)<0) TEST_ERROR;
    if(H5Dclose(dset_id)<0) TEST_ERROR;

    /* Check that its character encoding is the default */
    if(H5Lget_linkinfo(file_id, "dataset", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5F_CRT_DEFAULT_CSET) TEST_ERROR;

    /* Create a link creation property list with the UTF-8 character encoding */
    if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) <0) TEST_ERROR;
    if(H5Pset_char_encoding(lcpl_id, H5T_CSET_UTF8) < 0) TEST_ERROR;

    /* Create and link a group with the new LCPL */
    if((group_id = H5Gcreate_expand(file_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR;
    if(H5Lcreate(file_id, "/group2", group_id, lcpl_id)<0) TEST_ERROR;
    if(H5Gclose(group_id)<0) TEST_ERROR;

    /* Check that its character encoding is UTF-8 */
    if(H5Lget_linkinfo(file_id, "group2", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Create and commit a datatype with the new LCPL */
    if((type_id =H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR;
    if(H5Tcommit_expand(file_id, type_id, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Lcreate(file_id, "/type2", type_id, lcpl_id)<0) TEST_ERROR;    
    if(H5Tclose(type_id)<0) TEST_ERROR;    

    /* Check that its character encoding is UTF-8 */
    if(H5Lget_linkinfo(file_id, "type2", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Create a dataset using the new LCPL */
    if ((dset_id = H5Dcreate_expand(file_id, H5T_NATIVE_INT, space_id, H5P_DEFAULT)) <0) TEST_ERROR;
    if(H5Lcreate(file_id, "/dataset2", dset_id, lcpl_id)<0) TEST_ERROR;
    if(H5Dclose(dset_id)<0) TEST_ERROR;

    /* Check that its character encoding is UTF-8 */
    if(H5Lget_linkinfo(file_id, "dataset2", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Create a new link to the dataset with a different character encoding. */
    if(H5Pclose(lcpl_id)<0) TEST_ERROR;
    if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) <0) TEST_ERROR;
    if(H5Pset_char_encoding(lcpl_id, H5T_CSET_ASCII) < 0) TEST_ERROR;

    if(H5Lcreate_hard(file_id, "/dataset2", file_id, "/dataset2_link", lcpl_id) < 0) TEST_ERROR;

    /* Check that its character encoding is ASCII */
    if(H5Lget_linkinfo(file_id, "/dataset2_link", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5T_CSET_ASCII) TEST_ERROR;

    /* Check that the first link's encoding hasn't changed */
    if(H5Lget_linkinfo(file_id, "/dataset2", &linfo) < 0) TEST_ERROR;
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Close open IDs */
    if(H5Pclose(lcpl_id)<0) TEST_ERROR;
    if(H5Sclose(space_id)<0) TEST_ERROR;
    if(H5Fclose(file_id)<0) TEST_ERROR;
    if(H5Pclose(fapl_id)<0) TEST_ERROR;
    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
    H5Gclose(group_id);
    H5Dclose(dset_id);
    H5Tclose(type_id);
    H5Pclose(lcpl_id);
    H5Sclose(space_id);
    H5Fclose(file_id);
    H5Pclose(fapl_id);
    } H5E_END_TRY;
    return 1;
} /* end test_lcpl() */
#endif /* H5_GROUP_REVISION */


/*-------------------------------------------------------------------------
 * Function:    test_move
 *
 * Purpose:     Tests H5Lmove()
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  James Laird
 *              Friday, March 30, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_move(hid_t fapl)
{
    hid_t 	file_a, file_b=(-1);
    hid_t	grp_1=(-1), grp_2=(-1), grp_move=(-1), moved_grp=(-1);
    char 	filename[1024];

    TESTING("H5Lmove");

    /* Create two new files */
    h5_fixname(FILENAME[8], fapl, filename, sizeof filename);
    if ((file_a=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
        TEST_ERROR;
    h5_fixname(FILENAME[9], fapl, filename, sizeof filename);
    if ((file_b=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
        TEST_ERROR;

    /* Create groups in first file */
    if((grp_1=H5Gcreate(file_a, "group1", 0))<0) TEST_ERROR;
    if((grp_2=H5Gcreate(file_a, "group2", 0))<0) TEST_ERROR;
    if((grp_move=H5Gcreate(grp_1, "group_move", 0))<0) TEST_ERROR;

    /* Create hard and soft links. */
    if(H5Lcreate_hard(grp_1, "group_move", H5L_SAME_LOC, "hard", H5P_DEFAULT)<0)
	TEST_ERROR;
    if(H5Lcreate_soft("/group1/group_move", grp_2, "soft", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Move a group within the file.  Both of source and destination use
     * H5L_SAME_LOC.  Should fail. */
    H5E_BEGIN_TRY {
        if(H5Lmove(H5L_SAME_LOC, "group_move", H5L_SAME_LOC, "group_new_name", H5P_DEFAULT)
                !=FAIL) TEST_ERROR;
    } H5E_END_TRY;

    /* Move a group across files.  Should fail. */
    H5E_BEGIN_TRY {
        if(H5Lmove(grp_1, "group_move", file_b, "group_new_name", H5P_DEFAULT)
                !=FAIL) TEST_ERROR;
    } H5E_END_TRY;

    /* Move a group across groups in the same file while renaming it. */
    if(H5Lmove(grp_1, "group_move", grp_2, "group_new_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group just moved to the new location. */
    if((moved_grp = H5Gopen(grp_2, "group_new_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Verify that the group is no longer in the original location */
    H5E_BEGIN_TRY {
    if((moved_grp = H5Gopen(grp_1, "group_move"))>=0)
	TEST_ERROR;
    } H5E_END_TRY;

    /* Use H5Lmove to rename a group without moving it. */
    if(H5Lmove(grp_2, "group_new_name", H5L_SAME_LOC, "group_newer_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group. */
    if((moved_grp = H5Gopen(grp_2, "group_newer_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Use H5Lmove to move a group without renaming it. */
    if(H5Lmove(grp_2, "group_newer_name", grp_1, "group_newer_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group . */
    if((moved_grp = H5Gopen(grp_1, "group_newer_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Move the group while giving long paths. */
    if(H5Lmove(file_a, "/group1/group_newer_name", grp_2, "/group2/group_newest_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group just moved to the new location. */
    if((moved_grp = H5Gopen(grp_2, "group_newest_name"))<0)
	TEST_ERROR;

    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Verify that the group is in no previous locations */
    H5E_BEGIN_TRY {
    if((moved_grp = H5Gopen(grp_1, "group_newer_name"))>=0)
	TEST_ERROR;
    if((moved_grp = H5Gopen(grp_2, "group_newer_name"))>=0)
	TEST_ERROR;
    if((moved_grp = H5Gopen(grp_2, "group_new_name"))>=0)
	TEST_ERROR;
    if((moved_grp = H5Gopen(grp_1, "group_copy"))>=0)
	TEST_ERROR;
    } H5E_END_TRY;

    H5Gclose(grp_1);
    H5Gclose(grp_2);
    H5Gclose(grp_move);
    H5Fclose(file_a);
    H5Fclose(file_b);

    PASSED();
    return 0;

  error:
    H5_FAILED();
    H5E_BEGIN_TRY {
 	H5Gclose(grp_1);
	H5Gclose(grp_2);
	H5Gclose(grp_move);
        H5Gclose(moved_grp);
	H5Fclose(file_a);
	H5Fclose(file_b);
    } H5E_END_TRY;
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_copy
 *
 * Purpose:     Tests H5Lcopy()
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  James Laird
 *              Friday, March 30, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_copy(hid_t fapl)
{
    hid_t 	file_a, file_b=(-1);
    hid_t	grp_1=(-1), grp_2=(-1), grp_move=(-1), moved_grp=(-1);
    char 	filename[1024];

    TESTING("H5Lcopy");

    /* Create two new files */
    h5_fixname(FILENAME[8], fapl, filename, sizeof filename);
    if ((file_a=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
        TEST_ERROR;
    h5_fixname(FILENAME[9], fapl, filename, sizeof filename);
    if ((file_b=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
        TEST_ERROR;

    /* Create groups in first file */
    if((grp_1=H5Gcreate(file_a, "group1", 0))<0) TEST_ERROR;
    if((grp_2=H5Gcreate(file_a, "group2", 0))<0) TEST_ERROR;
    if((grp_move=H5Gcreate(grp_1, "group_copy", 0))<0) TEST_ERROR;

    /* Create hard and soft links. */
    if(H5Lcreate_hard(grp_1, "group_copy", H5L_SAME_LOC, "hard", H5P_DEFAULT)<0)
	TEST_ERROR;
    if(H5Lcreate_soft("/group1/group_copy", grp_2, "soft", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Copy a group within the file.  Both of source and destination use
     * H5L_SAME_LOC.  Should fail. */
    H5E_BEGIN_TRY {
        if(H5Lcopy(H5L_SAME_LOC, "group_copy", H5L_SAME_LOC, "group_new_name", H5P_DEFAULT)
                !=FAIL) TEST_ERROR;
    } H5E_END_TRY;

    /* Copy a group across files.  Should fail. */
    H5E_BEGIN_TRY {
        if(H5Lcopy(grp_1, "group_copy", file_b, "group_new_name", H5P_DEFAULT)
                !=FAIL) TEST_ERROR;
    } H5E_END_TRY;

    /* Move a group across groups in the same file while renaming it. */
    if(H5Lcopy(grp_1, "group_copy", grp_2, "group_new_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group just moved to the new location. */
    if((moved_grp = H5Gopen(grp_2, "group_new_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Verify that the group is also in the original location */
    if((moved_grp = H5Gopen(grp_1, "group_copy"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Use H5Lcopy to create a group in the same location with a different name. */
    if(H5Lcopy(grp_2, "group_new_name", H5L_SAME_LOC, "group_newer_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group. */
    if((moved_grp = H5Gopen(grp_2, "group_newer_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;
    /* Verify that the group is also in the original location */
    if((moved_grp = H5Gopen(grp_2, "group_new_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Use H5Lcopy to copy to a different location with the same name. */
    if(H5Lcopy(grp_2, "group_newer_name", grp_1, "group_newer_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group . */
    if((moved_grp = H5Gopen(grp_1, "group_newer_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;
    /* Verify that the group is still in the previous location */
    if((moved_grp = H5Gopen(grp_2, "group_new_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Copy the group while giving long paths. */
    if(H5Lcopy(file_a, "/group1/group_newer_name", grp_2, "/group2/group_newest_name", H5P_DEFAULT)<0)
	TEST_ERROR;

    /* Open the group just moved to the new location. */
    if((moved_grp = H5Gopen(grp_2, "group_newest_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    /* Verify that the group is still in all previous original locations */
    if((moved_grp = H5Gopen(grp_1, "group_newer_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;
    if((moved_grp = H5Gopen(grp_2, "group_newer_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;
    if((moved_grp = H5Gopen(grp_2, "group_new_name"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;
    if((moved_grp = H5Gopen(grp_1, "group_copy"))<0)
	TEST_ERROR;
    if( H5Gclose(moved_grp) < 0)
        TEST_ERROR;

    H5Gclose(grp_1);
    H5Gclose(grp_2);
    H5Gclose(grp_move);
    H5Fclose(file_a);
    H5Fclose(file_b);

    PASSED();
    return 0;

  error:
    H5_FAILED();
    H5E_BEGIN_TRY {
 	H5Gclose(grp_1);
	H5Gclose(grp_2);
	H5Gclose(grp_move);
        H5Gclose(moved_grp);
	H5Fclose(file_a);
	H5Fclose(file_b);
    } H5E_END_TRY;
    return 1;
}

#ifdef H5_GROUP_REVISION
/*-------------------------------------------------------------------------
 * Function:    test_move_preserves
 *
 * Purpose:     Tests that moving and renaming links preserves their
 *              properties.
 *
 * Return:      Success:        0
 *              Failure:        number of errors
 *
 * Programmer:  James Laird
 *              Monday, January 30, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_move_preserves(hid_t fapl_id)
{
    hid_t file_id=-1;
    hid_t group_id=-1;
    hid_t lcpl_id=-1;
    hid_t lcpl2_id=-1;
    H5G_stat_t statbuf;
    H5L_linkinfo_t linfo;
    time_t old_create_time;
    time_t old_modification_time;
    time_t curr_time;
    char filename[1024];

    TESTING("moving and copying links preserves their properties");

    /* Create file */
    h5_fixname(FILENAME[11], fapl_id, filename, sizeof filename);

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id))<0) TEST_ERROR;

    /* Create a link creation property list with the UTF-8 character encoding */
    if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) <0) TEST_ERROR;
    if(H5Pset_char_encoding(lcpl_id, H5T_CSET_UTF8) < 0) TEST_ERROR;
    /* Create a group with that lcpl */
    if((group_id = H5Gcreate_expand(file_id, H5P_DEFAULT, H5P_DEFAULT)) <0) TEST_ERROR;
    if(H5Lcreate(file_id, "group", group_id, lcpl_id) < 0) TEST_ERROR;
    if(H5Gclose(group_id) < 0) TEST_ERROR;

    /* Get the group's link's creation time */
    if(H5Lget_linkinfo(file_id, "group", &linfo) < 0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group", TRUE, &statbuf) <0) TEST_ERROR;
    old_create_time = linfo.ctime;
    old_modification_time = statbuf.mtime;

    /* If this test happens too quickly, the creation times will all be the same.  Make sure the time changes. */
    curr_time=time(NULL);
    while(time(NULL) <= curr_time );

    /* Close the file and reopen it */
    if(H5Fclose(file_id)<0) TEST_ERROR;
    if((file_id = H5Fopen(filename, H5F_ACC_RDWR, fapl_id)) <0) TEST_ERROR;

    /* Get the group's link's creation time.  The times should be unchanged */
    if(H5Lget_linkinfo(file_id, "group", &linfo) < 0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(old_create_time != linfo.ctime) TEST_ERROR;

    /* Create a new link to the group.  It should have a different creation time but the same modification time */
    if(H5Lcreate_hard(file_id, "group", file_id, "group2", H5P_DEFAULT) < 0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group2", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(H5Lget_linkinfo(file_id, "group2", &linfo) <0) TEST_ERROR;
    if(old_create_time == linfo.ctime) TEST_ERROR;

    /* Copy the first link to a UTF-8 name.  Its creation time and modification time should not change. */
    if(H5Lcopy(file_id, "group", file_id, "group_copied", lcpl_id) <0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group_copied", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(H5Lget_linkinfo(file_id, "group_copied", &linfo) <0) TEST_ERROR;
    if(old_create_time != linfo.ctime) TEST_ERROR;

    /* Check that its character encoding is UTF-8 */
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Move the link with the default property list. */
    if(H5Lmove(file_id, "group_copied", file_id, "group_copied2", H5P_DEFAULT) <0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group_copied2", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(H5Lget_linkinfo(file_id, "group_copied2", &linfo) <0) TEST_ERROR;
    if(old_create_time != linfo.ctime) TEST_ERROR;

    /* Check that its character encoding is not UTF-8 */
    if(linfo.cset == H5T_CSET_UTF8) TEST_ERROR;

    /* Check that the original link is unchanged */
    if(H5Gget_objinfo(file_id, "group", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(H5Lget_linkinfo(file_id, "group", &linfo) <0) TEST_ERROR;
    if(old_create_time != linfo.ctime) TEST_ERROR;
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Move the first link to a UTF-8 name.  Its creation time and modification time should not change. */
    if(H5Lmove(file_id, "group", file_id, "group_moved", lcpl_id) <0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group_moved", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(H5Lget_linkinfo(file_id, "group_moved", &linfo) <0) TEST_ERROR;
    if(old_create_time != linfo.ctime) TEST_ERROR;

    /* Check that its character encoding is UTF-8 */
    if(linfo.cset != H5T_CSET_UTF8) TEST_ERROR;

    /* Move the link again using the default property list. */
    if(H5Lmove(file_id, "group_moved", file_id, "group_moved_again", H5P_DEFAULT) <0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "group_moved_again", TRUE, &statbuf) <0) TEST_ERROR;
    if(old_modification_time != statbuf.mtime) TEST_ERROR;
    if(H5Lget_linkinfo(file_id, "group_moved_again", &linfo) <0) TEST_ERROR;
    if(old_create_time != linfo.ctime) TEST_ERROR;

    /* Check that its character encoding is not UTF-8 */
    if(linfo.cset == H5T_CSET_UTF8) TEST_ERROR;

    /* Close open IDs */
    if(H5Pclose(lcpl_id) < 0) TEST_ERROR;
    if(H5Fclose(file_id)<0) TEST_ERROR;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
	H5Pclose(lcpl_id);
	H5Pclose(lcpl2_id);
        H5Gclose(group_id);
        H5Fclose(file_id);
    } H5E_END_TRY;
    return 1;
} /* end test_move_preserves() */
#endif /* H5_GROUP_REVISION */


/*-------------------------------------------------------------------------
 * Function:    test_compat
 *
 * Purpose:     Tests deprecated functions for backward compatibility.
 *
 * Return:      Success:        0
 *              Failure:        number of errors
 *
 * Programmer:  James Laird
 *              Wednesday, April 26 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compat(hid_t fapl)
{
    hid_t file_id=-1;
    hid_t group1_id=-1;
    hid_t group2_id=-1;
    H5G_stat_t	sb_hard1, sb_hard2, sb_soft1;
    char filename[1024];
    char linkval[1024];

    TESTING("backwards compatibility");

    /* Create file */
    h5_fixname(FILENAME[15], fapl, filename, sizeof filename);

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR;

    /* Create two groups in the file */
    if((group1_id = H5Gcreate(file_id, "group1", 1)) < 0) TEST_ERROR;
    if((group2_id = H5Gcreate(file_id, "group2", 1)) < 0) TEST_ERROR;

    /* Create links using H5Glink and H5Glink2 */
    if(H5Glink(file_id, H5G_LINK_HARD, "group2", "group1/link_to_group2") < 0) TEST_ERROR;
    if(H5Glink2(file_id, "group1", H5G_LINK_HARD, group2_id, "link_to_group1") < 0) TEST_ERROR;
    if(H5Glink2(file_id, "link_to_group1", H5G_LINK_SOFT, H5G_SAME_LOC, "group2/soft_link_to_group1") < 0) TEST_ERROR;

    /* Test that H5Glink created hard links properly */
    if(H5Gget_objinfo(file_id, "/group2", TRUE, &sb_hard1)<0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "/group1/link_to_group2", TRUE, &sb_hard2)<0) TEST_ERROR;

    if (HDmemcmp(&sb_hard1.objno, sb_hard2.objno, sizeof(sb_hard1.objno))) {
        H5_FAILED();
        puts("    Hard link test failed.  Link seems not to point to the ");
        puts("    expected file location.");
        TEST_ERROR;
    }

    /* Test for the other hard link created */
    if(H5Gget_objinfo(file_id, "/group1", TRUE, &sb_hard1)<0) TEST_ERROR;
    if(H5Gget_objinfo(file_id, "/group2/link_to_group1", TRUE, &sb_hard2)<0) TEST_ERROR;

    if (HDmemcmp(&sb_hard1.objno, sb_hard2.objno, sizeof(sb_hard1.objno))) {
        H5_FAILED();
        puts("    Hard link test failed.  Link seems not to point to the ");
        puts("    expected file location.");
        TEST_ERROR;
    }

    /* Test the soft link */
    if(H5Gget_objinfo(file_id, "/group2/soft_link_to_group1", FALSE, &sb_soft1)<0) TEST_ERROR;
    if(sb_soft1.type != H5G_LINK) TEST_ERROR;
    if(sb_soft1.linklen != HDstrlen("link_to_group1") + 1) TEST_ERROR;

    if(H5Gget_linkval(group2_id, "soft_link_to_group1", sb_soft1.linklen, linkval) < 0) TEST_ERROR;
    if(HDstrcmp("link_to_group1", linkval)) TEST_ERROR;


    /* Test H5Gmove and H5Gmove2 */
    if(H5Gmove(file_id, "group1", "moved_group1") < 0) TEST_ERROR;
    if(H5Gmove2(file_id, "group2", group1_id, "moved_group2") < 0) TEST_ERROR;

    /* Ensure that both groups can be opened */
    if(H5Gclose(group2_id)<0) TEST_ERROR;
    if(H5Gclose(group1_id)<0) TEST_ERROR;

    if((group1_id = H5Gopen(file_id, "moved_group1")) < 0) TEST_ERROR;
    if((group2_id = H5Gopen(file_id, "moved_group1/moved_group2")) < 0) TEST_ERROR;

    /* Close open IDs */
    if(H5Gclose(group2_id)<0) TEST_ERROR;
    if(H5Gclose(group1_id)<0) TEST_ERROR;

    /* Test H5Gunlink */
    if(H5Gunlink(file_id, "moved_group1/moved_group2") < 0) TEST_ERROR;

    H5E_BEGIN_TRY {
        if(H5Gopen(file_id, "moved_group1/moved_group2") >=0) TEST_ERROR;
    } H5E_END_TRY;

    if(H5Fclose(file_id)<0) TEST_ERROR;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Gclose(group2_id);
        H5Gclose(group1_id);
        H5Fclose(file_id);
    } H5E_END_TRY;
    return 1;
} /* end test_compat() */


/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Test links
 *
 * Return:	Success:	exit(0)
 *
 *		Failure:	exit(non-zero)
 *
 * Programmer:	Robb Matzke
 *              Friday, August 14, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    int		nerrors = 0;
    hid_t	fapl;

    h5_reset();
    fapl = h5_fileaccess();

    /* The tests... */
    nerrors += mklinks(fapl) < 0 ? 1 : 0;
    nerrors += cklinks(fapl) < 0 ? 1 : 0;
    nerrors += new_links(fapl) < 0 ? 1 : 0;
    nerrors += ck_new_links(fapl) < 0 ? 1 : 0;
    nerrors += long_links(fapl) < 0 ? 1 : 0;
    nerrors += toomany(fapl) < 0 ? 1 : 0;

    /* Test new H5L link creation routine */
#ifdef H5_GROUP_REVISION
    nerrors += test_h5l_create(fapl);
    nerrors += test_lcpl(fapl);
#endif
    nerrors += test_move(fapl);
    nerrors += test_copy(fapl);
#ifdef H5_GROUP_REVISION
    nerrors += test_move_preserves(fapl);
#endif
    nerrors += test_compat(fapl);

    /* Results */
    if (nerrors) {
	printf("***** %d LINK TEST%s FAILED! *****\n",
	       nerrors, 1 == nerrors ? "" : "S");
	exit(1);
    }
    printf("All link tests passed.\n");
    h5_cleanup(FILENAME, fapl);
    return 0;
}