summaryrefslogtreecommitdiffstats
path: root/tests/io.test
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-05-08 17:30:32 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-05-08 17:30:32 (GMT)
commit8c081b3c39faeaf973eb300f8b269e403fa6107a (patch)
tree0d6ac9ee1d752c0e554a76646a2f8bd802263486 /tests/io.test
parent48ae7e42c1bd6a104c78d737fd6b826a1a4ee7bd (diff)
parenteb476fdf9350b70cf8ab1ec90ad848dec9d1b75b (diff)
downloadtcl-8c081b3c39faeaf973eb300f8b269e403fa6107a.zip
tcl-8c081b3c39faeaf973eb300f8b269e403fa6107a.tar.gz
tcl-8c081b3c39faeaf973eb300f8b269e403fa6107a.tar.bz2
Merge the reforms of dgp-read-bytes branch into 8.5+ releases.
Large overhaul of I/O read operations - Protects integer overflow of buffers, reusing append machinery - Forces -buffersize changes to take place when commanded - Uses assertions to simplify code in "can't happen" situations - Eliminated duplication of -translation processing - Fixes bugs io-35.18b and io-35.20
Diffstat (limited to 'tests/io.test')
-rw-r--r--tests/io.test158
1 files changed, 157 insertions, 1 deletions
diff --git a/tests/io.test b/tests/io.test
index 4791280..7707a28 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -4729,7 +4729,7 @@ test io-35.18a {Tcl_Eof, eof char, cr write, crlf read} -body {
close $f
list $s $l $e [scan [string index $in end] %c]
} -result {9 8 1 13}
-test io-35.18b {Tcl_Eof, eof char, cr write, crlf read} -constraints knownBug -body {
+test io-35.18b {Tcl_Eof, eof char, cr write, crlf read} -body {
file delete $path(test1)
set f [open $path(test1) w]
fconfigure $f -translation cr -eofchar \x1a
@@ -4772,6 +4772,21 @@ test io-35.19 {Tcl_Eof, eof char in middle, cr write, crlf read} -body {
close $f
list $c $l $e [scan [string index $in end] %c]
} -result {17 8 1 13}
+test io-35.20 {Tcl_Eof, eof char in middle, cr write, crlf read} {
+ file delete $path(test1)
+ set f [open $path(test1) w]
+ fconfigure $f -translation cr -eofchar {}
+ set i [format \n%cqrsuvw 26]
+ puts $f $i
+ close $f
+ set c [file size $path(test1)]
+ set f [open $path(test1) r]
+ fconfigure $f -translation crlf -eofchar \x1a
+ set l [string length [set in [read $f]]]
+ set e [eof $f]
+ close $f
+ list $c $l $e [scan [string index $in end] %c]
+} {9 1 1 13}
# Test Tcl_InputBlocked
@@ -6801,6 +6816,147 @@ test io-52.11 {TclCopyChannel & encodings} {fcopy} {
file size $path(kyrillic.txt)
} 3
+test io-52.12 {coverage of -translation auto} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 29
+test io-52.13 {coverage of -translation cr} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation cr
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 30
+test io-52.14 {coverage of -translation crlf} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation crlf
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 29
+test io-52.14.1 {coverage of -translation crlf} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation crlf
+ set out [open $path(test2) w]
+ fcopy $in $out -size 2
+ close $in
+ close $out
+ file size $path(test2)
+} 2
+test io-52.14.2 {coverage of -translation crlf} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -translation crlf
+ set out [open $path(test2) w]
+ fcopy $in $out -size 9
+ close $in
+ close $out
+ file size $path(test2)
+} 9
+test io-52.15 {coverage of -translation crlf} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\r
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation crlf
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 8
+test io-52.16 {coverage of eofChar handling} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation lf -eofchar a
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 0
+test io-52.17 {coverage of eofChar handling} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation lf -eofchar d
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 3
+test io-52.18 {coverage of eofChar handling} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 8 -translation crlf -eofchar h
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 8
+test io-52.19 {coverage of eofChar handling} {
+ file delete $path(test1) $path(test2)
+ set out [open $path(test1) wb]
+ chan configure $out -translation lf
+ puts -nonewline $out abcdefg\rhijklmn\nopqrstu\r\nvwxyz
+ close $out
+ set in [open $path(test1)]
+ chan configure $in -buffersize 10 -translation crlf -eofchar h
+ set out [open $path(test2) w]
+ fcopy $in $out
+ close $in
+ close $out
+ file size $path(test2)
+} 8
+
test io-53.1 {CopyData} {fcopy} {
file delete $path(test1)
set f1 [open $thisScript]
1343' href='#n1343'>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 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Programmer:  Robb Matzke <matzke@llnl.gov>
 *              Tuesday, December  9, 1997
 *
 * Purpose:     Tests the datatype interface (H5T)
 */

#include <math.h>
#include <time.h>
#include "h5test.h"
#include "H5Iprivate.h"     /* For checking that datatype id's don't leak */

/* Number of elements in each test */
#define NTESTELEM	100000

/* For test_compound_8 and test_compound_10 */
#define ARRAY_DIM       4

/*
 * Offset from alinged memory returned by malloc().  This can be used to test
 * that type conversions handle non-aligned buffers correctly.
 */
#define ALIGNMENT	1

/*
 * Define if you want to test alignment code on a machine that doesn't
 * normally require alignment. When set, all native datatypes must be aligned
 * on a byte boundary equal to the data size.
 */
#define TEST_ALIGNMENT

/* Alignment test stuff */
#ifdef TEST_ALIGNMENT
#define H5T_PACKAGE
#include "H5Tpkg.h"
#endif
#define SET_ALIGNMENT(TYPE,VAL) \
    H5T_NATIVE_##TYPE##_ALIGN_g=MAX(H5T_NATIVE_##TYPE##_ALIGN_g, VAL)

/*
 * Macro for checking that the correct number of datatype ids are present.  Be
 * careful as the call to H5Tunregister removes *ALL* compound conversions from
 * the soft conversion list.  One must call reset_hdf5() after this.
 */
#define CHECK_NMEMBS(NMEMBS,SRC_ID,DST_ID)                                     \
    if(H5Tunregister(H5T_PERS_SOFT, NULL, SRC_ID, DST_ID, NULL) < 0)           \
        FAIL_STACK_ERROR                                                       \
    if(H5Tclose(SRC_ID) < 0 || ((SRC_ID) != (DST_ID) && H5Tclose(DST_ID) < 0)) \
        FAIL_STACK_ERROR                                                       \
    if((NMEMBS) != H5I_nmembers(H5I_DATATYPE)) {                               \
        H5_FAILED();                                                           \
        printf("    #dtype ids expected: %d; found: %d\n", NMEMBS,             \
            H5I_nmembers(H5I_DATATYPE));                                       \
        goto error;                                                            \
    }

const char *FILENAME[] = {
    "dtypes1",
    "dtypes2",
    "dtypes3",
    "dtypes4",
    "dtypes5",
    "dtypes6",
    "dtypes7",
    "dtypes8",
    NULL
};

typedef struct complex_t {
    double                  re;
    double                  im;
} complex_t;

typedef enum dtype_t {
    INT_SCHAR, INT_UCHAR, INT_SHORT, INT_USHORT, INT_INT, INT_UINT,
    INT_LONG, INT_ULONG, INT_LLONG, INT_ULLONG, FLT_FLOAT, FLT_DOUBLE,
    FLT_LDOUBLE, OTHER
} dtype_t;

/* Constant for size of conversion buffer for int <-> float exception test */
#define CONVERT_SIZE    4

/* Constants for compound_13 test */
#define COMPOUND13_ARRAY_SIZE   256
#define COMPOUND13_ATTR_NAME    "attr"

/* Count opaque conversions */
static int num_opaque_conversions_g = 0;

static int opaque_check(int tag_it);
static herr_t convert_opaque(hid_t st, hid_t dt,
               H5T_cdata_t *cdata,
	       size_t nelmts, size_t buf_stride,
               size_t bkg_stride, void *_buf,
	       void *bkg, hid_t dset_xfer_plid);
static int opaque_long(void);
static int opaque_funcs(void);


/*-------------------------------------------------------------------------
 * Function:	reset_hdf5
 *
 * Purpose:	Reset the hdf5 library.  This causes statistics to be printed
 *		and counters to be reset.
 *
 * Return:	void
 *
 * Programmer:	Robb Matzke
 *              Monday, November 16, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
reset_hdf5(void)
{
    h5_reset();
#ifdef TEST_ALIGNMENT
    SET_ALIGNMENT(SCHAR,   H5_SIZEOF_CHAR);
    SET_ALIGNMENT(UCHAR,   H5_SIZEOF_CHAR);
    SET_ALIGNMENT(SHORT,   H5_SIZEOF_SHORT);
    SET_ALIGNMENT(USHORT,  H5_SIZEOF_SHORT);
    SET_ALIGNMENT(INT,     H5_SIZEOF_INT);
    SET_ALIGNMENT(UINT,    H5_SIZEOF_INT);
    SET_ALIGNMENT(LONG,    H5_SIZEOF_LONG);
    SET_ALIGNMENT(ULONG,   H5_SIZEOF_LONG);
    SET_ALIGNMENT(LLONG,   H5_SIZEOF_LONG_LONG);
    SET_ALIGNMENT(ULLONG,  H5_SIZEOF_LONG_LONG);
    SET_ALIGNMENT(FLOAT,   H5_SIZEOF_FLOAT);
    SET_ALIGNMENT(DOUBLE,  H5_SIZEOF_DOUBLE);
#if H5_SIZEOF_LONG_DOUBLE !=0
    SET_ALIGNMENT(LDOUBLE, H5_SIZEOF_LONG_DOUBLE);
#endif
#endif

}


/*-------------------------------------------------------------------------
 * Function:    test_classes
 *
 * Purpose:     Test type classes
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Robb Matzke
 *              Tuesday, December  9, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_classes(void)
{
    struct complex {    /* Struct with complex fields */
        hvl_t vl_c;
        hvl_t vl_s;
    };
    hid_t cmpd_id;      /* Compound datatype */
    hid_t vlc_id;       /* VL type of char   */
    hid_t vls_id;       /* VL string         */
    hid_t memb_id;      /* Compound member datatype */
    H5T_class_t         memb_cls;
    H5T_class_t         tcls;
    int                 nmembs;
    unsigned            u;

    TESTING("H5Tget_class()");

    /*-------------------------------------------------------------
     *  Check class of some atomic types.
     *-----------------------------------------------------------*/
    if((tcls = H5Tget_class(H5T_NATIVE_INT)) < 0) TEST_ERROR
    if(H5T_INTEGER != tcls) TEST_ERROR

    if((tcls = H5Tget_class(H5T_NATIVE_DOUBLE)) < 0) TEST_ERROR
    if(H5T_FLOAT != tcls) TEST_ERROR

    /* Create a VL datatype of char.  It should be a VL, not a string class. */
    if((vlc_id = H5Tvlen_create(H5T_NATIVE_CHAR)) < 0) TEST_ERROR

    /* Make certain that the correct classes can be detected */
    if((tcls = H5Tget_class(vlc_id)) < 0) TEST_ERROR
    if(H5T_VLEN != tcls) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5T_STRING == tcls) TEST_ERROR

    /* Create a VL string.  It should be a string, not a VL class. */
    if((vls_id = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
    if(H5Tset_size(vls_id, H5T_VARIABLE) < 0) TEST_ERROR;

    /* Make certain that the correct classes can be detected */
    if((tcls = H5Tget_class(vls_id)) < 0) TEST_ERROR
    if(H5T_STRING != tcls) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5T_VLEN == tcls) TEST_ERROR

    /*-------------------------------------------------------------
     *  Check class for member types of compound type.
     *-----------------------------------------------------------*/
    /* Create a compound datatype and insert some complex types */
    if((cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct complex))) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_id, "vl_c", HOFFSET(struct complex, vl_c), vlc_id) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_id, "vl_s", HOFFSET(struct complex, vl_s), vls_id) < 0) TEST_ERROR

    if((nmembs = H5Tget_nmembers(cmpd_id)) < 0) TEST_ERROR

    for(u = 0; u < (unsigned)nmembs; u++) {
        /* Get member type ID */
        if((memb_id = H5Tget_member_type(cmpd_id, u)) < 0) TEST_ERROR

        /* Get member type class */
        if((memb_cls = H5Tget_member_class (cmpd_id, u)) < 0) TEST_ERROR

        /* Verify member class */
        if(H5Tdetect_class(memb_id, memb_cls) < 0) TEST_ERROR

        /* Close member type ID */
        if(H5Tclose(memb_id) < 0) TEST_ERROR
    } /* end for */

    /* Close datatypes */
    if(H5Tclose(cmpd_id) < 0) TEST_ERROR
    if(H5Tclose(vlc_id) < 0) TEST_ERROR
    if(H5Tclose(vls_id) < 0) TEST_ERROR

    PASSED();
    return 0;

  error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_copy
 *
 * Purpose:     Are we able to copy a datatype?
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Robb Matzke
 *              Tuesday, December  9, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_copy(void)
{
    hid_t               a_copy;
    herr_t		status;

    TESTING("H5Tcopy()");

    if ((a_copy = H5Tcopy(H5T_NATIVE_SHORT)) < 0) goto error;
    if (H5Tclose(a_copy) < 0) goto error;

    /* We should not be able to close a built-in byte */
    H5E_BEGIN_TRY {
	status = H5Tclose (H5T_NATIVE_SCHAR);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	HDputs ("    Should not be able to close a predefined type!");
	goto error;
    }

    PASSED();
    return 0;

  error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_detect
 *
 * Purpose:     Are we able to detect datatype classes correctly?  (Especially
 *              in nested types)
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Quincey Koziol
 *              Saturday, August 30, 2003
 *
 * Modifications:
 *              Raymond Lu
 *              8 December 2009
 *              I added a field of VL string in the compound type to test
 *              H5Tdetect_class correctly detect it as string type.
 *-------------------------------------------------------------------------
 */
static int
test_detect(void)
{
    struct atomic {     /* Struct with atomic fields */
        int i;
        float f;
        char c;
        double d;
        short s;
    };
    struct complex {    /* Struct with complex fields */
        hobj_ref_t arr_r[3][3];
        int i;
        hvl_t vl_f;
        hvl_t vl_s;
        char c;
        short s;
    };
    hid_t atom_cmpd_id; /* Atomic Compound datatype */
    hid_t atom_arr_id;  /* Atomic Array datatype */
    hid_t atom_vlf_id;  /* Atomic VL datatype of float */
    hid_t atom_vlc_id;  /* Atomic VL datatype of char */
    hid_t atom_vls_id;  /* Atomic VL string datatype */
    hid_t cplx_cmpd_id; /* Complex Compound datatype */
    unsigned rank = 2;  /* Rank for array datatype */
    hsize_t dims[2] = {3,3};    /* Dimensions for array datatype */

    TESTING("H5Tdetect_class()");

    /*--------------------------------------------------------------------------------
     *  Test class of some atomic types.
     *------------------------------------------------------------------------------*/
    /* Native integers should be in the integer class */
    if(H5Tdetect_class(H5T_NATIVE_INT,H5T_INTEGER)!=TRUE) TEST_ERROR

    /* Native integers should _not_ be in other classes */
    if(H5Tdetect_class(H5T_NATIVE_INT,H5T_FLOAT)!=FALSE) TEST_ERROR
    if(H5Tdetect_class(H5T_NATIVE_INT,H5T_ARRAY)!=FALSE) TEST_ERROR
    if(H5Tdetect_class(H5T_NATIVE_INT,H5T_ENUM)!=FALSE) TEST_ERROR

    /*--------------------------------------------------------------------------------
     *  Test class of a compound type with some atomic types as fields.
     *------------------------------------------------------------------------------*/
    /* Create a compound datatype and insert some atomic types */
    if ((atom_cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct atomic))) < 0) TEST_ERROR
    if (H5Tinsert(atom_cmpd_id, "i", HOFFSET(struct atomic, i), H5T_NATIVE_INT) < 0) TEST_ERROR
    if (H5Tinsert(atom_cmpd_id, "f", HOFFSET(struct atomic, f), H5T_NATIVE_FLOAT) < 0) TEST_ERROR
    if (H5Tinsert(atom_cmpd_id, "c", HOFFSET(struct atomic, c), H5T_NATIVE_CHAR) < 0) TEST_ERROR
    if (H5Tinsert(atom_cmpd_id, "d", HOFFSET(struct atomic, d), H5T_NATIVE_DOUBLE) < 0) TEST_ERROR
    if (H5Tinsert(atom_cmpd_id, "s", HOFFSET(struct atomic, s), H5T_NATIVE_SHORT) < 0) TEST_ERROR

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(atom_cmpd_id,H5T_COMPOUND)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(atom_cmpd_id,H5T_INTEGER)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(atom_cmpd_id,H5T_FLOAT)!=TRUE) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5Tdetect_class(atom_cmpd_id,H5T_VLEN)!=FALSE) TEST_ERROR

    /*--------------------------------------------------------------------------------
     *  Test class of some complex types.
     *------------------------------------------------------------------------------*/
    /* Create an array datatype with an atomic base type */
    if((atom_arr_id = H5Tarray_create2(H5T_STD_REF_OBJ, rank, dims)) < 0) TEST_ERROR

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(atom_arr_id,H5T_ARRAY)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(atom_arr_id,H5T_REFERENCE)!=TRUE) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5Tdetect_class(atom_arr_id,H5T_VLEN)!=FALSE) TEST_ERROR
    if(H5Tdetect_class(atom_arr_id,H5T_FLOAT)!=FALSE) TEST_ERROR
    if(H5Tdetect_class(atom_arr_id,H5T_INTEGER)!=FALSE) TEST_ERROR

    /* Create a VL datatype with an atomic base type of float*/
    if((atom_vlf_id=H5Tvlen_create(H5T_NATIVE_FLOAT)) < 0) TEST_ERROR

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(atom_vlf_id,H5T_VLEN)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(atom_vlf_id,H5T_FLOAT)!=TRUE) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5Tdetect_class(atom_vlf_id,H5T_COMPOUND)!=FALSE) TEST_ERROR
    if(H5Tdetect_class(atom_vlf_id,H5T_INTEGER)!=FALSE) TEST_ERROR

    /* Create a VL datatype with an atomic base type of char.  It should be a VL
     * but not a string class. */
    if((atom_vlc_id=H5Tvlen_create(H5T_NATIVE_CHAR)) < 0) TEST_ERROR

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(atom_vlc_id,H5T_VLEN)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(atom_vlc_id,H5T_INTEGER)!=TRUE) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5Tdetect_class(atom_vlc_id,H5T_STRING)!=FALSE) TEST_ERROR

    /* Create a VL string.  It should be a string, not a VL class. */
    if((atom_vls_id=H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
    if(H5Tset_size(atom_vls_id, H5T_VARIABLE) < 0) TEST_ERROR;

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(atom_vls_id,H5T_STRING)!=TRUE) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5Tdetect_class(atom_vls_id,H5T_VLEN)!=FALSE) TEST_ERROR

    /*--------------------------------------------------------------------------------
     *  Test class of a compound type with some complex types as fields.
     *------------------------------------------------------------------------------*/
    /* Create a compound datatype and insert some complex types */
    if ((cplx_cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct complex))) < 0) TEST_ERROR
    if (H5Tinsert(cplx_cmpd_id, "arr_r", HOFFSET(struct complex, arr_r), atom_arr_id) < 0) TEST_ERROR
    if (H5Tinsert(cplx_cmpd_id, "i", HOFFSET(struct complex, i), H5T_NATIVE_INT) < 0) TEST_ERROR
    if (H5Tinsert(cplx_cmpd_id, "vl_f", HOFFSET(struct complex, vl_f), atom_vlf_id) < 0) TEST_ERROR
    if (H5Tinsert(cplx_cmpd_id, "vl_s", HOFFSET(struct complex, vl_s), atom_vls_id) < 0) TEST_ERROR
    if (H5Tinsert(cplx_cmpd_id, "c", HOFFSET(struct complex, c), H5T_NATIVE_CHAR) < 0) TEST_ERROR
    if (H5Tinsert(cplx_cmpd_id, "s", HOFFSET(struct complex, s), H5T_NATIVE_SHORT) < 0) TEST_ERROR

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(cplx_cmpd_id,H5T_COMPOUND)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_ARRAY)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_REFERENCE)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_INTEGER)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_FLOAT)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_STRING)!=TRUE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_VLEN)!=TRUE) TEST_ERROR

    /* Make certain that an incorrect class is not detected */
    if(H5Tdetect_class(cplx_cmpd_id,H5T_TIME)!=FALSE) TEST_ERROR
    if(H5Tdetect_class(cplx_cmpd_id,H5T_ENUM)!=FALSE) TEST_ERROR

    /* Close complex compound datatype */
    if(H5Tclose(cplx_cmpd_id) < 0) TEST_ERROR

    /* Close atomic VL datatype of float */
    if(H5Tclose(atom_vlf_id) < 0) TEST_ERROR

    /* Close atomic VL datatype of char */
    if(H5Tclose(atom_vlc_id) < 0) TEST_ERROR

    /* Close atomic VL string datatype  */
    if(H5Tclose(atom_vls_id) < 0) TEST_ERROR

    /* Close atomic array datatype */
    if(H5Tclose(atom_arr_id) < 0) TEST_ERROR

    /* Close atomic compound datatype */
    if(H5Tclose(atom_cmpd_id) < 0) TEST_ERROR

    PASSED();
    return 0;

error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_1
 *
 * Purpose:     Tests various things about compound datatypes.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Robb Matzke
 *              Wednesday, January  7, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_1(void)
{
    hid_t               complex_id;
    hid_t               super;
    size_t              size;
    H5T_pad_t           lsb, msb;
    H5T_cset_t          cset;
    H5T_str_t           strpad;
    H5T_order_t         order;
    H5T_sign_t          sign;
    char               *tag = NULL;
    int                 offset;
    herr_t ret;
    int                 retval = 1;

    TESTING("compound datatypes");

    /* Create the empty type */
    if ((complex_id = H5Tcreate(H5T_COMPOUND, sizeof(complex_t))) < 0)
        goto error;

    /* Attempt to add the new compound datatype as a field within itself */
    H5E_BEGIN_TRY {
        ret=H5Tinsert(complex_id, "compound", (size_t)0, complex_id);
    } H5E_END_TRY;
    if (ret>=0) {
        FAIL_PUTS_ERROR("Inserted compound datatype into itself?");
    } /* end if */

    /* Add a couple fields */
    if(H5Tinsert(complex_id, "real", HOFFSET(complex_t, re), H5T_NATIVE_DOUBLE) < 0)
        goto error;
    if(H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im), H5T_NATIVE_DOUBLE) < 0)
        goto error;

    /* Test some functions that aren't supposed to work for compound type */
    H5E_BEGIN_TRY {
        size=H5Tget_precision(complex_id);
    } H5E_END_TRY;
    if (size>0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    size = 128;
    H5E_BEGIN_TRY {
        ret = H5Tset_precision(complex_id, size);
    } H5E_END_TRY;
    if (ret>=0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        ret = H5Tget_pad(complex_id, &lsb, &msb);
    } H5E_END_TRY;
    if (ret>=0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        size = H5Tget_ebias(complex_id);
    } H5E_END_TRY;
    if (size>0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        lsb = H5Tget_inpad(complex_id);
    } H5E_END_TRY;
    if (lsb>=0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        cset = H5Tget_cset(complex_id);
    } H5E_END_TRY;
    if (cset>-1) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        strpad = H5Tget_strpad(complex_id);
    } H5E_END_TRY;
    if (strpad>-1) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        offset = H5Tget_offset(complex_id);
    } H5E_END_TRY;
    if (offset>=0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        order = H5Tget_order(complex_id);
    } H5E_END_TRY;
    if (order>-1) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        sign = H5Tget_sign(complex_id);
    } H5E_END_TRY;
    if (sign>-1) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        tag = H5Tget_tag(complex_id);
    } H5E_END_TRY;
    if (tag) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        super = H5Tget_super(complex_id);
    } H5E_END_TRY;
    if (super>=0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    if (H5Tclose (complex_id) < 0)
        goto error;

    PASSED();
    retval = 0;

error:
    if(tag)
        HDfree(tag);
    return retval;
}


