public void TestGetStyleRgch() { IVwStylesheet stylesheet = (IVwStylesheet) new TestFwStylesheet(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times"); ITsTextProps props1 = propsBldr.GetTextProps(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, 256); ITsTextProps props2 = propsBldr.GetTextProps(); int hvoNewStyle1 = stylesheet.MakeNewStyle(); stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, hvoNewStyle1, 0, false, false, props1); int hvoNewStyle2 = stylesheet.MakeNewStyle(); stylesheet.PutStyle("SecondStyle", "bla", hvoNewStyle2, 0, hvoNewStyle1, 0, false, false, props2); string sHowDifferent; bool fEqual = TsTextPropsHelper.PropsAreEqual(props2, stylesheet.GetStyleRgch(0, "SecondStyle"), out sHowDifferent); Assert.IsTrue(fEqual, sHowDifferent); fEqual = TsTextPropsHelper.PropsAreEqual(props1, stylesheet.GetStyleRgch(0, "FirstStyle"), out sHowDifferent); Assert.IsTrue(fEqual, sHowDifferent); }
public void PropsDifferByIntProps() { // test of different int prop: writing system ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565754); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565753); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in ktptWs property. Expected ws <4565754> and var <0>, but was ws <4565753> and var <0>.", s); // test of different int prop: background color tsPropsBldr = TsPropsBldrClass.Create(); // empty builder tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); //string prop, same for both tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, 98); ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, 99); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in intProp type 9. " + "Expected <98,0>, but was <99,0>.", s); }
public void PropsDifferByCount() { // test of different string property counts ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); //note: due to design in PropsAreEqual(), we will get the count message // only when all the str props in the first ttp match in the second ttp, and the // second ttp has additional str props tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "my font"); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in count of strProps. Expected <1>, but was <2>.", s); // test of different int property counts tsPropsBldr = TsPropsBldrClass.Create(); // empty builder tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, 123); ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvDefault, 10); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in count of intProps. Expected <1>, but was <2>.", s); }
public void PropsDifferByStrProps() { // test of different str prop: named style ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "your style"); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in ktptNamedStyle property. " + "Expected <my style>, but was <your style>.", s); // test of different str prop: named style tsPropsBldr = TsPropsBldrClass.Create(); // empty builder tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565754); // int prop, same for both tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "my font"); ttp1 = tsPropsBldr.GetTextProps(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "your font"); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsFalse(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("Props differ in strProp type 1. " + "Expected <my font>, but was <your font>.", s); }
public void PropsAreEqual() { // test of same int prop: writing system ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, 4565754); ITsTextProps ttp1 = tsPropsBldr.GetTextProps(); ITsTextProps ttp2 = tsPropsBldr.GetTextProps(); string s; Assert.IsTrue(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); // test of same int & string props tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "my style"); //add string prop to prior int prop ttp1 = tsPropsBldr.GetTextProps(); ttp2 = tsPropsBldr.GetTextProps(); Assert.IsTrue(TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out s)); Assert.AreEqual("TextProps objects appear to contain the same properties.", s); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies that the given run of the given ITsString contains the specified text and /// properties. /// </summary> /// <param name="tss">The ITsString to test</param> /// <param name="iRun">Zero-based run index to check</param> /// <param name="expectedText">Expected contents of run</param> /// <param name="expectedCharStyle">Expected character style name, or null if expecting /// default paragraph character props</param> /// <param name="expectedWs">Expected writing system for the run</param> /// <param name="fExpectNFD">Pass <c>true</c> to make sure that TSS is in normal /// form decomposed (which it probably should be if it has been saved to the DB); pass /// <c>false</c> if the string is not expected to be decomposed.</param> /// ------------------------------------------------------------------------------------ public static void RunIsCorrect(ITsString tss, int iRun, string expectedText, string expectedCharStyle, int expectedWs, bool fExpectNFD) { Assert.AreEqual(fExpectNFD, tss.get_IsNormalizedForm(FwNormalizationMode.knmNFD)); // If both strings are null then they're equal and there's nothing else to compare. if (expectedText == null) { Assert.IsNull(tss.Text); return; } // If both strings are 0-length, then they're equal; otherwise compare them. if (expectedText.Length == 0) { Assert.AreEqual(0, tss.Length); } else { // compare strings // apparently IndexOf performs Unicode normalization. if (expectedText.IndexOf(tss.get_RunText(iRun), StringComparison.Ordinal) != 0) { Assert.Fail("Run " + iRun + " text differs. Expected <" + expectedText + "> but was <" + tss.get_RunText(iRun) + ">"); } } ITsTextProps ttp1 = TsPropsFactoryClass.Create().MakeProps(expectedCharStyle, expectedWs, 0); ITsTextProps ttp2 = tss.get_Properties(iRun); string sWhy; if (!TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out sWhy)) { Assert.Fail(sWhy); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares two TsStrings /// </summary> /// <param name="tssExpected">expected</param> /// <param name="tssActual">actual</param> /// <param name="propsWithWiggleRoom">dictionary of format properties that needn't be exact, along with their acceptable errors</param> /// <param name="sHowDifferent">Human(geek)-readable string telling how the TsStrings are different, or null if they are the same</param> /// <returns>True if TsStrings match, false otherwise</returns> /// ------------------------------------------------------------------------------------ public static bool TsStringsAreEqual(ITsString tssExpected, ITsString tssActual, IDictionary <int, int> propsWithWiggleRoom, out string sHowDifferent) { sHowDifferent = null; // Deal with cases where one or both of the passed values is null if (tssExpected == null) { if (tssActual != null) { sHowDifferent = string.Format("TsStrings differ.{0}\tExpected <null>, but was <{1}>.", Environment.NewLine, tssActual.Text); return(false); } return(true); } if (tssActual == null) { sHowDifferent = string.Format("TsStrings differ.{0}\tExpected <{1}>, but was <null>.", Environment.NewLine, tssExpected.Text); return(false); } // If the lengths differ then the TS Strings are different if (tssExpected.Length != tssActual.Length) { sHowDifferent = string.Format("TsString lengths differ.{0}\tExpected <{1}>, but was <{2}>.", Environment.NewLine, tssExpected.Text, tssActual.Text); return(false); } if (tssExpected.Text != tssActual.Text) { sHowDifferent = string.Format("TsString text differs.{0}\tExpected <{1}>, but was <{2}>.", Environment.NewLine, tssExpected.Text, tssActual.Text); return(false); } var bldr = new StringBuilder(); int cRuns1 = tssExpected.RunCount; int cRuns2 = tssActual.RunCount; if (cRuns1 != cRuns2) { bldr.AppendFormat("TsStrings have different number of runs.{0}\tExpected {1} runs, but was {2} runs.", Environment.NewLine, cRuns1, cRuns2); for (int iRun = 0; iRun < cRuns1 || iRun < cRuns2; iRun++) { bldr.AppendFormat("{0}\tExpected run {1}:<", Environment.NewLine, iRun + 1); if (iRun < cRuns1) { bldr.Append(tssExpected.get_RunText(iRun)); } bldr.Append(">, but was:<"); if (iRun < cRuns2) { bldr.Append(tssActual.get_RunText(iRun)); } bldr.Append(">"); } sHowDifferent = bldr.ToString(); return(false); } for (int iRun = 0; iRun < cRuns1; iRun++) { string sRun1 = tssExpected.get_RunText(iRun); string sRun2 = tssActual.get_RunText(iRun); if (sRun1 != null && sRun1.Length != sRun2.Length) { sHowDifferent = string.Format("TsStrings differ in length of run {1}.{0}" + "\tExpected length={2}, but was length={3}.{0}" + "\texpected run:<{4}>{0}" + "\t but was:<{5}>", Environment.NewLine, iRun + 1, sRun1.Length, sRun2.Length, sRun1, sRun2); return(false); } string sDetails; if (!TsTextPropsHelper.PropsAreEqual(tssExpected.get_Properties(iRun), tssActual.get_Properties(iRun), propsWithWiggleRoom, out sDetails)) { sHowDifferent = string.Format("TsStrings differ in format of run {1}.{0}\t{2}", Environment.NewLine, iRun + 1, sDetails); return(false); } } // if we reach this point, no differences were found return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares two TsStrings /// </summary> /// <param name="tssExpected">expected</param> /// <param name="tssActual">actual</param> /// <param name="sHowDifferent">Human(geek)-readable string telling how the TsStrings /// are different, or null if they are the same</param> /// <returns>True if TsStrings match, false otherwise</returns> /// ------------------------------------------------------------------------------------ public static bool TsStringsAreEqual(ITsString tssExpected, ITsString tssActual, out string sHowDifferent) { sHowDifferent = null; // Deal with cases where one or both of the passed values is null if (tssExpected == null) { if (tssActual != null) { sHowDifferent = "TsStrings differ.\n\tExpected <null>, but was <" + tssActual.Text + ">."; return(false); } else { return(true); } } if (tssExpected != null && tssActual == null) { sHowDifferent = "TsStrings differ.\n\tExpected <" + tssExpected.Text + ">, but was <null>."; return(false); } // If the lengths differ then the TS Strings are different if (tssExpected.Length != tssActual.Length) { sHowDifferent = "TsString lengths differ.\n\tExpected <" + tssExpected.Text + ">, but was <" + tssActual.Text + ">."; return(false); } if (tssExpected.Text != tssActual.Text) { sHowDifferent = "TsString text differs.\n\tExpected <" + tssExpected.Text + ">, but was <" + tssActual.Text + ">."; return(false); } int cRuns1 = tssExpected.RunCount; int cRuns2 = tssActual.RunCount; if (cRuns1 != cRuns2) { sHowDifferent = "TsStrings have different number of runs.\n\tExpected " + cRuns1 + " runs, but was " + cRuns2 + " runs."; for (int iRun = 0; iRun < cRuns1 || iRun < cRuns2; iRun++) { sHowDifferent += "\n\tExpected run " + (iRun + 1) + ":<"; if (iRun < cRuns1) { sHowDifferent += tssExpected.get_RunText(iRun); } sHowDifferent += ">, but was:<"; if (iRun < cRuns2) { sHowDifferent += tssActual.get_RunText(iRun); } sHowDifferent += ">"; } return(false); } for (int iRun = 0; iRun < cRuns1; iRun++) { string sRun1 = tssExpected.get_RunText(iRun); string sRun2 = tssActual.get_RunText(iRun); if (sRun1 != null && sRun1.Length != sRun2.Length) { sHowDifferent = "TsStrings differ in length of run " + (iRun + 1) + ".\n\tExpected length=" + sRun1.Length + ", but was length=" + sRun2.Length + ".\n\texpected run:<" + sRun1 + ">\n\t" + "but was:<" + sRun2 + ">"; return(false); } string sDetails; if (!TsTextPropsHelper.PropsAreEqual(tssExpected.get_Properties(iRun), tssActual.get_Properties(iRun), out sDetails)) { sHowDifferent = "TsStrings differ in format of run " + (iRun + 1) + ".\n\t" + sDetails; return(false); } } // if we reach this point, no differences were found return(true); }