Project

Profile

Help

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

he / src / samples / cs / TestRunner10.0 / ResultsDocument.cs @ be17ef52

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

    
9
namespace TestRunner
10
{
11
    public abstract class ResultsDocument
12
    {
13
        public string resultsDir;
14
        public Spec spec;
15
        public XmlWriter results;
16
        public StreamWriter writer;
17

    
18
        public ResultsDocument(string rdir, Spec sp)
19
        {
20
            this.resultsDir = rdir;
21
            this.spec = sp;
22
        }
23

    
24
           
25
        public void createWriter(Processor processor) {
26

    
27
            string fileName = resultsDir + "/results"
28
                + "_" + ((SpecAttr)spec.GetAttr()).fname + "_" + processor.ProductVersion + "n.xml";
29
            // Delete the file if it exists.
30
       
31
            if (System.IO.File.Exists(fileName)){
32
            
33
                System.IO.File.Delete(fileName);
34
            }
35
          //  StreamWriter resultWriter = File.CreateText(fileName);   
36
        Serializer serializer =processor.NewSerializer();
37
          
38
        serializer.SetOutputWriter(null);
39
        serializer.SetOutputProperty(Serializer.METHOD, "xml");
40
        serializer.SetOutputProperty(Serializer.INDENT, "yes");
41
        //serializer.SetOutputProperty(Serializer.Property.SAXON_LINE_LENGTH, "120");
42
        //this.Writer = resultWriter;
43
       // this.results = serializer.GetResult(null);  . .GetXMLStreamWriter();
44
        results = new XmlTextWriter(new StreamWriter(fileName));
45
          
46
    }
47

    
48
    public abstract void writeResultFilePreamble(Processor processor, XdmNode catalog);
49

    
50

    
51

    
52
    public void writeResultFilePostamble() {
53
        try {
54
            this.results.WriteEndElement();
55
            this.results.Close();
56
        } catch (InvalidOperationException e) {
57
            throw new SystemException(e.Message);
58
        }
59
        if (writer != null) {
60
            try {
61
                writer.Close();
62
            } catch (EncoderFallbackException e) {
63
                throw new SystemException(e.Message);
64
            }
65
        }
66
    }
67

    
68
    public void startTestSetElement(XdmNode funcSetNode) {
69
        try {
70
            results.WriteStartElement("test-set");
71
            results.WriteAttributeString("name", funcSetNode.GetAttributeValue(new QName("name")));
72
        } catch (XmlException e) {
73
            throw new SystemException(e.Message);
74
        }
75
    }
76

    
77
    public void endElement() {
78
        try {
79
            results.WriteEndElement();
80
        } catch (Exception e) {
81
            throw new DynamicError(e.Message);
82
        }
83
    }
84

    
85
    public void writeTestcaseElement(String name, String result, String comment) {
86
        try {
87
            this.results.WriteStartElement("test-case");
88
            this.results.WriteAttributeString("name", name);
89
            this.results.WriteAttributeString("result", result);
90
            if (comment != null) {
91
                this.results.WriteAttributeString("comment", comment);
92
            }
93
            this.results.WriteEndElement();
94
        } catch (Exception e) {
95
            throw new DynamicError(e.Message);
96
        }
97
    }
98

    
99
    public string getDate() {
100
        return DateTime.Now.ToString();
101
    }
102
    }
103
}
(7-7/19)