コード例 #1
0
ファイル: JDFParser.cs プロジェクト: cip4/JDFLibNet
 ///
 ///	 * <param name="parser"> </param>
 ///
 public JDFParser(JDFParser parser)
     : this()
 {
     bKElementOnly = parser.bKElementOnly;
     m_eraseEmpty  = parser.m_eraseEmpty;
     initParser(m_SchemaLocation, m_DocumentClass);
 }
コード例 #2
0
ファイル: XMLDocTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testUmlaut()
        {
            XMLDoc        d      = new XMLDoc("doc", null);
            string        dirStr = sm_dirTestDataTemp + @"dir\dir%20 Grün€";
            DirectoryInfo dir    = new DirectoryInfo(dirStr);

            if (dir.Exists)
            {
                dir.Delete(true);
            }

            dir.Create();

            // get the directory path string without the relative path stuff (i.e. ..\..\)
            dirStr = dir.FullName;

            string   fStr = dirStr + @"\7€ .xml";
            FileInfo f    = new FileInfo(fStr);

            Assert.IsTrue(d.write2File(fStr, 0, true));
            Assert.IsTrue(f.Exists);

            JDFParser p  = new JDFParser();
            JDFDoc    d2 = p.parseFile(fStr);

            Assert.IsNotNull(d2);
            Assert.AreEqual("doc", d2.getRoot().LocalName);
        }
コード例 #3
0
        public virtual void testSchema()
        {
            DirectoryInfo foo = new DirectoryInfo(sm_dirTestSchema).Parent;

            Assert.IsTrue(foo.Exists, "please mount the svn schema parallel to jdflibJ");
            DirectoryInfo[] dirs = foo.GetDirectories("*Version_*");
            Assert.IsTrue(dirs.Length > 3);
            int nCheck = 0;

            for (int i = 0; i < dirs.Length; i++)
            {
                DirectoryInfo dir = dirs[i];
                if (!dir.Exists)
                {
                    continue;
                }
                FileInfo jdfxsd = new FileInfo(Path.Combine(dir.FullName, "JDF.xsd"));
                Assert.IsTrue(jdfxsd.Exists);
                JDFParser p = new JDFParser();
                p.setJDFSchemaLocation(jdfxsd);
                Assert.IsNotNull(p.parseString(s), "oops in" + jdfxsd);
                nCheck++;
            }
            Assert.IsTrue(nCheck >= 3);
        }
コード例 #4
0
ファイル: XMLDocTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testWriteToStreamIndent()
        {
            XMLDoc            d   = new XMLDoc("a", null);
            KElement          e   = d.getRoot();
            KElement          b   = e.appendElement("b");
            ByteArrayIOStream bos = new ByteArrayIOStream();

            d.write2Stream(bos, 2, false);
            string s = System.Text.Encoding.GetEncoding("utf-8").GetString(bos.ToArray());

            Assert.IsTrue(s.IndexOf("\n ") > 0);
            string text = "aa\r\nbb\r\n";

            b.setText(text);
            bos = new ByteArrayIOStream();
            d.write2Stream(bos, 2, false);
            s = System.Text.Encoding.GetEncoding("utf-8").GetString(bos.ToArray());
            Assert.IsTrue(s.IndexOf(text) > 0);
            JDFParser p = new JDFParser();

            //		JDFDoc dd =
            p.parseStream(bos.getInputStream());
            bos = new ByteArrayIOStream();
            d.write2Stream(bos, 2, false);
            s = System.Text.Encoding.GetEncoding("utf-8").GetString(bos.ToArray());
            Assert.IsTrue(s.IndexOf(text) > 0);
        }
