public virtual void testValidatePrivateDoc() { JDFDoc doc = new JDFDoc("JDF"); JDFValidator checkJDF = new JDFValidator(); checkJDF.setPrint(false); checkJDF.bQuiet = true; checkJDF.level = EnumValidationLevel.Incomplete; JDFNode n = doc.getJDFRoot(); checkJDF.setIgnorePrivate(true); n.setAttribute("foo:bar", "foobar", "www.foo.cpm"); XMLDoc schemaValidationResult = checkJDF.processSingleDocument(doc); KElement root = schemaValidationResult.getRoot(); Assert.AreEqual(root.getXPathAttribute("TestFile/CheckJDFOutput/@IsValid", "booboo"), "true"); n.removeAttribute("bar", "www.foo.cpm"); n.appendElement("foo:bar", "www.foo.cpm"); schemaValidationResult = checkJDF.processSingleDocument(doc); root = schemaValidationResult.getRoot(); Assert.AreEqual(root.getXPathAttribute("TestFile[2]/CheckJDFOutput/@IsValid", "booboo"), "true"); n.setAttribute("jdfbar", "thisbebad"); schemaValidationResult = checkJDF.processSingleDocument(doc); root = schemaValidationResult.getRoot(); Assert.AreEqual(root.getXPathAttribute("TestFile[3]/CheckJDFOutput/@IsValid", "booboo"), "false"); n.removeAttribute("jdfbar", null); n.appendElement("jdfbar", null); schemaValidationResult = checkJDF.processSingleDocument(doc); root = schemaValidationResult.getRoot(); Assert.AreEqual(root.getXPathAttribute("TestFile[4]/CheckJDFOutput/@IsValid", "booboo"), "false"); }
public virtual void testRegisterClass() { XMLDoc.registerCustomClass("JDFTestType", "org.cip4.jdflib.core.JDFTestType"); XMLDoc.registerCustomClass("fnarf:JDFTestType", "org.cip4.jdflib.core.JDFTestType"); JDFDoc d = new JDFDoc("JDF"); JDFNode n = d.getJDFRoot(); JDFTestType tt = (JDFTestType)n.appendElement("JDFTestType", null); tt.setAttribute("fnarf", 3, null); Assert.IsTrue(tt.isValid(KElement.EnumValidationLevel.Complete), "extension is valid"); tt = (JDFTestType)n.appendElement("fnarf:JDFTestType", "WWW.fnarf.com"); tt.setAttribute("fnarf", 3, null); Assert.IsTrue(tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); tt.setAttribute("fnarf", "a", null); // illegal - must be integer Assert.IsTrue(!tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); tt.removeAttribute("fnarf", null); Assert.IsTrue(tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); tt.setAttribute("gnu", "a", null); // illegal - non existent Assert.IsFalse(tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); // boolean bClassCast = false; // try // { // tt = (JDFTestType) n.appendElement("blub:JDFTestType", // "WWW.fnarf2.com"); // } // catch (ClassCastException exc) // { // bClassCast = true; // } // Assert.IsTrue("ns extension works", bClassCast); Assert.IsTrue(!(n.appendElement("blub:JDFTestType", "WWW.fnarf2.com") is JDFTestType), "ns extension works"); }
public virtual void testRemoveExtensions() { JDFDoc d = new JDFDoc("JDF"); JDFNode n = d.getJDFRoot(); n.appendElement("a:b", "a.com"); n.getAuditPool().appendElement("a:b", "a.com"); n.getAuditPool().setAttribute("a:b", "c", "a.com"); Assert.IsTrue(n.ToString().IndexOf("a:") > 0); n.removeExtensions(); Assert.AreEqual(-1, n.ToString().IndexOf("a:")); }
public virtual void testGenerateDotID() { JDFDoc doc = new JDFDoc("JDF"); JDFNode e = doc.getJDFRoot(); string dotID = e.generateDotID("foo", null); e.setAttribute("foo", dotID, null); Assert.IsNotNull(dotID); Assert.IsTrue(dotID.StartsWith("n")); JDFNode e2 = (JDFNode)e.appendElement("JDF", null); string generateDotID = e2.generateDotID("foo", null); e2.setAttribute("foo", generateDotID, null); Assert.AreEqual(dotID + ".1", generateDotID); JDFNode e3 = (JDFNode)e2.appendElement("JDF", null); generateDotID = e3.generateDotID("foo", null); e3.setAttribute("foo", generateDotID, null); Assert.AreEqual(dotID + ".1.1", generateDotID); e3 = (JDFNode)e2.appendElement("JDF", null); generateDotID = e3.generateDotID("foo", null); e3.setAttribute("foo", generateDotID, null); Assert.AreEqual(dotID + ".1.2", generateDotID); e2.setAttribute("foo", "whatever", null); e2 = (JDFNode)e.appendElement("JDF", null); generateDotID = e2.generateDotID("foo", null); e2.setAttribute("foo", generateDotID, null); Assert.AreEqual(dotID + ".2", generateDotID); for (int i = 3; i < 22; i++) { e2 = (JDFNode)e.appendElement("JDF", null); generateDotID = e2.generateDotID("foo", null); e2.setAttribute("foo", generateDotID, null); Assert.AreEqual(dotID + "." + Convert.ToString(i), generateDotID); } }
private void testJDFClass(string fileName) { bool result = false; string elementName = fileName; string prefix = elementName.StartsWith("JDFAuto") ? "JDFAuto" : "JDF"; //.Net Substring different than java substring. elementName = elementName.Substring(prefix.Length, elementName.Length - ".cs".Length - prefix.Length); // adjust the element name if (elementName.StartsWith("Span")) { elementName = elementName.Substring("Span".Length); } else if (elementName.Equals("ShapeElement")) { elementName = "Shape"; } else if (elementName.Equals("Node")) { elementName = "JDF"; } JDFDoc jdfDoc = new JDFDoc(ElementName.JDF); JDFNode jdfRoot = (JDFNode)jdfDoc.getRoot(); KElement kElem = jdfRoot.appendElement(elementName); // create a class // for // elementName string createdClass = kElem.GetType().ToString(); createdClass = createdClass.Substring(createdClass.LastIndexOf(".") + 1); result = elementName.Equals(createdClass.Substring("JDF".Length)) || (elementName.Equals(ElementName.COLORSUSED) && createdClass.Equals("JDFSeparationList")) || (elementName.Equals(ElementName.SHAPE) && createdClass.Equals("JDFShapeElement")) || (elementName.EndsWith(JDFConstants.LINK) && createdClass.Substring("JDF".Length).Equals(ElementName.RESOURCELINK)); if (!result) { totalResult = false; throw new Exception("Error!!! Class " + elementName + " (" + fileName + ") could not be instantiated!" + " --> missing entry in DocumentJDFImpl.sm_PackageNames ???"); } }
private void testJDFClass(string fileName) { bool result = false; string elementName = fileName; string prefix = elementName.StartsWith("JDFAuto") ? "JDFAuto" : "JDF"; //.Net Substring different than java substring. elementName = elementName.Substring(prefix.Length, elementName.Length - ".cs".Length - prefix.Length); // adjust the element name if (elementName.StartsWith("Span")) { elementName = elementName.Substring("Span".Length); } else if (elementName.Equals("ShapeElement")) { elementName = "Shape"; } else if (elementName.Equals("Node")) { elementName = "JDF"; } JDFDoc jdfDoc = new JDFDoc(ElementName.JDF); JDFNode jdfRoot = (JDFNode)jdfDoc.getRoot(); KElement kElem = jdfRoot.appendElement(elementName); // create a class // for // elementName string createdClass = kElem.GetType().ToString(); createdClass = createdClass.Substring(createdClass.LastIndexOf(".") + 1); result = fileName.Equals(createdClass + ".cs") || (fileName.StartsWith("JDFAuto") && createdClass.Equals(JDFConstants.JDFELEMENT)) || fileName.Equals(JDFConstants.JDFNODE) || !createdClass.Equals(JDFConstants.JDFELEMENT); if (!result) { throw new Exception("Class " + elementName + " (" + fileName + ") could not be instantiated!" + " --> missing entry in DocumentJDFImpl ???"); } }
public void testFitsValue_MatrixState() { JDFDoc jdfDoc = new JDFDoc(ElementName.JDF); JDFNode root = jdfDoc.getJDFRoot(); JDFMatrix matrix1 = new JDFMatrix("1 0 0 1 3.14 21631.3"); JDFMatrix matrix2 = new JDFMatrix("0 1 1 0 2 21000"); List <ValuedEnum> transforms = new List <ValuedEnum>(); transforms.Add(EnumOrientation.Rotate0); transforms.Add(EnumOrientation.Rotate270); transforms.Add(EnumOrientation.Flip0); JDFRectangle shift = new JDFRectangle("2 4 20000 23000"); string value1 = "1 0 0 1 3.14 21631.3"; JDFMatrixState k = (JDFMatrixState)root.appendElement("MatrixState"); k.appendValue(); // k.setValueValueUsage(0, EnumFitsValue.Allowed); k.setValueAllowedValue(0, matrix2); k.appendValue(); // k.setValueValueUsage(1, EnumFitsValue.Present); k.setValueAllowedValue(1, matrix1); k.setAllowedTransforms(transforms); k.setAllowedShift(shift); k.setAllowedRotateMod(15); EnumListType lt = EnumListType.UniqueList; // JDFAbstractState.EnumListType lt = EnumListType.ListType.Unknown; // JDFAbstractState.EnumListType lt = EnumListType.ListType.List; k.setListType(lt); // EnumListType listType = k.getListType(); Assert.IsTrue(k.fitsValue(value1, EnumFitsValue.Allowed), "Matrix OK"); string @value = "1 2 3 4 5 6 7 8 9 10 11 12 3 4 5 6 7 8"; VString vs = new VString(@value, JDFConstants.BLANK); int siz = vs.Count; Assert.AreEqual(0, siz % 6, "It is not a Matrix"); VString matrixList = new VString(); int i = 0; StringBuilder sb = new StringBuilder(250); sb.Append(vs[i]); while ((i + 1) < siz) { do { sb.Append(JDFConstants.BLANK); i++; sb.Append(vs[i]); } while ((i + 1) % 6 != 0); matrixList.Add(sb.ToString()); if ((i + 1) < siz) { i++; sb = new StringBuilder(250); sb.Append(vs[i]); } } for (int z = 0; z < matrixList.Count; z++) { JDFMatrix matrix3 = new JDFMatrix(matrixList.stringAt(z)); //matrix3.A; } }
protected internal static JDFDoc creatXMDoc() { JDFElement.setDefaultJDFVersion(EnumVersion.Version_1_3); JDFDoc doc = new JDFDoc("JDF"); JDFNode n = doc.getJDFRoot(); n.setJobPartID("P1"); n.setJobID("J1"); n.setType("ConventionalPrinting", true); n.appendElement("NS:Foobar", "www.foobar.com"); n.appendMatchingResource("Layout", JDFNode.EnumProcessUsage.AnyInput, null); JDFComponent comp = (JDFComponent)n.appendMatchingResource("Component", JDFNode.EnumProcessUsage.AnyOutput, null); JDFExposedMedia xm = (JDFExposedMedia)n.appendMatchingResource("ExposedMedia", JDFNode.EnumProcessUsage.Plate, null); JDFNodeInfo ni = n.appendNodeInfo(); JDFMedia m = xm.appendMedia(); m.appendElement("NS:FoobarMedia", "www.foobar.com"); Assert.AreEqual(EnumResourceClass.Consumable, m.getResourceClass(), "m Class"); VString vs = new VString(); vs.Add("SignatureName"); vs.Add("SheetName"); vs.Add("Side"); JDFAttributeMap mPart1 = new JDFAttributeMap("SignatureName", "Sig1"); mPart1.put("SheetName", "S1"); mPart1.put("Side", "Front"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); mPart1.put("Side", "Back"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); mPart1.put("SheetName", "S2"); mPart1.put("Side", "Front"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); mPart1.put("Side", "Back"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); mPart1.put("SignatureName", "Sig2"); mPart1.put("SheetName", "S1"); mPart1.put("Side", "Front"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); comp.appendElement("foo:bar", "www.foobar.com"); mPart1.put("Side", "Back"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); mPart1.put("SheetName", "S2"); mPart1.put("Side", "Front"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); mPart1.put("Side", "Back"); xm.getCreatePartition(mPart1, vs); ni.getCreatePartition(mPart1, vs); comp.getCreatePartition(mPart1, vs); return(doc); }