1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony; 18 19 import com.android.internal.telephony.WspTypeDecoder; 20 import com.android.internal.util.HexDump; 21 22 import java.io.ByteArrayOutputStream; 23 import java.util.HashMap; 24 import java.util.Map; 25 26 import junit.framework.TestCase; 27 28 public class Wap230WspContentTypeTest extends TestCase { 29 30 public static final Map<Integer, String> WELL_KNOWN_SHORT_MIME_TYPES 31 = new HashMap<Integer, String>(); 32 public static final Map<Integer, String> WELL_KNOWN_LONG_MIME_TYPES 33 = new HashMap<Integer, String>(); 34 public static final Map<Integer, String> WELL_KNOWN_PARAMETERS 35 = new HashMap<Integer, String>(); 36 37 static { 38 WELL_KNOWN_SHORT_MIME_TYPES.put(0x00, "*/*"); 39 WELL_KNOWN_SHORT_MIME_TYPES.put(0x01, "text/*"); 40 WELL_KNOWN_SHORT_MIME_TYPES.put(0x02, "text/html"); 41 WELL_KNOWN_SHORT_MIME_TYPES.put(0x03, "text/plain"); 42 WELL_KNOWN_SHORT_MIME_TYPES.put(0x04, "text/x-hdml"); 43 WELL_KNOWN_SHORT_MIME_TYPES.put(0x05, "text/x-ttml"); 44 WELL_KNOWN_SHORT_MIME_TYPES.put(0x06, "text/x-vCalendar"); 45 WELL_KNOWN_SHORT_MIME_TYPES.put(0x07, "text/x-vCard"); 46 WELL_KNOWN_SHORT_MIME_TYPES.put(0x08, "text/vnd.wap.wml"); 47 WELL_KNOWN_SHORT_MIME_TYPES.put(0x09, "text/vnd.wap.wmlscript"); 48 WELL_KNOWN_SHORT_MIME_TYPES.put(0x0A, "text/vnd.wap.wta-event"); 49 WELL_KNOWN_SHORT_MIME_TYPES.put(0x0B, "multipart/*"); 50 WELL_KNOWN_SHORT_MIME_TYPES.put(0x0C, "multipart/mixed"); 51 WELL_KNOWN_SHORT_MIME_TYPES.put(0x0D, "multipart/form-data"); 52 WELL_KNOWN_SHORT_MIME_TYPES.put(0x0E, "multipart/byterantes"); 53 WELL_KNOWN_SHORT_MIME_TYPES.put(0x0F, "multipart/alternative"); 54 WELL_KNOWN_SHORT_MIME_TYPES.put(0x10, "application/*"); 55 WELL_KNOWN_SHORT_MIME_TYPES.put(0x11, "application/java-vm"); 56 WELL_KNOWN_SHORT_MIME_TYPES.put(0x12, "application/x-www-form-urlencoded"); 57 WELL_KNOWN_SHORT_MIME_TYPES.put(0x13, "application/x-hdmlc"); 58 WELL_KNOWN_SHORT_MIME_TYPES.put(0x14, "application/vnd.wap.wmlc"); 59 WELL_KNOWN_SHORT_MIME_TYPES.put(0x15, "application/vnd.wap.wmlscriptc"); 60 WELL_KNOWN_SHORT_MIME_TYPES.put(0x16, "application/vnd.wap.wta-eventc"); 61 WELL_KNOWN_SHORT_MIME_TYPES.put(0x17, "application/vnd.wap.uaprof"); 62 WELL_KNOWN_SHORT_MIME_TYPES.put(0x18, "application/vnd.wap.wtls-ca-certificate"); 63 WELL_KNOWN_SHORT_MIME_TYPES.put(0x19, "application/vnd.wap.wtls-user-certificate"); 64 WELL_KNOWN_SHORT_MIME_TYPES.put(0x1A, "application/x-x509-ca-cert"); 65 WELL_KNOWN_SHORT_MIME_TYPES.put(0x1B, "application/x-x509-user-cert"); 66 WELL_KNOWN_SHORT_MIME_TYPES.put(0x1C, "image/*"); 67 WELL_KNOWN_SHORT_MIME_TYPES.put(0x1D, "image/gif"); 68 WELL_KNOWN_SHORT_MIME_TYPES.put(0x1E, "image/jpeg"); 69 WELL_KNOWN_SHORT_MIME_TYPES.put(0x1F, "image/tiff"); 70 WELL_KNOWN_SHORT_MIME_TYPES.put(0x20, "image/png"); 71 WELL_KNOWN_SHORT_MIME_TYPES.put(0x21, "image/vnd.wap.wbmp"); 72 WELL_KNOWN_SHORT_MIME_TYPES.put(0x22, "application/vnd.wap.multipart.*"); 73 WELL_KNOWN_SHORT_MIME_TYPES.put(0x23, "application/vnd.wap.multipart.mixed"); 74 WELL_KNOWN_SHORT_MIME_TYPES.put(0x24, "application/vnd.wap.multipart.form-data"); 75 WELL_KNOWN_SHORT_MIME_TYPES.put(0x25, "application/vnd.wap.multipart.byteranges"); 76 WELL_KNOWN_SHORT_MIME_TYPES.put(0x26, "application/vnd.wap.multipart.alternative"); 77 WELL_KNOWN_SHORT_MIME_TYPES.put(0x27, "application/xml"); 78 WELL_KNOWN_SHORT_MIME_TYPES.put(0x28, "text/xml"); 79 WELL_KNOWN_SHORT_MIME_TYPES.put(0x29, "application/vnd.wap.wbxml"); 80 WELL_KNOWN_SHORT_MIME_TYPES.put(0x2A, "application/x-x968-cross-cert"); 81 WELL_KNOWN_SHORT_MIME_TYPES.put(0x2B, "application/x-x968-ca-cert"); 82 WELL_KNOWN_SHORT_MIME_TYPES.put(0x2C, "application/x-x968-user-cert"); 83 WELL_KNOWN_SHORT_MIME_TYPES.put(0x2D, "text/vnd.wap.si"); 84 WELL_KNOWN_SHORT_MIME_TYPES.put(0x2E, "application/vnd.wap.sic"); 85 WELL_KNOWN_SHORT_MIME_TYPES.put(0x2F, "text/vnd.wap.sl"); 86 WELL_KNOWN_SHORT_MIME_TYPES.put(0x30, "application/vnd.wap.slc"); 87 WELL_KNOWN_SHORT_MIME_TYPES.put(0x31, "text/vnd.wap.co"); 88 WELL_KNOWN_SHORT_MIME_TYPES.put(0x32, "application/vnd.wap.coc"); 89 WELL_KNOWN_SHORT_MIME_TYPES.put(0x33, "application/vnd.wap.multipart.related"); 90 WELL_KNOWN_SHORT_MIME_TYPES.put(0x34, "application/vnd.wap.sia"); 91 WELL_KNOWN_SHORT_MIME_TYPES.put(0x35, "text/vnd.wap.connectivity-xml"); 92 WELL_KNOWN_SHORT_MIME_TYPES.put(0x36, "application/vnd.wap.connectivity-wbxml"); 93 WELL_KNOWN_SHORT_MIME_TYPES.put(0x37, "application/pkcs7-mime"); 94 WELL_KNOWN_SHORT_MIME_TYPES.put(0x38, "application/vnd.wap.hashed-certificate"); 95 WELL_KNOWN_SHORT_MIME_TYPES.put(0x39, "application/vnd.wap.signed-certificate"); 96 WELL_KNOWN_SHORT_MIME_TYPES.put(0x3A, "application/vnd.wap.cert-response"); 97 WELL_KNOWN_SHORT_MIME_TYPES.put(0x3B, "application/xhtml+xml"); 98 WELL_KNOWN_SHORT_MIME_TYPES.put(0x3C, "application/wml+xml"); 99 WELL_KNOWN_SHORT_MIME_TYPES.put(0x3D, "text/css"); 100 WELL_KNOWN_SHORT_MIME_TYPES.put(0x3E, "application/vnd.wap.mms-message"); 101 WELL_KNOWN_SHORT_MIME_TYPES.put(0x3F, "application/vnd.wap.rollover-certificate"); 102 WELL_KNOWN_SHORT_MIME_TYPES.put(0x40, "application/vnd.wap.locc+wbxml"); 103 WELL_KNOWN_SHORT_MIME_TYPES.put(0x41, "application/vnd.wap.loc+xml"); 104 WELL_KNOWN_SHORT_MIME_TYPES.put(0x42, "application/vnd.syncml.dm+wbxml"); 105 WELL_KNOWN_SHORT_MIME_TYPES.put(0x43, "application/vnd.syncml.dm+xml"); 106 WELL_KNOWN_SHORT_MIME_TYPES.put(0x44, "application/vnd.syncml.notification"); 107 WELL_KNOWN_SHORT_MIME_TYPES.put(0x45, "application/vnd.wap.xhtml+xml"); 108 WELL_KNOWN_SHORT_MIME_TYPES.put(0x46, "application/vnd.wv.csp.cir"); 109 WELL_KNOWN_SHORT_MIME_TYPES.put(0x47, "application/vnd.oma.dd+xml"); 110 WELL_KNOWN_SHORT_MIME_TYPES.put(0x48, "application/vnd.oma.drm.message"); 111 WELL_KNOWN_SHORT_MIME_TYPES.put(0x49, "application/vnd.oma.drm.content"); 112 WELL_KNOWN_SHORT_MIME_TYPES.put(0x4A, "application/vnd.oma.drm.rights+xml"); 113 WELL_KNOWN_SHORT_MIME_TYPES.put(0x4B, "application/vnd.oma.drm.rights+wbxml"); 114 WELL_KNOWN_SHORT_MIME_TYPES.put(0x4C, "application/vnd.wv.csp+xml"); 115 WELL_KNOWN_SHORT_MIME_TYPES.put(0x4D, "application/vnd.wv.csp+wbxml"); 116 WELL_KNOWN_SHORT_MIME_TYPES.put(0x4E, "application/vnd.syncml.ds.notification"); 117 WELL_KNOWN_SHORT_MIME_TYPES.put(0x4F, "audio/*"); 118 WELL_KNOWN_SHORT_MIME_TYPES.put(0x50, "video/*"); 119 WELL_KNOWN_SHORT_MIME_TYPES.put(0x51, "application/vnd.oma.dd2+xml"); 120 WELL_KNOWN_SHORT_MIME_TYPES.put(0x52, "application/mikey"); 121 WELL_KNOWN_SHORT_MIME_TYPES.put(0x53, "application/vnd.oma.dcd"); 122 WELL_KNOWN_SHORT_MIME_TYPES.put(0x54, "application/vnd.oma.dcdc"); 123 124 WELL_KNOWN_LONG_MIME_TYPES.put(0x0201, "application/vnd.uplanet.cacheop-wbxml"); 125 WELL_KNOWN_LONG_MIME_TYPES.put(0x0202, "application/vnd.uplanet.signal"); 126 WELL_KNOWN_LONG_MIME_TYPES.put(0x0203, "application/vnd.uplanet.alert-wbxml"); 127 WELL_KNOWN_LONG_MIME_TYPES.put(0x0204, "application/vnd.uplanet.list-wbxml"); 128 WELL_KNOWN_LONG_MIME_TYPES.put(0x0205, "application/vnd.uplanet.listcmd-wbxml"); 129 WELL_KNOWN_LONG_MIME_TYPES.put(0x0206, "application/vnd.uplanet.channel-wbxml"); 130 WELL_KNOWN_LONG_MIME_TYPES.put(0x0207, "application/vnd.uplanet.provisioning-status-uri"); 131 WELL_KNOWN_LONG_MIME_TYPES.put(0x0208, "x-wap.multipart/vnd.uplanet.header-set"); 132 WELL_KNOWN_LONG_MIME_TYPES.put(0x0209, "application/vnd.uplanet.bearer-choice-wbxml"); 133 WELL_KNOWN_LONG_MIME_TYPES.put(0x020A, "application/vnd.phonecom.mmc-wbxml"); 134 WELL_KNOWN_LONG_MIME_TYPES.put(0x020B, "application/vnd.nokia.syncset+wbxml"); 135 WELL_KNOWN_LONG_MIME_TYPES.put(0x020C, "image/x-up-wpng"); 136 WELL_KNOWN_LONG_MIME_TYPES.put(0x0300, "application/iota.mmc-wbxml"); 137 WELL_KNOWN_LONG_MIME_TYPES.put(0x0301, "application/iota.mmc-xml"); 138 WELL_KNOWN_LONG_MIME_TYPES.put(0x0302, "application/vnd.syncml+xml"); 139 WELL_KNOWN_LONG_MIME_TYPES.put(0x0303, "application/vnd.syncml+wbxml"); 140 WELL_KNOWN_LONG_MIME_TYPES.put(0x0304, "text/vnd.wap.emn+xml"); 141 WELL_KNOWN_LONG_MIME_TYPES.put(0x0305, "text/calendar"); 142 WELL_KNOWN_LONG_MIME_TYPES.put(0x0306, "application/vnd.omads-email+xml"); 143 WELL_KNOWN_LONG_MIME_TYPES.put(0x0307, "application/vnd.omads-file+xml"); 144 WELL_KNOWN_LONG_MIME_TYPES.put(0x0308, "application/vnd.omads-folder+xml"); 145 WELL_KNOWN_LONG_MIME_TYPES.put(0x0309, "text/directory;profile=vCard"); 146 WELL_KNOWN_LONG_MIME_TYPES.put(0x030A, "application/vnd.wap.emn+wbxml"); 147 WELL_KNOWN_LONG_MIME_TYPES.put(0x030B, "application/vnd.nokia.ipdc-purchase-response"); 148 WELL_KNOWN_LONG_MIME_TYPES.put(0x030C, "application/vnd.motorola.screen3+xml"); 149 WELL_KNOWN_LONG_MIME_TYPES.put(0x030D, "application/vnd.motorola.screen3+gzip"); 150 WELL_KNOWN_LONG_MIME_TYPES.put(0x030E, "application/vnd.cmcc.setting+wbxml"); 151 WELL_KNOWN_LONG_MIME_TYPES.put(0x030F, "application/vnd.cmcc.bombing+wbxml"); 152 WELL_KNOWN_LONG_MIME_TYPES.put(0x0310, "application/vnd.docomo.pf"); 153 WELL_KNOWN_LONG_MIME_TYPES.put(0x0311, "application/vnd.docomo.ub"); 154 WELL_KNOWN_LONG_MIME_TYPES.put(0x0312, "application/vnd.omaloc-supl-init"); 155 WELL_KNOWN_LONG_MIME_TYPES.put(0x0313, "application/vnd.oma.group-usage-list+xml"); 156 WELL_KNOWN_LONG_MIME_TYPES.put(0x0314, "application/oma-directory+xml"); 157 WELL_KNOWN_LONG_MIME_TYPES.put(0x0315, "application/vnd.docomo.pf2"); 158 WELL_KNOWN_LONG_MIME_TYPES.put(0x0316, "application/vnd.oma.drm.roap-trigger+wbxml"); 159 WELL_KNOWN_LONG_MIME_TYPES.put(0x0317, "application/vnd.sbm.mid2"); 160 WELL_KNOWN_LONG_MIME_TYPES.put(0x0318, "application/vnd.wmf.bootstrap"); 161 WELL_KNOWN_LONG_MIME_TYPES.put(0x0319, "application/vnc.cmcc.dcd+xml"); 162 WELL_KNOWN_LONG_MIME_TYPES.put(0x031A, "application/vnd.sbm.cid"); 163 WELL_KNOWN_LONG_MIME_TYPES.put(0x031B, "application/vnd.oma.bcast.provisioningtrigger"); 164 165 WELL_KNOWN_PARAMETERS.put(0x00, "Q"); 166 WELL_KNOWN_PARAMETERS.put(0x01, "Charset"); 167 WELL_KNOWN_PARAMETERS.put(0x02, "Level"); 168 WELL_KNOWN_PARAMETERS.put(0x03, "Type"); 169 WELL_KNOWN_PARAMETERS.put(0x07, "Differences"); 170 WELL_KNOWN_PARAMETERS.put(0x08, "Padding"); 171 WELL_KNOWN_PARAMETERS.put(0x09, "Type"); 172 WELL_KNOWN_PARAMETERS.put(0x0E, "Max-Age"); 173 WELL_KNOWN_PARAMETERS.put(0x10, "Secure"); 174 WELL_KNOWN_PARAMETERS.put(0x11, "SEC"); 175 WELL_KNOWN_PARAMETERS.put(0x12, "MAC"); 176 WELL_KNOWN_PARAMETERS.put(0x13, "Creation-date"); 177 WELL_KNOWN_PARAMETERS.put(0x14, "Modification-date"); 178 WELL_KNOWN_PARAMETERS.put(0x15, "Read-date"); 179 WELL_KNOWN_PARAMETERS.put(0x16, "Size"); 180 WELL_KNOWN_PARAMETERS.put(0x17, "Name"); 181 WELL_KNOWN_PARAMETERS.put(0x18, "Filename"); 182 WELL_KNOWN_PARAMETERS.put(0x19, "Start"); 183 WELL_KNOWN_PARAMETERS.put(0x1A, "Start-info"); 184 WELL_KNOWN_PARAMETERS.put(0x1B, "Comment"); 185 WELL_KNOWN_PARAMETERS.put(0x1C, "Domain"); 186 WELL_KNOWN_PARAMETERS.put(0x1D, "Path"); 187 188 } 189 190 final int WSP_DEFINED_SHORT_MIME_TYPE_COUNT = 85; 191 final int WSP_DEFINED_LONG_MIME_TYPE_COUNT = 40; 192 193 private static final byte WSP_STRING_TERMINATOR = 0x00; 194 private static final byte WSP_SHORT_INTEGER_MASK = (byte) 0x80; 195 private static final byte WSP_LENGTH_QUOTE = 0x1F; 196 private static final byte WSP_QUOTE = 0x22; 197 198 private static final short LONG_MIME_TYPE_OMA_DIRECTORY_XML = 0x0314; 199 private static final short LONG_MIME_TYPE_UNASSIGNED = 0x052C; 200 201 private static final byte SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE = 0x3F; 202 private static final byte SHORT_MIME_TYPE_UNASSIGNED = 0x60; 203 204 private static final String STRING_MIME_TYPE_ROLLOVER_CERTIFICATE 205 = "application/vnd.wap.rollover-certificate"; 206 207 private static final byte TYPED_PARAM_Q = 0x00; 208 private static final byte TYPED_PARAM_DOMAIN = 0x1C; 209 private static final byte PARAM_UNASSIGNED = 0x42; 210 private static final byte PARAM_NO_VALUE = 0x00; 211 private static final byte TYPED_PARAM_SEC = 0x11; 212 private static final byte TYPED_PARAM_MAC = 0x12; 213 214 public void testHasExpectedNumberOfShortMimeTypes() { 215 assertEquals(WSP_DEFINED_SHORT_MIME_TYPE_COUNT, WELL_KNOWN_SHORT_MIME_TYPES.size()); 216 } 217 218 public void testHasExpectedNumberOfLongMimeTypes() { 219 assertEquals(WSP_DEFINED_LONG_MIME_TYPE_COUNT, WELL_KNOWN_LONG_MIME_TYPES.size()); 220 } 221 222 public void testWellKnownShortIntegerMimeTypeValues() { 223 224 for (int value : Wap230WspContentTypeTest.WELL_KNOWN_SHORT_MIME_TYPES.keySet()) { 225 WspTypeDecoder unit = new WspTypeDecoder( 226 HexDump.toByteArray((byte) (value | WSP_SHORT_INTEGER_MASK))); 227 assertTrue(unit.decodeContentType(0)); 228 String mimeType = unit.getValueString(); 229 int wellKnownValue = (int) unit.getValue32(); 230 assertEquals(Wap230WspContentTypeTest.WELL_KNOWN_SHORT_MIME_TYPES.get(value), mimeType); 231 assertEquals(value, wellKnownValue); 232 assertEquals(1, unit.getDecodedDataLength()); 233 } 234 } 235 236 public void testWellKnownLongIntegerMimeTypeValues() { 237 byte headerLength = 3; 238 byte typeLength = 2; 239 for (int value : Wap230WspContentTypeTest.WELL_KNOWN_SHORT_MIME_TYPES.keySet()) { 240 byte[] data = new byte[10]; 241 data[0] = headerLength; 242 data[1] = typeLength; 243 data[2] = (byte) (value >> 8); 244 data[3] = (byte) (value & 0xFF); 245 WspTypeDecoder unit = new WspTypeDecoder(data); 246 assertTrue(unit.decodeContentType(0)); 247 String mimeType = unit.getValueString(); 248 int wellKnownValue = (int) unit.getValue32(); 249 assertEquals(Wap230WspContentTypeTest.WELL_KNOWN_SHORT_MIME_TYPES.get(value), mimeType); 250 assertEquals(value, wellKnownValue); 251 assertEquals(4, unit.getDecodedDataLength()); 252 } 253 } 254 255 public void testDecodeReturnsFalse_WhenOnlyAZeroBytePresent() { 256 257 ByteArrayOutputStream out = new ByteArrayOutputStream(); 258 out.write(0x00); 259 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 260 assertFalse(unit.decodeContentType(0)); 261 } 262 263 public void testConstrainedMediaExtensionMedia() throws Exception { 264 265 String testType = "application/wibble"; 266 ByteArrayOutputStream out = new ByteArrayOutputStream(); 267 out.write(testType.getBytes("US-ASCII")); 268 out.write(WSP_STRING_TERMINATOR); 269 270 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 271 assertTrue(unit.decodeContentType(0)); 272 String mimeType = unit.getValueString(); 273 assertEquals(testType, mimeType); 274 assertEquals(-1, unit.getValue32()); 275 assertEquals(19, unit.getDecodedDataLength()); 276 } 277 278 public void testGeneralFormShortLengthExtensionMedia() throws Exception { 279 280 String testType = "12345678901234567890123456789"; 281 ByteArrayOutputStream out = new ByteArrayOutputStream(); 282 out.write(testType.length() + 1); 283 out.write(testType.getBytes("US-ASCII")); 284 out.write(WSP_STRING_TERMINATOR); 285 286 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 287 assertTrue(unit.decodeContentType(0)); 288 289 String mimeType = unit.getValueString(); 290 assertEquals(testType, mimeType); 291 assertEquals(-1, unit.getValue32()); 292 assertEquals(31, unit.getDecodedDataLength()); 293 } 294 295 public void testGeneralFormShortLengthWellKnownShortInteger() { 296 297 ByteArrayOutputStream out = new ByteArrayOutputStream(); 298 out.write(0x01); 299 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 300 301 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 302 assertTrue(unit.decodeContentType(0)); 303 304 String mimeType = unit.getValueString(); 305 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 306 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 307 assertEquals(2, unit.getDecodedDataLength()); 308 309 } 310 311 public void testGeneralFormShortLengthWellKnownShortIntegerWithUnknownValue() { 312 313 ByteArrayOutputStream out = new ByteArrayOutputStream(); 314 out.write(0x01); 315 out.write(SHORT_MIME_TYPE_UNASSIGNED | WSP_SHORT_INTEGER_MASK); 316 317 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 318 assertTrue(unit.decodeContentType(0)); 319 320 String mimeType = unit.getValueString(); 321 assertNull(mimeType); 322 assertEquals(SHORT_MIME_TYPE_UNASSIGNED, unit.getValue32()); 323 assertEquals(2, unit.getDecodedDataLength()); 324 325 } 326 327 public void testGeneralFormShortLengthWellKnownLongInteger() { 328 329 ByteArrayOutputStream out = new ByteArrayOutputStream(); 330 331 out.write(0x03); // header length 332 out.write(0x02); // type length (2 octets) 333 out.write(LONG_MIME_TYPE_OMA_DIRECTORY_XML >> 8); 334 out.write(LONG_MIME_TYPE_OMA_DIRECTORY_XML & 0xFF); 335 336 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 337 assertTrue(unit.decodeContentType(0)); 338 339 String mimeType = unit.getValueString(); 340 341 assertEquals("application/oma-directory+xml", mimeType); 342 assertEquals(LONG_MIME_TYPE_OMA_DIRECTORY_XML, unit.getValue32()); 343 assertEquals(4, unit.getDecodedDataLength()); 344 } 345 346 public void testGeneralFormShortLengthWellKnownLongIntegerWithUnknownValue() { 347 348 ByteArrayOutputStream out = new ByteArrayOutputStream(); 349 350 out.write(0x03); // Value-length, short-length 351 out.write(0x02); // long-integer length (2 octets) 352 out.write(LONG_MIME_TYPE_UNASSIGNED >> 8); 353 out.write(LONG_MIME_TYPE_UNASSIGNED & 0xFF); 354 355 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 356 assertTrue(unit.decodeContentType(0)); 357 358 String mimeType = unit.getValueString(); 359 360 assertNull(mimeType); 361 assertEquals(LONG_MIME_TYPE_UNASSIGNED, unit.getValue32()); 362 assertEquals(4, unit.getDecodedDataLength()); 363 364 } 365 366 public void testGeneralFormLengthQuoteWellKnownShortInteger() { 367 368 ByteArrayOutputStream out = new ByteArrayOutputStream(); 369 370 out.write(WSP_LENGTH_QUOTE); 371 out.write(0x01); // Length as UINTVAR 372 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 373 374 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 375 assertTrue(unit.decodeContentType(0)); 376 377 String mimeType = unit.getValueString(); 378 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 379 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 380 assertEquals(3, unit.getDecodedDataLength()); 381 382 } 383 384 public void testGeneralFormLengthQuoteWellKnownShortIntegerWithUnknownValue() { 385 386 ByteArrayOutputStream out = new ByteArrayOutputStream(); 387 388 out.write(WSP_LENGTH_QUOTE); 389 out.write(0x01); // Length as UINTVAR 390 out.write(SHORT_MIME_TYPE_UNASSIGNED | WSP_SHORT_INTEGER_MASK); 391 392 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 393 assertTrue(unit.decodeContentType(0)); 394 395 String mimeType = unit.getValueString(); 396 assertNull(mimeType); 397 assertEquals(SHORT_MIME_TYPE_UNASSIGNED, unit.getValue32()); 398 assertEquals(3, unit.getDecodedDataLength()); 399 } 400 401 public void testGeneralFormLengthQuoteWellKnownLongInteger() { 402 403 ByteArrayOutputStream out = new ByteArrayOutputStream(); 404 405 out.write(WSP_LENGTH_QUOTE); 406 out.write(0x03); // Length as UINTVAR 407 out.write(0x02); // long-integer length (2 octets) 408 out.write(LONG_MIME_TYPE_OMA_DIRECTORY_XML >> 8); 409 out.write(LONG_MIME_TYPE_OMA_DIRECTORY_XML & 0xFF); 410 411 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 412 assertTrue(unit.decodeContentType(0)); 413 414 String mimeType = unit.getValueString(); 415 416 assertEquals("application/oma-directory+xml", mimeType); 417 assertEquals(LONG_MIME_TYPE_OMA_DIRECTORY_XML, unit.getValue32()); 418 assertEquals(5, unit.getDecodedDataLength()); 419 420 } 421 422 public void testGeneralFormLengthQuoteWellKnownLongIntegerWithUnknownValue() { 423 424 ByteArrayOutputStream out = new ByteArrayOutputStream(); 425 426 out.write(WSP_LENGTH_QUOTE); 427 out.write(0x03); // Length as UINTVAR 428 out.write(0x02); // long-integer length (2 octets) 429 out.write(LONG_MIME_TYPE_UNASSIGNED >> 8); 430 out.write(LONG_MIME_TYPE_UNASSIGNED & 0xFF); 431 432 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 433 assertTrue(unit.decodeContentType(0)); 434 435 String mimeType = unit.getValueString(); 436 437 assertNull(mimeType); 438 assertEquals(LONG_MIME_TYPE_UNASSIGNED, unit.getValue32()); 439 assertEquals(5, unit.getDecodedDataLength()); 440 441 } 442 443 public void testGeneralFormLengthQuoteExtensionMedia() throws Exception { 444 445 String testType = "application/wibble"; 446 ByteArrayOutputStream out = new ByteArrayOutputStream(); 447 448 out.write(WSP_LENGTH_QUOTE); 449 out.write(testType.length() + 1); // Length as UINTVAR 450 451 out.write(testType.getBytes("US-ASCII")); 452 out.write(WSP_STRING_TERMINATOR); 453 454 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 455 assertTrue(unit.decodeContentType(0)); 456 457 String mimeType = unit.getValueString(); 458 459 assertEquals(testType, mimeType); 460 assertEquals(-1, unit.getValue32()); 461 assertEquals(21, unit.getDecodedDataLength()); 462 463 } 464 465 public void testGeneralFormLengthQuoteExtensionMediaWithNiceLongMimeType() throws Exception { 466 467 String testType = 468 "01234567890123456789012345678901234567890123456789012345678901234567890123456789" 469 +"01234567890123456789012345678901234567890123456789012345678901234567890123456789"; 470 ByteArrayOutputStream out = new ByteArrayOutputStream(); 471 472 out.write(WSP_LENGTH_QUOTE); 473 out.write(0x81); // Length as UINTVAR (161 decimal, 0xA1), 2 bytes 474 out.write(0x21); 475 476 out.write(testType.getBytes("US-ASCII")); 477 out.write(WSP_STRING_TERMINATOR); 478 479 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 480 assertTrue(unit.decodeContentType(0)); 481 482 String mimeType = unit.getValueString(); 483 484 assertEquals(testType, mimeType); 485 assertEquals(-1, unit.getValue32()); 486 assertEquals(164, unit.getDecodedDataLength()); 487 488 } 489 490 public void testConstrainedMediaExtensionMediaWithSpace() throws Exception { 491 492 String testType = " application/wibble"; 493 ByteArrayOutputStream out = new ByteArrayOutputStream(); 494 out.write(testType.getBytes("US-ASCII")); 495 out.write(WSP_STRING_TERMINATOR); 496 497 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 498 assertTrue(unit.decodeContentType(0)); 499 500 String mimeType = unit.getValueString(); 501 502 assertEquals(testType, mimeType); 503 assertEquals(-1, unit.getValue32()); 504 assertEquals(20, unit.getDecodedDataLength()); 505 506 } 507 508 public void testTypedParamWellKnownShortIntegerNoValue() { 509 510 ByteArrayOutputStream out = new ByteArrayOutputStream(); 511 out.write(0x03); // Value-length, short-length 512 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 513 out.write(TYPED_PARAM_DOMAIN | WSP_SHORT_INTEGER_MASK); 514 out.write(PARAM_NO_VALUE); 515 516 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 517 assertTrue(unit.decodeContentType(0)); 518 519 String mimeType = unit.getValueString(); 520 521 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 522 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 523 524 assertEquals(4, unit.getDecodedDataLength()); 525 526 Map<String, String> params = unit.getContentParameters(); 527 assertEquals(null, params.get("Domain")); 528 529 } 530 531 public void testTypedParamWellKnownShortIntegerTokenText() throws Exception { 532 533 ByteArrayOutputStream out = new ByteArrayOutputStream(); 534 out.write(0x14); // Value-length, short-length 535 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 536 out.write(TYPED_PARAM_DOMAIN | WSP_SHORT_INTEGER_MASK); 537 out.write("wdstechnology.com".getBytes("US-ASCII")); 538 out.write(WSP_STRING_TERMINATOR); 539 540 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 541 assertTrue(unit.decodeContentType(0)); 542 543 String mimeType = unit.getValueString(); 544 545 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 546 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 547 548 assertEquals(out.toByteArray().length, unit.getDecodedDataLength()); 549 550 Map<String, String> params = unit.getContentParameters(); 551 assertEquals("wdstechnology.com", params.get("Domain")); 552 553 } 554 555 public void testTypedParamWellKnownLongIntegerTokenText() throws Exception { 556 557 ByteArrayOutputStream out = new ByteArrayOutputStream(); 558 out.write(0x15); 559 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 560 out.write(0x01); 561 out.write(TYPED_PARAM_DOMAIN); 562 out.write("wdstechnology.com".getBytes("US-ASCII")); 563 out.write(WSP_STRING_TERMINATOR); 564 565 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 566 assertTrue(unit.decodeContentType(0)); 567 568 String mimeType = unit.getValueString(); 569 570 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 571 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 572 573 assertEquals(22, unit.getDecodedDataLength()); 574 575 Map<String, String> params = unit.getContentParameters(); 576 assertEquals("wdstechnology.com", params.get("Domain")); 577 578 } 579 580 public void testTypedParamWellKnownShortIntegerQuotedText() throws Exception { 581 582 ByteArrayOutputStream out = new ByteArrayOutputStream(); 583 out.write(0x15); 584 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 585 out.write(TYPED_PARAM_DOMAIN | WSP_SHORT_INTEGER_MASK); 586 out.write(WSP_QUOTE); 587 out.write("wdstechnology.com".getBytes("US-ASCII")); 588 out.write(WSP_STRING_TERMINATOR); 589 590 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 591 assertTrue(unit.decodeContentType(0)); 592 593 String mimeType = unit.getValueString(); 594 595 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 596 assertEquals(0x3F, unit.getValue32()); 597 assertEquals(22, unit.getDecodedDataLength()); 598 599 Map<String, String> params = unit.getContentParameters(); 600 assertEquals("wdstechnology.com", params.get("Domain")); 601 602 } 603 604 public void testTypedParamWellKnownShortIntegerCompactIntegerValue() { 605 606 ByteArrayOutputStream out = new ByteArrayOutputStream(); 607 out.write(0x3); 608 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 609 out.write(TYPED_PARAM_SEC | WSP_SHORT_INTEGER_MASK); 610 out.write(0x01 | WSP_SHORT_INTEGER_MASK); 611 612 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 613 assertTrue(unit.decodeContentType(0)); 614 615 String mimeType = unit.getValueString(); 616 617 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 618 assertEquals(0x3F, unit.getValue32()); 619 assertEquals(4, unit.getDecodedDataLength()); 620 621 Map<String, String> params = unit.getContentParameters(); 622 assertEquals("1", params.get("SEC")); 623 624 } 625 626 public void testTypedParamWellKnownShortIntegerCompactIntegerValue_0() { 627 ByteArrayOutputStream out = new ByteArrayOutputStream(); 628 out.write(0x3); 629 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 630 out.write(TYPED_PARAM_SEC | WSP_SHORT_INTEGER_MASK); 631 out.write(0x00 | WSP_SHORT_INTEGER_MASK); 632 633 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 634 assertTrue(unit.decodeContentType(0)); 635 636 String mimeType = unit.getValueString(); 637 638 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 639 assertEquals(0x3F, unit.getValue32()); 640 assertEquals(4, unit.getDecodedDataLength()); 641 642 Map<String, String> params = unit.getContentParameters(); 643 assertEquals("0", params.get("SEC")); 644 } 645 646 public void testTypedParamWellKnownShortIntegerMultipleParameters() throws Exception { 647 648 ByteArrayOutputStream out = new ByteArrayOutputStream(); 649 out.write(0x0B); 650 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 651 out.write(TYPED_PARAM_SEC | WSP_SHORT_INTEGER_MASK); 652 out.write(0x01 | WSP_SHORT_INTEGER_MASK); 653 out.write(TYPED_PARAM_MAC | WSP_SHORT_INTEGER_MASK); 654 out.write(WSP_QUOTE); 655 out.write("imapc".getBytes("US-ASCII")); 656 out.write(WSP_STRING_TERMINATOR); 657 658 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 659 assertTrue(unit.decodeContentType(0)); 660 661 String mimeType = unit.getValueString(); 662 663 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 664 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 665 assertEquals(12, unit.getDecodedDataLength()); 666 667 Map<String, String> params = unit.getContentParameters(); 668 assertEquals("1", params.get("SEC")); 669 assertEquals("imapc", params.get("MAC")); 670 } 671 672 public void testUntypedParamIntegerValueShortInteger() throws Exception { 673 ByteArrayOutputStream out = new ByteArrayOutputStream(); 674 out.write(0x0A); 675 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 676 out.write("MYPARAM".getBytes("US-ASCII")); 677 out.write(WSP_STRING_TERMINATOR); // EOS 678 out.write(0x45 | WSP_SHORT_INTEGER_MASK); 679 680 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 681 assertTrue(unit.decodeContentType(0)); 682 683 String mimeType = unit.getValueString(); 684 685 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 686 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 687 assertEquals(11, unit.getDecodedDataLength()); 688 689 Map<String, String> params = unit.getContentParameters(); 690 assertEquals("69", params.get("MYPARAM")); 691 } 692 693 public void testUntypedParamIntegerValueLongInteger() throws Exception { 694 ByteArrayOutputStream out = new ByteArrayOutputStream(); 695 out.write(0x0C); 696 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 697 out.write("MYPARAM".getBytes("US-ASCII")); 698 out.write(WSP_STRING_TERMINATOR); 699 out.write(0x02); // Short Length 700 out.write(0x42); // Long Integer byte 1 701 out.write(0x69); // Long Integer byte 2 702 703 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 704 assertTrue(unit.decodeContentType(0)); 705 706 String mimeType = unit.getValueString(); 707 708 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 709 assertEquals(0x3F, unit.getValue32()); 710 assertEquals(13, unit.getDecodedDataLength()); 711 712 Map<String, String> params = unit.getContentParameters(); 713 assertEquals("17001", params.get("MYPARAM")); 714 } 715 716 public void testUntypedParamTextNoValue() throws Exception { 717 ByteArrayOutputStream out = new ByteArrayOutputStream(); 718 out.write(0x0A); 719 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 720 out.write("MYPARAM".getBytes("US-ASCII")); 721 out.write(WSP_STRING_TERMINATOR); 722 out.write(PARAM_NO_VALUE); 723 724 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 725 assertTrue(unit.decodeContentType(0)); 726 String mimeType = unit.getValueString(); 727 728 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 729 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 730 assertEquals(11, unit.getDecodedDataLength()); 731 732 Map<String, String> params = unit.getContentParameters(); 733 assertEquals(null, params.get("MYPARAM")); 734 735 } 736 737 public void testUntypedParamTextTokenText() throws Exception { 738 ByteArrayOutputStream out = new ByteArrayOutputStream(); 739 out.write(0x11); 740 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 741 out.write("MYPARAM".getBytes("US-ASCII")); 742 out.write(WSP_STRING_TERMINATOR); 743 out.write("myvalue".getBytes("US-ASCII")); 744 out.write(WSP_STRING_TERMINATOR); 745 746 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 747 assertTrue(unit.decodeContentType(0)); 748 String mimeType = unit.getValueString(); 749 750 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 751 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 752 assertEquals(18, unit.getDecodedDataLength()); 753 754 Map<String, String> params = unit.getContentParameters(); 755 assertEquals("myvalue", params.get("MYPARAM")); 756 } 757 758 public void testUntypedParamTextQuotedString() throws Exception { 759 ByteArrayOutputStream out = new ByteArrayOutputStream(); 760 out.write(0x11); 761 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 762 out.write("MYPARAM".getBytes("US-ASCII")); 763 out.write(WSP_STRING_TERMINATOR); 764 out.write(WSP_QUOTE); 765 out.write("myvalue".getBytes("US-ASCII")); 766 out.write(WSP_STRING_TERMINATOR); 767 768 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 769 assertTrue(unit.decodeContentType(0)); 770 String mimeType = unit.getValueString(); 771 772 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 773 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 774 assertEquals(19, unit.getDecodedDataLength()); 775 776 Map<String, String> params = unit.getContentParameters(); 777 assertEquals("myvalue", params.get("MYPARAM")); 778 779 } 780 781 public void testDecodesReturnsFalse_ForParamWithMissingValue() throws Exception { 782 ByteArrayOutputStream out = new ByteArrayOutputStream(); 783 out.write(0x09); 784 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 785 out.write("MYPARAM".getBytes("US-ASCII")); 786 out.write(WSP_STRING_TERMINATOR); 787 788 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 789 assertFalse(unit.decodeContentType(0)); 790 } 791 792 public void testTypedParamTextQValue() { 793 ByteArrayOutputStream out = new ByteArrayOutputStream(); 794 out.write(0x04); 795 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 796 out.write(TYPED_PARAM_Q); 797 out.write(0x83); // Q value byte 1 798 out.write(0x31); // Q value byte 2 799 800 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 801 assertTrue(unit.decodeContentType(0)); 802 String mimeType = unit.getValueString(); 803 804 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 805 assertEquals(0x3F, unit.getValue32()); 806 assertEquals(5, unit.getDecodedDataLength()); 807 808 Map<String, String> params = unit.getContentParameters(); 809 assertEquals("433", params.get("Q")); 810 811 } 812 813 public void testTypedParamUnassignedWellKnownShortIntegerTokenText() throws Exception { 814 815 ByteArrayOutputStream out = new ByteArrayOutputStream(); 816 out.write(0x14); 817 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 818 out.write(PARAM_UNASSIGNED | WSP_SHORT_INTEGER_MASK); 819 out.write("wdstechnology.com".getBytes("US-ASCII")); 820 out.write(WSP_STRING_TERMINATOR); 821 822 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 823 assertTrue(unit.decodeContentType(0)); 824 825 String mimeType = unit.getValueString(); 826 827 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 828 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 829 830 assertEquals(21, unit.getDecodedDataLength()); 831 832 Map<String, String> params = unit.getContentParameters(); 833 assertEquals("wdstechnology.com", params.get("unassigned/0x42")); 834 835 } 836 837 public void testTypedParamUnassignedWellKnownLongIntegerTokenText() throws Exception { 838 839 ByteArrayOutputStream out = new ByteArrayOutputStream(); 840 out.write(0x15); 841 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 842 out.write(0x01); // Short-length of well-known parameter token 843 out.write(PARAM_UNASSIGNED); 844 out.write("wdstechnology.com".getBytes("US-ASCII")); 845 out.write(WSP_STRING_TERMINATOR); 846 847 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 848 assertTrue(unit.decodeContentType(0)); 849 850 String mimeType = unit.getValueString(); 851 852 assertEquals(STRING_MIME_TYPE_ROLLOVER_CERTIFICATE, mimeType); 853 assertEquals(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE, unit.getValue32()); 854 855 assertEquals(22, unit.getDecodedDataLength()); 856 857 Map<String, String> params = unit.getContentParameters(); 858 assertEquals("wdstechnology.com", params.get("unassigned/0x42")); 859 } 860 861 public void testDecodesReturnsFalse_WhenParamValueNotTerminated() throws Exception { 862 863 ByteArrayOutputStream out = new ByteArrayOutputStream(); 864 out.write(0x15); 865 out.write(SHORT_MIME_TYPE_ROLLOVER_CERTIFICATE | WSP_SHORT_INTEGER_MASK); 866 out.write(0x01); 867 out.write(PARAM_UNASSIGNED); 868 out.write("wdstechnology.com".getBytes("US-ASCII")); 869 870 WspTypeDecoder unit = new WspTypeDecoder(out.toByteArray()); 871 assertFalse(unit.decodeContentType(0)); 872 } 873 } 874