Example #1
0
        public void NoModifierMeansRequired()
        {
            var foo = ProtozbuffLoader.Load(new StringReader(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<protozbuff xmlns=""http://tempuri.org/protoZ.xsd"">
  <message name=""Folder"" description=""Document definition"">
    <field id=""1"" name=""size"" type=""double""
           description=""Folder size."" />
  </message>
</protozbuff>"));

            const string result = @"package bar;

message FolderHeader
{
    required double size= 1;
}

message LocalMessageDescriptor
{
    repeated int32 coordinate = 1 [packed=true];
}
";
            var          writer = new StringWriter();

            ProtoGenerator.Generate(foo, writer, "bar");
            Assert.That(writer.ToString().RemoveCarriageReturn(), Is.EqualTo(result.RemoveCarriageReturn()));
        }
Example #2
0
        public void EmptyFilePath()
        {
            protozbuffType protoTree = null;

            Assert.DoesNotThrow(() => protoTree = ProtozbuffLoader.Load(""));
            Assert.That(protoTree, Is.Null);
        }
        ///<summary>Entry point</summary>
        public bool Launch()
        {
            InstallResources();

            var p = ProtozbuffLoader.Load(ProtoZFile);

            // protobufs package option (i.e. namespace) needs dots
            var protobufPackage = GeneratedNamespace.Replace(NamespaceSeparator, ".");

            ProtoGenerator.Generate(p, ProtoFile, protobufPackage); // generate .proto file

            CallProtocExe();

            return(GenerateLazyImplementation(p));
        }
Example #4
0
        public void InvalidProtoZBufferFile()
        {
            CreateFile(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<protozbuff xmlns=""http://tempuri.org/protoZ.xsd"">
  <message name=""Folder"" description=""Document definition"">
    <field id=""1"" modifier=""required"" name=""name"" type=""string""
           description=""Folder Name."" />
    </message>
  </message>
</protozbuff>");

            protozbuffType protoTree = null;

            Assert.DoesNotThrow(() => protoTree = ProtozbuffLoader.Load(_tempFilePath));
            Assert.That(protoTree, Is.Null);
        }
Example #5
0
        public void IndexWithDefault()
        {
            var foo = ProtozbuffLoader.Load(new StringReader(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<protozbuff xmlns=""http://tempuri.org/protoZ.xsd"">
  <message name=""Folder"" description=""Document definition"">
    <field id=""1"" name=""name"" type=""referenceMessage"" messageType=""File""
           description=""Folder Name."" modifier=""repeated"" default=""foo"" />
    <index id=""2"" name=""my_index"" forField=""1"" sortBy=""filename""/>
  </message>
  <message name=""File"" description=""File desc"">
     <field id=""3"" name=""filename"" type=""string"" modifier=""required""/>
  </message>
</protozbuff>"));

            const string result = @"package bar;

message FolderHeader
{
  //repeated FileHeader name= 1 [default=foo];
    repeated LocalMessageDescriptor name= 1 [default=foo];
  //repeated FileHeader my_index= 2 [default=foo];
    repeated LocalMessageDescriptor my_index= 2 [default=foo];
}

message FileHeader
{
    required string filename= 3;
}

message LocalMessageDescriptor
{
    repeated int32 coordinate = 1 [packed=true];
}
";

            Assert.That(foo, Is.Not.Null);
            var writer = new StringWriter();

            ProtoGenerator.Generate(foo, writer, "bar");
            Assert.That(writer.ToString().RemoveCarriageReturn(), Is.EqualTo(result.RemoveCarriageReturn()));
        }
Example #6
0
        public void EnumTypeForField()
        {
            var foo = ProtozbuffLoader.Load(new StringReader(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<protozbuff xmlns=""http://tempuri.org/protoZ.xsd"">
  <message name=""Folder"" description=""Document definition"">
    <field id=""1"" modifier=""required"" name=""name"" type=""enum"" enumType=""my_enum""
           description=""Folder Name."" />
  </message>
  <enum name=""my_enum"" description=""description of my enum"">
     <enumItem name=""item1"" description=""first item"" />
     <enumItem name=""item2"" description=""second item"" value=""42""/>
     <enumItem name=""item3"" description=""third item""/>
  </enum>
</protozbuff>"));

            const string result = @"package bar;

message FolderHeader
{
    required my_enum name= 1;
}

enum my_enum
{
    item1;
    item2=42;
    item3;
}

message LocalMessageDescriptor
{
    repeated int32 coordinate = 1 [packed=true];
}
";
            var          writer = new StringWriter();

            ProtoGenerator.Generate(foo, writer, "bar");
            Assert.That(writer.ToString().RemoveCarriageReturn(), Is.EqualTo(result.RemoveCarriageReturn()));
        }