sbsv2/raptor/test/unit_suite/raptor_api_unit.py
changeset 18 de5b887c98f7
child 28 b8fa7dfeeaa1
equal deleted inserted replaced
14:eb060913c963 18:de5b887c98f7
       
     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 # raptor_api_unit module
       
    16 
       
    17 import generic_path
       
    18 import raptor
       
    19 import raptor_api
       
    20 import unittest
       
    21 
       
    22 class TestRaptorApi(unittest.TestCase):
       
    23 			
       
    24 	def testContext(self):
       
    25 		api = raptor_api.Context()
       
    26 		
       
    27 	def testContextInitialiser(self):
       
    28 		r = raptor.Raptor()
       
    29 		api = raptor_api.Context(r)
       
    30 		
       
    31 	def testAliases(self):
       
    32 		r = raptor.Raptor()
       
    33 		r.cache.Load( generic_path.Join(r.home, "test", "config", "api.xml") )
       
    34 
       
    35 		api = raptor_api.Context(r)
       
    36 	
       
    37 		aliases = api.getaliases() # type == ""
       
    38 		self.failUnlessEqual(len(aliases), 4)
       
    39 		self.failUnlessEqual(set(["alias_A","alias_B","s1","s2"]),
       
    40 							 set(a.name for a in aliases))
       
    41 		
       
    42 		aliases = api.getaliases(raptor_api.ALL) # ignore type
       
    43 		self.failUnlessEqual(len(aliases), 6)
       
    44 		
       
    45 		aliases = api.getaliases("X") # type == "X"
       
    46 		self.failUnlessEqual(len(aliases), 1)
       
    47 		self.failUnlessEqual(aliases[0].name, "alias_D")
       
    48 		self.failUnlessEqual(aliases[0].meaning, "a.b.c.d")
       
    49 	
       
    50 	def testConfig(self):
       
    51 		r = raptor.Raptor()
       
    52 		r.cache.Load( generic_path.Join(r.home, "test", "config", "api.xml") )
       
    53 
       
    54 		api = raptor_api.Context(r)
       
    55 		
       
    56 		if r.filesystem == "unix":
       
    57 			path = "/home/raptor/foo/bar"
       
    58 		else:
       
    59 			path = "C:/home/raptor/foo/bar"
       
    60 			
       
    61 		config = api.getconfig("buildme")
       
    62 		self.failUnlessEqual(config.fullname, "buildme")
       
    63 		self.failUnlessEqual(config.outputpath, path)
       
    64 		
       
    65 		config = api.getconfig("buildme.foo")
       
    66 		self.failUnlessEqual(config.fullname, "buildme.foo")
       
    67 		self.failUnlessEqual(config.outputpath, path)
       
    68 		
       
    69 		config = api.getconfig("s1")
       
    70 		self.failUnlessEqual(config.fullname, "buildme.foo")
       
    71 		self.failUnlessEqual(config.outputpath, path)
       
    72 		
       
    73 		config = api.getconfig("s2.product_A")
       
    74 		self.failUnlessEqual(config.fullname, "buildme.foo.bar.product_A")
       
    75 		self.failUnlessEqual(config.outputpath, path)
       
    76 		
       
    77 	def testProducts(self):
       
    78 		r = raptor.Raptor()
       
    79 		r.cache.Load( generic_path.Join(r.home, "test", "config", "api.xml") )
       
    80 
       
    81 		api = raptor_api.Context(r)
       
    82 		
       
    83 		products = api.getproducts() # type == "product"
       
    84 		self.failUnlessEqual(len(products), 2)
       
    85 		self.failUnlessEqual(set(["product_A","product_C"]),
       
    86 							 set(p.name for p in products))
       
    87 		
       
    88 # run all the tests
       
    89 
       
    90 from raptor_tests import SmokeTest
       
    91 
       
    92 def run():
       
    93 	t = SmokeTest()
       
    94 	t.name = "raptor_api_unit"
       
    95 
       
    96 	tests = unittest.makeSuite(TestRaptorApi)
       
    97 	result = unittest.TextTestRunner(verbosity=2).run(tests)
       
    98 
       
    99 	if result.wasSuccessful():
       
   100 		t.result = SmokeTest.PASS
       
   101 	else:
       
   102 		t.result = SmokeTest.FAIL
       
   103 
       
   104 	return t