예제 #1
0
        public void TestProtoInput()
        {
            FileDescriptorSet files = new FileDescriptorSet();

            Assert.Equal(0, files.file.Count);
            InputFileLoader.Merge(files, @"ProtoGen\descriptor.proto", Console.Error);
            Assert.Equal(1, files.file.Count);
        }
예제 #2
0
        public void TestBinaryInput()
        {
            // compile .proto to .bin
            Process.Start("protoc", @"--descriptor_set_out=ProtoGen\descriptor.bin --include_imports ProtoGen\descriptor.proto").WaitForExit();

            // process .bin
            FileDescriptorSet files = new FileDescriptorSet();

            Assert.Equal(0, files.file.Count);
            InputFileLoader.Merge(files, @"ProtoGen\descriptor.bin", Console.Error);
            Assert.Equal(1, files.file.Count);
        }
예제 #3
0
        public void TestGarbageInput()
        {
            FileDescriptorSet files = new FileDescriptorSet();

            try {
                InputFileLoader.Merge(files, @"ProtoGen\InputLoader.cs", Console.Error);
                Assert.Fail("Should have barfed");
            }
            catch (ProtoParseException ex)
            {
                bool sw = ex.Message.StartsWith("An error occurred parsing InputLoader.cs");
                if (!sw)
                {
                    Assert.Fail("Expected message not found: " + ex.Message);
                }
            }
            catch
            {
                Assert.Fail("Expected ArgumentException");
            }
        }
예제 #4
0
        public FileDescriptorSet LoadTypes(Stream ms = null)
        {
            var files = new FileDescriptorSet();
            var args  = string.Join(" ", (_includePaths ?? new string[0])
                                    .Concat(_addToIncludePath
                    ? _paths.Select(Path.GetDirectoryName)
                    : new string[0])
                                    .Where(Directory.Exists)
                                    .Select(o => o.ToLowerInvariant())
                                    .Distinct()
                                    .Select(o => "-I " + o));

            using (var sr = ms != null ? new StreamWriter(ms) : StreamWriter.Null)
            {
                foreach (var path in _paths
                         .Where(File.Exists)
                         .Select(o => o.ToLowerInvariant())
                         .Distinct())
                {
                    InputFileLoader.Merge(files, path, sr, args);
                }
            }
            return(files);
        }
예제 #5
0
        public void TestMissingInput()
        {
            FileDescriptorSet files = new FileDescriptorSet();

            InputFileLoader.Merge(files, @"ProtoGen\NoneSuch.bin", Console.Error);
        }
예제 #6
0
        public void TestEmptyPath()
        {
            FileDescriptorSet files = new FileDescriptorSet();

            InputFileLoader.Merge(files, "", Console.Error);
        }
예제 #7
0
        public void TestNullPath()
        {
            FileDescriptorSet files = new FileDescriptorSet();

            InputFileLoader.Merge(files, null, Console.Error);
        }
예제 #8
0
 public void TestNullFileSet()
 {
     InputFileLoader.Merge(null, "abc", Console.Error);
 }