public void PropsDifferByIntProps() { // test of different int prop: writing system ITsPropsBldr tsPropsBldr = TsStringUtils.MakePropsBldr(); 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 = TsStringUtils.MakePropsBldr(); // 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 PropsDifferByStrProps() { // test of different str prop: named style ITsPropsBldr tsPropsBldr = TsStringUtils.MakePropsBldr(); 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 = TsStringUtils.MakePropsBldr(); // 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 PropsDifferByCount() { // test of different string property counts ITsPropsBldr tsPropsBldr = TsStringUtils.MakePropsBldr(); //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 = TsStringUtils.MakePropsBldr(); // 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 FromITsTextProps_IntAndStringProps_Copies() { var tpf = new TsPropsFactory(); var original = tpf.MakeProps("someStyle", 43, 57) as ITsTextProps; var copy = tpf.FromITsTextProps(original); string diff; Assert.That(TsTextPropsHelper.PropsAreEqual(original, copy, out diff)); }
public void PropsAreEqual() { // test of same int prop: writing system ITsPropsBldr tsPropsBldr = TsStringUtils.MakePropsBldr(); 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 = TsStringUtils.MakeProps(expectedCharStyle, expectedWs); 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); }