public void CppParserCorrectlyInfersCdeclForDefaultCallingConvention() { var config = new Config.ConfigFile { Id = nameof(CppParserCorrectlyInfersCdeclForDefaultCallingConvention), Assembly = nameof(CppParserCorrectlyInfersCdeclForDefaultCallingConvention), Namespace = nameof(CppParserCorrectlyInfersCdeclForDefaultCallingConvention), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("function", @" void func(); "), } }; var model = ParseCpp(config); var function = model.FindFirst <CppFunction>("func"); Assert.Equal(CppCallingConvention.CDecl, function.CallingConvention); }
public void CppParserCorrectlyParsesStdCall() { var config = new Config.ConfigFile { Id = nameof(CppParserCorrectlyParsesStdCall), Assembly = nameof(CppParserCorrectlyParsesStdCall), Namespace = nameof(CppParserCorrectlyParsesStdCall), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("function", @" void __stdcall func(); "), } }; var model = ParseCpp(config); var function = model.FindFirst <CppFunction>("func"); Assert.Equal(CppCallingConvention.StdCall, function.CallingConvention); }
public void TypedefedStructAdjustsNameToTypedef() { var config = new Config.ConfigFile { Id = nameof(TypedefedStructAdjustsNameToTypedef), Namespace = nameof(TypedefedStructAdjustsNameToTypedef), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("typedef", @" typedef struct _Test { int field1; int field2; } Test; typedef struct tagTest2 { int field1; int field2; } Test2; typedef struct { int field1; int field2; } Test3; ") } }; var model = ParseCpp(config); Assert.NotNull(model.FindFirst <CppStruct>("Test")); Assert.NotNull(model.FindFirst <CppStruct>("Test2")); Assert.NotNull(model.FindFirst <CppStruct>("Test3")); }
public void AnonymousEnumAssignedExpectedName() { var config = new Config.ConfigFile { Id = nameof(AnonymousEnumAssignedExpectedName), Assembly = nameof(AnonymousEnumAssignedExpectedName), Namespace = nameof(AnonymousEnumAssignedExpectedName), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("cppEnum", @" enum { Element1 }; ") } }; var model = ParseCpp(config); Assert.Single(model.Find <CppEnum>("CPPENUM_ENUM_0")); }
public void BitfieldStructHasCorrectBitOffsets() { var config = new Config.ConfigFile { Id = nameof(BitfieldStructHasCorrectBitOffsets), Namespace = nameof(BitfieldStructHasCorrectBitOffsets), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("bitfield", @" struct Test { int bitfield1 : 8; int bitfield2 : 6; }; ") } }; var model = ParseCpp(config); var generatedStruct = model.FindFirst <CppStruct>("Test"); var firstBitField = generatedStruct.FindFirst <CppField>("Test::bitfield1"); Assert.Equal(8, firstBitField.BitOffset); Assert.True(firstBitField.IsBitField); Assert.Equal(0, firstBitField.Offset); var secondBitField = generatedStruct.FindFirst <CppField>("Test::bitfield2"); Assert.Equal(6, secondBitField.BitOffset); Assert.True(secondBitField.IsBitField); Assert.Equal(0, secondBitField.Offset); }
public (bool success, string output) RunWithConfig(Config.ConfigFile config, string appType = "true", [CallerMemberName] string configName = "", bool failTestOnError = true) { config.Id = configName; var xUnitLogger = new XUnitLogger(outputHelper, failTestOnError); var logger = new Logger(xUnitLogger, null); var vcInstallDir = Environment.ExpandEnvironmentVariables("VCINSTALLDIR"); if (!Directory.Exists(vcInstallDir)) { vcInstallDir = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\"; } var msvcToolsetVer = File.ReadAllText(vcInstallDir + Path.Combine(@"\Auxiliary\Build", "Microsoft.VCToolsVersion.default.txt")).Trim(); var codeGenApp = new CodeGenApp(logger) { GlobalNamespace = new GlobalNamespaceProvider("SharpGen.Runtime"), CastXmlExecutablePath = "../../../../CastXML/bin/castxml.exe", VcToolsPath = Path.Combine(vcInstallDir, $@"Tools\MSVC\{msvcToolsetVer}\"), AppType = appType, Config = config, OutputDirectory = testDirectory.FullName, IntermediateOutputPath = testDirectory.FullName }; codeGenApp.Init(); codeGenApp.Run(); return(xUnitLogger.Success, xUnitLogger.ExitReason); }
public void UnionFieldOffsets0() { var config = new Config.ConfigFile { Id = nameof(UnionFieldOffsets0), Namespace = nameof(UnionFieldOffsets0), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("union", @" union Test { int field1; int field2; }; ") } }; var model = ParseCpp(config); var generatedStruct = model.FindFirst <CppStruct>("Test"); Assert.True(generatedStruct.IsUnion); var field = generatedStruct.FindFirst <CppField>("Test::field1"); Assert.NotNull(field); Assert.Equal(0, field.Offset); var field2 = generatedStruct.FindFirst <CppField>("Test::field2"); Assert.NotNull(field2); Assert.Equal(0, field2.Offset); }
public void InheritingStructHasBaseMemberSetCorrectly() { var config = new Config.ConfigFile { Id = nameof(InheritingStructHasBaseMemberSetCorrectly), Namespace = nameof(InheritingStructHasBaseMemberSetCorrectly), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("typedef", @" struct Test { int field1; int field2; }; struct Test2 : public Test { int field1; int field2; }; ") } }; var model = ParseCpp(config); var generatedStruct = model.FindFirst <CppStruct>("Test2"); Assert.Equal("Test", generatedStruct.Base); }
public void SequentialFieldsOffsets() { var config = new Config.ConfigFile { Id = nameof(SequentialFieldsOffsets), Namespace = nameof(SequentialFieldsOffsets), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("sequentialFields", @" struct Test { int field1; int field2; }; ") } }; var model = ParseCpp(config); var generatedStruct = model.FindFirst <CppStruct>("Test"); var field = generatedStruct.FindFirst <CppField>("Test::field1"); Assert.NotNull(field); Assert.Equal(0, field.Offset); var field2 = generatedStruct.FindFirst <CppField>("Test::field2"); Assert.NotNull(field2); Assert.Equal(1, field2.Offset); }
public void InnerStructGivenExpectedName() { var config = new Config.ConfigFile { Id = nameof(InnerStructGivenExpectedName), Namespace = nameof(InnerStructGivenExpectedName), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("anonStruct", @" struct Test { struct { int i; } field1; }; ") } }; var model = ParseCpp(config); var generatedStruct = model.FindFirst <CppStruct>("Test"); var field = generatedStruct.FindFirst <CppField>("Test::field1"); Assert.NotNull(field); Assert.Equal("Test_INNER_0", field.TypeName); }
public void SpecifiedUnderlyingType() { var config = new Config.ConfigFile { Id = nameof(SpecifiedUnderlyingType), Namespace = nameof(SpecifiedUnderlyingType), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("cppEnum", @" enum TestEnum : short { Element }; ") }, Bindings = { new Config.BindRule("short", "System.Int16"), } }; var model = ParseCpp(config); var cppEnum = model.FindFirst <CppEnum>("TestEnum"); Assert.Equal("short", cppEnum.UnderlyingType); }
public void PartialAttachOnlyAddsAttachedTypesToModel() { var config = new Config.ConfigFile { Id = nameof(InvalidCppErrorsLogger), Assembly = nameof(InvalidCppErrorsLogger), Namespace = nameof(InvalidCppErrorsLogger), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("invalid", @" struct Test {}; struct UnAttached {}; enum UnAttached2 { Element1 }; ", new List <string> { "Test" }) } }; var model = ParseCpp(config); Assert.NotNull(model.FindFirst <CppStruct>("Test")); Assert.Null(model.FindFirst <CppStruct>("UnAttached")); Assert.Null(model.FindFirst <CppEnum>("UnAttached2")); }
public void CppEnumWithDifferentUnderlyingTypeMapsToCSharpEnum() { var testDirectory = GenerateTestDirectory(); var config = new Config.ConfigFile { Assembly = nameof(CppEnumWithDifferentUnderlyingTypeMapsToCSharpEnum), Namespace = nameof(CppEnumWithDifferentUnderlyingTypeMapsToCSharpEnum), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("cppEnum", @" enum TestEnum : short { Element }; ") }, Bindings = { new Config.BindRule("short", "System.Int16"), } }; (var success, string output) = RunWithConfig(config); AssertRanSuccessfully(success, output); var compilation = GetCompilationForGeneratedCode(); var enumType = compilation.GetTypeByMetadataName($"{nameof(CppEnumWithDifferentUnderlyingTypeMapsToCSharpEnum)}.TestEnum"); Assert.Equal(compilation.GetSpecialType(SpecialType.System_Int16), enumType.EnumUnderlyingType); }
public void CanCreateCSharpEnumFromCppMacros() { var config = new Config.ConfigFile { Assembly = nameof(CanCreateCSharpEnumFromCppMacros), Namespace = nameof(CanCreateCSharpEnumFromCppMacros), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("cppEnum", @" # define TESTENUM_Element1 0 # define TESTENUM_Element2 1 "), }, Extension = new List <Config.ConfigBaseRule> { new Config.ContextRule("cppEnum"), new Config.ContextRule(nameof(CanCreateCSharpEnumFromCppMacros)), new Config.ContextRule($"{nameof(CanCreateCSharpEnumFromCppMacros)}-ext"), new Config.CreateCppExtensionRule { Enum = "SHARPGEN_TESTENUM", Macro = "TESTENUM_(.*)" }, new Config.ClearContextRule(), }, Mappings = { new Config.ContextRule("cppEnum"), new Config.ContextRule(nameof(CanCreateCSharpEnumFromCppMacros)), new Config.ContextRule($"{nameof(CanCreateCSharpEnumFromCppMacros)}-ext"), new Config.MappingRule { Enum = "SHARPGEN_TESTENUM", MappingName = "TestEnum", IsFinalMappingName = true, Assembly = nameof(CanCreateCSharpEnumFromCppMacros), Namespace = nameof(CanCreateCSharpEnumFromCppMacros) }, new Config.MappingRule { EnumItem = "TESTENUM_(.*)", MappingName = "$1" }, new Config.ClearContextRule() } }; (bool success, string output) = RunWithConfig(config); AssertRanSuccessfully(success, output); var compilation = GetCompilationForGeneratedCode(); var enumType = compilation.GetTypeByMetadataName($"{nameof(CanCreateCSharpEnumFromCppMacros)}.TestEnum"); Assert.Equal(compilation.GetSpecialType(SpecialType.System_Int32), enumType.EnumUnderlyingType); AssertEnumMemberCorrect(enumType, "Element1", 0); AssertEnumMemberCorrect(enumType, "Element2", 1); }
public void BasicCppEnumMapsToCSharpEnum() { var testDirectory = GenerateTestDirectory(); var config = new Config.ConfigFile { Assembly = nameof(BasicCppEnumMapsToCSharpEnum), Namespace = nameof(BasicCppEnumMapsToCSharpEnum), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("cppEnum", @" enum TestEnum { Element1, Element2 }; ") } }; (bool success, string output) = RunWithConfig(config); AssertRanSuccessfully(success, output); var compilation = GetCompilationForGeneratedCode(); var enumType = compilation.GetTypeByMetadataName($"{nameof(BasicCppEnumMapsToCSharpEnum)}.TestEnum"); Assert.Equal(compilation.GetSpecialType(SpecialType.System_Int32), enumType.EnumUnderlyingType); AssertEnumMemberCorrect(enumType, "Element1", 0); AssertEnumMemberCorrect(enumType, "Element2", 1); }
public void CppEnumWithExplicitValuesMapsToCSharpEnumWithCorrectValue() { var testDirectory = GenerateTestDirectory(); var config = new Config.ConfigFile { Assembly = nameof(CppEnumWithExplicitValuesMapsToCSharpEnumWithCorrectValue), Namespace = nameof(CppEnumWithExplicitValuesMapsToCSharpEnumWithCorrectValue), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("cppEnum", @" enum TestEnum { Element1 = 10, Element2 = 15, Element3 = 10 }; ") } }; (var success, string output) = RunWithConfig(config); AssertRanSuccessfully(success, output); var compilation = GetCompilationForGeneratedCode(); var enumType = compilation.GetTypeByMetadataName($"{nameof(CppEnumWithExplicitValuesMapsToCSharpEnumWithCorrectValue)}.TestEnum"); Assert.NotNull(enumType.EnumUnderlyingType); AssertEnumMemberCorrect(enumType, "Element1", 10); AssertEnumMemberCorrect(enumType, "Element2", 15); AssertEnumMemberCorrect(enumType, "Element3", 10); }
public void DefaultMethodCallingConventionIsThisCall() { var config = new Config.ConfigFile { Id = nameof(DefaultMethodCallingConventionIsThisCall), Assembly = nameof(DefaultMethodCallingConventionIsThisCall), Namespace = nameof(DefaultMethodCallingConventionIsThisCall), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("defaultcc", @" struct Test { virtual int Method() = 0; }; "), }, Bindings = { new Config.BindRule("int", "System.Int32") } }; var model = ParseCpp(config); Assert.Equal(CppCallingConvention.ThisCall, model.FindFirst <CppMethod>("Test::Method").CallingConvention); }
public void SequentialOffsets() { var config = new Config.ConfigFile { Id = nameof(SequentialOffsets), Namespace = nameof(SequentialOffsets), Includes = { new Config.IncludeRule { File = "simple.h", Attach = true, Namespace = nameof(SequentialOffsets) } }, Bindings = { new Config.BindRule("int", "System.Int32") } }; var cppStruct = new CppStruct { Name = "struct" }; cppStruct.Add(new CppField { Name = "field", TypeName = "int" }); cppStruct.Add(new CppField { Name = "field2", TypeName = "int", Offset = 1 }); var cppInclude = new CppInclude { Name = "simple" }; var cppModule = new CppModule(); cppModule.Add(cppInclude); cppInclude.Add(cppStruct); var(solution, _) = MapModel(cppModule, config); var csStruct = solution.EnumerateDescendants().OfType <CsStruct>().First(); var field = csStruct.Fields.First(fld => fld.Name == "Field"); var field2 = csStruct.Fields.First(fld => fld.Name == "Field2"); Assert.Equal(0, field.Offset); Assert.Equal(4, field2.Offset); }
public void AnonymousNestedStructureMembersInlined() { var config = new Config.ConfigFile { Id = nameof(AnonymousNestedStructureMembersInlined), Namespace = nameof(AnonymousNestedStructureMembersInlined), IncludeDirs = { GetTestFileIncludeRule() }, Includes = { CreateCppFile("anonStructure", @" struct Test { struct { int field; }; }; ") } }; var model = ParseCpp(config); var generatedStruct = model.FindFirst <CppStruct>("Test"); Assert.Single(generatedStruct.Find <CppField>("Test::field")); }
public void Simple() { var config = new Config.ConfigFile { Id = nameof(Simple), Namespace = nameof(Simple), Assembly = nameof(Simple), Includes = { new Config.IncludeRule { File = "simple.h", Attach = true, Namespace = nameof(Simple) } }, Bindings = { new Config.BindRule("int", "System.Int32") } }; var cppStruct = new CppStruct { Name = "struct" }; cppStruct.Add(new CppField { Name = "field", TypeName = "int" }); var cppInclude = new CppInclude { Name = "simple" }; var cppModule = new CppModule(); cppModule.Add(cppInclude); cppInclude.Add(cppStruct); var(solution, _) = MapModel(cppModule, config); Assert.Single(solution.EnumerateDescendants().OfType <CsStruct>()); var csStruct = solution.EnumerateDescendants().OfType <CsStruct>().First(); Assert.Single(csStruct.Fields.Where(fld => fld.Name == "Field")); var field = csStruct.Fields.First(fld => fld.Name == "Field"); Assert.IsType <CsFundamentalType>(field.PublicType); var fundamental = (CsFundamentalType)field.PublicType; Assert.Equal(typeof(int), fundamental.Type); }
public void EmptyConfigFails() { var testDirectory = GenerateTestDirectory(); var config = new Config.ConfigFile { }; Assert.False(RunWithConfig(config, failTestOnError: false).success); }
public void MappingNameRuleRenamesStructMember() { var config = new Config.ConfigFile { Id = nameof(MappingNameRuleRenamesStructMember), Namespace = nameof(MappingNameRuleRenamesStructMember), Assembly = nameof(MappingNameRuleRenamesStructMember), Includes = { new Config.IncludeRule { File = "simpleStruct.h", Attach = true, Namespace = nameof(MappingNameRuleRenamesStructMember) } }, Bindings = { new Config.BindRule("int", "System.Int32") }, Mappings = { new Config.MappingRule { Field = "Test::field", MappingName = "MyField" } } }; var cppStruct = new CppStruct { Name = "Test" }; cppStruct.Add(new CppField { Name = "field", TypeName = "int" }); var include = new CppInclude { Name = "simpleStruct" }; include.Add(cppStruct); var module = new CppModule(); module.Add(include); var(solution, _) = MapModel(module, config); var csStruct = solution.EnumerateDescendants().OfType <CsStruct>().First(element => element.Name == "Test"); Assert.Single(csStruct.Fields.Where(field => field.Name == "MyField")); }
public void RemoveParentDoesNotRemoveAllParents() { var config = new Config.ConfigFile { Id = nameof(RemoveParentDoesNotRemoveAllParents), Assembly = nameof(RemoveParentDoesNotRemoveAllParents), Namespace = nameof(RemoveParentDoesNotRemoveAllParents), Includes = { new Config.IncludeRule { Attach = true, File = "cppEnum.h", Namespace = nameof(RemoveParentDoesNotRemoveAllParents) } }, Mappings = { new Config.RemoveRule { Method = @"#.*ToRemove" } } }; var cppModel = new CppModule(); var cppInclude = new CppInclude { Name = "cppEnum" }; var cppIface = new CppInterface { Name = "TestInterface" }; cppInclude.Add(cppIface); var cppMethod = new CppMethod { Name = "Method" }; cppMethod.Add(new CppParameter { Name = "ParamToRemove" }); cppModel.Add(cppInclude); var(solution, _) = MapModel(cppModel, config); var members = solution.EnumerateDescendants(); Assert.NotEmpty(members.OfType <CsInterface>()); Assert.Empty(members.OfType <CsParameter>()); }
/// <summary> /// Callback function that is called whenever a keyboard event is fired. /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { //Load the game config file. Config.ConfigFile gameConfigFile = null; //Get the dictionary of keys from the configs Dictionary <string, string> keyDictionary = RemapKeys(gameConfigFile); //If a keyboard key was pressed. if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { //Parse the key mapping out of the config files. string pressedKeyString = ((Keys)Marshal.ReadInt32(lParam)).ToString(); //This is the key that the user pressed and we want to replace it with a new key. if (!keyPressed) { //If the database has the key, send off the replacement. if (keyDictionary.ContainsKey(pressedKeyString)) { keyPressed = true; SendKeys.Send(keyDictionary[pressedKeyString]);//Use SendKeys to simulate the key press in another application } //If the database doesn't have the key, reset the flag and ignore it. else { keyPressed = false; } //Always ignore the first key that a person presses. return((System.IntPtr) 1); } //After we send the key we want to send, it comes to the callback a second time. //Just let it through and reset the flag. else { keyPressed = false; } //Replace the pressed key with a new key and pass it along /*KBDLLHOOKSTRUCT replacementKey = new KBDLLHOOKSTRUCT(); * IntPtr newlParam = lParam; * Marshal.PtrToStructure(newlParam, replacementKey); * replacementKey.vkCode = (uint)remappedKey;//Set the key to a new key. * Marshal.StructureToPtr(replacementKey, newlParam, true);*/ //Return nothing to block the key presses. //return (System.IntPtr)1; //return CallNextHookEx(_hookID, nCode, wParam, newlParam); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
private void UpdateTagsThread() { Song song; bool fixErrors = DateTime.Now > _lastFixErrors + TimeSpan.FromMinutes(2); List <ManualResetEvent> doneEvents = new List <ManualResetEvent>(); Config.ConfigFile config = SongPlayerFactory.GetConfigFile(); string[] extensionsArray = config.GetValue("library.extensions").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.StartsWith(".", StringComparison.OrdinalIgnoreCase) ? x : "." + x) .ToArray(); HashSet <string> extensions = new HashSet <string>(extensionsArray, StringComparer.OrdinalIgnoreCase); if (extensions.Count == 0) { extensions.Add(".mp3"); } do { //Lock collection as short as possible lock (lockObject) { if (fixErrors) { song = _songs.Values.FirstOrDefault(s => s.TagRead == false); } else { song = _songs.Values.FirstOrDefault(s => s.TagRead == false && s.ErrorReadingTag == false); } } if (song != null) { if (extensions.Contains(song.Extension)) { if (song.ErrorReadingTag) { _lastFixErrors = DateTime.Now; } // update song UpdateSingleTag(song); _updatedTag = true; } } // loop until no song found } while (song != null); // finished this run _updateRunning = false; }
public void SaveConfigFile(Config.ConfigFile config, string configName) { config.Id = configName; var serializer = new XmlSerializer(typeof(Config.ConfigFile)); using (var configFile = File.Create(Path.Combine(testDirectory.FullName, configName + "-Mapping.xml"))) { serializer.Serialize(configFile, config); } }
public void IUnknownMappingGeneratesCorrectClass() { var testDirectory = GenerateTestDirectory(); var config = new Config.ConfigFile { Namespace = nameof(IUnknownMappingGeneratesCorrectClass), Assembly = nameof(IUnknownMappingGeneratesCorrectClass), IncludeProlog = { ComIncludeProlog }, IncludeDirs = { new Config.IncludeDirRule(@"=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots\KitsRoot10;Include\10.0.15063.0\shared"), new Config.IncludeDirRule(@"=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots\KitsRoot10;Include\10.0.15063.0\um"), new Config.IncludeDirRule(@"=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots\KitsRoot10;Include\10.0.15063.0\ucrt"), new Config.IncludeDirRule(@"$(VC_TOOLS_PATH)\include") }, Includes = { new Config.IncludeRule { File = "windows.h" }, new Config.IncludeRule { File = "Unknwnbase.h", AttachTypes = new List <string> { "IUnknown", }, Namespace = nameof(IUnknownMappingGeneratesCorrectClass) } }, Bindings = { new Config.BindRule("int", "System.Int32"), new Config.BindRule("GUID", "System.Guid"), new Config.BindRule("void", "System.Void"), new Config.BindRule("unsigned int", "System.UInt32") } }; (bool success, string output) = RunWithConfig(config); AssertRanSuccessfully(success, output); var compilation = GetCompilationForGeneratedCode(); var iUnknown = compilation.GetTypeByMetadataName($"{nameof(IUnknownMappingGeneratesCorrectClass)}.IUnknown"); AssertMethodCalliIndex(iUnknown.GetMembers("QueryInterface").Single(), 0); AssertMethodCalliIndex(iUnknown.GetMembers("AddRef").Single(), 1); AssertMethodCalliIndex(iUnknown.GetMembers("Release").Single(), 2); }
public void Enum() { var config = new Config.ConfigFile { Id = nameof(Enum), Assembly = nameof(Enum), Namespace = nameof(Enum), Includes = { new Config.IncludeRule { Attach = true, File = "cppEnum.h", Namespace = nameof(Enum) } }, Mappings = { new Config.RemoveRule { Enum = @".*ToRemove\d+" } } }; var cppModel = new CppModule(); var cppInclude = new CppInclude { Name = "cppEnum" }; var cppEnum = new CppEnum { Name = "TestEnum" }; cppInclude.Add(cppEnum); cppInclude.Add(new CppEnum { Name = "EnumToRemove1" }); cppModel.Add(cppInclude); var(solution, _) = MapModel(cppModel, config); var members = solution.EnumerateDescendants(); Assert.Single(members.OfType <CsEnum>()); }
/// <summary> /// Populate a dictionary of hard-mapped keys to game-sepcific keys /// </summary> public static Dictionary <string, string> RemapKeys(Config.ConfigFile gameConfigFile) { Dictionary <string, string> remapDictionary = new Dictionary <string, string>(); //Loop over every key for (int i = 0; i < keyMapConfigKeys.Length; i++) { //Map the global config key to the game config key remapDictionary.Add(Program.GlobalConfig.GetString(keyMapConfigSection, keyMapConfigKeys[i]), TheAlphabet[i % 10].ToLower());//Until we are able to properly load the gameconfig, just be random //gameConfigFile.GetString(keyMapConfigSection, keyMapConfigKeys[i])); } return(remapDictionary); }
public void ExplicitValues() { var config = new Config.ConfigFile { Id = nameof(ExplicitValues), Assembly = nameof(ExplicitValues), Namespace = nameof(ExplicitValues), Includes = { new Config.IncludeRule { Attach = true, File = "cppEnum.h", Namespace = nameof(ExplicitValues) } } }; var cppModel = new CppModule(); var cppInclude = new CppInclude { Name = "cppEnum" }; var cppEnum = new CppEnum { Name = "TestEnum" }; cppEnum.AddEnumItem("Element1", "10"); cppEnum.AddEnumItem("Element2", "15"); cppEnum.AddEnumItem("Element3", "10"); cppInclude.Add(cppEnum); cppModel.Add(cppInclude); var(solution, _) = MapModel(cppModel, config); var members = solution.EnumerateDescendants(); Assert.Single(members.OfType <CsEnum>()); var csEnum = members.OfType <CsEnum>().First(); Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element1" && item.Value == "10")); Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element2" && item.Value == "15")); Assert.Single(csEnum.EnumItems.Where(item => item.Name == "Element3" && item.Value == "10")); Assert.Equal(typeof(int), csEnum.UnderlyingType.Type); }
public World(string name) { config = new Config.ConfigFile(name + "/" + name + ".tssc"); }