private void OnWritingSystemSetupDialogClicked(object sender, EventArgs e) { string tempPath = Path.GetTempPath() + "WS-Test"; Directory.CreateDirectory(tempPath); KeyboardController.Initialize(); try { var wsRepo = LdmlInFolderWritingSystemRepository.Initialize(tempPath, onMigration, onLoadProblem); using (var dialog = new WritingSystemSetupDialog(wsRepo)) { dialog.WritingSystems.LocalKeyboardSettings = Settings.Default.LocalKeyboards; dialog.ShowDialog(); Settings.Default.LocalKeyboards = dialog.WritingSystems.LocalKeyboardSettings; Settings.Default.Save(); } } catch (Exception) { throw; } finally { KeyboardController.Shutdown(); } }
private void _openDirectory_Click(object sender, EventArgs e) { var openDir = new FolderBrowserDialog(); openDir.RootFolder = Environment.SpecialFolder.Personal; // Set the help text description for the FolderBrowserDialog. openDir.Description = "Select the folder with Writing Systems"; // Allow the user to create new files via the FolderBrowserDialog. openDir.ShowNewFolderButton = true; // Display the openFile dialog. DialogResult result = openDir.ShowDialog(); if (result == DialogResult.OK) { string newDir = openDir.SelectedPath; var ldmlRepo = _model.WritingSystems as LdmlInFolderWritingSystemRepository; IEnumerable <ICustomDataMapper <WritingSystemDefinition> > customDataMappers = ldmlRepo != null ? ldmlRepo.CustomDataMappers : Enumerable.Empty <ICustomDataMapper <WritingSystemDefinition> >(); LdmlInFolderWritingSystemRepository repository = LdmlInFolderWritingSystemRepository.Initialize(newDir, customDataMappers); var dlg = new WritingSystemSetupDialog(repository); dlg.WritingSystemSuggestor.SuggestVoice = true; dlg.WritingSystemSuggestor.OtherKnownWritingSystems = null; dlg.Text = String.Format("Writing Systems in folder {0}", newDir); dlg.Show(); } }
public void Save_WritingSystemIdChanged_ChangeLogUpdated() { using (var e = new TestEnvironment()) { var repo = LdmlInFolderWritingSystemRepository.Initialize(Path.Combine(e.TestPath, "idchangedtest1"), DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws = WritingSystemDefinition.Parse("en"); repo.Set(ws); repo.Save(); ws.Script = "Latn"; repo.Set(ws); ws.Script = "Thai"; repo.Set(ws); var ws2 = WritingSystemDefinition.Parse("de"); repo.Set(ws2); ws2.Script = "Latn"; repo.Save(); string logFilePath = Path.Combine(repo.PathToWritingSystems, "idchangelog.xml"); AssertThatXmlIn.File(logFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/From[text()='en']"); AssertThatXmlIn.File(logFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Change/To[text()='en-Thai']"); // writing systems added for the first time shouldn't be in the log as a change AssertThatXmlIn.File(logFilePath).HasNoMatchForXpath("/WritingSystemChangeLog/Changes/Change/From[text()='de']"); } }
private void OnWritingSystemSetupDialogClicked(object sender, EventArgs e) { string tempPath = Path.GetTempPath() + "WS-Test"; Directory.CreateDirectory(tempPath); if (!_KeyboardControllerInitialized) { KeyboardController.Initialize(); _KeyboardControllerInitialized = true; foreach (string key in ErrorReport.Properties.Keys) { Console.WriteLine("{0}: {1}", key, ErrorReport.Properties[key]); } } ICustomDataMapper <WritingSystemDefinition>[] customDataMappers = { new UserLexiconSettingsWritingSystemDataMapper(new ApplicationSettingsStore(Properties.Settings.Default, "UserSettings")), new ProjectLexiconSettingsWritingSystemDataMapper(new ApplicationSettingsStore(Properties.Settings.Default, "ProjectSettings")) }; LdmlInFolderWritingSystemRepository wsRepo = LdmlInFolderWritingSystemRepository.Initialize(tempPath, customDataMappers); using (var dialog = new WritingSystemSetupDialog(wsRepo)) dialog.ShowDialog(); }
private void _openDirectory_Click(object sender, EventArgs e) { FolderBrowserDialog openDir = new FolderBrowserDialog(); openDir.RootFolder = Environment.SpecialFolder.Personal; // Set the help text description for the FolderBrowserDialog. openDir.Description = "Select the folder with Writing Systems"; // Allow the user to create new files via the FolderBrowserDialog. openDir.ShowNewFolderButton = true; // Display the openFile dialog. DialogResult result = openDir.ShowDialog(); if (result == DialogResult.OK) { var newDir = openDir.SelectedPath; var repository = LdmlInFolderWritingSystemRepository.Initialize(newDir, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var dlg = new WritingSystemSetupDialog(repository); dlg.WritingSystemSuggestor.SuggestVoice = true; dlg.WritingSystemSuggestor.OtherKnownWritingSystems = null; dlg.Text = String.Format("Writing Systems in folder {0}", newDir); dlg.Show(); } }
/// <summary> Exports vernacular language character set to an ldml file </summary> private static void LdmlExport(string filePath, string vernacularBcp47, List <string> validChars) { var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath); var wsf = new LdmlInFolderWritingSystemFactory(wsr); wsf.Create(vernacularBcp47, out var wsDef); // If there isn't already a main character set defined, // make one and add it to the writing system definition. if (!wsDef.CharacterSets.TryGet("main", out var chars)) { chars = new CharacterSetDefinition("main"); wsDef.CharacterSets.Add(chars); } // Replace all the characters found with our copy of the character set chars.Characters.Clear(); foreach (var character in validChars) { chars.Characters.Add(character); } // Write out the new definition wsr.Set(wsDef); wsr.Save(); }
public void Constructor_LdmlFolderStoreContainsMultipleFilesThatOnLoadDescribeWritingSystemsWithIdenticalRFC5646Tags_Throws() { using (var environment = new TestEnvironment()) { File.WriteAllText(Path.Combine(environment.TestPath, "de-Zxxx-x-audio.ldml"), LdmlContentForTests.CurrentVersion("de", WellKnownSubTags.Audio.Script, "", WellKnownSubTags.Audio.PrivateUseSubtag)); File.WriteAllText(Path.Combine(environment.TestPath, "inconsistent-filename.ldml"), LdmlContentForTests.CurrentVersion("de", WellKnownSubTags.Audio.Script, "", WellKnownSubTags.Audio.PrivateUseSubtag)); var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath); var problems = repository.LoadProblems; Assert.That(problems.Count, Is.EqualTo(2)); Assert.That( problems[0].Exception, Is.TypeOf <ApplicationException>().With.Property("Message"). ContainsSubstring(String.Format( @"The writing system file {0} seems to be named inconsistently. It contains the Rfc5646 tag: 'de-Zxxx-x-audio'. The name should have been made consistent with its content upon migration of the writing systems.", Path.Combine(environment.TestPath, "inconsistent-filename.ldml") )) ); Assert.That( problems[1].Exception, Is.TypeOf <ArgumentException>().With.Property("Message"). ContainsSubstring("Unable to set writing system 'de-Zxxx-x-audio' because this id already exists. Please change this writing system id before setting it.") ); } }
private static IWritingSystemRepository GetWritingSystemRepository(string writingSystemdPath) { return(LdmlInFolderWritingSystemRepository.Initialize( writingSystemdPath, OnWritingSystemMigration, OnWritingSystemLoadProblem, WritingSystemCompatibility.Flex7V0Compatible )); }
public static WeSayWordsProject InitializeForTests() { WeSayWordsProject project = new WeSayWordsProject(); try { File.Delete(WeSayWordsProject.PathToPretendLiftFile); } catch (Exception) { } DirectoryInfo projectDirectory = Directory.CreateDirectory(Path.GetDirectoryName(WeSayWordsProject.PathToPretendLiftFile)); string pathToLdmlWsFolder = BasilProject.GetPathToLdmlWritingSystemsFolder(projectDirectory.FullName); if (File.Exists(WeSayWordsProject.PathToPretendWritingSystemPrefs)) { File.Delete(WeSayWordsProject.PathToPretendWritingSystemPrefs); } if (Directory.Exists(pathToLdmlWsFolder)) { Directory.Delete(pathToLdmlWsFolder, true); } Palaso.Lift.Utilities.CreateEmptyLiftFile(WeSayWordsProject.PathToPretendLiftFile, "InitializeForTests()", true); //setup writing systems Directory.CreateDirectory(pathToLdmlWsFolder); IWritingSystemRepository wsc = LdmlInFolderWritingSystemRepository.Initialize( pathToLdmlWsFolder, OnMigrationHandler, OnWritingSystemLoadProblem, WritingSystemCompatibility.Flex7V0Compatible ); IWritingSystemDefinition _ws1 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.VernacularIdForTest); _ws1.DefaultFontName = "Arial"; _ws1.DefaultFontSize = 30; wsc.Set(_ws1); IWritingSystemDefinition _ws2 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.AnalysisIdForTest); _ws2.DefaultFontName = new Font(FontFamily.GenericSansSerif, 12).Name; _ws2.DefaultFontSize = new Font(FontFamily.GenericSansSerif, 12).Size; wsc.Set(_ws2); IWritingSystemDefinition _ws3 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.OtherIdForTest); _ws3.DefaultFontName = "Arial"; _ws3.DefaultFontSize = 15; wsc.Set(_ws3); wsc.Save(); project.SetupProjectDirForTests(WeSayWordsProject.PathToPretendLiftFile); project.BackupMaker = null; //don't bother. Modern tests which might want to check backup won't be using this old approach anyways. return(project); }
public void Set_NewWritingSystem_StoreContainsWritingSystem() { using (var environment = new TestEnvironment()) { var ws = new WritingSystemDefinition("en"); environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); environment.Collection.Set(ws); Assert.That(environment.Collection.Get("en").Bcp47Tag, Is.EqualTo("en")); } }
public void LoadAllDefinitions_WsIsValidRfc5646TagStartingWithx_IsNotTreatedAsFlexPrivateUseAndThrows() { using (var environment = new TestEnvironment()) { var ldmlPath = Path.Combine(environment.TestPath, "xh.ldml"); File.WriteAllText(ldmlPath, LdmlContentForTests.Version0("xh", "", "", "")); var repo = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Strict); //Assert.That(() => new LdmlInFolderWritingSystemRepository(environment.TestPath), Throws.Exception.TypeOf<ApplicationException>()); } }
public void SavesWhenDirectoryNotFound() { using (var environment = new TestEnvironment()) { var newRepoPath = Path.Combine(environment.TestPath, "newguy"); var newRepository = LdmlInFolderWritingSystemRepository.Initialize(newRepoPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); newRepository.SaveDefinition(environment.WritingSystem); Assert.That(File.Exists(Path.Combine(newRepoPath, environment.WritingSystem.Bcp47Tag + ".ldml"))); } }
public TestEnvironment() { var writingSystemRepository = LdmlInFolderWritingSystemRepository.Initialize( _folder.Path, OnMigration, OnLoadProblem ); MockSetupModel = new Mock <WritingSystemSetupModel>(writingSystemRepository); SetDefinitionsInStore(new WritingSystemDefinition[] { }); }
public void MarkedAsNotModifiedWhenLoaded() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; environment.Collection.SaveDefinition(environment.WritingSystem); var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = newCollection.Get(environment.WritingSystem.StoreID); Assert.IsFalse(ws2.Modified); } }
public WritingSystemSetupDialog( string writingSystemRepositoryPath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler, WritingSystemLoadProblemHandler loadProblemHandler ) : this(LdmlInFolderWritingSystemRepository.Initialize( writingSystemRepositoryPath, migrationHandler, loadProblemHandler )) { }
public void SaveDefinition_WritingSystemCameFromFlexPrivateUseLdml_FileNameIsRetained() { using (var environment = new TestEnvironment()) { var pathToFlexprivateUseLdml = Path.Combine(environment.TestPath, "x-Zxxx-x-audio.ldml"); File.WriteAllText(pathToFlexprivateUseLdml, LdmlContentForTests.Version0("x", "Zxxx", "", "x-audio")); environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Flex7V0Compatible); var ws = environment.Collection.Get("x-Zxxx-x-audio"); environment.Collection.SaveDefinition(ws); Assert.That(File.Exists(pathToFlexprivateUseLdml)); } }
public void Constructor_LdmlFolderStoreContainsInconsistentlyNamedFileDifferingInCaseOnly_HasNoProblem() { using (var environment = new TestEnvironment()) { File.WriteAllText(Path.Combine(environment.TestPath, "tpi-latn.ldml"), LdmlContentForTests.CurrentVersion("tpi", "Latn", "", "")); var repository = new LdmlInFolderWritingSystemRepository(environment.TestPath); var problems = repository.LoadProblems; Assert.That(problems.Count, Is.EqualTo(0)); } }
public TestEnvironment() { _tempFolder = new TemporaryFolder("LdmlInFolderWritingSystemRepositoryTests"); NamespaceManager = new XmlNamespaceManager(new NameTable()); NamespaceManager.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1"); if (Directory.Exists(TestPath)) { Directory.Delete(TestPath, true); } _writingSystem = new WritingSystemDefinition(); Collection = LdmlInFolderWritingSystemRepository.Initialize(TestPath, DummyWritingSystemHandler.onMigration, onLoadProblem); }
public void IsUnicodeEncoded_TrueByDefault() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; environment.Collection.SaveDefinition(environment.WritingSystem); var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = newCollection.Get("en"); Assert.IsTrue(ws2.IsUnicodeEncoded); } }
public void LoadAllDefinitions_FilenameIsFlexConformPrivateUseAndDoesNotMatchRfc5646Tag_Migrates() { using (var environment = new TestEnvironment()) { var ldmlPath = Path.Combine(environment.TestPath, "x-en-Zxxx.ldml"); File.WriteAllText(ldmlPath, LdmlContentForTests.Version0("x-en", "Zxxx", "", "")); var repo = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Strict); // Now try to load up. Assert.That(repo.Get("qaa-Zxxx-x-en").Language, Is.EqualTo("qaa")); } }
public void Set_WritingSystemWasLoadedFromFlexPrivateUseLdmlAndRearranged_DoesNotChangeFileName() { using (var environment = new TestEnvironment()) { var pathToFlexprivateUseLdml = Path.Combine(environment.TestPath, "x-en-Zxxx-x-audio.ldml"); File.WriteAllText(pathToFlexprivateUseLdml, LdmlContentForTests.Version0("x-en", "Zxxx", "", "x-audio")); environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem, WritingSystemCompatibility.Flex7V0Compatible); var ws = environment.Collection.Get("x-en-Zxxx-x-audio"); environment.Collection.Set(ws); Assert.That(File.Exists(pathToFlexprivateUseLdml), Is.True); } }
public void CanSaveAndReadKeyboardName() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; environment.WritingSystem.Keyboard = "Thai"; environment.Collection.SaveDefinition(environment.WritingSystem); var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = (ILegacyWritingSystemDefinition)newCollection.Get("en"); Assert.AreEqual("Thai", ws2.Keyboard); } }
public void CanSaveAndReadDefaultFont() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; environment.WritingSystem.DefaultFontName = "Courier"; environment.Collection.SaveDefinition(environment.WritingSystem); var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = newCollection.Get("en"); Assert.AreEqual("Courier", ws2.DefaultFontName); } }
public void StoreIDAfterLoad_SameAsFileNameWithoutExtension() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; Assert.AreNotEqual(0, Directory.GetFiles(environment.TestPath, "*.ldml")); environment.Collection.SaveDefinition(environment.WritingSystem); var newStore = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = newStore.Get("en"); Assert.AreEqual( Path.GetFileNameWithoutExtension(Directory.GetFiles(environment.TestPath, "*.ldml")[0]), ws2.StoreID); } }
public void CanReadVariant() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; environment.WritingSystem.Variant = "x-piglatin"; environment.Collection.SaveDefinition(environment.WritingSystem); var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = newCollection.Get(environment.WritingSystem.StoreID); Assert.AreEqual("x-piglatin", ws2.Variant); } }
/// <summary> Imports main character set for a project from an ldml file </summary> public void LdmlImport(string filePath, string langTag, IProjectRepository projRepo, Project project) { var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath); var wsf = new LdmlInFolderWritingSystemFactory(wsr); wsf.Create(langTag, out var wsDef); // If there is a main character set, import it to the project if (wsDef.CharacterSets.Contains("main")) { project.ValidCharacters = wsDef.CharacterSets["main"].Characters.ToList(); projRepo.Update(project.Id, project); } }
public override IWritingSystemRepository CreateNewStore() { string testPath = Path.GetTempPath() + "PalasoTest" + _testPaths.Count; if (Directory.Exists(testPath)) { Directory.Delete(testPath, true); } _testPaths.Add(testPath); LdmlInFolderWritingSystemRepository repository = LdmlInFolderWritingSystemRepository.Initialize(testPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); //repository.DontAddDefaultDefinitions = true; return(repository); }
public void CanSaveAndReadRightToLeft() { using (var environment = new TestEnvironment()) { environment.WritingSystem.Language = "en"; Assert.IsFalse(environment.WritingSystem.RightToLeftScript); environment.WritingSystem.RightToLeftScript = true; Assert.IsTrue(environment.WritingSystem.RightToLeftScript); environment.Collection.SaveDefinition(environment.WritingSystem); var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); var ws2 = newCollection.Get("en"); Assert.IsTrue(ws2.RightToLeftScript); } }
private static ViewTemplate MakeMasterInventory() { using (var tempFolder = new TemporaryFolder("ProjectFromViewTemplateTests")) { IWritingSystemRepository w = LdmlInFolderWritingSystemRepository.Initialize( tempFolder.Path, OnWritingSystemMigration, OnWritingSystemLoadProblem, WritingSystemCompatibility.Flex7V0Compatible ); w.Set(WritingSystemDefinition.Parse("aaa")); w.Set(WritingSystemDefinition.Parse("aab")); return(ViewTemplate.MakeMasterTemplate(w)); } }
//this used to throw public void LoadAllDefinitions_FilenameDoesNotMatchRfc5646Tag_NoProblem() { using (var environment = new TestEnvironment()) { //Make the filepath inconsistant environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); environment.WritingSystem.Language = "en"; environment.Collection.SaveDefinition(environment.WritingSystem); File.Move(Path.Combine(environment.TestPath, "en.ldml"), Path.Combine(environment.TestPath, "de.ldml")); // Now try to load up. environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem); Assert.That(environment.Collection.Contains("en")); } }
public TestLdmlInFolderWritingSystemFactory(LdmlInFolderWritingSystemRepository writingSystemRepository) : base(writingSystemRepository) { _sldrLdmls = new Dictionary<string, string>(); }