public void RoundTrippingLdmlDoesNotDuplicateSections() { using (var roundTripOut2 = new TempFile()) using (var roundTripOut = new TempFile()) using (var tempFile = new TempFile()) { using (var writer = new StreamWriter(tempFile.Path, false, Encoding.UTF8)) { writer.Write( @"<?xml version='1.0' encoding='utf-8'?> <ldml> <identity> <version number='' /> <language type='qaa' /> <variant type='x-lel' /> </identity> <collations /> <special xmlns:fw='urn://fieldworks.sil.org/ldmlExtensions/v1'> <fw:graphiteEnabled value='False' /> <fw:windowsLCID value='1036' /> </special> </ldml>".Replace("'", "\"")); } var ws = new WritingSystemDefinition(); var dataMapper = new LdmlDataMapper(); dataMapper.Read(tempFile.Path, ws); var keyboard1 = new DefaultKeyboardDefinition(); keyboard1.Locale = "en-US"; keyboard1.Layout = "MyFavoriteKeyboard"; keyboard1.OperatingSystem = PlatformID.MacOSX; // pick something that for sure won't be our default ws.AddKnownKeyboard(keyboard1); using (var fileStream = new FileStream(tempFile.Path, FileMode.Open)) { dataMapper.Write(roundTripOut.Path, ws, fileStream); } AssertThatXmlIn.File(roundTripOut.Path).HasSpecifiedNumberOfMatchesForXpath("/ldml/special/*[local-name()='windowsLCID']", 1); var secondTripMapper = new LdmlDataMapper(); var secondTripWs = new WritingSystemDefinition(); secondTripMapper.Read(roundTripOut.Path, secondTripWs); secondTripWs.AddKnownKeyboard(new DefaultKeyboardDefinition() { Locale = "qaa", Layout = "x-tel", OperatingSystem = PlatformID.Xbox }); secondTripWs.WindowsLcid = "1037"; using (var fileStream = new FileStream(roundTripOut.Path, FileMode.Open)) { secondTripMapper.Write(roundTripOut2.Path, secondTripWs, fileStream); } AssertThatXmlIn.File(roundTripOut2.Path).HasSpecifiedNumberOfMatchesForXpath("/ldml/special/*[local-name()='windowsLCID']", 1); //Element duplicated on round trip } }
public void RoundtripKnownKeyboards() { var ldmlAdaptor = new LdmlDataMapper(); Keyboard.Controller = new MyKeyboardController(); const string sortRules = "(A̍ a̍)"; var wsWithKnownKeyboards = new WritingSystemDefinition(); var keyboard1 = new DefaultKeyboardDefinition(); keyboard1.Locale = "en-US"; keyboard1.Layout = "MyFavoriteKeyboard"; keyboard1.OperatingSystem = PlatformID.MacOSX; // pick something that for sure won't be our default wsWithKnownKeyboards.AddKnownKeyboard(keyboard1); var keyboard2 = new DefaultKeyboardDefinition(); keyboard2.Locale = "en-GB"; keyboard2.Layout = "SusannasFavoriteKeyboard"; keyboard2.OperatingSystem = PlatformID.Unix; wsWithKnownKeyboards.AddKnownKeyboard(keyboard2); var wsFromLdml = new WritingSystemDefinition(); using (var tempFile = new TempFile()) { ldmlAdaptor.Write(tempFile.Path, wsWithKnownKeyboards, null); ldmlAdaptor.Read(tempFile.Path, wsFromLdml); } var knownKeyboards = wsFromLdml.KnownKeyboards.ToList(); Assert.That(knownKeyboards, Has.Count.EqualTo(2), "restored WS should have known keyboards"); var keyboard1FromLdml = knownKeyboards[0]; Assert.That(keyboard1FromLdml.Layout, Is.EqualTo("MyFavoriteKeyboard")); Assert.That(keyboard1FromLdml.Locale, Is.EqualTo("en-US")); Assert.That(keyboard1FromLdml.OperatingSystem, Is.EqualTo(PlatformID.MacOSX)); Assert.That(keyboard1FromLdml, Is.InstanceOf <MyKeyboardDefn>(), "Reader should have used controller to create keyboard defn"); var keyboard2FromLdml = knownKeyboards[1]; Assert.That(keyboard2FromLdml.Layout, Is.EqualTo("SusannasFavoriteKeyboard")); Assert.That(keyboard2FromLdml.Locale, Is.EqualTo("en-GB")); Assert.That(keyboard2FromLdml.OperatingSystem, Is.EqualTo(PlatformID.Unix)); }
public void RoundTrippingLdmlDoesNotDuplicateSections() { using(var roundTripOut2 = new TempFile()) using(var roundTripOut = new TempFile()) using(var tempFile = new TempFile()) { using(var writer = new StreamWriter(tempFile.Path, false, Encoding.UTF8)) { writer.Write( @"<?xml version='1.0' encoding='utf-8'?> <ldml> <identity> <version number='' /> <language type='qaa' /> <variant type='x-lel' /> </identity> <collations /> <special xmlns:fw='urn://fieldworks.sil.org/ldmlExtensions/v1'> <fw:graphiteEnabled value='False' /> <fw:windowsLCID value='1036' /> </special> </ldml>".Replace("'", "\"")); } var ws = new WritingSystemDefinition(); var dataMapper = new LdmlDataMapper(); dataMapper.Read(tempFile.Path, ws); var keyboard1 = new DefaultKeyboardDefinition(); keyboard1.Locale = "en-US"; keyboard1.Layout = "MyFavoriteKeyboard"; keyboard1.OperatingSystem = PlatformID.MacOSX; // pick something that for sure won't be our default ws.AddKnownKeyboard(keyboard1); using(var fileStream = new FileStream(tempFile.Path, FileMode.Open)) { dataMapper.Write(roundTripOut.Path, ws, fileStream); } AssertThatXmlIn.File(roundTripOut.Path).HasSpecifiedNumberOfMatchesForXpath("/ldml/special/*[local-name()='windowsLCID']", 1); var secondTripMapper = new LdmlDataMapper(); var secondTripWs = new WritingSystemDefinition(); secondTripMapper.Read(roundTripOut.Path, secondTripWs); secondTripWs.AddKnownKeyboard(new DefaultKeyboardDefinition() { Locale = "qaa", Layout = "x-tel", OperatingSystem = PlatformID.Xbox }); secondTripWs.WindowsLcid = "1037"; using(var fileStream = new FileStream(roundTripOut.Path, FileMode.Open)) { secondTripMapper.Write(roundTripOut2.Path, secondTripWs, fileStream); } AssertThatXmlIn.File(roundTripOut2.Path).HasSpecifiedNumberOfMatchesForXpath("/ldml/special/*[local-name()='windowsLCID']", 1); //Element duplicated on round trip } }
public void RoundtripKnownKeyboards() { var ldmlAdaptor = new LdmlDataMapper(); Keyboard.Controller = new MyKeyboardController(); const string sortRules = "(A̍ a̍)"; var wsWithKnownKeyboards = new WritingSystemDefinition(); var keyboard1 = new DefaultKeyboardDefinition(); keyboard1.Locale = "en-US"; keyboard1.Layout = "MyFavoriteKeyboard"; keyboard1.OperatingSystem = PlatformID.MacOSX; // pick something that for sure won't be our default wsWithKnownKeyboards.AddKnownKeyboard(keyboard1); var keyboard2 = new DefaultKeyboardDefinition(); keyboard2.Locale = "en-GB"; keyboard2.Layout = "SusannasFavoriteKeyboard"; keyboard2.OperatingSystem = PlatformID.Unix; wsWithKnownKeyboards.AddKnownKeyboard(keyboard2); var wsFromLdml = new WritingSystemDefinition(); using (var tempFile = new TempFile()) { ldmlAdaptor.Write(tempFile.Path, wsWithKnownKeyboards, null); ldmlAdaptor.Read(tempFile.Path, wsFromLdml); } var knownKeyboards = wsFromLdml.KnownKeyboards.ToList(); Assert.That(knownKeyboards, Has.Count.EqualTo(2), "restored WS should have known keyboards"); var keyboard1FromLdml = knownKeyboards[0]; Assert.That(keyboard1FromLdml.Layout, Is.EqualTo("MyFavoriteKeyboard")); Assert.That(keyboard1FromLdml.Locale, Is.EqualTo("en-US")); Assert.That(keyboard1FromLdml.OperatingSystem, Is.EqualTo(PlatformID.MacOSX)); Assert.That(keyboard1FromLdml, Is.InstanceOf<MyKeyboardDefn>(), "Reader should have used controller to create keyboard defn"); var keyboard2FromLdml = knownKeyboards[1]; Assert.That(keyboard2FromLdml.Layout, Is.EqualTo("SusannasFavoriteKeyboard")); Assert.That(keyboard2FromLdml.Locale, Is.EqualTo("en-GB")); Assert.That(keyboard2FromLdml.OperatingSystem, Is.EqualTo(PlatformID.Unix)); }