1 module plist.tests.data; 2 import plist; 3 import plist.types; 4 5 unittest { 6 /* Can we even parse? */ 7 { 8 string xml = `<?xml version="1.0" encoding="UTF-8"?> 9 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 10 <plist version="1.0"> 11 <data>QUFBQQ==</data> 12 </plist>`; 13 Plist parse = new Plist(); 14 parse.read(xml); 15 16 assert(parse.length == 1, "Expected length of 1"); 17 18 assert(parse.write() == xml, "Writing doesn't output the same what we put in"); 19 20 assert(parse[0].type() == PlistElementType.PLIST_ELEMENT_DATA, "Expected data type"); 21 } 22 /* Test if value is correct */ 23 { 24 string xml = `<?xml version="1.0" encoding="UTF-8"?> 25 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 26 <plist version="1.0"> 27 <data>QUFBQQ==</data> 28 </plist>`; 29 Plist parse = new Plist(); 30 parse.read(xml); 31 32 assert(parse.length == 1, "Expected length of 1"); 33 34 assert(parse.write() == xml, "Writing doesn't output the same what we put in"); 35 36 assert(parse[0].type() == PlistElementType.PLIST_ELEMENT_DATA, "Expected data type"); 37 38 PlistElementData dat = cast(PlistElementData)parse[0]; 39 40 assert(dat.value == [0x41, 0x41, 0x41, 0x41], "Did not get magic value from decoding"); 41 } 42 /* Test modifying the value */ 43 { 44 string xml = `<?xml version="1.0" encoding="UTF-8"?> 45 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 46 <plist version="1.0"> 47 <data>QUFBQQ==</data> 48 </plist>`; 49 string expected = `<?xml version="1.0" encoding="UTF-8"?> 50 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 51 <plist version="1.0"> 52 <data>3q2+7w==</data> 53 </plist>`; 54 55 Plist parse = new Plist(); 56 parse.read(xml); 57 58 assert(parse.length == 1, "Expected length of 1"); 59 60 assert(parse.write() == xml, "Writing doesn't output the same what we put in"); 61 62 assert(parse[0].type() == PlistElementType.PLIST_ELEMENT_DATA, "Expected data type"); 63 64 PlistElementData dat = cast(PlistElementData)parse[0]; 65 66 assert(dat.value == [0x41, 0x41, 0x41, 0x41], "Did not get magic value from decoding"); 67 ubyte[] val = dat.value; 68 val[0] = 0xDE; 69 val[1] = 0xAD; 70 val[2] = 0xBE; 71 val[3] = 0xEF; 72 dat.value = val; 73 assert(parse.write() == expected, "Did not get magic value from encoding"); 74 } 75 /* Data is empty */ 76 { 77 string xml = `<?xml version="1.0" encoding="UTF-8"?> 78 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 79 <plist version="1.0"> 80 <data/> 81 </plist>`; 82 Plist parse = new Plist(); 83 parse.read(xml); 84 85 assert(parse.length == 1, "Expected length of 1"); 86 87 assert(parse.write() == xml, "Writing doesn't output the same what we put in"); 88 89 assert(parse[0].type() == PlistElementType.PLIST_ELEMENT_DATA, "Expected data type"); 90 91 PlistElementData dat = cast(PlistElementData)parse[0]; 92 93 assert(dat.value == [], "Did not get magic value from decoding"); 94 } 95 /* Ditto */ 96 { 97 string xml = `<?xml version="1.0" encoding="UTF-8"?> 98 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 99 <plist version="1.0"> 100 <data></data> 101 </plist>`; 102 string expected = `<?xml version="1.0" encoding="UTF-8"?> 103 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 104 <plist version="1.0"> 105 <data/> 106 </plist>`; 107 108 Plist parse = new Plist(); 109 parse.read(xml); 110 111 assert(parse.length == 1, "Expected length of 1"); 112 113 assert(parse.write() == expected, "Writing doesn't output the same what we put in"); 114 115 assert(parse[0].type() == PlistElementType.PLIST_ELEMENT_DATA, "Expected data type"); 116 117 PlistElementData dat = cast(PlistElementData)parse[0]; 118 119 assert(dat.value == [], "Did not get magic value from decoding"); 120 } 121 }