Пример #1
0
        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());
        }
Пример #2
0
        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));
        }
Пример #3
0
        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");
        }
Пример #4
0
        public virtual void warning(Exception exception)
        {
            string   warn = exception.Message;
            KElement kEl  = root.appendElement("Warning");

            kEl.setAttribute("Message", warn);
        }
Пример #5
0
        public virtual void testgetNodeNames()
        {
            XMLDoc   d = new XMLDoc("doc", null);
            KElement e = d.getRoot();

            e.appendElement("a1");
            e.appendElement("b:a2", "b");
            VElement v = e.getChildElementVector(null, null, null, true, 0, true);
            VString  s = v.getElementNameVector(false);

            CollectionAssert.AreEqual(new VString("a1 b:a2", " "), s);
            s = v.getElementNameVector(true);
            CollectionAssert.AreEqual(new VString("a1 a2", " "), s);
        }
Пример #6
0
        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);
        }
Пример #7
0
            ///
            ///		 <summary> * (non-Javadoc)
            ///		 *  </summary>
            ///		 * <seealso cref= java.lang.Runnable#run() </seealso>
            ///
            protected internal override void runMyThread()
            {
                KElement root    = d.getRoot();
                string   baseDir = DirTestDataTemp + @"\threadDir";

                new DirectoryInfo(baseDir).Create();
                string @base = baseDir + @"\ThreadWrite_" + iLoop + "_";

                for (int j = 0; j < outerLoop; j++)
                {
                    if (j % 100 == 0)
                    {
                        Console.Write("\n" + iLoop + " " + j + " " + new JDFDate().TimeISO + " - ");
                    }
                    root.appendElement("bar");
                    Console.Write(".");
                    for (int i = 0; i < 100; i++)
                    {
                        string   fn   = @base + i + ".jdf";
                        FileInfo file = new FileInfo(fn);
                        file.Delete();
                        //Assert.IsTrue(file.createNewFile());
                        if (!d.write2File(file, 0, true))
                        {
                            Console.WriteLine("snafu " + iLoop);
                            throw new JDFException("Snafu");
                        }
                    }
                }
            }
Пример #8
0
        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");
            }
        }
Пример #9
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]);
        }
Пример #10
0
        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);
        }
Пример #11
0
        public virtual void testClone()
        {
            JDFDoc   d  = new JDFDoc("JDF");
            JDFDoc   d2 = (JDFDoc)d.Clone();
            KElement e1 = d.getRoot();
            KElement e2 = d2.getRoot();

            Assert.AreNotEqual(e1, e2);
            e1.appendElement("foo");
            Assert.IsNull(e2.getElement("foo"));
        }
Пример #12
0
        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"));
        }
Пример #13
0
        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));
        }
Пример #14
0
        public virtual void testWriteToStringIndent()
        {
            XMLDoc   d = new XMLDoc("a", null);
            KElement e = d.getRoot();

            e.appendElement("b");
            string s = d.write2String(2);

            Assert.IsTrue(s.IndexOf("\n ") > 0);
            s = d.write2String(0);
            Assert.IsTrue(s.EndsWith("<a>\r\n<b />\r\n</a>"));
        }
Пример #15
0
        public virtual void testGetParentJDFStatic()
        {
            JDFDoc     d    = new JDFDoc("JDF");
            JDFElement root = d.getJDFRoot();

            Assert.IsNull(JDFElement.getParentJDF(root));
            Assert.IsNull(JDFElement.getParentJDF(null));
            KElement k = root.appendElement("NodeInfo");

            Assert.AreEqual(root, JDFElement.getParentJDF(k));
            k = k.appendElement("foo:Bar", "www.foo.com");
            Assert.AreEqual(root, JDFElement.getParentJDF(k));
            k = root.appendElement("JDF");
            Assert.AreEqual(root, JDFElement.getParentJDF(k));
        }
Пример #16
0
        public virtual void testAppendElement()
        {
            JDFDoc   d = new JDFDoc("JDF");
            KElement r = d.getRoot();
            KElement e = r.appendElement("e");

            Assert.AreEqual(e.getNamespaceURI(), JDFElement.getSchemaURL());
            KElement foo = e.appendElement("pt:foo", "www.pt.com");

            Assert.AreEqual("www.pt.com", foo.getNamespaceURI());
            KElement bar = foo.appendElement("bar");

            Assert.IsNotNull(bar.getNamespaceURI());
            KElement foo2 = bar.appendElement("pt:foo", "www.pt.com");

            Assert.AreEqual("www.pt.com", foo2.getNamespaceURI());
        }
