Example usage for org.bouncycastle.util Arrays areEqual

List of usage examples for org.bouncycastle.util Arrays areEqual

Introduction

In this page you can find the example usage for org.bouncycastle.util Arrays areEqual.

Prototype

public static boolean areEqual(short[] a, short[] b) 

Source Link

Usage

From source file:net.sf.dynamicreports.test.jasper.component.Image2Test.java

License:Open Source License

@Override
public void test() {
    super.test();

    numberOfPagesTest(2);//  ww w  . jav  a2 s  .c  o  m

    try {
        JRPrintImage jrImage = (JRPrintImage) getElementAt("pageHeader.image1", 0);
        byte[] imageData1 = jrImage.getRenderable().getImageData(DefaultJasperReportsContext.getInstance());
        jrImage = (JRPrintImage) getElementAt("pageHeader.image1", 1);
        byte[] imageData2 = jrImage.getRenderable().getImageData(DefaultJasperReportsContext.getInstance());
        Assert.assertTrue("image data", Arrays.areEqual(imageData1, imageData2));
        Assert.assertEquals("image horizontal alignment", HorizontalAlignEnum.CENTER,
                jrImage.getHorizontalAlignmentValue());
    } catch (JRException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:net.shibboleth.idp.attribute.resolver.spring.dc.StoredIDDataConnectorParserTest.java

License:Open Source License

@Test
public void withSalt() throws ComponentInitializationException {
    StoredIDDataConnector connector = getDataConnector("stored.xml", StoredIDDataConnector.class);

    Assert.assertEquals(connector.getId(), "stored");
    Assert.assertEquals(connector.getSourceAttributeId(), "theSourceRemainsTheSame");
    Assert.assertEquals(connector.getGeneratedAttributeId(), "jenny");
    Assert.assertEquals(connector.getSalt(), "abcdefghijklmnopqrst".getBytes());
    Assert.assertEquals(connector.getTransactionRetries(), 5);
    Assert.assertEquals(connector.getFailFast(), false);
    Assert.assertTrue(/*from  w  w  w  .ja v  a 2  s  .co m*/
            Arrays.areEqual(connector.getRetryableErrors().toArray(), new String[] { "25000", "25001" }));

    connector.initialize();
}

From source file:net.yacy.visualization.CircleToolTest.java

License:Open Source License

/**
 * Check circle function consistency when run on multiple concurrent threads.
 *
 * @throws Exception when an unexpected error occurred
 *//*  w w w.  jav  a2 s.  c o  m*/
@Test
public void testCircleConcurrentConsistency() throws Exception {
    final int concurrency = 20;
    final int side = 600;
    final String ext = "png";

    final Callable<byte[]> drawTask = () -> {
        final RasterPlotter raster = new RasterPlotter(side, side, RasterPlotter.DrawMode.MODE_SUB, "FFFFFF");
        for (int radius = side / 4; radius < side / 2; radius++) {
            raster.setColor(RasterPlotter.GREEN);
            CircleTool.circle(raster, side / 2, side / 2, radius, 100);
            raster.setColor(RasterPlotter.RED);
            CircleTool.circle(raster, side / 2, side / 2, radius, 0, 45);
        }

        final EncodedImage image = new EncodedImage(raster, ext, true);
        return image.getImage().getBytes();
    };

    /* Generate a reference image without concurrency */
    CircleTool.clearcache();
    final byte[] refImageBytes = drawTask.call();

    /* Write the reference image to the file system to enable manual visual check */
    final Path outputPath = Paths.get(System.getProperty("java.io.tmpdir", ""), "CircleToolTest." + ext);
    try {
        Files.write(outputPath, refImageBytes);
        System.out.println("Wrote CircleTool.circle() test image to file " + outputPath.toAbsolutePath());
    } catch (final IOException e) {
        /*
         * Even if output file writing failed we do not make the test fail as this is
         * not the purpose of the test
         */
        e.printStackTrace();
    }

    /*
     * Generate the same image multiple times in concurrent threads without initial
     * cache
     */
    CircleTool.clearcache();
    final ExecutorService executor = Executors.newFixedThreadPool(concurrency);
    final ArrayList<Future<byte[]>> futures = new ArrayList<>();
    for (int i = 0; i < concurrency; i++) {
        futures.add(executor.submit(drawTask));
    }
    try {
        for (final Future<byte[]> future : futures) {
            /* Check that all concurrently generated images are equal to the reference */
            final byte[] imageBytes = future.get();
            if (!Arrays.areEqual(refImageBytes, imageBytes)) {
                /* Write the image in error to file system to enable manual visual check */
                final Path errOutputPath = Paths.get(System.getProperty("java.io.tmpdir", ""),
                        "CircleToolTestError." + ext);
                try {
                    Files.write(errOutputPath, imageBytes);
                    System.out.println(
                            "Wrote CircleTool.circle() error image to file " + errOutputPath.toAbsolutePath());
                } catch (final IOException e) {
                    e.printStackTrace();
                }
                Assert.fail();
            }
        }
    } finally {
        executor.shutdown();
    }
}

From source file:org.apache.drill.test.rowSet.RowSetComparison.java

License:Apache License

private void verifyScalar(String label, ScalarReader ec, ScalarReader ac) {
    assertEquals(label + " - value type", ec.valueType(), ac.valueType());
    if (ec.isNull()) {
        assertTrue(label + " - column not null", ac.isNull());
        return;// w w w  .  j  av a2 s.  c  o m
    }
    if (!ec.isNull()) {
        assertTrue(label + " - column is null", !ac.isNull());
    }

    switch (ec.valueType()) {
    case BYTES:
        byte expected[] = ac.getBytes();
        byte actual[] = ac.getBytes();
        assertEquals(label + " - byte lengths differ", expected.length, actual.length);
        assertTrue(label, Arrays.areEqual(expected, actual));
        break;
    default:
        assertEquals(label, getScalar(ec), getScalar(ac));
    }
}

From source file:org.apache.drill.test.rowSet.RowSetUtilities.java

License:Apache License

public static void assertEqualValues(String msg, ValueType type, Object expectedObj, Object actualObj) {
    switch (type) {
    case BYTES: {
        byte expected[] = (byte[]) expectedObj;
        byte actual[] = (byte[]) actualObj;
        assertEquals(msg + " - byte lengths differ", expected.length, actual.length);
        assertTrue(msg, Arrays.areEqual(expected, actual));
        break;//  www  .j a  v  a  2s .  c o m
    }
    case DOUBLE:
        assertEquals(msg, (double) expectedObj, (double) actualObj, 0.0001);
        break;
    case INTEGER:
    case LONG:
    case STRING:
    case DECIMAL:
        assertEquals(msg, expectedObj, actualObj);
        break;
    case PERIOD: {
        Period expected = (Period) expectedObj;
        Period actual = (Period) actualObj;
        assertEquals(msg, expected.normalizedStandard(), actual.normalizedStandard());
        break;
    }
    default:
        throw new IllegalStateException("Unexpected type: " + type);
    }
}

From source file:org.apache.drill.vector.TestToNullable.java

License:Apache License

@SuppressWarnings("resource")
@Test/*ww w .  ja v a 2s.c  om*/
public void testVariableWidth() {
    MaterializedField nonNullableSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR, DataMode.REQUIRED);
    VarCharVector nonNullableVector = new VarCharVector(nonNullableSchema, fixture.allocator());
    VarCharVector.Mutator mutator = nonNullableVector.getMutator();
    nonNullableVector.allocateNew(100, 20);
    byte value[] = new byte[20];
    for (int i = 0; i < 100; i++) {
        Arrays.fill(value, (byte) ('A' + i % 26));
        mutator.setSafe(i, value);
    }
    mutator.setValueCount(100);

    MaterializedField nullableVarCharSchema = SchemaBuilder.columnSchema("a", MinorType.VARCHAR,
            DataMode.OPTIONAL);
    NullableVarCharVector nullableVector = new NullableVarCharVector(nullableVarCharSchema,
            fixture.allocator());

    nonNullableVector.toNullable(nullableVector);

    assertEquals(0, nonNullableVector.getAccessor().getValueCount());
    NullableVarCharVector.Accessor nullableAccessor = nullableVector.getAccessor();
    assertEquals(100, nullableAccessor.getValueCount());
    for (int i = 0; i < 100; i++) {
        assertFalse(nullableAccessor.isNull(i));
        Arrays.fill(value, (byte) ('A' + i % 26));
        assertTrue(Arrays.areEqual(value, nullableAccessor.get(i)));
    }

    nullableVector.clear();

    // Don't clear the nonNullableVector, it should be empty.
    // If it is not, the test will fail with a memory leak error.
}

From source file:org.apache.harmony.crypto.tests.javax.crypto.func.KeyAgreementThread.java

License:Apache License

@Override
public void test() throws Exception {
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DH");
    apg.init(1024, new SecureRandom());
    AlgorithmParameters ap = apg.generateParameters();
    DHParameterSpec ps = ap.getParameterSpec(DHParameterSpec.class);

    KeyAgreementGen kag1 = new KeyAgreementGen(ps);
    KeyAgreementGen kag2 = new KeyAgreementGen(ps);

    byte[] bArray1 = kag1.getPublicKeyBytes();
    byte[] bArray2 = kag2.getPublicKeyBytes();

    byte[] sk1 = kag1.getSecretKey(algName, bArray2);
    byte[] sk2 = kag2.getSecretKey(algName, bArray1);

    if (Arrays.areEqual(sk1, sk2) == false) {
        throw new Exception("Generated keys are not the same");
    }/*from  w  w  w  . ja v a 2  s .co m*/
}

From source file:org.ccnx.ccn.io.content.ConfigSlice.java

License:Open Source License

public boolean equals(ConfigSlice otherSlice) {
    return Arrays.areEqual(this.getHash(), otherSlice.getHash());
}

From source file:org.ccnx.ccn.io.content.EncodableObjectTest.java

License:Open Source License

@Test
public void testSave() {
    Log.info(Log.FAC_TEST, "Starting testSave");

    EncodableCollectionData ecd0 = new EncodableCollectionData(empty);
    EncodableCollectionData ecd1 = new EncodableCollectionData(small1);
    EncodableCollectionData ecd2 = new EncodableCollectionData(small1);
    EncodableCollectionData ecd3 = new EncodableCollectionData(big);

    ByteArrayOutputStream baos0 = new ByteArrayOutputStream();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
    ByteArrayOutputStream baos3 = new ByteArrayOutputStream();

    try {/*from   w  w  w.  j a  v a  2s.  c om*/
        ecd0.save(baos0);
        Assert.assertFalse(baos0.toByteArray().length == 0);
        System.out.println("Saved empty Collection, length: " + baos0.toByteArray().length);
        ecd1.save(baos);
        ecd2.save(baos2); // will this save? currently not, should it?
        Assert.assertArrayEquals("Serializing two versions of same content should produce same output",
                baos.toByteArray(), baos2.toByteArray());
        ecd3.save(baos3);
        boolean be = Arrays.areEqual(baos.toByteArray(), baos3.toByteArray());
        Assert.assertFalse("Two different objects shouldn't have matching output.", be);
        System.out.println("Saved two collection datas, lengths " + baos.toByteArray().length + " and "
                + baos3.toByteArray().length);
    } catch (IOException e) {
        fail("IOException! " + e.getMessage());
    }

    Log.info(Log.FAC_TEST, "Completed testSave");
}

From source file:org.ccnx.ccn.io.content.EncodableObjectTest.java

License:Open Source License

@Test
public void testUpdate() {
    Log.info(Log.FAC_TEST, "Starting testUpdate");

    boolean caught = false;
    EncodableCollectionData emptycoll = new EncodableCollectionData();
    try {//from   w w  w. j a va2 s.  c  om
        emptycoll.collection();
    } catch (ContentNotReadyException iox) {
        // this is what we expect to happen
        caught = true;
    } catch (IOException ie) {
        Assert.fail("Unexpectd IOException!");
    }
    Assert.assertTrue("Failed to produce expected exception.", caught);

    EncodableCollectionData ecd1 = new EncodableCollectionData(small1);
    EncodableCollectionData ecd2 = new EncodableCollectionData();
    EncodableCollectionData ecd3 = new EncodableCollectionData(small2);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ByteArrayOutputStream baos3 = new ByteArrayOutputStream();

    try {
        ecd1.save(baos);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ecd2.update(bais); // will this save? currently not, should it?
        Assert.assertEquals("Writing content out and back in again should give matching object.", ecd1, ecd2);
        ecd3.save(baos3);
        boolean be = Arrays.areEqual(baos.toByteArray(), baos3.toByteArray());
        Assert.assertFalse("Two different objects shouldn't have matching output.", be);
        System.out.println("Saved two collection datas, lengths " + baos.toByteArray().length + " and "
                + baos3.toByteArray().length);
    } catch (ContentDecodingException e) {
        fail("ContentDecodingException! " + e.getMessage());
    } catch (IOException e) {
        fail("IOException! " + e.getMessage());
    }

    Log.info(Log.FAC_TEST, "Completed testUpdate");
}