View Javadoc
1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package net.sf.atmodem4j.core.gsm;
6   
7   /*
8    * #%L
9    * ATModem4J Core
10   * %%
11   * Copyright (C) 2009 - 2014 atmodem4j
12   * %%
13   * atmodem4j - Drivers for the AT modem - http://atmodem4j.sourceforge.net/
14   * Copyright (C) 2009-2014, atmodem4j.sf.net, and individual contributors as indicated
15   * by the @authors tag. See the copyright.txt in the distribution for a
16   * full listing of individual contributors.
17   * 
18   * This is free software; you can redistribute it and/or modify it
19   * under the terms of the GNU General Public License as
20   * published by the Free Software Foundation; either version 3 of
21   * the License, or (at your option) any later version.
22   * 
23   * This software is distributed in the hope that it will be useful,
24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26   * Lesser General Public License for more details.
27   * 
28   * You should have received a copy of the GNU Lesser General Public
29   * License along with this software; if not, write to the Free
30   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
31   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
32   * #L%
33   */
34  
35  import org.junit.After;
36  import org.junit.AfterClass;
37  import org.junit.Before;
38  import org.junit.BeforeClass;
39  import org.junit.Ignore;
40  import org.junit.Test;
41  import static org.junit.Assert.*;
42  
43  /**
44   *
45   * @author aploese
46   */
47  public class PduEncoderTest {
48  
49      public PduEncoderTest() {
50      }
51  
52      @BeforeClass
53      public static void setUpClass() throws Exception {
54      }
55  
56      @AfterClass
57      public static void tearDownClass() throws Exception {
58      }
59  
60      @Before
61      public void setUp() {
62      }
63  
64      @After
65      public void tearDown() {
66      }
67  
68      /**
69       * Single SMS 7 Bit Ascii coded.
70       */
71      @Test
72      public void testSingle7BitASCII() {
73          System.out.println("testSingle7BitASCII");
74          PduEncoder instance = new PduEncoder();
75          instance.setReceiverPhonenumber("491234567890");
76  //        instance.setMessageText("@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./:;<=>?¡"); //ÄÖÑܧ¿äöñüà"); //get7BitText(100));
77          instance.setMessageText("A|A|AAA");
78  //        instance.setMessageText("@@");
79          String[] pdus = instance.encodePdus();
80          assertEquals(1, pdus.length);
81          PduDecoder d = new PduDecoder();
82          assertEquals("A|A|AAA", d.decodeFromOctets(pdus[0]).getText());
83          assertEquals("0011000C919421436587090000AA09C10D30B801068341", pdus[0]);
84      }
85  
86      /**
87       * Single SMS 7 Bit Ascii coded.
88       */
89      @Test
90      public void testMulti7BitASCII() {
91          System.out.println("testSingle7BitASCII");
92          PduEncoder instance = new PduEncoder();
93          instance.setReceiverPhonenumber("491234567890");
94          StringBuilder sb = new StringBuilder();
95          for (int i = 0; i < 153; i++) {
96              sb.append('A');
97          }
98          for (int i = 0; i < 153; i++) {
99              sb.append('B');
100         }
101         sb.append('C');
102         instance.setMessageText(sb.toString());
103         String[] pdus = instance.encodePdus();
104         //TODO decode SMS and look for errors
105         PduDecoder d = new PduDecoder();
106         PduSubmit p = (PduSubmit)d.decodeFromOctets(pdus[0]);
107         assertEquals(3, pdus.length);
108         assertEquals("+491234567890", p.getDestinationAddress());
109         assertEquals(153, p.getText().length());
110         assertEquals("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", p.getText());
111         assertEquals(
112                 "0051000C919421436587090000AAA005000300030182C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683",
113                 pdus[0]);
114         assertEquals(
115                 "0051000C919421436587090000AAA00500030103028442A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A8542A15028140A85",
116                 pdus[1]);
117         assertEquals(
118                 "0051000C919421436587090000AA0805000302030386", pdus[2]);
119     }
120     @Test
121     public void testMulti7BitASCII_1() {
122         System.out.println("testSingle7BitASCII_1");
123         PduEncoder instance = new PduEncoder();
124         instance.setReceiverPhonenumber("491234567890");
125         String text = "Abacabacabacabacabac abacabacabacabacabac effeeffeeffeeffeeffe effeeffeeffeeffeeffe highhighhighhighhigh highhighhighhighhigh llllllllllllllllllll llllllllllllllllllll mommmommmommmommmomm mommmommmommmommmomm pppppppppppppppppppp pppppppppppppppppppp tuttuttuttuttuttuttu tuttuttuttuttuttuttu wwwwwwwwwwwwwwwwwwzw wwwwwwwwwwwwwwwwwwzw                      abacabacabacabacabac effeeffeeffee mommmommmommnon ";
126         instance.setMessageText(text);
127         String[] pdus = instance.encodePdus();
128         assertEquals(
129                 "0051000C919421436587090000AAA005000300030182E2F0382C0E8FC3E2F0382C0E8FC3E2F018141687C76171781C1687C76171781C1687C7A0B2D95C2E9BCDE5B2D95C2E9BCDE5B2D95C0695CDE672D96C2E97CDE672D96C2E97CDE632089D3EA3D1E9331A9D3EA3D1E9331A9D3EA341E8F4198D4E9FD1E8F4198D4E9FD1E8F4190D62B3D96C369BCD66B3D96C369BCD66B3D96C109BCD66B3D9",
130                 pdus[0]);
131         assertEquals(
132                 "0051000C919421436587090000AAA0050003010302D86C369BCD66B3D96C369BCD06B5DFED76FBDD6EB7DFED76FBDD6EB7DFED36A8FD6EB7DBEF76BBFD6EB7DBEF76BBFD6EB74170381C0E87C3E170381C0E87C3E170381C0E82C3E170381C0E87C3E170381C0E87C3E17010BD4EA7D7E9F43A9D5EA7D3EB747A9D4EAF83E8753ABD4EA7D7E9F43A9D5EA7D3EB747A1D74BFDFEFF7FBFD7EBFDFEF",
133                 pdus[1]);
134         assertEquals(
135                 "0051000C919421436587090000AA6D050003020303EEF7FBFD7ED7DF41F7FBFD7EBFDFEFF7FBFD7EBFDFEFF7BBFE0E02814020100804028140201008040281402050581C1E87C5E171581C1E87C5E171581C1E83CA6673B96C3697CB6673B90C6ABFDBEDF6BBDD6EBFDB6DF7DB0D02", pdus[2]);
136     }
137 
138 
139     /**
140      * Test of getMessageText method, of class PduEncoder.
141      */
142     @Ignore
143     @Test
144     public void testGetMessageText() {
145         System.out.println("getMessageText");
146         PduEncoder instance = new PduEncoder();
147         String expResult = "";
148         String result = instance.getMessageText();
149         assertEquals(expResult, result);
150         // TODO review the generated test code and remove the default call to fail.
151         fail("The test case is a prototype.");
152     }
153 
154     /**
155      * Test of setMessageText method, of class PduEncoder.
156      */
157     @Ignore
158     @Test
159     public void testSetMessageText() {
160         System.out.println("setMessageText");
161         String messageText = "";
162         PduEncoder instance = new PduEncoder();
163         instance.setMessageText(messageText);
164         // TODO review the generated test code and remove the default call to fail.
165         fail("The test case is a prototype.");
166     }
167 
168     /**
169      * Test of getReceiverPhonenumber method, of class PduEncoder.
170      */
171     @Ignore
172     @Test
173     public void testGetReceiverPhonenumber() {
174         System.out.println("getReceiverPhonenumber");
175         PduEncoder instance = new PduEncoder();
176         String expResult = "";
177         String result = instance.getReceiverPhonenumber();
178         assertEquals(expResult, result);
179         // TODO review the generated test code and remove the default call to fail.
180         fail("The test case is a prototype.");
181     }
182 
183     /**
184      * Test of setReceiverPhonenumber method, of class PduEncoder.
185      */
186     @Ignore
187     @Test
188     public void testSetReceiverPhonenumber() {
189         System.out.println("setReceiverPhonenumber");
190         String receiverPhonenumber = "";
191         PduEncoder instance = new PduEncoder();
192         instance.setReceiverPhonenumber(receiverPhonenumber);
193         // TODO review the generated test code and remove the default call to fail.
194         fail("The test case is a prototype.");
195     }
196 
197     private String get7BitText(int i) {
198         StringBuilder sb = new StringBuilder(i);
199         for (int j = 0; j < i; j++) {
200             sb.append(Entry7BitEncoding.table[j % Entry7BitEncoding.table.length].c);
201         }
202         return sb.toString();
203     }
204 
205 }