summaryrefslogtreecommitdiffstats
path: root/src/goqtestlib/result_test.go
blob: 1cc80ada4a5ed4c0f75e810b2fa94edbde7f9ab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
package goqtestlib

import (
	"encoding/xml"
	"testing"
)

func TestXMLSchema(t *testing.T) {
	rawXML := `<?xml version="1.0" encoding="UTF-8"?>
<TestCase name="tst_QIODevice">
<Environment>
    <QtVersion>5.6.0</QtVersion>
    <QtBuild>Qt 5.6.0 (x86_64&#x002D;little_endian&#x002D;lp64 shared (dynamic) debug build; by GCC 4.9.2)</QtBuild>
    <QTestVersion>5.6.0</QTestVersion>
</Environment>
<TestFunction name="initTestCase">
<Incident type="pass" file="" line="0" />
    <Duration msecs="0.274962"/>
</TestFunction>
<TestFunction name="getSetCheck">
<Message type="qwarn" file="" line="0">
    <Description><![CDATA[QIODevice::seek (QTcpSocket): Cannot call seek on a sequential device]]></Description>
    </Message>
<Incident type="pass" file="" line="0" />
    <Duration msecs="0.115120"/>
</TestFunction>
<TestFunction name="readLine2">
<Incident type="pass" file="" line="0">
    <DataTag><![CDATA[1024 - 4]]></DataTag>
</Incident>
<Incident type="pass" file="" line="0">
    <DataTag><![CDATA[1024 - 3]]></DataTag>
</Incident>
<BenchmarkResult metric="InstructionReads" tag="" value="19838" iterations="1" />
</TestFunction>
<Duration msecs="760.801970"/>
</TestCase>`

	actual := &ParsedTestResult{}
	err := xml.Unmarshal([]byte(rawXML), &actual)
	if err != nil {
		t.Errorf("Error decoding XML: %s", err)
		t.FailNow()
	}

	if actual.Name != "tst_QIODevice" {
		t.Errorf("Invalid name attribute decoding. Got %s", actual.Name)
	}

	if actual.Env.QtVersion != "5.6.0" {
		t.Errorf("Error decoding Qt version from environment. Got %s", actual.Env.QtVersion)
	}

	if actual.Duration.Msecs != 760.801970 {
		t.Errorf("Error decoding Test Duration. Got %f", actual.Duration.Msecs)
	}

	if len(actual.Functions) != 3 {
		t.Errorf("Incorrect number of parsed test functions. Got %v", len(actual.Functions))
		t.FailNow()
	}

	function := actual.Functions[0]

	if function.Name != "initTestCase" {
		t.Errorf("Incorrectly parsed test function name for first test function. Got %v", function.Name)
	}

	if len(function.Incidents) != 1 {
		t.Errorf("Incorrectly parsed incidents for first test function. Parsed %v incidents", len(function.Incidents))
		t.FailNow()
	}

	if function.Duration.Msecs != 0.274962 {
		t.Errorf("Wrong duration %v", function.Duration.Msecs)
	}

	incident := function.Incidents[0]

	if incident.Type != "pass" {
		t.Errorf("Incorrectly parsed type for incident. Got %v", incident.Type)
	}

	if incident.File != "" {
		t.Errorf("Incorrectly parsed file name for incident. Got %v", incident.File)
	}

	if incident.Line != 0 {
		t.Errorf("Incorrectly parsed line number for incident. Got %v", incident.Line)
	}

	function = actual.Functions[1]

	if len(function.Messages) != 1 {
		t.Errorf("Incorrectly parsed number of messages incident. Got %v", len(function.Messages))
	}

	if function.Duration.Msecs != 0.115120 {
		t.Errorf("Wrong duration %v", function.Duration.Msecs)
	}

	message := function.Messages[0]

	if message.Type != "qwarn" {
		t.Errorf("Incorrectly parsed message type. Got %v", len(message.Type))
	}

	if message.Description != "QIODevice::seek (QTcpSocket): Cannot call seek on a sequential device" {
		t.Errorf("Incorrectly parsed message description. Got %v", message.Description)
	}

	function = actual.Functions[2]

	if len(function.Incidents) != 2 {
		t.Errorf("Incorrectly parsed incidents for third test function. Parsed %v incidents", len(function.Incidents))
		t.FailNow()
	}

	if function.Duration.Msecs != 0.0 {
		t.Errorf("Wrong duration %v", function.Duration.Msecs)
	}

	incident = function.Incidents[0]
	if incident.Type != "pass" {
		t.Errorf("Incorrectly parsed incident type. Got %v", incident.Type)
	}

	if incident.DataTag != "1024 - 4" {
		t.Errorf("Incorrectly parsed incident data tag. Got %v", incident.Type)
	}

	incident = function.Incidents[1]
	if incident.DataTag != "1024 - 3" {
		t.Errorf("Incorrectly parsed incident data tag. Got %v", incident.Type)
	}

	if len(function.BenchmarkResults) != 1 {
		t.Fatalf("Incorrectly parsed number of benchmark results. Expected 1 got %v", len(function.BenchmarkResults))
	}

	result := function.BenchmarkResults[0]
	if result.Metric != "InstructionReads" {
		t.Errorf("Incorrectly parsed benchmark metric %s", result.Metric)
	}

	if result.Value != 19838 {
		t.Errorf("Incorrectly parsed benchmark value %v", result.Value)
	}

	if result.Iterations != 1 {
		t.Errorf("Incorrectly parsed benchmark iteration count %v", result.Iterations)
	}
}