michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let WSP = {}; michael@0: subscriptLoader.loadSubScript("resource://gre/modules/WspPduHelper.jsm", WSP); michael@0: WSP.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: ensureHeader michael@0: // michael@0: michael@0: add_test(function test_ensureHeader() { michael@0: do_check_throws(function() { michael@0: WSP.ensureHeader({}, "no-such-property"); michael@0: }, "FatalCodeError" michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: skipValue() michael@0: // michael@0: michael@0: add_test(function test_skipValue() { michael@0: function func(data) { michael@0: return WSP.skipValue(data); michael@0: } michael@0: michael@0: // Test for zero-valued first octet: michael@0: wsp_decode_test_ex(func, [0], null); michael@0: // Test first octet < 31 michael@0: wsp_decode_test_ex(func, [1, 2], [2]); michael@0: // Test first octet = 31 michael@0: wsp_decode_test_ex(func, [31, 0], null); michael@0: wsp_decode_test_ex(func, [31, 1, 2], [2]); michael@0: // Test first octet <= 127 michael@0: wsp_decode_test_ex(func, strToCharCodeArray("Hello world!"), "Hello world!"); michael@0: // Test first octet >= 128 michael@0: wsp_decode_test_ex(func, [0x80 | 0x01], 0x01); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: Octet michael@0: // michael@0: michael@0: //// Octet.decode //// michael@0: michael@0: add_test(function test_Octet_decode() { michael@0: wsp_decode_test(WSP.Octet, [1], 1); michael@0: wsp_decode_test(WSP.Octet, [], null, "RangeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Octet.decodeMultiple //// michael@0: michael@0: add_test(function test_Octet_decodeMultiple() { michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.Octet.decodeMultiple(data, 3); michael@0: }, [0, 1, 2], [0, 1, 2], null michael@0: ); michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.Octet.decodeMultiple(data, 3); michael@0: }, new Uint8Array([0, 1, 2]), new Uint8Array([0, 1, 2]), null michael@0: ); michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.Octet.decodeMultiple(data, 4); michael@0: }, [0, 1, 2], null, "RangeError" michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Octet.decodeEqualTo //// michael@0: michael@0: add_test(function test_Octet_decodeEqualTo() { michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.Octet.decodeEqualTo(data, 1); michael@0: }, [1], 1, null michael@0: ); michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.Octet.decodeEqualTo(data, 2); michael@0: }, [1], null, "CodeError" michael@0: ); michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.Octet.decodeEqualTo(data, 2); michael@0: }, [], null, "RangeError" michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Octet.encode //// michael@0: michael@0: add_test(function test_Octet_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: wsp_encode_test(WSP.Octet, i, [i]); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Octet.encodeMultiple //// michael@0: michael@0: add_test(function test_Octet_encodeMultiple() { michael@0: wsp_encode_test_ex(function(data, input) { michael@0: WSP.Octet.encodeMultiple(data, input); michael@0: return data.array; michael@0: }, [0, 1, 2, 3], [0, 1, 2, 3]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: Text michael@0: // michael@0: michael@0: //// Text.decode //// michael@0: michael@0: add_test(function test_Text_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i == 0) { michael@0: wsp_decode_test(WSP.Text, [0], null, "NullCharError"); michael@0: } else if ((i < WSP.CTLS) || (i == WSP.DEL)) { michael@0: wsp_decode_test(WSP.Text, [i], null, "CodeError"); michael@0: } else { michael@0: wsp_decode_test(WSP.Text, [i], String.fromCharCode(i)); michael@0: } michael@0: } michael@0: // Test \r\n(SP|HT)* sequence: michael@0: wsp_decode_test(WSP.Text, strToCharCodeArray("\r\n \t \t \t", true), " "); michael@0: wsp_decode_test(WSP.Text, strToCharCodeArray("\r\n \t \t \t"), " "); michael@0: wsp_decode_test(WSP.Text, strToCharCodeArray("\r\n \t \t \tA"), " "); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Text.encode //// michael@0: michael@0: add_test(function test_Text_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i < WSP.CTLS) || (i == WSP.DEL)) { michael@0: wsp_encode_test(WSP.Text, String.fromCharCode(i), null, "CodeError"); michael@0: } else { michael@0: wsp_encode_test(WSP.Text, String.fromCharCode(i), [i]); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: NullTerminatedTexts michael@0: // michael@0: michael@0: //// NullTerminatedTexts.decode //// michael@0: michael@0: add_test(function test_NullTerminatedTexts_decode() { michael@0: // Test incompleted string: michael@0: wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray(" ", true), null, "RangeError"); michael@0: // Test control char: michael@0: wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray(" \n"), null, "CodeError"); michael@0: // Test normal string: michael@0: wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray(""), ""); michael@0: wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray("oops"), "oops"); michael@0: // Test \r\n(SP|HT)* sequence: michael@0: wsp_decode_test(WSP.NullTerminatedTexts, strToCharCodeArray("A\r\n \t \t \tB"), "A B"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// NullTerminatedTexts.encode //// michael@0: michael@0: add_test(function test_NullTerminatedTexts_encode() { michael@0: wsp_encode_test(WSP.NullTerminatedTexts, "", [0]); michael@0: wsp_encode_test(WSP.NullTerminatedTexts, "Hello, World!", michael@0: strToCharCodeArray("Hello, World!")); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: Token michael@0: // michael@0: michael@0: let TOKEN_SEPS = "()<>@,;:\\\"/[]?={} \t"; michael@0: michael@0: //// Token.decode //// michael@0: michael@0: add_test(function test_Token_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i == 0) { michael@0: wsp_decode_test(WSP.Token, [i], null, "NullCharError"); michael@0: } else if ((i < WSP.CTLS) || (i >= WSP.ASCIIS) michael@0: || (TOKEN_SEPS.indexOf(String.fromCharCode(i)) >= 0)) { michael@0: wsp_decode_test(WSP.Token, [i], null, "CodeError"); michael@0: } else { michael@0: wsp_decode_test(WSP.Token, [i], String.fromCharCode(i)); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Token.encode //// michael@0: michael@0: add_test(function test_Token_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if ((i < WSP.CTLS) || (i >= WSP.ASCIIS) michael@0: || (TOKEN_SEPS.indexOf(String.fromCharCode(i)) >= 0)) { michael@0: wsp_encode_test(WSP.Token, String.fromCharCode(i), null, "CodeError"); michael@0: } else { michael@0: wsp_encode_test(WSP.Token, String.fromCharCode(i), [i]); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: URIC michael@0: // michael@0: michael@0: //// URIC.decode //// michael@0: michael@0: add_test(function test_URIC_decode() { michael@0: let uric = "!#$%&'()*+,-./0123456789:;=?@ABCDEFGHIJKLMN" michael@0: + "OPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"; michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i == 0) { michael@0: wsp_decode_test(WSP.URIC, [i], null, "NullCharError"); michael@0: } else if (uric.indexOf(String.fromCharCode(i)) >= 0) { michael@0: wsp_decode_test(WSP.URIC, [i], String.fromCharCode(i)); michael@0: } else { michael@0: wsp_decode_test(WSP.URIC, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: TextString michael@0: // michael@0: michael@0: //// TextString.decode //// michael@0: michael@0: add_test(function test_TextString_decode() { michael@0: // Test quoted string michael@0: wsp_decode_test(WSP.TextString, [127, 128, 0], String.fromCharCode(128)); michael@0: // Test illegal quoted string michael@0: wsp_decode_test(WSP.TextString, [127, 32, 0], null, "CodeError"); michael@0: // Test illegal unquoted string michael@0: wsp_decode_test(WSP.TextString, [128, 0], null, "CodeError"); michael@0: // Test normal string michael@0: wsp_decode_test(WSP.TextString, [32, 0], " "); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// TextString.encode //// michael@0: michael@0: add_test(function test_TextString_encode() { michael@0: // Test quoted string michael@0: wsp_encode_test(WSP.TextString, String.fromCharCode(128), [127, 128, 0]); michael@0: // Test normal string michael@0: wsp_encode_test(WSP.TextString, "Mozilla", strToCharCodeArray("Mozilla")); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: TokenText michael@0: // michael@0: michael@0: //// TokenText.decode //// michael@0: michael@0: add_test(function test_TokenText_decode() { michael@0: wsp_decode_test(WSP.TokenText, [65], null, "RangeError"); michael@0: wsp_decode_test(WSP.TokenText, [0], ""); michael@0: wsp_decode_test(WSP.TokenText, [65, 0], "A"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// TokenText.encode //// michael@0: michael@0: add_test(function test_TokenText_encode() { michael@0: wsp_encode_test(WSP.TokenText, "B2G", strToCharCodeArray("B2G")); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: QuotedString michael@0: // michael@0: michael@0: //// QuotedString.decode //// michael@0: michael@0: add_test(function test_QuotedString_decode() { michael@0: // Test non-quoted string michael@0: wsp_decode_test(WSP.QuotedString, [32, 0], null, "CodeError"); michael@0: // Test incompleted string michael@0: wsp_decode_test(WSP.QuotedString, [34, 32], null, "RangeError"); michael@0: wsp_decode_test(WSP.QuotedString, [34, 32, 0], " "); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// QuotedString.encode //// michael@0: michael@0: add_test(function test_QuotedString_encode() { michael@0: wsp_encode_test(WSP.QuotedString, "B2G", [34].concat(strToCharCodeArray("B2G"))); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ShortInteger michael@0: // michael@0: michael@0: //// ShortInteger.decode //// michael@0: michael@0: add_test(function test_ShortInteger_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i & 0x80) { michael@0: wsp_decode_test(WSP.ShortInteger, [i], i & 0x7F); michael@0: } else { michael@0: wsp_decode_test(WSP.ShortInteger, [i], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ShortInteger.encode //// michael@0: michael@0: add_test(function test_ShortInteger_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i & 0x80) { michael@0: wsp_encode_test(WSP.ShortInteger, i, null, "CodeError"); michael@0: } else { michael@0: wsp_encode_test(WSP.ShortInteger, i, [0x80 | i]); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: LongInteger michael@0: // michael@0: michael@0: //// LongInteger.decode //// michael@0: michael@0: function LongInteger_decode_testcases(target) { michael@0: // Test LongInteger of zero octet michael@0: wsp_decode_test(target, [0, 0], null, "CodeError"); michael@0: wsp_decode_test(target, [1, 0x80], 0x80); michael@0: wsp_decode_test(target, [2, 0x80, 2], 0x8002); michael@0: wsp_decode_test(target, [3, 0x80, 2, 3], 0x800203); michael@0: wsp_decode_test(target, [4, 0x80, 2, 3, 4], 0x80020304); michael@0: wsp_decode_test(target, [5, 0x80, 2, 3, 4, 5], 0x8002030405); michael@0: wsp_decode_test(target, [6, 0x80, 2, 3, 4, 5, 6], 0x800203040506); michael@0: // Test LongInteger of more than 6 octets michael@0: wsp_decode_test(target, [7, 0x80, 2, 3, 4, 5, 6, 7], [0x80, 2, 3, 4, 5, 6, 7]); michael@0: // Test LongInteger of more than 30 octets michael@0: wsp_decode_test(target, [31], null, "CodeError"); michael@0: } michael@0: add_test(function test_LongInteger_decode() { michael@0: LongInteger_decode_testcases(WSP.LongInteger); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// LongInteger.encode //// michael@0: michael@0: function LongInteger_encode_testcases(target) { michael@0: wsp_encode_test(target, 0x80, [1, 0x80]); michael@0: wsp_encode_test(target, 0x8002, [2, 0x80, 2]); michael@0: wsp_encode_test(target, 0x800203, [3, 0x80, 2, 3]); michael@0: wsp_encode_test(target, 0x80020304, [4, 0x80, 2, 3, 4]); michael@0: wsp_encode_test(target, 0x8002030405, [5, 0x80, 2, 3, 4, 5]); michael@0: wsp_encode_test(target, 0x800203040506, [6, 0x80, 2, 3, 4, 5, 6]); michael@0: // Test LongInteger of more than 6 octets michael@0: wsp_encode_test(target, 0x1000000000000, null, "CodeError"); michael@0: // Test input empty array michael@0: wsp_encode_test(target, [], null, "CodeError"); michael@0: // Test input octets array of length 1..30 michael@0: let array = []; michael@0: for (let i = 1; i <= 30; i++) { michael@0: array.push(i); michael@0: wsp_encode_test(target, array, [i].concat(array)); michael@0: } michael@0: // Test input octets array of 31 elements. michael@0: array.push(31); michael@0: wsp_encode_test(target, array, null, "CodeError"); michael@0: } michael@0: add_test(function test_LongInteger_encode() { michael@0: wsp_encode_test(WSP.LongInteger, 0, [1, 0]); michael@0: michael@0: LongInteger_encode_testcases(WSP.LongInteger); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: UintVar michael@0: // michael@0: michael@0: //// UintVar.decode //// michael@0: michael@0: add_test(function test_UintVar_decode() { michael@0: wsp_decode_test(WSP.UintVar, [0x80], null, "RangeError"); michael@0: // Test up to max 53 bits integer michael@0: wsp_decode_test(WSP.UintVar, [0x7F], 0x7F); michael@0: wsp_decode_test(WSP.UintVar, [0xFF, 0x7F], 0x3FFF); michael@0: wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0x7F], 0x1FFFFF); michael@0: wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0x7F], 0xFFFFFFF); michael@0: wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x7FFFFFFFF); michael@0: wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x3FFFFFFFFFF); michael@0: wsp_decode_test(WSP.UintVar, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x1FFFFFFFFFFFF); michael@0: wsp_decode_test(WSP.UintVar, [0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], 0x1FFFFFFFFFFFFF); michael@0: wsp_decode_test(WSP.UintVar, [0x01, 0x02], 1); michael@0: wsp_decode_test(WSP.UintVar, [0x80, 0x01, 0x02], 1); michael@0: wsp_decode_test(WSP.UintVar, [0x80, 0x80, 0x80, 0x01, 0x2], 1); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// UintVar.encode //// michael@0: michael@0: add_test(function test_UintVar_encode() { michael@0: // Test up to max 53 bits integer michael@0: wsp_encode_test(WSP.UintVar, 0, [0]); michael@0: wsp_encode_test(WSP.UintVar, 0x7F, [0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0x3FFF, [0xFF, 0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0x1FFFFF, [0xFF, 0xFF, 0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0xFFFFFFF, [0xFF, 0xFF, 0xFF, 0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0x7FFFFFFFF, [0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0x3FFFFFFFFFF, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0x1FFFFFFFFFFFF, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); michael@0: wsp_encode_test(WSP.UintVar, 0x1FFFFFFFFFFFFF, [0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ConstrainedEncoding michael@0: // michael@0: michael@0: //// ConstrainedEncoding.decode //// michael@0: michael@0: add_test(function test_ConstrainedEncoding_decode() { michael@0: wsp_decode_test(WSP.ConstrainedEncoding, [0x80], 0); michael@0: wsp_decode_test(WSP.ConstrainedEncoding, [32, 0], " "); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ConstrainedEncoding.encode //// michael@0: michael@0: add_test(function test_ConstrainedEncoding_encode() { michael@0: wsp_encode_test(WSP.ConstrainedEncoding, 0, [0x80 | 0]); michael@0: wsp_encode_test(WSP.ConstrainedEncoding, "A", [65, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ValueLength michael@0: // michael@0: michael@0: //// ValueLength.decode //// michael@0: michael@0: add_test(function test_ValueLength_decode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i < 31) { michael@0: wsp_decode_test(WSP.ValueLength, [i, 0x8F, 0x7F], i); michael@0: } else if (i == 31) { michael@0: wsp_decode_test(WSP.ValueLength, [i, 0x8F, 0x7F], 0x7FF); michael@0: } else { michael@0: wsp_decode_test(WSP.ValueLength, [i, 0x8F, 0x7F], null, "CodeError"); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ValueLength.encode //// michael@0: michael@0: add_test(function test_ValueLength_encode() { michael@0: for (let i = 0; i < 256; i++) { michael@0: if (i < 31) { michael@0: wsp_encode_test(WSP.ValueLength, i, [i]); michael@0: } else if (i < 128) { michael@0: wsp_encode_test(WSP.ValueLength, i, [31, i]); michael@0: } else { michael@0: wsp_encode_test(WSP.ValueLength, i, [31, (0x80 | (i / 128)), i % 128]); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: NoValue michael@0: // michael@0: michael@0: //// NoValue.decode //// michael@0: michael@0: add_test(function test_NoValue_decode() { michael@0: wsp_decode_test(WSP.NoValue, [0], null); michael@0: for (let i = 1; i < 256; i++) { michael@0: wsp_decode_test(WSP.NoValue, [i], null, "CodeError"); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// NoValue.encode //// michael@0: michael@0: add_test(function test_NoValue_encode() { michael@0: wsp_encode_test(WSP.NoValue, undefined, [0]); michael@0: wsp_encode_test(WSP.NoValue, null, [0]); michael@0: wsp_encode_test(WSP.NoValue, 0, null, "CodeError"); michael@0: wsp_encode_test(WSP.NoValue, "", null, "CodeError"); michael@0: wsp_encode_test(WSP.NoValue, [], null, "CodeError"); michael@0: wsp_encode_test(WSP.NoValue, {}, null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: TextValue michael@0: // michael@0: michael@0: //// TextValue.decode //// michael@0: michael@0: add_test(function test_TextValue_decode() { michael@0: wsp_decode_test(WSP.TextValue, [0], null); michael@0: wsp_decode_test(WSP.TextValue, [65, 0], "A"); michael@0: wsp_decode_test(WSP.TextValue, [32, 0], null, "CodeError"); michael@0: wsp_decode_test(WSP.TextValue, [34, 32, 0], " "); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// TextValue.encode //// michael@0: michael@0: add_test(function test_TextValue_encode() { michael@0: wsp_encode_test(WSP.TextValue, undefined, [0]); michael@0: wsp_encode_test(WSP.TextValue, null, [0]); michael@0: wsp_encode_test(WSP.TextValue, "", [0]); michael@0: wsp_encode_test(WSP.TextValue, "A", [65, 0]); michael@0: wsp_encode_test(WSP.TextValue, "\x80", [34, 128, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: IntegerValue michael@0: // michael@0: michael@0: //// IntegerValue.decode //// michael@0: michael@0: add_test(function test_IntegerValue_decode() { michael@0: for (let i = 128; i < 256; i++) { michael@0: wsp_decode_test(WSP.IntegerValue, [i], i & 0x7F); michael@0: } michael@0: michael@0: LongInteger_decode_testcases(WSP.IntegerValue); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// IntegerValue.decode //// michael@0: michael@0: add_test(function test_IntegerValue_encode() { michael@0: for (let i = 0; i < 128; i++) { michael@0: wsp_encode_test(WSP.IntegerValue, i, [0x80 | i]); michael@0: } michael@0: michael@0: LongInteger_encode_testcases(WSP.IntegerValue); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: DateValue michael@0: // michael@0: michael@0: //// DateValue.decode //// michael@0: michael@0: add_test(function test_DateValue_decode() { michael@0: wsp_decode_test(WSP.DateValue, [0, 0], null, "CodeError"); michael@0: wsp_decode_test(WSP.DateValue, [1, 0x80], new Date(0x80 * 1000)); michael@0: wsp_decode_test(WSP.DateValue, [31], null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// DateValue.encode //// michael@0: michael@0: add_test(function test_DateValue_encode() { michael@0: wsp_encode_test(WSP.DateValue, new Date(0x80 * 1000), [1, 0x80]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: DeltaSecondsValue michael@0: // michael@0: // DeltaSecondsValue is only an alias of IntegerValue. michael@0: michael@0: // michael@0: // Test target: QValue michael@0: // michael@0: michael@0: //// QValue.decode //// michael@0: michael@0: add_test(function test_QValue_decode() { michael@0: wsp_decode_test(WSP.QValue, [0], null, "CodeError"); michael@0: wsp_decode_test(WSP.QValue, [1], 0); michael@0: wsp_decode_test(WSP.QValue, [100], 0.99); michael@0: wsp_decode_test(WSP.QValue, [101], 0.001); michael@0: wsp_decode_test(WSP.QValue, [0x88, 0x4B], 0.999); michael@0: wsp_decode_test(WSP.QValue, [0x88, 0x4C], null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// QValue.encode //// michael@0: michael@0: add_test(function test_QValue_encode() { michael@0: wsp_encode_test(WSP.QValue, 0, [1]); michael@0: wsp_encode_test(WSP.QValue, 0.99, [100]); michael@0: wsp_encode_test(WSP.QValue, 0.001, [101]); michael@0: wsp_encode_test(WSP.QValue, 0.999, [0x88, 0x4B]); michael@0: wsp_encode_test(WSP.QValue, 1, null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: VersionValue michael@0: // michael@0: michael@0: //// VersionValue.decode //// michael@0: michael@0: add_test(function test_VersionValue_decode() { michael@0: for (let major = 1; major < 8; major++) { michael@0: let version = (major << 4) | 0x0F; michael@0: wsp_decode_test(WSP.VersionValue, [0x80 | version], version); michael@0: wsp_decode_test(WSP.VersionValue, [major + 0x30, 0], version); michael@0: michael@0: for (let minor = 0; minor < 15; minor++) { michael@0: version = (major << 4) | minor; michael@0: wsp_decode_test(WSP.VersionValue, [0x80 | version], version); michael@0: if (minor >= 10) { michael@0: wsp_decode_test(WSP.VersionValue, [major + 0x30, 0x2E, 0x31, (minor - 10) + 0x30, 0], version); michael@0: } else { michael@0: wsp_decode_test(WSP.VersionValue, [major + 0x30, 0x2E, minor + 0x30, 0], version); michael@0: } michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// VersionValue.encode //// michael@0: michael@0: add_test(function test_VersionValue_encode() { michael@0: for (let major = 1; major < 8; major++) { michael@0: let version = (major << 4) | 0x0F; michael@0: wsp_encode_test(WSP.VersionValue, version, [0x80 | version]); michael@0: michael@0: for (let minor = 0; minor < 15; minor++) { michael@0: version = (major << 4) | minor; michael@0: wsp_encode_test(WSP.VersionValue, version, [0x80 | version]); michael@0: } michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: UriValue michael@0: // michael@0: michael@0: //// UriValue.decode //// michael@0: michael@0: add_test(function test_UriValue_decode() { michael@0: wsp_decode_test(WSP.UriValue, [97], null, "RangeError"); michael@0: wsp_decode_test(WSP.UriValue, [0], ""); michael@0: wsp_decode_test(WSP.UriValue, [65, 0], "A"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: TypeValue michael@0: // michael@0: michael@0: //// TypeValue.decode //// michael@0: michael@0: add_test(function test_TypeValue_decode() { michael@0: // Test for string-typed return value from ConstrainedEncoding michael@0: wsp_decode_test(WSP.TypeValue, [65, 0], "a"); michael@0: // Test for number-typed return value from ConstrainedEncoding michael@0: wsp_decode_test(WSP.TypeValue, [0x33 | 0x80], michael@0: "application/vnd.wap.multipart.related"); michael@0: wsp_decode_test(WSP.TypeValue, [0x1d | 0x80], "image/gif"); michael@0: // Test for NotWellKnownEncodingError michael@0: wsp_decode_test(WSP.TypeValue, [0x59 | 0x80], null, "NotWellKnownEncodingError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// TypeValue.encode //// michael@0: michael@0: add_test(function test_TypeValue_encode() { michael@0: wsp_encode_test(WSP.TypeValue, "no/such.type", michael@0: [110, 111, 47, 115, 117, 99, 104, 46, 116, 121, 112, 101, 0]); michael@0: wsp_encode_test(WSP.TypeValue, "application/vnd.wap.multipart.related", michael@0: [0x33 | 0x80]); michael@0: wsp_encode_test(WSP.TypeValue, "image/gif", michael@0: [0x1d | 0x80]); 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.decodeTypedParameter //// michael@0: michael@0: add_test(function test_Parameter_decodeTypedParameter() { michael@0: function func(data) { michael@0: return WSP.Parameter.decodeTypedParameter(data); michael@0: } michael@0: michael@0: // Test for array-typed return value from IntegerValue michael@0: wsp_decode_test_ex(func, [7, 0, 0, 0, 0, 0, 0, 0], null, "CodeError"); michael@0: // Test for number-typed return value from IntegerValue michael@0: wsp_decode_test_ex(func, [1, 0, 0], {name: "q", value: null}); michael@0: // Test for NotWellKnownEncodingError michael@0: wsp_decode_test_ex(func, [1, 0xFF], null, "NotWellKnownEncodingError"); michael@0: // Test for parameter specific decoder michael@0: wsp_decode_test_ex(func, [1, 0, 100], {name: "q", value: 0.99}); michael@0: // Test for TextValue michael@0: wsp_decode_test_ex(func, [1, 0x10, 48, 46, 57, 57, 0], michael@0: {name: "secure", value: "0.99"}); michael@0: // Test for TextString michael@0: wsp_decode_test_ex(func, [1, 0x0A, 60, 115, 109, 105, 108, 62, 0], michael@0: {name: "start", value: ""}); michael@0: // Test for skipValue michael@0: wsp_decode_test_ex(func, [1, 0x0A, 128], null); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.decodeUntypedParameter //// michael@0: michael@0: add_test(function test_Parameter_decodeUntypedParameter() { michael@0: function func (data) { michael@0: return WSP.Parameter.decodeUntypedParameter(data); michael@0: } michael@0: michael@0: wsp_decode_test_ex(func, [1], null, "CodeError"); michael@0: wsp_decode_test_ex(func, [65, 0, 0], {name: "a", value: null}); michael@0: // Test for IntegerValue michael@0: wsp_decode_test_ex(func, [65, 0, 1, 0], {name: "a", value: 0}); michael@0: // Test for TextValue michael@0: wsp_decode_test_ex(func, [65, 0, 66, 0], {name: "a", value: "B"}); 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(WSP.Parameter, [1, 0x0A, 60, 115, 109, 105, 108, 62, 0], michael@0: {name: "start", value: ""}); michael@0: wsp_decode_test(WSP.Parameter, [65, 0, 66, 0], {name: "a", value: "B"}); 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: wsp_decode_test_ex(function(data) { michael@0: return WSP.Parameter.decodeMultiple(data, 13); michael@0: }, [1, 0x0A, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0], {start: "", a: "B"} michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.encodeTypedParameter //// michael@0: michael@0: add_test(function test_Parameter_encodeTypedParameter() { michael@0: function func(data, input) { michael@0: WSP.Parameter.encodeTypedParameter(data, input); michael@0: return data.array; michael@0: } michael@0: michael@0: // Test for NotWellKnownEncodingError michael@0: wsp_encode_test_ex(func, {name: "xxx", value: 0}, null, "NotWellKnownEncodingError"); michael@0: wsp_encode_test_ex(func, {name: "q", value: 0}, [0x80, 1]); michael@0: wsp_encode_test_ex(func, {name: "name", value: "A"}, [0x85, 65, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.encodeUntypedParameter //// michael@0: michael@0: add_test(function test_Parameter_encodeUntypedParameter() { michael@0: function func(data, input) { michael@0: WSP.Parameter.encodeUntypedParameter(data, input); michael@0: return data.array; michael@0: } michael@0: michael@0: wsp_encode_test_ex(func, {name: "q", value: 0}, [113, 0, 0x80]); michael@0: wsp_encode_test_ex(func, {name: "name", value: "A"}, [110, 97, 109, 101, 0, 65, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// Parameter.encodeMultiple //// michael@0: michael@0: add_test(function test_Parameter_encodeMultiple() { michael@0: function func(data, input) { michael@0: WSP.Parameter.encodeMultiple(data, input); michael@0: return data.array; michael@0: } michael@0: michael@0: wsp_encode_test_ex(func, {q: 0, n: "A"}, [0x80, 1, 110, 0, 65, 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: michael@0: wsp_encode_test(WSP.Parameter, {name: "q", value: 0}, [0x80, 1]); michael@0: wsp_encode_test(WSP.Parameter, {name: "n", value: "A"}, [110, 0, 65, 0]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: Header michael@0: // michael@0: michael@0: //// Header.decode //// michael@0: michael@0: add_test(function test_Header_decode() { michael@0: wsp_decode_test(WSP.Header, [0x34 | 0x80, 0x80], {name: "push-flag", value: 0}); michael@0: wsp_decode_test(WSP.Header, [65, 0, 66, 0], {name: "a", value: "B"}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: WellKnownHeader michael@0: // michael@0: michael@0: //// WellKnownHeader.decode //// michael@0: michael@0: add_test(function test_WellKnownHeader_decode() { michael@0: wsp_decode_test(WSP.WellKnownHeader, [0xFF], null, "NotWellKnownEncodingError"); michael@0: let (entry = WSP.WSP_HEADER_FIELDS["push-flag"]) { michael@0: // Test for Short-Integer michael@0: wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 0x80], michael@0: {name: entry.name, value: 0}); michael@0: // Test for NoValue michael@0: wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 0], michael@0: {name: entry.name, value: null}); michael@0: // Test for TokenText michael@0: wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 65, 0], michael@0: {name: entry.name, value: "A"}); michael@0: // Test for QuotedString michael@0: wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 34, 128, 0], michael@0: {name: entry.name, value: String.fromCharCode(128)}); michael@0: // Test for skipValue michael@0: wsp_decode_test(WSP.WellKnownHeader, [entry.number | 0x80, 2, 0, 0], null); michael@0: } michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ApplicationHeader michael@0: // michael@0: michael@0: //// ApplicationHeader.decode //// michael@0: michael@0: add_test(function test_ApplicationHeader_decode() { michael@0: wsp_decode_test(WSP.ApplicationHeader, [5, 0, 66, 0], null, "CodeError"); michael@0: wsp_decode_test(WSP.ApplicationHeader, [65, 0, 66, 0], {name: "a", value: "B"}); michael@0: // Test for skipValue michael@0: wsp_decode_test(WSP.ApplicationHeader, [65, 0, 2, 0, 0], null); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ApplicationHeader.encode //// michael@0: michael@0: add_test(function test_ApplicationHeader_encode() { michael@0: // Test invalid header name string: michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: undefined, value: "asdf"}, null, "CodeError"); michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: null, value: "asdf"}, null, "CodeError"); michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: "", value: "asdf"}, null, "CodeError"); michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: "a b", value: "asdf"}, null, "CodeError"); michael@0: // Test value string: michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: "asdf", value: undefined}, michael@0: strToCharCodeArray("asdf").concat([0])); michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: "asdf", value: null}, michael@0: strToCharCodeArray("asdf").concat([0])); michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: "asdf", value: ""}, michael@0: strToCharCodeArray("asdf").concat([0])); michael@0: wsp_encode_test(WSP.ApplicationHeader, {name: "asdf", value: "fdsa"}, michael@0: strToCharCodeArray("asdf").concat(strToCharCodeArray("fdsa"))); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: FieldName michael@0: // michael@0: michael@0: //// FieldName.decode //// michael@0: michael@0: add_test(function test_FieldName_decode() { michael@0: wsp_decode_test(WSP.FieldName, [0], ""); michael@0: wsp_decode_test(WSP.FieldName, [65, 0], "a"); michael@0: wsp_decode_test(WSP.FieldName, [97, 0], "a"); michael@0: let (entry = WSP.WSP_HEADER_FIELDS["content-length"]) { michael@0: wsp_decode_test(WSP.FieldName, [entry.number | 0x80], entry.name); michael@0: } michael@0: wsp_decode_test(WSP.FieldName, [0xFF], null, "NotWellKnownEncodingError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// FieldName.encode //// michael@0: michael@0: add_test(function test_FieldName_encode() { michael@0: wsp_encode_test(WSP.FieldName, "", [0]); michael@0: wsp_encode_test(WSP.FieldName, "date", [0x92]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: AcceptCharsetValue michael@0: // michael@0: michael@0: //// AcceptCharsetValue.decode //// michael@0: michael@0: add_test(function test_AcceptCharsetValue_decode() { michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [0xFF], null, "CodeError"); michael@0: // Test for Any-Charset michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [128], {charset: "*"}); michael@0: // Test for Constrained-Charset michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [65, 0], {charset: "A"}); michael@0: let (entry = WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) { michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [entry.number | 0x80], {charset: entry.name}); michael@0: } michael@0: // Test for Accept-Charset-General-Form michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [1, 128], {charset: "*"}); michael@0: let (entry = WSP.WSP_WELL_KNOWN_CHARSETS["utf-8"]) { michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [2, 1, entry.number], {charset: entry.name}); michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [1, entry.number | 0x80], {charset: entry.name}); michael@0: } michael@0: wsp_decode_test(WSP.AcceptCharsetValue, [3, 65, 0, 100], {charset: "A", q: 0.99}); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// AcceptCharsetValue.encodeAnyCharset //// michael@0: michael@0: add_test(function test_AcceptCharsetValue_encodeAnyCharset() { michael@0: function func(data, input) { michael@0: WSP.AcceptCharsetValue.encodeAnyCharset(data, input); michael@0: return data.array; michael@0: } michael@0: michael@0: wsp_encode_test_ex(func, null, [0x80]); michael@0: wsp_encode_test_ex(func, undefined, [0x80]); michael@0: wsp_encode_test_ex(func, {}, [0x80]); michael@0: wsp_encode_test_ex(func, {charset: null}, [0x80]); michael@0: wsp_encode_test_ex(func, {charset: "*"}, [0x80]); michael@0: wsp_encode_test_ex(func, {charset: "en"}, null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: WellKnownCharset michael@0: // michael@0: michael@0: //// WellKnownCharset.decode //// michael@0: michael@0: add_test(function test_WellKnownCharset_decode() { michael@0: wsp_decode_test(WSP.WellKnownCharset, [0xFF], null, "NotWellKnownEncodingError"); michael@0: // Test for Any-Charset michael@0: wsp_decode_test(WSP.WellKnownCharset, [128], {charset: "*"}); michael@0: // Test for number-typed return value from IntegerValue michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 3], {charset: "us-ascii"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 4], {charset: "iso-8859-1"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 5], {charset: "iso-8859-2"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 6], {charset: "iso-8859-3"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 7], {charset: "iso-8859-4"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 8], {charset: "iso-8859-5"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 9], {charset: "iso-8859-6"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 10], {charset: "iso-8859-7"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 11], {charset: "iso-8859-8"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 12], {charset: "iso-8859-9"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 13], {charset: "iso-8859-10"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 17], {charset: "shift_jis"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 18], {charset: "euc-jp"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 37], {charset: "iso-2022-kr"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 38], {charset: "euc-kr"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 39], {charset: "iso-2022-jp"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 40], {charset: "iso-2022-jp-2"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 81], {charset: "iso-8859-6-e"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 82], {charset: "iso-8859-6-i"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 84], {charset: "iso-8859-8-e"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 85], {charset: "iso-8859-8-i"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 1000], {charset: "iso-10646-ucs-2"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 1015], {charset: "utf-16"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 2025], {charset: "gb2312"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 2026], {charset: "big5"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 2084], {charset: "koi8-r"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [1, 2252], {charset: "windows-1252"}); michael@0: wsp_decode_test(WSP.WellKnownCharset, [2, 3, 247], {charset: "utf-16"}); michael@0: // Test for array-typed return value from IntegerValue michael@0: wsp_decode_test(WSP.WellKnownCharset, [7, 0, 0, 0, 0, 0, 0, 0, 3], null, "CodeError"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// WellKnownCharset.encode //// michael@0: michael@0: add_test(function test_WellKnownCharset_encode() { michael@0: // Test for Any-charset michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "*"}, [0x80]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "us-ascii"}, [128 + 3]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-1"}, [128 + 4]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-2"}, [128 + 5]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-3"}, [128 + 6]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-4"}, [128 + 7]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-5"}, [128 + 8]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-6"}, [128 + 9]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-7"}, [128 + 10]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-8"}, [128 + 11]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-9"}, [128 + 12]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-10"}, [128 + 13]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "shift_jis"}, [128 + 17]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "euc-jp"}, [128 + 18]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-2022-kr"}, [128 + 37]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "euc-kr"}, [128 + 38]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-2022-jp"}, [128 + 39]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-2022-jp-2"}, [128 + 40]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-6-e"}, [128 + 81]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-6-i"}, [128 + 82]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-8-e"}, [128 + 84]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-8859-8-i"}, [128 + 85]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "UTF-8"}, [128 + 106]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "iso-10646-ucs-2"}, [2, 0x3, 0xe8]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "UTF-16"}, [2, 0x3, 0xf7]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "gb2312"}, [2, 0x7, 0xe9]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "big5"}, [2, 0x7, 0xea]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "koi8-r"}, [2, 0x8, 0x24]); michael@0: wsp_encode_test(WSP.WellKnownCharset, {charset: "windows-1252"}, [2, 0x8, 0xcc]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // michael@0: // Test target: ContentTypeValue michael@0: // michael@0: michael@0: //// ContentTypeValue.decodeConstrainedMedia //// michael@0: michael@0: add_test(function test_ContentTypeValue_decodeConstrainedMedia() { michael@0: function func(data) { michael@0: return WSP.ContentTypeValue.decodeConstrainedMedia(data); michael@0: } michael@0: michael@0: // Test for string-typed return value from ConstrainedEncoding michael@0: wsp_decode_test_ex(func, [65, 0], {media: "a", params: null}); michael@0: // Test for number-typed return value from ConstrainedEncoding michael@0: for(let ix = 0; ix ", a: "B"}} michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ContentTypeValue.decodeContentGeneralForm //// michael@0: michael@0: add_test(function test_ContentTypeValue_decodeContentGeneralForm() { michael@0: wsp_decode_test_ex(function(data) { michael@0: return WSP.ContentTypeValue.decodeContentGeneralForm(data); michael@0: }, [14, 0x3E | 0x80, 1, 0x0A, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0], michael@0: {media: "application/vnd.wap.mms-message", params: {start: "", a: "B"}} michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ContentTypeValue.decode //// michael@0: michael@0: add_test(function test_ContentTypeValue_decode() { michael@0: wsp_decode_test(WSP.ContentTypeValue, michael@0: [14, 0x3E | 0x80, 1, 0x0A, 60, 115, 109, 105, 108, 62, 0, 65, 0, 66, 0], michael@0: {media: "application/vnd.wap.mms-message", params: {start: "", a: "B"}} michael@0: ); michael@0: michael@0: wsp_decode_test(WSP.ContentTypeValue, [0x33 | 0x80], michael@0: {media: "application/vnd.wap.multipart.related", params: null} michael@0: ); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: //// ContentTypeValue.encodeConstrainedMedia //// michael@0: michael@0: add_test(function test_ContentTypeValue_encodeConstrainedMedia() { michael@0: function func(data, input) { michael@0: WSP.ContentTypeValue.encodeConstrainedMedia(data, input); michael@0: return data.array; michael@0: } michael@0: michael@0: // Test media type with additional parameters. michael@0: wsp_encode_test_ex(func, {media: "a", params: [{a: "b"}]}, null, "CodeError"); michael@0: wsp_encode_test_ex(func, {media: "no/such.type"}, michael@0: [110, 111, 47, 115, 117, 99, 104, 46, 116, 121, 112, 101, 0]); michael@0: for(let ix = 0; ix