sbsv2/raptor/test/unit_suite/raptor_xml_unit.py
changeset 18 de5b887c98f7
parent 13 c327db0664bb
child 28 b8fa7dfeeaa1
equal deleted inserted replaced
14:eb060913c963 18:de5b887c98f7
     1 #
     1 #
     2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 # Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 # All rights reserved.
     3 # All rights reserved.
     4 # This component and the accompanying materials are made available
     4 # This component and the accompanying materials are made available
     5 # under the terms of the License "Eclipse Public License v1.0"
     5 # under the terms of the License "Eclipse Public License v1.0"
     6 # which accompanies this distribution, and is available
     6 # which accompanies this distribution, and is available
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
    15 # raptor_xml_unit module
    15 # raptor_xml_unit module
    16 # This module tests the identification and parsing of XML metadata files
    16 # This module tests the identification and parsing of XML metadata files
    17 #
    17 #
    18 
    18 
    19 import os
    19 import os
       
    20 import generic_path
    20 import raptor
    21 import raptor
    21 import generic_path
       
    22 import raptor_xml
    22 import raptor_xml
    23 import unittest
    23 import unittest
    24 
    24 
    25 class TestRaptorXML(unittest.TestCase):
    25 class TestRaptorXML(unittest.TestCase):
       
    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 			
    26 	
    45 	
    27 	def setUp(self):
    46 	def setUp(self):
    28 		self.__logger = raptor.Raptor()
    47 		self.__logger = TestRaptorXML.Logger()
    29 		self.__nullSysDefRoot = generic_path.Path("smoke_suite/test_resources")
    48 		self.__nullSysDefRoot = generic_path.Path("smoke_suite/test_resources")
    30 		self.__sysDefRoot = generic_path.Join(os.environ[raptor.env],"test/smoke_suite/test_resources")
    49 		self.__sysDefRoot = generic_path.Join(os.environ[raptor.env],"test/smoke_suite/test_resources")
    31 		self.__sysDefFileRoot = generic_path.Join(os.environ[raptor.env], "test/metadata/system")
    50 		self.__sysDefFileRoot = generic_path.Join(os.environ[raptor.env], "test/metadata/system")
    32 		
    51 		
    33 	def testSystemDefinitionProcessing(self):
    52 	def testSystemDefinitionProcessing(self):
    62 				
    81 				
    63 		del os.environ["SOURCEROOT"]
    82 		del os.environ["SOURCEROOT"]
    64 		systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_3.0.0.xml"), self.__sysDefRoot)
    83 		systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_3.0.0.xml"), self.__sysDefRoot)
    65 		self.__compareFileLists([], systemModel.GetAllComponents())
    84 		self.__compareFileLists([], systemModel.GetAllComponents())
    66 				
    85 				
    67 		
    86 		self.__logger.Clear()
    68 		systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_multi_layers.xml"), self.__sysDefRoot)
    87 		systemModel = raptor_xml.SystemModel(self.__logger, generic_path.Join(self.__sysDefFileRoot, "system_definition_multi_layers.xml"), self.__sysDefRoot)
       
    88 		self.assertTrue(len(self.__logger.errors) == 0)
       
    89 
       
    90 		# Confirm components returned from layers are correct
    69 
    91 
    70 		expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple/bld.inf"),\
    92 		expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple/bld.inf"),\
    71 							generic_path.Join(self.__sysDefRoot, "simple_dll/bld.inf"),\
    93 							generic_path.Join(self.__sysDefRoot, "simple_dll/bld.inf"),\
    72 						    generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\
    94 						    generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\
    73 						    generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf"),\
    95 						    generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf"),\
    74 						    generic_path.Join(self.__sysDefRoot, "simple_implib/bld.inf"),\
    96 						    generic_path.Join(self.__sysDefRoot, "simple_implib/bld.inf"),\
    75 						    generic_path.Join(self.__sysDefRoot, "simple_lib/bld.inf"),\
    97 						    generic_path.Join(self.__sysDefRoot, "simple_lib/bld.inf"),\
    76 						    generic_path.Join(self.__sysDefRoot, "simple_stringtable/bld.inf"),\
    98 						    generic_path.Join(self.__sysDefRoot, "simple_stringtable/bld.inf"),\
    77 						    generic_path.Join(self.__sysDefRoot, "simple_test/bld.inf")]
    99 						    generic_path.Join(self.__sysDefRoot, "simple_test/bld.inf"),\
       
   100 						    generic_path.Join(self.__sysDefRoot, "simple_plugin/bld.inf")]
    78 		self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
   101 		self.__compareFileLists(expectedBldInfs, systemModel.GetAllComponents())
    79 	
   102 	
    80 		expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\
   103 		expectedBldInfs = [ generic_path.Join(self.__sysDefRoot, "simple_export/bld.inf"),\
    81 						    generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf")]
   104 						    generic_path.Join(self.__sysDefRoot, "simple_gui/Bld.inf")]
    82 		self.__compareFileLists(expectedBldInfs, systemModel.GetLayerComponents("Second Layer"))
   105 		self.__compareFileLists(expectedBldInfs, systemModel.GetLayerComponents("Second Layer"))
    83 
   106 
    84 		self.__compareFileLists([], systemModel.GetLayerComponents("Fifth Layer"))
   107 		self.__compareFileLists([], systemModel.GetLayerComponents("Fifth Layer"))
    85 				
   108 				
    86 		self.__compareFileLists([], systemModel.GetLayerComponents("Sixth Layer"))
   109 		self.__compareFileLists([], systemModel.GetLayerComponents("Sixth Layer"))
    87 		
   110 		
       
   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)))
    88 				
   128 				
    89 		# Probably redundant, but return local environment (at least its dictionary) to pre-test state
   129 		# Probably redundant, but return local environment (at least its dictionary) to pre-test state
    90 		os.environ["SOURCEROOT"] = sourceroot
   130 		os.environ["SOURCEROOT"] = sourceroot
    91 		
   131 		
    92 	def __compareFileLists (self, aListOne, aListTwo):
   132 	def __compareFileLists (self, aListOne, aListTwo):