Exemple #1
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);
        }
Exemple #2
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());
        }
Exemple #3
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");
     }
 }
Exemple #4
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());
        }
Exemple #5
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);
        }
Exemple #6
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());
        }
Exemple #7
0
        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);
        }
Exemple #8
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));
            }
        }
Exemple #9
0
        public virtual void testParseString()
        {
            JDFParser parser = new JDFParser();

            Assert.IsNotNull(parser.parseString(s));
        }