/// <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"); }
/// <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> /// Check that xxx1_Wwww_YY2_ZZZ3 installed correctly /// </summary> private void Checkel_Mysc_UNH_IPAResults() { Icu.UErrorCode error; string result; Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); Icu.GetDisplayName("el_Mysc_UNH_IPA", "en", out result, out error); Assert.AreEqual("Greek (MyScript, UnheardOf, IPA)", result, "Data not put into the ICUFiles"); Icu.GetDisplayLanguage("el_Mysc_UNH_IPA", "en", out result, out error); Assert.AreEqual("Greek", result, "Greek should not be changed as it is a factory value."); Icu.GetDisplayScript("el_Mysc_UNH_IPA", "en", out result, out error); Assert.AreEqual("MyScript", result, "The display script should be changed."); Icu.GetDisplayCountry("el_Mysc_UNH_IPA", "en", out result, out error); Assert.AreEqual("UnheardOf", result, "The display country should be changed."); Icu.GetDisplayVariant("el_Mysc_UNH_IPA", "en", out result, out error); Assert.AreEqual("IPA", result, "The display variant should not be changed."); StreamReader reader; TestUtils.RunProgram("InstallLanguage", "-q -customLanguages", 0, out reader); string output = reader.ReadToEnd(); Assert.IsTrue(output.IndexOf("<el>") == -1, "Should not have installed factory locale 'el' as a custom language." + "Installed Custom Languages: " + output.ToString()); }
/// <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"); }
/// <summary> /// Check that xxx1_Wwww_YY2_ZZZ3 installed correctly /// </summary> private void Checkxxx1_Wwww_YY2_ZZZ3Results() { Icu.UErrorCode error; string result; Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); Icu.GetDisplayName("xxx1_Wwww_YY2_ZZZ3", "en", out result, out error); Assert.AreEqual("XXXLanguage1 (WWScript2, YYCountry2, ZZZVariant3)", result, "Data not put into the ICUFiles"); }
/// <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> /// Checks to make sure that "InstallLanguage pig" did what is was supposed to. /// Use the ICU methods to see if the minimal 'pig' language was installed. /// </summary> public void CheckLDPigResults() { // Now use the ICU methods to see if the minimal 'pig' language was installed Icu.SetDataDirectory(TestUtils.GetIcuDataDir()); string result; SIL.FieldWorks.Common.FwUtils.Icu.UErrorCode error; Icu.GetDisplayName("pig", "en", out result, out error); Assert.AreEqual("Piggy", result, "Data 'pig' not put into the ICUFiles"); }
/// <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"); }
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_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 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."); }