1package com.android.bluetooth.tests;
2
3import java.io.ByteArrayInputStream;
4import java.io.ByteArrayOutputStream;
5import java.io.InputStream;
6import java.io.UnsupportedEncodingException;
7import java.text.SimpleDateFormat;
8import java.util.Calendar;
9import java.util.Date;
10
11import org.apache.http.message.BasicHeaderValueFormatter;
12
13import android.preference.PreferenceFragment;
14import android.test.AndroidTestCase;
15import android.util.Log;
16import android.view.Menu;
17import android.view.MenuItem;
18
19import com.android.bluetooth.map.BluetoothMapAppParams;
20import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
21import com.android.bluetooth.map.BluetoothMapSmsPdu;
22import com.android.bluetooth.map.BluetoothMapbMessage;
23import com.android.bluetooth.map.BluetoothMapbMessageMmsEmail;
24import com.android.bluetooth.map.BluetoothMapbMessageSms;
25import org.apache.http.message.BasicHeaderValueFormatter;
26import org.apache.http.message.BasicHeaderElement;
27
28/***
29 *
30 * Test cases for the bMessage class. (encoding and decoding)
31 *
32 */
33public class BluetoothMapbMessageTest extends AndroidTestCase {
34    protected static String TAG = "BluetoothMapbMessageTest";
35    protected static final boolean D = true;
36
37    public BluetoothMapbMessageTest() {
38        super();
39    }
40
41    /***
42     * Test encoding of a simple SMS text message (UTF8). This validates most parameters.
43     */
44    public void testSmsEncodeText() {
45        BluetoothMapbMessageSms msg = new BluetoothMapbMessageSms();
46        String str1 =
47                 "BEGIN:BMSG\r\n" +
48                    "VERSION:1.0\r\n" +
49                    "STATUS:UNREAD\r\n" +
50                    "TYPE:SMS_GSM\r\n" +
51                    "FOLDER:telecom/msg/inbox\r\n" +
52                    "BEGIN:VCARD\r\n" +
53                        "VERSION:3.0\r\n" +
54                        "FN:Casper Bonde\r\n" +
55                        "N:Bonde,Casper\r\n" +
56                        "TEL:+4512345678\r\n" +
57                        "TEL:+4587654321\r\n" +
58                        "EMAIL:casper@email.add\r\n" +
59                        "EMAIL:bonde@email.add\r\n" +
60                    "END:VCARD\r\n" +
61                    "BEGIN:BENV\r\n" +
62                        "BEGIN:VCARD\r\n" +
63                            "VERSION:3.0\r\n" +
64                            "FN:Jens Hansen\r\n" +
65                            "N:\r\n" +
66                            "TEL:+4512345678\r\n" +
67                            "TEL:+4587654321\r\n" +
68                            "EMAIL:casper@email.add\r\n" +
69                            "EMAIL:bonde@email.add\r\n" +
70                        "END:VCARD\r\n" +
71                        "BEGIN:BBODY\r\n" +
72                            "CHARSET:UTF-8\r\n" +
73                            "LENGTH:45\r\n" +
74                            "BEGIN:MSG\r\n" +
75                                "This is a short message\r\n" +
76                            "END:MSG\r\n" +
77                        "END:BBODY\r\n" +
78                    "END:BENV\r\n" +
79                 "END:BMSG\r\n";
80
81        String encoded;
82        String[] phone = {"+4512345678", "+4587654321"};
83        String[] email = {"casper@email.add", "bonde@email.add"};
84        msg.addOriginator("Bonde,Casper", "Casper Bonde", phone, email);
85        msg.addRecipient("", "Jens Hansen", phone, email);
86        msg.setFolder("inbox");
87        msg.setSmsBody("This is a short message");
88        msg.setStatus(false);
89        msg.setType(TYPE.SMS_GSM);
90        try {
91            encoded = new String(msg.encode());
92            if(D) Log.d(TAG, encoded);
93            assertTrue(str1.equals(encoded));
94        } catch (UnsupportedEncodingException e) {
95            Log.d(TAG, "Encoding failed.",e);
96            assertTrue("Encoding failed.", true);
97        }
98    }
99
100    /***
101     * Test native Deliver PDU encoding (decoding not possible), based on the example in the MAP 1.1 specification.
102     * The difference between this PDU, and the one in the specification:
103     *  - The invalid SC address 0191 is replaced with no address 00
104     *  - The "No more messages flag" is set (bit 2 in the second byte)
105     *  - The phone number type is changed from private 91 to international 81
106     *  - The time is changed to local time, since the time zone cannot be controlled through the API
107     */
108    public void testSmsEncodeNativeDeliverPdu() {
109        BluetoothMapbMessageSms msg = new BluetoothMapbMessageSms();
110        SimpleDateFormat format = new SimpleDateFormat("yyMMddHHmmss");
111        Date date = new Date(System.currentTimeMillis());
112        String timeStr = format.format(date); // Format to YYMMDDTHHMMSS UTC time
113        ByteArrayOutputStream scTime = new ByteArrayOutputStream(7);
114        StringBuilder scTimeSb = new StringBuilder();
115        byte[] timeChars;
116        try {
117            timeChars = timeStr.getBytes("US-ASCII");
118        } catch (UnsupportedEncodingException e1) {
119            assertTrue("Failed to extract bytes from string using US-ASCII", true);
120            return;
121        }
122
123        for(int i = 0, n = timeStr.length(); i < n; i+=2) {
124            scTime.write((timeChars[i+1]-0x30) << 4 | (timeChars[i]-0x30)); // Offset from ascii char to decimal value
125        }
126
127        Calendar cal = Calendar.getInstance();
128        int offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (15 * 60 * 1000); /* offset in quarters of an hour */
129        String offsetString;
130        if(offset < 0) {
131            offsetString = String.format("%1$02d", -(offset));
132            char[] offsetChars = offsetString.toCharArray();
133            scTime.write((offsetChars[1]-0x30) << 4 | 0x40 | (offsetChars[0]-0x30));
134        }
135        else {
136            offsetString = String.format("%1$02d", offset);
137            char[] offsetChars = offsetString.toCharArray();
138            scTime.write((offsetChars[1]-0x30) << 4 | (offsetChars[0]-0x30));
139        }
140        byte[] scTimeData = scTime.toByteArray();
141        for(int i = 0; i < scTimeData.length; i++) {
142            scTimeSb.append(Integer.toString((scTimeData[i] >> 4) & 0x0f,16)); // MS-nibble first
143            scTimeSb.append(Integer.toString( scTimeData[i]       & 0x0f,16));
144        }
145        if(D) Log.v(TAG, "Generated time string: " + scTimeSb.toString());
146        String expected =
147                 "BEGIN:BMSG\r\n" +
148                    "VERSION:1.0\r\n" +
149                    "STATUS:UNREAD\r\n" +
150                    "TYPE:SMS_GSM\r\n" +
151                    "FOLDER:telecom/msg/inbox\r\n" +
152                    "BEGIN:VCARD\r\n" +
153                        "VERSION:3.0\r\n" +
154                        "FN:Casper Bonde\r\n" +
155                        "N:Bonde,Casper\r\n" +
156                        "TEL:00498912345678\r\n" +
157                        "TEL:+4587654321\r\n" +
158                        "EMAIL:casper@email.add\r\n" +
159                        "EMAIL:bonde@email.add\r\n" +
160                    "END:VCARD\r\n" +
161                    "BEGIN:BENV\r\n" +
162                        "BEGIN:VCARD\r\n" +
163                            "VERSION:3.0\r\n" +
164                            "FN:Jens Hansen\r\n" +
165                            "N:\r\n" +
166                            "TEL:00498912345678\r\n" +
167                            "TEL:+4587654321\r\n" +
168                            "EMAIL:casper@email.add\r\n" +
169                            "EMAIL:bonde@email.add\r\n" +
170                        "END:VCARD\r\n" +
171                        "BEGIN:BBODY\r\n" +
172                            "ENCODING:G-7BIT\r\n" +
173                            "LENGTH:94\r\n" +
174                            "BEGIN:MSG\r\n" +
175                                "00040E81009498214365870000" + scTimeSb.toString() +
176                                "11CC32FD34079DDF20737A8E4EBBCF21\r\n" +
177                            "END:MSG\r\n" +
178                        "END:BBODY\r\n" +
179                    "END:BENV\r\n" +
180                 "END:BMSG\r\n";
181
182        String encoded;
183        String[] phone = {"00498912345678", "+4587654321"};
184        String[] email = {"casper@email.add", "bonde@email.add"};
185        msg.addOriginator("Bonde,Casper", "Casper Bonde", phone, email);
186        msg.addRecipient("", "Jens Hansen", phone, email);
187        msg.setFolder("inbox");
188        /* TODO: extract current time, and build the expected string */
189        msg.setSmsBodyPdus(BluetoothMapSmsPdu.getDeliverPdus("Let's go fishing!", "00498912345678", date.getTime()));
190        msg.setStatus(false);
191        msg.setType(TYPE.SMS_GSM);
192        try {
193            byte[] encodedBytes = msg.encode();
194//            InputStream is = new ByteArrayInputStream(encodedBytes);
195            encoded = new String(encodedBytes);
196//            BluetoothMapbMessage newMsg = BluetoothMapbMessage.parse(is, BluetoothMapAppParams.CHARSET_NATIVE);
197//            String decoded = ((BluetoothMapbMessageSms) newMsg).getSmsBody();
198            if(D) Log.d(TAG, "\nExpected: \n" + expected);
199            if(D) Log.d(TAG, "\nEncoded: \n" + encoded);
200//            if(D) Log.d(TAG, "\nDecoded: \n" + decoded);
201            assertTrue(expected.equalsIgnoreCase(encoded));
202        } catch (UnsupportedEncodingException e) {
203            Log.d(TAG, "Encoding failed.",e);
204            assertTrue("Encoding failed.", true);
205        }
206    }
207
208    /***
209     * Test native Submit PDU encoding and decoding, based on the example in the MAP 1.1 specification.
210     * The difference between this PDU, and the one in the specification:
211     *  - The invalid SC address 0191 is replaced with no address 00
212     *  - The PDU is converted to a submit PDU by adding the TP-MR and removing the service center time stamp.
213     *  - The phone number type is changed from private 91 to international 81
214     */
215    public void testSmsEncodeDecodeNativeSubmitPdu() {
216        BluetoothMapbMessageSms msg = new BluetoothMapbMessageSms();
217        String expected =
218                 "BEGIN:BMSG\r\n" +
219                    "VERSION:1.0\r\n" +
220                    "STATUS:UNREAD\r\n" +
221                    "TYPE:SMS_GSM\r\n" +
222                    "FOLDER:telecom/msg/outbox\r\n" +
223                    "BEGIN:VCARD\r\n" +
224                        "VERSION:3.0\r\n" +
225                        "FN:Casper Bonde\r\n" +
226                        "N:Bonde,Casper\r\n" +
227                        "TEL:00498912345678\r\n" +
228                        "TEL:+4587654321\r\n" +
229                        "EMAIL:casper@email.add\r\n" +
230                        "EMAIL:bonde@email.add\r\n" +
231                    "END:VCARD\r\n" +
232                    "BEGIN:BENV\r\n" +
233                        "BEGIN:VCARD\r\n" +
234                            "VERSION:3.0\r\n" +
235                            "FN:Jens Hansen\r\n" +
236                            "N:\r\n" +
237                            "TEL:00498912345678\r\n" +
238                            "TEL:+4587654321\r\n" +
239                            "EMAIL:casper@email.add\r\n" +
240                            "EMAIL:bonde@email.add\r\n" +
241                        "END:VCARD\r\n" +
242                        "BEGIN:BBODY\r\n" +
243                            "ENCODING:G-7BIT\r\n" +
244                            "LENGTH:82\r\n" +
245                            "BEGIN:MSG\r\n" + /*Length 11 */
246                                "0001000E8100949821436587000011CC32FD34079DDF20737A8E4EBBCF21\r\n" + /* Length 62 */
247                            "END:MSG\r\n" + /* Length 9 */
248                        "END:BBODY\r\n" +
249                    "END:BENV\r\n" +
250                 "END:BMSG\r\n";
251
252        String encoded;
253        String[] phone = {"00498912345678", "+4587654321"};
254        String[] email = {"casper@email.add", "bonde@email.add"};
255        msg.addOriginator("Bonde,Casper", "Casper Bonde", phone, email);
256        msg.addRecipient("", "Jens Hansen", phone, email);
257        msg.setFolder("outbox");
258        /* TODO: extract current time, and build the expected string */
259        msg.setSmsBodyPdus(BluetoothMapSmsPdu.getSubmitPdus("Let's go fishing!", "00498912345678"));
260        msg.setStatus(false);
261        msg.setType(TYPE.SMS_GSM);
262        try {
263            byte[] encodedBytes = msg.encode();
264            InputStream is = new ByteArrayInputStream(encodedBytes);
265            encoded = new String(encodedBytes);
266            BluetoothMapbMessage newMsg = BluetoothMapbMessage.parse(is, BluetoothMapAppParams.CHARSET_NATIVE);
267            String decoded = ((BluetoothMapbMessageSms) newMsg).getSmsBody();
268            if(D) Log.d(TAG, "\nCalling encoder on decoded message to log its content");
269            newMsg.encode();
270            if(D) Log.d(TAG, "\nExpected: \n" + expected);
271            if(D) Log.d(TAG, "\nEncoded: \n" + encoded);
272            if(D) Log.d(TAG, "\nDecoded: \n" + decoded);
273            assertTrue("The encoded bMessage do not match the expected.", expected.equalsIgnoreCase(encoded));
274            assertTrue("The decoded text is \"" + decoded + "\" - expected \"Let's go fishing!\"", decoded.equalsIgnoreCase("Let's go fishing!"));
275        } catch (UnsupportedEncodingException e) {
276            Log.d(TAG, "Encoding failed.",e);
277            assertTrue("Encoding failed.", true);
278        }
279    }
280
281    /***
282     * Test native Submit PDU encoding and decoding, based on the example in the MAP 1.1 specification.
283     * The difference between this PDU, and the one in the specification:
284     *  - The invalid SC address 0191 is replaced with no address 00
285     *  - The PDU is converted to a submit PDU by adding the TP-MR and removing the service center time stamp.
286     *  - The phone number type is changed from private 91 to international 81
287     */
288    public void testSmsEncodeDecodeNativeSubmitPduWithSc() {
289        BluetoothMapbMessageSms msg = new BluetoothMapbMessageSms();
290        String encoded =
291                 "BEGIN:BMSG\r\n" +
292                    "VERSION:1.0\r\n" +
293                    "STATUS:UNREAD\r\n" +
294                    "TYPE:SMS_GSM\r\n" +
295                    "FOLDER:telecom/msg/outbox\r\n" +
296                    "BEGIN:VCARD\r\n" +
297                        "VERSION:3.0\r\n" +
298                        "FN:Casper Bonde\r\n" +
299                        "N:Bonde,Casper\r\n" +
300                        "TEL:00498912345678\r\n" +
301                        "TEL:+4587654321\r\n" +
302                        "EMAIL:casper@email.add\r\n" +
303                        "EMAIL:bonde@email.add\r\n" +
304                    "END:VCARD\r\n" +
305                    "BEGIN:BENV\r\n" +
306                        "BEGIN:VCARD\r\n" +
307                            "VERSION:3.0\r\n" +
308                            "FN:Jens Hansen\r\n" +
309                            "N:\r\n" +
310                            "TEL:00498912345678\r\n" +
311                            "TEL:+4587654321\r\n" +
312                            "EMAIL:casper@email.add\r\n" +
313                            "EMAIL:bonde@email.add\r\n" +
314                        "END:VCARD\r\n" +
315                        "BEGIN:BBODY\r\n" +
316                            "ENCODING:G-7BIT\r\n" +
317                            "LENGTH:58 \r\n" +
318                            "BEGIN:MSG\r\n" + /*Length 11 */
319                                "018001000B912184254590F500000346F61B\r\n" + /* Length 38 */
320                            "END:MSG\r\n" + /* Length 9 */
321                        "END:BBODY\r\n" +
322                    "END:BENV\r\n" +
323                 "END:BMSG\r\n";
324        try {
325            String expected = "Flo";
326            InputStream is = new ByteArrayInputStream(encoded.getBytes("UTF-8"));
327            BluetoothMapbMessage newMsg = BluetoothMapbMessage.parse(is, BluetoothMapAppParams.CHARSET_NATIVE);
328            String decoded = ((BluetoothMapbMessageSms) newMsg).getSmsBody();
329            if(D) Log.d(TAG, "\nEncoded: \n" + encoded);
330            if(D) Log.d(TAG, "\nDecoded: \n" + decoded);
331            assertTrue("Decoded string (" + decoded + ") did not match expected (" + expected + ")", expected.equals(decoded));
332        } catch (UnsupportedEncodingException e) {
333            Log.d(TAG, "Encoding failed.",e);
334            assertTrue("Encoding failed.", false);
335        }
336    }
337
338    /***
339     * Validate that the folder is correctly truncated to 512 bytes, if a longer folder path
340     * is supplied.
341     */
342    public void testFolderLengthTruncation() {
343        String folder = "";
344        int levelCount = 0;
345        while(folder.length()<640)
346            folder += "/folder" + levelCount++;
347
348        String expected = folder.substring(folder.length()-512, folder.length());
349
350        BluetoothMapbMessageSms msg = new BluetoothMapbMessageSms();
351        msg.setFolder(folder);
352        msg.setStatus(false);
353        msg.setType(TYPE.SMS_GSM);
354
355        try {
356            byte[] encoded = msg.encode();
357            InputStream is = new ByteArrayInputStream(encoded);
358            if(D) Log.d(TAG, new String(encoded));
359            BluetoothMapbMessage newMsg = BluetoothMapbMessage.parse(is, BluetoothMapAppParams.CHARSET_UTF8);
360            assertTrue("Wrong length expected 512, got " + expected.length(), expected.length() == 512);
361            Log.d(TAG, "expected:           " + expected);
362            Log.d(TAG, "newMsg.getFolder(): " + newMsg.getFolder());
363            assertTrue("Folder string did not match", expected.equals(newMsg.getFolder()));
364
365        } catch (UnsupportedEncodingException e) {
366            Log.d(TAG, "Encoding failed.",e);
367            assertTrue("Encoding failed", false);
368        }
369    }
370
371    /***
372     * Test multipart message decoding.
373     */
374    public void testSmsMultipartDecode() {
375        BluetoothMapbMessageSms msg = new BluetoothMapbMessageSms();
376        String encoded =
377                 "BEGIN:BMSG\r\n" +
378                 "VERSION:1.0\r\n" +
379                 "STATUS:READ\r\n" +
380                 "TYPE:SMS_GSM\r\n" +
381                 "FOLDER:/telecom/msg/outbox\r\n" +
382                 "BEGIN:VCARD\r\n" +
383                 "VERSION:2.1\r\n" +
384                 "N:12485254094 \r\n" +
385                 "TEL:12485254094\r\n" +
386                 "END:VCARD\r\n" +
387                 "BEGIN:BENV\r\n" +
388                 "BEGIN:VCARD\r\n" +
389                 "VERSION:2.1\r\n" +
390                 "N:+12485254095 \r\n" +
391                 "TEL:+12485254095\r\n" +
392                 "END:VCARD\r\n" +
393                 "BEGIN:BBODY\r\n" +
394                 "ENCODING:G-7BIT\r\n" +
395                 "LENGTH:762\r\n" +
396                 "BEGIN:MSG\r\n" +
397                 "018041000B912184254590F50000A0050003010301A8E8F41C949E83C220F69B0E7A9B41F7B79C3C07D1DF20F35BDE068541E3B77B1CA697DD617A990C6A97E7F3F0B90C0ABBC9203ABA0C32A7E5733A889E6E9741F437888E2E83E66537B92C07A5DBED32391DA697D97990FB4D4F9BF3A07619B476BFEFA03B3A4C07E5DF7550585E06B9DF74D0BC2E2F83F2EF3A681C7683C86F509A0EBABFEB\r\n" +
398                 "END:MSG\r\n" +
399                 "BEGIN:MSG\r\n" +
400                 "018041000B912184254590F50000A0050003010302C820767A5D06D1D16550DA4D2FBBC96532485E1EA7E1E9B29B0E82B3CBE17919644EBBC9A0779D0EA2A3CB20735A3EA783E8E8B4FB0CA2BF41E437C8FDA683E6757919947FD741E3B01B447E83D274D0FD5D679341ECB7BD0C4AD341F7F01C44479741E6B47C4E0791C379D0DB0C6AE741F2F2BCDE2E83CC6F3928FFAECB41E57638CD06A5E7\r\n" +
401                 "END:MSG\r\n" +
402                 "BEGIN:MSG\r\n" +
403                 "018041000B912184254590F500001A050003010303DC6F3A685E979741F9771D340EBB41E437\r\n" +
404                 "END:MSG\r\n" +
405                 "END:BBODY\r\n" +
406                 "END:BENV\r\n" +
407                 "END:BMSG\r\n";
408        try {
409            InputStream is = new ByteArrayInputStream(encoded.getBytes("UTF-8"));
410            BluetoothMapbMessage newMsg = BluetoothMapbMessage.parse(is, BluetoothMapAppParams.CHARSET_NATIVE);
411            String decoded = ((BluetoothMapbMessageSms) newMsg).getSmsBody();
412            if(D) Log.d(TAG, "\nEncoded: \n" + encoded);
413            if(D) Log.d(TAG, "\nDecoded: \n" + decoded);
414        } catch (UnsupportedEncodingException e) {
415            Log.d(TAG, "Decoding failed.",e);
416            assertTrue("Decoding failed.", false);
417        }
418    }
419
420    /***
421     * Test encoding of a simple MMS text message (UTF8). This validates most parameters.
422     */
423    public void testMmsEncodeText() {
424        BluetoothMapbMessageMmsEmail msg = new BluetoothMapbMessageMmsEmail();
425        String str1 =
426                 "BEGIN:BMSG\r\n" +
427                    "VERSION:1.0\r\n" +
428                    "STATUS:UNREAD\r\n" +
429                    "TYPE:MMS\r\n" +
430                    "FOLDER:telecom/msg/inbox\r\n" +
431                    "BEGIN:VCARD\r\n" +
432                        "VERSION:3.0\r\n" +
433                        "FN:Casper Bonde\r\n" +
434                        "N:Bonde,Casper\r\n" +
435                        "TEL:+4512345678\r\n" +
436                        "TEL:+4587654321\r\n" +
437                        "EMAIL:casper@email.add\r\n" +
438                        "EMAIL:bonde@email.add\r\n" +
439                    "END:VCARD\r\n" +
440                    "BEGIN:BENV\r\n" +
441                        "BEGIN:VCARD\r\n" +
442                            "VERSION:3.0\r\n" +
443                            "FN:Jørn Hansen\r\n" +
444                            "N:\r\n" +
445                            "TEL:+4512345678\r\n" +
446                            "TEL:+4587654321\r\n" +
447                            "EMAIL:casper@email.add\r\n" +
448                            "EMAIL:bonde@email.add\r\n" +
449                        "END:VCARD\r\n" +
450                        "BEGIN:BBODY\r\n" +
451                            "CHARSET:UTF-8\r\n" +
452                            "LENGTH:45\r\n" +
453                            "BEGIN:MSG\r\n" +
454                                "This is a short message\r\n" +
455                            "END:MSG\r\n" +
456                        "END:BBODY\r\n" +
457                    "END:BENV\r\n" +
458                 "END:BMSG\r\n";
459
460        String encoded;
461        String[] phone = {"+4512345678", "+4587654321"};
462        String[] email = {"casper@email.add", "bonde@email.add"};
463        msg.addOriginator("Bonde,Casper", "Casper Bonde", phone, email);
464        msg.addRecipient("", "Jørn Hansen", phone, email);
465        msg.setFolder("inbox");
466        msg.setIncludeAttachments(false);
467        msg.addTo("Jørn Hansen", "bonde@email.add");
468        msg.addCc("Jens Hansen", "bonde@email.add");
469        msg.addFrom("Jørn Hansen", "bonde@email.add");
470        BluetoothMapbMessageMmsEmail.MimePart part = msg.addMimePart();
471        part.partName = "partNameText";
472        part.contentType ="dsfajfdlk/text/asdfafda";
473        try {
474            part.data = new String("This is a short message\r\n").getBytes("UTF-8");
475        }
476        catch (UnsupportedEncodingException e) {
477            if(D) Log.e(TAG, "UnsupportedEncodingException should never happen???", e);
478            assertTrue(false);
479        }
480
481        part = msg.addMimePart();
482        part.partName = "partNameimage";
483        part.contentType = "dsfajfdlk/image/asdfafda";
484        part.data = null;
485
486        msg.setStatus(false);
487        msg.setType(TYPE.MMS);
488        try {
489            encoded = new String(msg.encode());
490            if(D) Log.d(TAG, encoded);
491            assertTrue(str1.equals(encoded));
492        } catch (UnsupportedEncodingException e) {
493            Log.d(TAG, "Encoding failed.",e);
494            assertTrue("Encoding failed.", true);
495        }
496    }
497
498    public void testHeaderEncode() {
499        BasicHeaderElement header = new BasicHeaderElement("To","Jørgen <joergen@hest.com>");
500        String headerStr = BasicHeaderValueFormatter.formatHeaderElement(header, true, BasicHeaderValueFormatter.DEFAULT);
501        if(D) Log.i(TAG, "The encoded header: " + headerStr);
502    }
503
504}
505
506