michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let MMS = {}; michael@0: subscriptLoader.loadSubScript("resource://gre/modules/MmsPduHelper.jsm", MMS); michael@0: MMS.debug = do_print; michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: // michael@0: // Test target: BooleanValue michael@0: // michael@0: michael@0: //// BooleanValue.decode //// michael@0: michael@0: add_test(function test_BooleanValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i == 128) { michael@0: wsp_decode_test(MMS.BooleanValue, [128], true); michael@0: } else if (i == 129) { michael@0: wsp_decode_test(MMS.BooleanValue, [129], false); michael@0: } else { michael@0: wsp_decode_test(MMS.BooleanValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// BooleanValue.encode //// michael@0: michael@0: add_test(function test_BooleanValue_encode() { michael@0: wsp_encode_test(MMS.BooleanValue, true, [128]); michael@0: wsp_encode_test(MMS.BooleanValue, false, [129]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: Address michael@0: // michael@0: michael@0: //// Address.decode //// michael@0: michael@0: add_test(function test_Address_decode() { michael@0: // Test for PLMN address michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("+123.456-789/TYPE=PLMN"), michael@0: {address: "+123.456-789", type: "PLMN"}); michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("123456789/TYPE=PLMN"), michael@0: {address: "123456789", type: "PLMN"}); michael@0: // Test for IPv4 michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("1.2.3.4/TYPE=IPv4"), michael@0: {address: "1.2.3.4", type: "IPv4"}); michael@0: // Test for IPv6 michael@0: wsp_decode_test(MMS.Address, michael@0: strToCharCodeArray("1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000/TYPE=IPv6"), michael@0: {address: "1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000", type: "IPv6"} michael@0: ); michael@0: // Test for other device-address michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("+H-e.l%l_o/TYPE=W0r1d_"), michael@0: {address: "+H-e.l%l_o", type: "W0r1d_"}); michael@0: // Test for num-shortcode michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("+123"), michael@0: {address: "+123", type: "num"}); michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("*123"), michael@0: {address: "*123", type: "num"}); michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("#123"), michael@0: {address: "#123", type: "num"}); michael@0: // Test for alphanum-shortcode michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("H0wD0Y0uTurnTh1s0n"), michael@0: {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"}); michael@0: // Test for email address michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("Joe User "), michael@0: {address: "Joe User ", type: "email"}); michael@0: // Test for invalid address michael@0: wsp_decode_test(MMS.Address, strToCharCodeArray("@@@@@"), michael@0: null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Address.encode //// michael@0: michael@0: add_test(function test_Address_encode() { michael@0: // Test for PLMN address michael@0: wsp_encode_test(MMS.Address, {address: "+123.456-789", type: "PLMN"}, michael@0: strToCharCodeArray("+123.456-789/TYPE=PLMN")); michael@0: wsp_encode_test(MMS.Address, {address: "123456789", type: "PLMN"}, michael@0: strToCharCodeArray("123456789/TYPE=PLMN")); michael@0: // Test for IPv4 michael@0: wsp_encode_test(MMS.Address, {address: "1.2.3.4", type: "IPv4"}, michael@0: strToCharCodeArray("1.2.3.4/TYPE=IPv4")); michael@0: // Test for IPv6 michael@0: wsp_encode_test(MMS.Address, michael@0: {address: "1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000", type: "IPv6"}, michael@0: strToCharCodeArray("1111:AAAA:bbbb:CdEf:1ABC:2cde:3Def:0000/TYPE=IPv6") michael@0: ); michael@0: // Test for other device-address michael@0: wsp_encode_test(MMS.Address, {address: "+H-e.l%l_o", type: "W0r1d_"}, michael@0: strToCharCodeArray("+H-e.l%l_o/TYPE=W0r1d_")); michael@0: // Test for num-shortcode michael@0: wsp_encode_test(MMS.Address, {address: "+123", type: "num"}, michael@0: strToCharCodeArray("+123")); michael@0: wsp_encode_test(MMS.Address, {address: "*123", type: "num"}, michael@0: strToCharCodeArray("*123")); michael@0: wsp_encode_test(MMS.Address, {address: "#123", type: "num"}, michael@0: strToCharCodeArray("#123")); michael@0: // Test for alphanum-shortcode michael@0: wsp_encode_test(MMS.Address, {address: "H0wD0Y0uTurnTh1s0n", type: "alphanum"}, michael@0: strToCharCodeArray("H0wD0Y0uTurnTh1s0n")); michael@0: // Test for email address michael@0: wsp_encode_test(MMS.Address, {address: "Joe User ", type: "email"}, michael@0: strToCharCodeArray("Joe User ")); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: HeaderField michael@0: // michael@0: michael@0: //// HeaderField.decode //// michael@0: michael@0: add_test(function test_HeaderField_decode() { michael@0: wsp_decode_test(MMS.HeaderField, [65, 0, 66, 0], {name: "a", value: "B"}); michael@0: wsp_decode_test(MMS.HeaderField, [0x80 | 0x27, 128], michael@0: {name: "x-mms-stored", value: true}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// HeaderField.encode //// michael@0: michael@0: add_test(function test_HeaderField_encode() { michael@0: // Test for MmsHeader michael@0: wsp_encode_test(MMS.HeaderField, {name: "X-Mms-Message-Type", michael@0: value: MMS_PDU_TYPE_SEND_REQ}, michael@0: [0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]); michael@0: // Test for ApplicationHeader michael@0: wsp_encode_test(MMS.HeaderField, {name: "a", value: "B"}, [97, 0, 66, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: MmsHeader michael@0: // michael@0: michael@0: //// MmsHeader.decode //// michael@0: michael@0: add_test(function test_MmsHeader_decode() { michael@0: wsp_decode_test(MMS.MmsHeader, [0x80 | 0x00], null, "NotWellKnownEncodingError"); michael@0: wsp_decode_test(MMS.MmsHeader, [0x80 | 0x27, 128], michael@0: {name: "x-mms-stored", value: true}); michael@0: wsp_decode_test(MMS.MmsHeader, [0x80 | 0x27, 255], null); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// MmsHeader.encode //// michael@0: michael@0: add_test(function test_MmsHeader_encode() { michael@0: // Test for empty header name: michael@0: wsp_encode_test(MMS.MmsHeader, {name: undefined, value: null}, null, "CodeError"); michael@0: wsp_encode_test(MMS.MmsHeader, {name: null, value: null}, null, "CodeError"); michael@0: wsp_encode_test(MMS.MmsHeader, {name: "", value: null}, null, "CodeError"); michael@0: // Test for non-well-known header name: michael@0: wsp_encode_test(MMS.MmsHeader, {name: "X-No-Such-Field", value: null}, michael@0: null, "NotWellKnownEncodingError"); michael@0: // Test for normal header michael@0: wsp_encode_test(MMS.MmsHeader, {name: "X-Mms-Message-Type", michael@0: value: MMS_PDU_TYPE_SEND_REQ}, michael@0: [0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: CancelStatusValue michael@0: // michael@0: michael@0: //// CancelStatusValue.decode //// michael@0: michael@0: add_test(function test_CancelStatusValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 129)) { michael@0: wsp_decode_test(MMS.CancelStatusValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.CancelStatusValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// CancelStatusValue.encode //// michael@0: michael@0: add_test(function test_CancelStatusValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 129)) { michael@0: wsp_encode_test(MMS.CancelStatusValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.CancelStatusValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ContentClassValue michael@0: // michael@0: michael@0: //// ContentClassValue.decode //// michael@0: michael@0: add_test(function test_ContentClassValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 135)) { michael@0: wsp_decode_test(MMS.ContentClassValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.ContentClassValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ContentClassValue.encode //// michael@0: michael@0: add_test(function test_ContentClassValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 135)) { michael@0: wsp_encode_test(MMS.ContentClassValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.ContentClassValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ContentLocationValue michael@0: // michael@0: michael@0: //// ContentLocationValue.decode //// michael@0: michael@0: add_test(function test_ContentLocationValue_decode() { michael@0: // Test for MMS_PDU_TYPE_MBOX_DELETE_CONF & MMS_PDU_TYPE_DELETE_CONF michael@0: function test(type, statusCount, exception) { michael@0: function decode(data) { michael@0: let options = {}; michael@0: if (type) { michael@0: options["x-mms-message-type"] = type; michael@0: } michael@0: return MMS.ContentLocationValue.decode(data, options); michael@0: } michael@0: michael@0: let uri = "http://no.such.com/path"; michael@0: michael@0: let data = strToCharCodeArray(uri); michael@0: if (statusCount != null) { michael@0: data = [data.length + 1, statusCount | 0x80].concat(data); michael@0: } michael@0: michael@0: let expected; michael@0: if (!exception) { michael@0: expected = {}; michael@0: if (statusCount != null) { michael@0: expected.statusCount = statusCount; michael@0: } michael@0: expected.uri = uri; michael@0: } michael@0: michael@0: do_print("data = " + JSON.stringify(data)); michael@0: wsp_decode_test_ex(decode, data, expected, exception); michael@0: } michael@0: michael@0: test(null, null, "FatalCodeError"); michael@0: for (let type = MMS_PDU_TYPE_SEND_REQ; type <= MMS_PDU_TYPE_CANCEL_CONF; type++) { michael@0: if ((type == MMS_PDU_TYPE_MBOX_DELETE_CONF) michael@0: || (type == MMS_PDU_TYPE_DELETE_CONF)) { michael@0: test(type, 1, null); michael@0: } else { michael@0: test(type, null, null); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ElementDescriptorValue michael@0: // michael@0: michael@0: //// ElementDescriptorValue.decode //// michael@0: michael@0: add_test(function test_ElementDescriptorValue_decode() { michael@0: wsp_decode_test(MMS.ElementDescriptorValue, [2, 97, 0], {contentReference: "a"}); michael@0: wsp_decode_test(MMS.ElementDescriptorValue, [4, 97, 0, 0x80 | 0x02, 0x80], michael@0: {contentReference: "a", params: {type: 0}}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: Parameter michael@0: // michael@0: michael@0: //// Parameter.decodeParameterName //// michael@0: michael@0: add_test(function test_Parameter_decodeParameterName() { michael@0: wsp_decode_test_ex(function(data) { michael@0: return MMS.Parameter.decodeParameterName(data); michael@0: }, [0x80 | 0x02], "type" michael@0: ); michael@0: wsp_decode_test_ex(function(data) { michael@0: return MMS.Parameter.decodeParameterName(data); michael@0: }, strToCharCodeArray("type"), "type" michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.decode //// michael@0: michael@0: add_test(function test_Parameter_decode() { michael@0: wsp_decode_test(MMS.Parameter, [0x80 | 0x02, 0x80 | 0x00], {name: "type", value: 0}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.decodeMultiple //// michael@0: michael@0: add_test(function test_Parameter_decodeMultiple() { michael@0: // FIXME: The following test case falls because Parameter-value decoding of michael@0: // "type" parameters utilies WSP.ConstrainedEncoding, which in turn michael@0: // utilies WSP.TextString, and TextString is not matual exclusive to michael@0: // each other. michael@0: //wsp_decode_test_ex(function(data) { michael@0: // return MMS.Parameter.decodeMultiple(data, data.array.length); michael@0: // }, [0x80 | 0x02, 0x80 | 0x00].concat(strToCharCodeArray("good")).concat([0x80 | 0x01]), michael@0: // {type: 0, good: 1} michael@0: //); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.encode //// michael@0: michael@0: add_test(function test_Parameter_encode() { michael@0: // Test for invalid parameter value michael@0: wsp_encode_test(MMS.Parameter, null, null, "CodeError"); michael@0: wsp_encode_test(MMS.Parameter, undefined, null, "CodeError"); michael@0: wsp_encode_test(MMS.Parameter, {}, null, "CodeError"); michael@0: // Test for case-insensitive parameter name michael@0: wsp_encode_test(MMS.Parameter, {name: "TYPE", value: 0}, [130, 128]); michael@0: wsp_encode_test(MMS.Parameter, {name: "type", value: 0}, [130, 128]); michael@0: // Test for non-well-known parameter name michael@0: wsp_encode_test(MMS.Parameter, {name: "name", value: 0}, [110, 97, 109, 101, 0, 128]); michael@0: // Test for constrained encoding value michael@0: wsp_encode_test(MMS.Parameter, {name: "type", value: "0"}, [130, 48, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: EncodedStringValue michael@0: // michael@0: michael@0: //// EncodedStringValue.decode //// michael@0: michael@0: add_test(function test_EncodedStringValue_decode() { michael@0: // Test for normal TextString michael@0: wsp_decode_test(MMS.EncodedStringValue, strToCharCodeArray("Hello"), "Hello"); michael@0: // Test for non-well-known charset michael@0: wsp_decode_test(MMS.EncodedStringValue, [1, 0x80], null, "NotWellKnownEncodingError"); michael@0: // Test for utf-8 michael@0: let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) { michael@0: // "Mozilla" in full width. michael@0: let str = "\uff2d\uff4f\uff5a\uff49\uff4c\uff4c\uff41"; michael@0: michael@0: let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] michael@0: .createInstance(Ci.nsIScriptableUnicodeConverter); michael@0: conv.charset = entry.converter; michael@0: michael@0: let raw = conv.convertToByteArray(str).concat([0]); michael@0: wsp_decode_test(MMS.EncodedStringValue, michael@0: [raw.length + 2, 0x80 | entry.number, 127].concat(raw), str); michael@0: } michael@0: michael@0: let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-16"]) { michael@0: // "Mozilla" in full width. michael@0: let str = "\u004d\u006F\u007A\u0069\u006C\u006C\u0061"; michael@0: michael@0: let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] michael@0: .createInstance(Ci.nsIScriptableUnicodeConverter); michael@0: conv.charset = entry.converter; michael@0: michael@0: let raw = conv.convertToByteArray(str).concat([0]); michael@0: wsp_decode_test(MMS.EncodedStringValue, michael@0: [raw.length + 3, 2, 3, 247].concat(raw), str); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// EncodedStringValue.encode //// michael@0: michael@0: add_test(function test_EncodedStringValue_encode() { michael@0: // Test for normal TextString michael@0: wsp_encode_test(MMS.EncodedStringValue, "Hello", strToCharCodeArray("Hello")); michael@0: michael@0: // Test for utf-8 michael@0: let (entry = MMS.WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) { michael@0: // "Mozilla" in full width. michael@0: let str = "\uff2d\uff4f\uff5a\uff49\uff4c\uff4c\uff41"; michael@0: michael@0: let conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] michael@0: .createInstance(Ci.nsIScriptableUnicodeConverter); michael@0: conv.charset = entry.converter; michael@0: michael@0: let raw = conv.convertToByteArray(str).concat([0]); michael@0: wsp_encode_test(MMS.EncodedStringValue, str, michael@0: [raw.length + 2, 0x80 | entry.number, 127].concat(raw)); michael@0: michael@0: // MMS.EncodedStringValue encodes non us-ascii characters (128 ~ 255) michael@0: // (e.g., 'Ñ' or 'ü') by the utf-8 encoding. Otherwise, for us-ascii michael@0: // characters (0 ~ 127), still use the normal TextString encoding. michael@0: michael@0: // "Ñü" in full width. michael@0: str = "\u00d1\u00fc"; michael@0: raw = conv.convertToByteArray(str).concat([0]); michael@0: wsp_encode_test(MMS.EncodedStringValue, str, michael@0: [raw.length + 2, 0x80 | entry.number, 127].concat(raw)); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ExpiryValue michael@0: // michael@0: michael@0: //// ExpiryValue.decode //// michael@0: michael@0: add_test(function test_ExpiryValue_decode() { michael@0: // Test for Absolute-token Date-value michael@0: wsp_decode_test(MMS.ExpiryValue, [3, 128, 1, 0x80], new Date(0x80 * 1000)); michael@0: // Test for Relative-token Delta-seconds-value michael@0: wsp_decode_test(MMS.ExpiryValue, [2, 129, 0x80], 0); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ExpiryValue.encode //// michael@0: michael@0: add_test(function test_ExpiryValue_encode() { michael@0: // Test for Absolute-token Date-value michael@0: wsp_encode_test(MMS.ExpiryValue, new Date(0x80 * 1000), [3, 128, 1, 0x80]); michael@0: // Test for Relative-token Delta-seconds-value michael@0: wsp_encode_test(MMS.ExpiryValue, 0, [2, 129, 0x80]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: PreviouslySentByValue michael@0: // michael@0: michael@0: //// PreviouslySentByValue.decode //// michael@0: michael@0: add_test(function test_PreviouslySentByValue_decode() { michael@0: wsp_decode_test(MMS.PreviouslySentByValue, [3, 0x80 | 0x03, 65, 0], michael@0: {forwardedCount: 3, originator: {address: "A", michael@0: type: "alphanum"}}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: PreviouslySentDateValue michael@0: // michael@0: michael@0: //// PreviouslySentDateValue.decode //// michael@0: michael@0: add_test(function test_PreviouslySentDateValue_decode() { michael@0: wsp_decode_test(MMS.PreviouslySentDateValue, [3, 0x80 | 0x03, 1, 4], michael@0: {forwardedCount: 3, timestamp: new Date(4 * 1000)}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: FromValue michael@0: // michael@0: michael@0: //// FromValue.decode //// michael@0: michael@0: add_test(function test_FromValue_decode() { michael@0: // Test for Insert-address-token: michael@0: wsp_decode_test(MMS.FromValue, [1, 129], null); michael@0: // Test for Address-present-token: michael@0: let (addr = strToCharCodeArray("+123/TYPE=PLMN")) { michael@0: wsp_decode_test(MMS.FromValue, [addr.length + 1, 128].concat(addr), michael@0: {address: "+123", type: "PLMN"}); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// FromValue.encode //// michael@0: michael@0: add_test(function test_FromValue_encode() { michael@0: // Test for Insert-address-token: michael@0: wsp_encode_test(MMS.FromValue, null, [1, 129]); michael@0: // Test for Address-present-token: michael@0: let (addr = strToCharCodeArray("+123/TYPE=PLMN")) { michael@0: wsp_encode_test(MMS.FromValue, {address: "+123", type: "PLMN"}, michael@0: [addr.length + 1, 128].concat(addr)); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: MessageClassValue michael@0: // michael@0: michael@0: //// MessageClassValue.decodeClassIdentifier //// michael@0: michael@0: add_test(function test_MessageClassValue_decodeClassIdentifier() { michael@0: let (IDs = ["personal", "advertisement", "informational", "auto"]) { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 131)) { michael@0: wsp_decode_test_ex(function(data) { michael@0: return MMS.MessageClassValue.decodeClassIdentifier(data); michael@0: }, [i], IDs[i - 128] michael@0: ); michael@0: } else { michael@0: wsp_decode_test_ex(function(data) { michael@0: return MMS.MessageClassValue.decodeClassIdentifier(data); michael@0: }, [i], null, "CodeError" michael@0: ); michael@0: } michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// MessageClassValue.decode //// michael@0: michael@0: add_test(function test_MessageClassValue_decode() { michael@0: wsp_decode_test(MMS.MessageClassValue, [65, 0], "A"); michael@0: wsp_decode_test(MMS.MessageClassValue, [128], "personal"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// MessageClassValue.encode //// michael@0: michael@0: add_test(function test_MessageClassValue_encode() { michael@0: wsp_encode_test(MMS.MessageClassValue, "personal", [128]); michael@0: wsp_encode_test(MMS.MessageClassValue, "advertisement", [129]); michael@0: wsp_encode_test(MMS.MessageClassValue, "informational", [130]); michael@0: wsp_encode_test(MMS.MessageClassValue, "auto", [131]); michael@0: wsp_encode_test(MMS.MessageClassValue, "A", [65, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: MessageTypeValue michael@0: // michael@0: michael@0: //// MessageTypeValue.decode //// michael@0: michael@0: add_test(function test_MessageTypeValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 151)) { michael@0: wsp_decode_test(MMS.MessageTypeValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.MessageTypeValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// MessageTypeValue.encode //// michael@0: michael@0: add_test(function test_MessageTypeValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 151)) { michael@0: wsp_encode_test(MMS.MessageTypeValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.MessageTypeValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: MmFlagsValue michael@0: // michael@0: michael@0: //// MmFlagsValue.decode //// michael@0: michael@0: add_test(function test_MmFlagsValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 130)) { michael@0: wsp_decode_test(MMS.MmFlagsValue, [3, i, 65, 0], {type: i, text: "A"}); michael@0: } else { michael@0: wsp_decode_test(MMS.MmFlagsValue, [3, i, 65, 0], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// MmFlagsValue.encode //// michael@0: michael@0: add_test(function test_MmFlagsValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 130)) { michael@0: wsp_encode_test(MMS.MmFlagsValue, {type: i, text: "A"}, [3, i, 65, 0]); michael@0: } else { michael@0: wsp_encode_test(MMS.MmFlagsValue, {type: i, text: "A"}, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: MmStateValue michael@0: // michael@0: michael@0: //// MmStateValue.decode //// michael@0: michael@0: add_test(function test_MmStateValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 132)) { michael@0: wsp_decode_test(MMS.MmStateValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.MmStateValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// MmStateValue.encode //// michael@0: michael@0: add_test(function test_MmStateValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 132)) { michael@0: wsp_encode_test(MMS.MmStateValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.MmStateValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: PriorityValue michael@0: // michael@0: michael@0: //// PriorityValue.decode //// michael@0: michael@0: add_test(function test_PriorityValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 130)) { michael@0: wsp_decode_test(MMS.PriorityValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.PriorityValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// PriorityValue.encode //// michael@0: michael@0: add_test(function test_PriorityValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 130)) { michael@0: wsp_encode_test(MMS.PriorityValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.PriorityValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ReadStatusValue michael@0: // michael@0: michael@0: //// ReadStatusValue.decode //// michael@0: michael@0: add_test(function test_ReadStatusValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 129)) { michael@0: wsp_decode_test(MMS.ReadStatusValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.ReadStatusValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ReadStatusValue.encode //// michael@0: michael@0: add_test(function test_ReadStatusValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 129)) { michael@0: wsp_encode_test(MMS.ReadStatusValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.ReadStatusValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: RecommendedRetrievalModeValue michael@0: // michael@0: michael@0: //// RecommendedRetrievalModeValue.decode //// michael@0: michael@0: add_test(function test_RecommendedRetrievalModeValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i == 128) { michael@0: wsp_decode_test(MMS.RecommendedRetrievalModeValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.RecommendedRetrievalModeValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ReplyChargingValue michael@0: // michael@0: michael@0: //// ReplyChargingValue.decode //// michael@0: michael@0: add_test(function test_ReplyChargingValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 131)) { michael@0: wsp_decode_test(MMS.ReplyChargingValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.ReplyChargingValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ReplyChargingValue.encode //// michael@0: michael@0: add_test(function test_ReplyChargingValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 131)) { michael@0: wsp_encode_test(MMS.ReplyChargingValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.ReplyChargingValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ResponseText michael@0: // michael@0: michael@0: //// ResponseText.decode //// michael@0: michael@0: add_test(function test_ResponseText_decode() { michael@0: // Test for MMS_PDU_TYPE_MBOX_DELETE_CONF & MMS_PDU_TYPE_DELETE_CONF michael@0: wsp_decode_test_ex(function(data) { michael@0: data.array[0] = data.array.length - 1; michael@0: michael@0: let options = {}; michael@0: options["x-mms-message-type"] = MMS_PDU_TYPE_MBOX_DELETE_CONF; michael@0: return MMS.ResponseText.decode(data, options); michael@0: }, [0, 0x80 | 0x00].concat(strToCharCodeArray("http://no.such.com/path")), michael@0: {statusCount: 0, text: "http://no.such.com/path"} michael@0: ); michael@0: wsp_decode_test_ex(function(data) { michael@0: data.array[0] = data.array.length - 1; michael@0: michael@0: let options = {}; michael@0: options["x-mms-message-type"] = MMS_PDU_TYPE_DELETE_CONF; michael@0: return MMS.ResponseText.decode(data, options); michael@0: }, [0, 0x80 | 0x00].concat(strToCharCodeArray("http://no.such.com/path")), michael@0: {statusCount: 0, text: "http://no.such.com/path"} michael@0: ); michael@0: // Test for other situations michael@0: wsp_decode_test_ex(function(data) { michael@0: let options = {}; michael@0: options["x-mms-message-type"] = MMS_PDU_TYPE_SEND_REQ; michael@0: return MMS.ResponseText.decode(data, options); michael@0: }, strToCharCodeArray("http://no.such.com/path"), michael@0: {text: "http://no.such.com/path"} michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: RetrieveStatusValue michael@0: // michael@0: michael@0: //// RetrieveStatusValue.decode //// michael@0: michael@0: add_test(function test_RetrieveStatusValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i == MMS_PDU_ERROR_OK) michael@0: || (i >= MMS_PDU_ERROR_TRANSIENT_FAILURE)) { michael@0: wsp_decode_test(MMS.RetrieveStatusValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.RetrieveStatusValue, [i], michael@0: MMS_PDU_ERROR_PERMANENT_FAILURE); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: SenderVisibilityValue michael@0: // michael@0: michael@0: //// SenderVisibilityValue.decode //// michael@0: michael@0: add_test(function test_SenderVisibilityValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 129)) { michael@0: wsp_decode_test(MMS.SenderVisibilityValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.SenderVisibilityValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// SenderVisibilityValue.encode //// michael@0: michael@0: add_test(function test_SenderVisibilityValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 129)) { michael@0: wsp_encode_test(MMS.SenderVisibilityValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.SenderVisibilityValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: StatusValue michael@0: // michael@0: michael@0: //// StatusValue.decode //// michael@0: michael@0: add_test(function test_StatusValue_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 135)) { michael@0: wsp_decode_test(MMS.StatusValue, [i], i); michael@0: } else { michael@0: wsp_decode_test(MMS.StatusValue, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// StatusValue.encode //// michael@0: michael@0: add_test(function test_StatusValue_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i >= 128) && (i <= 135)) { michael@0: wsp_encode_test(MMS.StatusValue, i, [i]); michael@0: } else { michael@0: wsp_encode_test(MMS.StatusValue, i, null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: PduHelper michael@0: // michael@0: michael@0: //// PduHelper.parseHeaders //// michael@0: michael@0: add_test(function test_PduHelper_parseHeaders() { michael@0: function parse(input, expect, exception) { michael@0: let data = {array: input, offset: 0}; michael@0: do_check_throws(wsp_test_func.bind(null, MMS.PduHelper.parseHeaders, data, expect), michael@0: exception); michael@0: } michael@0: michael@0: // Parse ends with Content-Type michael@0: let expect = {}; michael@0: expect["x-mms-mms-version"] = MMS_VERSION_1_3; michael@0: expect["content-type"] = { michael@0: media: "application/vnd.wap.multipart.related", michael@0: params: null, michael@0: }; michael@0: parse([0x80 | 0x0D, 0x80 | MMS_VERSION_1_3, // X-Mms-Mms-Version: 1.3 michael@0: 0x80 | 0x04, 0x80 | 0x33, // Content-Type: application/vnd.wap.multipart.related michael@0: 0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ // X-Mms-Message-Type: M-Send.req michael@0: ], expect); michael@0: michael@0: // Parse header fields with multiple entries michael@0: expect = { michael@0: to: [ michael@0: { address: "+123", type: "PLMN" }, michael@0: { address: "+456", type: "num" }, michael@0: ], michael@0: }; michael@0: expect["content-type"] = { michael@0: media: "application/vnd.wap.multipart.related", michael@0: params: null, michael@0: }; michael@0: parse(Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN")) michael@0: .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456")) michael@0: .concat([0x80 | 0x04, 0x80 | 0x33]), michael@0: expect); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// PduHelper.encodeHeader //// michael@0: michael@0: add_test(function test_PduHelper_encodeHeader() { michael@0: function func(name, data, headers) { michael@0: MMS.PduHelper.encodeHeader(data, headers, name); michael@0: michael@0: // Remove extra space consumed during encoding. michael@0: while (data.array.length > data.offset) { michael@0: data.array.pop(); michael@0: } michael@0: michael@0: return data.array; michael@0: } michael@0: michael@0: // Encode header fields with multiple entries michael@0: let headers = { michael@0: to: [ michael@0: { address: "+123", type: "PLMN" }, michael@0: { address: "+456", type: "num" }, michael@0: ], michael@0: }; michael@0: wsp_encode_test_ex(func.bind(null, "to"), headers, michael@0: Array.concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN")) michael@0: .concat([0x80 | 0x17]).concat(strToCharCodeArray("+456"))); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// PduHelper.encodeHeaderIfExists //// michael@0: michael@0: add_test(function test_PduHelper_encodeHeaderIfExists() { michael@0: function func(name, data, headers) { michael@0: MMS.PduHelper.encodeHeaderIfExists(data, headers, name); michael@0: michael@0: // Remove extra space consumed during encoding. michael@0: while (data.array.length > data.offset) { michael@0: data.array.pop(); michael@0: } michael@0: michael@0: return data.array; michael@0: } michael@0: michael@0: wsp_encode_test_ex(func.bind(null, "to"), {}, []); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// PduHelper.encodeHeaders //// michael@0: michael@0: add_test(function test_PduHelper_encodeHeaders() { michael@0: function func(data, headers) { michael@0: MMS.PduHelper.encodeHeaders(data, headers); michael@0: michael@0: // Remove extra space consumed during encoding. michael@0: while (data.array.length > data.offset) { michael@0: data.array.pop(); michael@0: } michael@0: michael@0: return data.array; michael@0: } michael@0: michael@0: let headers = {}; michael@0: headers["x-mms-message-type"] = MMS_PDU_TYPE_SEND_REQ; michael@0: headers["x-mms-mms-version"] = MMS_VERSION_1_3; michael@0: headers["x-mms-transaction-id"] = "asdf"; michael@0: headers["to"] = { address: "+123", type: "PLMN" }; michael@0: headers["content-type"] = { michael@0: media: "application/vnd.wap.multipart.related", michael@0: }; michael@0: wsp_encode_test_ex(func, headers, michael@0: Array.concat([0x80 | 0x0C, MMS_PDU_TYPE_SEND_REQ]) michael@0: .concat([0x80 | 0x18]).concat(strToCharCodeArray(headers["x-mms-transaction-id"])) michael@0: .concat([0x80 | 0x0D, 0x80 | MMS_VERSION_1_3]) michael@0: .concat([0x80 | 0x17]).concat(strToCharCodeArray("+123/TYPE=PLMN")) michael@0: .concat([0x80 | 0x04, 0x80 | 0x33])); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: