public void testSimple() throws Exception
    {
        File f = getFile("TestModel.proto");
        assertTrue(f.exists());

        Proto proto = new Proto(f);
        ProtoUtil.loadFrom(f, proto);
        assertEquals(proto.getPackageName(), "simple");
        assertEquals(proto.getJavaPackageName(), "com.example.simple");
        assertTrue(proto.getEnumGroups().size() == 0);
        assertTrue(proto.getMessages().size() == 3);

        Message foo = proto.getMessage("Foo");
        Message bar = proto.getMessage("Bar");
        Message baz = proto.getMessage("Baz");
        assertNotNull(foo);
        assertNotNull(bar);
        assertNotNull(baz);

        assertTrue(foo.getNestedEnumGroups().size() == 1);
        EnumGroup enumSample = foo.getNestedEnumGroup("EnumSample");
        assertNotNull(enumSample);
        assertTrue(enumSample.getValues().size() == 5);
        assertEquals("TYPE0", enumSample.getValue(0).getName());
        assertEquals("TYPE1", enumSample.getValue(1).getName());
        assertEquals("TYPE2", enumSample.getValue(2).getName());
        assertEquals("TYPE3", enumSample.getValue(3).getName());
        assertEquals("TYPE4", enumSample.getValue(4).getName());

        assertTrue(foo.getFields().size() == 9);
        Field.Int32 foo_some_int = (Field.Int32) foo.getField("some_int");
        Field.String foo_some_string = (Field.String) foo.getField("some_string");
        MessageField foo_bar = (MessageField) foo.getField("bar");
        EnumField foo_some_enum = (EnumField) foo.getField("some_enum");
        Field.Bytes foo_some_bytes = (Field.Bytes) foo.getField("some_bytes");
        Field.Bool foo_some_boolean = (Field.Bool) foo.getField("some_boolean");
        Field.Float foo_some_float = (Field.Float) foo.getField("some_float");
        Field.Double foo_some_double = (Field.Double) foo.getField("some_double");
        Field.Int64 foo_some_long = (Field.Int64) foo.getField("some_long");

        assertTrue(foo_some_int != null && foo_some_int.modifier == Modifier.REPEATED);
        assertTrue(foo_some_string != null && foo_some_string.modifier == Modifier.REPEATED);
        assertTrue(foo_bar != null && foo_bar.modifier == Modifier.REPEATED);
        assertTrue(foo_some_enum != null && foo_some_enum.modifier == Modifier.REPEATED);
        assertTrue(foo_some_bytes != null && foo_some_bytes.modifier == Modifier.REPEATED);
        assertTrue(foo_some_boolean != null && foo_some_boolean.modifier == Modifier.REPEATED);
        assertTrue(foo_some_float != null && foo_some_float.modifier == Modifier.REPEATED);
        assertTrue(foo_some_double != null && foo_some_double.modifier == Modifier.REPEATED);
        assertTrue(foo_some_long != null && foo_some_long.modifier == Modifier.REPEATED);

        Field.Int32 bar_some_int = (Field.Int32) bar.getField("some_int");
        Field.String bar_some_string = (Field.String) bar.getField("some_string");
        MessageField bar_baz = (MessageField) bar.getField("baz");
        EnumField bar_some_enum = (EnumField) bar.getField("some_enum");
        Field.Bytes bar_some_bytes = (Field.Bytes) bar.getField("some_bytes");
        Field.Bool bar_some_boolean = (Field.Bool) bar.getField("some_boolean");
        Field.Float bar_some_float = (Field.Float) bar.getField("some_float");
        Field.Double bar_some_double = (Field.Double) bar.getField("some_double");
        Field.Int64 bar_some_long = (Field.Int64) bar.getField("some_long");

        assertTrue(bar_some_int != null && bar_some_int.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_string != null && bar_some_string.modifier == Modifier.OPTIONAL);
        assertTrue(bar_baz != null && bar_baz.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_enum != null && bar_some_enum.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_bytes != null && bar_some_bytes.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_boolean != null && bar_some_boolean.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_float != null && bar_some_float.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_double != null && bar_some_double.modifier == Modifier.OPTIONAL);
        assertTrue(bar_some_long != null && bar_some_long.modifier == Modifier.OPTIONAL);

        Field.Int64 baz_id = (Field.Int64) baz.getField("id");
        Field.String baz_name = (Field.String) baz.getField("name");
        Field.Int64 baz_timestamp = (Field.Int64) baz.getField("timestamp");
        Field.Bytes baz_data = (Field.Bytes) baz.getField("data");

        assertTrue(baz_id != null && baz_id.modifier == Modifier.REQUIRED);
        assertTrue(baz_name != null && baz_name.modifier == Modifier.OPTIONAL);
        assertTrue(baz_timestamp != null && baz_timestamp.modifier == Modifier.OPTIONAL);
        assertTrue(baz_data != null && baz_data.modifier == Modifier.OPTIONAL);

        assertEquals(bar_some_int.defaultValue, Integer.valueOf(127));
        assertEquals(new String(bar_some_string.defaultValue.getBytes(TextFormat.ISO_8859_1), "UTF-8"), "\u1234");
        assertEquals(bar_some_float.defaultValue, Float.valueOf(127.0f));
        assertEquals(bar_some_double.defaultValue, Double.valueOf(45.123));
        byte[] data = baz_data.getDefaultValue();
        assertTrue(data != null && data.length == 2);
        assertTrue((data[0] & 0xFF) == 0xFA);
        assertTrue((data[1] & 0xFF) == 0xCE);
    }
Various tests for the proto parser.

@author David Yu
@created Dec 18, 2009
protostuff-parser/src/test/java/io/protostuff/parser/ProtoParserTest.java