Search in sources :

Example 1 with BrokenTest

use of dalvik.annotation.BrokenTest in project robovm by robovm.

the class OldNumberFormatTest method test_parseLjava_lang_String.

@BrokenTest("Fails in CTS, passes in CoreTestRunner")
public void test_parseLjava_lang_String() {
    NumberFormat nf1 = NumberFormat.getInstance();
    try {
        assertEquals("Test1: NumberFormat.getInstance().parse(\"1234567890.1\") returned wrong number", new Double(1234567890.1), nf1.parse("1234567890.1"));
    } catch (java.text.ParseException pe) {
        fail("java.text.ParseException is thrown for 1234567890.1");
    }
    try {
        assertEquals("Test2: NumberFormat.getInstance().parse(\"-1234567890.1\") returned wrong number", new Double(-1234567890.1), nf1.parse("-1,234,567,890.1"));
    } catch (java.text.ParseException pe) {
        fail("java.text.ParseException is thrown for -1,234,567,890.1");
    }
    try {
        nf1.parse("@1,234,567,8901");
        fail("java.text.ParseException is not thrown for 1,234,567,890z1");
    } catch (java.text.ParseException pe) {
    // expected
    }
    nf1 = NumberFormat.getPercentInstance();
    try {
        assertEquals("Test3: NumberFormat.getPercentInstance().parse(\"-123%\") returned wrong number", new Double(-1.23), nf1.parse("-123%"));
    } catch (java.text.ParseException pe) {
        fail("java.text.ParseException is thrown for -123%");
    }
    nf1 = NumberFormat.getCurrencyInstance();
    try {
        assertEquals("Test4: NumberFormat.getCurrencyInstance().parse(\"$123\") returned wrong number", new Long(123), nf1.parse("$123"));
    } catch (java.text.ParseException pe) {
        fail("java.text.ParseException is thrown for $123");
    }
    try {
        assertEquals("Test4: NumberFormat.getCurrencyInstance().parse(\"$123abc\") returned wrong number", new Long(123), nf1.parse("$123abc"));
    } catch (java.text.ParseException pe) {
        fail("java.text.ParseException is thrown for $123");
    }
    nf1 = NumberFormat.getIntegerInstance();
    try {
        assertEquals("Test5: NumberFormat.getIntegerInstance().parse(\"-123.123\") returned wrong number", nf1.parseObject("-123.123"), nf1.parse("-123.123"));
    } catch (java.text.ParseException pe) {
        fail("java.text.ParseException is thrown for $123");
    }
}
Also used : ParseException(java.text.ParseException) NumberFormat(java.text.NumberFormat) BrokenTest(dalvik.annotation.BrokenTest)

Example 2 with BrokenTest

use of dalvik.annotation.BrokenTest in project robovm by robovm.

the class OldSocketChannelTest method test_writeLjava_nio_ByteBuffer_Nonblocking_HugeData.