コード例 #5
0
        public virtual void testFormat()
        {
            JDFDoc     doc  = new JDFDoc(ElementName.JDF);
            JDFNode    root = doc.getJDFRoot();
            JDFComment c11  = root.appendComment();
            string     txt  = "This element should have no ID attribute and is a rellly long line with many many characters.. asfihAFLKFKJGFaufksgUFGagfAFKJSG";

            txt += txt;
            txt += txt; // even longer...
            c11.setText(txt);
            JDFComment   c21  = root.appendComment();
            const string txt2 = "This element \n has \n crlf";

            c21.setText(txt2);
            Assert.AreEqual(txt, c11.getText(), "text is equal in DOM");
            Assert.AreEqual(txt2, c21.getText(), "text is equal in DOM");
            string commentFile = sm_dirTestDataTemp + @"\CommentTest.JDF";

            doc.write2File(commentFile, 2, true);
            JDFParser  p     = new JDFParser();
            JDFDoc     doc2  = p.parseFile(commentFile);
            JDFNode    root2 = doc2.getJDFRoot();
            JDFComment c12   = root2.getComment(0);
            JDFComment c22   = root2.getComment(1);

            Assert.AreEqual(txt, c12.getText(), "text is equal after parse");
            Assert.AreEqual(txt2, c22.getText(), "text is equal after parse");
        }
コード例 #6
0
ファイル: FactoryTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testFactory()
        {
            string strFile = "bookintent.jdf";

            JDFParser p      = new JDFParser();
            JDFDoc    jdfDoc = p.parseFile(sm_dirTestData + strFile);

            Assert.IsTrue(jdfDoc != null, "");
        }
コード例 #7
0
        public virtual void testSpeed2()
        {
            long      l1 = DateTime.Now.Ticks;
            JDFParser p  = new JDFParser();

            for (int i = 0; i < 1000; i++)
            {
                p.parseString(s);
            }
            Console.WriteLine("reuse: " + (DateTime.Now.Ticks - l1) / 1000000);
        }
コード例 #8
0
        public virtual void testParseSpeed()
        {
            JDFParser parser = new JDFParser();

            System.GC.Collect();
            long   l1 = DateTime.Now.Ticks;
            JDFDoc d  = parser.parseFile(sm_dirTestData + "bigWhite.jdf");

            Assert.IsNotNull(d);
            Console.WriteLine("big parse:   " + (DateTime.Now.Ticks - l1) / 1000000);
        }
コード例 #9
0
        public virtual void testNull()
        {
            JDFDoc    doc = null;
            string    foo = "wehflkh";
            JDFParser p   = new JDFParser();

            doc = p.parseString(foo);
            Assert.IsNull(doc);
            doc = new JDFDoc("JDF");
            Assert.IsNotNull(doc.getNodeName());
        }
コード例 #10
0
        public virtual void testRoots()
        {
            string xmlFile = "job.jdf";

            JDFParser p      = new JDFParser();
            JDFDoc    jdfDoc = p.parseFile(sm_dirTestData + xmlFile);

            Assert.IsTrue(jdfDoc != null, xmlFile + ": Parse Error");
            if (jdfDoc == null)
            {
                return; // soothe findbugs ;)
            }
            Assert.IsNotNull(jdfDoc.getJDFRoot(), "jdf root");
            Assert.IsNull(jdfDoc.getJMFRoot(), "no jmf root");
        }
コード例 #11
0
        public virtual void testForeignRoot()
        {
            XMLDoc   doc = new XMLDoc("Foo", "fooNS");
            KElement r   = doc.getRoot();
            JDFNode  n   = new JDFDoc("JDF").getJDFRoot();

            r.copyElement(n, null);
            string    s = doc.write2String(0);
            JDFParser p = new JDFParser();
            JDFDoc    d = p.parseString(s);

            Assert.IsNotNull(d.getJDFRoot());
            Assert.IsNotNull(d.getRoot());
            Assert.AreNotEqual(d.getRoot(), d.getJDFRoot());
        }
コード例 #12
0
ファイル: JDFElementTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testCopyElement()
        {
            JDFDoc     d  = new JDFDoc("d1");
            JDFElement e  = (JDFElement)d.getRoot();
            JDFDoc     d2 = new JDFDoc("d2");
            JDFElement e2 = (JDFElement)d2.getRoot();
            KElement   e3 = e.copyElement(e2, null);
            JDFParser  p  = new JDFParser();
            JDFDoc     dp = p.parseString("<Device xmlns=\"www.CIP4.org/JDFSchema_1_1\"/>");
            KElement   ep = dp.getRoot();
            KElement   e4 = e.copyElement(ep, null);

            Assert.AreEqual(e4.hasAttribute("xmlns"), ep.hasAttribute("xmlns"));
            Assert.AreEqual(e3.getNamespaceURI(), e.getNamespaceURI());
            Assert.IsFalse(d.ToString().IndexOf("xmlns=\"\"") >= 0);
        }
