1 package be
.nikiroo
.utils
.test_code
;
3 import be
.nikiroo
.utils
.CryptUtils
;
4 import be
.nikiroo
.utils
.test
.TestCase
;
5 import be
.nikiroo
.utils
.test
.TestLauncher
;
7 class CryptUtilsTest
extends TestLauncher
{
9 private CryptUtils crypt
;
11 public CryptUtilsTest(String
[] args
) {
12 super("CryptUtils test", args
);
14 String longKey
= "some long string with more than 128 bits (=32 bytes) of data";
16 addSeries(new CryptUtilsTest(args
, "Manual input wuth NULL key", null,
18 addSeries(new CryptUtilsTest(args
, "Streams with NULL key", null, true));
20 addSeries(new CryptUtilsTest(args
, "Manual input with emptykey", "", 1));
21 addSeries(new CryptUtilsTest(args
, "Streams with empty key", "", true));
23 addSeries(new CryptUtilsTest(args
, "Manual input with long key",
25 addSeries(new CryptUtilsTest(args
, "Streams with long key", longKey
,
30 protected void addTest(final TestCase test
) {
31 super.addTest(new TestCase(test
.getName()) {
33 public void test() throws Exception
{
38 public void setUp() throws Exception
{
39 crypt
= new CryptUtils(key
);
44 public void tearDown() throws Exception
{
51 private CryptUtilsTest(String
[] args
, String title
, String key
,
52 @SuppressWarnings("unused") int dummy
) {
56 final String longData
= "Le premier jour, Le Grand Barbu dans le cloud fit la lumière, et il vit que c'était bien. Ou quelque chose comme ça. Je préfère la Science-Fiction en général, je trouve ça plus sain :/";
58 addTest(new TestCase("Short") {
60 public void test() throws Exception
{
62 byte[] encrypted
= crypt
.encrypt(orig
);
63 String decrypted
= crypt
.decrypts(encrypted
);
65 assertEquals(orig
, decrypted
);
69 addTest(new TestCase("Short, base64") {
71 public void test() throws Exception
{
73 String encrypted
= crypt
.encrypt64(orig
, false);
74 String decrypted
= crypt
.decrypt64s(encrypted
, false);
76 assertEquals(orig
, decrypted
);
80 addTest(new TestCase("Empty") {
82 public void test() throws Exception
{
84 byte[] encrypted
= crypt
.encrypt(orig
);
85 String decrypted
= crypt
.decrypts(encrypted
);
87 assertEquals(orig
, decrypted
);
91 addTest(new TestCase("Empty, base64") {
93 public void test() throws Exception
{
95 String encrypted
= crypt
.encrypt64(orig
, false);
96 String decrypted
= crypt
.decrypt64s(encrypted
, false);
98 assertEquals(orig
, decrypted
);
102 addTest(new TestCase("Long") {
104 public void test() throws Exception
{
105 String orig
= longData
;
106 byte[] encrypted
= crypt
.encrypt(orig
);
107 String decrypted
= crypt
.decrypts(encrypted
);
109 assertEquals(orig
, decrypted
);
113 addTest(new TestCase("Long, base64") {
115 public void test() throws Exception
{
116 String orig
= longData
;
117 String encrypted
= crypt
.encrypt64(orig
, false);
118 String decrypted
= crypt
.decrypt64s(encrypted
, false);
120 assertEquals(orig
, decrypted
);
125 private CryptUtilsTest(String
[] args
, String title
, String key
,
126 @SuppressWarnings("unused") boolean dummy
) {
130 addTest(new TestCase("TODO: Make some tests with the Streams") {
132 public void test() throws Exception
{