Skip to content

Commit

Permalink
Add more protobuf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmbakker committed Apr 26, 2017
1 parent 0ef87b8 commit 9b92e9e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
17 changes: 13 additions & 4 deletions SharpCaster.Simple/SharpCaster.Simple.nuget.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">C:\Users\habakker\Documents\Source\SharpCaster\SharpCaster.Simple\project.lock.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\habakker\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">ProjectJson</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">4.1.0</NuGetToolVersion>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\Microsoft.Bcl.Build\1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('$(NuGetPackageRoot)\Microsoft.Bcl.Build\1.0.21\build\Microsoft.Bcl.Build.targets')" />
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.bcl.build\1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.bcl.build\1.0.21\build\Microsoft.Bcl.Build.targets')" />
</ImportGroup>
</Project>
34 changes: 33 additions & 1 deletion SharpCaster.Test/ProtoBufTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,46 @@ namespace SharpCaster.Test
public class ProtoBufTester
{
[Fact]
public void TestProtoBuf()
public void Connect_Should_Be_Serialized_Well()
{
var connectMessage = MessageFactory.Connect();
connectMessage.Namespace = "urn:x-cast:com.google.cast.tp.connection";
var bytes = connectMessage.ToProto();
Assert.Equal(bytes, new byte[] { 0, 0, 0, 88, 8, 0, 18, 8, 115, 101, 110, 100, 101, 114, 45, 48, 26, 10, 114, 101, 99, 101, 105, 118, 101, 114, 45, 48, 34, 40, 117, 114, 110, 58, 120, 45, 99, 97, 115, 116, 58, 99, 111, 109, 46, 103, 111, 111, 103, 108, 101, 46, 99, 97, 115, 116, 46, 116, 112, 46, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 40, 0, 50, 18, 123, 34, 116, 121, 112, 101, 34, 58, 34, 67, 79, 78, 78, 69, 67, 84, 34, 125 });
}

[Fact]
public void Ping_Should_Be_Serialized_Well()
{
var pingMessage = MessageFactory.Ping;
var bytes = pingMessage.ToProto();
Assert.Equal(bytes, new byte[] { 0, 0, 0, 43, 8, 0, 18, 8, 115, 101, 110, 100, 101, 114, 45, 48, 26, 10, 114, 101, 99, 101, 105, 118, 101, 114, 45, 48, 40, 0, 50, 15, 123, 34, 116, 121, 112, 101, 34, 58, 34, 80, 73, 78, 71, 34, 125 });
}

[Fact]
public void Close_Should_Be_Serialized_Well()
{
var closeMessage = MessageFactory.Close;
var bytes = closeMessage.ToProto();
Assert.Equal(bytes, new byte[] { 0, 0, 0, 44, 8, 0, 18, 8, 115, 101, 110, 100, 101, 114, 45, 48, 26, 10, 114, 101, 99, 101, 105, 118, 101, 114, 45, 48, 40, 0, 50, 16, 123, 34, 116, 121, 112, 101, 34, 58, 34, 67, 76, 79, 83, 69, 34, 125 });
}

[Fact]
public void Volume_Level_Should_Be_Serialized_Well()
{
var volumeLevel = MessageFactory.Volume(0.7);
var bytes = volumeLevel.ToProto();
Assert.Equal(bytes, new byte[] { 0, 0, 0, 94, 8, 0, 18, 8, 115, 101, 110, 100, 101, 114, 45, 48, 26, 10, 114, 101, 99, 101, 105, 118, 101, 114, 45, 48, 40, 0, 50, 66, 123, 34, 118, 111, 108, 117, 109, 101, 34, 58, 123, 34, 108, 101, 118, 101, 108, 34, 58, 48, 46, 55, 125, 44, 34, 114, 101, 113, 117, 101, 115, 116, 73, 100, 34, 58, 53, 53, 52, 55, 54, 51, 57, 50, 53, 44, 34, 116, 121, 112, 101, 34, 58, 34, 83, 69, 84, 95, 86, 79, 76, 85, 77, 69, 34, 125 });
}

[Fact]
public void Volume_Mute_Should_Be_Serialized_Well()
{
var volumeMuted = MessageFactory.Volume(true);
var bytes = volumeMuted.ToProto();
Assert.Equal(bytes, new byte[] { 0, 0, 0, 96, 8, 0, 18, 8, 115, 101, 110, 100, 101, 114, 45, 48, 26, 10, 114, 101, 99, 101, 105, 118, 101, 114, 45, 48, 40, 0, 50, 68, 123, 34, 118, 111, 108, 117, 109, 101, 34, 58, 123, 34, 109, 117, 116, 101, 100, 34, 58, 116, 114, 117, 101, 125, 44, 34, 114, 101, 113, 117, 101, 115, 116, 73, 100, 34, 58, 50, 48, 51, 53, 51, 56, 52, 49, 53, 56, 44, 34, 116, 121, 112, 101, 34, 58, 34, 83, 69, 84, 95, 86, 79, 76, 85, 77, 69, 34, 125 });
}

private static string PrintBytes(byte[] byteArray)
{
var sb = new StringBuilder("new byte[] { ");
Expand Down

0 comments on commit 9b92e9e

Please sign in to comment.