@BrokenTest("Occasionally fail in CTS, but works in CoreTestRunner")
public void test_writeLjava_nio_ByteBuffer_Nonblocking_HugeData() throws IOException {
    // initialize write content
    ByteBuffer writeContent = ByteBuffer.allocate(CAPACITY_HUGE);
    for (int i = 0; i < CAPACITY_HUGE; i++) {
        writeContent.put((byte) i);
    }
    writeContent.flip();
    // establish connection
    channel1.connect(localAddr1);
    Socket acceptedSocket = server1.accept();
    channel1.configureBlocking(false);
    int writtenTotalCount = 0;
    int writtenCount = 1;
    long startTime = System.currentTimeMillis();
    // use SocketChannel.write(ByteBuffer) to try to write CAPACITY_HUGE bytes
    while (writtenTotalCount < CAPACITY_HUGE && writtenCount > 0) {
        writtenCount = channel1.write(writeContent);
        if (writtenCount == 0 && writtenTotalCount < CAPACITY_HUGE) {
            assertEquals(0, channel1.write(writeContent));
            break;
        }
        writtenTotalCount += writtenCount;
        // if the channel could not finish writing in TIMEOUT ms, the
        // test fails. It is used to guarantee the test never hangs even
        // if there are bugs of SocketChannel implementation.
        assertTimeout(startTime, TIMEOUT);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) BrokenTest(dalvik.annotation.BrokenTest)

Example 3 with BrokenTest

use of dalvik.annotation.BrokenTest in project robovm by robovm.

the class DHPublicKeyTest method test_getParams.

@BrokenTest("Too slow - disabling for now")
public void test_getParams() throws Exception {
    KeyPairGenerator kg = KeyPairGenerator.getInstance("DH");
    kg.initialize(1024);
    KeyPair kp1 = kg.genKeyPair();
    KeyPair kp2 = kg.genKeyPair();
    DHPublicKey pk1 = (DHPublicKey) kp1.getPublic();
    DHPublicKey pk2 = (DHPublicKey) kp2.getPublic();
    assertTrue(pk1.getY().getClass().getCanonicalName().equals("java.math.BigInteger"));
    assertTrue(pk2.getParams().getClass().getCanonicalName().equals("javax.crypto.spec.DHParameterSpec"));
    assertFalse(pk1.equals(pk2));
    assertTrue(pk1.getY().equals(pk1.getY()));
}
Also used : KeyPair(java.security.KeyPair) DHPublicKey(javax.crypto.interfaces.DHPublicKey) KeyPairGenerator(java.security.KeyPairGenerator) BrokenTest(dalvik.annotation.BrokenTest)

Example 4 with BrokenTest

use of dalvik.annotation.BrokenTest in project robovm by robovm.

the class OldDHTest method testDHGen.

@BrokenTest("Suffers from DH slowness, disabling for now")
public void testDHGen() throws Exception {
    KeyPairGenerator gen = null;
    try {
        gen = KeyPairGenerator.getInstance("DH");
    } catch (NoSuchAlgorithmException e) {
        fail(e.getMessage());
    }
    AlgorithmParameterGenerator algorithmparametergenerator = AlgorithmParameterGenerator.getInstance("DH");
    algorithmparametergenerator.init(1024, new SecureRandom());
    AlgorithmParameters algorithmparameters = algorithmparametergenerator.generateParameters();
    DHParameterSpec dhparameterspec = algorithmparameters.getParameterSpec(DHParameterSpec.class);
    //gen.initialize(1024);
    gen.initialize(dhparameterspec);
    KeyPair key = gen.generateKeyPair();
}
Also used : KeyPair(java.security.KeyPair) AlgorithmParameterGenerator(java.security.AlgorithmParameterGenerator) SecureRandom(java.security.SecureRandom) DHParameterSpec(javax.crypto.spec.DHParameterSpec) KeyPairGenerator(java.security.KeyPairGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AlgorithmParameters(java.security.AlgorithmParameters) BrokenTest(dalvik.annotation.BrokenTest)

Example 5 with BrokenTest

use of dalvik.annotation.BrokenTest in project robovm by robovm.

the class OldKeyPairGeneratorTestDH method testKeyPairGenerator.

@BrokenTest("Takes ages due to DH computations. Disabling for now.")
public void testKeyPairGenerator() throws NoSuchAlgorithmException {
    KeyPairGenerator generator = KeyPairGenerator.getInstance("DH");
    generator.initialize(1024);
    KeyPair keyPair = generator.generateKeyPair();
    assertNotNull("no keypair generated", keyPair);
    assertNotNull("no public key generated", keyPair.getPublic());
    assertNotNull("no private key generated", keyPair.getPrivate());
    new KeyAgreementHelper("DH").test(keyPair);
}
Also used : KeyPair(java.security.KeyPair) KeyPairGenerator(java.security.KeyPairGenerator) KeyAgreementHelper(tests.security.KeyAgreementHelper) BrokenTest(dalvik.annotation.BrokenTest)

Aggregations

BrokenTest (dalvik.annotation.BrokenTest)7 KeyPair (java.security.KeyPair)3 KeyPairGenerator (java.security.KeyPairGenerator)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 JarURLConnection (java.net.JarURLConnection)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ByteBuffer (java.nio.ByteBuffer)1 AlgorithmParameterGenerator (java.security.AlgorithmParameterGenerator)1 AlgorithmParameters (java.security.AlgorithmParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SecureRandom (java.security.SecureRandom)1 PKIXParameters (java.security.cert.PKIXParameters)1 NumberFormat (java.text.NumberFormat)1