Project

Profile

Help

How to connect?
Download (3.37 KB) Statistics
| Branch: | Revision:

he / src / test / nunit / SaxonNUnit / SaxonNUnit / TestPackage.cs @ 3df04590

1
using System;
2
using System.Collections.Generic;
3
using System.Collections;
4
using System.Linq;
5
using System.IO;
6
using System.Text;
7
using Saxon.Api;
8
using NUnit.Framework;
9
using System.Xml;
10

    
11
namespace SaxonNUnit
12
{
13
    class TestPackage
14
    {
15

    
16
        [Test]
17
        public void TestSimple()
18
        {
19
            try {
20
                Processor proc = new Processor(true);
21
               // proc.Implementation.setConfigurationProperty("", false);
22
                XsltCompiler xc = proc.NewXsltCompiler();
23
                FileStream file1 = new FileStream(ConfigTest.XSLT3TS_DIR + "decl\\override\\override-base-f-001.xsl", FileMode.Open);
24
                XsltPackage pack1 = xc.CompilePackage(file1);
25
                FileStream file2 = new FileStream(ConfigTest.DATA_DIR + "test-package-001.pack", FileMode.Create);
26
                pack1.Save(file2);
27

    
28
                Processor proc2 = new Processor(true);
29
                XsltCompiler xc2 = proc2.NewXsltCompiler();
30
                XsltPackage xp = xc2.LoadLibraryPackage(new Uri(ConfigTest.DATA_DIR + "test-package-001.pack"));
31
                xc2.ImportPackage(xp);
32
                FileStream file3 = new FileStream(ConfigTest.XSLT3TS_DIR + "decl\\override\\override-f-001.xsl", FileMode.Open);
33
                XsltExecutable xe = xc2.Compile(file3);
34
                Xslt30Transformer xt = xe.Load30();
35
                XdmValue result = xt.CallTemplate(new QName("main"));
36

    
37

    
38
                file1.Close();
39
                file2.Close();
40
                Assert.True(true);
41
            }
42
            catch (javax.xml.transform.TransformerException e)
43
            {
44
                Console.WriteLine(e.getMessage());
45
                Assert.Fail();
46
            }
47
        
48
    }
49

    
50
        [Test]
51
        public void TestPackage1() {
52
            try { 
53
            Processor processor = new Processor(true);
54

    
55
            XsltCompiler xsltCompiler = processor.NewXsltCompiler();
56
            xsltCompiler.XsltLanguageVersion = "3.0";
57
            XsltPackage packageA;
58
            using (Stream stream = File.OpenRead(ConfigTest.NUNIT_DATA_DIR + "packageA.xsl"))
59
                packageA = xsltCompiler.CompilePackage(stream);
60

    
61
            xsltCompiler = processor.NewXsltCompiler();
62
            xsltCompiler.XsltLanguageVersion = "3.0";
63
            xsltCompiler.ImportPackage(packageA);
64
            XsltPackage packageB;
65
            using (Stream stream = File.OpenRead(ConfigTest.NUNIT_DATA_DIR + "packageB.xsl"))
66
                packageB = xsltCompiler.CompilePackage(stream);
67

    
68
            xsltCompiler = processor.NewXsltCompiler();
69
            xsltCompiler.XsltLanguageVersion = "3.0";
70
            xsltCompiler.ImportPackage(packageA);
71
            xsltCompiler.ImportPackage(packageB);
72
            XsltExecutable exec = xsltCompiler.Compile(new Uri("file:///"+ ConfigTest.NUNIT_DATA_DIR+"testPackage.xsl"));
73
            Xslt30Transformer transf = exec.Load30();
74
            Serializer serializer = processor.NewSerializer();
75
            StringWriter sw = new StringWriter();
76
            serializer.SetOutputWriter(sw);
77
            serializer.SetOutputProperty(Serializer.METHOD, "text");
78
               
79
            transf.CallTemplate(null, serializer);
80
            string res = sw.ToString();
81
                Assert.NotNull(res);
82
            }
83
            catch (Exception e)
84
            {
85
                Console.WriteLine(e.Message);
86
                Assert.Fail();
87
            }
88
        }
89
    }
90
}
(11-11/19)