use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testAvailable.
/**
* available() method testing. Tests that the method always return 0.
*/
public void testAvailable() throws Exception {
byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
TestInputStream tis = new TestInputStream(data);
CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
assertEquals("The returned by available() method value " + "should be 0.", cis.available(), 0);
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testRead1.
/**
* read() method testing. Tests that method returns the correct value
* (related to the InputStream) and that it returns -1 at the end of stream.
*/
public void testRead1() throws Exception {
byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
TestInputStream tis = new TestInputStream(data);
CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
byte res;
for (int i = 0; i < data.length; i++) {
if ((res = (byte) cis.read()) != data[i]) {
fail("read() returned the incorrect value. " + "Expected: " + data[i] + ", Got: " + res + ".");
}
}
if (cis.read() != -1) {
fail("read() should return -1 at the end of the stream.");
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testRead2.
/**
* read(byte[] b) method testing. Tests that method returns the correct
* value (related to the InputStream) and that it returns -1 at the end of
* stream.
*/
public void testRead2() throws Exception {
byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
TestInputStream tis = new TestInputStream(data);
CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
int expected = data.length;
byte[] result = new byte[expected];
// index into the data array (to check the got data)
int ind = 0;
// the number of got bytes
int got = cis.read(result);
while (true) {
for (int j = 0; j < got - ind; j++) {
if (result[j] != data[ind + j]) {
fail("read(byte[] b) returned incorrect data.");
}
}
if (got == expected) {
break;
} else if (got > expected) {
fail("The data returned by read(byte[] b) " + "is larger than expected.");
} else {
ind = got;
got += cis.read(result);
}
}
if (cis.read(result) != -1) {
fail("read(byte[] b) should return -1 " + "at the end of the stream.");
}
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testClose.
/**
* close() method testing. Tests that the method calls the close()
* method of the underlying input stream.
*/
public void testClose() throws Exception {
byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
TestInputStream tis = new TestInputStream(data);
CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
cis.close();
assertTrue("The close() method should call the close() method " + "of its underlying input stream.", tis.wasClosed());
}
use of javax.crypto.NullCipher in project robovm by robovm.
the class CipherInputStream1Test method testMarkSupported.
/**
* markSupported() method testing. Tests that mark is not supported.
*/
public void testMarkSupported() {
byte[] data = new byte[] { -127, -100, -50, -10, -1, 0, 1, 10, 50, 127 };
TestInputStream tis = new TestInputStream(data);
CipherInputStream cis = new CipherInputStream(tis, new NullCipher());
assertFalse("The returned by markSupported() method value " + "should be false.", cis.markSupported());
}
Aggregations