File: test_udf.py

package info (click to toggle)
python-pycdlib 1.12.0%2Bds1-4%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,044 kB
  • sloc: python: 35,639; makefile: 63
file content (2543 lines) | stat: -rw-r--r-- 127,642 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
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
from __future__ import absolute_import

import pytest
import os
import sys
try:
    from cStringIO import StringIO as BytesIO
except ImportError:
    from io import BytesIO
import struct

prefix = '.'
for i in range(0, 3):
    if os.path.isdir(os.path.join(prefix, 'pycdlib')):
        sys.path.insert(0, prefix)
        break
    else:
        prefix = '../' + prefix

import pycdlib.udf

# BEA
def test_bea_parse_initialized_twice():
    bea = pycdlib.udf.BEAVolumeStructure()
    bea.parse(b'\x00BEA01\x01' + b'\x00'*2041, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bea.parse(b'\x00BEA01\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'BEA Volume Structure already initialized')

def test_bea_parse_bad_structure():
    bea = pycdlib.udf.BEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        bea.parse(b'\x01BEA01\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid structure type')

def test_bea_parse_bad_ident():
    bea = pycdlib.udf.BEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        bea.parse(b'\x00CEA01\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid standard identifier')

def test_bea_parse_bad_version():
    bea = pycdlib.udf.BEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        bea.parse(b'\x00BEA01\x02' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid structure version')

def test_bea_record_not_initialized():
    bea = pycdlib.udf.BEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bea.record()
    assert(str(excinfo.value) == 'BEA Volume Structure not initialized')

def test_bea_new_initialized_twice():
    bea = pycdlib.udf.BEAVolumeStructure()
    bea.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bea.new()
    assert(str(excinfo.value) == 'BEA Volume Structure already initialized')

def test_bea_extent_location_not_initialized():
    bea = pycdlib.udf.BEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bea.extent_location()
    assert(str(excinfo.value) == 'UDF BEA Volume Structure not initialized')

def test_bea_set_extent_location_not_initialized():
    bea = pycdlib.udf.BEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bea.set_extent_location(0)
    assert(str(excinfo.value) == 'This Volume Descriptor is not initialized')

# NSR
def test_nsr_parse_initialized_twice():
    nsr = pycdlib.udf.NSRVolumeStructure()
    nsr.parse(b'\x00NSR02\x01' + b'\x00'*2041, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        nsr.parse(b'\x00NSR02\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'UDF NSR Volume Structure already initialized')

def test_nsr_parse_bad_structure():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        nsr.parse(b'\x01NSR02\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid structure type')

def test_nsr_parse_bad_ident():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        nsr.parse(b'\x00NSR04\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid standard identifier')

def test_nsr_parse_bad_version():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        nsr.parse(b'\x00NSR02\x02' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid structure version')

def test_nsr_record_not_initialized():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        nsr.record()
    assert(str(excinfo.value) == 'UDF NSR Volume Structure not initialized')

def test_nsr_new_initialized_twice():
    nsr = pycdlib.udf.NSRVolumeStructure()
    nsr.new(2)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        nsr.new(2)
    assert(str(excinfo.value) == 'UDF NSR Volume Structure already initialized')

def test_nsr_new_version_three():
    nsr = pycdlib.udf.NSRVolumeStructure()
    nsr.new(3)
    assert(nsr.standard_ident == b'NSR03')

def test_nsr_new_bad_version():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        nsr.new(4)
    assert(str(excinfo.value) == 'Invalid NSR version requested')

def test_nsr_extent_location_not_initialized():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        nsr.extent_location()
    assert(str(excinfo.value) == 'UDF NSR Volume Structure not initialized')

def test_nsr_set_extent_location_not_initialized():
    nsr = pycdlib.udf.NSRVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        nsr.set_extent_location(0)
    assert(str(excinfo.value) == 'This Volume Descriptor is not initialized')

# TEA
def test_tea_parse_initialized_twice():
    tea = pycdlib.udf.TEAVolumeStructure()
    tea.parse(b'\x00TEA01\x01' + b'\x00'*2041, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tea.parse(b'\x00TEA01\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'TEA Volume Structure already initialized')

def test_tea_parse_bad_type():
    tea = pycdlib.udf.TEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        tea.parse(b'\x01TEA01\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid structure type')

def test_tea_parse_bad_ident():
    tea = pycdlib.udf.TEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        tea.parse(b'\x00TEA02\x01' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid standard identifier')

def test_tea_parse_bad_version():
    tea = pycdlib.udf.TEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        tea.parse(b'\x00TEA01\x02' + b'\x00'*2041, 0)
    assert(str(excinfo.value) == 'Invalid structure version')

def test_tea_record_not_initialized():
    tea = pycdlib.udf.TEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tea.record()
    assert(str(excinfo.value) == 'UDF TEA Volume Structure not initialized')

def test_tea_new_initialized_twice():
    tea = pycdlib.udf.TEAVolumeStructure()
    tea.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tea.new()
    assert(str(excinfo.value) == 'UDF TEA Volume Structure already initialized')

def test_tea_extent_location_not_initialized():
    tea = pycdlib.udf.TEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tea.extent_location()
    assert(str(excinfo.value) == 'UDF TEA Volume Structure not initialized')

def test_tea_set_extent_location_not_initialized():
    tea = pycdlib.udf.TEAVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tea.set_extent_location(0)
    assert(str(excinfo.value) == 'This Volume Descriptor is not initialized')

# Boot Descriptor
def test_boot_descriptor_parse():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.parse(b'\x00BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(boot.boot_extent_loc == 0)
    assert(boot.boot_extent_len == 0)
    assert(boot.load_address == 0)
    assert(boot.start_address == 0)
    assert(boot.flags == 0)

def test_boot_descriptor_parse_initialized_twice():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.parse(b'\x00BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        boot.parse(b'\x00BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'UDF Boot Descriptor already initialized')

def test_boot_descriptor_parse_bad_type():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        boot.parse(b'\x01BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'Invalid structure type')

def test_boot_descriptor_parse_bad_ident():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        boot.parse(b'\x00BOOT1\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'Invalid standard identifier')

def test_boot_descriptor_parse_bad_version():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        boot.parse(b'\x00BOOT2\x02\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'Invalid structure version')

def test_boot_descriptor_parse_bad_reserved():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        boot.parse(b'\x00BOOT2\x01\x01' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'Invalid reserved1')

def test_boot_descriptor_parse_bad_flags():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        boot.parse(b'\x00BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x02\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'Invalid flags (must be 0 or 1)')

def test_boot_descriptor_parse_bad_reserved2():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        boot.parse(b'\x00BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x01'*32 + b'\x00'*1906, 0)
    assert(str(excinfo.value) == 'Invalid reserved2')

def test_boot_descriptor_new():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.new()
    assert(boot.flags == 0)
    assert(boot.boot_extent_loc == 0)
    assert(boot.boot_extent_len == 0)
    assert(boot.load_address == 0)
    assert(boot.start_address == 0)
    assert(boot.flags == 0)
    assert(boot._initialized)

def test_boot_descriptor_new_initialized_twice():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        boot.new()
    assert(str(excinfo.value) == 'UDF Boot Descriptor already initialized')

def test_boot_descriptor_record_not_initialized():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        boot.record()
    assert(str(excinfo.value) == 'UDF Boot Descriptor not initialized')

def test_boot_descriptor_record():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.new()
    rec = boot.record()
    assert(rec[0:8] == b'\x00BOOT2\x01\x00')

def test_boot_descriptor_extent_location_not_initialized():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        boot.extent_location()
    assert(str(excinfo.value) == 'UDF Boot Descriptor not initialized')

def test_boot_descriptor_extent_location():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.parse(b'\x00BOOT2\x01\x00' + b'\x00'*32 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00' + b'\x00'*32 + b'\x00'*1906, 0)
    assert(boot.extent_location() == 0)

def test_boot_descriptor_set_extent_location_not_initialized():
    boot = pycdlib.udf.UDFBootDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        boot.set_extent_location(0)
    assert(str(excinfo.value) == 'This UDF Boot Descriptor is not initialized')

def test_boot_descriptor_set_extent_location():
    boot = pycdlib.udf.UDFBootDescriptor()
    boot.new()
    boot.set_extent_location(1)
    assert(boot.extent_location() == 1)

# UDFTag
def test_tag_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.parse(b'\x00\x00\x02\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tag.parse(b'\x00\x00\x02\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0)
    assert(str(excinfo.value) == 'UDF Tag already initialized')

def test_tag_parse_bad_csum():
    tag = pycdlib.udf.UDFTag()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        tag.parse(b'\x00\x00\x02\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0)
    assert(str(excinfo.value) == 'Tag checksum does not match!')

def test_tag_parse_not_enough_crc_data():
    tag = pycdlib.udf.UDFTag()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tag.parse(b'\x00\x00\x02\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00', 0)
    assert(str(excinfo.value) == 'Not enough bytes to compute CRC')

def test_tag_parse_bad_crc():
    tag = pycdlib.udf.UDFTag()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        tag.parse(b'\x00\x00\x02\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\xee', 0)
    assert(str(excinfo.value) == 'Tag CRC does not match!')

def test_tag_parse():
    tag = pycdlib.udf.UDFTag()
    tag.parse(b'\x00\x00\x02\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00', 0)
    assert(tag.tag_ident == 0)
    assert(tag.desc_version == 2)
    assert(tag.tag_serial_number == 0)
    assert(tag.desc_crc_length == 1)
    assert(tag.tag_location == 0)
    assert(tag._initialized)

def test_tag_record_not_initialized():
    tag = pycdlib.udf.UDFTag()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tag.record(b'\x00')
    assert(str(excinfo.value) == 'UDF Descriptor Tag not initialized')

def test_tag_new_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        tag.new(0, 0)
    assert(str(excinfo.value) == 'UDF Tag already initialized')

def test_tag_eq():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    tag2 = pycdlib.udf.UDFTag()
    tag2.new(0, 0)

    assert(tag == tag2)

# Anchor
def test_anchor_parse_initialized_twice():
    anchor = pycdlib.udf.UDFAnchorVolumeStructure()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    anchor.parse(b'\x00'*16 + b'\x00'*8 + b'\x00'*8 + b'\x00'*480, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        anchor.parse(b'\x00'*16 + b'\x00'*8 + b'\x00'*8 + b'\x00'*480, 0, tag)
    assert(str(excinfo.value) == 'Anchor Volume Structure already initialized')

def test_anchor_record_not_initialized():
    anchor = pycdlib.udf.UDFAnchorVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        anchor.record()
    assert(str(excinfo.value) == 'UDF Anchor Volume Descriptor not initialized')

def test_anchor_extent_location_not_initialized():
    anchor = pycdlib.udf.UDFAnchorVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        anchor.extent_location()
    assert(str(excinfo.value) == 'UDF Anchor Volume Structure not initialized')

def test_anchor_new_initialized_twice():
    anchor = pycdlib.udf.UDFAnchorVolumeStructure()
    anchor.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        anchor.new()
    assert(str(excinfo.value) == 'UDF Anchor Volume Structure already initialized')

def test_anchor_set_extent_location_not_initialized():
    anchor = pycdlib.udf.UDFAnchorVolumeStructure()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        anchor.set_extent_location(0, 0, 0)
    assert(str(excinfo.value) == 'UDF Anchor Volume Structure not initialized')

# Volume Descriptor Pointer
def test_vdp_parse_initialized_twice():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    vdp.parse(b'\x00'*16 + b'\x00\x00\x00x\00' + b'\x00'*8 + b'\x00'*484, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        vdp.parse(b'\x00'*16 + b'\x00\x00\x00x\00' + b'\x00'*8 + b'\x00'*484, 0, b'\x00'*16)
    assert(str(excinfo.value) == 'UDF Volume Descriptor Pointer already initialized')

def test_vdp_parse():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    vdp.parse(b'\x00'*16 + b'\x00\x00\x00x\00' + b'\x00'*8 + b'\x00'*484, 0, tag)
    assert(vdp.orig_extent_loc == 0)
    assert(vdp.initialized)

def test_vdp_record_not_initialized():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        vdp.record()
    assert(str(excinfo.value) == 'UDF Volume Descriptor Pointer not initialized')

def test_vdp_record():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    vdp.parse(b'\x00'*16 + b'\x00\x00\x00x\00' + b'\x00'*8 + b'\x00'*484, 0, tag)
    assert(vdp.record() == (b'\x00\x00\x02\x00\x22\x00\x00\x00\x9c\x93\xf0\x01\x00\x00\x00\x00\x00\x00\x00\x78' + b'\x00'*492))

def test_vdp_extent_location_not_initialized():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        vdp.extent_location()
    assert(str(excinfo.value) == 'UDF Volume Descriptor Pointer not initialized')

def test_vdp_extent_location_parse():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    vdp.parse(b'\x00'*16 + b'\x00\x00\x00x\00' + b'\x00'*8 + b'\x00'*484, 0, tag)
    assert(vdp.extent_location() == 0)

def test_vdp_extent_location_new():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    vdp.new()
    assert(vdp.extent_location() == 0)

def test_vdp_new_initialized_twice():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    vdp.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        vdp.new()
    assert(str(excinfo.value) == 'UDF Volume Descriptor Pointer already initialized')

def test_vdp_new():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    vdp.new()
    assert(vdp.vol_seqnum == 0)
    assert(vdp.initialized)

def test_vdp_set_extent_location_not_initialized():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        vdp.set_extent_location(1)
    assert(str(excinfo.value) == 'UDF Volume Descriptor Pointer not initialized')

def test_vdp_set_extent_location():
    vdp = pycdlib.udf.UDFVolumeDescriptorPointer()
    vdp.new()
    vdp.set_extent_location(1)
    assert(vdp.new_extent_loc == 1)

# Timestamp
def test_timestamp_parse_initialized_twice():
    ts = pycdlib.udf.UDFTimestamp()
    ts.parse(b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ts.parse(b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Timestamp already initialized')

def test_timestamp_parse_bad_tz():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x06\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF timezone')

def test_timestamp_parse_bad_year():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF year')

def test_timestamp_parse_bad_month():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF month')

def test_timestamp_parse_bad_day():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF day')

def test_timestamp_parse_bad_hour():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x00\x01\x00\x01\x01\x20\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF hour')

def test_timestamp_parse_bad_minute():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x00\x01\x00\x01\x01\x00\x40\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF minute')

def test_timestamp_parse_bad_second():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        ts.parse(b'\x00\x00\x01\x00\x01\x01\x00\x00\x40\x00\x00\x00')
    assert(str(excinfo.value) == 'Invalid UDF second')

def test_timestamp_record_not_initialized():
    ts = pycdlib.udf.UDFTimestamp()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ts.record()
    assert(str(excinfo.value) == 'UDF Timestamp not initialized')

def test_timestamp_new_initialized_twice():
    ts = pycdlib.udf.UDFTimestamp()
    ts.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ts.new()
    assert(str(excinfo.value) == 'UDF Timestamp already initialized')

def test_timestamp_equal():
    ts = pycdlib.udf.UDFTimestamp()
    ts.new()

    ts2 = pycdlib.udf.UDFTimestamp()
    ts2.new()

    assert(ts == ts2)

# EntityID
def test_entityid_parse_initialized_twice():
    entity = pycdlib.udf.UDFEntityID()
    entity.parse(b'\x00'*32)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entity.parse(b'\x00'*32)
    assert(str(excinfo.value) == 'UDF Entity ID already initialized')

def test_entityid_parse_bad_flags():
    entity = pycdlib.udf.UDFEntityID()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        entity.parse(b'\x04' + b'\x00'*31)
    assert(str(excinfo.value) == 'UDF Entity ID flags must be between 0 and 3')

def test_entityid_record_not_initialized():
    entity = pycdlib.udf.UDFEntityID()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entity.record()
    assert(str(excinfo.value) == 'UDF Entity ID not initialized')

def test_entityid_new_initialized_twice():
    entity = pycdlib.udf.UDFEntityID()
    entity.new(0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entity.new(0)
    assert(str(excinfo.value) == 'UDF Entity ID already initialized')

def test_entityid_new_bad_flags():
    entity = pycdlib.udf.UDFEntityID()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        entity.new(4)
    assert(str(excinfo.value) == 'UDF Entity ID flags must be between 0 and 3')

def test_entityid_new_bad_identifier():
    entity = pycdlib.udf.UDFEntityID()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        entity.new(0, b'\x00'*25)
    assert(str(excinfo.value) == 'UDF Entity ID identifier must be less than 23 characters')

def test_entityid_new_bad_suffix():
    entity = pycdlib.udf.UDFEntityID()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        entity.new(0, b'', b'\x00'*10)
    assert(str(excinfo.value) == 'UDF Entity ID suffix must be less than 8 characters')

def test_entityid_equals():
    entity = pycdlib.udf.UDFEntityID()
    entity.new(0)

    entity2 = pycdlib.udf.UDFEntityID()
    entity2.new(0)

    assert(entity == entity2)

# Charspec
def test_charspec_parse_initialized_twice():
    charspec = pycdlib.udf.UDFCharspec()
    charspec.parse(b'\x00'*64)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        charspec.parse(b'\x00'*64)
    assert(str(excinfo.value) == 'UDF Charspec already initialized')

def test_charspec_parse_bad_set_type():
    charspec = pycdlib.udf.UDFCharspec()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        charspec.parse(b'\x09' + b'\x00'*63)
    assert(str(excinfo.value) == 'Invalid charset parsed; only 0-8 supported')

def test_charspec_new_initialized_twice():
    charspec = pycdlib.udf.UDFCharspec()
    charspec.new(0, b'')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        charspec.new(0, b'')
    assert(str(excinfo.value) == 'UDF Charspec already initialized')

def test_charspec_new_bad_set_type():
    charspec = pycdlib.udf.UDFCharspec()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        charspec.new(9, b'')
    assert(str(excinfo.value) == 'Invalid charset specified; only 0-8 supported')

def test_charspec_new_bad_set_information():
    charspec = pycdlib.udf.UDFCharspec()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        charspec.new(0, b'\x00'*64)
    assert(str(excinfo.value) == 'Invalid charset information; exceeds maximum size of 63')

def test_charspec_record_not_initialized():
    charspec = pycdlib.udf.UDFCharspec()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        charspec.record()
    assert(str(excinfo.value) == 'UDF Charspec not initialized')

def test_charspec_equal():
    charspec = pycdlib.udf.UDFCharspec()
    charspec.new(0, b'\x00'*63)

    charspec2 = pycdlib.udf.UDFCharspec()
    charspec2.new(0, b'\x00'*63)

    assert(charspec == charspec2)

# ExtentAD
def test_extentad_parse_initialized_twice():
    extentad = pycdlib.udf.UDFExtentAD()
    extentad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        extentad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Extent descriptor already initialized')

def test_extentad_parse_bad_length():
    extentad = pycdlib.udf.UDFExtentAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        extentad.parse(b'\x00\x00\x00\xff\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Extent descriptor length must be less than 0x3fffffff')

def test_extentad_record_not_initialized():
    extentad = pycdlib.udf.UDFExtentAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        extentad.record()
    assert(str(excinfo.value) == 'UDF Extent AD not initialized')

def test_extentad_new_initialized_twice():
    extentad = pycdlib.udf.UDFExtentAD()
    extentad.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        extentad.new(0, 0)
    assert(str(excinfo.value) == 'UDF Extent AD already initialized')

def test_extentad_new_bad_length():
    extentad = pycdlib.udf.UDFExtentAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        extentad.new(0xff000000, 0)
    assert(str(excinfo.value) == 'UDF Extent AD length must be less than 0x3fffffff')

def test_extentad_equals():
    extentad = pycdlib.udf.UDFExtentAD()
    extentad.new(0, 0)

    extentad2 = pycdlib.udf.UDFExtentAD()
    extentad2.new(0, 0)

    assert(extentad == extentad2)

# PVD
def test_pvd_parse_initialized_twice():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'UDF Primary Volume Descriptor already initialized')

def test_pvd_parse_bad_volseqnum():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00\x00\x01\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_pvd_parse_bad_maxvolseqnum():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_pvd_parse_bad_interchangelevel():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'Unsupported interchange level (only 2 and 3 supported)')

def test_pvd_parse_bad_charsetlist():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_pvd_parse_bad_maxcharsetlist():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x02\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_pvd_parse_bad_flags():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x02\x00' + b'\x00'*22, 0, tag)
    assert(str(excinfo.value) == 'Invalid UDF flags')

def test_pvd_parse_bad_reserved():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        pvd.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x01\x00\x01\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*128 + b'\x00'*64 + b'\x00'*64 + b'\x00'*8 + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*64 + b'\x00\x00\x00\x00\x00\x00' + b'\x01' + b'\x00'*21, 0, tag)
    assert(str(excinfo.value) == 'UDF Primary Volume Descriptor reserved data not 0')

def test_pvd_record_not_initialized():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        pvd.record()
    assert(str(excinfo.value) == 'UDF Primary Volume Descriptor not initialized')

def test_pvd_extent_location_not_initialized():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        pvd.extent_location()
    assert(str(excinfo.value) == 'UDF Primary Volume Descriptor not initialized')

def test_pvd_new_initialized_twice():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    pvd.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        pvd.new()
    assert(str(excinfo.value) == 'UDF Primary Volume Descriptor already initialized')

def test_pvd_set_extent_location_not_initialized():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        pvd.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Primary Volume Descriptor not initialized')

def test_pvd_equals():
    pvd = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    pvd.new()

    pvd2 = pycdlib.udf.UDFPrimaryVolumeDescriptor()
    pvd2.new()
    pvd2.vol_set_ident = pvd.vol_set_ident
    pvd2.recording_date = pvd.recording_date

    assert(pvd == pvd2)

# Implementation Use Volume Descriptor Implementation Use
def test_impl_use_impl_use_parse_initialized_twice():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
    impl.parse(b'\x00'*64 + b'\x00'*128 + b'\x00'*36 + b'\x00'*36 + b'\x00'*36 + b'\x00'*32 + b'\x00'*128)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.parse(b'\x00'*64 + b'\x00'*128 + b'\x00'*36 + b'\x00'*36 + b'\x00'*36 + b'\x00'*32 + b'\x00'*128)
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor Implementation Use field already initialized')

def test_impl_use_impl_use_record_not_initialized():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.record()
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor Implementation Use field not initialized')

def test_impl_use_impl_use_new_initialized_twice():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
    impl.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.new()
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor Implementation Use field already initialized')

def test_impl_use_impl_use_new_equals():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
    impl.new()

    impl2 = pycdlib.udf.UDFImplementationUseVolumeDescriptorImplementationUse()
    impl2.new()

    assert(impl == impl2)

# Implementation Use
def test_impl_use_parse_initialized_twice():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    impl.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00*UDF LV Info' + b'\x00'*19 + b'\x00'*460, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00*UDF LV Info' + b'\x00'*19 + b'\x00'*460, 0, tag)
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor already initialized')

def test_impl_use_parse_bad_ident():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        impl.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00*MDF LV Info' + b'\x00'*19 + b'\x00'*460, 0, tag)
    assert(str(excinfo.value) == "Implementation Use Identifier not '*UDF LV Info'")

def test_impl_use_record_not_initialized():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.record()
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor not initialized')

def test_impl_use_extent_location_not_initialized():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.extent_location()
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor not initialized')

def test_impl_use_new_initialized_twice():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    impl.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.new()
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor already initialized')

def test_impl_use_set_extent_location_not_initialized():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Implementation Use Volume Descriptor not initialized')

def test_impl_use_equals():
    impl = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    impl.new()

    impl2 = pycdlib.udf.UDFImplementationUseVolumeDescriptor()
    impl2.new()

    assert(impl == impl2)

# Partition Header Descriptor
def test_part_header_parse_initialized_twice():
    header = pycdlib.udf.UDFPartitionHeaderDescriptor()
    header.parse(b'\x00'*8 + b'\x00'*8 + b'\x00'*8 + b'\x00'*8 + b'\x00'*8 + b'\x00'*88)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        header.parse(b'\x00'*8 + b'\x00'*8 + b'\x00'*8 + b'\x00'*8 + b'\x00'*8 + b'\x00'*88)
    assert(str(excinfo.value) == 'UDF Partition Header Descriptor already initialized')

def test_part_header_record_not_initialized():
    header = pycdlib.udf.UDFPartitionHeaderDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        header.record()
    assert(str(excinfo.value) == 'UDF Partition Header Descriptor not initialized')

def test_part_header_new_initialized_twice():
    header = pycdlib.udf.UDFPartitionHeaderDescriptor()
    header.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        header.new()
    assert(str(excinfo.value) == 'UDF Partition Header Descriptor already initialized')

def test_part_header_equals():
    header = pycdlib.udf.UDFPartitionHeaderDescriptor()
    header.new()

    header2 = pycdlib.udf.UDFPartitionHeaderDescriptor()
    header2.new()

    assert(header == header2)

# Partition Volume
def test_part_parse_initialized_twice():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00+NSR02' + b'\x00'*25 + b'\x00'*128 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*156, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00+NSR02' + b'\x00'*25 + b'\x00'*128 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*156, 0, tag)
    assert(str(excinfo.value) == 'UDF Partition Volume Descriptor already initialized')

def test_part_parse_bad_flags():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x02\x00\x00\x00' + b'\x00+NSR02' + b'\x00'*25 + b'\x00'*128 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*156, 0, tag)
    assert(str(excinfo.value) == 'Invalid partition flags')

def test_part_parse_bad_entity():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00+NSR04' + b'\x00'*25 + b'\x00'*128 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*156, 0, tag)
    assert(str(excinfo.value) == "Partition Contents Identifier not '+FDC01', '+CD001', '+CDW02', '+NSR02', or '+NSR03'")

def test_part_parse_bad_access_type():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00+NSR02' + b'\x00'*25 + b'\x00'*128 + b'\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*156, 0, tag)
    assert(str(excinfo.value) == 'Invalid UDF partition access type')

def test_part_record_not_initialized():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.record()
    assert(str(excinfo.value) == 'UDF Partition Volume Descriptor not initialized')

def test_part_extent_location_not_initialized():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.extent_location()
    assert(str(excinfo.value) == 'UDF Partition Volume Descriptor not initialized')

def test_part_new_initialized_twice():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    part.new(2)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.new(2)
    assert(str(excinfo.value) == 'UDF Partition Volume Descriptor already initialized')

def test_part_new_initialized_version3():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    part.new(3)
    assert(part.part_contents.identifier[:6] == b'+NSR03')

def test_part_new_bad_version():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.new(4)
    assert(str(excinfo.value) == 'Invalid NSR version requested')

def test_part_set_extent_location_not_initialized():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Partition Volume Descriptor not initialized')

def test_part_set_start_location_not_initialized():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.set_start_location(0)
    assert(str(excinfo.value) == 'UDF Partition Volume Descriptor not initialized')

def test_part_equals():
    part = pycdlib.udf.UDFPartitionVolumeDescriptor()
    part.new(3)

    part2 = pycdlib.udf.UDFPartitionVolumeDescriptor()
    part2.new(3)

    assert(part == part2)

# Type 0 Partition Map
def test_type_zero_part_map_parse_initialized_twice():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    partmap.parse(b'\x00\x02')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.parse(b'\x00\x02')
    assert(str(excinfo.value) == 'UDF Type 0 Partition Map already initialized')

def test_type_zero_part_map_parse_bad_map_type():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        partmap.parse(b'\x01\x00')
    assert(str(excinfo.value) == 'UDF Type 0 Partition Map type is not 0')

def test_type_zero_part_map_parse_bad_map_length():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        partmap.parse(b'\x00\x01')
    assert(str(excinfo.value) == 'UDF Type 0 Partition Map length does not equal data length')

def test_type_zero_part_map_parse():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    partmap.parse(b'\x00\x02')
    assert(partmap._initialized)

def test_type_zero_part_map_record_not_initialized():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.record()
    assert(str(excinfo.value) == 'UDF Type 0 Partition Map not initialized')

def test_type_zero_part_map_record():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    partmap.parse(b'\x00\x02')
    assert(partmap.record() == b'\x00\x02')

def test_type_zero_part_map_new_initialized_twice():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    partmap.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.new()
    assert(str(excinfo.value) == 'UDF Type 0 Partition Map already initialized')

def test_type_zero_part_map_new():
    partmap = pycdlib.udf.UDFType0PartitionMap()
    partmap.new()
    assert(partmap._initialized)

# Type 1 Partition Map
def test_type_one_part_map_parse_initialized_twice():
    partmap = pycdlib.udf.UDFType1PartitionMap()
    partmap.parse(b'\x01\x06\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.parse(b'\x01\x06\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Type 1 Partition Map already initialized')

def test_type_one_part_map_parse_bad_map_type():
    partmap = pycdlib.udf.UDFType1PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        partmap.parse(b'\x00\x06\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Type 1 Partition Map type is not 1')

def test_type_one_part_map_parse_bad_map_length():
    partmap = pycdlib.udf.UDFType1PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        partmap.parse(b'\x01\x05\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Type 1 Partition Map length is not 6')

def test_type_one_part_map_record_not_initialized():
    partmap = pycdlib.udf.UDFType1PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.record()
    assert(str(excinfo.value) == 'UDF Type 1 Partition Map not initialized')

def test_type_one_part_map_new_initialized_twice():
    partmap = pycdlib.udf.UDFType1PartitionMap()
    partmap.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.new()
    assert(str(excinfo.value) == 'UDF Type 1 Partition Map already initialized')

# Type 2 Partition Map
def test_type_two_part_map_parse_initialized_twice():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    partmap.parse(b'\x02\x40' + b'\x00'*62)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.parse(b'\x02\x40' + b'\x00'*62)
    assert(str(excinfo.value) == 'UDF Type 2 Partition Map already initialized')

def test_type_two_part_map_parse_bad_map_type():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        partmap.parse(b'\x00\x40' + b'\x00'*62)
    assert(str(excinfo.value) == 'UDF Type 2 Partition Map type is not 2')

def test_type_two_part_map_parse_bad_map_length():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        partmap.parse(b'\x02\x20' + b'\x00'*62)
    assert(str(excinfo.value) == 'UDF Type 2 Partition Map length is not 64')

def test_type_two_part_map_parse():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    partmap.parse(b'\x02\x40' + b'\x00'*62)
    assert(partmap._initialized)

def test_type_two_part_map_record_not_initialized():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.record()
    assert(str(excinfo.value) == 'UDF Type 2 Partition Map not initialized')

def test_type_two_part_map_record():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    partmap.parse(b'\x02\x40' + b'\x00'*62)
    assert(partmap.record() == (b'\x02\x40' + b'\x00'*62))

def test_type_two_part_map_new_initialized_twice():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    partmap.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        partmap.new()
    assert(str(excinfo.value) == 'UDF Type 2 Partition Map already initialized')

def test_type_two_part_map_new():
    partmap = pycdlib.udf.UDFType2PartitionMap()
    partmap.new()
    assert(partmap._initialized)

# Extended AD
def test_extendedad_parse_initialized_twice():
    ad = pycdlib.udf.UDFExtendedAD()
    ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*6 + b'\x00'*2)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*6 + b'\x00'*2)
    assert(str(excinfo.value) == 'UDF Extended Allocation descriptor already initialized')

def test_extendedad_parse():
    ad = pycdlib.udf.UDFExtendedAD()
    ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*6 + b'\x00'*2)
    assert(ad._initialized)
    assert(ad.extent_length == 0)

def test_extendedad_record_not_initialized():
    ad = pycdlib.udf.UDFExtendedAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.record()
    assert(str(excinfo.value) == 'UDF Extended Allocation Descriptor not initialized')

def test_extendedad_record():
    ad = pycdlib.udf.UDFExtendedAD()
    ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*6 + b'\x00'*2)
    rec = ad.record()
    assert(rec == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*6 + b'\x00'*2)

def test_extendedad_new_initialized_twice():
    ad = pycdlib.udf.UDFExtendedAD()
    ad.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.new()
    assert(str(excinfo.value) == 'UDF Extended Allocation Descriptor already initialized')

def test_extendedad_new():
    ad = pycdlib.udf.UDFExtendedAD()
    ad.new()
    assert(ad._initialized)
    assert(ad.extent_length == 0)

# Short AD
def test_shortad_parse_initialized_twice():
    ad = pycdlib.udf.UDFShortAD()
    ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Short Allocation descriptor already initialized')

def test_shortad_record_not_initialized():
    ad = pycdlib.udf.UDFShortAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.record()
    assert(str(excinfo.value) == 'UDF Short AD not initialized')

def test_shortad_new_initialized_twice():
    ad = pycdlib.udf.UDFShortAD()
    ad.new(0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.new(0)
    assert(str(excinfo.value) == 'UDF Short AD already initialized')

def test_shortad_new_bad_length():
    ad = pycdlib.udf.UDFShortAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.new(0x40000000)
    assert(str(excinfo.value) == 'UDF Short AD length must be less than or equal to 0x3fffffff')

def test_shortad_set_extent_location_not_initialized():
    ad = pycdlib.udf.UDFShortAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.set_extent_location(0, 0)
    assert(str(excinfo.value) == 'UDF Short AD not initialized')

def test_shortad_set_extent_location():
    ad = pycdlib.udf.UDFShortAD()
    ad.new(0)
    ad.set_extent_location(0, 1)
    assert(ad.log_block_num == 1)

# Long AD
def test_longad_parse_initialized_twice():
    ad = pycdlib.udf.UDFLongAD()
    ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.parse(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Long Allocation descriptor already initialized')

def test_longad_record_not_initialized():
    ad = pycdlib.udf.UDFLongAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.record()
    assert(str(excinfo.value) == 'UDF Long AD not initialized')

def test_longad_new_initialized_twice():
    ad = pycdlib.udf.UDFLongAD()
    ad.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.new(0, 0)
    assert(str(excinfo.value) == 'UDF Long AD already initialized')

def test_longad_set_extent_location_not_initialized():
    ad = pycdlib.udf.UDFLongAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.set_extent_location(0, 0)
    assert(str(excinfo.value) == 'UDF Long AD not initialized')

def test_longad_length():
    ad = pycdlib.udf.UDFLongAD()
    assert(ad.length() == 16)

def test_longad_equals():
    ad = pycdlib.udf.UDFLongAD()
    ad.new(0, 0)

    ad2 = pycdlib.udf.UDFLongAD()
    ad2.new(0, 0)

    assert(ad == ad2)

# Inline AD
def test_inlinead_parse_initialized_twice():
    ad = pycdlib.udf.UDFInlineAD()
    ad.parse(0, 0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.parse(0, 0, 0)
    assert(str(excinfo.value) == 'UDF Inline Allocation Descriptor already initialized')

def test_inlinead_record_not_initialized():
    ad = pycdlib.udf.UDFInlineAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.record()
    assert(str(excinfo.value) == 'UDF Inline AD not initialized')

def test_inlinead_record():
    ad = pycdlib.udf.UDFInlineAD()
    ad.parse(0, 0, 0)
    assert(ad.record() == b'')

def test_inlinead_new_initialized_twice():
    ad = pycdlib.udf.UDFInlineAD()
    ad.new(0, 0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.new(0, 0, 0)
    assert(str(excinfo.value) == 'UDF Inline AD already initialized')

def test_inlinead_set_extent_location_not_initialized():
    ad = pycdlib.udf.UDFInlineAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.set_extent_location(1, 1)
    assert(str(excinfo.value) == 'UDF Inline AD not initialized')

def test_inlinead_set_extent_location():
    ad = pycdlib.udf.UDFInlineAD()
    ad.new(0, 0, 0)
    ad.set_extent_location(1, 1)
    assert(ad.log_block_num == 1)

def test_inlinead_length_not_initialized():
    ad = pycdlib.udf.UDFInlineAD()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ad.length()
    assert(str(excinfo.value) == 'UDF Inline AD not initialized')

def test_inlinead_length():
    ad = pycdlib.udf.UDFInlineAD()
    ad.new(1, 0, 0)
    assert(ad.length() == 1)

# Logical Volume Descriptor
def test_logvoldesc_parse_initialized_twice():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00'*72, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00'*72, 0, tag)
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor already initialized')

def test_logvoldesc_parse_bad_logical_block_size():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x07\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00'*72, 0, tag)
    assert(str(excinfo.value) == 'Volume Descriptor block size is not 2048')

def test_logvoldesc_parse_bad_domain_ident():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00$OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00'*72, 0, tag)
    assert(str(excinfo.value) == "Volume Descriptor Identifier not '*OSTA UDF Compliant'")

def test_logvoldesc_parse_bad_map_table_length():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x10\x00\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00'*72, 0, tag)
    assert(str(excinfo.value) == 'Map table length greater than size of partition map data; ISO corrupt')

def test_logvoldesc_parse_bad_map_data():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00\x80' + b'\x00'*70, 0, tag)
    assert(str(excinfo.value) == 'Partition map goes beyond end of data, ISO corrupt')

def test_logvoldesc_parse_not_enough_map_data_left():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00\x20' + b'\x00'*70, 0, tag)
    assert(str(excinfo.value) == 'Partition map goes beyond map_table_length left, ISO corrupt')

def test_logvoldesc_parse_map_type_0():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x02\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x00\x02' + b'\x00'*70, 0, tag)
    assert(len(logvol.partition_maps) == 1)
    assert(isinstance(logvol.partition_maps[0], pycdlib.udf.UDFType0PartitionMap))

def test_logvoldesc_parse_map_type_2():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x42\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x02\x40' + b'\x00'*70, 0, tag)
    assert(len(logvol.partition_maps) == 1)
    assert(isinstance(logvol.partition_maps[0], pycdlib.udf.UDFType2PartitionMap))

def test_logvoldesc_parse_bad_map_type():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        logvol.parse(b'\x00'*16 + b'\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00\x08\x00\x00' + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x42\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*32 + b'\x00'*128 + b'\x00'*8 + b'\x03\x40' + b'\x00'*70, 0, tag)
    assert(str(excinfo.value) == 'Unsupported partition map type')

def test_logvoldesc_record_not_initialized():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.record()
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor not initialized')

def test_logvoldesc_extent_location_not_initialized():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.extent_location()
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor not initialized')

def test_logvoldesc_new_initialized_twice():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.new()
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor already initialized')

def test_logvoldesc_add_partition_map_not_initialized():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.add_partition_map(1)
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor not initialized')

def test_logvoldesc_add_partition_map_type_0():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol.new()
    logvol.add_partition_map(0)
    assert(len(logvol.partition_maps) == 1)

def test_logvoldesc_add_partition_map_type_2():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol.new()
    logvol.add_partition_map(2)
    assert(len(logvol.partition_maps) == 1)

def test_logvoldesc_add_partition_map_invalid_type():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.add_partition_map(3)
    assert(str(excinfo.value) == 'UDF Partition map type must be 0, 1, or 2')

def test_logvoldesc_add_partition_map_too_many_maps():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol.new()
    logvol.add_partition_map(2)
    logvol.add_partition_map(2)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.add_partition_map(2)
    assert(str(excinfo.value) == 'Too many UDF partition maps')

def test_logvoldesc_set_extent_location_not_initialized():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor not initialized')

def test_logvoldesc_set_integrity_location_not_initialized():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        logvol.set_integrity_location(0)
    assert(str(excinfo.value) == 'UDF Logical Volume Descriptor not initialized')

def test_logvoldesc_equals():
    logvol = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol.new()

    logvol2 = pycdlib.udf.UDFLogicalVolumeDescriptor()
    logvol2.new()

    assert(logvol == logvol2)

# Unallocated Space
def test_unallocated_parse_initialized_twice():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    un.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*488, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        un.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*488, 0, tag)
    assert(str(excinfo.value) == 'UDF Unallocated Space Descriptor already initialized')

def test_unallocated_parse_too_many_alloc_descs():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        un.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x3e\x00\x00\x00' + b'\x00'*488, 0, tag)
    assert(str(excinfo.value) == 'Too many allocation descriptors')

def test_unallocated_parse_alloc_descs():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    un.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*488, 0, tag)
    assert(len(un.alloc_descs) == 1)

def test_unallocated_record_not_initialized():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        un.record()
    assert(str(excinfo.value) == 'UDF Unallocated Space Descriptor not initialized')

def test_unallocated_record_alloc_descs():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    un.parse(b'\x00\x00\x02\x00\x05\x00\x00\x00\x52\xc0\xf0\x01\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*488, 0, tag)
    assert(un.record() == b'\x00\x00\x02\x00\x05\x00\x00\x00\x52\xc0\xf0\x01\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*488)

def test_unallocated_extent_location_not_initialized():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        un.extent_location()
    assert(str(excinfo.value) == 'UDF Unallocated Space Descriptor not initialized')

def test_unallocated_new_initialized_twice():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    un.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        un.new()
    assert(str(excinfo.value) == 'UDF Unallocated Space Descriptor already initialized')

def test_unallocated_set_extent_location_not_initialized():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        un.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Unallocated Space Descriptor not initialized')

def test_unallocated_equals():
    un = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    un.new()

    un2 = pycdlib.udf.UDFUnallocatedSpaceDescriptor()
    un2.new()

    assert(un == un2)

# Terminating Descriptor
def test_terminating_parse_initialized_twice():
    term = pycdlib.udf.UDFTerminatingDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    term.parse(0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.parse(0, tag)
    assert(str(excinfo.value) == 'UDF Terminating Descriptor already initialized')

def test_terminating_record_not_initialized():
    term = pycdlib.udf.UDFTerminatingDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.record()
    assert(str(excinfo.value) == 'UDF Terminating Descriptor not initialized')

def test_terminating_extent_location_not_initialized():
    term = pycdlib.udf.UDFTerminatingDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.extent_location()
    assert(str(excinfo.value) == 'UDF Terminating Descriptor not initialized')

def test_terminating_new_initialized_twice():
    term = pycdlib.udf.UDFTerminatingDescriptor()
    term.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.new()
    assert(str(excinfo.value) == 'UDF Terminating Descriptor already initialized')

def test_terminating_set_extent_location_not_initialized():
    term = pycdlib.udf.UDFTerminatingDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Terminating Descriptor not initialized')

# Logical Volume Header
def test_logvol_header_parse_initialized_twice():
    header = pycdlib.udf.UDFLogicalVolumeHeaderDescriptor()
    header.parse(b'\x00'*8 + b'\x00'*24)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        header.parse(b'\x00'*8 + b'\x00'*24)
    assert(str(excinfo.value) == 'UDF Logical Volume Header Descriptor already initialized')

def test_logvol_header_record_not_initialized():
    header = pycdlib.udf.UDFLogicalVolumeHeaderDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        header.record()
    assert(str(excinfo.value) == 'UDF Logical Volume Header Descriptor not initialized')

def test_logvol_header_new_initialized_twice():
    header = pycdlib.udf.UDFLogicalVolumeHeaderDescriptor()
    header.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        header.new()
    assert(str(excinfo.value) == 'UDF Logical Volume Header Descriptor already initialized')

# Logical Volume Implementation Use
def test_logvol_impl_parse_initialized_twice():
    impl = pycdlib.udf.UDFLogicalVolumeImplementationUse()
    impl.parse(b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.parse(b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF Logical Volume Implementation Use already initialized')

def test_logvol_impl_record_not_initialized():
    impl = pycdlib.udf.UDFLogicalVolumeImplementationUse()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.record()
    assert(str(excinfo.value) == 'UDF Logical Volume Implementation Use not initialized')

def test_logvol_impl_new_initialized_twice():
    impl = pycdlib.udf.UDFLogicalVolumeImplementationUse()
    impl.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        impl.new()
    assert(str(excinfo.value) == 'UDF Logical Volume Implementation Use already initialized')

# Logical Volume Integrity
def test_logvol_integrity_parse_initialized_twice():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    integrity.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*432, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        integrity.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*432, 0, tag)
    assert(str(excinfo.value) == 'UDF Logical Volume Integrity Descriptor already initialized')

def test_logvol_integrity_parse_bad_integrity_type():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        integrity.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x02\x00\x00\x00' + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*432, 0, tag)
    assert(str(excinfo.value) == 'Logical Volume Integrity Type not 0 or 1')

def test_logvol_integrity_parse_bad_impl_use():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        integrity.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*8 + b'\x00'*32 + b'\x00\x00\x00\x00\xb1\x01\x00\x00' + b'\x00'*432, 0, tag)
    assert(str(excinfo.value) == 'UDF Logical Volume Integrity specified an implementation use that is too large')

def test_logvol_integrity_record_not_initialized():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        integrity.record()
    assert(str(excinfo.value) == 'UDF Logical Volume Integrity Descriptor not initialized')

def test_logvol_integrity_extent_location_not_initialized():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        integrity.extent_location()
    assert(str(excinfo.value) == 'UDF Logical Volume Integrity Descriptor not initialized')

def test_logvol_integrity_new_initialized_twice():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    integrity.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        integrity.new()
    assert(str(excinfo.value) == 'UDF Logical Volume Integrity Descriptor already initialized')

def test_logvol_integrity_set_extent_location_not_initialized():
    integrity = pycdlib.udf.UDFLogicalVolumeIntegrityDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        integrity.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Logical Volume Integrity Descriptor not initialized')

# File Set
def test_file_set_parse_initialized_twice():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == 'UDF File Set Descriptor already initialized')

def test_file_set_parse_bad_interchange():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x02\x00\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_file_set_parse_bad_max_interchange():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x02\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_file_set_parse_bad_char_set_list():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_file_set_parse_bad_max_char_set_list():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_file_set_parse_bad_file_set_desc_num():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*OSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == 'Only DVD Read-Only disks are supported')

def test_file_set_parse_bad_domain_ident():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fileset.parse(b'\x00'*16 + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x03\x00\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*64 + b'\x00'*128 + b'\x00'*64 + b'\x00'*32 + b'\x00'*32 + b'\x00'*32 + b'\x00'*16 + b'\x00*MSTA UDF Compliant' + b'\x00'*12 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32, 0, tag)
    assert(str(excinfo.value) == "File Set Descriptor Identifier not '*OSTA UDF Compliant'")

def test_file_set_record_not_initialized():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fileset.record()
    assert(str(excinfo.value) == 'UDF File Set Descriptor not initialized')

def test_file_set_extent_location_not_initialized():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fileset.extent_location()
    assert(str(excinfo.value) == 'UDF File Set Descriptor not initialized')

def test_file_set_new_initialized_twice():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    fileset.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fileset.new()
    assert(str(excinfo.value) == 'UDF File Set Descriptor already initialized')

def test_file_set_set_extent_location_not_initialized():
    fileset = pycdlib.udf.UDFFileSetDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fileset.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF File Set Descriptor not initialized')

# LBAddr
def test_lbaddr_parse_initialized_twice():
    lb = pycdlib.udf.UDFLBAddr()
    lb.parse(b'\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        lb.parse(b'\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF LBAddr already initialized')

def test_lbaddr_record_not_initialized():
    lb = pycdlib.udf.UDFLBAddr()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        lb.record()
    assert(str(excinfo.value) == 'UDF LBAddr not initialized')

def test_lbaddr_new_initialized_twice():
    lb = pycdlib.udf.UDFLBAddr()
    lb.new(0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        lb.new(0)
    assert(str(excinfo.value) == 'UDF LBAddr already initialized')

# ICBTag
def test_icbtag_parse_initialized_twice():
    icb = pycdlib.udf.UDFICBTag()
    icb.parse(b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        icb.parse(b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    assert(str(excinfo.value) == 'UDF ICB Tag already initialized')

def test_icbtag_record_not_initialized():
    icb = pycdlib.udf.UDFICBTag()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        icb.record()
    assert(str(excinfo.value) == 'UDF ICB Tag not initialized')

def test_icbtag_new_initialized_twice():
    icb = pycdlib.udf.UDFICBTag()
    icb.new('dir')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        icb.new('dir')
    assert(str(excinfo.value) == 'UDF ICB Tag already initialized')

def test_icbtag_new_bad_file_type():
    icb = pycdlib.udf.UDFICBTag()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        icb.new('foo')
    assert(str(excinfo.value) == "Invalid file type for ICB; must be one of 'dir', 'file', or 'symlink'")

# File Entry
def test_file_entry_parse_initialized_twice():
    entry = pycdlib.udf.UDFFileEntry()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    entry.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x01\x00\x00\x00' + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, None, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x01\x00\x00\x00' + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, None, tag)
    assert(str(excinfo.value) == 'UDF File Entry already initialized')

def test_file_entry_parse_bad_record_format():
    entry = pycdlib.udf.UDFFileEntry()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        entry.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x01\x00\x00\x00' + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, None, tag)
    assert(str(excinfo.value) == 'File Entry record format is not 0')

def test_file_entry_parse_bad_record_display_attrs():
    entry = pycdlib.udf.UDFFileEntry()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        entry.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x01\x00\x00\x00' + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, None, tag)
    assert(str(excinfo.value) == 'File Entry record display attributes is not 0')

def test_file_entry_parse_bad_record_len():
    entry = pycdlib.udf.UDFFileEntry()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        entry.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x01\x00\x00\x00' + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, None, tag)
    assert(str(excinfo.value) == 'File Entry record length is not 0')

def test_file_entry_parse_bad_checkpoint():
    entry = pycdlib.udf.UDFFileEntry()
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        entry.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x00\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, None, tag)
    assert(str(excinfo.value) == 'Only DVD Read-only disks supported')

def test_file_entry_record_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.record()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_extent_location_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.extent_location()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_new_initialized_twice():
    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'dir', None, 2048)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.new(0, 'dir', None, 2048)
    assert(str(excinfo.value) == 'UDF File Entry already initialized')

def test_file_entry_new_bad_file_type():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.new(0, 'foo', None, 2048)
    assert(str(excinfo.value) == "UDF File Entry file type must be one of 'dir', 'file', or 'symlink'")

def test_file_entry_set_extent_location_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.set_extent_location(0, 0)
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_add_file_ident_desc_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    desc = pycdlib.udf.UDFFileIdentifierDescriptor()
    desc.new(False, False, b'foo', None)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.add_file_ident_desc(desc, 2048)
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_add_file_ident_desc_bad_file_type():
    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'file', None, 2048)
    desc = pycdlib.udf.UDFFileIdentifierDescriptor()
    desc.new(False, False, b'foo', None)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        entry.add_file_ident_desc(desc, 2048)
    assert(str(excinfo.value) == 'Can only add a UDF File Identifier to a directory')

def test_file_entry_remove_file_ident_desc_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.remove_file_ident_desc_by_name(b'foo', 2048)
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_remove_file_ident_desc_file_not_found():
    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'dir', None, 2048)
    desc = pycdlib.udf.UDFFileIdentifierDescriptor()
    desc.new(False, False, b'foo', None)
    entry.add_file_ident_desc(desc, 2048)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as excinfo:
        entry.remove_file_ident_desc_by_name(b'bar', 2048)
    assert(str(excinfo.value) == 'Cannot find file to remove')

def test_file_entry_set_data_location_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.set_data_location(0, 0)
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_get_data_length_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.get_data_length()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_set_data_length_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.set_data_length(0)
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_is_file_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.is_file()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_is_symlink_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.is_symlink()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_is_dir_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.is_dir()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_file_identifier_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.file_identifier()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_find_file_ident_desc_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.find_file_ident_desc_by_name(b'')
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_track_file_ident_desc_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.track_file_ident_desc(None)
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_is_dot_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.is_dot()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

def test_file_entry_is_dotdot_not_initialized():
    entry = pycdlib.udf.UDFFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        entry.is_dotdot()
    assert(str(excinfo.value) == 'UDF File Entry not initialized')

# File Identifier
def test_file_ident_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'dir', None, 2048)

    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.parse(b'\x00'*16 + b'\x01\x00\x08\x00' + b'\x00'*16 + b'\x00\x00', 0, tag, entry)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.parse(b'\x00'*16 + b'\x01\x00\x08\x00' + b'\x00'*16 + b'\x00\x00', 0, tag, entry)
    assert(str(excinfo.value) == 'UDF File Identifier Descriptor already initialized')

def test_file_ident_parse_bad_file_version():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'dir', None, 2048)

    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fi.parse(b'\x00'*16 + b'\x00\x00\x08\x00' + b'\x00'*16 + b'\x00\x00', 0, tag, entry)
    assert(str(excinfo.value) == 'File Identifier Descriptor file version number not 1')

def test_file_ident_parse_bad_encoding():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'dir', None, 2048)

    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        fi.parse(b'\x00'*16 + b'\x01\x00\x00\x01' + b'\x00'*16 + b'\x00\x00\x00', 0, tag, entry)
    assert(str(excinfo.value) == 'Only UDF File Identifier Descriptor Encodings 8 or 16 are supported')

def test_file_ident_is_dir_not_initialized():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.is_dir()
    assert(str(excinfo.value) == 'UDF File Identifier Descriptor not initialized')

def test_file_ident_is_parent_not_initialized():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.is_parent()
    assert(str(excinfo.value) == 'UDF File Identifier Descriptor not initialized')

def test_file_ident_record_not_initialized():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.record()
    assert(str(excinfo.value) == 'UDF File Identifier Descriptor not initialized')

def test_file_ident_record_bad_encoding():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    entry = pycdlib.udf.UDFFileEntry()
    entry.new(0, 'dir', None, 2048)

    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.parse(b'\x00'*16 + b'\x01\x00\x08\x01' + b'\x00'*16 + b'\x00\x00\x00', 0, tag, entry)
    fi.encoding = 'bad'
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.record()
    assert(str(excinfo.value) == 'Invalid UDF encoding; this should not happen')

def test_file_ident_extent_location_not_initialized():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.extent_location()
    assert(str(excinfo.value) == 'UDF File Identifier not initialized')

def test_file_ident_new_initialized_twice():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, False, b'foo', None)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.new(False, False, b'foo', None)
    assert(str(excinfo.value) == 'UDF File Identifier already initialized')

def test_file_ident_set_extent_location_not_initialized():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.set_extent_location(0, 0)
    assert(str(excinfo.value) == 'UDF File Identifier not initialized')

def test_file_ident_set_icb_not_initialized():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        fi.set_icb(0, 0)
    assert(str(excinfo.value) == 'UDF File Identifier not initialized')

def test_file_ident_lt():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, False, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, False, b'hoo', None)

    assert(fi < fi2)

def test_file_ident_lt_both_parent():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, True, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, True, b'hoo', None)

    assert(not(fi < fi2))

def test_file_ident_lt_one_parent():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, True, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, False, b'hoo', None)

    assert(fi < fi2)

def test_file_ident_lt_other_parent():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, False, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, True, b'hoo', None)

    assert(not(fi < fi2))

def test_file_ident_equals():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, False, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, False, b'foo', None)

    assert(fi == fi2)

def test_file_ident_equals_both_parent():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, True, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, True, b'foo', None)

    assert(fi == fi2)

def test_file_ident_equals_both_parent():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, True, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, True, b'foo', None)

    assert(fi == fi2)

def test_file_ident_equals_other_parent():
    fi = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi.new(False, False, b'foo', None)

    fi2 = pycdlib.udf.UDFFileIdentifierDescriptor()
    fi2.new(False, True, b'foo', None)

    assert(fi != fi2)

# Space Bitmap
def test_space_bitmap_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*24, 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bitmap.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*24, 0, tag)
    assert(str(excinfo.value) == 'UDF Space Bitmap Descriptor already initialized')

def test_space_bitmap_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*24, 0, tag)
    assert(bitmap.num_bits == 0)
    assert(bitmap.num_bytes == 0)

