diff options
Diffstat (limited to 'test/com')
-rw-r--r-- | test/com/isode/stroke/stringcodecs/HexifyTest.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/com/isode/stroke/stringcodecs/HexifyTest.java b/test/com/isode/stroke/stringcodecs/HexifyTest.java new file mode 100644 index 0000000..4d6dc0d --- /dev/null +++ b/test/com/isode/stroke/stringcodecs/HexifyTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon. + * All rights reserved. + */ +package com.isode.stroke.stringcodecs; + +import com.isode.stroke.base.ByteArray; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class HexifyTest { + + private ByteArray fix(int[] vals) { + byte[] fixed = new byte[vals.length]; + for (int i = 0; i < fixed.length; i++) { + fixed[i] = (byte) vals[i]; + } + return new ByteArray(fixed); + } + + @Test + public void testHexify() { + assertEquals("4206b23ca6b0a643d20d89b04ff58cf78b8096ed", Hexify.hexify(fix(new int[]{0x42, 0x06, 0xb2, 0x3c, 0xa6, 0xb0, 0xa6, 0x43, 0xd2, 0x0d, 0x89, 0xb0, 0x4f, 0xf5, 0x8c, 0xf7, 0x8b, 0x80, 0x96, 0xed}))); + } + + @Test + public void testHexify_Byte() { + assertEquals("b2", Hexify.hexify((byte) 0xb2)); + } + + @Test + public void testUnhexify() { + assertEquals("ffaf02", Hexify.hexify(Hexify.unhexify("ffaf02"))); + assertEquals(new ByteArray(fix(new int[]{0x01, 0x23, 0xf2})), Hexify.unhexify("0123f2")); + } +}; + |