コード例 #13
0
ファイル: JDFElementTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testIsValid()
        {
            DirectoryInfo testData = new DirectoryInfo(sm_dirTestData + "SampleFiles");

            Assert.IsTrue(testData.Exists, "testData dir");
            FileInfo[] fList = testData.GetFiles();
            JDFParser  p     = new JDFParser();
            JDFParser  p2    = new JDFParser();

            p2.m_SchemaLocation = sm_dirTestSchema + "JDF.xsd";

            for (int i = 0; i < fList.Length; i++)
            {
                FileInfo file = fList[i];
                // skip directories in CVS environments
                //if (file.isDirectory())
                //   continue;

                // skip schema files
                if (file.FullName.EndsWith(".xsd"))
                {
                    continue;
                }

                Console.WriteLine("Parsing: " + file.FullName);
                JDFDoc jdfDoc = p.parseFile(file.FullName);
                Assert.IsTrue(jdfDoc != null, "parse ok");

                KElement e = null;
                if (jdfDoc != null)
                {
                    e = jdfDoc.getRoot();
                    Assert.IsTrue(e.isValid(EnumValidationLevel.RecursiveComplete), "valid doc: " + file.FullName);
                }

                // now with schema validation
                jdfDoc = p2.parseFile(file.FullName);
                Assert.IsTrue(jdfDoc != null, "schema parse ok");

                // TODO fix handling of prerelease default attributes
                if (jdfDoc != null)
                {
                    e = jdfDoc.getRoot();
                    Assert.IsTrue(e.isValid(EnumValidationLevel.RecursiveComplete), "valid doc: " + file.FullName);
                }
            }
        }
コード例 #14
0
        public virtual void testCorrupt()
        {
            JDFDoc    doc = null;
            string    foo = "wehflkh";
            JDFParser p   = new JDFParser();

            doc = p.parseString(foo);
            Assert.IsNull(doc);
            foo = "<xxx><yyy><zzz></yyy></xxx>";
            doc = p.parseString(foo);
            Assert.IsNull(doc);

            doc = p.parseFile(sm_dirTestData + "corrupt.jdf");
            Assert.IsNull(doc);
            doc = new JDFDoc("JDF");
            Assert.IsNotNull(doc.getNodeName());
        }
コード例 #15
0
ファイル: JDFElementTest.cs プロジェクト: cip4/JDFLibNet
        private void _setUp()
        {
            // setup the fixture
            string xmlFile = "bookintent.jdf";

            // test jdf functions
            // ==================
            JDFParser p = new JDFParser();

            m_jdfDoc = p.parseFile(sm_dirTestData + xmlFile);

            Assert.IsTrue(m_jdfDoc != null, sm_dirTestData + xmlFile + ": Parse Error");

            m_jdfRoot    = (JDFNode)m_jdfDoc.getRoot();
            m_kElement   = m_jdfRoot.getChildByTagName("Dimensions", "", 0, null, false, true);
            m_jdfElement = (JDFElement)m_kElement;
        }
コード例 #16
0
ファイル: XMLDocTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testParseNoNS()
        {
            XMLDoc d  = new XMLDoc("TEST", null);
            string fn = sm_dirTestDataTemp + "testParseNoNS.xml";

            d.write2File(fn, 2, true);
            JDFParser p    = new JDFParser();
            JDFDoc    d2   = p.parseFile(fn);
            KElement  root = d2.getRoot();

            // Assert.IsNull(root.getNamespaceURI());
            Assert.IsFalse(d2.ToString().IndexOf("xmlns=\"\"") >= 0);
            Assert.IsFalse(d.ToString().IndexOf("xmlns=\"\"") >= 0);
            Assert.IsFalse(root.ToString().IndexOf("xmlns=\"\"") >= 0);
            KElement foo = root.appendElement("foofoo");

            Assert.IsNull(foo.getNamespaceURI() == "" ? null : "");
        }
