Use embedded resources.

This commit is contained in:
Kuba Ober 2019-09-03 12:08:39 -04:00
parent 05661ae9bb
commit 68df661e63
14 changed files with 24 additions and 321 deletions

View File

@ -1,5 +1,4 @@
using capnpc_csharp.Tests.Properties; using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -17,7 +16,7 @@ namespace capnpc_csharp.Tests
bool _success; bool _success;
Exception _generateException; Exception _generateException;
Stream LoadResource(string name) internal static Stream LoadResource(string name)
{ {
var assembly = Assembly.GetExecutingAssembly(); var assembly = Assembly.GetExecutingAssembly();
string[] names = assembly.GetManifestResourceNames(); string[] names = assembly.GetManifestResourceNames();

View File

@ -1,143 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.42000
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
namespace capnpc_csharp.Tests.Properties {
using System;
/// <summary>
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
/// </summary>
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("capnpc_csharp.Tests.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] schema_with_offsets_capnp {
get {
object obj = ResourceManager.GetObject("schema_with_offsets_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest1_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest1_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest10_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest10_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest11_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest11_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest2_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest2_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest20_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest20_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest3_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest3_capnp", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] UnitTest4_capnp {
get {
object obj = ResourceManager.GetObject("UnitTest4_capnp", resourceCulture);
return ((byte[])(obj));
}
}
}
}

View File

@ -1,145 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="UnitTest10_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest10.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitTest20_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest20.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitTest3_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest3.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitTest2_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest2.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitTest1_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest1.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="schema_with_offsets_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\schema-with-offsets.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitTest11_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest11.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="UnitTest4_capnp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UnitTest4.capnp.bin;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

View File

@ -1,4 +1,4 @@
using capnpc_csharp.Tests.Properties; using capnpc_csharp.Tests;
using Capnp; using Capnp;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System; using System;
@ -16,14 +16,14 @@ namespace CapnpC
[TestMethod] [TestMethod]
public void Test00Enumerant() public void Test00Enumerant()
{ {
var model = Load(Resources.UnitTest1_capnp); var model = Load("UnitTest1.capnp.bin");
Assert.AreEqual("@byte", GetTypeDef(0xc8461867c409f5d4, model).Enumerants[0].Literal); Assert.AreEqual("@byte", GetTypeDef(0xc8461867c409f5d4, model).Enumerants[0].Literal);
} }
[TestMethod] [TestMethod]
public void Test01NestedClash() public void Test01NestedClash()
{ {
var run = LoadAndGenerate(Resources.UnitTest1_capnp, 1); var run = LoadAndGenerate("UnitTest1.capnp.bin", 1);
var structFoo = GetTypeDef(0x93db6ba5509bac24, run.Model); var structFoo = GetTypeDef(0x93db6ba5509bac24, run.Model);
var names = run.CodeGen.GetNames(); var names = run.CodeGen.GetNames();
var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString(); var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString();
@ -34,28 +34,28 @@ namespace CapnpC
[TestMethod] [TestMethod]
public void Test02ForwardInheritance() public void Test02ForwardInheritance()
{ {
LoadAndGenerate(Resources.UnitTest2_capnp, 2); LoadAndGenerate("UnitTest2.capnp.bin", 2);
// Should not throw // Should not throw
} }
[TestMethod] [TestMethod]
public void Test03NonGeneratedNodeSkip() public void Test03NonGeneratedNodeSkip()
{ {
LoadAndGenerate(Resources.UnitTest3_capnp, 3); LoadAndGenerate("UnitTest3.capnp.bin", 3);
// Should not throw // Should not throw
} }
[TestMethod] [TestMethod]
public void Test04MutualDependencies() public void Test04MutualDependencies()
{ {
LoadAndGenerate(Resources.UnitTest4_capnp, 4); LoadAndGenerate("UnitTest4.capnp.bin", 4);
// Should not throw // Should not throw
} }
[TestMethod] [TestMethod]
public void Test10ImportedNamespaces() public void Test10ImportedNamespaces()
{ {
var run = LoadAndGenerate(Resources.UnitTest10_capnp, 10); var run = LoadAndGenerate("UnitTest10.capnp.bin", 10);
var outerTypeDef = run.FirstFile.NestedTypes.First(); var outerTypeDef = run.FirstFile.NestedTypes.First();
var outerType = Model.Types.FromDefinition(outerTypeDef); var outerType = Model.Types.FromDefinition(outerTypeDef);
var innerType = outerTypeDef.Fields[0].Type; var innerType = outerTypeDef.Fields[0].Type;
@ -76,21 +76,21 @@ namespace CapnpC
[TestMethod] [TestMethod]
public void Test11ImportedConst() public void Test11ImportedConst()
{ {
LoadAndGenerate(Resources.UnitTest11_capnp, 11); LoadAndGenerate("UnitTest11.capnp.bin", 11);
// Should not throw // Should not throw
} }
[TestMethod] [TestMethod]
public void Test20AnnotationAndConst() public void Test20AnnotationAndConst()
{ {
LoadAndGenerate(Resources.UnitTest20_capnp, 20); LoadAndGenerate("UnitTest20.capnp.bin", 20);
// Should not throw // Should not throw
} }
[TestMethod] [TestMethod]
public void Test30SchemaCapnp() public void Test30SchemaCapnp()
{ {
LoadAndGenerate(Resources.schema_with_offsets_capnp); LoadAndGenerate("schema-with-offsets.capnp.bin");
// Should not throw // Should not throw
} }
@ -105,10 +105,10 @@ namespace CapnpC
static Generator.CodeGenerator NewGeneratorFor(Model.SchemaModel model) static Generator.CodeGenerator NewGeneratorFor(Model.SchemaModel model)
=> new Generator.CodeGenerator(model, new Generator.GeneratorOptions()); => new Generator.CodeGenerator(model, new Generator.GeneratorOptions());
Run LoadAndGenerate(byte[] input, int? testNum = null) Run LoadAndGenerate(string inputName, int? testNum = null)
{ {
var run = new Run(); var run = new Run();
run.Model = Load(input); run.Model = Load(inputName);
run.CodeGen = NewGeneratorFor(run.Model); run.CodeGen = NewGeneratorFor(run.Model);
run.FirstFile = run.Model.FilesToGenerate.First(); run.FirstFile = run.Model.FilesToGenerate.First();
run.Code = run.CodeGen.Transform(run.FirstFile); run.Code = run.CodeGen.Transform(run.FirstFile);
@ -137,10 +137,10 @@ namespace CapnpC
return null; return null;
} }
static Model.SchemaModel Load(byte[] data) static Model.SchemaModel Load(string inputName)
{ {
WireFrame segments; WireFrame segments;
var input = new MemoryStream(data); var input = CodeGeneratorSteps.LoadResource(inputName);
using (input) using (input)
{ {
segments = Framing.ReadSegments(input); segments = Framing.ReadSegments(input);

View File

@ -23,7 +23,6 @@
<ItemGroup> <ItemGroup>
<Compile Remove="*.cs" /> <Compile Remove="*.cs" />
<Compile Remove="Embedded Resources\test.cs" /> <Compile Remove="Embedded Resources\test.cs" />
<Compile Remove="Resources\test.cs" />
<None Remove="Embedded Resources\null.bin" /> <None Remove="Embedded Resources\null.bin" />
<None Remove="Embedded Resources\test.capnp" /> <None Remove="Embedded Resources\test.capnp" />
<None Remove="Embedded Resources\test.capnp.bin" /> <None Remove="Embedded Resources\test.capnp.bin" />
@ -38,21 +37,14 @@
<EmbeddedResource Include="Embedded Resources\null.bin" /> <EmbeddedResource Include="Embedded Resources\null.bin" />
<EmbeddedResource Include="Embedded Resources\test.capnp.bin" /> <EmbeddedResource Include="Embedded Resources\test.capnp.bin" />
<EmbeddedResource Include="Embedded Resources\test.cs" /> <EmbeddedResource Include="Embedded Resources\test.cs" />
</ItemGroup> <EmbeddedResource Include="Embedded Resources\UnitTest1.capnp.bin" />
<EmbeddedResource Include="Embedded Resources\UnitTest2.capnp.bin" />
<ItemGroup> <EmbeddedResource Include="Embedded Resources\UnitTest3.capnp.bin" />
<Compile Update="Properties\Resources.Designer.cs"> <EmbeddedResource Include="Embedded Resources\UnitTest4.capnp.bin" />
<DesignTime>True</DesignTime> <EmbeddedResource Include="Embedded Resources\UnitTest10.capnp.bin" />
<AutoGen>True</AutoGen> <EmbeddedResource Include="Embedded Resources\UnitTest11.capnp.bin" />
<DependentUpon>Resources.resx</DependentUpon> <EmbeddedResource Include="Embedded Resources\UnitTest20.capnp.bin" />
</Compile> <EmbeddedResource Include="Embedded Resources\schema-with-offsets.capnp.bin" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>