def test_space_bitmap_record_not_initialized():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bitmap.record()
    assert(str(excinfo.value) == 'UDF Space Bitmap Descriptor not initialized')

def test_space_bitmap_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*24, 0, tag)

    assert(bitmap.record() == b'\x00\x00\x02\x00\x22\x00\x00\x00\x00\x00\x20' + b'\x00'*37)

def test_space_bitmap_new_initialized_twice():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bitmap.new()
    assert(str(excinfo.value) == 'UDF Space Bitmap Descriptor already initialized')

def test_space_bitmap_new():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.new()
    assert(bitmap.num_bits == 0)
    assert(bitmap.num_bytes == 0)

def test_space_bitmap_extent_location_not_initialized():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bitmap.extent_location()
    assert(str(excinfo.value) == 'UDF Space Bitmap Descriptor not initialized')

def test_space_bitmap_extent_location_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*24, 0, tag)
    assert(bitmap.extent_location() == 0)

def test_space_bitmap_extent_location_new():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.new()
    bitmap.set_extent_location(0)
    assert(bitmap.extent_location() == 0)

def test_space_bitmap_set_extent_location_not_initialized():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        bitmap.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Space Bitmap Descriptor not initialized')

def test_space_bitmap_set_extent_location():
    bitmap = pycdlib.udf.UDFSpaceBitmapDescriptor()
    bitmap.new()
    bitmap.set_extent_location(1)
    assert(bitmap.extent_location() == 1)

