13
|
1 |
#
|
18
|
2 |
# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
13
|
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 |
# raptor_xml_unit module
|
|
16 |
# This module tests the identification and parsing of XML metadata files
|
|
17 |
#
|
|
18 |
|
|
19 |
import os
|
18
|
20 |
import generic_path
|
13
|
21 |
import raptor
|
|
22 |
import raptor_xml
|
|
23 |
import unittest
|
|
24 |
|
|
25 |
class TestRaptorXML(unittest.TestCase):
|
18
|
26 |
|
|
27 |
class Logger(object):
|
|
28 |
# Basic custom logger class to store errors (and only errors) for test checks
|
|
29 |
|
|
30 |
def __init__(self):
|
|
31 |
self.errors = []
|
|
32 |
|
|
33 |
def Error(self, format, *extras, **attributes):
|
|
34 |
self.errors.append(format % extras)
|
|
35 |
|
|
36 |
def Info(self, format, *extras, **attributes):
|
|
37 |
return
|
|
38 |
|
|
39 |
def InfoDiscovery(self, object_type, count):
|
|
40 |
return
|
|
41 |
|
|
42 |
def Clear(self):
|
|
43 |
del self.errors[:]
|
|
44 |
|
13
|
45 |
|
|
46 |
def setUp(self):
|
18
|
47 |
self.__logger = TestRaptorXML.Logger()
|
13
|
48 |
self.__nullSysDefRoot = generic_path.Path("smoke_suite/test_resources")
|
|
49 |
self.__sysDefRoot = generic_path.Join(os.environ[raptor.env],"test/smoke_suite/test_resources")
|
|
50 |
self.__sysDefFileRoot = generic_path.Join(os.environ[raptor.env], "test/metadata/system")
|
|
51 |
|
|
52 |
def testSystemDefinitionProcessing(self):
|
|
53 |
# Make formatting neater
|
|
54 |
print
|
|
55 |
expectedBldInfs = [generic_path.Join(self.__sysDefRoot, "simple/bld.inf"),\
|
|
56 |
generic_path.Join(self.__sysDefRoot, "basics/helloworld/Bld.inf")]
|
|
57 |
|
|
58 |
sysdefs = ["1.4.1", "1.3.1", "1.5.1"]
|
|
59 |
for sysdef in sysdefs:
|
|
60 |
systemModel = raptor_xml.SystemModel(self.__logger,
|
|
61 |
generic_path.Join(self.__sysDefFileRoot,
|
|
62 |
"system_definition_" + sysdef + ".xml"), self.__sysDefRoot)
|
|
63 |
self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
|
|
64 |
|
|
65 |
|
|
66 |
sourceroot = ""
|
|
67 |
if os.environ.has_key('SOURCEROOT'):
|
|
68 |
sourceroot = os.environ['SOURCEROOT']
|
|
69 |
os.environ['SOURCEROOT'] = self.__sysDefRoot.GetLocalString()
|
|
70 |
systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_2.0.0.xml"), self.__nullSysDefRoot)
|
|
71 |
self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
|
|
72 |
|
|
73 |
del os.environ["SOURCEROOT"]
|
|
74 |
systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_2.0.0.xml"), self.__sysDefRoot)
|
|
75 |
self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
|
|
76 |
|
|
77 |
os.environ["SOURCEROOT"] = 'i_am_not_a_valid_path_at_all'
|
|
78 |
systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_2.0.0.xml"), self.__sysDefRoot)
|
|
79 |
self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
|
|
80 |
|
|
81 |
|
|
82 |
del os.environ["SOURCEROOT"]
|
|
83 |
systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_3.0.0.xml"), self.__sysDefRoot)
|
|
84 |
self.__compareFileLists([], systemModel.GetAllComponents())
|
|
85 |
|
18
|
86 |
self.__logger.Clear()
|
13
|
87 |
systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_multi_layers.xml"), self.__sysDefRoot)
|
18
|
88 |
self.assertTrue(len(self.__logger.errors) == 0)
|
|
89 |
|
|
90 |
# Confirm components returned from layers are correct
|
13
|
91 |
|
|
92 |
expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple/bld.inf"),\
|
|
93 |
generic_path.Join(self.__sysDefRoot, "simple_dll/bld.inf"),\
|
|
94 |
generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\
|
|
95 |
generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf"),\
|
|
96 |
generic_path.Join(self.__sysDefRoot, "simple_implib/bld.inf"),\
|
|
97 |
generic_path.Join(self.__sysDefRoot, "simple_lib/bld.inf"),\
|
|
98 |
generic_path.Join(self.__sysDefRoot, "simple_stringtable/bld.inf"),\
|
18
|
99 |
generic_path.Join(self.__sysDefRoot, "simple_test/bld.inf"),\
|
|
100 |
generic_path.Join(self.__sysDefRoot, "simple_plugin/bld.inf")]
|
13
|
101 |
self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
|
|
102 |
|
|
103 |
expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\
|
|
104 |
generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf")]
|
|
105 |
self.__compareFileLists(expectedBldInfs, systemModel.GetLayerComponents("Second Layer"))
|
|
106 |
|
|
107 |
self.__compareFileLists([], systemModel.GetLayerComponents("Fifth Layer"))
|
|
108 |
|
|
109 |
self.__compareFileLists([], systemModel.GetLayerComponents("Sixth Layer"))
|
|
110 |
|
18
|
111 |
# Check that the overall "buildability" of layers is returned correctly
|
|
112 |
# Note that a layer is still buildable if some bld.infs in it are missing as long as at least 1 exists
|
|
113 |
# However, errors should always be generated for missing bld.infs when a layer is checked
|
|
114 |
|
|
115 |
self.assertTrue(systemModel.IsLayerBuildable("First Layer"))
|
|
116 |
self.assertFalse(systemModel.IsLayerBuildable("Sixth Layer"))
|
|
117 |
|
|
118 |
self.__logger.Clear()
|
|
119 |
self.assertTrue(systemModel.IsLayerBuildable("Seventh Layer"))
|
|
120 |
self.assertTrue(len(self.__logger.errors) == 1)
|
|
121 |
sbsHome = os.environ["SBS_HOME"]
|
|
122 |
sysDefPath = sbsHome + "/test/metadata/system/system_definition_multi_layers.xml"
|
|
123 |
sysDefPath = sysDefPath.replace("\\","/")
|
|
124 |
bldInfPath = sbsHome + "/test/smoke_suite/test_resources/does_not_existbld.inf"
|
|
125 |
bldInfPath = bldInfPath.replace("\\","/")
|
|
126 |
self.assertEquals(self.__logger.errors[0],
|
|
127 |
("System Definition layer \"Seventh Layer\" from system definition file \"%s\" refers to non existent bld.inf file %s" % (sysDefPath, bldInfPath)))
|
13
|
128 |
|
|
129 |
# Probably redundant, but return local environment (at least its dictionary) to pre-test state
|
|
130 |
os.environ["SOURCEROOT"] = sourceroot
|
|
131 |
|
|
132 |
def __compareFileLists (self, aListOne, aListTwo):
|
|
133 |
|
|
134 |
self.assertEquals(len(aListOne), len(aListTwo))
|
|
135 |
|
|
136 |
i = 0
|
|
137 |
while i < len(aListOne) :
|
|
138 |
self.assertEquals(aListOne[i].GetLocalString().lower(), aListTwo[i].GetLocalString().lower())
|
|
139 |
i = i + 1
|
|
140 |
|
|
141 |
# run all the tests
|
|
142 |
|
|
143 |
from raptor_tests import SmokeTest
|
|
144 |
|
|
145 |
def run():
|
|
146 |
t = SmokeTest()
|
|
147 |
t.id = "999"
|
|
148 |
t.name = "raptor_xml_unit"
|
|
149 |
|
|
150 |
tests = unittest.makeSuite(TestRaptorXML)
|
|
151 |
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
152 |
|
|
153 |
if result.wasSuccessful():
|
|
154 |
t.result = SmokeTest.PASS
|
|
155 |
else:
|
|
156 |
t.result = SmokeTest.FAIL
|
|
157 |
|
|
158 |
return t
|