コード例 #17
0
 public virtual void testSchemaDefault()
 {
     for (int i = 0; i < 3; i++)
     {
         JDFDoc  doc = new JDFDoc("JDF");
         JDFNode n   = (JDFNode)doc.getRoot();
         Assert.IsFalse(n.hasAttribute(AttributeName.TEMPLATE), "no schema - no default");
         string    s           = doc.write2String(2);
         JDFParser parser      = new JDFParser();
         JDFDoc    docNoSchema = parser.parseString(s);
         JDFNode   as2         = (JDFNode)docNoSchema.getRoot();
         Assert.IsFalse(as2.hasAttribute(AttributeName.TEMPLATE), "no schema - no default");
         parser.m_SchemaLocation = sm_dirTestSchema + @"\JDF.xsd";
         JDFDoc  docSchema = parser.parseString(s);
         JDFNode as3       = (JDFNode)docSchema.getRoot();
         Assert.IsTrue(as3.hasAttribute(AttributeName.TEMPLATE), "schema parse - default is set");
         Assert.IsFalse(as3.getTemplate(), "schema parse - default is set");
     }
 }
コード例 #18
0
ファイル: FactoryTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testRemoveAttributeStringString()
        {
            JDFParser p      = new JDFParser();
            JDFDoc    jdfDoc = p.parseFile(sm_dirTestData + "emptyAuthorAttribute.jdf");

            JDFElement root  = jdfDoc.getJDFRoot();
            KElement   kElem = root.getChildByTagName("Created", "", 0, null, false, true);

            bool before = kElem.hasAttribute("Author", "", false);

            Assert.IsTrue(before, "The Attribute 'Author' does not exist");

            if (before)
            {
                kElem.removeAttribute("Author", "");
                bool after = kElem.hasAttribute("Author", "", false);

                Assert.IsFalse(after, "The Attribute 'Author' was not removed");
            }
        }
コード例 #19
0
ファイル: JDFDocumentBuilder.cs プロジェクト: cip4/JDFLibNet
        ///
        ///	 <summary> * Method init
        ///	 *  </summary>
        ///	 * <param name="parser"> </param>
        ///

        private void init(JDFParser parser)
        {
            m_parser = parser;
            m_parser.m_DocumentClass = "org.cip4.jdflib.core.DocumentJDFImpl";
        }
