|
26 | 26 |
|
27 | 27 | import static org.junit.Assert.assertEquals; |
28 | 28 | import static org.junit.Assert.assertFalse; |
| 29 | +import static org.junit.Assert.assertNotNull; |
29 | 30 | import static org.junit.Assert.assertTrue; |
30 | 31 |
|
31 | 32 | public class IDEDriveDescriptorTest { |
@@ -117,57 +118,145 @@ public void testConstructorDataWrongLength() { |
117 | 118 | public void testGetSerialNumber() { |
118 | 119 | String result = ideDescriptor.getSerialNumber(); |
119 | 120 | assertEquals("5LS9K7CF", result); |
| 121 | + assertNotNull("Serial number must not be null", result); |
| 122 | + assertTrue("Serial number must not be empty", result.length() > 0); |
120 | 123 | } |
121 | 124 |
|
122 | 125 | @Test |
123 | 126 | public void testGetModel() { |
124 | 127 | String result = ideDescriptor.getModel(); |
125 | 128 | assertEquals("ST3160812AS", result); |
| 129 | + assertNotNull("Model must not be null", result); |
| 130 | + assertTrue("Model must not be empty", result.length() > 0); |
| 131 | + assertTrue("Model must be at most 40 chars", result.length() <= 40); |
126 | 132 | } |
127 | 133 |
|
128 | 134 | @Test |
129 | 135 | public void testGetFirmware() { |
130 | 136 | String result = ideDescriptor.getFirmware(); |
131 | 137 | assertEquals("3.ADJ", result); |
| 138 | + assertNotNull("Firmware must not be null", result); |
| 139 | + assertTrue("Firmware must not be empty", result.length() > 0); |
| 140 | + assertTrue("Firmware must be at most 8 chars", result.length() <= 8); |
132 | 141 | } |
133 | 142 |
|
134 | 143 | @Test |
135 | 144 | public void testGetSectorsAddressable() { |
136 | 145 | long result = ideDescriptor.getSectorsAddressable(); |
137 | 146 | //Get actually the LBA48 user addressable sectors |
138 | 147 | assertEquals(312500000, result); |
| 148 | + assertTrue("Sectors addressable must be positive", result > 0); |
| 149 | + int[] data28bit = new int[256]; |
| 150 | + System.arraycopy(ide, 0, data28bit, 0, 256); |
| 151 | + data28bit[83] = data28bit[83] & ~0x400; |
| 152 | + IDEDriveDescriptor desc28 = new IDEDriveDescriptor(data28bit, true); |
| 153 | + long result28 = desc28.getSectorsAddressable(); |
| 154 | + assertEquals("28-bit addressing sectors", 268435455L, result28); |
| 155 | + assertTrue("28-bit sectors must be positive", result28 > 0); |
139 | 156 | } |
140 | 157 |
|
141 | 158 | @Test |
142 | 159 | public void testSupports48bitAddressing() { |
143 | 160 | boolean result = ideDescriptor.supports48bitAddressing(); |
144 | 161 | assertTrue("Must support 48bits addressing", result); |
| 162 | + assertTrue("Bit10 of word83 must be set for LBA48", |
| 163 | + (ide[83] & 0x400) != 0); |
145 | 164 | } |
146 | 165 |
|
147 | 166 | @Test |
148 | 167 | public void testSupportsLBA() { |
149 | 168 | boolean result = ideDescriptor.supportsLBA(); |
150 | 169 | assertTrue("Must support LBA", result); |
| 170 | + assertTrue("Bit9 of word49 must be set for LBA support", |
| 171 | + (ide[49] & 0x0200) != 0); |
151 | 172 | } |
152 | 173 |
|
153 | 174 | @Test |
154 | 175 | public void testDMA() { |
155 | 176 | boolean result = ideDescriptor.supportsDMA(); |
156 | 177 | assertTrue("Must support DMA", result); |
| 178 | + assertTrue("Bit8 of word49 must be set for DMA support", |
| 179 | + (ide[49] & 0x0100) != 0); |
157 | 180 | } |
158 | 181 |
|
159 | 182 | @Test |
160 | 183 | public void testIsATA() { |
161 | 184 | boolean result = ideDescriptor.isAta(); |
162 | 185 | assertTrue("Must be ATA drive", result); |
| 186 | + assertFalse("Bit15 of word0 must be clear for ATA", |
| 187 | + (ide[0] & 0x8000) != 0); |
| 188 | + assertFalse("CD-ROM must not be ATA", cdromIdeDescriptor.isAta()); |
163 | 189 | } |
164 | 190 |
|
165 | 191 | @Test |
166 | 192 | public void testIsRemovable() { |
167 | 193 | boolean result = ideDescriptor.isRemovable(); |
168 | 194 | assertFalse("Must not be a removable device", result); |
| 195 | + assertFalse("Bit7 of word0 must be clear for non-removable", |
| 196 | + (ide[0] & 0x80) != 0); |
169 | 197 | result = cdromIdeDescriptor.isRemovable(); |
170 | 198 | assertTrue("Must be a removable device", result); |
| 199 | + assertTrue("Bit7 of word0 must be set for removable", |
| 200 | + (cdrom[0] & 0x80) != 0); |
| 201 | + } |
| 202 | + |
| 203 | + @Test |
| 204 | + public void testIsDisk() { |
| 205 | + IDEDriveDescriptor ataDisk = new IDEDriveDescriptor(ide, false); |
| 206 | + assertTrue("IDE disk must be a disk", ataDisk.isDisk()); |
| 207 | + IDEDriveDescriptor atapiDisk = new IDEDriveDescriptor(cdrom, true); |
| 208 | + assertFalse("CD-ROM must not be a disk", atapiDisk.isDisk()); |
| 209 | + } |
| 210 | + |
| 211 | + @Test |
| 212 | + public void testIsCDROM() { |
| 213 | + IDEDriveDescriptor ataDisk = new IDEDriveDescriptor(ide, false); |
| 214 | + assertFalse("IDE disk must not be a CD-ROM", ataDisk.isCDROM()); |
| 215 | + assertTrue("CD-ROM descriptor must be a CD-ROM", cdromIdeDescriptor.isCDROM()); |
| 216 | + } |
| 217 | + |
| 218 | + @Test |
| 219 | + public void testIsTape() { |
| 220 | + assertFalse("IDE disk must not be a tape", ideDescriptor.isTape()); |
| 221 | + assertFalse("CD-ROM must not be a tape", cdromIdeDescriptor.isTape()); |
| 222 | + } |
| 223 | + |
| 224 | + @Test |
| 225 | + public void testIsAtapi() { |
| 226 | + IDEDriveDescriptor ataDisk = new IDEDriveDescriptor(ide, false); |
| 227 | + assertFalse("IDE disk must not be ATAPI", ataDisk.isAtapi()); |
| 228 | + assertTrue("CD-ROM descriptor must be ATAPI", cdromIdeDescriptor.isAtapi()); |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + public void testToString() { |
| 233 | + String result = ideDescriptor.toString(); |
| 234 | + assertNotNull("toString must not be null", result); |
| 235 | + assertTrue("toString must contain serial", result.contains("serial=[5LS9K7CF]")); |
| 236 | + assertTrue("toString must contain firmware", result.contains("firmware=[3.ADJ]")); |
| 237 | + assertTrue("toString must contain model", result.contains("model=[ST3160812AS]")); |
| 238 | + assertTrue("toString must not be empty", result.length() > 0); |
| 239 | + } |
| 240 | + |
| 241 | + @Test |
| 242 | + public void testCdromSerialNumber() { |
| 243 | + String result = cdromIdeDescriptor.getSerialNumber(); |
| 244 | + assertNotNull("CD-ROM serial must not be null", result); |
| 245 | + assertEquals("CD-ROM serial (all spaces)", "", result); |
| 246 | + } |
| 247 | + |
| 248 | + @Test |
| 249 | + public void testCdromModel() { |
| 250 | + String result = cdromIdeDescriptor.getModel(); |
| 251 | + assertNotNull("CD-ROM model must not be null", result); |
| 252 | + assertEquals("CD-ROM model", "_NEC DVD+/-RW ND-3650A", result); |
| 253 | + } |
| 254 | + |
| 255 | + @Test |
| 256 | + public void testCdromFirmware() { |
| 257 | + String result = cdromIdeDescriptor.getFirmware(); |
| 258 | + assertNotNull("CD-ROM firmware must not be null", result); |
| 259 | + assertEquals("CD-ROM firmware", "105C", result); |
171 | 260 | } |
172 | 261 |
|
173 | 262 | } |
0 commit comments