# Allocation Extent
def test_alloc_extent_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        alloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(str(excinfo.value) == 'UDF Allocation Extent Descriptor already initialized')

def test_alloc_extent_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(alloc.prev_allocation_extent_loc == 0)
    assert(alloc.len_allocation_descs == 0)

def test_alloc_extent_record_not_initialized():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        alloc.record()
    assert(str(excinfo.value) == 'UDF Allocation Extent Descriptor not initialized')

def test_alloc_extent_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(alloc.record() == b'\x00\x00\x02\x00\x0a\x00\x00\x00\x00\x00\x08' + b'\x00'*13)

def test_alloc_extent_new_initialized_twice():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        alloc.new()
    assert(str(excinfo.value) == 'UDF Allocation Extent Descriptor already initialized')

def test_alloc_extent_new():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.new()
    assert(alloc.prev_allocation_extent_loc == 0)
    assert(alloc.len_allocation_descs == 0)

def test_alloc_extent_extent_location_not_initialized():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        alloc.extent_location()
    assert(str(excinfo.value) == 'UDF Allocation Extent Descriptor not initialized')

def test_alloc_extent_extent_location_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)

    assert(alloc.extent_location() == 0)

def test_alloc_extent_extent_location_new():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.new()
    alloc.set_extent_location(0)
    assert(alloc.extent_location() == 0)