コード例 #20
0
        public virtual void testPerformance()
        {
            {
                JDFDoc   doc  = new JDFDoc("JDF");
                KElement root = doc.getRoot();
                long     l    = DateTime.Now.Ticks;
                // Java to C# Conversion - Divide number of tests by 1000 for now
                for (int i = 0; i < 10; i++)
                {
                    root.appendElement("Elem00");
                }
                Console.WriteLine("Append With factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                string s = doc.write2String(0);
                Console.WriteLine("Write With factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                JDFParser p = new JDFParser();
                Console.WriteLine("Parser With factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                p.parseString(s);
                Console.WriteLine("Parse With factory: " + (DateTime.Now.Ticks - l));
            }
            {
                JDFDoc   doc  = new JDFDoc("JDF");
                KElement root = doc.getRoot();
                ((DocumentJDFImpl)root.OwnerDocument).bKElementOnly = true;
                long l = DateTime.Now.Ticks;
                // Java to C# Conversion - Divide number of tests by 1000 for now
                for (int i = 0; i < 10; i++)
                {
                    root.appendElement("Elem00");
                }
                Console.WriteLine("Append Without factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                string s = doc.write2String(0);
                Console.WriteLine("Write Without factory: " + (DateTime.Now.Ticks - l) + " " + s.Length);
                l = DateTime.Now.Ticks;
                JDFParser p = new JDFParser();
                Console.WriteLine("Parser Without factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                p.parseString(s);
                Console.WriteLine("Parse Without factory: " + (DateTime.Now.Ticks - l));
            }

            {
                JDFDoc   doc  = new JDFDoc("JDF");
                KElement root = doc.getRoot();
                ((DocumentJDFImpl)root.OwnerDocument).bKElementOnly = true;
                long l = DateTime.Now.Ticks;
                // Java to C# Conversion - Divide number of tests by 1000 for now
                for (int i = 0; i < 10; i++)
                {
                    root.appendElement("Elem00");
                }
                Console.WriteLine("Append00 Without factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                string s = doc.write2String(0);
                Console.WriteLine("Write00 Without factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                JDFParser p = new JDFParser();
                Console.WriteLine("Parser00 Without factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                p.parseString(s);
                Console.WriteLine("Parse00 Without factory: " + (DateTime.Now.Ticks - l));
            }

            {
                JDFDoc   doc  = new JDFDoc("JDF");
                KElement root = doc.getRoot();
                long     l    = DateTime.Now.Ticks;
                // Java to C# Conversion - Divide number of tests by 1000 for now
                for (int i = 0; i < 10; i++)
                {
                    root.appendElement("Elem00");
                }
                Console.WriteLine("Append With factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                string s = doc.write2String(0);
                Console.WriteLine("Write With factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                JDFParser p = new JDFParser();
                Console.WriteLine("Parser With factory: " + (DateTime.Now.Ticks - l));
                l = DateTime.Now.Ticks;
                p.parseString(s);
                Console.WriteLine("Parse With factory: " + (DateTime.Now.Ticks - l));
            }
        }
コード例 #21
0
        public virtual void testParseString()
        {
            JDFParser parser = new JDFParser();

            Assert.IsNotNull(parser.parseString(s));
        }
コード例 #22
0
ファイル: XMLDocTest.cs プロジェクト: cip4/JDFLibNet
        public virtual void testDirtyIDs()
        {
            // -i bookintent.jdf -o spawned.jdf -p 4
            string xmlFile   = "bookintent.jdf";
            string outFile   = "spawned.jdf";
            string strPartID = "4";

            JDFParser p        = new JDFParser();
            JDFDoc    jdfDocIn = p.parseFile(sm_dirTestData + xmlFile);

            Assert.IsTrue(jdfDocIn != null);
            if (jdfDocIn == null)
            {
                return; // soothe findbugs ;)
            }

            XMLDocUserData xmlUserData = jdfDocIn.getCreateXMLDocUserData();

            xmlUserData.setDirtyPolicy(XMLDocUserData.EnumDirtyPolicy.ID);

            JDFNode rootIn = (JDFNode)jdfDocIn.getRoot();

            JDFNode nodeToSpawn;

            if (strPartID.Equals(""))
            {
                nodeToSpawn = rootIn;
            }
            else
            {
                nodeToSpawn = rootIn.getJobPart(strPartID, "");
            }

            if (nodeToSpawn == null)
            {
                Assert.Fail("No such JobPartID: " + strPartID);
            }
            else
            {
                ArrayList vRWResources = new ArrayList();
                vRWResources.Add("Component");
                vRWResources.Add("RunList");

                VJDFAttributeMap vSpawnParts = new VJDFAttributeMap();
                JDFSpawn         spawn       = new JDFSpawn(nodeToSpawn);

                JDFNode node = spawn.spawn(xmlFile, outFile, vRWResources, vSpawnParts, false, false, false, false);

                // neu gespawntes FileInfo rausschreiben
                JDFNode rootOut = node;
                XMLDoc  docOut  = rootOut.getOwnerDocument_KElement();
                docOut.write2File(sm_dirTestDataTemp + outFile, 0, true);

                // verändertes Ausgangsfile rausschreiben
                string strOutXMLFile = "_" + xmlFile;
                rootIn.eraseEmptyNodes(true);
                jdfDocIn.write2File(sm_dirTestDataTemp + strOutXMLFile, 0, true);
                Assert.IsTrue(true, "SpawnJDF ok");

                // test, if all changed nodes are in our list

                // Java to C# Conversion - Java version indicated there should be 5 Dirty IDs, but it only checks for 4.
                //                         C# version returns 4 Dirty IDs.  Set it to 4 for now.
                VString vstrDirtyIDs = jdfDocIn.getDirtyIDs();
                Assert.AreEqual(4, vstrDirtyIDs.Count);
                Assert.IsTrue(vstrDirtyIDs.Contains("n0014")); // audit pool was added
                Assert.IsTrue(vstrDirtyIDs.Contains("n0016")); // status changed:
                // waiting --> spawned
                Assert.IsTrue(vstrDirtyIDs.Contains("r0017")); //SpawnStatus="SpawnedRW"
                // added
                Assert.IsTrue(vstrDirtyIDs.Contains("r0018")); // SizeIntent added
            }
        }