public virtual void testContainsElement() { XMLDoc d = new XMLDoc("doc", null); KElement e = d.getRoot(); KElement e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); VElement v = new VElement(); v.appendUnique(e1); e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); Assert.IsTrue(v.containsElement(e1), "containsElement"); Assert.IsFalse(v.Contains(e1), "contains"); e1.setText("foo"); Assert.IsFalse(v.containsElement(e1), "containsElement"); v.appendUnique(e1); Assert.AreEqual(2, v.Count, "size"); e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); e1.setText("foo"); Assert.IsTrue(v.containsElement(e1), "containsElement"); e1.setText("bar"); Assert.IsFalse(v.containsElement(e1), "containsElement"); }
/// /// <summary> * UpdateBusiness /// * </summary> /// * <param name="businessObject"> </param> /// * <param name="newID"> /// * @return </param> /// public virtual bool updateBusiness(EnumBusinessObject businessObject, string newID) { KElement bo = getElement(ElementName.BUSINESSINFO, JDFConstants.EMPTYSTRING, 0); ArrayList vBos = EnumBusinessObject.getNamesVector(); KElement boe = bo.getChildFromList(new VString(vBos), 0, null, true); string bos = boe.Name; int oldType = vBos.IndexOf(bos); Console.WriteLine("JDFNodeInfo:: " + businessObject.getValue() + " Boe:: " + boe); //C# renameElement only returns the renamed element. boe = boe.renameElement((string)vBos[businessObject.getValue()], JDFConstants.EMPTYSTRING); if (businessObject.getValue() > oldType) { boe.setAttribute(JDFConstants.BUSINESSREFID, boe.getAttribute(JDFConstants.BUSINESSID, JDFConstants.EMPTYSTRING, JDFConstants.EMPTYSTRING), JDFConstants.EMPTYSTRING); if (newID.Length != 0) { boe.setAttribute(JDFConstants.BUSINESSID, newID, JDFConstants.EMPTYSTRING); } } return(true); }
public virtual void warning(Exception exception) { string warn = exception.Message; KElement kEl = root.appendElement("Warning"); kEl.setAttribute("Message", warn); }
public virtual void testIsEqual() { XMLDoc d = new XMLDoc("doc", null); KElement e = d.getRoot(); KElement e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); KElement e2 = e.appendElement("e1"); e2.setAttribute("a", "c"); KElement e3 = e.appendElement("e1"); e3.setAttribute("a", "c"); KElement e4 = e.appendElement("e1"); e4.setAttribute("a", "d"); VElement v = new VElement(); v.Add(e1); v.Add(e2); VElement v2 = new VElement(v); Assert.IsTrue(v.isEqual(v2)); v2[1] = e3; Assert.IsTrue(v.isEqual(v2)); v2[1] = e4; Assert.IsFalse(v.isEqual(v2)); }
public virtual void testCreateBig() { for (int ii = 0; ii < 4; ii++) { XMLDoc d = ii % 2 == 0 ? new XMLDoc("foo", null) : new JDFDoc("JDF"); KElement e = d.getRoot(); long l = DateTime.Now.Ticks; for (int j = 0; j < 2000; j++) { KElement e2 = e.appendElement("AuditPool"); KElement e3 = e2.appendElement("Created"); for (int i = 33; i < 199; i++) { if (i < 2) { e3.setAttribute("k" + Convert.ToString(i), "value" + Convert.ToString(i)); } else { e3.setAttributeRaw("k" + Convert.ToString(i), "value" + Convert.ToString(i)); } } } long l2 = DateTime.Now.Ticks; Console.WriteLine("xmldoc create: " + ii + " " + (l2 - l) / 1000000); string fil = sm_dirTestDataTemp + "big" + ii + "writ.jdf"; d.write2File(fil, 2, false); FileInfo f = new FileInfo(fil); long l3 = DateTime.Now.Ticks; Console.WriteLine("xmldoc write: " + ii + " " + (l3 - l2) / 1000000 + " " + f.Length); Console.WriteLine("xmldoc total: " + ii + " " + (l3 - l) / 1000000 + "\n"); } }
public virtual void testIsDirty() { XMLDoc doc = new XMLDoc("test", null); KElement e = doc.getRoot(); Assert.IsFalse(e.isDirty()); Assert.IsFalse(doc.isDirty(null)); doc.getCreateXMLDocUserData().setDirtyPolicy(EnumDirtyPolicy.Doc); Assert.IsFalse(e.isDirty()); Assert.IsFalse(doc.isDirty(null)); e.setAttribute("foo", "bar"); Assert.IsTrue(e.isDirty()); Assert.IsTrue(doc.isDirty(null)); doc.clearDirtyIDs(); Assert.IsFalse(doc.isDirty(null)); Assert.IsFalse(e.isDirty()); KElement e2 = e.appendElement("foobar"); Assert.IsTrue(e.isDirty()); Assert.IsTrue(doc.isDirty(null)); Assert.IsTrue(e2.isDirty()); doc.getCreateXMLDocUserData().setDirtyPolicy(EnumDirtyPolicy.XPath); doc.clearDirtyIDs(); Assert.IsFalse(doc.isDirty(null)); Assert.IsFalse(e.isDirty()); e2 = e.appendElement("foobar"); Assert.IsTrue(doc.isDirty(null)); Assert.IsTrue(e.isDirty()); Assert.IsTrue(e2.isDirty()); }
/// /// * <param name="exception"> SAXParseException </param> /// * <exception cref="JDFException"> - if fatal error occurs </exception> /// public virtual void fatalError(Exception exception) { string er = exception.Message; KElement kEl = root.appendElement("FatalError"); kEl.setAttribute("Message", er); throw new JDFException("Fatal error in the Parser:" + er); }
public virtual void testUnify() { XMLDoc d = new XMLDoc("doc", null); KElement e = d.getRoot(); KElement e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); VElement v = new VElement(); v.Add(e1); v.Add(e1); e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); v.Add(e1); Assert.AreEqual(3, v.Count); v.unify(); Assert.AreEqual(2, v.Count); v.unifyElement(); Assert.AreEqual(1, v.Count); }
public virtual void testCreateElement() { XMLDoc d = new XMLDoc("TEST", null); KElement e = (KElement)d.createElement("foo:bar"); // e.appendElement("bar:foo"); e.setAttribute("foo:at", "1"); e.appendElement("bar2"); d.getRoot().appendChild(e); Assert.AreEqual("1", e.getAttribute("foo:at")); }
public virtual void error(Exception exception) { // print out all parser errors except undefined variables for non-JDF // stuff string er = exception.Message; if ((er.IndexOf("http://www.CIP4.org/JDFSchema") != -1) || (er.IndexOf("is not declared for") == -1)) { KElement kEl = root.appendElement("Error"); kEl.setAttribute("Message", er); } }
public virtual void testEscapeStrings() { XMLDoc d = new XMLDoc("foo", "www.foo.com"); KElement e = d.getRoot(); e.setAttribute("bar", "><&'\""); string s = d.write2String(0); Assert.IsTrue(s.IndexOf("<") > 0); Assert.IsTrue(s.IndexOf("&") > 0); Assert.IsTrue(s.IndexOf(""") > 0); }
public virtual void testSort() { XMLDoc d = new XMLDoc("doc", null); KElement e = d.getRoot(); KElement e1 = e.appendElement("e1"); e1.setAttribute("a", "z"); KElement e2 = e.appendElement("e1"); e2.setAttribute("a", "c"); VElement v = new VElement(); v.Add(e1); v.Add(e2); v.Sort(); Assert.AreEqual(e2, v[0]); }
public virtual void testClone() { XMLDoc doc = new XMLDoc("foobar", null); XMLDoc doc2 = (XMLDoc)doc.Clone(); Assert.IsNotNull(doc.getDocumentElement()); Assert.IsNotNull(doc2.getDocumentElement()); Assert.AreNotEqual(doc.getDocumentElement(), doc2.getDocumentElement()); KElement e = doc.getRoot(); e.setAttribute("foo", "bar"); Assert.IsTrue(e.hasAttribute("foo")); KElement e2 = doc2.getRoot(); Assert.IsFalse(e2.hasAttribute("foo")); Assert.AreEqual(doc.getDoctype(), doc2.getDoctype()); Assert.AreEqual(e2.getOwnerDocument_KElement(), doc2); Assert.AreNotEqual(doc.getXMLDocUserData(), doc2.getXMLDocUserData()); }
public virtual void testMatchesPathKElement() { JDFDoc doc = new JDFDoc("Test"); // make sure we call jdf methods KElement root = doc.getRoot(); KElement a = root.appendElement("a"); root.appendElement("b"); KElement a2 = root.appendElement("a"); KElement a3 = root.appendElement("a"); a.setAttribute("att", "42"); Assert.IsTrue(a.matchesPath("//a", false)); Assert.IsTrue(a.matchesPath("/Test/a", false)); Assert.IsTrue(a.matchesPath("/Test/a[1]", false)); // Java to C# Conversion - Don't know why this fails, other tests pass. //Assert.IsTrue(a.matchesPath("/Test/a[@att=\"42\"]", false)); Assert.IsTrue(a2.matchesPath("/Test/a[2]", false)); Assert.IsTrue(a3.matchesPath("/Test/a[3]", false)); Assert.IsFalse(a3.matchesPath("/Test/a[@att=\"*\"]", false)); Assert.IsTrue(a.matchesPath("/Test/a[@att=\"*\"]", false)); }
public virtual void testSize() { Process.GetCurrentProcess(); GC.Collect(); Process.GetCurrentProcess(); GC.Collect(); Process.GetCurrentProcess(); GC.Collect(); XMLDoc d = new XMLDoc("JDF:foo", JDFConstants.JDFNAMESPACE); long memlocal = d.getDocMemoryUsed(); string s = d.write2String(0); Assert.IsTrue(memlocal + 100000 > s.Length, "mem 1"); // the gc is messy and sometimes returns +/- a few 10k Assert.IsTrue(memlocal + 100000 > s.Length, "mem 2"); d = JDFTestCaseBase.creatXMDoc(); memlocal = d.getDocMemoryUsed(); s = d.write2String(0); Assert.IsTrue(memlocal + 10000 > s.Length, "mem 3"); d = new XMLDoc("foo", null); KElement e = d.getRoot(); KElement e2 = e.appendElement("e2"); KElement e3 = e2.appendElement("e3"); for (int i = 33; i < 999; i++) { e3.setAttribute("k" + Convert.ToString(i), "value" + Convert.ToString(i)); } for (int j = 0; j < 99; j++) { e2.copyElement(e3, null); } memlocal = d.getDocMemoryUsed(); s = d.write2String(0); Assert.IsTrue(memlocal + 200000 > s.Length, "mem 4"); }
/// /// <summary> * remove duplicate warnings from the list and set schemaloction /// * </summary> /// * <param name="schemaLocation"> </param> /// public virtual void cleanXML(string schemaLocation) { VElement v = root.getChildElementVector(null, null, null, true, 0, false); v.unifyElement(); root.removeChildren(null, null, null); int size = v.Count; for (int i = 0; i < size; i++) { root.appendChild(v.item(i)); } if (schemaLocation == null) { root.setAttribute("ValidationResult", "NotPerformed"); } else { root.setAttribute("SchemaLocation", schemaLocation); if (root.hasChildElement("FatalError", null)) { root.setAttribute("ValidationResult", "FatalError"); } else if (root.hasChildElement("Error", null)) { root.setAttribute("ValidationResult", "Error"); } else if (root.hasChildElement("Warning", null)) { root.setAttribute("ValidationResult", "Warning"); } else { root.setAttribute("ValidationResult", "Valid"); } } }