First pass at C# conformance tests.
Completely untested so far - easier to get started in VS and then transfer to Linux for tweaking...
This commit is contained in:
parent
d77d70d227
commit
044c36ebef
2
csharp/.gitignore
vendored
2
csharp/.gitignore
vendored
@ -5,6 +5,8 @@ src/AddressBook/bin
|
|||||||
src/AddressBook/obj
|
src/AddressBook/obj
|
||||||
src/Google.Protobuf/bin/
|
src/Google.Protobuf/bin/
|
||||||
src/Google.Protobuf/obj/
|
src/Google.Protobuf/obj/
|
||||||
|
src/Google.Protobuf.Conformance/bin/
|
||||||
|
src/Google.Protobuf.Conformance/obj/
|
||||||
src/Google.Protobuf.Test/bin/
|
src/Google.Protobuf.Test/bin/
|
||||||
src/Google.Protobuf.Test/obj/
|
src/Google.Protobuf.Test/obj/
|
||||||
src/Google.Protobuf.JsonDump/bin/
|
src/Google.Protobuf.JsonDump/bin/
|
||||||
|
@ -68,3 +68,6 @@ $PROTOC -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos
|
|||||||
# AddressBook sample protos
|
# AddressBook sample protos
|
||||||
$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
|
$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
|
||||||
examples/addressbook.proto
|
examples/addressbook.proto
|
||||||
|
|
||||||
|
$PROTOC -Iconformance --csharp_out=csharp/src/Google.Protobuf.Conformance \
|
||||||
|
conformance/conformance.proto
|
||||||
|
6
csharp/src/Google.Protobuf.Conformance/App.config
Normal file
6
csharp/src/Google.Protobuf.Conformance/App.config
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
2400
csharp/src/Google.Protobuf.Conformance/Conformance.cs
Normal file
2400
csharp/src/Google.Protobuf.Conformance/Conformance.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{0607D1B8-80D6-4B35-9857-1263C1B32B94}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Google.Protobuf.Conformance</RootNamespace>
|
||||||
|
<AssemblyName>Google.Protobuf.Conformance</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Conformance.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Google.Protobuf\Google.Protobuf.csproj">
|
||||||
|
<Project>{6908bdce-d925-43f3-94ac-a531e6df2591}</Project>
|
||||||
|
<Name>Google.Protobuf</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
126
csharp/src/Google.Protobuf.Conformance/Program.cs
Normal file
126
csharp/src/Google.Protobuf.Conformance/Program.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#region Copyright notice and license
|
||||||
|
// Protocol Buffers - Google's data interchange format
|
||||||
|
// Copyright 2015 Google Inc. All rights reserved.
|
||||||
|
// https://developers.google.com/protocol-buffers/
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following disclaimer
|
||||||
|
// in the documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
// * Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using Conformance;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Google.Protobuf.Conformance
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Conformance tests. The test runner will provide JSON or proto data on stdin,
|
||||||
|
/// and this program will produce its output on stdout.
|
||||||
|
/// </summary>
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
private static void Main(string[] args)
|
||||||
|
{
|
||||||
|
// This way we get the binary streams instead of readers/writers.
|
||||||
|
var input = new BinaryReader(Console.OpenStandardInput());
|
||||||
|
var output = new BinaryWriter(Console.OpenStandardOutput());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (RunTest(input, output))
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
Console.Error.WriteLine("Received EOF after {0} tests", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool RunTest(BinaryReader input, BinaryWriter output)
|
||||||
|
{
|
||||||
|
int? size = ReadInt32(input);
|
||||||
|
if (size == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
byte[] inputData = input.ReadBytes(size.Value);
|
||||||
|
if (inputData.Length != size.Value)
|
||||||
|
{
|
||||||
|
throw new EndOfStreamException("Read " + inputData.Length + " bytes of data when expecting " + size);
|
||||||
|
}
|
||||||
|
ConformanceRequest request = ConformanceRequest.Parser.ParseFrom(inputData);
|
||||||
|
ConformanceResponse response = PerformRequest(request);
|
||||||
|
byte[] outputData = response.ToByteArray();
|
||||||
|
output.Write(outputData.Length);
|
||||||
|
output.Write(outputData);
|
||||||
|
// Ready for another test...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ConformanceResponse PerformRequest(ConformanceRequest request)
|
||||||
|
{
|
||||||
|
TestAllTypes message;
|
||||||
|
switch (request.PayloadCase)
|
||||||
|
{
|
||||||
|
case ConformanceRequest.PayloadOneofCase.JsonPayload:
|
||||||
|
return new ConformanceResponse { Skipped = "JSON parsing not implemented in C# yet" };
|
||||||
|
case ConformanceRequest.PayloadOneofCase.ProtobufPayload:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
message = TestAllTypes.Parser.ParseFrom(request.ProtobufPayload);
|
||||||
|
}
|
||||||
|
catch (InvalidProtocolBufferException e)
|
||||||
|
{
|
||||||
|
return new ConformanceResponse { ParseError = e.Message };
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Unsupported request payload: " + request.PayloadCase);
|
||||||
|
}
|
||||||
|
switch (request.RequestedOutputFormat)
|
||||||
|
{
|
||||||
|
case global::Conformance.WireFormat.JSON:
|
||||||
|
return new ConformanceResponse { JsonPayload = JsonFormatter.Default.Format(message) };
|
||||||
|
case global::Conformance.WireFormat.PROTOBUF:
|
||||||
|
return new ConformanceResponse { ProtobufPayload = message.ToByteString() };
|
||||||
|
default:
|
||||||
|
throw new Exception("Unsupported request output format: " + request.PayloadCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int? ReadInt32(BinaryReader input)
|
||||||
|
{
|
||||||
|
byte[] bytes = input.ReadBytes(4);
|
||||||
|
if (bytes.Length == 0)
|
||||||
|
{
|
||||||
|
// Cleanly reached the end of the stream
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (bytes.Length != 4)
|
||||||
|
{
|
||||||
|
throw new EndOfStreamException("Read " + bytes.Length + " bytes of size when expecting 4");
|
||||||
|
}
|
||||||
|
return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("Google.Protobuf.Conformance")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("Google.Protobuf.Conformance")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("0607d1b8-80d6-4b35-9857-1263c1b32b94")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddressBook", "AddressBook\
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{D7282E99-2DC3-405B-946F-177DB2FD2AE2}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{D7282E99-2DC3-405B-946F-177DB2FD2AE2}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.csproj", "{0607D1B8-80D6-4B35-9857-1263C1B32B94}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -41,6 +43,12 @@ Global
|
|||||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU
|
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU
|
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
Loading…
Reference in New Issue
Block a user