public void testSplitText() { assertEquals( "Empty text should be split into one part (unported).", 1, GsmAlphabet.splitText("", false).length); assertEquals( "Empty text should be split into one part (ported).", 1, GsmAlphabet.splitText("", true).length); }
private void testStringToBytes(String text) { byte[] refBytes = new byte[400]; int cBytesLength = ReferenceGsmAlphabet.stringToBytes(text, refBytes); byte[] finalRefBytes = new byte[cBytesLength]; System.arraycopy(refBytes, 0, finalRefBytes, 0, cBytesLength); assertEquals("", finalRefBytes, GsmAlphabet.stringToBytes(text)); }
private void testBytesToString(byte[] bytes) { String cString = ReferenceGsmAlphabet.bytesToString(bytes); String myString = GsmAlphabet.bytesToString(bytes); try { myAssertEquals("Generated strings not equal.", myString, cString); } catch (ComparisonFailure c) { System.out.println("cString : " + cString); System.out.println("myString : " + myString); System.out.println("bytes : " + new String(bytes)); int minLen = Math.min(cString.length(), myString.length()); for (int i = 0; i < minLen; i++) { if (cString.charAt(i) != myString.charAt(i)) { System.out.println("Naughty Character Found:"); System.out.println(" c : " + cString.charAt(i) + "\t" + ((int) cString.charAt(i))); System.out.println(" my: " + myString.charAt(i) + "\t" + ((int) myString.charAt(i))); break; } } throw c; } }
/** * FIXME rename this test in line with renamed {@link GsmAlphabet#pduToText(String)} rename. * * @param pdu */ private void testPduToText(String pdu) { byte[] nonRefBytes = GsmAlphabet.pduToText(pdu); StringBuilder nonRefPdu = new StringBuilder(nonRefBytes.length); for (byte b : nonRefBytes) nonRefPdu.append((char) b); String referencePdu = ReferenceGsmAlphabet.pduToText(pdu); String nonRefPduString = nonRefPdu.toString(); for (int i = 0; i < referencePdu.length(); i++) { assertEquals( "Character " + i + "was different - expected '" + referencePdu + "' but was '" + nonRefPduString + "'", referencePdu.charAt(i), nonRefPdu.charAt(i)); } // Cunningly ignore the first character - the new implementation is correct, but the old one // was very nearly correct! // TODO update this testPduToText method, and the reference implementation, to the correct // implementation. }