def test_alloc_extent_set_extent_location_not_initialized():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        alloc.set_extent_location(0)
    assert(str(excinfo.value) == 'UDF Allocation Extent Descriptor not initialized')

def test_alloc_extent_set_extent_location():
    alloc = pycdlib.udf.UDFAllocationExtentDescriptor()
    alloc.new()
    alloc.set_extent_location(1)
    assert(alloc.extent_location() == 1)

# Indirect Entry
def test_indirect_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    indirect = pycdlib.udf.UDFIndirectEntry()
    indirect.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        indirect.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16, tag)
    assert(str(excinfo.value) == 'UDF Indirect Entry already initialized')

def test_indirect_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    indirect = pycdlib.udf.UDFIndirectEntry()
    indirect.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16, tag)
    assert(indirect.desc_tag.tag_ident == 0)

def test_indirect_record_not_initialized():
    indirect = pycdlib.udf.UDFIndirectEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        indirect.record()
    assert(str(excinfo.value) == 'UDF Indirect Entry not initialized')

def test_indirect_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    indirect = pycdlib.udf.UDFIndirectEntry()
    indirect.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16, tag)
    assert(indirect.record() == b'\x00\x00\x02\x00\xd4\x00\x00\x00\x39\x75\x24' + b'\x00'*5 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00'*16)

def test_indirect_new_initialized_twice():
    indirect = pycdlib.udf.UDFIndirectEntry()
    indirect.new('dir')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        indirect.new('dir')
    assert(str(excinfo.value) == 'UDF Indirect Entry already initialized')

def test_indirect_new():
    indirect = pycdlib.udf.UDFIndirectEntry()
    indirect.new('dir')
    assert(indirect.desc_tag.tag_ident == 259)

# Terminating
def test_terminating_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    term = pycdlib.udf.UDFTerminalEntry()
    term.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.parse(b'\x00'*16 + b'\x00'*20, tag)
    assert(str(excinfo.value) == 'UDF Terminal Entry already initialized')

def test_terminating_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    term = pycdlib.udf.UDFTerminalEntry()
    term.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    assert(term.desc_tag.tag_ident == 0)

def test_terminating_record_not_initialized():
    term = pycdlib.udf.UDFTerminalEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.record()
    assert(str(excinfo.value) == 'UDF Terminal Entry not initialized')

def test_terminating_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    term = pycdlib.udf.UDFTerminalEntry()
    term.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    assert(term.record() == b'\x00\x00\x02\x00\x68\x00\x00\x00\xd2\x80\x14\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

def test_terminating_new_initialized_twice():
    term = pycdlib.udf.UDFTerminalEntry()
    term.new('dir')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        term.new('dir')
    assert(str(excinfo.value) == 'UDF Terminal Entry already initialized')

def test_terminating_new():
    term = pycdlib.udf.UDFTerminalEntry()
    term.new('dir')
    assert(term.desc_tag.tag_ident == 260)

# Extended Attribute Header
def test_ext_header_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    ext = pycdlib.udf.UDFExtendedAttributeHeaderDescriptor()
    ext.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ext.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    assert(str(excinfo.value) == 'UDF Extended Attribute Header Descriptor already initialized')

def test_ext_header_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    ext = pycdlib.udf.UDFExtendedAttributeHeaderDescriptor()
    ext.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    assert(ext.desc_tag.tag_ident == 0)

def test_ext_header_record_not_initialized():
    ext = pycdlib.udf.UDFExtendedAttributeHeaderDescriptor()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ext.record()
    assert(str(excinfo.value) == 'UDF Extended Attribute Header Descriptor not initialized')

def test_ext_header_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    ext = pycdlib.udf.UDFExtendedAttributeHeaderDescriptor()
    ext.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x00\x00\x00\x00', tag)
    assert(ext.record() == b'\x00\x00\x02\x00\x0a\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00' + b'\x00'*8)

def test_ext_header_new_initialized_twice():
    ext = pycdlib.udf.UDFExtendedAttributeHeaderDescriptor()
    ext.new()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ext.new()
    assert(str(excinfo.value) == 'UDF Extended Attribute Header Descriptor already initialized')

def test_ext_header_new():
    ext = pycdlib.udf.UDFExtendedAttributeHeaderDescriptor()
    ext.new()
    assert(ext.desc_tag.tag_ident == 262)

# Unallocated Space
def test_unalloc_space_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    unalloc = pycdlib.udf.UDFUnallocatedSpaceEntry()
    unalloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00', 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        unalloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00', 0, tag)
    assert(str(excinfo.value) == 'UDF Unallocated Space Entry already initialized')

def test_unalloc_space_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    unalloc = pycdlib.udf.UDFUnallocatedSpaceEntry()
    unalloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00', 0, tag)
    assert(unalloc.desc_tag.tag_ident == 0)

def test_unalloc_space_record_not_initialized():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    unalloc = pycdlib.udf.UDFUnallocatedSpaceEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        unalloc.record()
    assert(str(excinfo.value) == 'UDF Unallocated Space Entry not initialized')

def test_unalloc_space_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    unalloc = pycdlib.udf.UDFUnallocatedSpaceEntry()
    unalloc.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(unalloc.record() == b'\x00\x00\x02\x00\xa3\x00\x00\x00\xf8\x89 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

def test_unalloc_space_new_initialized_twice():
    unalloc = pycdlib.udf.UDFUnallocatedSpaceEntry()
    unalloc.new('dir')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        unalloc.new('dir')
    assert(str(excinfo.value) == 'UDF Unallocated Space Entry already initialized')

def test_unalloc_space_new():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    unalloc = pycdlib.udf.UDFUnallocatedSpaceEntry()
    unalloc.new('dir')
    assert(unalloc.desc_tag.tag_ident == 263)

# Partition Integrity
def test_part_integrity_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    part = pycdlib.udf.UDFPartitionIntegrityEntry()
    part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00' + b'\x00'*175 + b'\x00'*32 + b'\x00'*256, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00' + b'\x00'*175 + b'\x00'*32 + b'\x00'*256, tag)
    assert(str(excinfo.value) == 'UDF Partition Integrity Entry already initialized')

def test_part_integrity_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    part = pycdlib.udf.UDFPartitionIntegrityEntry()
    part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00' + b'\x00'*175 + b'\x00'*32 + b'\x00'*256, tag)
    assert(part.desc_tag.tag_ident == 0)

def test_part_integrity_record_not_initialized():
    part = pycdlib.udf.UDFPartitionIntegrityEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.record()
    assert(str(excinfo.value) == 'UDF Partition Integrity Entry not initialized')

def test_part_integrity_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    part = pycdlib.udf.UDFPartitionIntegrityEntry()
    part.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00' + b'\x00'*175 + b'\x00'*32 + b'\x00'*256, tag)
    assert(part.record() == b'\x00\x00\x02\x00\x00\x00\x00\x00\xbe\x4f\xf0\x01\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

def test_part_integrity_new_initialized_twice():
    part = pycdlib.udf.UDFPartitionIntegrityEntry()
    part.new('dir')
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        part.new('dir')
    assert(str(excinfo.value) == 'UDF Partition Integrity Entry already initialized')

def test_part_integrity_new():
    part = pycdlib.udf.UDFPartitionIntegrityEntry()
    part.new('dir')
    assert(part.desc_tag.tag_ident == 265)

# Extended File
def test_extended_file_parse_initialized_twice():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    ef = pycdlib.udf.UDFExtendedFileEntry()
    ef.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*4 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ef.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*4 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(str(excinfo.value) == 'UDF Extended File Entry already initialized')

def test_extended_file_parse():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    ef = pycdlib.udf.UDFExtendedFileEntry()
    ef.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*4 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(ef.desc_tag.tag_ident == 0)

def test_extended_file_record_not_initialized():
    ef = pycdlib.udf.UDFExtendedFileEntry()
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ef.record()
    assert(str(excinfo.value) == 'UDF Extended File Entry not initialized')

def test_extended_file_record():
    tag = pycdlib.udf.UDFTag()
    tag.new(0, 0)

    ef = pycdlib.udf.UDFExtendedFileEntry()
    ef.parse(b'\x00'*16 + b'\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00' + b'\x00\x00\x00\x00' + b'\x00'*4 + b'\x00'*16 + b'\x00'*16 + b'\x00'*32 + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00' + b'\x00\x00\x00\x00\x00\x00\x00\x00', 0, tag)
    assert(ef.record() == b'\x00\x00\x02\x00\xf1\x00\x00\x00\x52\xcd\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

def test_extended_file_new_initialized_twice():
    ef = pycdlib.udf.UDFExtendedFileEntry()
    ef.new('dir', 0, 2048)
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        ef.new('dir', 0, 2048)
    assert(str(excinfo.value) == 'UDF Extended File Entry already initialized')

def test_extended_file_new_dir():
    ef = pycdlib.udf.UDFExtendedFileEntry()
    ef.new('dir', 0, 2048)
    assert(ef.desc_tag.tag_ident == 266)

def test_extended_file_new_file():
    ef = pycdlib.udf.UDFExtendedFileEntry()
    ef.new('file', 5, 2048)
    assert(ef.desc_tag.tag_ident == 266)

# parse_allocation_descriptors
def test_parse_allocation_descriptors_long():
    alloc_descs = pycdlib.udf._parse_allocation_descriptors(1, b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 16, 0, 0)
    assert(len(alloc_descs) == 1)
    assert(isinstance(alloc_descs[0], pycdlib.udf.UDFLongAD))

def test_parse_allocation_descriptors_extended():
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
        alloc_descs = pycdlib.udf._parse_allocation_descriptors(2, b'', 0, 0, 0)
    assert(str(excinfo.value) == 'UDF Allocation Descriptor of type 2 (Extended) not yet supported')

def test_parse_allocation_descriptors_inline():
    alloc_descs = pycdlib.udf._parse_allocation_descriptors(3, b'', 0, 0, 0)
    assert(len(alloc_descs) == 1)
    assert(isinstance(alloc_descs[0], pycdlib.udf.UDFInlineAD))

def test_parse_allocation_descriptors_invalid():
    with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidISO) as excinfo:
        alloc_descs = pycdlib.udf._parse_allocation_descriptors(4, b'', 0, 0, 0)
    assert(str(excinfo.value) == 'UDF Allocation Descriptor type invalid')