/*-------------------------------------------------------------------------
 * Function:	test_compound_2
 *
 * Purpose:	Tests a compound type conversion where the source and
 *		destination are the same except for the order of the
 *		elements.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, June 17, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_2(void)
{
    struct st {
	int a, b, c[4], d, e;
    } *s_ptr;
    struct dt {
	int e, d, c[4], b, a;
    } *d_ptr;

    const size_t	nelmts = NTESTELEM;
    const hsize_t	four = 4;
    unsigned char	*buf=NULL, *orig=NULL, *bkg=NULL;
    hid_t		st=-1, dt=-1;
    hid_t       array_dt;
    int			i, nmembs;

    TESTING("compound element reordering");

    if ((nmembs = H5I_nmembers(H5I_DATATYPE)) < 0)
        FAIL_STACK_ERROR

    /* Sizes should be the same, but be careful just in case */
    buf = (unsigned char*)malloc(nelmts * MAX(sizeof(struct st), sizeof(struct dt)));
    bkg = (unsigned char*)malloc(nelmts * sizeof(struct dt));
    orig = (unsigned char*)malloc(nelmts * sizeof(struct st));
    for (i=0; i<(int)nelmts; i++) {
	s_ptr = ((struct st*)orig) + i;
	s_ptr->a    = i*8+0;
	s_ptr->b    = i*8+1;
	s_ptr->c[0] = i*8+2;
	s_ptr->c[1] = i*8+3;
	s_ptr->c[2] = i*8+4;
	s_ptr->c[3] = i*8+5;
	s_ptr->d    = i*8+6;
	s_ptr->e    = i*8+7;
    }
    HDmemcpy(buf, orig, nelmts*sizeof(struct st));

    /* Build hdf5 datatypes */
    array_dt = H5Tarray_create2(H5T_NATIVE_INT,1, &four);
    if((st = H5Tcreate(H5T_COMPOUND, sizeof(struct st))) < 0 ||
            H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "c", HOFFSET(struct st, c), array_dt) < 0 ||
            H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT) < 0)
        goto error;
    H5Tclose(array_dt);

    array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four);
    if((dt = H5Tcreate(H5T_COMPOUND, sizeof(struct dt))) < 0 ||
            H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(dt, "c", HOFFSET(struct dt, c), array_dt) < 0 ||
            H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT) < 0)
        goto error;
    H5Tclose(array_dt);

    /* Perform the conversion */
    if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT) < 0) goto error;

    /* Compare results */
    for (i=0; i<(int)nelmts; i++) {
	s_ptr = ((struct st*)orig) + i;
	d_ptr = ((struct dt*)buf)  + i;
	if (s_ptr->a    != d_ptr->a    ||
	    s_ptr->b    != d_ptr->b    ||
	    s_ptr->c[0] != d_ptr->c[0] ||
	    s_ptr->c[1] != d_ptr->c[1] ||
	    s_ptr->c[2] != d_ptr->c[2] ||
	    s_ptr->c[3] != d_ptr->c[3] ||
	    s_ptr->d    != d_ptr->d    ||
	    s_ptr->e    != d_ptr->e) {
	    H5_FAILED();
	    printf("    i=%d\n", i);
	    printf("    src={a=%d, b=%d, c=[%d,%d,%d,%d], d=%d, e=%d\n",
		   s_ptr->a, s_ptr->b, s_ptr->c[0], s_ptr->c[1], s_ptr->c[2],
		   s_ptr->c[3], s_ptr->d, s_ptr->e);
	    printf("    dst={a=%d, b=%d, c=[%d,%d,%d,%d], d=%d, e=%d\n",
		   d_ptr->a, d_ptr->b, d_ptr->c[0], d_ptr->c[1], d_ptr->c[2],
		   d_ptr->c[3], d_ptr->d, d_ptr->e);
	    goto error;
	}
    }

    /* Release resources */
    free(buf);
    free(bkg);
    free(orig);
    CHECK_NMEMBS(nmembs , st, dt)

    PASSED();
    reset_hdf5();
    return 0;

 error:
    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_compound_3
 *
 * Purpose:	Tests compound conversions where the source and destination
 *		are the same except the destination is missing a couple
 *		members which appear in the source.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, June 17, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_3(void)
{
    struct st {
	int a, b, c[4], d, e;
    } *s_ptr;
    struct dt {
	int a,    c[4],    e;
    } *d_ptr;

    const size_t	nelmts = NTESTELEM;
    const hsize_t	four = 4;
    unsigned char	*buf=NULL, *orig=NULL, *bkg=NULL;
    hid_t		st=-1, dt=-1;
    hid_t       array_dt;
    int			i, nmembs;

    TESTING("compound subset conversions");

    if ((nmembs = H5I_nmembers(H5I_DATATYPE)) < 0)
        FAIL_STACK_ERROR

    /* Initialize */
    buf = (unsigned char*)malloc(nelmts * MAX(sizeof(struct st), sizeof(struct dt)));
    bkg = (unsigned char*)malloc(nelmts * sizeof(struct dt));
    orig = (unsigned char*)malloc(nelmts * sizeof(struct st));
    for (i=0; i<(int)nelmts; i++) {
        s_ptr = ((struct st*)orig) + i;
        s_ptr->a    = i*8+0;
        s_ptr->b    = i*8+1;
        s_ptr->c[0] = i*8+2;
        s_ptr->c[1] = i*8+3;
        s_ptr->c[2] = i*8+4;
        s_ptr->c[3] = i*8+5;
        s_ptr->d    = i*8+6;
        s_ptr->e    = i*8+7;
    }
    HDmemcpy(buf, orig, nelmts*sizeof(struct st));

    /* Build hdf5 datatypes */
    array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four);
    if((st = H5Tcreate(H5T_COMPOUND, sizeof(struct st))) < 0 ||
            H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "c", HOFFSET(struct st, c), array_dt) < 0 ||
            H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT) < 0)
        goto error;
    H5Tclose(array_dt);

    array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four);
    if((dt = H5Tcreate(H5T_COMPOUND, sizeof(struct dt))) < 0 ||
            H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(dt, "c", HOFFSET(struct dt, c), array_dt) < 0 ||
            H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT) < 0)
        goto error;
    H5Tclose(array_dt);

    /* Perform the conversion */
    if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT) < 0)
        goto error;

    /* Compare results */
    for (i=0; i<(int)nelmts; i++) {
	s_ptr = ((struct st*)orig) + i;
	d_ptr = ((struct dt*)buf)  + i;
	if (s_ptr->a    != d_ptr->a    ||
	    s_ptr->c[0] != d_ptr->c[0] ||
	    s_ptr->c[1] != d_ptr->c[1] ||
	    s_ptr->c[2] != d_ptr->c[2] ||
	    s_ptr->c[3] != d_ptr->c[3] ||
	    s_ptr->e    != d_ptr->e) {
	    H5_FAILED();
	    printf("    i=%d\n", i);
	    printf("    src={a=%d, b=%d, c=[%d,%d,%d,%d], d=%d, e=%d\n",
		   s_ptr->a, s_ptr->b, s_ptr->c[0], s_ptr->c[1], s_ptr->c[2],
		   s_ptr->c[3], s_ptr->d, s_ptr->e);
	    printf("    dst={a=%d, c=[%d,%d,%d,%d], e=%d\n",
		   d_ptr->a, d_ptr->c[0], d_ptr->c[1], d_ptr->c[2],
		   d_ptr->c[3], d_ptr->e);
	    goto error;
	}
    }

    /* Release resources */
    free(buf);
    free(bkg);
    free(orig);
    CHECK_NMEMBS(nmembs, st, dt)

    PASSED();
    reset_hdf5();
    return 0;

 error:
    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_compound_4
 *
 * Purpose:	Tests compound conversions when the destination has the same
 *		fields as the source but one or more of the fields are
 *		smaller.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, June 17, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_4(void)
{

    struct st {
	int a, b, c[4], d, e;
    } *s_ptr;
    struct dt {
	short b;
	int a, c[4];
	short d;
	int e;
    } *d_ptr;

    const size_t	nelmts = NTESTELEM;
    const hsize_t	four = 4;
    unsigned char	*buf=NULL, *orig=NULL, *bkg=NULL;
    hid_t		st=-1, dt=-1;
    hid_t       array_dt;
    int			i, nmembs;

    TESTING("compound element shrinking & reordering");

    if ((nmembs = H5I_nmembers(H5I_DATATYPE)) < 0)
        FAIL_STACK_ERROR

    /* Sizes should be the same, but be careful just in case */
    buf = (unsigned char*)malloc(nelmts * MAX(sizeof(struct st), sizeof(struct dt)));
    bkg = (unsigned char*)malloc(nelmts * sizeof(struct dt));
    orig = (unsigned char*)malloc(nelmts * sizeof(struct st));
    for (i=0; i<(int)nelmts; i++) {
        s_ptr = ((struct st*)orig) + i;
        s_ptr->a    = i*8+0;
        s_ptr->b    = (i*8+1) & 0x7fff;
        s_ptr->c[0] = i*8+2;
        s_ptr->c[1] = i*8+3;
        s_ptr->c[2] = i*8+4;
        s_ptr->c[3] = i*8+5;
        s_ptr->d    = (i*8+6) & 0x7fff;
        s_ptr->e    = i*8+7;
    }
    HDmemcpy(buf, orig, nelmts*sizeof(struct st));

    /* Build hdf5 datatypes */
    array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four);
    if((st = H5Tcreate(H5T_COMPOUND, sizeof(struct st))) < 0 ||
            H5Tinsert(st, "a", HOFFSET(struct st, a), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "c", HOFFSET(struct st, c), array_dt) < 0 ||
            H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(st, "e", HOFFSET(struct st, e), H5T_NATIVE_INT) < 0)
        goto error;
    H5Tclose(array_dt);

    array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, &four);
    if((dt = H5Tcreate(H5T_COMPOUND, sizeof(struct dt))) < 0 ||
            H5Tinsert(dt, "a", HOFFSET(struct dt, a), H5T_NATIVE_INT) < 0 ||
            H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_SHORT) < 0 ||
            H5Tinsert(dt, "c", HOFFSET(struct dt, c), array_dt) < 0 ||
            H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_SHORT) < 0 ||
            H5Tinsert(dt, "e", HOFFSET(struct dt, e), H5T_NATIVE_INT) < 0)
        goto error;
    H5Tclose(array_dt);

    /* Perform the conversion */
    if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT) < 0)
        goto error;

    /* Compare results */
    for (i=0; i<(int)nelmts; i++) {
	s_ptr = ((struct st*)orig) + i;
	d_ptr = ((struct dt*)buf)  + i;
	if (s_ptr->a    != d_ptr->a    ||
	    s_ptr->b    != d_ptr->b    ||
	    s_ptr->c[0] != d_ptr->c[0] ||
	    s_ptr->c[1] != d_ptr->c[1] ||
	    s_ptr->c[2] != d_ptr->c[2] ||
	    s_ptr->c[3] != d_ptr->c[3] ||
	    s_ptr->d    != d_ptr->d    ||
	    s_ptr->e    != d_ptr->e) {
	    H5_FAILED();
	    printf("    i=%d\n", i);
	    printf("    src={a=%d, b=%d, c=[%d,%d,%d,%d], d=%d, e=%d\n",
		   s_ptr->a, s_ptr->b, s_ptr->c[0], s_ptr->c[1], s_ptr->c[2],
		   s_ptr->c[3], s_ptr->d, s_ptr->e);
	    printf("    dst={a=%d, b=%d, c=[%d,%d,%d,%d], d=%d, e=%d\n",
		   d_ptr->a, d_ptr->b, d_ptr->c[0], d_ptr->c[1], d_ptr->c[2],
		   d_ptr->c[3], d_ptr->d, d_ptr->e);
	    goto error;
	}
    }

    /* Release resources */
    free(buf);
    free(bkg);
    free(orig);
    CHECK_NMEMBS(nmembs, st, dt)

    PASSED();
    reset_hdf5();
    return 0;

 error:
    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_compound_5
 *
 * Purpose:	Many versions of HDF5 have a bug in the optimized compound
 *              datatype conversion function, H5T_conv_struct_opt(), which
 *              is triggered when the top-level type contains a struct
 *              which must undergo a conversion.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, June 17, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_5(void)
{
    typedef struct {
        char    name[16];
        short   tdim;
        short   coll_ids[4];
    } src_type_t;

    typedef struct {
        char    name[16];
        short   tdim;
        int     coll_ids[4];
    } dst_type_t;

    hsize_t      dims[1] = {4};
    hid_t       src_type, dst_type, short_array, int_array, string;
    hid_t       array_dt;
    src_type_t  src[2] = {{"one", 102, {104, 105, 106, 107}},
                          {"two", 202, {204, 205, 206, 207}}};

    dst_type_t  *dst;
    void        *buf = HDcalloc((size_t)2, sizeof(dst_type_t));
    void        *bkg = HDcalloc((size_t)2, sizeof(dst_type_t));
    int          retval = 1;

#if 1
    TESTING("optimized struct converter");
#else
    /* Turn off optimized compound conversion function to work around
     * the problem. */
    TESTING("optimized struct converter bug workaround");
    H5Tunregister(H5T_PERS_DONTCARE, "struct(opt)", -1, -1, NULL);
#endif

    /* Build datatypes */
    short_array = H5Tcreate(H5T_COMPOUND, 4*sizeof(short));
    array_dt = H5Tarray_create2(H5T_NATIVE_SHORT, 1, dims);
    H5Tinsert(short_array, "_", (size_t)0, array_dt);
    H5Tclose(array_dt);

    int_array   = H5Tcreate(H5T_COMPOUND, 4*sizeof(int));
    array_dt = H5Tarray_create2(H5T_NATIVE_INT, 1, dims);
    H5Tinsert(int_array, "_", (size_t)0, array_dt);
    H5Tclose(array_dt);

    string = H5Tcopy(H5T_C_S1);
    H5Tset_size(string, (size_t)16);

    src_type = H5Tcreate(H5T_COMPOUND, sizeof(src_type_t));
    H5Tinsert(src_type, "name",     HOFFSET(src_type_t, name),             string          );
    H5Tinsert(src_type, "tdim",     HOFFSET(src_type_t, tdim),             H5T_NATIVE_SHORT);
    H5Tinsert(src_type, "coll_ids", HOFFSET(src_type_t, coll_ids),         short_array     );

    dst_type = H5Tcreate(H5T_COMPOUND, sizeof(dst_type_t));
    H5Tinsert(dst_type, "name",     HOFFSET(dst_type_t, name),             string          );
    H5Tinsert(dst_type, "tdim",     HOFFSET(dst_type_t, tdim),             H5T_NATIVE_SHORT);
    H5Tinsert(dst_type, "coll_ids", HOFFSET(dst_type_t, coll_ids),         int_array       );

    /* Convert data */
    HDmemcpy(buf, src, sizeof(src));
    H5Tconvert(src_type, dst_type, (size_t)2, buf, bkg, H5P_DEFAULT);
    dst = (dst_type_t*)buf;

    /* Cleanup */
    H5Tclose(src_type);
    H5Tclose(dst_type);
    H5Tclose(string);
    H5Tclose(short_array);
    H5Tclose(int_array);



    /* Check results */
    if (HDmemcmp(src[1].name, dst[1].name, sizeof(src[1].name)) ||
        src[1].tdim!=dst[1].tdim ||
        src[1].coll_ids[0]!=dst[1].coll_ids[0] ||
        src[1].coll_ids[1]!=dst[1].coll_ids[1] ||
        src[1].coll_ids[2]!=dst[1].coll_ids[2] ||
        src[1].coll_ids[3]!=dst[1].coll_ids[3]) {
        H5_FAILED();
    } else {
        PASSED();
        retval = 0;
    }

    /* Free memory buffers */
    if(buf)
        HDfree(buf);
    if(bkg)
        HDfree(bkg);
    return retval;
}


/*-------------------------------------------------------------------------
 * Function:	test_compound_6
 *
 * Purpose:	Tests compound conversions when the destination has the same
 *		fields as the source but one or more of the fields are
 *		larger.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Quincey Koziol
 *              Wednesday, December 13, 2000
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_6(void)
{

    struct st {
        short b;
        short d;
    } *s_ptr;
    struct dt {
        long b;
        long d;
    } *d_ptr;

    const size_t	nelmts = NTESTELEM;
    unsigned char	*buf=NULL, *orig=NULL, *bkg=NULL;
    hid_t		st=-1, dt=-1;
    int			i, nmembs;

    TESTING("compound element growing");

    if ((nmembs = H5I_nmembers(H5I_DATATYPE)) < 0)
        FAIL_STACK_ERROR

    /* Sizes should be the same, but be careful just in case */
    buf = (unsigned char*)malloc(nelmts * MAX(sizeof(struct st), sizeof(struct dt)));
    bkg = (unsigned char*)malloc(nelmts * sizeof(struct dt));
    orig = (unsigned char*)malloc(nelmts * sizeof(struct st));
    for (i=0; i<(int)nelmts; i++) {
        s_ptr = ((struct st*)orig) + i;
        s_ptr->b    = (i*8+1) & 0x7fff;
        s_ptr->d    = (i*8+6) & 0x7fff;
    }
    HDmemcpy(buf, orig, nelmts*sizeof(struct st));

    /* Build hdf5 datatypes */
    if ((st=H5Tcreate(H5T_COMPOUND, sizeof(struct st))) < 0 ||
            H5Tinsert(st, "b", HOFFSET(struct st, b), H5T_NATIVE_SHORT) < 0 ||
            H5Tinsert(st, "d", HOFFSET(struct st, d), H5T_NATIVE_SHORT) < 0) {
        H5_FAILED();
        goto error;
    }

    if ((dt=H5Tcreate(H5T_COMPOUND, sizeof(struct dt))) < 0 ||
            H5Tinsert(dt, "b", HOFFSET(struct dt, b), H5T_NATIVE_LONG) < 0 ||
            H5Tinsert(dt, "d", HOFFSET(struct dt, d), H5T_NATIVE_LONG) < 0) {
        H5_FAILED();
        goto error;
    }

    /* Perform the conversion */
    if (H5Tconvert(st, dt, nelmts, buf, bkg, H5P_DEFAULT) < 0) {
        H5_FAILED();
        goto error;
    }

    /* Compare results */
    for (i=0; i<(int)nelmts; i++) {
	s_ptr = ((struct st*)orig) + i;
	d_ptr = ((struct dt*)buf)  + i;
	if (s_ptr->b    != d_ptr->b    ||
	    s_ptr->d    != d_ptr->d) {
	    H5_FAILED();
	    printf("    i=%d\n", i);
	    printf("    src={b=%d, d=%d\n",
           (int)s_ptr->b, (int)s_ptr->d);
	    printf("    dst={b=%ld, d=%ld\n",
           d_ptr->b, d_ptr->d);
	    goto error;
	}
    }

    /* Release resources */
    free(buf);
    free(bkg);
    free(orig);
    CHECK_NMEMBS(nmembs, st, dt)

    PASSED();
    reset_hdf5();
    return 0;

 error:
    reset_hdf5();
    return 1;
}

