674
|
1 |
#
|
|
2 |
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
# Unit tests for the filter_interface module
|
|
17 |
|
|
18 |
import unittest
|
|
19 |
import filter_interface
|
|
20 |
import sys
|
|
21 |
|
|
22 |
# No point testing the Filter interface - it's fully abstract
|
|
23 |
|
|
24 |
class TestFilterInterface(unittest.TestCase):
|
|
25 |
def testSAXFilter(self):
|
|
26 |
# Areas for improvement:
|
|
27 |
# - Test non-well formed XML
|
|
28 |
# - Test all error cases (error, fatalError, warning)
|
|
29 |
class testFilter(filter_interface.FilterSAX):
|
|
30 |
def __init__(self):
|
|
31 |
super(testFilter,self).__init__()
|
|
32 |
self.failed = False
|
|
33 |
self.seendoc = False
|
|
34 |
self.startcount = 2
|
|
35 |
self.endcount = 2
|
|
36 |
self.charcount = 14
|
|
37 |
|
|
38 |
def startDocument(self):
|
|
39 |
if self.seendoc:
|
|
40 |
self.failed = True
|
|
41 |
sys.stdout.write('FAIL: Nested document elements')
|
|
42 |
self.seendoc = True
|
|
43 |
|
|
44 |
def startElement(self, name, attributes):
|
|
45 |
self.startcount -= 1
|
|
46 |
|
|
47 |
if self.startcount < 0:
|
|
48 |
self.failed = True
|
|
49 |
# Report the number of excessive start elements
|
|
50 |
sys.stdout.write('FAIL: Seen {0} too many start elements'.format(0-self.startcount))
|
|
51 |
|
|
52 |
def endElement(self, name):
|
|
53 |
self.endcount -= 1
|
|
54 |
|
|
55 |
if self.endcount < 0:
|
|
56 |
self.failed = True
|
|
57 |
# Report the number of excessive end elements
|
|
58 |
sys.stdout.write('FAIL: Seen {0} too many end elements'.format(0-self.endcount))
|
|
59 |
|
|
60 |
def endDocument(self):
|
|
61 |
if not self.seendoc:
|
|
62 |
self.failed = True
|
|
63 |
self.stdout.write('FAIL: Not in a document at doc end')
|
|
64 |
self.seendoc = False
|
|
65 |
|
|
66 |
def characters(self, char):
|
|
67 |
self.charcount -= len(char)
|
|
68 |
|
|
69 |
if self.charcount < 0:
|
|
70 |
self.failed = True
|
|
71 |
# Report the number of excessive characters
|
|
72 |
sys.stdout.write('FAIL: Seen {0} too many characters'.format(0-self.charcount))
|
|
73 |
|
|
74 |
def finish(self):
|
|
75 |
# if self.seendoc:
|
|
76 |
# self.failed = True
|
|
77 |
# sys.stdout.write('FAIL: Still in a doc at end')
|
|
78 |
if self.startcount > 0:
|
|
79 |
# Already tested to see if it's less than 0
|
|
80 |
self.failed = True
|
|
81 |
sys.stdout.write('FAIL: Not enough start elements')
|
|
82 |
if self.endcount > 0:
|
|
83 |
self.failed = True
|
|
84 |
sys.stdout.write('FAIL: Not enough end elements')
|
|
85 |
if self.charcount > 0:
|
|
86 |
self.failed = True
|
|
87 |
sys.stdout.write('FAIL: Not enough chars')
|
|
88 |
|
|
89 |
|
|
90 |
filter = testFilter()
|
|
91 |
filter.open([])
|
|
92 |
self.assertTrue(filter.write("<foo>FooText<bar>BarText</bar></foo>"))
|
|
93 |
filter.finish()
|
|
94 |
self.assertFalse(filter.failed)
|
|
95 |
|
|
96 |
def testPerRecipeFilter(self):
|
|
97 |
class testFilter(filter_interface.PerRecipeFilter):
|
|
98 |
recipes = [ { 'name':'recipe1', 'target':'target1', 'host':'host1', 'layer':'layer1', 'component':'component1', 'bldinf':'test1.inf', 'mmp':'test1.mmp', 'config':'winscw_test1', 'platform':'plat1', 'phase':'PHASE1', 'source':'source1', 'prereqs':'prereqs1', 'text':'\nTest text 1\n\n'},
|
|
99 |
{ 'name':'recipe2', 'target':'target2', 'host':'host2', 'layer':'layer2', 'component':'component2', 'bldinf':'test2.inf', 'mmp':'test2.mmp', 'config':'winscw_test2', 'platform':'', 'phase':'PHASE2', 'source':'', 'prereqs':'', 'text':'\nTest text 2\n\n'} ]
|
|
100 |
|
|
101 |
def __init__(self):
|
|
102 |
super(testFilter,self).__init__()
|
|
103 |
self.failed = False
|
|
104 |
|
|
105 |
def HandleRecipe(self):
|
|
106 |
testRecipe = self.recipes[0]
|
|
107 |
self.recipes = self.recipes[1:]
|
|
108 |
|
|
109 |
for key in testRecipe.keys():
|
|
110 |
if not self.__dict__.has_key(key):
|
|
111 |
self.failed = True
|
|
112 |
sys.stdout.write('FAIL: self.{0} not set\n'.format(key))
|
|
113 |
elif self.__dict__[key] != testRecipe[key]:
|
|
114 |
self.failed = True
|
|
115 |
sys.stdout.write('FAIL: {0} != {1}\n'.format(repr(self.__dict__[key]),repr(testRecipe[key])))
|
|
116 |
|
|
117 |
filter = testFilter()
|
|
118 |
filter.open([])
|
|
119 |
self.assertTrue(filter.write('''<?xml version="1.0" encoding="ISO-8859-1" ?>
|
|
120 |
<buildlog sbs_version="99.99.9 [ISODATE symbian build system CHANGESET]" xmlns="http://symbian.com/xml/build/log" xmlns:progress="http://symbian.com/xml/build/log/progress" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symbian.com/xml/build/log http://symbian.com/xml/build/log/1_0.xsd">
|
|
121 |
<info>sbs: version 99.99.9 [ISODATE symbian build system CHANGESET]
|
|
122 |
</info>
|
|
123 |
<progress:discovery object_type='bld.inf references' count='1' />
|
|
124 |
<whatlog bldinf='test.inf' mmp='' config=''>
|
|
125 |
<export destination='test' source='test2'/>
|
|
126 |
</whatlog>
|
|
127 |
<recipe name='recipe1' target='target1' host='host1' layer='layer1' component='component1' bldinf='test1.inf' mmp='test1.mmp' config='winscw_test1' platform='plat1' phase='PHASE1' source='source1' prereqs='prereqs1'>
|
|
128 |
<![CDATA[Test text 1]]><time start='1234567890.01234' elapsed='1.234' />
|
|
129 |
<status exit='ok' attempt='1' flags='FLAGS1' />
|
|
130 |
</recipe>
|
|
131 |
<recipe name='recipe2' target='target2' host='host2' layer='layer2' component='component2' bldinf='test2.inf' mmp='test2.mmp' config='winscw_test2' platform='' phase='PHASE2' source='' prereqs=''>
|
|
132 |
<![CDATA[Test text 2]]><time start='0123456789.12340' elapsed='2.345' />
|
|
133 |
<status exit='failed' attempt='2' flags='FLAGS2' />
|
|
134 |
</recipe>
|
|
135 |
</buildlog>
|
|
136 |
'''))
|
|
137 |
self.assertFalse(filter.failed)
|
|
138 |
|
|
139 |
# run all the tests
|
|
140 |
|
|
141 |
from raptor_tests import SmokeTest
|
|
142 |
|
|
143 |
def run():
|
|
144 |
t = SmokeTest()
|
|
145 |
t.id = "999"
|
|
146 |
t.name = "filter_interface_unit"
|
|
147 |
|
|
148 |
tests = unittest.makeSuite(TestFilterInterface)
|
|
149 |
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
150 |
|
|
151 |
if result.wasSuccessful():
|
|
152 |
t.result = SmokeTest.PASS
|
|
153 |
else:
|
|
154 |
t.result = SmokeTest.FAIL
|
|
155 |
|
|
156 |
return t
|