Пример #17
0
        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 : "");
        }
Пример #18
0
        public virtual void testContextSensitiveElementNames()
        { // HoleType, Method, Shape and Surface are context sensitive elements
          // The type casts below should all succeed
            JDFDoc   doc      = new JDFDoc(ElementName.JDF);
            KElement rootNode = doc.getRoot();

            JDFStringSpan kelem21 = (JDFStringSpan)rootNode.appendElement("HoleType", null);

            kelem21.setAttribute("Type", "org.cip4.jdflib.span.JDFStringSpan");
            KElement        kelem22 = rootNode.appendElement("RingBinding", null);
            JDFSpanHoleType kelem23 = (JDFSpanHoleType)kelem22.appendElement("HoleType", null);

            kelem23.setAttribute("Type", "org.cip4.jdflib.span.JDFSpanHoleType");

            JDFNameSpan kelem11 = (JDFNameSpan)rootNode.appendElement("Method", null);

            kelem11.setAttribute("Type", "org.cip4.jdflib.span.JDFNameSpan");
            KElement      kelem12 = rootNode.appendElement("InsertingIntent", null);
            JDFSpanMethod kelem13 = (JDFSpanMethod)kelem12.appendElement("Method", null);

            kelem13.setAttribute("Type", "org.cip4.jdflib.span.JDFSpanMethod");

            JDFShapeElement kelem4 = (JDFShapeElement)rootNode.appendElement("Shape", null);

            kelem4.setAttribute("Type", "org.cip4.jdflib.resource.JDFShapeElement");
            KElement     kelem5 = rootNode.appendElement("BookCase", null);
            JDFSpanShape kelem6 = (JDFSpanShape)kelem5.appendElement("Shape", null);

            kelem6.setAttribute("Type", "org.cip4.jdflib.span.JDFSpanShape");

            JDFSurface kelem7 = (JDFSurface)rootNode.appendElement("Surface", null);

            kelem7.setAttribute("Type", "org.cip4.jdflib.resource.process.JDFSurface");
            KElement       kelem8 = rootNode.appendElement("LaminatingIntent", null);
            JDFSpanSurface kelem9 = (JDFSpanSurface)kelem8.appendElement("Surface", null);

            kelem9.setAttribute("Type", "org.cip4.jdflib.span.JDFSpanSurface");
        }
Пример #19
0
        public virtual void testAppendAnchor()
        {
            JDFDoc     doc = new JDFDoc("JDF");
            JDFElement e   = doc.getJDFRoot();

            SupportClass.HashSetSupport m = new SupportClass.HashSetSupport();
            KElement e2 = e.appendElement("e2");

            // Java to C# Conversion - Divide number of tests by 1000 for now
            for (int i = 0; i < 10; i++)
            {
                JDFElement appendElement = (JDFElement)e2.appendElement("FooBar");
                string     s             = appendElement.appendAnchor(null);
                if (m.Contains(s))
                {
                    Assert.Fail("oops");
                }
                Assert.AreEqual(s, appendElement.getID());
                Assert.IsTrue(s.IndexOf("..") < 0);
                m.Add(s);
            }
        }
Пример #20
0
        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");
        }
Пример #21
0
        public virtual void testWriteToFileThreadWrite()
        {
            XMLDoc d    = new XMLDoc("doc", null);
            string @out = sm_dirTestDataTemp + @"\Thread.jdf";

            KElement root = d.getRoot();

            for (int i = 0; i < 1000; i++)
            {
                root.appendElement("elem0").appendElement("elem1").appendElement("elem2").setAttribute("foo", "bar" + i);
            }
            MyWriteThread[] mrs = new MyWriteThread[10];
            for (int i = 0; i < 10; i++)
            {
                MyWriteThread mr = new MyWriteThread();
                mr.d     = d;
                mr.iLoop = i;
                mrs[i]   = mr;
                new Thread(new ThreadStart(mr.Run)).Start();
            }
            Console.WriteLine("Writing start");
            Assert.IsTrue(d.write2File(@out, 2, true));
            Console.WriteLine("Writing done");
            for (int i = 0; i < 10; i++)
            {
                if (mrs[i].hook != null)
                {
                    // Assert.Fail("exception: "+h.e);
                    Console.WriteLine("******** Xerces known defect: not threadsafe: " + mrs[i].hook);
                }
            }

            FileInfo f = new FileInfo(@out);

            Assert.IsTrue(f.Exists);
        }
Пример #22
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));
            }
        }