/*-------------------------------------------------------------------------
 * Function:	test_compound_7
 *
 * Purpose:	Tests inserting fields into compound datatypes when the field
 *              overlaps the end of the compound datatype.  Also, tests
 *              increasing compound type size.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, December 18, 2001
 *
 * Modifications:
 *              The size of compound datatype can be expanded now.
 *              Raymond Lu
 *              Wednesday, September 10, 2003
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_7(void)
{
    struct s1 {
        int a;
        float b;
        long c;
    };

    struct s2 {
        int a;
        float b;
        long c;
        double d;
    };

    hid_t tid1,tid2;
    herr_t ret;

    TESTING("compound element insertion");

    if((tid1= H5Tcreate( H5T_COMPOUND, sizeof(struct s1))) < 0) {
        H5_FAILED();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(tid1,"a",HOFFSET(struct s1,a),H5T_NATIVE_INT) < 0) {
        H5_FAILED();
        printf("Can't insert field 'a'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(tid1,"b",HOFFSET(struct s1,b),H5T_NATIVE_FLOAT) < 0) {
        H5_FAILED();
        printf("Can't insert field 'b'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(tid1,"c",HOFFSET(struct s1,c),H5T_NATIVE_LONG) < 0) {
        H5_FAILED();
        printf("Can't insert field 'c'\n");
        goto error;
    } /* end if */

    if(H5Tget_size(tid1)!=sizeof(struct s1)) {
        H5_FAILED();
        printf("Incorrect size for struct 1\n");
        goto error;
    } /* end if */

    if((tid2= H5Tcopy(tid1)) < 0) {
        H5_FAILED();
        printf("Can't copy datatype\n");
        goto error;
    } /* end if */

    if(H5Tget_size(tid2)==sizeof(struct s2)) {
        H5_FAILED();
        printf("Incorrect size for struct 2\n");
        goto error;
    } /* end if */

    /* Should not be able to insert field past end of compound datatype */
    H5E_BEGIN_TRY {
        ret=H5Tinsert(tid2,"d",HOFFSET(struct s2,d),H5T_NATIVE_DOUBLE);
    } H5E_END_TRY;
    if(ret>=0) {
        H5_FAILED();
        printf("Inserted field 'd'?\n");
        goto error;
    } /* end if */

    /* Should not be able to shrink size of compound datatype */
    H5E_BEGIN_TRY {
        ret=H5Tset_size(tid2, sizeof(struct s1)/2);
    } H5E_END_TRY;
    if(ret>=0) {
        H5_FAILED();
        printf("Shrunk compound type?\n");
        goto error;
    } /* end if */

    /* Increase compound type size and try inserting field again */
    if(H5Tset_size(tid2, sizeof(struct s2)) < 0) {
        H5_FAILED();
        printf("Can't increase size for compound type\n");
        goto error;
    } /* end if */

    if( H5Tinsert(tid2,"d",HOFFSET(struct s2,d),H5T_NATIVE_DOUBLE) < 0) {
        H5_FAILED();
        printf("Can't expand compound datatype\n");
        goto error;
    } /* end if */

    if(H5Tget_size(tid2)!=sizeof(struct s2)) {
        H5_FAILED();
        printf("Incorrect size for struct 2\n");
        goto error;
    } /* end if */

    /* Release resources */
    if (H5Tclose(tid1) < 0 || H5Tclose(tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatypes\n");
        goto error;
    } /* end if */

    PASSED();
    reset_hdf5();
    return 0;

 error:
    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_8
 *
 * Purpose:     Tests H5Tpack for compound datatypes.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Robb Matzke
 *              Wednesday, January  7, 1998
 *
 * Modifications:
 *              Raymond Lu
 *              27 June 2008
 *              Added verification of compound type size for H5Tpack and
 *              test for array of nested compound type.
 *-------------------------------------------------------------------------
 */
static int
test_compound_8(void)
{
    typedef struct s1 {
        char    a;
        int     b;
    } s1;

    typedef struct s2 {
        char    c;
        s1      d;
    } s2;
    hid_t  tid1, tid1_copy, tid2, tid2_copy, tid3, arr_tid;
    size_t tsize;
    hsize_t dims[1] = {ARRAY_DIM};
    herr_t ret;

    TESTING("packing compound datatypes");

    /*------------------------------------------------------------
     *    Test H5Tpack for compound type
     */
    /* Create first compound datatype */
    if((tid1 = H5Tcreate( H5T_COMPOUND, sizeof(struct s1))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(tid1,"a",HOFFSET(struct s1,a),H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'a'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(tid1,"b",HOFFSET(struct s1,b),H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'b'\n");
        goto error;
    } /* end if */

    /* Make a copy of the type for later use */
    if((tid1_copy = H5Tcopy(tid1)) < 0) {
        H5_FAILED(); AT();
        printf("Can't copy type #1\n");
        goto error;
    } /* end if */

    /* Test H5Tpack for the first compound type */
    if(H5Tpack(tid1) < 0) {
        H5_FAILED(); AT();
        printf("Can't pack the compound datatype\n");
        goto error;
    } /* end if */

    if(H5Tlock(tid1) < 0) {
        H5_FAILED(); AT();
        printf("Can't lock the compound datatype\n");
        goto error;
    } /* end if */

    /* If the type is already packed, packing a locked type is OK */
    if(H5Tpack(tid1) < 0) {
        H5_FAILED(); AT();
        printf("Can't pack the compound datatype for second time\n");
        goto error;
    } /* end if */

    /* Verify the size of packed compound type */
    if((tsize = H5Tget_size(tid1)) == 0) {
        H5_FAILED(); AT();
        printf("Can't get size of the compound datatype\n");
        goto error;
    } /* end if */

    if(tsize != (sizeof(char) + sizeof(int))) {
        H5_FAILED(); AT();
        printf("The size of the packed compound datatype is incorrect\n");
        goto error;
    } /* end if */

    /*------------------------------------------------------------
     *    Test H5Tpack for nested compound type
     */
    /* Create second compound datatype */
    if((tid2 = H5Tcreate( H5T_COMPOUND, sizeof(struct s2))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(tid2,"c",HOFFSET(struct s2,c),H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c'\n");
        goto error;
    } /* end if */

    /* Insert the member of unpacked compound type */
    if(H5Tinsert(tid2,"d",HOFFSET(struct s2,d),tid1_copy) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'd'\n");
        goto error;
    } /* end if */

    /* Make a copy of the type for later */
    if((tid3=H5Tcopy(tid2)) < 0) {
        H5_FAILED(); AT();
        printf("Can't copy type #2\n");
        goto error;
    } /* end if */

    /* Make a copy of the type for later */
    if((tid2_copy = H5Tcopy(tid2)) < 0) {
        H5_FAILED(); AT();
        printf("Can't copy type #2\n");
        goto error;
    } /* end if */

    /* Test H5Tpack for the second compound type */
    if(H5Tpack(tid2) < 0) {
        H5_FAILED(); AT();
        printf("Can't pack the compound datatype\n");
        goto error;
    } /* end if */

    if(H5Tlock(tid2) < 0) {
        H5_FAILED(); AT();
        printf("Can't lock the compound datatype\n");
        goto error;
    } /* end if */

    /* If the type is already packed, packing a locked type is OK */
    if(H5Tpack(tid2) < 0) {
        H5_FAILED(); AT();
        printf("Can't pack the compound datatype for second time\n");
        goto error;
    } /* end if */

    /* Lock unpacked type */
    if(H5Tlock(tid3) < 0) {
        H5_FAILED(); AT();
        printf("Can't lock the compound datatype\n");
        goto error;
    } /* end if */

    /* If the type is not packed, packing a locked type shouldn't work */
    H5E_BEGIN_TRY {
        ret=H5Tpack(tid3);
    } H5E_END_TRY;
    if(ret>=0) {
        H5_FAILED(); AT();
        printf("Packing locked datatype worked?\n");
        goto error;
    } /* end if */

    /* Verify the size of packed compound type */
    if((tsize = H5Tget_size(tid2)) == 0) {
        H5_FAILED(); AT();
        printf("Can't get size of the compound datatype\n");
        goto error;
    } /* end if */

    if(tsize != (sizeof(char) + sizeof(char) + sizeof(int))) {
        H5_FAILED(); AT();
        printf("The size of the packed compound datatype is incorrect\n");
        goto error;
    } /* end if */

    /*------------------------------------------------------------
     *    Test H5Tpack for array type of nested compound type
     */
    /* Create an array type of compound type */
    if((arr_tid = H5Tarray_create2(tid2_copy, 1, dims)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create an array datatype\n");
        goto error;
    } /* end if */

    /* Test H5Tpack for the array type */
    if(H5Tpack(arr_tid) < 0) {
        H5_FAILED(); AT();
        printf("Can't pack the array datatype\n");
        goto error;
    } /* end if */

    /* Verify the size of packed compound type */
    if((tsize = H5Tget_size(arr_tid)) == 0) {
        H5_FAILED(); AT();
        printf("Can't get size of the array datatype\n");
        goto error;
    } /* end if */

    if(tsize != ARRAY_DIM * (sizeof(char) + sizeof(char) + sizeof(int))) {
        H5_FAILED(); AT();
        printf("The size of the packed array datatype is incorrect\n");
        goto error;
    } /* end if */


    if(H5Tclose(tid1_copy) < 0) {
        H5_FAILED(); AT();
        printf("Can't close the compound datatype\n");
        goto error;
    } /* end if */

    if(H5Tclose(tid2_copy) < 0) {
        H5_FAILED(); AT();
        printf("Can't close the compound datatype\n");
        goto error;
    } /* end if */

    if(H5Tclose(arr_tid) < 0) {
        H5_FAILED(); AT();
        printf("Can't close the array datatype\n");
        goto error;
    } /* end if */

    /* Can't release resources - they are locked */

    PASSED();
    return 0;

  error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_9
 *
 * Purpose:     Tests compound datatype with VL string as field.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Raymond Lu
 *              Wednesday, June 9, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_9(void)
{
    typedef struct cmpd_struct {
       int    i1;
       char*  str;
       int    i2;
    } cmpd_struct;

    cmpd_struct wdata = {11, "variable-length string", 22};
    cmpd_struct rdata;
    hid_t       file;
    hid_t       cmpd_tid, str_id, dup_tid;
    hid_t       space_id;
    hid_t       dset_id;
    hsize_t     dim1[1];
    char        filename[1024];

    TESTING("compound datatype with VL string");

    /* Create File */
    h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create file!\n");
        goto error;
    } /* end if */

    /* Create first compound datatype */
    if((cmpd_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid,"i1",HOFFSET(struct cmpd_struct,i1),H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i1'\n");
        goto error;
    } /* end if */

    str_id = H5Tcopy(H5T_C_S1);
    if(H5Tset_size(str_id,H5T_VARIABLE) < 0) {
        H5_FAILED(); AT();
        printf("Can't set size for VL string\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid, "vl_string", HOFFSET(cmpd_struct, str), str_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid, "i2", HOFFSET(struct cmpd_struct, i2), H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i2'\n");
        goto error;
    } /* end if */

    if(H5Tcommit2(file, "compound", cmpd_tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
        H5_FAILED(); AT();
        printf("Can't commit datatype\n");
        goto error;
    } /* end if */

    if(H5Tclose(cmpd_tid) < 0) {
        H5_FAILED(); AT();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */

    if((cmpd_tid = H5Topen2(file, "compound", H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    if((dup_tid = H5Tcopy(cmpd_tid)) < 0) {
        H5_FAILED(); AT();
        printf("Can't copy datatype\n");
        goto error;
    } /* end if */

    dim1[0] = 1;
    if((space_id = H5Screate_simple(1, dim1, NULL)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create space\n");
        goto error;
    } /* end if */

    if((dset_id = H5Dcreate2(file, "Dataset", dup_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create dataset\n");
        goto error;
    } /* end if */

    if(H5Dwrite(dset_id, dup_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't write data\n");
        goto error;
    } /* end if */

    if(H5Dread(dset_id, dup_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    if(rdata.i1 != wdata.i1 || rdata.i2 != wdata.i2 || HDstrcmp(rdata.str, wdata.str)) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    if(H5Dclose(dset_id) < 0)
        goto error;
    if(H5Tclose(cmpd_tid) < 0)
        goto error;
    if(H5Tclose(dup_tid) < 0)
        goto error;
    if(H5Tclose(str_id) < 0)
        goto error;
    if(H5Sclose(space_id) < 0)
        goto error;
    if(H5Fclose(file) < 0)
        goto error;


    if((file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("cannot open file\n");
        goto error;
    } /* end if */

    if((dset_id = H5Dopen2(file, "Dataset", H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("cannot open dataset\n");
        goto error;
    } /* end if */

    if((cmpd_tid = H5Dget_type(dset_id)) < 0) {
         H5_FAILED(); AT();
        printf("cannot open dataset\n");
        goto error;
    } /* end if */

    if((dup_tid = H5Tcopy(cmpd_tid)) < 0) {
        H5_FAILED(); AT();
        printf("Can't copy datatype\n");
        goto error;
    } /* end if */

    rdata.i1 = rdata.i2 = 0;
    if(rdata.str) free(rdata.str);

    if(H5Dread(dset_id, dup_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    if(rdata.i1!=wdata.i1 || rdata.i2!=wdata.i2 || strcmp(rdata.str, wdata.str)) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    if(rdata.str) free(rdata.str);

    if(H5Dclose(dset_id) < 0)
        goto error;
    if(H5Tclose(cmpd_tid) < 0)
        goto error;
    if(H5Tclose(dup_tid) < 0)
        goto error;
    if(H5Fclose(file) < 0)
        goto error;

    PASSED();
    return 0;

 error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_10
 *
 * Purpose:     Tests array datatype of compound type with VL string as field.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Raymond Lu
 *              Tuesday, June 15, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_10(void)
{
    typedef struct cmpd_struct {
       int          i1;
       char*        str;
       hvl_t        text;
       int          i2;
    } cmpd_struct;

    cmpd_struct wdata[ARRAY_DIM];
    cmpd_struct rdata[ARRAY_DIM];
    hid_t       file;
    hid_t       arr_tid, cmpd_tid, cstr_id, vlstr_id;
    hid_t       space_id;
    hid_t       dset_id;
    hsize_t     arr_dim[1] = {ARRAY_DIM};  /* Array dimensions */
    hsize_t     dim1[1];
    void        *t1, *t2;
    char        filename[1024];
    int         len;
    int         i;

    TESTING("array datatype of compound type with VL string");

    for(i=0; i<ARRAY_DIM; i++) {
        wdata[i].i1 = i*10+i;
        wdata[i].str = HDstrdup("C string A");
        wdata[i].str[9] += i;
        wdata[i].i2 = i*1000+i*10;

        wdata[i].text.p   = (void*)HDstrdup("variable-length text A\0");
        len = wdata[i].text.len = strlen((char*)wdata[i].text.p)+1;
        ((char*)(wdata[i].text.p))[len-2] += i;
        ((char*)(wdata[i].text.p))[len-1] = '\0';
    }

    /* Create File */
    h5_fixname(FILENAME[4], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create file!\n");
        goto error;
    } /* end if */

    /* Create first compound datatype */
    if((cmpd_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid,"i1",HOFFSET(struct cmpd_struct,i1),H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i1'\n");
        goto error;
    } /* end if */

    cstr_id = H5Tcopy(H5T_C_S1);
    if(H5Tset_size(cstr_id,H5T_VARIABLE) < 0) {
        H5_FAILED(); AT();
        printf("Can't set size for C string\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid,"c_string",HOFFSET(cmpd_struct,str),cstr_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'str'\n");
        goto error;
    } /* end if */

    /* Create vl-string datatype */
    if((vlstr_id =  H5Tvlen_create(H5T_NATIVE_CHAR)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create VL string\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid, "vl_string",HOFFSET(cmpd_struct, text), vlstr_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'text'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_tid,"i2",HOFFSET(struct cmpd_struct,i2),H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i2'\n");
        goto error;
    } /* end if */

    /* Create the array datatype for c_string data */
    if((arr_tid = H5Tarray_create2(cmpd_tid, 1, arr_dim)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create array type\n");
        goto error;
    } /* end if */

    dim1[0] = 1;
    if((space_id = H5Screate_simple(1,dim1,NULL)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create space\n");
        goto error;
    } /* end if */

    if((dset_id = H5Dcreate2(file, "Dataset", arr_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create dataset\n");
        goto error;
    } /* end if */

    if(H5Dwrite(dset_id, arr_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't write data\n");
        goto error;
    } /* end if */

    if(H5Dread(dset_id, arr_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    for(i = 0; i < ARRAY_DIM; i++) {
        if(rdata[i].i1 != wdata[i].i1 || rdata[i].i2 != wdata[i].i2 ||
            HDstrcmp(rdata[i].str, wdata[i].str)) {
            H5_FAILED(); AT();
            printf("incorrect read data\n");
            goto error;
        } /* end if */

        if(rdata[i].text.len!=wdata[i].text.len) {
            H5_FAILED(); AT();
            printf("incorrect VL length\n");
            goto error;
        } /* end if */

        t1 = rdata[i].text.p;
        t2 = wdata[i].text.p;
        if(strcmp((char*)t1, (char*)t2)) {
            H5_FAILED(); AT();
            printf("incorrect VL read data\n");
            goto error;
        }

        free(t1);
        free(t2);
        free(wdata[i].str);
        free(rdata[i].str);
    } /* end for */

    if(H5Dclose(dset_id) < 0)
        goto error;
    if(H5Tclose(arr_tid) < 0)
        goto error;
    if(H5Tclose(cmpd_tid) < 0)
        goto error;
    if(H5Tclose(cstr_id) < 0)
        goto error;
    if(H5Tclose(vlstr_id) < 0)
        goto error;
    if(H5Sclose(space_id) < 0)
        goto error;
    if(H5Fclose(file) < 0)
        goto error;

    PASSED();
    return 0;

 error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_11
 *
 * Purpose:     Tests whether registering/unregistering a type conversion
 *              function correctly causes compound datatypes to recalculate
 *              their cached field conversion information
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Quincey Koziol
 *              Saturday, August 7, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_11(void)
{
    typedef struct {
        double d1;
        int i1;
        char *s1;
        int i2;
        double d2;
        double d3;
    } big_t;

    typedef struct {
        double d1;
        int i1;
        char *s1;
    } little_t;

    hid_t var_string_tid;  /* Datatype IDs for type conversion */
    hid_t big_tid, little_tid;  /* Datatype IDs for type conversion */
    hid_t big_tid2, little_tid2;  /* Datatype IDs for type conversion */
    hid_t opaq_src_tid, opaq_dst_tid;  /* Datatype IDs for type conversion */
    void *buf = NULL;          /* Conversion buffer */
    void *buf_orig = NULL;      /* Copy of original conversion buffer */
    void *bkg = NULL;           /* Background buffer */
    size_t u;           /* Local index variable */
    int retval = 1;

    TESTING("registering type conversion routine with compound conversions");

    /* Create variable string type for use in both structs */
    if((var_string_tid=H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
    if(H5Tset_size(var_string_tid,H5T_VARIABLE) < 0) TEST_ERROR

    /* Create type for 'big' struct */
    if((big_tid = H5Tcreate(H5T_COMPOUND, sizeof(big_t))) < 0) TEST_ERROR

    if(H5Tinsert(big_tid, "d1", HOFFSET(big_t, d1), H5T_NATIVE_DOUBLE) < 0) TEST_ERROR
    if(H5Tinsert(big_tid, "i1", HOFFSET(big_t, i1), H5T_NATIVE_INT) < 0) TEST_ERROR
    if(H5Tinsert(big_tid, "s1", HOFFSET(big_t, s1), var_string_tid) < 0) TEST_ERROR
    if(H5Tinsert(big_tid, "i2", HOFFSET(big_t, i2), H5T_NATIVE_INT) < 0) TEST_ERROR
    if(H5Tinsert(big_tid, "d2", HOFFSET(big_t, d2), H5T_NATIVE_DOUBLE) < 0) TEST_ERROR
    if(H5Tinsert(big_tid, "d3", HOFFSET(big_t, d3), H5T_NATIVE_DOUBLE) < 0) TEST_ERROR

    /* Create type for 'little' struct (with "out of order" inserts) */
    if((little_tid = H5Tcreate(H5T_COMPOUND, sizeof(little_t))) < 0) TEST_ERROR

    if(H5Tinsert(little_tid, "d1", HOFFSET(little_t, d1), H5T_NATIVE_DOUBLE) < 0) TEST_ERROR
    if(H5Tinsert(little_tid, "s1", HOFFSET(little_t, s1), var_string_tid) < 0) TEST_ERROR
    if(H5Tinsert(little_tid, "i1", HOFFSET(little_t, i1), H5T_NATIVE_INT) < 0) TEST_ERROR

    /* Allocate buffers */
    if((buf=HDmalloc(sizeof(big_t)*NTESTELEM))==NULL) TEST_ERROR
    if((buf_orig=HDmalloc(sizeof(big_t)*NTESTELEM))==NULL) TEST_ERROR
    if((bkg=HDmalloc(sizeof(big_t)*NTESTELEM))==NULL) TEST_ERROR

    /* Initialize buffer */
    for(u = 0; u < NTESTELEM; u++) {
        ((big_t *)buf)[u].d1 = (double)u * (double)1.5;
        ((big_t *)buf)[u].d2 = (double)u * (double)2.5;
        ((big_t *)buf)[u].d3 = (double)u * (double)3.5;
        ((big_t *)buf)[u].i1 = u * 3;
        ((big_t *)buf)[u].i2 = u * 5;
        ((big_t *)buf)[u].s1 = (char *)HDmalloc((size_t)32);
        sprintf(((big_t *)buf)[u].s1, "%u", (unsigned)u);
    } /* end for */

    /* Make copy of buffer before conversion */
    HDmemcpy(buf_orig,buf,sizeof(big_t)*NTESTELEM);

    /* Make copies of the 'big' and 'little' datatypes, so the type
     * conversion routine doesn't use the same ones this time and next time
     */
    if((big_tid2=H5Tcopy(big_tid)) < 0) TEST_ERROR
    if((little_tid2=H5Tcopy(little_tid)) < 0) TEST_ERROR

    /* Convert buffer from 'big' to 'little' struct */
    if(H5Tconvert(big_tid2,little_tid2,(size_t)NTESTELEM,buf,bkg,H5P_DEFAULT) < 0) TEST_ERROR

    /* Verify converted buffer is correct */
    for(u=0; u<NTESTELEM; u++) {
        if(((big_t *)buf_orig)[u].d1!=((little_t *)buf)[u].d1) {
            printf("Error, line #%d: buf_orig[%u].d1=%f, buf[%u].d1=%f\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].d1,(unsigned)u,((little_t *)buf)[u].d1);
            TEST_ERROR
        } /* end if */
        if(((big_t *)buf_orig)[u].i1!=((little_t *)buf)[u].i1) {
            printf("Error, line #%d: buf_orig[%u].i1=%d, buf[%u].i1=%d\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].i1,(unsigned)u,((little_t *)buf)[u].i1);
            TEST_ERROR
        } /* end if */
        if(((big_t *)buf_orig)[u].s1==NULL || ((little_t *)buf)[u].s1==NULL) {
            printf("Error, line #%d: buf_orig[%u].s1=%p, buf[%u].s1=%p\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].s1,(unsigned)u,((little_t *)buf)[u].s1);
            TEST_ERROR
        } /* end if */
        else if(HDstrcmp(((big_t *)buf_orig)[u].s1,((little_t *)buf)[u].s1)) {
            printf("Error, line #%d: buf_orig[%u].s1=%s, buf[%u].s1=%s\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].s1,(unsigned)u,((little_t *)buf)[u].s1);
            TEST_ERROR
        } /* end if */
        HDfree(((little_t *)buf)[u].s1);
    } /* end for */

    /* Build source and destination types for conversion routine */
    if((opaq_src_tid=H5Tcreate(H5T_OPAQUE, (size_t)4)) < 0) TEST_ERROR
    if(H5Tset_tag(opaq_src_tid, "opaque source type") < 0) TEST_ERROR
    if((opaq_dst_tid=H5Tcreate(H5T_OPAQUE, (size_t)4)) < 0) TEST_ERROR
    if(H5Tset_tag(opaq_dst_tid, "opaque destination type") < 0) TEST_ERROR

    /* Register new type conversion routine */
    if(H5Tregister(H5T_PERS_HARD, "opaq_test", opaq_src_tid, opaq_dst_tid, convert_opaque) < 0) TEST_ERROR

    /* Recover the original buffer information */
    HDmemcpy(buf,buf_orig,sizeof(big_t)*NTESTELEM);

    /* Convert buffer from 'big' to 'little' struct */
    if(H5Tconvert(big_tid,little_tid,(size_t)NTESTELEM,buf,bkg,H5P_DEFAULT) < 0) TEST_ERROR

    /* Verify converted buffer is correct */
    for(u=0; u<NTESTELEM; u++) {
        if(((big_t *)buf_orig)[u].d1!=((little_t *)buf)[u].d1) {
            printf("Error, line #%d: buf_orig[%u].d1=%f, buf[%u].d1=%f\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].d1,(unsigned)u,((little_t *)buf)[u].d1);
            TEST_ERROR
        } /* end if */
        if(((big_t *)buf_orig)[u].i1!=((little_t *)buf)[u].i1) {
            printf("Error, line #%d: buf_orig[%u].i1=%d, buf[%u].i1=%d\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].i1,(unsigned)u,((little_t *)buf)[u].i1);
            TEST_ERROR
        } /* end if */
        if(((big_t *)buf_orig)[u].s1==NULL || ((little_t *)buf)[u].s1==NULL) {
            printf("Error, line #%d: buf_orig[%u].s1=%p, buf[%u].s1=%p\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].s1,(unsigned)u,((little_t *)buf)[u].s1);
            TEST_ERROR
        } /* end if */
        else if(HDstrcmp(((big_t *)buf_orig)[u].s1,((little_t *)buf)[u].s1)) {
            printf("Error, line #%d: buf_orig[%u].s1=%s, buf[%u].s1=%s\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].s1,(unsigned)u,((little_t *)buf)[u].s1);
            TEST_ERROR
        } /* end if */
        HDfree(((little_t *)buf)[u].s1);
    } /* end for */

    /* Unregister the conversion routine */
    if(H5Tunregister(H5T_PERS_HARD, "opaq_test", opaq_src_tid, opaq_dst_tid, convert_opaque) < 0) TEST_ERROR

    /* Recover the original buffer information */
    HDmemcpy(buf,buf_orig,sizeof(big_t)*NTESTELEM);

    /* Convert buffer from 'big' to 'little' struct */
    if(H5Tconvert(big_tid,little_tid,(size_t)NTESTELEM,buf,bkg,H5P_DEFAULT) < 0) TEST_ERROR

    /* Verify converted buffer is correct */
    for(u=0; u<NTESTELEM; u++) {
        if(((big_t *)buf_orig)[u].d1!=((little_t *)buf)[u].d1) {
            printf("Error, line #%d: buf_orig[%u].d1=%f, buf[%u].d1=%f\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].d1,(unsigned)u,((little_t *)buf)[u].d1);
            TEST_ERROR
        } /* end if */
        if(((big_t *)buf_orig)[u].i1!=((little_t *)buf)[u].i1) {
            printf("Error, line #%d: buf_orig[%u].i1=%d, buf[%u].i1=%d\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].i1,(unsigned)u,((little_t *)buf)[u].i1);
            TEST_ERROR
        } /* end if */
        if(((big_t *)buf_orig)[u].s1==NULL || ((little_t *)buf)[u].s1==NULL) {
            printf("Error, line #%d: buf_orig[%u].s1=%p, buf[%u].s1=%p\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].s1,(unsigned)u,((little_t *)buf)[u].s1);
            TEST_ERROR
        } /* end if */
        else if(HDstrcmp(((big_t *)buf_orig)[u].s1,((little_t *)buf)[u].s1)) {
            printf("Error, line #%d: buf_orig[%u].s1=%s, buf[%u].s1=%s\n",__LINE__,
                    (unsigned)u,((big_t *)buf_orig)[u].s1,(unsigned)u,((little_t *)buf)[u].s1);
            TEST_ERROR
        } /* end if */
        HDfree(((little_t *)buf)[u].s1);
    } /* end for */

    /* Free everything */
    for(u=0; u<NTESTELEM; u++)
        HDfree(((big_t *)buf_orig)[u].s1);
    if(H5Tclose(opaq_dst_tid) < 0) TEST_ERROR
    if(H5Tclose(opaq_src_tid) < 0) TEST_ERROR
    if(H5Tclose(little_tid2) < 0) TEST_ERROR
    if(H5Tclose(big_tid2) < 0) TEST_ERROR
    if(H5Tclose(little_tid) < 0) TEST_ERROR
    if(H5Tclose(big_tid) < 0) TEST_ERROR
    if(H5Tclose(var_string_tid) < 0) TEST_ERROR

    PASSED();
    retval = 0;

error:
    if(buf)
        HDfree(buf);
    if(buf_orig)
        HDfree(buf_orig);
    if(bkg)
        HDfree(bkg);
    return retval;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_12
 *
 * Purpose:     Tests size adjustment of compound datatypes.  Start with
 *              no member and 0 size, increase the size as inserting
 *              members.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Raymond Lu
 *              Wednesday, September 29, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_12(void)
{
    hid_t                   complex_id;
    size_t                  size = 0;
    size_t                  offset, new_size, tmp_size;
    herr_t ret;

    TESTING("adjust size of compound datatypes");

    /* Create a compound type of minimal size */
    if ((complex_id = H5Tcreate(H5T_COMPOUND, (size_t)1)) < 0) goto error;

    /* Verify the size */
    if((new_size=H5Tget_size(complex_id))==0) goto error;
    if(new_size!=1) goto error;

    /* Add a couple fields and adjust the size */
    offset = size;
    if((tmp_size=H5Tget_size(H5T_NATIVE_DOUBLE))==0) goto error;
    size+=tmp_size;
    if (H5Tset_size(complex_id, size) < 0) goto error;
    if (H5Tinsert(complex_id, "real", offset,
		  H5T_NATIVE_DOUBLE) < 0) goto error;

    offset = size;
    if((tmp_size=H5Tget_size(H5T_NATIVE_DOUBLE))==0) goto error;
    size+=tmp_size;
    if (H5Tset_size(complex_id, size) < 0) goto error;
    if (H5Tinsert(complex_id, "imaginary", offset,
		  H5T_NATIVE_DOUBLE) < 0) goto error;

    /* Increase and decrease the size. */
    if((tmp_size=H5Tget_size(H5T_NATIVE_DOUBLE))==0) goto error;
    size+=tmp_size;
    if (H5Tset_size(complex_id, size) < 0) goto error;

    if((tmp_size=H5Tget_size(H5T_NATIVE_DOUBLE))==0) goto error;
    size-=tmp_size;
    if (H5Tset_size(complex_id, size) < 0) goto error;

    /* Verify the size */
    if((new_size=H5Tget_size(complex_id))==0) goto error;
    if(new_size!=size) goto error;

    /* Tries to cut last member.  Supposed to fail. */
    size--;
    H5E_BEGIN_TRY {
        ret = H5Tset_size(complex_id, size);
    } H5E_END_TRY;
    if(ret>=0) {
        H5_FAILED();
        puts("  Tries to cut off the last member. Should have failed.");
        goto error;
    }

    if (H5Tclose (complex_id) < 0) goto error;
    PASSED();
    return 0;

  error:
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_compound_13
 *
 * Purpose:     Tests compound datatypes whose size is at the boundary for
 *              needing 2 bytes for the datatype size and "use the latest
 *              format" flag is enabled so that the size of the offsets uses
 *              the smallest # of bytes possible.
 *
 * Return:      Success:        0
 *              Failure:        number of errors
 *
 * Programmer:  Quincey Koziol
 *              Thursday, March 13, 2008
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_13(void)
{
    struct s1 {
        unsigned char x[COMPOUND13_ARRAY_SIZE + 1];
        float y;
    };
    struct s1   data_out, data_in;
    hid_t       fileid, grpid, dtypeid, array1_tid, spaceid, attid;
    hid_t       fapl_id;
    hsize_t     dims[1] = {COMPOUND13_ARRAY_SIZE + 1};
    char        filename[1024];
    unsigned    u;

    TESTING("compound datatypes of boundary size with latest format");

    /* Create some phony data. */
    for(u = 0; u < COMPOUND13_ARRAY_SIZE + 1; u++)
        data_out.x[u] = u;
    data_out.y = 99.99;

    /* Set latest_format in access propertly list to enable the latest
     * compound datatype format.
     */
    if((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) FAIL_STACK_ERROR
    if(H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) FAIL_STACK_ERROR

    /* Open file and get root group. */
    h5_fixname(FILENAME[4], H5P_DEFAULT, filename, sizeof filename);
    if((fileid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) FAIL_STACK_ERROR
    if((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR

    /* Create a compound type. */
    if((dtypeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) FAIL_STACK_ERROR
    if((array1_tid = H5Tarray_create2(H5T_NATIVE_UCHAR, 1, dims)) < 0) FAIL_STACK_ERROR
    if(H5Tinsert(dtypeid, "x", HOFFSET(struct s1, x), array1_tid) < 0) FAIL_STACK_ERROR
    if(H5Tinsert(dtypeid, "y", HOFFSET(struct s1, y), H5T_NATIVE_FLOAT) < 0) FAIL_STACK_ERROR

    /* Create a space. */
    if((spaceid = H5Screate(H5S_SCALAR)) < 0) FAIL_STACK_ERROR

    /* Create an attribute of this compound type. */
    if((attid = H5Acreate2(grpid, COMPOUND13_ATTR_NAME, dtypeid, spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR

    /* Write some data. */
    if(H5Awrite(attid, dtypeid, &data_out) < 0) FAIL_STACK_ERROR

    /* Release all resources. */
    if(H5Aclose(attid) < 0) FAIL_STACK_ERROR
    if(H5Tclose(array1_tid) < 0) FAIL_STACK_ERROR
    if(H5Tclose(dtypeid) < 0) FAIL_STACK_ERROR
    if(H5Sclose(spaceid) < 0) FAIL_STACK_ERROR
    if(H5Gclose(grpid) < 0) FAIL_STACK_ERROR
    if(H5Fclose(fileid) < 0) FAIL_STACK_ERROR
    if(H5Pclose(fapl_id) < 0) FAIL_STACK_ERROR

    /* Now open the file and read it. */
    if((fileid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
    if((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
    if((attid = H5Aopen(grpid, COMPOUND13_ATTR_NAME, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
    if((dtypeid = H5Aget_type(attid)) < 0) FAIL_STACK_ERROR
    if(H5Tget_class(dtypeid) != H5T_COMPOUND) FAIL_STACK_ERROR
    if(HOFFSET(struct s1, x) != H5Tget_member_offset(dtypeid, 0)) TEST_ERROR
    if(HOFFSET(struct s1, y) != H5Tget_member_offset(dtypeid, 1)) TEST_ERROR
    if(H5Aread(attid, dtypeid, &data_in) < 0) FAIL_STACK_ERROR

    /* Check the data. */
    for (u = 0; u < COMPOUND13_ARRAY_SIZE + 1; u++)
        if(data_out.x[u] != data_in.x[u]) TEST_ERROR
    if(data_out.y != data_in.y) TEST_ERROR

    /* Release all resources. */
    if(H5Aclose(attid) < 0) FAIL_STACK_ERROR
    if(H5Tclose(dtypeid) < 0) FAIL_STACK_ERROR
    if(H5Gclose(grpid) < 0) FAIL_STACK_ERROR
    if(H5Fclose(fileid) < 0) FAIL_STACK_ERROR

    PASSED();
    return 0;

error:
    return 1;
} /* end test_compound_13() */


/*-------------------------------------------------------------------------
 * Function:    test_compound_14
 *
 * Purpose:     Tests compound type conversions where a vlen string will
                be misaligned in the conversion buffer and the file.  The
                two compound types are meant to trigger two different
                conversion routines.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Neil Fortner
 *              Monday, August 25, 2008
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_14(void)
{
    typedef struct cmpd_struct_1 {
       char         c1;
       char         c2;
       char*        str;
    } cmpd_struct_1;

    typedef struct cmpd_struct_2 {
       char         c1;
       char         c2;
       char*        str;
       long         l1;
       long         l2;
       long         l3;
       long         l4;
    } cmpd_struct_2;

    cmpd_struct_1 wdata1 = {'A', 'B', "variable-length string"};

    cmpd_struct_1 rdata1;
    cmpd_struct_2 wdata2 = {'C', 'D', "another vlen!", 1, 2, -1, 9001};
    cmpd_struct_2 rdata2;
    hid_t       file;
    hid_t       cmpd_m1_tid, cmpd_f1_tid, cmpd_m2_tid, cmpd_f2_tid, str_id;
    hid_t       space_id;
    hid_t       dset1_id, dset2_id;
    hsize_t     dim1[1];
    char        filename[1024];

    TESTING("unaligned VL strings in compound");

    /* Create File */
    h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create file!\n");
        goto error;
    } /* end if */

    /* Create memory compound datatype 1 */
    if((cmpd_m1_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct_1))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m1_tid,"c1",HOFFSET(struct cmpd_struct_1,c1),H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m1_tid,"c2",HOFFSET(struct cmpd_struct_1,c2),H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c2'\n");
        goto error;
    } /* end if */

    str_id = H5Tcopy(H5T_C_S1);
    if(H5Tset_size(str_id,H5T_VARIABLE) < 0) {
        H5_FAILED(); AT();
        printf("Can't set size for VL string\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m1_tid, "vl_string", HOFFSET(cmpd_struct_1, str), str_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'vl_string'\n");
        goto error;
    } /* end if */

    /* Create file compound datatype 1 */
    if((cmpd_f1_tid = H5Tcreate( H5T_COMPOUND, 8 + 1 + sizeof(hvl_t))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f1_tid,"c1",(size_t)0,H5T_STD_I64BE) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f1_tid,"c2",(size_t)8,H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c2'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f1_tid, "vl_string",(size_t)(8 + 1), str_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'vl_string'\n");
        goto error;
    } /* end if */

    /* Create memory compound datatype 2 */
    if((cmpd_m2_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct_2))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid,"c1",HOFFSET(struct cmpd_struct_2,c1),H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid,"c2",HOFFSET(struct cmpd_struct_2,c2),H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c2'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid, "vl_string", HOFFSET(cmpd_struct_2, str), str_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'vl_string'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid,"l1",HOFFSET(struct cmpd_struct_2,l1),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid,"l2",HOFFSET(struct cmpd_struct_2,l2),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l2'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid,"l3",HOFFSET(struct cmpd_struct_2,l3),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l3'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m2_tid,"l4",HOFFSET(struct cmpd_struct_2,l4),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l4'\n");
        goto error;
    } /* end if */

    /* Create file compound datatype 2 */
    if((cmpd_f2_tid = H5Tcreate( H5T_COMPOUND, 8 + 1 + sizeof(hvl_t) + 4*sizeof(long))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid,"c1",(size_t)0,H5T_STD_I64BE) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid,"c2",(size_t)8,H5T_NATIVE_CHAR) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'c2'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid, "vl_string", (size_t)(8 + 1), str_id) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'vl_string'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid,"l1",8 + 1 + sizeof(hvl_t),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid,"l2",8 + 1 + sizeof(hvl_t) + sizeof(long),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l2'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid,"l3",8 + 1 + sizeof(hvl_t) + 2*sizeof(long),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l3'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f2_tid,"l4",8 + 1 + sizeof(hvl_t) + 3*sizeof(long),H5T_NATIVE_LONG) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'l4'\n");
        goto error;
    } /* end if */

    dim1[0] = 1;
    if((space_id = H5Screate_simple(1, dim1, NULL)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create space\n");
        goto error;
    } /* end if */

    if((dset1_id = H5Dcreate2(file, "Dataset1", cmpd_f1_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create dataset\n");
        goto error;
    } /* end if */

    if((dset2_id = H5Dcreate2(file, "Dataset2", cmpd_f2_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create dataset\n");
        goto error;
    } /* end if */

    if(H5Dwrite(dset1_id, cmpd_m1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata1) < 0) {
        H5_FAILED(); AT();
        printf("Can't write data\n");
        goto error;
    } /* end if */

    if(H5Dwrite(dset2_id, cmpd_m2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata2) < 0) {
        H5_FAILED(); AT();
        printf("Can't write data\n");
        goto error;
    } /* end if */

    if(H5Dread(dset1_id, cmpd_m1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata1) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    if(H5Dread(dset2_id, cmpd_m2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata2) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    if(rdata1.c1 != wdata1.c1 || rdata1.c2 != wdata1.c2 || HDstrcmp(rdata1.str, wdata1.str)) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    if(rdata2.c1 != wdata2.c1 || rdata2.c2 != wdata2.c2 || HDstrcmp(rdata2.str, wdata2.str) ||
        rdata2.l1 != wdata2.l1 || rdata2.l2 != wdata2.l2 || rdata2.l3 != wdata2.l3 || rdata2.l4 != wdata2.l4) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    if(H5Dclose(dset1_id) < 0)
        goto error;
    if(H5Dclose(dset2_id) < 0)
        goto error;
    if(H5Tclose(cmpd_f1_tid) < 0)
        goto error;
    if(H5Tclose(cmpd_f2_tid) < 0)
        goto error;
    if(H5Tclose(str_id) < 0)
        goto error;
    if(H5Sclose(space_id) < 0)
        goto error;
    if(H5Fclose(file) < 0)
        goto error;


    if((file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("cannot open file\n");
        goto error;
    } /* end if */

    if((dset1_id = H5Dopen2(file, "Dataset1", H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("cannot open dataset\n");
        goto error;
    } /* end if */

    if((dset2_id = H5Dopen2(file, "Dataset2", H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("cannot open dataset\n");
        goto error;
    } /* end if */

    rdata1.c1 = rdata1.c2 = 0;
    if(rdata1.str) HDfree(rdata1.str);

    rdata2.c1 = rdata2.c2 = 0;
    rdata2.l1 = rdata2.l2 = rdata2.l3 = rdata2.l4 = 0;
    if(rdata2.str) {
        HDfree(rdata2.str);
        rdata2.str = NULL;
    } /* end if */

    if(H5Dread(dset1_id, cmpd_m1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata1) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    if(H5Dread(dset2_id, cmpd_m2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata2) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    if(rdata1.c1!=wdata1.c1 || rdata1.c2!=wdata1.c2 || strcmp(rdata1.str, wdata1.str)) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    if(rdata2.c1 != wdata2.c1 || rdata2.c2 != wdata2.c2 || HDstrcmp(rdata2.str, wdata2.str) ||
        rdata2.l1 != wdata2.l1 || rdata2.l2 != wdata2.l2 || rdata2.l3 != wdata2.l3 || rdata2.l4 != wdata2.l4) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    if(rdata1.str) HDfree(rdata1.str);
    if(rdata2.str) HDfree(rdata2.str);

    if(H5Dclose(dset1_id) < 0)
        goto error;
    if(H5Dclose(dset2_id) < 0)
        goto error;
    if(H5Tclose(cmpd_m1_tid) < 0)
        goto error;
    if(H5Tclose(cmpd_m2_tid) < 0)
        goto error;
    if(H5Fclose(file) < 0)
        goto error;

    PASSED();
    return 0;

 error:
    return 1;
} /* end test_compound_14() */


/*-------------------------------------------------------------------------
 * Function:    test_compound_15
 *
 * Purpose:     Tests that conversion occurs correctly when the source is
 *              subset of the destination, but there is extra space at the
 *              end of the source type.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Neil Fortner
 *              Friday, September 19, 2008
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_15(void)
{
    typedef struct cmpd_struct {
       int  i1;
       int  i2;
    } cmpd_struct;

    cmpd_struct wdata1 = {1254, 5471};
    cmpd_struct rdata;
    int         wdata2[2] = {1, 2};
    hid_t       file;
    hid_t       cmpd_m_tid, cmpd_f_tid;
    hid_t       space_id;
    hid_t       dset_id;
    hsize_t     dim1[1];
    char        filename[1024];

    TESTING("compound subset conversion with extra space in source");

    /* Create File */
    h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create file!\n");
        goto error;
    } /* end if */

    /* Create file compound datatype */
    if((cmpd_f_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f_tid,"i1",HOFFSET(struct cmpd_struct,i1),H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i1'\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_f_tid,"i2",HOFFSET(struct cmpd_struct,i2),H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i2'\n");
        goto error;
    } /* end if */

    /* Create memory compound datatype */
    if((cmpd_m_tid = H5Tcreate( H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) {
        H5_FAILED(); AT();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */

    if(H5Tinsert(cmpd_m_tid,"i1",(size_t)0,H5T_NATIVE_INT) < 0) {
        H5_FAILED(); AT();
        printf("Can't insert field 'i1'\n");
        goto error;
    } /* end if */

    /* Create space, dataset, write wdata1 */
    dim1[0] = 1;
    if((space_id = H5Screate_simple(1, dim1, NULL)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create space\n");
        goto error;
    } /* end if */

    if((dset_id = H5Dcreate2(file, "Dataset", cmpd_f_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        H5_FAILED(); AT();
        printf("Can't create dataset\n");
        goto error;
    } /* end if */

    if(H5Dwrite(dset_id, cmpd_f_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata1) < 0) {
        H5_FAILED(); AT();
        printf("Can't write data\n");
        goto error;
    } /* end if */

    /* Write wdata2.  The use of cmpd_m_tid here should cause only the first
     * element of wdata2 to be written. */
    if(H5Dwrite(dset_id, cmpd_m_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata2) < 0) {
        H5_FAILED(); AT();
        printf("Can't write data\n");
        goto error;
    } /* end if */

    /* Read data */
    if(H5Dread(dset_id, cmpd_f_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    /* Check for correctness of read data */
    if(rdata.i1 != wdata2[0] || rdata.i2 != wdata1.i2) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    /* Now try reading only the i1 field, verify it does not overwrite i2 in the
     * read buffer */
    rdata.i1 = wdata1.i1;
    rdata.i2 = wdata2[1];

    /* Read data */
    if(H5Dread(dset_id, cmpd_m_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
        H5_FAILED(); AT();
        printf("Can't read data\n");
        goto error;
    } /* end if */

    /* Check for correctness of read data */
    if(rdata.i1 != wdata2[0] || rdata.i2 != wdata2[1]) {
        H5_FAILED(); AT();
        printf("incorrect read data\n");
        goto error;
    } /* end if */

    /* Close */
    if(H5Dclose(dset_id) < 0)
        goto error;
    if(H5Tclose(cmpd_f_tid) < 0)
        goto error;
    if(H5Tclose(cmpd_m_tid) < 0)
        goto error;
    if(H5Sclose(space_id) < 0)
        goto error;
    if(H5Fclose(file) < 0)
        goto error;

    PASSED();
    return 0;

 error:
    return 1;
} /* end test_compound_15() */


/*-------------------------------------------------------------------------
 * Function:    test_compound_16
 *
 * Purpose:     Tests that committed types that can be registered during
 *              compound conversion are not visible to the application
 *              with H5Fget_obj_count or H5Fget_obj_ids.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Neil Fortner
 *              Friday, October 3, 2008
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_16(void)
{
    typedef struct cmpd_struct {
       int  i1;
       int  i2;
    } cmpd_struct;

    cmpd_struct wdata1 = {1254, 5471};
    int         obj_count;
    hid_t       file;
    hid_t       cmpd_m_tid, cmpd_f_tid, int_id;
    hid_t       space_id;
    hid_t       dset_id;
    hid_t       open_dtypes[2] = {0, 0};
    hsize_t     dim1[1] = {1};
    char        filename[1024];

    TESTING("visibility of internally registered type ids");

    /* Create File */
    h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Copy and commit integer datatype */
    if((int_id = H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR
    if(H5Tcommit2(file, "int", int_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR

    /* Create file compound datatype */
    if((cmpd_f_tid = H5Tcreate(H5T_COMPOUND, 2 * sizeof(int) + 2)) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_f_tid, "i1", (size_t)0, int_id) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_f_tid, "i2", sizeof(int) + 1, int_id) < 0) TEST_ERROR

    /* Create memory compound datatype */
    if((cmpd_m_tid = H5Tcreate(H5T_COMPOUND, sizeof(struct cmpd_struct))) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_m_tid, "i1", HOFFSET(struct cmpd_struct, i1), int_id) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_m_tid, "i2", HOFFSET(struct cmpd_struct, i2), int_id) < 0) TEST_ERROR

    /* Create space, dataset, write wdata1 */
    if((space_id = H5Screate_simple(1, dim1, NULL)) < 0) TEST_ERROR
    if((dset_id = H5Dcreate2(file, "Dataset", cmpd_f_tid, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
    if(H5Dwrite(dset_id, cmpd_m_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata1) < 0) TEST_ERROR

    /* Check behavior of H5Fget_obj_count */
    if((obj_count = H5Fget_obj_count(file, H5F_OBJ_DATATYPE)) != 1) {
        H5_FAILED(); AT();
        printf("    H5Fget_obj_count returned: %d; expected: 1\n", obj_count);
        goto error;
    }

    /* Check behavior of H5Fget_obj_ids */
    if(H5Fget_obj_ids(file, H5F_OBJ_DATATYPE, (size_t)2, open_dtypes) < 0) TEST_ERROR
    if(open_dtypes[1]) {
        H5_FAILED(); AT();
        printf("    H5Fget_obj_ids returned as second id: %d; expected: 0\n", open_dtypes[1]);
        goto error;
    }

    /* Close */
    if(H5Dclose(dset_id) < 0) TEST_ERROR
    if(H5Sclose(space_id) < 0) TEST_ERROR
    if(H5Tclose(cmpd_f_tid) < 0) TEST_ERROR
    if(H5Tclose(cmpd_m_tid) < 0) TEST_ERROR
    if(H5Tclose(int_id) < 0) TEST_ERROR
    if(H5Fclose(file) < 0) TEST_ERROR

    PASSED();
    return 0;

error:
    return 1;
} /* end test_compound_16() */


/*-------------------------------------------------------------------------
 * Function:    test_compound_17
 *
 * Purpose:     Tests that compound types are packed correctly when they
 *              only have extra space at the end.  The compounds are
 *              "hidden" inside arrays to make sure that they are still
 *              detected correctly.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Neil Fortner
 *              Tuesday, January 13, 2009
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_compound_17(void)
{
    hid_t       file;
    hid_t       cmpd_int, arr_int, cmpd_ext, arr_ext, tmp_dt;
    hsize_t     dims[1] = {2};
    char        filename[1024];

    TESTING("that H5Tpack removes trailing bytes");

    /* Create inner compound datatype.  This type will be "packed" according
     * to the internal field, but will have trailing space at the end. */
    if((cmpd_int = H5Tcreate(H5T_COMPOUND, (size_t)4)) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_int, "c", (size_t)0, H5T_NATIVE_CHAR) < 0) TEST_ERROR

    /* Create inner array datatype */
    if((arr_int = H5Tarray_create2(cmpd_int, 1, dims)) < 0) TEST_ERROR

    /* Create outer compound datatype.  This type will be truly packed, with no
     * trailing space.  However, the internal compound contained within is not
     * packed. */
    if((cmpd_ext = H5Tcreate(H5T_COMPOUND, (size_t)8)) < 0) TEST_ERROR
    if(H5Tinsert(cmpd_ext, "arr", (size_t)0, arr_int) < 0) TEST_ERROR

    /* Create outer array datatype */
    if((arr_ext = H5Tarray_create2(cmpd_ext, 1, dims)) < 0) TEST_ERROR

    /* Try packing the internal array.  Size should be 2 after packing. */
    if((tmp_dt = H5Tcopy(arr_int)) < 0) TEST_ERROR
    if(H5Tpack(tmp_dt) < 0) TEST_ERROR
    if(2 != H5Tget_size(tmp_dt)) {
        H5_FAILED(); AT();
        printf("    Size after packing: %u; expected: 2\n", (unsigned)H5Tget_size(tmp_dt));
        goto error;
    }
    if(H5Tclose(tmp_dt) < 0) TEST_ERROR

    /* Try packing the external array.  Size should be 4 after packing. */
    if((tmp_dt = H5Tcopy(arr_ext)) < 0) TEST_ERROR
    if(H5Tpack(tmp_dt) < 0) TEST_ERROR
    if(4 != H5Tget_size(tmp_dt)) {
        H5_FAILED(); AT();
        printf("    Size after packing: %u; expected: 4\n", (unsigned)H5Tget_size(tmp_dt));
        goto error;
    }
    if(H5Tclose(tmp_dt) < 0) TEST_ERROR

    /* Now we will commit arr_int and arr_ext to a file, and verify that they
     * are still packed correctly after opening them from the file */
    /* Create File */
    h5_fixname(FILENAME[3], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Commit the datatypes.  Note that they are still unpacked. */
    if(H5Tcommit2(file, "arr_int", arr_int, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
    if(H5Tcommit2(file, "arr_ext", arr_ext, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR

    /* Close IDs */
    if(H5Tclose(cmpd_int) < 0) TEST_ERROR
    if(H5Tclose(arr_int) < 0) TEST_ERROR
    if(H5Tclose(cmpd_ext) < 0) TEST_ERROR
    if(H5Tclose(arr_ext) < 0) TEST_ERROR
    if(H5Fclose(file) < 0) TEST_ERROR

    /* Reopen file */
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Open committed array datatypes */
    if((arr_int = H5Topen2(file, "arr_int", H5P_DEFAULT)) < 0) TEST_ERROR
    if((arr_ext = H5Topen2(file, "arr_ext", H5P_DEFAULT)) < 0) TEST_ERROR

    /* Try packing the internal array.  Size should be 2 after packing. */
    if((tmp_dt = H5Tcopy(arr_int)) < 0) TEST_ERROR
    if(H5Tpack(tmp_dt) < 0) TEST_ERROR
    if(2 != H5Tget_size(tmp_dt)) {
        H5_FAILED(); AT();
        printf("    Size after packing: %u; expected: 2\n", (unsigned)H5Tget_size(tmp_dt));
        goto error;
    }
    if(H5Tclose(tmp_dt) < 0) TEST_ERROR

    /* Try packing the external array.  Size should be 4 after packing. */
    if((tmp_dt = H5Tcopy(arr_ext)) < 0) TEST_ERROR
    if(H5Tpack(tmp_dt) < 0) TEST_ERROR
    if(4 != H5Tget_size(tmp_dt)) {
        H5_FAILED(); AT();
        printf("    Size after packing: %u; expected: 4\n", (unsigned)H5Tget_size(tmp_dt));
        goto error;
    }
    if(H5Tclose(tmp_dt) < 0) TEST_ERROR

    /* Close IDs */
    if(H5Tclose(arr_int) < 0) TEST_ERROR
    if(H5Tclose(arr_ext) < 0) TEST_ERROR
    if(H5Fclose(file) < 0) TEST_ERROR

    PASSED();
    return 0;

error:
    return 1;
} /* end test_compound_17() */


/*-------------------------------------------------------------------------
 * Function:    test_query
 *
 * Purpose:     Tests query functions of compound and enumeration types.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Raymond Lu
 *              Thursday, April 4, 2002
 *
 * Modifications:
 *              Raymond Lu
 *              Wednesday, Febuary 9, 2005
 *              Added test for H5Tenum_valueof, H5Tenum_nameof, and
 *              H5Tget_member_value.
 *-------------------------------------------------------------------------
 */
static int
test_query(void)
{
    struct s1 {
        int    a;
        float  b;
        long   c;
        double d;
    };
    hid_t       file=-1, tid1=-1, tid2=-1;
    char        filename[1024];
    char        compnd_type[]="Compound_type", enum_type[]="Enum_type";
    short       enum_val;
    char        enum_name[16];

    TESTING("query functions of compound and enumeration types");

    /* Create File */
    h5_fixname(FILENAME[2], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        goto error;

    /* Create a compound datatype */
    if((tid1=H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) {
        H5_FAILED();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "a", HOFFSET(struct s1, a), H5T_NATIVE_INT) < 0) {
        H5_FAILED();
        printf("Can't insert field 'a'\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "b", HOFFSET(struct s1, b), H5T_NATIVE_FLOAT) < 0) {
        H5_FAILED();
        printf("Can't insert field 'b'\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "c", HOFFSET(struct s1, c), H5T_NATIVE_LONG) < 0) {
        H5_FAILED();
        printf("Can't insert field 'c'\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "d", HOFFSET(struct s1, d), H5T_NATIVE_DOUBLE) < 0) {
        H5_FAILED();
        printf("Can't insert field 'd'\n");
        goto error;
    } /* end if */

    /* Create a enumerate datatype */
    if((tid2=H5Tcreate(H5T_ENUM, sizeof(short))) < 0) {
        H5_FAILED();
        printf("Can't create enumerate type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "RED", (enum_val=10,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "GREEN", (enum_val=11,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "BLUE", (enum_val=12,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "ORANGE", (enum_val=13,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "YELLOW", (enum_val=14,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */

    /* Query member number and member index by name, for compound type. */
    if(H5Tget_nmembers(tid1)!=4) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(tid1, "c")!=2) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */

    /* Query member number and member index by member name, for enumeration type. */
    if(H5Tget_nmembers(tid2) != 5) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(tid2, "ORANGE") != 3) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */

    /* Commit compound datatype and close it */
    if(H5Tcommit2(file, compnd_type, tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
        H5_FAILED();
        printf("Can't commit compound datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid1) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */

    /* Commit enumeration datatype and close it */
    if(H5Tcommit2(file, enum_type, tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
        H5_FAILED();
        printf("Can't commit compound datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */

    /* Open the dataytpe for query */
    if((tid1 = H5Topen2(file, compnd_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR
    if((tid2 = H5Topen2(file, enum_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    /* Query member number and member index by name, for compound type */
    if(H5Tget_nmembers(tid1) != 4) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(tid1, "c") != 2) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */

    /* Query member number and member index by member name, for enumeration type */
    if(H5Tget_nmembers(tid2)!=5) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(tid2, "ORANGE")!=3) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */

    /* Query member value by member name, for enumeration type */
    if(H5Tenum_valueof (tid2, "ORANGE", &enum_val) < 0) {
        H5_FAILED();
        printf("Can't get value for enumerate member\n");
        goto error;
    } /* end if */
    if(enum_val!=13) {
        H5_FAILED();
        printf("Incorrect value for enum member\n");
        goto error;
    } /* end if */

    /* Query member value by member index, for enumeration type */
    if(H5Tget_member_value (tid2, 2, &enum_val) < 0) {
        H5_FAILED();
        printf("Can't get value for enum member\n");
        goto error;
    } /* end if */
    if(enum_val!=12) {
        H5_FAILED();
        printf("Incorrect value for enum member\n");
        goto error;
    } /* end if */

    /* Query member name by member value, for enumeration type */
    enum_val = 14;
    if(H5Tenum_nameof(tid2, &enum_val, enum_name, (size_t)16) < 0) {
        H5_FAILED();
        printf("Can't get name for enum member\n");
        goto error;
    } /* end if */
    if(strcmp("YELLOW", enum_name)) {
        H5_FAILED();
        printf("Incorrect name for enum member\n");
        goto error;
    } /* end if */

    /* Close datatype and file */
    if(H5Tclose(tid1) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */

    if(H5Fclose(file) < 0) {
        H5_FAILED();
        printf("Can't close file\n");
        goto error;
    } /* end if */

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
        H5Tclose (tid1);
        H5Tclose (tid2);
        H5Fclose (file);
    } H5E_END_TRY;
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_transient
 *
 * Purpose:	Tests transient datatypes.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, June  4, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_transient (hid_t fapl)
{
    static hsize_t	ds_size[2] = {10, 20};
    hid_t		file=-1, type=-1, space=-1, dset=-1, t2=-1;
    char		filename[1024];
    herr_t		status;

    TESTING("transient datatypes");

    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if ((file=H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) {
	goto error;
    }
    if ((space = H5Screate_simple (2, ds_size, ds_size)) < 0) goto error;

    /* Predefined types cannot be modified or closed */
    H5E_BEGIN_TRY {
	status = H5Tset_precision(H5T_NATIVE_INT, (size_t)256);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	HDputs ("    Predefined types should not be modifiable!");
	goto error;
    }
    H5E_BEGIN_TRY {
	status = H5Tclose (H5T_NATIVE_INT);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	HDputs ("    Predefined types should not be closable!");
	goto error;
    }

    /* Copying a predefined type results in a modifiable copy */
    if((type=H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
    if(H5Tset_precision(type, (size_t)256) < 0) goto error;

    /* It should not be possible to create an attribute for a transient type */
    H5E_BEGIN_TRY {
	status = H5Acreate2(type, "attr1", H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	HDputs ("    Attributes should not be allowed for transient types!");
	goto error;
    }

    /* Create a dataset from a transient datatype */
    if(H5Tclose(type) < 0) goto error;
    if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
    if((dset = H5Dcreate2(file, "dset1", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
	goto error;

    /* The type returned from a dataset should not be modifiable */
    if((t2 = H5Dget_type(dset)) < 0) goto error;
    H5E_BEGIN_TRY {
	status = H5Tset_precision(t2, (size_t)256);
    } H5E_END_TRY;
    if(status >= 0) {
	H5_FAILED();
	HDputs ("    Dataset datatypes should not be modifiable!");
	goto error;
    }
    if(H5Tclose(t2) < 0) goto error;

    /*
     * Close the dataset and reopen it, testing that it's type is still
     * read-only.
     */
    if(H5Dclose(dset) < 0) goto error;
    if((dset = H5Dopen2(file, "dset1", H5P_DEFAULT)) < 0) goto error;
    if((t2 = H5Dget_type(dset)) < 0) goto error;
    H5E_BEGIN_TRY {
	status = H5Tset_precision(t2, (size_t)256);
    } H5E_END_TRY;
    if(status >= 0) {
	H5_FAILED();
	HDputs ("    Dataset datatypes should not be modifiable!");
	goto error;
    }
    if(H5Tclose(t2) < 0) goto error;

    /*
     * Get the dataset datatype by applying H5Tcopy() to the dataset. The
     * result should be modifiable.
     */
    if((t2=H5Tcopy(dset)) < 0) goto error;
    if(H5Tset_precision(t2, (size_t)256) < 0) goto error;
    if(H5Tclose(t2) < 0) goto error;


    if(H5Dclose(dset) < 0) goto error;
    if(H5Fclose(file) < 0) goto error;
    if(H5Tclose(type) < 0) goto error;
    if(H5Sclose(space) < 0) goto error;

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
	H5Tclose (t2);
	H5Tclose (type);
	H5Sclose (space);
	H5Dclose (dset);
	H5Fclose (file);
    } H5E_END_TRY;
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_named
 *
 * Purpose:	Tests named datatypes.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Monday, June  1, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_named (hid_t fapl)
{
    hid_t		file=-1, type=-1, space=-1, dset=-1, t2=-1, t3=-1, attr1=-1;
    herr_t		status;
    static hsize_t	ds_size[2] = {10, 20};
    size_t		i,j;
    unsigned 		attr_data[10][20];
    char		filename[1024];

    TESTING("named datatypes");

    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if ((file=H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) {
	goto error;
    }
    if ((space = H5Screate_simple (2, ds_size, ds_size)) < 0) goto error;

    /* Predefined types cannot be committed */
    H5E_BEGIN_TRY {
	status = H5Tcommit2(file, "test_named_1 (should not exist)", H5T_NATIVE_INT, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;
    if(status >= 0) {
	H5_FAILED();
	HDputs ("    Predefined types should not be committable!");
	goto error;
    }

    /* Copy a predefined datatype and commit the copy */
    if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
    if(H5Tcommit2(file, "native-int", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) goto error;
    if((status = H5Tcommitted(type)) < 0) goto error;
    if(0 == status) {
	H5_FAILED();
	HDputs ("    H5Tcommitted() returned false!");
	goto error;
    }

    /* We should not be able to modify a type after it has been committed. */
    H5E_BEGIN_TRY {
	status = H5Tset_precision (type, (size_t)256);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	HDputs ("    Committed type is not constant!");
	goto error;
    }

    /* We should not be able to re-commit a committed type */
    H5E_BEGIN_TRY {
	status = H5Tcommit2(file, "test_named_2 (should not exist)", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;
    if(status >= 0) {
	H5_FAILED();
	HDputs ("    Committed types should not be recommitted!");
	goto error;
    }

    /* It should be possible to define an attribute for the named type */
    if((attr1 = H5Acreate2(type, "attr1", H5T_NATIVE_UCHAR, space,
			  H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error;
    for(i = 0; i < (size_t)ds_size[0]; i++)
        for(j = 0; j < (size_t)ds_size[1]; j++)
            attr_data[i][j] = (int)(i * ds_size[1] + j);
    if(H5Awrite(attr1, H5T_NATIVE_UINT, attr_data) < 0) goto error;
    if(H5Aclose(attr1) < 0) goto error;

    /*
     * Copying a committed type should result in a transient type which is
     * not locked.
     */
    if((t2 = H5Tcopy(type)) < 0) goto error;
    if((status = H5Tcommitted(t2)) < 0) goto error;
    if(status) {
	H5_FAILED();
	HDputs ("    Copying a named type should result in a transient type!");
	goto error;
    }
    if(H5Tset_precision(t2, (size_t)256) < 0) goto error;
    if(H5Tclose(t2) < 0) goto error;

    /*
     * Close the committed type and reopen it.  It should return a named type.
     */
    if(H5Tclose(type) < 0) goto error;
    if((type = H5Topen2(file, "native-int", H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR
    if((status = H5Tcommitted(type)) < 0) goto error;
    if(!status) {
	H5_FAILED();
	HDputs ("    Opened named types should be named types!");
	goto error;
    }

    /* Create a dataset that uses the named type */
    if((dset = H5Dcreate2(file, "dset1", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
	goto error;

    /* Get the dataset's datatype and make sure it's a named type */
    if((t2 = H5Dget_type(dset)) < 0) goto error;
    if((status = H5Tcommitted(t2)) < 0) goto error;
    if(!status) {
	H5_FAILED();
	HDputs ("    Dataset type should be a named type!");
	goto error;
    }

    /* Close the dataset, then close its type, then reopen the dataset */
    if(H5Dclose(dset) < 0) goto error;
    if(H5Tclose(t2) < 0) goto error;
    if((dset = H5Dopen2(file, "dset1", H5P_DEFAULT)) < 0) goto error;

    /* Get the dataset's type and make sure it's named */
    if((t2 = H5Dget_type(dset)) < 0) goto error;
    if((status = H5Tcommitted(t2)) < 0) goto error;
    if(!status) {
	H5_FAILED();
	HDputs ("    Dataset type should be a named type!");
	goto error;
    }

    /*
     * Close the dataset and create another with the type returned from the
     * first dataset.
     */
    if(H5Dclose(dset) < 0) goto error;
    if((dset = H5Dcreate2(file, "dset2", t2, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error;

    /* Reopen the second dataset and make sure the type is shared */
    if(H5Tclose(t2) < 0) goto error;
    if(H5Dclose(dset) < 0) goto error;
    if((dset = H5Dopen2(file, "dset2", H5P_DEFAULT)) < 0) goto error;
    if((t2 = H5Dget_type(dset)) < 0) goto error;
    if((status = H5Tcommitted(t2)) < 0) goto error;
    if(!status) {
	H5_FAILED();
	HDputs ("    Dataset type should be a named type!");
	goto error;
    }
    if(H5Tclose(t2) < 0) goto error;

    /*
     * Get the dataset datatype by applying H5Tcopy() to the dataset. The
     * result should be modifiable.
     */
    if((t2 = H5Tcopy(dset)) < 0) goto error;
    if(H5Tset_precision(t2, (size_t)256) < 0) goto error;
    if(H5Tclose(t2) < 0) goto error;
    if(H5Dclose(dset) < 0) goto error;

    /*
     * Copy of committed type used as dataset type should not be name type
     */
    if((t2 = H5Tcopy(type)) < 0) goto error;
    if((status = H5Tcommitted(t2)) < 0) goto error;
    if(status) {
	H5_FAILED();
	HDputs ("    Copied type should not be a named type!");
	goto error;
    }
    if((dset = H5Dcreate2(file, "dset3", t2, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error;
    if((t3 = H5Dget_type(dset)) < 0) goto error;
    if((status = H5Tcommitted(t3)) < 0) goto error;
    if(status) {
	H5_FAILED();
	HDputs ("    Datatype from dataset using copied type should not be a named type!");
	goto error;
    }
    if(H5Tclose(t3) < 0) goto error;
    if(H5Dclose(dset) < 0) goto error;

    /* Close */
    if(H5Tclose(type) < 0) goto error;
    if(H5Sclose(space) < 0) goto error;
    if(H5Fclose(file) < 0) goto error;

    /* Reopen file with read only access */
    if ((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
        goto error;

    /* Verify that H5Tcommit2 returns an error */
    if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
    H5E_BEGIN_TRY {
        status = H5Tcommit2(file, "test_named_3 (should not exist)", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;
    if(status >= 0) {
        H5_FAILED();
        HDputs ("    Types should not be committable to a read-only file!");
        goto error;
    }

    /* Verify that H5Tcommit_anon returns an error */
    if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
    H5E_BEGIN_TRY {
        status = H5Tcommit_anon(file, type, H5P_DEFAULT, H5P_DEFAULT);
    } H5E_END_TRY;
    if(status >= 0) {
        H5_FAILED();
        HDputs ("    Types should not be committable to a read-only file!");
        goto error;
    }

    /* Close */
    if(H5Tclose(type) < 0) goto error;
    if(H5Fclose(file) < 0) goto error;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
	H5Tclose(t3);
	H5Tclose(t2);
	H5Tclose(type);
	H5Sclose(space);
	H5Dclose(dset);
	H5Fclose(file);
    } H5E_END_TRY;
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	mkstr
 *
 * Purpose:	Create a new string datatype
 *
 * Return:	Success:	New type
 *		Failure:	-1
 *
 * Programmer:	Robb Matzke
 *              Monday, August 10, 1998
 *
 *-------------------------------------------------------------------------
 */
static hid_t
mkstr(size_t len, H5T_str_t strpad)
{
    hid_t	t;

    if((t = H5Tcopy(H5T_C_S1)) < 0)
        return -1;
    if(H5Tset_size(t, len) < 0)
        return -1;
    if(H5Tset_strpad(t, strpad) < 0)
        return -1;

    return t;
}


/*-------------------------------------------------------------------------
 * Function:	test_conv_str_1
 *
 * Purpose:	Test string conversions
 *
 * Return:	Success:	0
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Monday, August 10, 1998
 *
 *-------------------------------------------------------------------------
 */
static int
test_conv_str_1(void)
{
    char	*buf = NULL;
    hid_t	src_type = -1;
    hid_t   dst_type = -1;

    TESTING("string conversions");

    /*
     * Convert a null-terminated string to a shorter and longer null
     * terminated string.
     */
    if((src_type = mkstr((size_t)10, H5T_STR_NULLTERM)) < 0) goto error;
    if((dst_type = mkstr((size_t)5, H5T_STR_NULLTERM)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc((size_t)2, (size_t)10))) goto error;
    HDmemcpy(buf, "abcdefghi\0abcdefghi\0", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd\0abcd\0abcdefghi\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Truncated C-string test failed");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd\0\0\0\0\0\0abcd\0\0\0\0\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Extended C-string test failed");
	goto error;
    }
    HDfree(buf);
    buf = NULL;
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;

    /*
     * Convert a null padded string to a shorter and then longer string.
     */
    if((src_type = mkstr((size_t)10, H5T_STR_NULLPAD)) < 0) goto error;
    if((dst_type = mkstr((size_t)5, H5T_STR_NULLPAD)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc((size_t)2, (size_t)10))) goto error;
    HDmemcpy(buf, "abcdefghijabcdefghij", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdeabcdeabcdefghij", (size_t)20)) {
	H5_FAILED();
	HDputs("    Truncated C buffer test failed");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Extended C buffer test failed");
	goto error;
    }
    HDfree(buf);
    buf = NULL;
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;

    /*
     * Convert a space-padded string to a shorter and then longer string.
     */
    if((src_type = mkstr((size_t)10, H5T_STR_SPACEPAD)) < 0) goto error;
    if((dst_type = mkstr((size_t)5, H5T_STR_SPACEPAD)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc((size_t)2, (size_t)10))) goto error;
    HDmemcpy(buf, "abcdefghijabcdefghij", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdeabcdeabcdefghij", (size_t)20)) {
	H5_FAILED();
	HDputs("    Truncated Fortran-string test failed");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcde     abcde     ", (size_t)20)) {
	H5_FAILED();
	HDputs("    Extended Fortran-string test failed");
	goto error;
    }
    HDfree(buf);
    buf = NULL;
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;

    /*
     * What happens if a null-terminated string is not null terminated?  If
     * the conversion is to an identical string then nothing happens but if
     * the destination is a different size or type of string then the right
     * thing should happen.
     */
    if((src_type = mkstr((size_t)10, H5T_STR_NULLTERM)) < 0) goto error;
    if((dst_type = mkstr((size_t)10, H5T_STR_NULLTERM)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc((size_t)2, (size_t)10))) goto error;
    HDmemcpy(buf, "abcdefghijabcdefghij", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdefghijabcdefghij", (size_t)20)) {
	H5_FAILED();
	HDputs("    Non-terminated string test 1");
	goto error;
    }
    H5Tclose(dst_type);
    if((dst_type = mkstr((size_t)5, H5T_STR_NULLTERM)) < 0) goto error;
    HDmemcpy(buf, "abcdefghijabcdefghij", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd\0abcd\0abcdefghij", (size_t)20)) {
	H5_FAILED();
	HDputs("    Non-terminated string test 2");
	goto error;
    }
    HDmemcpy(buf, "abcdeabcdexxxxxxxxxx", (size_t)20);
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Non-terminated string test 2");
	goto error;
    }
    HDfree(buf);
    buf = NULL;
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;

    /*
     * Test C string to Fortran and vice versa.
     */
    if((src_type = mkstr((size_t)10, H5T_STR_NULLTERM)) < 0) goto error;
    if((dst_type = mkstr((size_t)10, H5T_STR_SPACEPAD)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc((size_t)2, (size_t)10))) goto error;
    HDmemcpy(buf, "abcdefghi\0abcdefghi\0", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdefghi abcdefghi ", (size_t)20)) {
	H5_FAILED();
	HDputs("    C string to Fortran test 1");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdefghi\0abcdefghi\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Fortran to C string test 1");
	goto error;
    }
    if (H5Tclose(dst_type) < 0) goto error;
    if((dst_type = mkstr((size_t)5, H5T_STR_SPACEPAD)) < 0) goto error;
    HDmemcpy(buf, "abcdefgh\0\0abcdefgh\0\0", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdeabcdeabcdefgh\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    C string to Fortran test 2");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Fortran to C string test 2");
	goto error;
    }
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;
    if((src_type = mkstr((size_t)5, H5T_STR_NULLTERM)) < 0) goto error;
    if((dst_type = mkstr((size_t)10, H5T_STR_SPACEPAD)) < 0) goto error;
    HDmemcpy(buf, "abcd\0abcd\0xxxxxxxxxx", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd      abcd      ", (size_t)20)) {
	H5_FAILED();
	HDputs("    C string to Fortran test 3");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd\0abcd\0abcd      ", (size_t)20)) {
	H5_FAILED();
	HDputs("    Fortran to C string test 3");
	goto error;
    }
    HDfree(buf);
    buf = NULL;
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;

    /*
     * Test C buffer to Fortran and vice versa.
     */
    if((src_type = mkstr((size_t)10, H5T_STR_NULLPAD)) < 0) goto error;
    if((dst_type = mkstr((size_t)10, H5T_STR_SPACEPAD)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc((size_t)2, (size_t)10))) goto error;
    HDmemcpy(buf, "abcdefghijabcdefghij", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdefghijabcdefghij", (size_t)20)) {
	H5_FAILED();
	HDputs("    C buffer to Fortran test 1");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdefghijabcdefghij", (size_t)20)) {
	H5_FAILED();
	HDputs("    Fortran to C buffer test 1");
	goto error;
    }
    if (H5Tclose(dst_type) < 0) goto error;
    if((dst_type = mkstr((size_t)5, H5T_STR_SPACEPAD)) < 0) goto error;
    HDmemcpy(buf, "abcdefgh\0\0abcdefgh\0\0", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcdeabcdeabcdefgh\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    C buffer to Fortran test 2");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", (size_t)20)) {
	H5_FAILED();
	HDputs("    Fortran to C buffer test 2");
	goto error;
    }
    if (H5Tclose(src_type) < 0) goto error;
    if (H5Tclose(dst_type) < 0) goto error;
    if((src_type = mkstr((size_t)5, H5T_STR_NULLPAD)) < 0) goto error;
    if((dst_type = mkstr((size_t)10, H5T_STR_SPACEPAD)) < 0) goto error;
    HDmemcpy(buf, "abcd\0abcd\0xxxxxxxxxx", (size_t)20);
    if (H5Tconvert(src_type, dst_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd      abcd      ", (size_t)20)) {
	H5_FAILED();
	HDputs("    C buffer to Fortran test 3");
	goto error;
    }
    if (H5Tconvert(dst_type, src_type, (size_t)2, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (HDmemcmp(buf, "abcd\0abcd\0abcd      ", (size_t)20)) {
	H5_FAILED();
	HDputs("    Fortran to C buffer test 3");
	goto error;
    }
    if(H5Tclose(src_type) < 0) goto error;
    if(H5Tclose(dst_type) < 0) goto error;
    HDfree(buf);

    PASSED();
    reset_hdf5();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Tclose(src_type); 
        H5Tclose(dst_type);
    } H5E_END_TRY;

    if(buf)
        HDfree(buf);

    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_conv_str_2
 *
 * Purpose:	Tests C-to-Fortran and Fortran-to-C string conversion speed.
 *
 * Return:	Success:	0
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Monday, August 10, 1998
 *
 *-------------------------------------------------------------------------
 */
static int
test_conv_str_2(void)
{
    char		*buf = NULL, s[80];
    hid_t		c_type = -1;
    hid_t       	f_type = -1;
    const size_t	nelmts = NTESTELEM;
    size_t		i, j, nchars;
    int			ret_value = 1;

    /*
     * Initialize types and buffer.
     */
    if((c_type = mkstr((size_t)8, H5T_STR_NULLPAD)) < 0) goto error;
    if((f_type = mkstr((size_t)8, H5T_STR_SPACEPAD)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc(nelmts, (size_t)8))) goto error;
    for(i = 0; i < nelmts; i++) {
	nchars = HDrand() % 8;
	for(j = 0; j < nchars; j++)
	    buf[i * 8 + j] = 'a' + HDrand() % 26;
	while(j < nchars)
            buf[i * 8 + j++] = '\0';
    } /* end for */

    /* Do the conversions */
    sprintf(s, "Testing random string conversion speed");
    printf("%-70s", s);
    HDfflush(stdout);
    if(H5Tconvert(c_type, f_type, nelmts, buf, NULL, H5P_DEFAULT) < 0)
        goto error;
    if(H5Tconvert(f_type, c_type, nelmts, buf, NULL, H5P_DEFAULT) < 0)
        goto error;
    PASSED();

    ret_value = 0;

error:
    H5E_BEGIN_TRY {
        H5Tclose(c_type);
        H5Tclose(f_type);
    } H5E_END_TRY;

    if(buf)
        HDfree(buf);

    reset_hdf5();
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	test_conv_str_3
 *
 * Purpose:	Tests some functions that are or aren't supposed to work
 *              for string type.
 *
 * Return:	Success:	0
 *		Failure:	number of errors
 *
 * Programmer:	Raymond Lu
 *              Tuesday, April 4, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_conv_str_3(void)
{
    char		*buf=NULL;
    hid_t		type = -1;
    hid_t       	super = -1;
    const size_t	nelmts = NTESTELEM;
    size_t		i, j, nchars;
    int			ret_value = 1;
    int                 size;
    H5T_pad_t           inpad;
    H5T_sign_t          sign;
    char               *tag = NULL;
    herr_t              ret;

    TESTING("some type functions for string");

    /*
     * Initialize types and buffer.
     */
    if((type = mkstr((size_t)8, H5T_STR_NULLPAD)) < 0) goto error;
    if(NULL == (buf = (char*)HDcalloc(nelmts, (size_t)8)))
        FAIL_PUTS_ERROR("Allocation failed.");
    for(i = 0; i < nelmts; i++) {
	nchars = HDrand() % 8;
	for(j = 0; j < nchars; j++)
	    buf[i * 8 + j] = 'a' + HDrand() % 26;
	while(j < nchars)
            buf[i * 8 + j++] = '\0';
    } /* end for */

    if(H5Tget_precision(type) == 0) FAIL_STACK_ERROR
    if(H5Tget_size(type) == 0) FAIL_STACK_ERROR
    if(H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE) < 0) FAIL_STACK_ERROR
    if(H5Tget_cset(type) < 0) FAIL_STACK_ERROR
    if(H5Tget_strpad(type) < 0) FAIL_STACK_ERROR
    if(H5Tset_offset(type, (size_t)0) < 0) FAIL_STACK_ERROR
    if(H5Tget_order(type) < 0) FAIL_STACK_ERROR

    H5E_BEGIN_TRY {
        ret = H5Tset_precision(type, nelmts);
    } H5E_END_TRY;
    if(ret >= 0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        size = H5Tget_ebias(type);
    } H5E_END_TRY;
    if(size > 0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        inpad = H5Tget_inpad(type);
    } H5E_END_TRY;
    if(inpad > -1) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        sign = H5Tget_sign(type);
    } H5E_END_TRY;
    if(sign > -1) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        tag = H5Tget_tag(type);
    } H5E_END_TRY;
    if(tag) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    H5E_BEGIN_TRY {
        super = H5Tget_super(type);
    } H5E_END_TRY;
    if(super >= 0) {
        FAIL_PUTS_ERROR("Operation not allowed for this type.");
    } /* end if */

    PASSED();
    ret_value = 0;

error:
    H5E_BEGIN_TRY {
        H5Tclose(type);
        H5Tclose(super);
    } H5E_END_TRY;

    if(buf) 
        HDfree(buf);
    if(tag)
        HDfree(tag);

    reset_hdf5();
    return ret_value;  /* Number of errors */
}


/*-------------------------------------------------------------------------
 * Function:	test_conv_enum_1
 *
 * Purpose:	Test conversion speed for enum datatypes
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Tuesday, January  5, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_conv_enum_1(void)
{
    const size_t nelmts=NTESTELEM;
    int		i, val, *buf=NULL;
    hid_t	t1 = -1;
    hid_t	t2 = -1;
    char	s[80];
    int		ret_value = 1;
    size_t      u;

    /* Build the datatypes */
    if((t1 = H5Tcreate(H5T_ENUM, sizeof(int))) < 0) goto error;
    if((t2 = H5Tenum_create(H5T_NATIVE_INT)) < 0) goto error;
    s[1] = '\0';
    for(i = 0; i < 26; i++) {
	s[0] = 'A' + i;
	H5Tenum_insert(t1, s, &i);
	H5Tenum_insert(t2, s, (val = i * 1000 + i, &val));
    } /* end for */

    /* Initialize the buffer */
    if(NULL == (buf = (int*)HDmalloc(nelmts * MAX(H5Tget_size(t1), H5Tget_size(t2)))))
        goto error;
    for(u = 0; u < nelmts; u++)
        buf[u] = HDrand() % 26;

    /* Conversions */
    sprintf(s, "Testing random enum conversion O(N)");
    printf("%-70s", s);
    HDfflush(stdout);
    if(H5Tconvert(t1, t2, nelmts, buf, NULL, H5P_DEFAULT) < 0) goto error;
    PASSED();

    sprintf(s, "Testing random enum conversion O(N log N)");
    printf("%-70s", s);
    HDfflush(stdout);
    if(H5Tconvert(t2, t1, nelmts, buf, NULL, H5P_DEFAULT) < 0) goto error;
    PASSED();

    ret_value = 0;

error:
    H5E_BEGIN_TRY {
        H5Tclose(t1);
        H5Tclose(t2);
    } H5E_END_TRY;

    if(buf)
        HDfree(buf);

    reset_hdf5();
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:    test_conv_enum_2
 *
 * Purpose:     Tests enumeration conversions where source isn't a native type.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Robb Matzke, LLNL, 2003-06-09
 *
 * Modifications:
 *-------------------------------------------------------------------------
 */
static int
test_conv_enum_2(void)
{
    hid_t       srctype=-1, dsttype=-1, oddsize=-1;
    int         *data=NULL, i, nerrors=0;
    const char  *mname[] = { "RED",
                             "GREEN",
                             "BLUE",
                             "YELLOW",
                             "PINK",
                             "PURPLE",
                             "ORANGE",
                             "WHITE" };

    TESTING("non-native enumeration type conversion");

    /* Source enum type */
    oddsize = H5Tcopy(H5T_STD_I32BE);
    H5Tset_size(oddsize, (size_t)3); /*reduce to 24 bits, not corresponding to any native size*/
    srctype = H5Tenum_create(oddsize);
    for (i=7; i>=0; --i) {
        char pattern[3];
        pattern[2] = i;
        pattern[0] = pattern[1] = 0;
        H5Tenum_insert(srctype, mname[i], pattern);
    }

    /* Destination enum type */
    dsttype = H5Tenum_create(H5T_NATIVE_INT);
    assert(H5Tget_size(dsttype) > H5Tget_size(srctype));
    for (i=0; i<8; i++)
        H5Tenum_insert(dsttype, mname[i], &i);

    /* Source data */
    data = (int*)malloc(NTESTELEM*sizeof(int));
    for (i=0; i<NTESTELEM; i++) {
        ((char*)data)[i*3+2] = i % 8;
        ((char*)data)[i*3+0] = 0;
        ((char*)data)[i*3+1] = 0;
    }

    /* Convert to destination type */
    H5Tconvert(srctype, dsttype, (size_t)NTESTELEM, data, NULL, H5P_DEFAULT);

    /* Check results */
    for (i=0; i<NTESTELEM; i++) {
        if (data[i] != i%8) {
            if (!nerrors++) {
                H5_FAILED();
                printf("element %d is %d but should have been  %d\n",
                       i, data[i], i%8);
            }
        }
    }

    /* Cleanup */
    free(data);
    H5Tclose(srctype);
    H5Tclose(dsttype);
    H5Tclose(oddsize);

    /* Failure */
    if (nerrors) {
        printf("total of %d conversion errors out of %d elements for enums\n",
               nerrors, NTESTELEM);
        return 1;
    }

    PASSED();
    return 0;
}


/*-------------------------------------------------------------------------
 * Function:	test_conv_bitfield
 *
 * Purpose:	Test bitfield conversions.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, May 20, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_conv_bitfield(void)
{
    unsigned char	buf[4];
    hid_t		st=-1, dt=-1;

    TESTING("bitfield conversions");

    /*
     * First test a simple bitfield conversion:
     *                   1010101010101010
     *   ________________1010101010101010
     */
    st = H5Tcopy(H5T_STD_B16LE);
    dt = H5Tcopy(H5T_STD_B32LE);
    buf[0] = buf[1] = 0xAA;
    buf[2] = buf[3] = 0x55; /*irrelevant*/
    if (H5Tconvert(st, dt, (size_t)1, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (buf[0]!=0xAA || buf[1]!=0xAA || buf[2]!=0 || buf[3]!=0) {
	H5_FAILED();
	printf("    s=0xaaaa, d=0x%02x%02x%02x%02x (test 1)\n",
	       buf[3], buf[2], buf[1], buf[0]);
	goto error;
    }

    /*
     * Test2: Offset a 12-byte value in the middle of a 16 and 32 byte
     * field.
     *              __10 1010 1010 10__
     *    ____ ____ __10 1010 1010 10__ ____ ____
     */
    H5Tset_precision(st, (size_t)12);
    H5Tset_offset(st, (size_t)2);
    H5Tset_precision(dt, (size_t)12);
    H5Tset_offset(dt, (size_t)10);
    buf[0] = 0xA8; buf[1] = 0x2A; buf[2] = buf[3] = 0;
    if (H5Tconvert(st, dt, (size_t)1, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (buf[0]!=0 || buf[1]!=0xA8 || buf[2]!=0x2A || buf[3]!=0) {
	H5_FAILED();
	printf("    s=0x2AA8 d=0x%02x%02x%02x%02x (test 2)\n",
	       buf[3], buf[2], buf[1], buf[0]);
	goto error;
    }

    /*
     * Same as previous test except unused bits of the destination will
     * be filled with ones.
     */
    H5Tset_pad(dt, H5T_PAD_ONE, H5T_PAD_ONE);
    buf[0] = 0xA8; buf[1] = 0x2A; buf[2] = buf[3] = 0;
    if (H5Tconvert(st, dt, (size_t)1, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (buf[0]!=0xff || buf[1]!=0xAB || buf[2]!=0xEA || buf[3]!=0xff) {
	H5_FAILED();
	printf("    s=0x2AA8 d=0x%02x%02x%02x%02x (test 3)\n",
	       buf[3], buf[2], buf[1], buf[0]);
	goto error;
    }

    H5Tclose(st);
    H5Tclose(dt);
    PASSED();
    reset_hdf5();
    return 0;

 error:
    H5Tclose(st);
    H5Tclose(dt);
    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	test_bitfield_funcs
 *
 * Purpose:	Test some datatype functions that are and aren't supposed
 *              work for bitfield type.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Raymond Lu
 *              Wednesday, April 5, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_bitfield_funcs(void)
{
    hid_t		type=-1, ntype=-1, super=-1;
    int                 size;
    char*               tag;
    H5T_pad_t           inpad;
    H5T_cset_t          cset;
    H5T_str_t           strpad;
    herr_t              ret;

    TESTING("some type functions for bitfield");

    /*
     * First create a bitfield type.
     */
    if((type = H5Tcopy(H5T_STD_B32LE)) < 0) goto error;

    /*
     * Offset a 12-byte value in the middle of a 16 and 32 byte
     * field.  Pad unused bits with ones.
     *    ____ ____ __10 1010 1010 10__ ____ ____
     */
    if(H5Tset_precision(type, (size_t)12) < 0) goto error;
    if(H5Tset_offset(type, (size_t)10) < 0) goto error;
    if(H5Tset_pad(type, H5T_PAD_ONE, H5T_PAD_ONE)) goto error;
    if((size=H5Tget_size(type))==0) goto error;
    if(H5Tset_order(type, H5T_ORDER_BE) < 0) goto error;
    if((ntype = H5Tget_native_type(type, H5T_DIR_ASCEND)) < 0) goto error;

    H5E_BEGIN_TRY {
        size=H5Tget_ebias(type);
    } H5E_END_TRY;
    if (size>0) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5E_BEGIN_TRY {
        inpad=H5Tget_inpad(type);
    } H5E_END_TRY;
    if (inpad>-1) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5E_BEGIN_TRY {
        cset=H5Tget_cset(type);
    } H5E_END_TRY;
    if (cset>-1) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5E_BEGIN_TRY {
        strpad=H5Tget_strpad(type);
    } H5E_END_TRY;
    if (strpad>-1) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5E_BEGIN_TRY {
        ret=H5Tset_sign(type, H5T_SGN_2);
    } H5E_END_TRY;
    if(ret>=0) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5E_BEGIN_TRY {
        tag = H5Tget_tag(type);
    } H5E_END_TRY;
    if (tag) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5E_BEGIN_TRY {
        super = H5Tget_super(type);
    } H5E_END_TRY;
    if (super>=0) {
        H5_FAILED();
        printf("Operation not allowed for this type.\n");
        goto error;
    } /* end if */

    H5Tclose(type);
    H5Tclose(ntype);
    PASSED();
    reset_hdf5();
    return 0;

 error:
    H5Tclose(type);
    reset_hdf5();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	convert_opaque
 *
 * Purpose:	A fake opaque conversion functions
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:	Robb Matzke
 *              Friday, June  4, 1999
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
convert_opaque(hid_t UNUSED st, hid_t UNUSED dt, H5T_cdata_t *cdata,
	       size_t UNUSED nelmts, size_t UNUSED buf_stride,
               size_t UNUSED bkg_stride, void UNUSED *_buf,
	       void UNUSED *bkg, hid_t UNUSED dset_xfer_plid)
{
    if (H5T_CONV_CONV==cdata->command) num_opaque_conversions_g++;
    return 0;
}


/*-------------------------------------------------------------------------
 * Function:	test_opaque
 *
 * Purpose:	Driver function to test opaque datatypes
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Raymond Lu
 *              June 2, 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_opaque(void)
{
    int num_errors = 0;

    TESTING("opaque datatypes");

    /* Test opaque types with tags */
    num_errors += opaque_check(0);
    /* Test opaque types without tag */
    num_errors += opaque_check(1);
    /* Test named opaque types with very long tag */
    num_errors += opaque_long();
    /* Test some type functions with opaque type */
    num_errors += opaque_funcs();

    if(num_errors)
        goto error;

    PASSED();
    return 0;

 error:
    return num_errors;
}


/*-------------------------------------------------------------------------
 * Function:	opaque_check
 *
 * Purpose:	Test opaque datatypes
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Thursday, May 20, 1999
 *
 *-------------------------------------------------------------------------
 */
static int
opaque_check(int tag_it)
{
#define OPAQUE_NELMTS 1000
    hid_t	st=-1, dt=-1;
    herr_t	status;
    char	buf[1]; /*not really used*/
    int		saved;

    saved = num_opaque_conversions_g = 0;

    /* Build source and destination types */
    if ((st=H5Tcreate(H5T_OPAQUE, (size_t)4)) < 0) goto error;
    if (H5Tset_tag(st, "opaque source type") < 0) goto error;

    if ((dt=H5Tcreate(H5T_OPAQUE, (size_t)4)) < 0) goto error;
    if (tag_it) {
        if (H5Tset_tag(dt, "opaque destination type") < 0)
            goto error;
    }

    /* Make sure that we can't convert between the types yet */
    H5E_BEGIN_TRY {
	status = H5Tconvert(st, dt, (size_t)OPAQUE_NELMTS, buf, NULL, H5P_DEFAULT);
    } H5E_END_TRY;
    if (status>=0) {
	H5_FAILED();
	printf("    opaque conversion should have failed but succeeded\n");
	goto error;
    }

    /* Register a conversion function */
    if (H5Tregister(H5T_PERS_HARD, "o_test", st, dt, convert_opaque) < 0)
	goto error;

    /* Try the conversion again, this time it should work */
    if (H5Tconvert(st, dt, (size_t)OPAQUE_NELMTS, buf, NULL, H5P_DEFAULT) < 0) goto error;
    if (saved+1 != num_opaque_conversions_g) {
	H5_FAILED();
	printf("    unexpected number of opaque conversions\n");
	goto error;
    }

    /* Unregister conversion function */
    if (H5Tunregister(H5T_PERS_HARD, "o_test", st, dt, convert_opaque) < 0)
	goto error;

    H5Tclose(st);
    H5Tclose(dt);
    return 0;

 error:
    if (st>0) H5Tclose(st);
    if (dt>0) H5Tclose(dt);
    H5_FAILED();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	opaque_long
 *
 * Purpose:	Test named (committed) opaque datatypes w/very long tags
 *
 * Return:	Success:	0
 *		Failure:	number of errors
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, June 14, 2005
 *
 *-------------------------------------------------------------------------
 */
static int
opaque_long(void)
{
    char 	*long_tag = NULL;
    hid_t	dt = -1;
    herr_t      ret;

    /* Build opaque type */
    if((dt=H5Tcreate(H5T_OPAQUE, (size_t)4)) < 0) TEST_ERROR

    /* Create long tag */
    if(NULL == (long_tag = (char *)HDmalloc((size_t)(16384 + 1)))) TEST_ERROR
    HDmemset(long_tag, 'a', (size_t)16384);
    long_tag[16384] = '\0';

    /* Set opaque type's tag */
    H5E_BEGIN_TRY {
	ret = H5Tset_tag(dt, long_tag);
    } H5E_END_TRY;
    if(ret != FAIL) TEST_ERROR

    /* Close datatype */
    if(H5Tclose(dt) < 0) TEST_ERROR

    /* Release memory for tag */
    HDfree(long_tag);

    return 0;

error:
    if(dt>0)
        H5Tclose(dt);
    if(long_tag)
        HDfree(long_tag);
    H5_FAILED();
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:	opaque_funcs
 *
 * Purpose:	Test some type functions that are and aren't supposed to
 *              work with opaque type.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Raymond Lu
 *              Wednesday, April 5, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
opaque_funcs(void)
{
    hid_t	type = -1, super=-1;
    int         size;
    H5T_pad_t   inpad;
    H5T_cset_t  cset;
    H5T_str_t   strpad;
    H5T_sign_t  sign;
    herr_t      ret;

    /* Build opaque type */
    if ((type=H5Tcreate(H5T_OPAQUE, (size_t)4)) < 0) TEST_ERROR
    if (H5Tset_tag(type, "opaque source type") < 0) TEST_ERROR

    if ((size=H5Tget_size(type))==0) goto error;

    H5E_BEGIN_TRY {
        ret=H5Tset_precision(type, (size_t)32);
    } H5E_END_TRY;
    if (ret>=0) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        ret=H5Tset_pad(type, H5T_PAD_ZERO, H5T_PAD_ONE);
    } H5E_END_TRY;
    if (ret>=0) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        size=H5Tget_ebias(type);
    } H5E_END_TRY;
    if (size>0) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        inpad=H5Tget_inpad(type);
    } H5E_END_TRY;
    if (inpad>-1) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        cset=H5Tget_cset(type);
    } H5E_END_TRY;
    if (cset>-1) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        strpad=H5Tget_strpad(type);
    } H5E_END_TRY;
    if (strpad>-1) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        ret=H5Tset_offset(type, (size_t)16);
    } H5E_END_TRY;
    if (ret>=0) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        ret=H5Tset_order(type, H5T_ORDER_BE);
    } H5E_END_TRY;
    if (ret>=0) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        sign = H5Tget_sign(type);
    } H5E_END_TRY;
    if (sign>-1) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    H5E_BEGIN_TRY {
        super = H5Tget_super(type);
    } H5E_END_TRY;
    if (super>=0) {
        printf("Operation not allowed for this type.\n");
        TEST_ERROR
    } /* end if */

    /* Close datatype */
    if(H5Tclose(type) < 0) TEST_ERROR
    return 0;

 error:
    if (type>0) H5Tclose(type);
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_encode
 *
 * Purpose:     Tests functions of encoding and decoding datatype.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Raymond Lu
 *              July 14, 2004
 *
 * Modifications: Raymond Lu
 *              July 13, 2009
 *              Added the test for VL string types.
 *-------------------------------------------------------------------------
 */
static int
test_encode(void)
{
    struct s1 {
        int    a;
        float  b;
        long   c;
        double d;
    };
    hid_t       file=-1, tid1=-1, tid2=-1, tid3=-1;
    hid_t       decoded_tid1=-1, decoded_tid2=-1, decoded_tid3=-1;
    char        filename[1024];
    char        compnd_type[]="Compound_type", enum_type[]="Enum_type";
    char        vlstr_type[]="VLstring_type";
    short       enum_val;
    size_t      cmpd_buf_size = 0;
    size_t      enum_buf_size = 0;
    size_t      vlstr_buf_size = 0;
    unsigned char       *cmpd_buf=NULL, *enum_buf=NULL, *vlstr_buf=NULL;
    herr_t      ret;

    TESTING("functions of encoding and decoding datatypes");

    /* Create File */
    h5_fixname(FILENAME[5], H5P_DEFAULT, filename, sizeof filename);
    if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        goto error;

    /*-----------------------------------------------------------------------
     * Create compound, enumerate, and VL string datatypes
     *-----------------------------------------------------------------------
     */
    /* Create a compound datatype */
    if((tid1=H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) {
        H5_FAILED();
        printf("Can't create datatype!\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "a", HOFFSET(struct s1, a), H5T_NATIVE_INT) < 0) {
        H5_FAILED();
        printf("Can't insert field 'a'\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "b", HOFFSET(struct s1, b), H5T_NATIVE_FLOAT) < 0) {
        H5_FAILED();
        printf("Can't insert field 'b'\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "c", HOFFSET(struct s1, c), H5T_NATIVE_LONG) < 0) {
        H5_FAILED();
        printf("Can't insert field 'c'\n");
        goto error;
    } /* end if */
    if(H5Tinsert(tid1, "d", HOFFSET(struct s1, d), H5T_NATIVE_DOUBLE) < 0) {
        H5_FAILED();
        printf("Can't insert field 'd'\n");
        goto error;
    } /* end if */

    /* Create a enumerate datatype */
    if((tid2=H5Tcreate(H5T_ENUM, sizeof(short))) < 0) {
        H5_FAILED();
        printf("Can't create enumerate type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "RED", (enum_val=0,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "GREEN", (enum_val=1,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "BLUE", (enum_val=2,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "ORANGE", (enum_val=3,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */
    if(H5Tenum_insert(tid2, "YELLOW", (enum_val=4,&enum_val)) < 0) {
        H5_FAILED();
        printf("Can't insert field into enumeration type\n");
        goto error;
    } /* end if */

    /* Create a variable-length string type */
    if((tid3 = H5Tcopy(H5T_C_S1)) < 0) {
        H5_FAILED();
        printf("Can't copy a string type\n");
        goto error;
    } /* end if */
    if(H5Tset_size(tid3, H5T_VARIABLE) < 0) {
        H5_FAILED();
        printf("Can't the string type to be variable-length\n");
        goto error;
    } /* end if */

    /*-----------------------------------------------------------------------
     * Test encoding and decoding compound, enumerate, and VL string datatypes
     *-----------------------------------------------------------------------
     */
    /* Encode compound type in a buffer */
    if(H5Tencode(tid1, NULL, &cmpd_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode compound type\n");
        goto error;
    } /* end if */

    if(cmpd_buf_size>0)
        cmpd_buf = (unsigned char*)HDcalloc((size_t)1, cmpd_buf_size);

    /* Try decoding bogus buffer */
    H5E_BEGIN_TRY {
	ret = H5Tdecode(cmpd_buf);
    } H5E_END_TRY;
    if(ret!=FAIL) {
        H5_FAILED();
        printf("Decoded bogus buffer!\n");
        goto error;
    }

    if(H5Tencode(tid1, cmpd_buf, &cmpd_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode compound type\n");
        goto error;
    } /* end if */

    /* Decode from the compound buffer and return an object handle */
    if((decoded_tid1 = H5Tdecode(cmpd_buf)) < 0)
        FAIL_PUTS_ERROR("Can't decode compound type\n")

    /* Verify that the datatype was copied exactly */
    if(H5Tequal(decoded_tid1, tid1)<=0) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */

    /* Query member number and member index by name, for compound type. */
    if(H5Tget_nmembers(decoded_tid1)!=4) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(decoded_tid1, "c")!=2) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */


    /* Encode enumerate type in a buffer */
    if(H5Tencode(tid2, NULL, &enum_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode enumerate type\n");
        goto error;
    } /* end if */

    if(enum_buf_size>0)
        enum_buf = (unsigned char*)HDcalloc((size_t)1, enum_buf_size);

    if(H5Tencode(tid2, enum_buf, &enum_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode enumerate type\n");
        goto error;
    } /* end if */

    /* Decode from the enumerate buffer and return an object handle */
    if((decoded_tid2=H5Tdecode(enum_buf)) < 0) {
        H5_FAILED();
        printf("Can't decode enumerate type\n");
        goto error;
    } /* end if */

    /* Verify that the datatype was copied exactly */
    if(H5Tequal(decoded_tid2, tid2)<=0) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */

    /* Query member number and member index by name, for enumeration type. */
    if(H5Tget_nmembers(decoded_tid2)!=5) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(decoded_tid2, "ORANGE") != 3) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */


    /* Encode VL string type in a buffer */
    if(H5Tencode(tid3, NULL, &vlstr_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode VL string type\n");
        goto error;
    } /* end if */

    if(vlstr_buf_size>0)
        vlstr_buf = (unsigned char*)HDcalloc((size_t)1, vlstr_buf_size);

    if(H5Tencode(tid3, vlstr_buf, &vlstr_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode VL string type\n");
        goto error;
    } /* end if */

    /* Decode from the VL string buffer and return an object handle */
    if((decoded_tid3=H5Tdecode(vlstr_buf)) < 0) {
        H5_FAILED();
        printf("Can't decode VL string type\n");
        goto error;
    } /* end if */

    /* Verify that the datatype was copied exactly */
    if(H5Tequal(decoded_tid3, tid3)<=0) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */
    if(!H5Tis_variable_str(decoded_tid3)) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */

    /*-----------------------------------------------------------------------
     * Commit and reopen the compound, enumerate, VL string datatypes
     *-----------------------------------------------------------------------
     */
    /* Commit compound datatype and close it */
    if(H5Tcommit2(file, compnd_type, tid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
        H5_FAILED();
        printf("Can't commit compound datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid1) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(decoded_tid1) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    free(cmpd_buf);
    cmpd_buf_size = 0;

    /* Commit enumeration datatype and close it */
    if(H5Tcommit2(file, enum_type, tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
        H5_FAILED();
        printf("Can't commit compound datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(decoded_tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    free(enum_buf);
    enum_buf_size = 0;

    /* Commit enumeration datatype and close it */
    if(H5Tcommit2(file, vlstr_type, tid3, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
        H5_FAILED();
        printf("Can't commit vl string datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid3) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(decoded_tid3) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    free(vlstr_buf);
    vlstr_buf_size = 0;

    /* Open the dataytpe for query */
    if((tid1 = H5Topen2(file, compnd_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR
    if((tid2 = H5Topen2(file, enum_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR
    if((tid3 = H5Topen2(file, vlstr_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    /*-----------------------------------------------------------------------
     * Test encoding and decoding compound, enumerate, and vl string datatypes
     *-----------------------------------------------------------------------
     */
    /* Encode compound type in a buffer */
    if(H5Tencode(tid1, NULL, &cmpd_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode compound type\n");
        goto error;
    } /* end if */

    if(cmpd_buf_size>0)
        cmpd_buf = (unsigned char*)HDcalloc((size_t)1, cmpd_buf_size);

    if(H5Tencode(tid1, cmpd_buf, &cmpd_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode compound type\n");
        goto error;
    } /* end if */

    /* Decode from the compound buffer and return an object handle */
    if((decoded_tid1 = H5Tdecode(cmpd_buf)) < 0)
        FAIL_PUTS_ERROR("Can't decode compound type\n")

    /* Verify that the datatype was copied exactly */
    if(H5Tequal(decoded_tid1, tid1)<=0) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */

    /* Query member number and member index by name, for compound type. */
    if(H5Tget_nmembers(decoded_tid1)!=4) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(decoded_tid1, "c")!=2) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */

    /* Encode enumerate type in a buffer */
    if(H5Tencode(tid2, NULL, &enum_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode enumerate type\n");
        goto error;
    } /* end if */

    if(enum_buf_size>0)
        enum_buf = (unsigned char*)HDcalloc((size_t)1, enum_buf_size);

    if(H5Tencode(tid2, enum_buf, &enum_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode enumerate type\n");
        goto error;
    } /* end if */

    /* Decode from the enumerate buffer and return an object handle */
    if((decoded_tid2=H5Tdecode(enum_buf)) < 0) {
        H5_FAILED();
        printf("Can't decode enumerate type\n");
        goto error;
    } /* end if */

    /* Verify that the datatype was copied exactly */
    if(H5Tequal(decoded_tid2, tid2)<=0) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */

    /* Query member number and member index by name, for enumeration type. */
    if(H5Tget_nmembers(decoded_tid2)!=5) {
        H5_FAILED();
        printf("Can't get member number\n");
        goto error;
    } /* end if */
    if(H5Tget_member_index(decoded_tid2, "ORANGE")!=3) {
        H5_FAILED();
        printf("Can't get correct index number\n");
        goto error;
    } /* end if */

    /* Encode VL string type in a buffer */
    if(H5Tencode(tid3, NULL, &vlstr_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode VL string type\n");
        goto error;
    } /* end if */

    if(vlstr_buf_size>0)
        vlstr_buf = (unsigned char*)HDcalloc((size_t)1, vlstr_buf_size);

    if(H5Tencode(tid3, vlstr_buf, &vlstr_buf_size) < 0) {
        H5_FAILED();
        printf("Can't encode VL string type\n");
        goto error;
    } /* end if */

    /* Decode from the VL string buffer and return an object handle */
    if((decoded_tid3=H5Tdecode(vlstr_buf)) < 0) {
        H5_FAILED();
        printf("Can't decode VL string type\n");
        goto error;
    } /* end if */

    /* Verify that the datatype was copied exactly */
    if(H5Tequal(decoded_tid3, tid3)<=0) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */
    if(!H5Tis_variable_str(decoded_tid3)) {
        H5_FAILED();
        printf("Datatype wasn't encoded & decoded identically\n");
        goto error;
    } /* end if */

    /*-----------------------------------------------------------------------
     * Close and release
     *-----------------------------------------------------------------------
     */
    /* Close datatype and file */
    if(H5Tclose(tid1) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(tid3) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */

    if(H5Tclose(decoded_tid1) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(decoded_tid2) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */
    if(H5Tclose(decoded_tid3) < 0) {
        H5_FAILED();
        printf("Can't close datatype\n");
        goto error;
    } /* end if */

    if(H5Fclose(file) < 0) {
        H5_FAILED();
        printf("Can't close file\n");
        goto error;
    } /* end if */

    free(cmpd_buf);
    free(enum_buf);

    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
        H5Tclose (tid1);
        H5Tclose (tid2);
        H5Tclose (tid3);
        H5Tclose (decoded_tid1);
        H5Tclose (decoded_tid2);
        H5Tclose (decoded_tid3);
        H5Fclose (file);
    } H5E_END_TRY;
    return 1;
}


/*-------------------------------------------------------------------------
 * Function:    test_latest
 *
 * Purpose:     Test encoding datatypes with the "use the latest version of
 *              the file format" flag turned on.
 *
 * Return:      Success:        0
 *              Failure:        number of errors
 *
 * Programmer:  Quincey Koziol
 *              October 2, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_latest(void)
{
    struct s1 {
        int    a;
        float  b;
        long   c;
        double d;
    };
    hid_t       file = (-1);            /* File ID */
    hid_t       tid1 = (-1), tid2 = (-1); /* Datatype ID */
    hid_t       fapl = (-1);            /* File access property list */
    H5O_info_t	oi;                     /* Stat buffer for committed datatype */
    hsize_t     old_dtype_oh_size;      /* Size of object header with "old" format */
    hsize_t     new_dtype_oh_size;      /* Size of object header with "new" format */
    char        filename[1024];         /* Buffer for filename */
    const char  compnd_type[] = "Compound_type";        /* Name of committed datatype */

    TESTING("encoding datatypes with the 'use the latest format' flag");

    /* Create a compound datatype */
    if((tid1 = H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0)
        FAIL_STACK_ERROR
    if(H5Tinsert(tid1, "a", HOFFSET(struct s1, a), H5T_NATIVE_INT) < 0)
        FAIL_STACK_ERROR
    if(H5Tinsert(tid1, "b", HOFFSET(struct s1, b), H5T_NATIVE_FLOAT) < 0)
        FAIL_STACK_ERROR
    if(H5Tinsert(tid1, "c", HOFFSET(struct s1, c), H5T_NATIVE_LONG) < 0)
        FAIL_STACK_ERROR
    if(H5Tinsert(tid1, "d", HOFFSET(struct s1, d), H5T_NATIVE_DOUBLE) < 0)
        FAIL_STACK_ERROR

    /* Create file using default FAPL */
    h5_fixname(FILENAME[5], H5P_DEFAULT, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    /* Make a copy of the datatype, to commit */
    if((tid2 = H5Tcopy(tid1)) < 0)
        FAIL_STACK_ERROR

    /* Commit compound datatype */
    if(H5Tcommit2(file, compnd_type, tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0)
        FAIL_STACK_ERROR

    /* Get information about datatype on disk */
    if(H5Oget_info_by_name(file, compnd_type, &oi, H5P_DEFAULT) < 0)
        FAIL_STACK_ERROR
    old_dtype_oh_size = oi.hdr.space.total;

    /* Close datatype */
    if(H5Tclose(tid2) < 0)
        FAIL_STACK_ERROR

    /* Close file */
    if(H5Fclose(file) < 0)
        FAIL_STACK_ERROR

    /* Check that datatype has been encoded/decoded correctly */
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    /* Open the dataytpe for query */
    if((tid2 = H5Topen2(file, compnd_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    /* Verify that the datatype was encoded/decoded correctly */
    if(H5Tequal(tid1, tid2) <= 0)
        FAIL_STACK_ERROR

    /* Get information about datatype on disk */
    if(H5Oget_info_by_name(file, compnd_type, &oi, H5P_DEFAULT) < 0)
        FAIL_STACK_ERROR

    /* Check that the object header info is still the same */
    if(old_dtype_oh_size != oi.hdr.space.total)
        TEST_ERROR

    /* Close datatype */
    if(H5Tclose(tid2) < 0)
        FAIL_STACK_ERROR

    /* Close file */
    if(H5Fclose(file) < 0)
        FAIL_STACK_ERROR


    /* Set the 'use the latest format' bounds in the FAPL */
    if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
        FAIL_STACK_ERROR
    if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
        FAIL_STACK_ERROR

    /* Create file using default FAPL */
    h5_fixname(FILENAME[5], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        FAIL_STACK_ERROR

    /* Make a copy of the datatype, to commit */
    if((tid2 = H5Tcopy(tid1)) < 0)
        FAIL_STACK_ERROR

    /* Commit compound datatype */
    if(H5Tcommit2(file, compnd_type, tid2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0)
        FAIL_STACK_ERROR

    /* Get information about datatype on disk */
    if(H5Oget_info_by_name(file, compnd_type, &oi, H5P_DEFAULT) < 0)
        FAIL_STACK_ERROR
    new_dtype_oh_size = oi.hdr.space.total;

    /* Check that the new format is smaller than the old format */
    if(old_dtype_oh_size <= new_dtype_oh_size)
        TEST_ERROR

    /* Close datatype */
    if(H5Tclose(tid2) < 0)
        FAIL_STACK_ERROR

    /* Close file */
    if(H5Fclose(file) < 0)
        FAIL_STACK_ERROR

    /* Check that datatype has been encoded/decoded correctly */
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
        FAIL_STACK_ERROR

    /* Open the dataytpe for query */
    if((tid2 = H5Topen2(file, compnd_type, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR

    /* Verify that the datatype was encoded/decoded correctly */
    if(H5Tequal(tid1, tid2) <= 0)
        FAIL_STACK_ERROR

    /* Get information about datatype on disk */
    if(H5Oget_info_by_name(file, compnd_type, &oi, H5P_DEFAULT) < 0)
        FAIL_STACK_ERROR

    /* Check that the object header info is still the same */
    if(new_dtype_oh_size != oi.hdr.space.total)
        TEST_ERROR

    /* Close datatype */
    if(H5Tclose(tid2) < 0)
        FAIL_STACK_ERROR

    /* Close file */
    if(H5Fclose(file) < 0)
        FAIL_STACK_ERROR


    /* Close FAPL */
    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR

    /* Close datatype */
    if(H5Tclose(tid1) < 0)
        FAIL_STACK_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
        H5Tclose(tid2);
        H5Tclose(tid1);
        H5Fclose(file);
        H5Pclose(fapl);
    } H5E_END_TRY;

    return 1;
} /* end test_latest() */

typedef struct {
    unsigned num_range_hi;      /* Number of H5T_CONV_EXCEPT_RANGE_HI exceptions seen */
    unsigned num_range_low;     /* Number of H5T_CONV_EXCEPT_RANGE_LOW exceptions seen */
    unsigned num_precision;     /* Number of H5T_CONV_EXCEPT_PRECISION exceptions seen */
    unsigned num_truncate;      /* Number of H5T_CONV_EXCEPT_TRUNCATE exceptions seen */
    unsigned num_other;         /* Number of other exceptions seen */
} except_info_t;

static H5T_conv_ret_t
conv_except(H5T_conv_except_t except_type, hid_t UNUSED src_id, hid_t UNUSED dst_id,
    void UNUSED *src_buf, void UNUSED *dst_buf, void *_user_data)
{
    except_info_t *user_data = (except_info_t *)_user_data;

    if(except_type == H5T_CONV_EXCEPT_RANGE_HI)
        user_data->num_range_hi++;
    else if(except_type == H5T_CONV_EXCEPT_RANGE_LOW)
        user_data->num_range_low++;
    else if(except_type == H5T_CONV_EXCEPT_PRECISION)
        user_data->num_precision++;
    else if(except_type == H5T_CONV_EXCEPT_TRUNCATE)
        user_data->num_truncate++;
    else
        user_data->num_other++;

    return(H5T_CONV_UNHANDLED);
}


/*-------------------------------------------------------------------------
 * Function:    test_int_float_except
 *
 * Purpose:     Tests exception handling behavior of int <-> float
 *              conversions.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Quincey Koziol
 *              August 18, 2005
 *
 * Notes: This routine is pretty specific to 4 byte integers and 4 byte
 *              floats and I can't think of a particularly good way to
 *              make it portable to other architectures, but further
 *              input and changes are welcome.  -QAK
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_int_float_except(void)
{
#if H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4
    float buf[CONVERT_SIZE] = {(float)INT_MIN - 172.0, (float)INT_MAX - 32.0,
            (float)INT_MAX - 68.0, (float)4.5};
    int buf_int[CONVERT_SIZE] = {INT_MIN, INT_MAX, INT_MAX-127, 4};
    float buf_float[CONVERT_SIZE] = {INT_MIN, INT_MAX + 1.0, INT_MAX - 127.0, 4};
    int *intp;          /* Pointer to buffer, as integers */
    int buf2[CONVERT_SIZE] = {INT_MIN, INT_MAX, INT_MAX - 72, 0};
    float buf2_float[CONVERT_SIZE] = {INT_MIN, INT_MAX, INT_MAX - 127.0, (float)0.0};
    int buf2_int[CONVERT_SIZE] = {INT_MIN, INT_MAX, INT_MAX - 127, 0};
    float *floatp;      /* Pointer to buffer #2, as floats */
    hid_t dxpl;         /* Dataset transfer property list */
    except_info_t e;    /* Exception information */
    unsigned u;         /* Local index variables */
#endif /* H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4 */

    TESTING("exceptions for int <-> float conversions");

#if H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4
    /* Create dataset transfer property list */
    if((dxpl = H5Pcreate(H5P_DATASET_XFER) ) < 0) TEST_ERROR

    /* Set the conversion exception handler in the DXPL */
    if(H5Pset_type_conv_cb(dxpl, conv_except, &e) < 0) TEST_ERROR

    /* Convert buffer */
    HDmemset(&e, 0, sizeof(except_info_t));
    if(H5Tconvert(H5T_NATIVE_FLOAT, H5T_NATIVE_INT, (size_t)CONVERT_SIZE, buf, NULL, dxpl) < 0) TEST_ERROR

    /* Check the buffer after conversion, as integers */
    for(u = 0; u < CONVERT_SIZE; u++) {
        intp = (int *)&buf[u];
        if(*intp != buf_int[u]) TEST_ERROR
    } /* end for */

    /* Check for proper exceptions */
    if(e.num_range_hi != 1) TEST_ERROR
    if(e.num_range_low != 1) TEST_ERROR
    if(e.num_precision != 0) TEST_ERROR
    if(e.num_truncate != 1) TEST_ERROR
    if(e.num_other != 0) TEST_ERROR

    /* Convert buffer */
    HDmemset(&e, 0, sizeof(except_info_t));
    if(H5Tconvert(H5T_NATIVE_INT, H5T_NATIVE_FLOAT, (size_t)CONVERT_SIZE,
            buf, NULL, dxpl) < 0) TEST_ERROR

    /* Check the buffer after conversion, as floats */
    for(u = 0; u < CONVERT_SIZE; u++) {
        floatp = (float *)&buf[u];
        if(*floatp != buf_float[u]) TEST_ERROR
    } /* end for */

    /* Check for proper exceptions */
    if(e.num_range_hi != 0) TEST_ERROR
    if(e.num_range_low != 0) TEST_ERROR
    if(e.num_precision != 1) TEST_ERROR
    if(e.num_truncate != 0) TEST_ERROR
    if(e.num_other != 0) TEST_ERROR


    /* Work on second buffer */

    /* Convert second buffer */
    HDmemset(&e, 0, sizeof(except_info_t));
    if(H5Tconvert(H5T_NATIVE_INT, H5T_NATIVE_FLOAT, (size_t)CONVERT_SIZE,
            buf2, NULL, dxpl) < 0) TEST_ERROR

    /* Check the buffer after conversion, as floats */
    for(u = 0; u < CONVERT_SIZE; u++) {
        floatp = (float *)&buf2[u];
        if(*floatp != buf2_float[u]) TEST_ERROR
    } /* end for */

    /* Check for proper exceptions */
    if(e.num_range_hi != 0) TEST_ERROR
    if(e.num_range_low != 0) TEST_ERROR
    if(e.num_precision != 2) TEST_ERROR
    if(e.num_truncate != 0) TEST_ERROR
    if(e.num_other != 0) TEST_ERROR

    /* Convert buffer */
    HDmemset(&e, 0, sizeof(except_info_t));
    if(H5Tconvert(H5T_NATIVE_FLOAT, H5T_NATIVE_INT, (size_t)CONVERT_SIZE,
            buf2, NULL, dxpl) < 0) TEST_ERROR

    /* Check the buffer after conversion, as integers */
    for(u = 0; u < CONVERT_SIZE; u++) {
        intp = (int *)&buf2[u];
        if(*intp != buf2_int[u]) TEST_ERROR
    } /* end for */

    /* Check for proper exceptions */
    if(e.num_range_hi != 1) TEST_ERROR
    if(e.num_range_low != 0) TEST_ERROR
    if(e.num_precision != 0) TEST_ERROR
    if(e.num_truncate != 0) TEST_ERROR
    if(e.num_other != 0) TEST_ERROR

    /* Close DXPL */
    if(H5Pclose(dxpl) < 0) TEST_ERROR

    PASSED();
#else /* H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4 */
    SKIPPED();
    HDputs("    Test skipped due to int or float not 4 bytes.");
#endif /* H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4 */
    return 0;

#if H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4
error:
    H5E_BEGIN_TRY {
        H5Pclose (dxpl);
    } H5E_END_TRY;
    return 1;
#endif /* H5_SIZEOF_INT==4 && H5_SIZEOF_FLOAT==4 */
} /* end test_int_float_except() */


/*-------------------------------------------------------------------------
 * Function:    test_set_order
 *
 * Purpose:     Tests H5Tset_order/H5Tget_order.  Verifies that
 *              H5T_ORDER_NONE cannot be set.
 *
 * Return:      Success:        0
 *
 *              Failure:        number of errors
 *
 * Programmer:  Neil Fortner
 *              January 23, 2009
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_set_order(void)
{
    hid_t       dtype;              /* Datatype ID */
    H5T_order_t order;              /* Byte order */
    hsize_t     dims[2] = {3, 4};   /* Array dimenstions */
    herr_t      ret;                /* Generic return value */

    TESTING("H5Tset/get_order");

    /* Integer */
    if ((dtype = H5Tcopy(H5T_STD_I32BE)) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Float */
    if ((dtype = H5Tcopy(H5T_IEEE_F64LE)) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Time */
    if ((dtype = H5Tcopy(H5T_UNIX_D64BE)) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Fixed length string */
    if ((dtype = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
    if (H5Tset_size(dtype, (size_t)5) < 0) TEST_ERROR
    if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR;
    if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;

    /* Variable length string */
    if (H5Tset_size(dtype, H5T_VARIABLE) < 0) TEST_ERROR
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Bitfield */
    if ((dtype = H5Tcopy(H5T_STD_B16LE)) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Opaque - functions should fail */
    if ((dtype = H5Tcreate(H5T_OPAQUE, (size_t)96)) < 0) TEST_ERROR
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_LE);
        order = H5Tget_order(dtype);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (order >= 0) TEST_ERROR
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Compound - functions should fail */
    if ((dtype = H5Tcreate(H5T_COMPOUND, (size_t)48)) < 0) TEST_ERROR
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_LE);
        order = H5Tget_order(dtype);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (order >= 0) TEST_ERROR
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Object reference */
    if ((dtype = H5Tcopy(H5T_STD_REF_OBJ)) < 0) TEST_ERROR
    if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR;
    if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Region reference */
    if ((dtype = H5Tcopy(H5T_STD_REF_DSETREG)) < 0) TEST_ERROR
    if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tset_order(dtype, H5T_ORDER_NONE) < 0) TEST_ERROR;
    if (H5T_ORDER_NONE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Enum */
    if ((dtype = H5Tenum_create(H5T_STD_I16BE)) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Vlen */
    if ((dtype = H5Tvlen_create(H5T_STD_U64LE)) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_BE) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    /* Array */
    if ((dtype = H5Tarray_create2(H5T_IEEE_F64BE, 2, dims)) < 0) TEST_ERROR
    if (H5T_ORDER_BE != H5Tget_order(dtype)) TEST_ERROR;
    H5E_BEGIN_TRY
        ret = H5Tset_order(dtype, H5T_ORDER_NONE);
    H5E_END_TRY
    if (ret >= 0) TEST_ERROR
    if (H5Tset_order(dtype, H5T_ORDER_LE) < 0) TEST_ERROR
    if (H5T_ORDER_LE != H5Tget_order(dtype)) TEST_ERROR;
    if (H5Tclose(dtype) < 0) TEST_ERROR

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY
        H5Tclose (dtype);
    H5E_END_TRY;
    return 1;
} /* end test_set_order() */


/*-------------------------------------------------------------------------
 * Function:	test_named_indirect_reopen
 *
 * Purpose:	Tests that open named datatypes can be reopened indirectly
 *              through H5Dget_type without causing problems.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Neil Fortner
 *              Thursday, June 4, 2009
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_named_indirect_reopen(hid_t fapl)
{
    hid_t		file=-1, type=-1, reopened_type=-1, strtype=-1, dset=-1, space=-1;
    static hsize_t	dims[1] = {3};
    size_t              dt_size;
    int                 enum_value;
    const char          *tag = "opaque_tag";
    char                *tag_ret = NULL;
    char		filename[1024];

    TESTING("indirectly reopening committed datatypes");

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

    /*
     * Compound
     */

    /* Create compound type */
    if((strtype = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
    if(H5Tset_size(strtype, H5T_VARIABLE) < 0) TEST_ERROR
    if((type = H5Tcreate(H5T_COMPOUND, sizeof(char *))) < 0) TEST_ERROR
    if(H5Tinsert(type, "vlstr", (size_t)0, strtype) < 0) TEST_ERROR
    if(H5Tclose(strtype) < 0) TEST_ERROR

    /* Get size of compound type */
    if((dt_size = H5Tget_size(type)) == 0) TEST_ERROR

    /* Commit compound type and verify the size doesn't change */
    if(H5Tcommit2(file, "cmpd_type", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(type)) TEST_ERROR

    /* Create dataset with compound type */
    if((dset = H5Dcreate2(file, "cmpd_dset", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Indirectly reopen type and verify that the size doesn't change */
    if((reopened_type = H5Dget_type(dset)) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(reopened_type)) TEST_ERROR

    /* Close types and dataset */
    if(H5Tclose(type) < 0) TEST_ERROR
    if(H5Tclose(reopened_type) < 0) TEST_ERROR
    if(H5Dclose(dset) < 0) TEST_ERROR

    /*
     * Enum
     */

    /* Create enum type */
    if((type = H5Tenum_create(H5T_NATIVE_INT)) < 0) TEST_ERROR
    enum_value = 0;
    if(H5Tenum_insert(type, "val1", &enum_value) < 0) TEST_ERROR
    enum_value = 1;
    if(H5Tenum_insert(type, "val2", &enum_value) < 0) TEST_ERROR

    /* Get size of enum type */
    if((dt_size = H5Tget_size(type)) == 0) TEST_ERROR

    /* Commit enum type and verify the size doesn't change */
    if(H5Tcommit2(file, "enum_type", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(type)) TEST_ERROR

    /* Create dataset with enum type */
    if((dset = H5Dcreate2(file, "enum_dset", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Indirectly reopen type and verify that the size doesn't change */
    if((reopened_type = H5Dget_type(dset)) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(reopened_type)) TEST_ERROR

    /* Close types and dataset */
    if(H5Tclose(type) < 0) TEST_ERROR
    if(H5Tclose(reopened_type) < 0) TEST_ERROR
    if(H5Dclose(dset) < 0) TEST_ERROR

    /*
     * Vlen
     */

    /* Create vlen type */
    if((type = H5Tvlen_create(H5T_NATIVE_INT)) < 0) TEST_ERROR

    /* Get size of vlen type */
    if((dt_size = H5Tget_size(type)) == 0) TEST_ERROR

    /* Commit vlen type and verify the size doesn't change */
    if(H5Tcommit2(file, "vlen_type", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(type)) TEST_ERROR

    /* Create dataset with vlen type */
    if((dset = H5Dcreate2(file, "vlen_dset", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Indirectly reopen type and verify that the size doesn't change */
    if((reopened_type = H5Dget_type(dset)) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(reopened_type)) TEST_ERROR

    /* Close types and dataset */
    if(H5Tclose(type) < 0) TEST_ERROR
    if(H5Tclose(reopened_type) < 0) TEST_ERROR
    if(H5Dclose(dset) < 0) TEST_ERROR

    /*
     * Opaque
     */

    /* Create opaque type */
    if((type = H5Tcreate(H5T_OPAQUE, (size_t)13)) < 0) TEST_ERROR
    if(H5Tset_tag(type, tag) < 0) TEST_ERROR

    /* Get size of opaque type */
    if((dt_size = H5Tget_size(type)) == 0) TEST_ERROR

    /* Commit opaque type and verify the size and tag don't change */
    if(H5Tcommit2(file, "opaque_type", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(type)) TEST_ERROR
    if(NULL == (tag_ret = H5Tget_tag(type))) TEST_ERROR
    if(HDstrcmp(tag, tag_ret)) TEST_ERROR
    HDfree(tag_ret);
    tag_ret = NULL;

    /* Create dataset with opaque type */
    if((dset = H5Dcreate2(file, "opaque_dset", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Indirectly reopen type and verify that the size and tag don't change */
    if((reopened_type = H5Dget_type(dset)) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(reopened_type)) TEST_ERROR
    if(NULL == (tag_ret = H5Tget_tag(type))) TEST_ERROR
    if(HDstrcmp(tag, tag_ret)) TEST_ERROR
    HDfree(tag_ret);
    tag_ret = NULL;

    /* Close types and dataset */
    if(H5Tclose(type) < 0) TEST_ERROR
    if(H5Tclose(reopened_type) < 0) TEST_ERROR
    if(H5Dclose(dset) < 0) TEST_ERROR

    /*
     * Array
     */

    /* Create array type */
    if((type = H5Tarray_create2(H5T_NATIVE_INT, 1, dims)) < 0) TEST_ERROR

    /* Get size of array type */
    if((dt_size = H5Tget_size(type)) == 0) TEST_ERROR

    /* Commit array type and verify the size doesn't change */
    if(H5Tcommit2(file, "array_type", type, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(type)) TEST_ERROR

    /* Create dataset with array type */
    if((dset = H5Dcreate2(file, "array_dset", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR

    /* Indirectly reopen type and verify that the size doesn't change */
    if((reopened_type = H5Dget_type(dset)) < 0) TEST_ERROR
    if(dt_size != H5Tget_size(reopened_type)) TEST_ERROR

    /* Close types and dataset */
    if(H5Tclose(type) < 0) TEST_ERROR
    if(H5Tclose(reopened_type) < 0) TEST_ERROR
    if(H5Dclose(dset) < 0) TEST_ERROR

    /* Close file and dataspace */
    if(H5Sclose(space) < 0) TEST_ERROR
    if(H5Fclose(file) < 0) TEST_ERROR
    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
	H5Tclose(type);
	H5Tclose(strtype);
	H5Tclose(reopened_type);
	H5Sclose(space);
	H5Dclose(dset);
	H5Fclose(file);
    } H5E_END_TRY;
    if(tag_ret)
        HDfree(tag_ret);
    return 1;
} /* end test_named_indirect_reopen() */


/*-------------------------------------------------------------------------
 * Function:	test_deprec
 *
 * Purpose:	Tests deprecated API routines for datatypes.
 *
 * Return:	Success:	0
 *		Failure:	number of errors
 *
 * Programmer:	Quincey Koziol
 *              Thursday, September 27, 2007
 *
 *-------------------------------------------------------------------------
 */
#ifndef H5_NO_DEPRECATED_SYMBOLS
static int
test_deprec(hid_t fapl)
{
    hid_t		file = -1;              /* File ID */
    hid_t		type = -1;              /* Datatype ID */
    unsigned            rank = 2;               /* Rank for array datatype */
    hsize_t             dims[2] = {3, 3};       /* Dimensions for array datatype */
    int                 perm[2] = {0, 1};       /* Dimensions permutations for array datatype */
    hsize_t             rdims[2]= {0, 0};       /* Dimensions for querying array datatype */
    int                 rperm[2] = {-2, -2};    /* Dimensions permutations for array datatype */
    hbool_t             dim_mismatch;           /* Whether any dimensions didn't match */
    char		filename[1024];
    unsigned            u;                      /* Local index variable */
    herr_t		status;                 /* Generic routine value */

    TESTING("deprected API routines for datatypes");

    /* Create an array datatype with an atomic base type */
    /* (dimension permutations allowed, but not stored) */
    if((type = H5Tarray_create1(H5T_NATIVE_INT, (int)rank, dims, perm)) < 0)
        FAIL_STACK_ERROR

    /* Make certain that the correct classes can be detected */
    if(H5Tdetect_class(type, H5T_ARRAY) != TRUE)
        FAIL_STACK_ERROR
    if(H5Tdetect_class(type, H5T_INTEGER) != TRUE)
        FAIL_STACK_ERROR

    /* Get the array dimensions */
    /* (Query the dimension permutations, which is allowed, but ignored) */
    if(H5Tget_array_dims1(type, rdims, rperm) < 0)
        FAIL_STACK_ERROR

    /* Check the array dimensions */
    dim_mismatch = FALSE;
    for(u = 0; u < rank; u++)
        if(rdims[u] != dims[u]) {
            TestErrPrintf("Array dimension information doesn't match!, rdims1[%u]=%d, tdims1[%u]=%d\n", u, (int)rdims[u], u, (int)dims[u]);
            dim_mismatch = TRUE;
        } /* end if */
    if(dim_mismatch)
	FAIL_PUTS_ERROR("    Dimensions didn't match!")

    /* Check the array dimension permutations */
    dim_mismatch = FALSE;
    for(u = 0; u < rank; u++)
        if(rperm[u] != -2) {
            TestErrPrintf("Array dimension permutation information was modified!, rdims1[%u]=%d, tdims1[%u]=%d\n", u, rperm[u], u, perm[u]);
            dim_mismatch = TRUE;
        } /* end if */
    if(dim_mismatch)
	FAIL_PUTS_ERROR("    Dimension permutations modified!")

    /* Close the datatype */
    if(H5Tclose(type) < 0)
        FAIL_STACK_ERROR


    h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        FAIL_STACK_ERROR

    /* Predefined types cannot be committed */
    H5E_BEGIN_TRY {
	status = H5Tcommit1(file, "test_named_1 (should not exist)", H5T_NATIVE_INT);
    } H5E_END_TRY;
    if(status >= 0)
	FAIL_PUTS_ERROR("    Predefined types should not be committable!")

    /* Copy a predefined datatype and commit the copy */
    if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) FAIL_STACK_ERROR
    if(H5Tcommit1(file, "native-int", type) < 0) FAIL_STACK_ERROR
    if((status = H5Tcommitted(type)) < 0) FAIL_STACK_ERROR
    if(0 == status)
	FAIL_PUTS_ERROR("    H5Tcommitted() returned false!")

    /* We should not be able to modify a type after it has been committed. */
    H5E_BEGIN_TRY {
	status = H5Tset_precision(type, (size_t)256);
    } H5E_END_TRY;
    if(status >= 0)
	FAIL_PUTS_ERROR("    Committed type is not constant!")

    /* We should not be able to re-commit a committed type */
    H5E_BEGIN_TRY {
	status = H5Tcommit1(file, "test_named_2 (should not exist)", type);
    } H5E_END_TRY;
    if(status >= 0)
	FAIL_PUTS_ERROR("    Committed types should not be recommitted!")

    /*
     * Close the committed type and reopen it.  It should return a named type.
     */
    if(H5Tclose(type) < 0) FAIL_STACK_ERROR
    if((type = H5Topen1(file, "native-int")) < 0) FAIL_STACK_ERROR
    if((status = H5Tcommitted(type)) < 0) FAIL_STACK_ERROR
    if(!status)
	FAIL_PUTS_ERROR("    Opened named types should be named types!")

    /* Close */
    if(H5Tclose(type) < 0) FAIL_STACK_ERROR
    if(H5Fclose(file) < 0) FAIL_STACK_ERROR

    /* Reopen file with read only access */
    if ((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
        goto error;

    /* Verify that H5Tcommit2 returns an error */
    if((type = H5Tcopy(H5T_NATIVE_INT)) < 0) goto error;
    H5E_BEGIN_TRY {
        status = H5Tcommit1(file, "test_named_3 (should not exist)", type);
    } H5E_END_TRY;
    if(status >= 0) {
        H5_FAILED();
        HDputs ("    Types should not be committable to a read-only file!");
        goto error;
    }

    /* Close */
    if(H5Tclose(type) < 0) goto error;
    if(H5Fclose(file) < 0) goto error;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
	H5Tclose(type);
	H5Fclose(file);
    } H5E_END_TRY;
    return 1;
} /* end test_deprec() */
#endif /* H5_NO_DEPRECATED_SYMBOLS */


/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     Test the datatype interface.
 *
 * Return:      Success:
 *
 *              Failure:
 *
 * Programmer:  Robb Matzke
 *              Tuesday, December  9, 1997
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    unsigned long	nerrors = 0;
    hid_t		fapl = -1;

    /* Set the random # seed */
    HDsrandom((unsigned)HDtime(NULL));

    reset_hdf5();
    fapl = h5_fileaccess();

    if(ALIGNMENT)
	printf("Testing non-aligned conversions (ALIGNMENT=%d)....\n", ALIGNMENT);

    /* Do the tests */
    nerrors += test_classes();
    nerrors += test_copy();
    nerrors += test_detect();
    nerrors += test_compound_1();
    nerrors += test_query();

    nerrors += test_transient(fapl);
    nerrors += test_named(fapl);
    nerrors += test_encode();
    nerrors += test_latest();
    nerrors += test_int_float_except();
    nerrors += test_named_indirect_reopen(fapl);
#ifndef H5_NO_DEPRECATED_SYMBOLS
    nerrors += test_deprec(fapl);
#endif /* H5_NO_DEPRECATED_SYMBOLS */
    h5_cleanup(FILENAME, fapl); /*must happen before first reset*/
    reset_hdf5();

    nerrors += test_conv_str_1();
    nerrors += test_conv_str_2();
    nerrors += test_conv_str_3();
    nerrors += test_compound_2();
    nerrors += test_compound_3();
    nerrors += test_compound_4();
    nerrors += test_compound_5();
    nerrors += test_compound_6();
    nerrors += test_compound_7();
    nerrors += test_compound_8();
    nerrors += test_compound_9();
    nerrors += test_compound_10();
    nerrors += test_compound_11();
    nerrors += test_compound_12();
    nerrors += test_compound_13();
    nerrors += test_compound_14();
    nerrors += test_compound_15();
    nerrors += test_compound_16();
    nerrors += test_compound_17();
    nerrors += test_conv_enum_1();
    nerrors += test_conv_enum_2();
    nerrors += test_conv_bitfield();
    nerrors += test_bitfield_funcs();
    nerrors += test_opaque();
    nerrors += test_set_order();

    if(nerrors) {
        printf("***** %lu FAILURE%s! *****\n",
               nerrors, 1==nerrors?"":"S");
        HDexit(1);
    }

    printf("All datatype tests passed.\n");

    return 0;
}