/// <summary> /// Test the character name at the memory address specified. /// Will assert an error if the PUA codepoint name is not correct. /// </summary> /// <param name="puaIndex">Unicode codepoint</param> /// <param name="puaName">Expected correct PUA codepoint name</param> /// <param name="puaGenCat">The expected PUA General Category</param> public static void Check_PUA(int puaIndex, string puaName, LgGeneralCharCategory puaGenCat) { string name = ""; LgGeneralCharCategory genCategory = LgGeneralCharCategory.kccCn; //Getting the character name at the memory address specified ILgCharacterPropertyEngine charPropEngine = LgIcuCharPropEngineClass.Create(); try { string icuDataDir = GetIcuDataDir(); Icu.SetDataDirectory(icuDataDir); Icu.UErrorCode error; Icu.UCharNameChoice choice = Icu.UCharNameChoice.U_UNICODE_CHAR_NAME; int len = Icu.u_CharName(puaIndex, choice, out name, out error); genCategory = charPropEngine.get_GeneralCategory(puaIndex); } finally { // Must release pointer to free memory-mapping before we try to restore files. Marshal.ReleaseComObject(charPropEngine); charPropEngine = null; Icu.Cleanup(); // clean up the ICU files / data } //Check to make sure expected result is the same as actual result, if not, output error Assert.AreEqual(puaName, name, "PUA Character " + puaIndex.ToString("x", new System.Globalization.NumberFormatInfo()) + " is incorrect"); //Check to make sure expected result is the same as actual result, if not, output error Assert.AreEqual(puaGenCat, genCategory, "PUA Character " + puaIndex.ToString("x", new System.Globalization.NumberFormatInfo()) + " has an incorrect digit value"); }
/// <summary> /// Test the character name at the memory address specified. /// Will assert an error if the PUA codepoint name and digit value are not correct. /// </summary> /// <param name="puaIndex">Unicode codepoint</param> /// <param name="digit">Expected correct PUA codepoint name</param> public static void Check_PUA_Digit(int puaIndex, int digit) { string name = ""; int icuDigit = -1; //Getting the character name at the memory address specified try { string icuDataDir = GetIcuDataDir(); Icu.SetDataDirectory(icuDataDir); Icu.UErrorCode error; Icu.UCharNameChoice choice = Icu.UCharNameChoice.U_UNICODE_CHAR_NAME; int len = Icu.u_CharName(puaIndex, choice, out name, out error); // Radix means "base", so this will return the base 10 value of this digit. // (Note, the radix is just used to return an error if the digit isn't valid in the given radix) icuDigit = Icu.u_Digit(puaIndex, 10); } finally { Icu.Cleanup(); // clean up the ICU files / data } //Check to make sure expected result is the same as actual result, if not, output error Assert.AreEqual(digit, icuDigit, "PUA Character " + puaIndex.ToString("x", new System.Globalization.NumberFormatInfo()) + " has an incorrect digit value"); }
private static bool InitializeIcuData() { var icuDir = Icu.DefaultDirectory; ZipInputStream zipIn = null; try { try { var baseDir = DirectoryFinder.FWDataDirectory; zipIn = new ZipInputStream(File.OpenRead(Path.Combine(baseDir, "Icu50.zip"))); } catch (Exception e1) { MessageBoxUtils.Show("Something is wrong with the file you chose." + Environment.NewLine + " The file could not be opened. " + Environment.NewLine + Environment.NewLine + " The error message was: '" + e1.Message); } if (zipIn == null) { return(false); } Icu.Cleanup(); foreach (var dir in Directory.GetDirectories(icuDir)) { var subdir = Path.GetFileName(dir).ToLowerInvariant(); if (subdir == "data" || (subdir.StartsWith("icudt") && subdir.EndsWith("l"))) { Directory.Delete(dir, true); } } ZipEntry entry; while ((entry = zipIn.GetNextEntry()) != null) { var dirName = Path.GetDirectoryName(entry.Name); var match = new Regex(@"^ICU\d\d[\\/]?(.*)$").Match(dirName); if (match.Success) // Zip file was built in a way that includes the root directory name. { dirName = match.Groups[1].Value; // Strip it off. May leave empty string. } var fileName = Path.GetFileName(entry.Name); var fOk = UnzipFile(zipIn, fileName, entry.Size, Path.Combine(icuDir, dirName)); if (!fOk) { return(false); } } return(true); } finally { if (zipIn != null) { zipIn.Dispose(); } } }
/// <summary> /// Tests the results of running InstallLanguage -c pua but doesn't run it /// </summary> /// This is not a test, because it won't work unless you have run "InstallLanguage -c pua" without restoring the original files ///[Test] public void Check_for_PUA_Results() { //Check to see if individual pua characters were loaded properly //TestUtils.Check_PUA(0xF175,"COMBINING GRAVE-ACUTE-GRAVE"); Icu.Cleanup(); Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); TestUtils.Check_PUA(0xE001, "PIG NUMERAL 1", LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xE002, "PIG NUMERAL 2", LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xF00D, "PIG NUMERAL 3", LgGeneralCharCategory.kccNd); // TestUtils.Check_PUA (0xF00E,"PIG NUMERAL 4",LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xF0ED, "PIG NUMERAL 5", LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xF0EE, "PIG NUMERAL 6", LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xF12E, "PIG NUMERAL 7", LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xF12F, "PIG NUMERAL 8", LgGeneralCharCategory.kccNd); TestUtils.Check_PUA(0xF136, "PIGDASH", LgGeneralCharCategory.kccMn); TestUtils.Check_PUA(0xF137, "PIG Curlytail", LgGeneralCharCategory.kccMn); TestUtils.Check_PUA(0xF139, "PIG Jump", LgGeneralCharCategory.kccLl); // TestUtils.Check_PUA (0xF16F,"JIBBERISH SMALL LETTER P WITH TWO STROKES",LgGeneralCharCategory.kccSm); TestUtils.Check_PUA(0xF171, "PIGCHARACTER UGLY", LgGeneralCharCategory.kccLl); TestUtils.Check_PUA_Digit(0xF00D, 3); TestUtils.Check_PUA_Digit(0xF00E, 4); TestUtils.Check_PUA_Digit(0xF12F, -1); //JIBBERISH SMALL LETTER P WITH TWO STROKES;Sm;0;EN; //<compat> 0050;;;;Y;OLD NAME OF JIBBERISH;NO COMMENT;0050;0070;0050 TestUtils.Check_PUA(0xF16F, "JIBBERISH SMALL LETTER P WITH TWO STROKES", LgGeneralCharCategory.kccSm, 0, LgBidiCategory.kbicEN, "P", false, -1, "NO COMMENT", 'P', 'p', 'P'); //PIG NUMERAL 4;Nd;228;EN;<small> 0034;4;4;4;N;PIGGY 4;<none>;;; TestUtils.Check_PUA(0xF00E, "PIG NUMERAL 4", LgGeneralCharCategory.kccMn, 0228, LgBidiCategory.kbicNSM, "4", false, 4, "<none>", 0xF00E, 0xF00E, 0xF00E); // Note: the "puaNumeric" parameter is false, since this doesn't have a type that is numeric. // Perhaps all characters that have a numeric value should have a numeric type //PIG NUMERAL 3;Nd;228;EN;<small> 0033;3;3;3;N;PIGGY 3;<none>;;; TestUtils.Check_PUA(0xF00D, "PIG NUMERAL 3", LgGeneralCharCategory.kccNd, 0228, LgBidiCategory.kbicEN, "3", true, 3, "<none>", 0xF00D, 0xF00D, 0xF00D); // Note: the "puaNumeric" parameter is false, since this doesn't have a type that is numeric. // Perhaps all characters that have a numeric value should have a numeric type // puaOutOfRange.xml - uses non PUA characters // TestUtils.Check_PUA(0xE000, "PIG NUMERAL 7"); // TestUtils.Check_PUA(0xE001, "PIG NUMERAL 8"); // TestUtils.Check_PUA(0xDC01, "PIG NUMERAL 1"); // TestUtils.Check_PUA(0xDC02, "PIG NUMERAL 2"); // TestUtils.Check_PUA(0xDEEE, "PIG NUMERAL 3"); // TestUtils.Check_PUA(0xDFFE, "PIG NUMERAL 5"); // TestUtils.Check_PUA(0xDEEF, "PIG NUMERAL 4"); // TestUtils.Check_PUA(0xDFFF, "PIG NUMERAL 6"); // // TestUtils.Check_PUA(0xF136, "PIGDASH"); // TestUtils.Check_PUA(0xF137, "PIG Curlytail"); // TestUtils.Check_PUA(0xF139, "PIG Jump"); // TestUtils.Check_PUA(0xF171, "PIGCHARACTER UGLY"); // TestUtils.Check_PUA(0xF16F, "JIBBERISH SMALL LETTER P WITH TWO STROKES"); }
private static bool InitializeIcuData() { var icuDir = Icu.DefaultDirectory; ZipInputStream zipIn = null; try { try { var baseDir = FwDirectoryFinder.DataDirectory; zipIn = new ZipInputStream(File.OpenRead(Path.Combine(baseDir, string.Format("Icu{0}.zip", Icu.Version)))); } catch (Exception e1) { MessageBoxUtils.Show("Something is wrong with the file you chose." + Environment.NewLine + " The file could not be opened. " + Environment.NewLine + Environment.NewLine + " The error message was: '" + e1.Message); } if (zipIn == null) { return(false); } Icu.Cleanup(); foreach (string dir in Directory.GetDirectories(icuDir)) { string subdir = Path.GetFileName(dir); if (subdir.Equals(string.Format("icudt{0}l", Icu.Version), StringComparison.OrdinalIgnoreCase)) { Directory.Delete(dir, true); } } ZipEntry entry; while ((entry = zipIn.GetNextEntry()) != null) { string dirName = Path.GetDirectoryName(entry.Name); Match match = Regex.Match(dirName, @"^ICU\d\d[\\/]?(.*)$", RegexOptions.IgnoreCase); if (match.Success) // Zip file was built in a way that includes the root directory name. { dirName = match.Groups[1].Value; // Strip it off. May leave empty string. } string fileName = Path.GetFileName(entry.Name); bool fOk = UnzipFile(zipIn, fileName, entry.Size, Path.Combine(icuDir, dirName)); if (!fOk) { return(false); } } return(true); } finally { if (zipIn != null) { zipIn.Dispose(); } } }
/// <summary> /// Check that ICU was correctly restored for xxx1_Wwww_YY2_ZZZ3 /// </summary> public static void Checkxxx1_Wwww_YY2_ZZZ3Restored() { Icu.UErrorCode error; string result; Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); Icu.GetDisplayName("xxx1_Wwww_YY2_ZZZ3", "en", out result, out error); Icu.Cleanup(); // clean up the ICU files / data Assert.AreEqual("xxx1 (Wwww, YY2, ZZZ3)", result, "Data 'xxx1_Wwww_YY2_ZZZ3' not removed from the ICU Files"); }
/// <summary> /// Check that ICU was correctly restored for xxx1_Wwww_YY2_ZZZ3 /// </summary> private void Checkel_Mysc_UNH_IPARestored() { Icu.UErrorCode error; string result; Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); Icu.GetDisplayName("el_Mysc_UNH_IPA", "en", out result, out error); Icu.Cleanup(); // clean up the ICU files / data // Note "Greek" and "IPA" are already added as "factory" locales. Assert.AreEqual("Greek (Mysc, UNH, IPA)", result, "Data 'el_Mysc_UNH_IPA' not removed from the ICU Files"); }
/// <summary> /// Cleans up all the shared stuff. /// 1. Icu.Cleanup() /// 2. Restores all the files to their original values /// </summary> /// <param name="saveFiles">The files to overwrite with their backups</param> /// <param name="backupFiles">The files to copy from</param> /// <param name="tempFiles">The files to delete, may be null, in which case they will not be deleted.</param> public static void CleanUpAndRestore(ArrayList saveFiles, ArrayList backupFiles, System.CodeDom.Compiler.TempFileCollection tempFiles) { Icu.Cleanup(); // clean up the ICU files / data // Now restore all the original files (pre-test files) for (int i = 0; i < saveFiles.Count; i++) { File.Copy((string)(backupFiles[i]), (string)(saveFiles[i]), true); } if (tempFiles != null) { // removes all the temporary files tempFiles.Delete(); } }
public void TestInstallLanguage_PigAndPUA() { // First backup the 'important' icu files and unidata files ArrayList saveFiles = new ArrayList(); LDInstallSaveFiles(saveFiles); PUAInstallSaveFiles(saveFiles); System.CodeDom.Compiler.TempFileCollection tempFiles; ArrayList backupFiles; TestUtils.MakeTempFiles(saveFiles, out backupFiles, out tempFiles); LDPigTempFiles(tempFiles); string puaTestFile = MoveLDF("puapig.xml"); // remove file when done with test tempFiles.AddFile(puaTestFile, false); try { TestUtils.RunProgram("InstallLanguage.exe", "-i -c " + puaTestFile + " -q", 0); CheckLDPigResults(); Check_for_PUA_Results(); Icu.Cleanup(); // clean up the ICU files / data TestUtils.RunProgram("InstallLanguage.exe", "-r puapig -q", 0); } finally { TestUtils.CleanUpAndRestore(saveFiles, backupFiles, tempFiles); } // Now make sure the Language was uninstalled / icu restored properly Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); string result2; SIL.FieldWorks.Common.FwUtils.Icu.UErrorCode error; Icu.GetDisplayName("pig", "en", out result2, out error); Icu.Cleanup(); Assert.AreEqual("pig", result2, "Data 'pig' not removed from the ICU Files"); //Make sure the unicodeData file was restored properly TestUtils.Check_PUA(0xF171, "COMBINING MACRON-ACUTE", LgGeneralCharCategory.kccMn); }
public void TestInstallLanguage_el_Mysc_UNH_IPA() { // First backup the 'important' icu files ArrayList saveFiles = new ArrayList(); LDInstallSaveFiles(saveFiles); // make sure no resedue from last time string elTxtFile = TestUtils.GetIcuDir() + "data\\locales\\el_Mysc_UNH_IPA.txt"; TestUtils.DeleteFile(elTxtFile); System.CodeDom.Compiler.TempFileCollection tempFiles; ArrayList backupFiles; TestUtils.MakeTempFiles(saveFiles, out backupFiles, out tempFiles); // Add files that need to be removed when we are done. tempFiles.AddFile(elTxtFile, false); tempFiles.AddFile(TestUtils.GetIcuDataDir() + "el_Mysc_UNH_IPA.res", false); // Process myProcess = new Process(); // string rootPath = TestUtils.GetFWRootDir(); string elFile = MoveLDF("el_Mysc_UNH_IPA.xml"); tempFiles.AddFile(elFile, false); // remove file when done with test try { TestUtils.RunProgram("InstallLanguage.exe", "-i " + elFile + " -q", 0); // Now use the ICU methods to see if the language was installed Checkel_Mysc_UNH_IPAResults(); } finally { Icu.Cleanup(); TestUtils.RunProgram("InstallLanguage.exe", "-r el_Mysc_UNH_IPA -q", 0); TestUtils.CleanUpAndRestore(saveFiles, backupFiles, tempFiles); } // Now make sure the Language was uninstalled / icu restored properly Checkel_Mysc_UNH_IPARestored(); }
public void TestInstallLanguage_pig() { ArrayList saveFiles = new ArrayList(); ArrayList backupFiles; System.CodeDom.Compiler.TempFileCollection tempFiles; // Decide what files we want to save (LD pig related) LDInstallSaveFiles(saveFiles); // Save the backup TestUtils.MakeTempFiles(saveFiles, out backupFiles, out tempFiles); // Adds files to "tempFiles" that need to be removed when we are done LDPigTempFiles(tempFiles); string pigFile = MoveLDF("pig.xml"); // remove file when done with test tempFiles.AddFile(pigFile, false); Icu.UErrorCode error; try { TestUtils.RunProgram("InstallLanguage.exe", "-i " + pigFile + " -q", 0); CheckLDPigResults(); Icu.Cleanup(); TestUtils.RunProgram("InstallLanguage.exe", "-r pig -q", 0); } finally { TestUtils.CleanUpAndRestore(saveFiles, backupFiles, tempFiles); } // Now make sure the Language was uninstalled / icu restored properly Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); string result2; Icu.GetDisplayName("pig", "en", out result2, out error); Icu.Cleanup(); Assert.AreEqual("pig", result2, "Data 'pig' not removed from the ICU Files"); }
public void TestInstallLanguage_xxx1_Wwww_YY2_ZZZ3() { // First backup the 'important' icu files ArrayList saveFiles = new ArrayList(); LDInstallSaveFiles(saveFiles); // make sure no residue from last time string xxTxtFile = TestUtils.GetIcuDir() + "data\\locales\\xxx1_Wwww_YY2_ZZZ3.txt"; TestUtils.DeleteFile(xxTxtFile); System.CodeDom.Compiler.TempFileCollection tempFiles; ArrayList backupFiles; TestUtils.MakeTempFiles(saveFiles, out backupFiles, out tempFiles); string xxxFile = MoveLDF("xxx1_Wwww_YY2_ZZZ3.xml"); tempFiles.AddFile(xxxFile, false); // remove file when done with test try { TestUtils.RunProgram("InstallLanguage.exe", "-i " + xxxFile + " -q", 0); // Now use the ICU methods to see if the language was installed Checkxxx1_Wwww_YY2_ZZZ3Results(); } finally { Icu.Cleanup(); TestUtils.RunProgram("InstallLanguage.exe", "-r xxx1_Wwww_YY2_ZZZ3 -q", 0); TestUtils.CleanUpAndRestore(saveFiles, backupFiles, tempFiles); } // Now make sure the Language was uninstalled / icu restored properly Checkxxx1_Wwww_YY2_ZZZ3Restored(); }
public void TestAdd_and_Remove_pig() { string icuDataDir; string icuDir; string icuPrefix; GetIcuLocationInfo(out icuDataDir, out icuDir, out icuPrefix); try { CreateBackupFiles(); InstallLocal("pig"); string result; Icu.UErrorCode error; Icu.SetDataDirectory(icuDataDir); Icu.GetDisplayName("frm__snz", "en", out result, out error); Icu.GetDisplayName("pig", "en", out result, out error); Icu.Cleanup(); // clean up the ICU files / data Assert.AreEqual("Piggy", result, "Data 'pig' not put into the ICUFiles"); RemoveLocal("pig"); Icu.SetDataDirectory(icuDataDir); Icu.GetDisplayName("pig", "en", out result, out error); Icu.Cleanup(); // clean up the ICU files / data Assert.AreEqual("pig", result, "Data 'pig' not removed from the ICUFiles"); } finally { Icu.Cleanup(); // clean up the ICU files / data RemoveLocal("pig"); RestoreBackupFiles(); TestUtils.DeleteFile(icuDir + icuPrefix + "pig.res"); } }
/// <summary> /// Checks all the values of a character in the UnicodeData.txt. /// Checks: fields 1-8,11-14 /// (Skips, 9 and 10, the "Bidi Mirrored" and "Unicode Version 1" /// </summary> /// <param name="puaIndex"></param><param name="puaName"></param> /// <param name="puaGenCat"></param><param name="puaCombiningClass"></param> /// <param name="puaBidiClass"></param><param name="puaDecomposition"></param> /// <param name="puaNumeric"></param><param name="puaNumericValue"></param> /// <param name="puaComment"></param><param name="puaToUpper"></param> /// <param name="puaToLower"></param><param name="puaToTitle"></param> public static void Check_PUA( int puaIndex, string puaName, LgGeneralCharCategory puaGenCat, int puaCombiningClass, LgBidiCategory puaBidiClass, string puaDecomposition, bool puaNumeric, int puaNumericValue, string puaComment, int puaToUpper, int puaToLower, int puaToTitle ) { string name = ""; LgGeneralCharCategory genCategory = LgGeneralCharCategory.kccCn; int combiningClass = 0; string decomposition = "None"; LgBidiCategory bidiCategory = LgBidiCategory.kbicL; string fullDecomp = "I have no clue"; bool isNumber = false; int numericValue = -1; int upper = -1; int lower = -1; int title = -1; string comment = "<none>"; //Getting the character name at the memory address specified ILgCharacterPropertyEngine charPropEngine = LgIcuCharPropEngineClass.Create(); try { string icuDataDir = GetIcuDataDir(); Icu.SetDataDirectory(icuDataDir); Icu.UErrorCode error; Icu.UCharNameChoice choice = Icu.UCharNameChoice.U_UNICODE_CHAR_NAME; int len = Icu.u_CharName(puaIndex, choice, out name, out error); genCategory = charPropEngine.get_GeneralCategory(puaIndex); combiningClass = charPropEngine.get_CombiningClass(puaIndex); bidiCategory = charPropEngine.get_BidiCategory(puaIndex); decomposition = charPropEngine.get_Decomposition(puaIndex); fullDecomp = charPropEngine.get_FullDecomp(puaIndex); // Note: isNumber merely checks the General category, it doesn't check to see if there is a valid numeric value. isNumber = charPropEngine.get_IsNumber(puaIndex); if (isNumber) { numericValue = charPropEngine.get_NumericValue(puaIndex); } comment = charPropEngine.get_Comment(puaIndex); upper = charPropEngine.get_ToUpperCh(puaIndex); lower = charPropEngine.get_ToLowerCh(puaIndex); title = charPropEngine.get_ToTitleCh(puaIndex); } finally { // Must release pointer to free memory-mapping before we try to restore files. Marshal.ReleaseComObject(charPropEngine); charPropEngine = null; Icu.Cleanup(); // clean up the ICU files / data } // StringWriter used to print hexadecimal values in the error messages. StringWriter stringWriter = new StringWriter(new System.Globalization.NumberFormatInfo()); string errorMessage = "PUA Character " + puaIndex.ToString("x", new System.Globalization.NumberFormatInfo()) + " has an incorrect "; //Check Name [1] Assert.AreEqual(puaName, name, errorMessage + "name."); //Check general category [2] Assert.AreEqual(puaGenCat, genCategory, errorMessage + "general category."); //Check combining class [3] Assert.AreEqual(puaCombiningClass, combiningClass, errorMessage + "combining class."); //Check Bidi class [4] Assert.AreEqual(puaBidiClass, bidiCategory, errorMessage + "bidi class value."); //Check Decomposition [5] stringWriter.WriteLine(errorMessage + "decomposition."); stringWriter.WriteLine("Decomposition, {0:x}, is incorrect", (int)decomposition[0]); Assert.AreEqual(puaDecomposition, decomposition, stringWriter.ToString()); //Check Numeric Value [6,7,8] if (puaNumeric != isNumber) { Assert.AreEqual(puaNumeric, isNumber, errorMessage + "numeric type (i.e. does or doesn't have a numeric value when it should be the other)."); } if (puaNumeric) { Assert.AreEqual(puaNumericValue, numericValue, errorMessage + "numeric value."); } //Check ISO Comment [11] Assert.AreEqual(puaComment, comment, errorMessage + "ISO commment"); //Check uppercase [12] stringWriter.Flush(); stringWriter.WriteLine(errorMessage + "upper case."); stringWriter.WriteLine("Found uppercase value: {0:x}", upper); Assert.AreEqual(puaToUpper, upper, stringWriter.ToString()); //Check lowercase [13] Assert.AreEqual(puaToLower, lower, errorMessage + "lower case."); //Check titlecase [14] Assert.AreEqual(puaToTitle, title, errorMessage + "title case."); }