Package org.apache.qpid.proton

Examples of org.apache.qpid.proton.TestDecoder


        return m;
    }

    TestDecoder createDecoder(byte[] data)
    {
        TestDecoder td = new TestDecoder(data);
        return td;
    }
View Full Code Here


    }

    @Test
    public void testPrimitives() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("primitives"));
        assertEquals(true, d.readBoolean());
        assertEquals(false, d.readBoolean());
        assertEquals(d.readUnsignedByte().intValue(), 42);
        assertEquals(42, d.readUnsignedShort().intValue());
        assertEquals(-42, d.readShort().intValue());
        assertEquals(12345, d.readUnsignedInteger().intValue());
        assertEquals(-12345, d.readInteger().intValue());
        assertEquals(12345, d.readUnsignedLong().longValue());
        assertEquals(-12345, d.readLong().longValue());
        assertEquals(0.125, d.readFloat().floatValue(), 0e-10);
        assertEquals(0.125, d.readDouble().doubleValue(), 0e-10);
    }
View Full Code Here

    }

    @Test
    public void testStrings() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("strings"));
        assertEquals(new Binary("abc\0defg".getBytes("UTF-8")), d.readBinary());
        assertEquals("abcdefg", d.readString());
        assertEquals(Symbol.valueOf("abcdefg"), d.readSymbol());
        assertEquals(new Binary(new byte[0]), d.readBinary());
        assertEquals("", d.readString());
        assertEquals(Symbol.valueOf(""), d.readSymbol());
    }
View Full Code Here

    }

    @Test
    public void testDescribed() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("described"));
        DescribedType dt = (DescribedType) (d.readObject());
        assertEquals(Symbol.valueOf("foo-descriptor"), dt.getDescriptor());
        assertEquals("foo-value", dt.getDescribed());

        dt = (DescribedType) (d.readObject());
        assertEquals(12, dt.getDescriptor());
        assertEquals(13, dt.getDescribed());
    }
View Full Code Here

    }

    @Test
    public void testDescribedArray() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("described_array"));
        DescribedType a[] = (DescribedType[]) (d.readArray());
        for (int i = 0; i < 10; ++i)
        {
            assertEquals(Symbol.valueOf("int-array"), a[i].getDescriptor());
            assertEquals(i, a[i].getDescribed());
        }
View Full Code Here

    }

    @Test
    public void testArrays() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("arrays"));

        // int array
        Vector<Integer> ints = new Vector<Integer>();
        for (int i = 0; i < 100; ++i)
            ints.add(new Integer(i));
        assertArrayEquals(ints.toArray(), d.readArray());

        // String array
        String strings[] =
        { "a", "b", "c" };
        assertArrayEquals(strings, d.readArray());

        // Empty array
        assertArrayEquals(new Integer[0], d.readArray());
    }
View Full Code Here

    }

    @Test
    public void testLists() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("lists"));
        List<Object> l = new ArrayList<Object>()
        {
            {
                add(new Integer(32));
                add("foo");
                add(new Boolean(true));
            }
        };
        assertEquals(l, d.readList());
        l.clear();
        assertEquals(l, d.readList());
    }
View Full Code Here

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Test
    public void testMaps() throws IOException
    {
        TestDecoder d = createDecoder(getBytes("maps"));
        Map map = new HashMap()
        {
            {
                put("one", 1);
                put("two", 2);
                put("three", 3);
            }
        };
        assertEquals(map, d.readMap());

        map = new HashMap()
        {
            {
                put(1, "one");
                put(2, "two");
                put(3, "three");
            }
        };
        assertEquals(map, d.readMap());

        map = new HashMap();
        assertEquals(map, d.readMap());
    }
View Full Code Here

TOP

Related Classes of org.apache.qpid.proton.TestDecoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.