Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net8windows keyboarding and writing systems #1366

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions SIL.Windows.Forms.Keyboarding.Tests/KeyboardControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@
using System.Globalization;
using NUnit.Framework;
using SIL.Keyboarding;
using Rhino.Mocks;
using Moq;

namespace SIL.Windows.Forms.Keyboarding.Tests
{
[TestFixture]
public class KeyboardControllerTests
{
private IKeyboardRetrievingAdaptor _mockKeyboardAdaptor = MockRepository.GenerateMock<IKeyboardRetrievingAdaptor>();
private Mock<IKeyboardRetrievingAdaptor> _mockKeyboardAdaptor = new Mock<IKeyboardRetrievingAdaptor>();

[SetUp]
public void Setup()
{
// To avoid OS specific behavior in these tests we mock up our own keyboard adaptor returning appropriate values to enable these tests
_mockKeyboardAdaptor.Stub(k => k.IsApplicable).Return(true);
_mockKeyboardAdaptor.Stub(k => k.Type).Return(KeyboardAdaptorType.System);
_mockKeyboardAdaptor.Stub(k => k.CanHandleFormat(KeyboardFormat.Unknown)).Return(true);
_mockKeyboardAdaptor.Stub(k => k.CreateKeyboardDefinition(Arg<string>.Is.Anything)).Return(null) // will be ignored but still the API requires it
.WhenCalled(k =>
_mockKeyboardAdaptor.Setup(k => k.IsApplicable).Returns(true);
_mockKeyboardAdaptor.Setup(k => k.Type).Returns(KeyboardAdaptorType.System);
_mockKeyboardAdaptor.Setup(k => k.CanHandleFormat(KeyboardFormat.Unknown)).Returns(true);
_mockKeyboardAdaptor.Setup(k => k.CreateKeyboardDefinition(It.IsAny<string>())).Returns<string>(
id =>
{
var id = (string)k.Arguments[0];
var idParts = id.Split('_');
var mockKd = new MockKeyboardDescription(id, idParts[0], idParts[1]);
k.ReturnValue = mockKd;
return mockKd;
});
KeyboardController.Initialize(_mockKeyboardAdaptor);
KeyboardController.Initialize(_mockKeyboardAdaptor.Object);
}

[TearDown]
Expand Down Expand Up @@ -118,7 +117,7 @@ public void GetKeyboard_FromInputLanguage_NonExistingKeyboard()
}

/// <summary>
/// This mock (less code than a Rhino.Mocks version) provides sufficient IKeyboardDefinition for testing the KeyboardController
/// This mock provides sufficient IKeyboardDefinition for testing the KeyboardController
/// </summary>
private class MockKeyboardDescription : KeyboardDescription
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<RootNamespace>SIL.Windows.Forms.Keyboarding.Tests</RootNamespace>
<AssemblyTitle>SIL.Windows.Forms.Keyboarding.Tests</AssemblyTitle>
<Description>Unit tests for SIL.Windows.Forms.Keyboarding</Description>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

Expand All @@ -16,7 +17,6 @@
<PackageReference Include="NDesk.DBus" Version="0.15.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" PrivateAssets="All" />
<PackageReference Include="RhinoMocks" Version="3.6.1" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand All @@ -25,8 +25,27 @@
<ProjectReference Include="..\SIL.Windows.Forms.Keyboarding\SIL.Windows.Forms.Keyboarding.csproj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition=" $(DefineConstants.Contains('NETFRAMEWORK')) ">
<Reference Include="System.Windows.Forms" />
</ItemGroup>

<!-- explicitly remove Linux files for Windows -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<Compile Remove="TestHelper\GnomeKeyboardRetrievingHelperDouble.cs" />
<Compile Remove="TestHelper\GnomeShellIbusKeyboardRetrievingAdaptorDouble.cs" />
<Compile Remove="CombinedIbusKeyboardRetrievingAdaptorTests.cs" />
<Compile Remove="CombinedIbusKeyboardSwitchingAdaptorTests.cs" />
<Compile Remove="GnomeKeyboardRetrievingHelperTests.cs" />
<Compile Remove="GnomeShellIbusKeyboardRetrievingAdaptorTests.cs" />
<Compile Remove="GnomeShellIbusKeyboardSwitchingAdaptorTests.cs" />
<Compile Remove="IbusDefaultEventHandlerTests.cs" />
<Compile Remove="IbusKeyboardAdaptorTests.cs" />
<Compile Remove="IbusKeyboardDescriptionTests.cs" />
<Compile Remove="IbusXkbKeyboardDescriptionTests.cs" />
<Compile Remove="LinuxKeyboardControllerTests.cs" />
<Compile Remove="UnityKeyboardRetrievingHelperTests.cs" />
<Compile Remove="XkbKeyboardAdapterTests.cs" />
<Compile Remove="XklEngineTests.cs" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions SIL.Windows.Forms.Keyboarding/KeyboardController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using SIL.ObjectModel;
using SIL.PlatformUtilities;
using SIL.Reporting;
#if NETFRAMEWORK
using SIL.Windows.Forms.Keyboarding.Linux;
#endif
using SIL.Windows.Forms.Keyboarding.Windows;

namespace SIL.Windows.Forms.Keyboarding
Expand Down Expand Up @@ -217,10 +219,12 @@ private void SetDefaultKeyboardAdaptors()
}
: new IKeyboardRetrievingAdaptor[]
{
#if NETFRAMEWORK
new XkbKeyboardRetrievingAdaptor(), new IbusKeyboardRetrievingAdaptor(),
new UnityXkbKeyboardRetrievingAdaptor(), new UnityIbusKeyboardRetrievingAdaptor(),
new CombinedIbusKeyboardRetrievingAdaptor(),
new GnomeShellIbusKeyboardRetrievingAdaptor()
#endif
}
);
}
Expand Down
15 changes: 13 additions & 2 deletions SIL.Windows.Forms.Keyboarding/SIL.Windows.Forms.Keyboarding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
<RootNamespace>SIL.Windows.Forms.Keyboarding</RootNamespace>
<AssemblyTitle>SIL.Windows.Forms.Keyboarding</AssemblyTitle>
<Description>The SIL.Windows.Forms.Keyboarding library provides cross-platform functionality for keyboard selection and switching in Windows Forms applications. Currently, this library supports system and Keyman keyboards on Windows, and X keyboard extension (XKB) and Intelligent Input Bus (IBus) keyboards on Linux.</Description>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<Content Remove="Linux\**" />
<Compile Remove="Linux\**" />
<EmbeddedResource Remove="Linux\**" />
<None Remove="Linux\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
<PackageReference Include="ibusdotnet" Version="2.0.3" />
Expand All @@ -23,6 +31,11 @@
<ProjectReference Include="..\SIL.Core\SIL.Core.csproj" />
</ItemGroup>

<ItemGroup Condition=" $(DefineConstants.Contains('NETFRAMEWORK')) ">
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>

<ItemGroup>
<Reference Include="Keyman10Interop">
<HintPath>..\lib\Keyman10Interop.dll</HintPath>
Expand All @@ -33,8 +46,6 @@
<Reference Include="KeymanLink">
<HintPath>..\lib\KeymanLink.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<None Include="../lib/Keyman*.dll">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<IsPackable>false</IsPackable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<RootNamespace>SIL.Windows.Forms.WritingSystems</RootNamespace>
<AssemblyTitle>SIL.Windows.Forms.WritingSystems</AssemblyTitle>
<Description>SIL.Windows.Forms.WritingSystems contains Windows Forms UI elements for displaying and editing writing systems as defined by the SIL.WritingSystems assembly.</Description>
<TargetFrameworks>$(TargetFrameworks);net8.0-windows</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>
Expand Down
Loading