buildframework/helium/tools/common/python/lib/test/test_parsers.py
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
child 180 e02a83d4c571
child 592 3215c239276a
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
     1 # -*- encoding: latin-1 -*-
       
     2 
       
     3 #============================================================================ 
       
     4 #Name        : test_parsers.py 
       
     5 #Part of     : Helium 
       
     6 
       
     7 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 #All rights reserved.
       
     9 #This component and the accompanying materials are made available
       
    10 #under the terms of the License "Eclipse Public License v1.0"
       
    11 #which accompanies this distribution, and is available
       
    12 #at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 #
       
    14 #Initial Contributors:
       
    15 #Nokia Corporation - initial contribution.
       
    16 #
       
    17 #Contributors:
       
    18 #
       
    19 #Description:
       
    20 #===============================================================================
       
    21 
       
    22 import os
       
    23 import sys
       
    24 import tempfile
       
    25 import mocker
       
    26 from path import path
       
    27 import StringIO
       
    28 
       
    29 import ats3.parsers
       
    30 import ats3.testconfigurator
       
    31 
       
    32 import logging
       
    33 logging.getLogger().setLevel(logging.ERROR)
       
    34 
       
    35 TSRC_DIR = None
       
    36 
       
    37 def setup_module():
       
    38     """Setup the test environment. The testing of the test parser script requires spesific
       
    39     structure to be available with bld.inf files (with the content written into those)."""
       
    40     global TSRC_DIR
       
    41     TSRC_DIR = path(tempfile.mkdtemp()).normpath()
       
    42     test_component = TSRC_DIR
       
    43     for path_parts in (("tsrc", "group"),
       
    44                        ("tsrc", "tc1", "group"),
       
    45                        ("tsrc", "tc1", "data"),
       
    46                        ("tsrc", "tc1", "dependent_1", "group"),
       
    47                        ("tsrc", "tc1", "dependent_2", "group"),
       
    48                        ("tsrc", "tc1", "subtest", "group"),
       
    49                        ("tsrc", "tc1", "subtest", "data"),
       
    50                        ("tsrc", "tc1", "subtest", "if_test", "group"),
       
    51                        ("tsrc", "tc2", "group"),
       
    52                        ("tsrc", "tc2", "data"),
       
    53                        ("tsrc", "tc3", "group"),
       
    54                        ("tsrc", "tc3", "data"),
       
    55                        ("tmp", "macros"),
       
    56                        ):
       
    57         filepath = path.joinpath(test_component, *path_parts).normpath()
       
    58         if not filepath.exists():
       
    59             os.makedirs(filepath)
       
    60     
       
    61         
       
    62     tsrc = open(path.joinpath(TSRC_DIR, "tsrc", "group", "bld.inf"), 'w')
       
    63     tsrc.write(
       
    64             r"""
       
    65 #include "../tc1/group/bld.inf"
       
    66 #include "../tc2/group/bld.inf"
       
    67 #include "../tc3/group/bld.inf" 
       
    68 
       
    69 PRJ_TESTMMPFILES
       
    70 
       
    71             """)
       
    72     tsrc.close()
       
    73     
       
    74     tc1 = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "group", "bld.inf"), 'w')
       
    75     tc1.write(
       
    76             r"""
       
    77 #include "../dependent_1/group/bld.inf"
       
    78 #include "../dependent_2/group/bld.inf"
       
    79 #include "../subtest/group/bld.inf"
       
    80 
       
    81 PRJ_TESTMMPFILES
       
    82 tc1.mmp
       
    83 
       
    84 PRJ_MMPFILES
       
    85 not_included.mmp
       
    86             """)
       
    87     tc1.close()
       
    88     
       
    89     tc1_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "group", "tc1.mmp"), 'w')
       
    90     tc1_mmp.write(
       
    91             r"""
       
    92 TARGET          tc1.dll
       
    93 TARGETTYPE      dll
       
    94 LIBRARY         stiftestinterface.lib
       
    95 LIBRARY         user.lib
       
    96             """)
       
    97     tc1_mmp.close()
       
    98     
       
    99     tc1_sub = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "subtest", "group", "bld.inf"), "w")
       
   100     tc1_sub.write(
       
   101             r"""
       
   102 PRJ_TESTMMPFILES
       
   103 sub_test.mmp    
       
   104 #ifndef RD_TEST1
       
   105 #include "../if_test/group/bld.inf"
       
   106 #endif
       
   107             """)
       
   108     tc1_sub.close()
       
   109     tc1_sub_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "subtest", "group", "sub_test.mmp"), 'w')
       
   110     tc1_sub_mmp.write(
       
   111             r"""
       
   112 TARGET          sub_test.dll
       
   113 TARGETTYPE      dll
       
   114 LIBRARY         stiftestinterface.lib
       
   115             """)
       
   116     tc1_sub_mmp.close()
       
   117 
       
   118     
       
   119     tc1_if = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "subtest", "if_test", "group", "bld.inf"), "w")
       
   120     tc1_if.write(
       
   121             r"""
       
   122 PRJ_TESTMMPFILES
       
   123 if_test.mmp
       
   124             """)
       
   125     tc1_if.close()
       
   126     tc1_if_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "subtest", "if_test", "group", "if_test.mmp"), 'w')
       
   127     tc1_if_mmp.write(
       
   128             r"""
       
   129 TARGET          tc1_if.dll
       
   130 TARGETTYPE      dll
       
   131 LIBRARY         stifunit.lib
       
   132             """)
       
   133     tc1_if_mmp.close()
       
   134 
       
   135     tc1_dep1 = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "dependent_1", "group", "bld.inf"), "w")
       
   136     tc1_dep1.write(
       
   137             r"""
       
   138 PRJ_TESTMMPFILES
       
   139 dependent_1.mmp
       
   140 onemore.mmp
       
   141             """)
       
   142     tc1_dep1.close()
       
   143 
       
   144     tc1_dep1_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "dependent_1", "group", "dependent_1.mmp"), 'w')
       
   145     tc1_dep1_mmp.write(
       
   146             r"""
       
   147 TARGET          dependent_1.dll
       
   148 TARGETTYPE      PLUGIN
       
   149             """)
       
   150     tc1_dep1_mmp.close()
       
   151         
       
   152     tc1_dep2 = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "dependent_2", "group", "bld.inf"), "w")
       
   153     tc1_dep2.write(
       
   154             r"""
       
   155 PRJ_TESTMMPFILES
       
   156 dependent_2.mmp
       
   157             """)
       
   158     tc1_dep2.close()
       
   159     
       
   160     tc1_dep2_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "dependent_2", "group", "dependent_2.mmp"), 'w')
       
   161     tc1_dep2_mmp.write(
       
   162             r"""
       
   163 TARGET          dependent_2.dll
       
   164 TARGETTYPE      PLUGIN
       
   165             """)
       
   166     tc1_dep2_mmp.close()
       
   167     
       
   168     tc1_pkg = open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "group", "tc1.pkg"), 'w')
       
   169     tc1_pkg.write(
       
   170                   r"""
       
   171 ;Language - standard language definitions
       
   172 &EN
       
   173 
       
   174 ; standard SIS file header
       
   175 #{"BTEngTestApp"},(0x04DA27D5),1,0,0
       
   176 
       
   177 ;Supports Series 60 v 3.0
       
   178 (0x101F7961), 0, 0, 0, {"Series60ProductID"}
       
   179 
       
   180 ;Localized Vendor Name
       
   181 %{"BTEngTestApp"}
       
   182 
       
   183 ;Unique Vendor name
       
   184 :"Nokia"
       
   185 
       
   186 ; Files to copy
       
   187 "..\data\file1.dll"-"c:\sys\bin\file1.dll"
       
   188 "..\data\file1.txt"-"e:\sys\bin\file1.txt" , FF   ; FF stands for Normal file
       
   189 "..\data\file2.mp3"-"e:\sys\bin\file2.mp3"
       
   190 "..\data\TestFramework.ini"-"c:\sys\bin\TestFramework.ini"
       
   191 ;"..\xyz\TestFramework.ini"-"!:\sys\bin\TestFramework.ini" (commented line)
       
   192 "../data/temp.ini"-"!:/sys/bin/temp.ini" , FF ; "something here"
       
   193 "..\data\tc1.cfg"-"e:\sys\bin\tc1.cfg"
       
   194 "..\data\tc1.sisx"-"e:\sys\bin\tc1.sisx"
       
   195 "..\data\DUMP.xyz"-"e:\sys\bin\DUMP.xyz"
       
   196 
       
   197             
       
   198         """.replace('\\', os.sep))
       
   199     tc1_pkg.close()
       
   200     
       
   201     open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "data", "file1.dll"), 'w').close()
       
   202     open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "data", "file1.txt"), 'w').close()
       
   203     open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "data", "file2.mp3"), 'w').close()
       
   204     open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "data", "TestFramework.ini"), 'w').close()
       
   205     open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "data", "temp.ini"), 'w').close()
       
   206     open(path.joinpath(TSRC_DIR, "tsrc", "tc1", "data", "DUMP.xyz"), 'w').close()
       
   207     
       
   208     tc2 = open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "group", "bld.inf"), "w")
       
   209     tc2.write(
       
   210             r"""
       
   211 PRJ_TESTMMPFILES
       
   212 tc2.mmp
       
   213             """)
       
   214     tc2.close()
       
   215     tc2_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "group", "tc2.mmp"), 'w')
       
   216     tc2_mmp.write(
       
   217             r"""
       
   218 TARGET          tc2.dll
       
   219 TARGETTYPE      dll
       
   220 LIBRARY         EUnit.lib
       
   221             """)
       
   222     tc2_mmp.close()
       
   223     
       
   224     tc2_pkg = open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "group", "tc2.pkg"), 'w')
       
   225     tc2_pkg.write(
       
   226                   r"""
       
   227 ;Language - standard language definitions
       
   228 &EN
       
   229 
       
   230 ; standard SIS file header
       
   231 #{"BTEngTestApp"},(0x04DA27D5),1,0,0
       
   232 
       
   233 ;Supports Series 60 v 3.0
       
   234 (0x101F7961), 0, 0, 0, {"Series60ProductID"}
       
   235 
       
   236 ;Localized Vendor Name
       
   237 %{"BTEngTestApp"}
       
   238 
       
   239 ;Unique Vendor name
       
   240 :"Nokia"
       
   241 
       
   242 ; Files to copy
       
   243 "..\data\file1.dll"-"c:\sys\bin\file1.dll"
       
   244 "..\data\file1.txt"-"e:\sys\bin\file1.txt"
       
   245 "..\data\file2.mp3"-"e:\sys\bin\file2.mp3"
       
   246 "..\data\TestFramework.ini"-"!:\sys\bin\TestFramework.ini" , FF   ; FF stands for Normal file
       
   247 "..\data\tc2.cfg"-"!:\sys\bin\tc2.cfg"
       
   248         """.replace('\\', os.sep))
       
   249     tc2_pkg.close()
       
   250     
       
   251     open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "data", "file1.dll"), 'w').close()
       
   252     open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "data", "file1.txt"), 'w').close()
       
   253     open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "data", "file2.mp3"), 'w').close()
       
   254     open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "data", "TestFramework.ini"), 'w').close()
       
   255     open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "data", "tc2.cfg"), 'w').close()
       
   256 
       
   257     
       
   258     tc3 = open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "group", "bld.inf"), "w")
       
   259     tc3.write(
       
   260             r"""
       
   261 PRJ_TESTMMPFILES
       
   262 tc3.mmp
       
   263             """)
       
   264     tc3.close()
       
   265     tc3_mmp = open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "group", "tc3.mmp"), 'w')
       
   266     tc3_mmp.write(
       
   267             r"""
       
   268 TARGET          tc3.dll
       
   269 TARGETTYPE      dll
       
   270 LIBRARY         EUnit.lib
       
   271             """)
       
   272     tc3_mmp.close()
       
   273     
       
   274     tc3_pkg = open(path.joinpath(TSRC_DIR, "tsrc", "tc2", "group", "tc2.pkg"), 'w')
       
   275     tc3_pkg.write(
       
   276                   r"""
       
   277 ;Language - standard language definitions
       
   278 &EN
       
   279 
       
   280 ; standard SIS file header
       
   281 #{"BTEngTestApp"},(0x04DA27D5),1,0,0
       
   282 
       
   283 ;Supports Series 60 v 3.0
       
   284 (0x101F7961), 0, 0, 0, {"Series60ProductID"}
       
   285 
       
   286 ;Localized Vendor Name
       
   287 %{"BTEngTestApp"}
       
   288 
       
   289 ;Unique Vendor name
       
   290 :"Nokia"
       
   291 
       
   292 ; Files to copy
       
   293 "..\data\file1.dll"-"c:\sys\bin\file1.dll"
       
   294 "..\data\file1.txt"-"e:\sys\bin\file1.txt"
       
   295 "..\data\file2.mp3"-"e:\sys\bin\file2.mp3" , FF   ; FF stands for Normal file
       
   296 "..\data\TestFramework.ini"-"!:\sys\bin\TestFramework.ini"
       
   297 "..\data\temp.ini"-"!:\sys\bin\temp.ini"
       
   298 "..\data\tc2.cfg"-"!:\sys\bin\tc2.cfg"
       
   299         """.replace('\\', os.sep))
       
   300     tc3_pkg.close()
       
   301     
       
   302     open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "data", "file1.dll"), 'w').close()
       
   303     open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "data", "file1.txt"), 'w').close()
       
   304     open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "data", "file2.mp3"), 'w').close()
       
   305     open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "data", "TestFramework.ini"), 'w').close()
       
   306     open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "data", "temp.ini"), 'w').close()
       
   307     open(path.joinpath(TSRC_DIR, "tsrc", "tc3", "data", "tc2.cfg"), 'w').close()
       
   308     
       
   309     macros = open(path.joinpath(TSRC_DIR, "tmp", "macros", "bldcodeline.hrh"), 'w')
       
   310     macros.write(
       
   311               r"""
       
   312 #ifndef __BLDCODELINE_HRH
       
   313 #define __BLDCODELINE_HRH
       
   314 
       
   315 /** #RD_TEST */
       
   316 #define RD_TEST1
       
   317 
       
   318 /** #RD_TEST2 */
       
   319 #define RD_TEST2
       
   320 
       
   321 /** #RD_TEST3 */
       
   322 #define RD_TEST3
       
   323 
       
   324 #endif  // __BLDCODELINE_HRH
       
   325 
       
   326     """)
       
   327     macros.close()
       
   328 
       
   329     
       
   330 def teardown_module():
       
   331     """ Cleanup environment after testing. """    
       
   332     def __init__():
       
   333         TSRC_DIR.rmtree()
       
   334         
       
   335         
       
   336 #        list_of_paths = []
       
   337 #        list_of_paths = path.walk(TSRC_DIR)
       
   338 #        for file in list_of_paths[2]:
       
   339 #            continue
       
   340 #        for dir in list_of_paths[1]:
       
   341 #            continue
       
   342         
       
   343 
       
   344 class TestPkgFileParser(mocker.MockerTestCase):
       
   345     """Testing Package file parser"""
       
   346     def __init__(self, methodName="runTest"):
       
   347         mocker.MockerTestCase.__init__(self, methodName)
       
   348 
       
   349     def setUp(self):
       
   350         """Setup for PkgFile parser"""
       
   351         self.pkg_file_path1 = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "tc1", "group"))
       
   352         self.pkg_file_path2 = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "tc2", "group"))
       
   353         self.pkg_file_path3 = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "tc3", "group"))
       
   354         self.tcp = ats3.parsers.PkgFileParser("tc1.pkg")        
       
   355         
       
   356         self.data_files = [
       
   357             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "file1.dll").normpath(), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.dll").normpath(), "testmodule", 'tc1.pkg'),
       
   358             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "file1.txt").normpath(), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file1.txt").normpath(), "data", 'tc1.pkg'),
       
   359             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "file2.mp3").normpath(), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "file2.mp3").normpath(), "data", 'tc1.pkg'),
       
   360             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "TestFramework.ini").normpath(), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "TestFramework.ini").normpath(), "engine_ini", 'tc1.pkg'),
       
   361             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "temp.ini").normpath(), path(r"c:" + os.sep + "sys" + os.sep + "bin" + os.sep + "temp.ini").normpath(), "engine_ini", 'tc1.pkg'),
       
   362             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "tc1.cfg").normpath(), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "tc1.cfg").normpath(), "conf", 'tc1.pkg'),
       
   363             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "tc1.sisx").normpath(), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "tc1.sisx").normpath(), "", 'tc1.pkg'),
       
   364             (path(TSRC_DIR+r"" + os.sep + "tsrc" + os.sep + "tc1" + os.sep + "data" + os.sep + "DUMP.xyz").normpath(), path(r"e:" + os.sep + "sys" + os.sep + "bin" + os.sep + "DUMP.xyz").normpath(), "data", 'tc1.pkg'),
       
   365             ]
       
   366 
       
   367     def test_get_pkg_files(self):
       
   368         """Test if pkg files are returned from a specified location"""
       
   369         assert self.tcp.get_pkg_files(self.pkg_file_path1, False) == ["tc1.pkg"]
       
   370 
       
   371 
       
   372 
       
   373     def test_parser_receives_path(self):      
       
   374         """Test if None is returned when a path to PKG file is incorrect"""
       
   375         assert self.tcp.get_data_files("string") == []
       
   376             
       
   377     def test_data_files_creation_without_exclude(self):
       
   378         """ Tests if PKG file parser creates data files list as expected without exclude"""
       
   379         assert self.tcp.get_data_files(self.pkg_file_path1, "d:") == self.data_files
       
   380         
       
   381     def test_data_files_creation_with_exclude(self):
       
   382         """ Tests if PKG file parser creates data files list as expected with exclude"""
       
   383         self.data_files.pop()
       
   384         assert self.tcp.get_data_files(self.pkg_file_path1, "d:", "\.xyz") == self.data_files
       
   385 
       
   386     def test_data_files_creation_without_drive_with_exclude(self):
       
   387         """ Tests if PKG file parser creates data files list as expected without drive with exclude"""
       
   388         
       
   389         self.data_files.pop()
       
   390         assert self.tcp.get_data_files(self.pkg_file_path1, "", "\.xyz") == self.data_files
       
   391 
       
   392     def test_data_files_creation_without_drive_without_exclude(self):
       
   393         """ Tests if PKG file parser creates data files list as expected without drive without exclude"""
       
   394         
       
   395         assert self.tcp.get_data_files(self.pkg_file_path1, "") == self.data_files
       
   396             
       
   397 
       
   398 class TestCppParser(mocker.MockerTestCase):
       
   399     """Testing CPP parser"""
       
   400     def __init__(self, methodName="runTest"):
       
   401         mocker.MockerTestCase.__init__(self, methodName)
       
   402 
       
   403     def setUp(self):
       
   404         self.bld_path = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "group"))
       
   405         self.bld_path_comp1 = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "tc1", "group"))
       
   406         self.tcp = ats3.parsers.CppParser()
       
   407         upper_bld_path = os.path.dirname(self.bld_path)
       
   408         self.bldDir = r'C:\DOCUME~1\wbernard\LOCALS~1\Temp\tmpbrgo0s\tsrc'
       
   409 
       
   410         
       
   411         self.dependent_paths_dictionary = {(os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/subtest/if_test/group"))): {'content': {(os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/subtest/if_test/group"))): {'pkg_files': [], 'mmp_files': ['if_test.mmp'], 'harness': 'STIFUNIT', 'type': ''}}},
       
   412                                             (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc2//group"))): {'content': {(os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc2/group"))): {'pkg_files': ['tc2.pkg'], 'mmp_files': ['tc2.mmp'], 'harness': 'EUNIT', 'type': 'executable'}}}, 
       
   413                                             (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc3/group"))): {'content': {(os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc3/group"))): {'pkg_files':[], 'mmp_files': ['tc3.mmp'], 'harness': 'EUNIT', 'type': 'executable'}}},
       
   414                                             (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group"))): {'content': {(os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/subtest/group"))): {'pkg_files': [], 'mmp_files': ['sub_test.mmp'], 'harness': 'STIF', 'type': 'executable'}, 
       
   415                                                                                                                                 (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/dependent_1/group"))): {'pkg_files': [], 'mmp_files': ['dependent_1.mmp', 'onemore.mmp'], 'harness': "", 'type':''}, 
       
   416                                                                                                                                 (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/dependent_2/group"))): {'pkg_files': [], 'mmp_files': ['dependent_2.mmp'], 'harness': "", 'type': 'dependent'}, 
       
   417                                                                                                                                 (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group"))): {'pkg_files': ['tc1.pkg'], 'mmp_files': ['tc1.mmp'],'harness': 'STIF', 'type': 'executable'}}}} 
       
   418         
       
   419         self.extended_path_list = [(os.path.normpath(upper_bld_path), upper_bld_path),
       
   420                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group")), upper_bld_path),
       
   421                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../dependent_1/group")), os.path.normpath(os.path.join(upper_bld_path, "../tc1/group"))),
       
   422                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../dependent_2/group")), os.path.normpath(os.path.join(upper_bld_path, "../tc1/group"))),
       
   423                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../subtest/group")), os.path.normpath(os.path.join(upper_bld_path, "../tc1/group"))),
       
   424                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../subtest/group/../if_test/group")), os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group"))),
       
   425                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc2/group")), upper_bld_path),
       
   426                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc3/group")), upper_bld_path),
       
   427                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/group/group")), upper_bld_path),
       
   428                            ]
       
   429         self.path_list = [os.path.normpath(os.path.join(upper_bld_path, "group")),
       
   430                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group")),
       
   431                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../dependent_1/group")),
       
   432                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../dependent_2/group")),
       
   433                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../subtest/group")),
       
   434                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../subtest/group/../if_test/group")),
       
   435                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc2/group")),
       
   436                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc3/group")),
       
   437                            ]
       
   438         self.path_list_without_undefined = [os.path.normpath(upper_bld_path),
       
   439                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group")),
       
   440                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_1/group")),
       
   441                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_2/group")),
       
   442                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group")),
       
   443                            os.path.normpath(os.path.join(upper_bld_path, "../tc2/group")),
       
   444                            os.path.normpath(os.path.join(upper_bld_path, "../tc3/group")),
       
   445                            ]
       
   446         self.cpp_output = ['# 1 "bld.inf"', 
       
   447                            '# 1 "../tc1/group/bld.inf" 1', 
       
   448                            '# 1 "../tc1/group/../dependent_1/group/bld.inf" 1', 
       
   449                            '# 4 "../tc1/group/bld.inf" 2', 
       
   450                            '# 1 "../tc1/group/../dependent_2/group/bld.inf" 1', 
       
   451                            '# 5 "../tc1/group/bld.inf" 2', 
       
   452                            '# 1 "../tc1/group/../subtest/group/bld.inf" 1', 
       
   453                            '# 1 "../tc1/group/../subtest/group/../if_test/group/bld.inf" 1', 
       
   454                            '# 4 "../tc1/group/../subtest/group/bld.inf" 2', 
       
   455                            '# 6 "../tc1/group/bld.inf" 2', 
       
   456                            '# 3 "bld.inf" 2', 
       
   457                            '# 1 "../tc2/group/bld.inf" 1', 
       
   458                            '# 4 "bld.inf" 2', 
       
   459                            '# 1 "../tc3/group/bld.inf" 1', 
       
   460                            '# 5 "bld.inf" 2']
       
   461         
       
   462         
       
   463          
       
   464     def test_pathlist_output(self):
       
   465         """Test get_cpp_output-method using "n" -parameter"""
       
   466         assert self.path_list.sort() == self.tcp.get_cpp_output(self.bld_path, "n").sort()
       
   467         
       
   468     def test_extended_pathlist_output(self):
       
   469         """Test get_cpp_output-method using "e" -parameter"""
       
   470         assert self.extended_path_list.sort() == self.tcp.get_cpp_output(self.bld_path, "e").sort()
       
   471 
       
   472     def test_dictionary_pathlist_output(self):
       
   473         """Test get_cpp_output-method using "d" -parameter (dependent paths)"""
       
   474         output = """# 1 "bld.inf"
       
   475 
       
   476 # 1 "../tc1/group/bld.inf" 1
       
   477 
       
   478 # 1 "../tc1/group/../dependent_1/group/bld.inf" 1
       
   479 
       
   480 PRJ_TESTMMPFILES
       
   481 dependent_1.mmp
       
   482 onemore.mmp
       
   483             
       
   484 # 2 "../tc1/group/bld.inf" 2
       
   485 
       
   486 # 1 "../tc1/group/../dependent_2/group/bld.inf" 1
       
   487 
       
   488 PRJ_TESTMMPFILES
       
   489 dependent_2.mmp
       
   490             
       
   491 # 3 "../tc1/group/bld.inf" 2
       
   492 
       
   493 # 1 "../tc1/group/../subtest/group/bld.inf" 1
       
   494 
       
   495 PRJ_TESTMMPFILES
       
   496 sub_test.mmp    
       
   497 
       
   498 # 1 "../tc1/group/../subtest/group/../if_test/group/bld.inf" 1
       
   499 
       
   500 PRJ_TESTMMPFILES
       
   501 if_test.mmp
       
   502             
       
   503 # 5 "../tc1/group/../subtest/group/bld.inf" 2
       
   504 
       
   505 
       
   506             
       
   507 # 4 "../tc1/group/bld.inf" 2
       
   508 
       
   509 
       
   510 PRJ_TESTMMPFILES
       
   511 tc1.mmp
       
   512 
       
   513 PRJ_MMPFILES
       
   514 not_included.mmp
       
   515             
       
   516 # 2 "bld.inf" 2
       
   517 
       
   518 # 1 "../tc2/group/bld.inf" 1
       
   519 
       
   520 PRJ_TESTMMPFILES
       
   521 tc2.mmp
       
   522             
       
   523 # 3 "bld.inf" 2
       
   524 
       
   525 # 1 "../tc3/group/bld.inf" 1
       
   526 
       
   527 PRJ_TESTMMPFILES
       
   528 tc3.mmp
       
   529             
       
   530 # 4 "bld.inf" 2
       
   531 
       
   532 
       
   533 PRJ_TESTMMPFILES
       
   534 
       
   535             
       
   536 """
       
   537         
       
   538         result = self.tcp.create_dependency_dictionary(StringIO.StringIO(output), self.bld_path)
       
   539         print "INPUT :", self.dependent_paths_dictionary
       
   540         print "OUTPUT:", result 
       
   541 
       
   542         assert self.dependent_paths_dictionary == result
       
   543         
       
   544     def test_conditional_cpp_parsing(self):
       
   545         """Test functionality of cpp parser when removing conditionals"""
       
   546         assert self.path_list_without_undefined.sort() == self.tcp.get_cpp_output(bld_path=self.bld_path, output_parameter="n", imacros=os.path.normpath(os.path.join(TSRC_DIR, "tmp", "macros", "bldcodeline.hrh"))).sort()
       
   547 
       
   548 class TestBldFileParser(mocker.MockerTestCase):
       
   549     """Testing BldFileParser Class"""
       
   550     
       
   551     def __init__(self, methodName="runTest"):
       
   552         mocker.MockerTestCase.__init__(self, methodName)
       
   553     
       
   554     def setUp(self):
       
   555         """Setup for BldFile parser"""
       
   556 
       
   557         self.bld_path = path.joinpath(TSRC_DIR, "tsrc", "group", "bld.inf").normpath()
       
   558         upper_bld_path = self.bld_path.dirname()
       
   559         self.tcp = ats3.parsers.BldFileParser()
       
   560         
       
   561         self.test_mmp_files = [
       
   562                                ['tc1.mmp'], 
       
   563                                ['dependent_1.mmp', 'onemore.mmp'], 
       
   564                                ['dependent_2.mmp'], 
       
   565                                ['sub_test.mmp'], 
       
   566                                ['if_test.mmp'], 
       
   567                                ['tc2.mmp'], 
       
   568                                ["tc3.mmp"],
       
   569                                ]
       
   570 
       
   571         self.path_list = [path.joinpath(upper_bld_path, "../tc1/group").normpath(),
       
   572                            path.joinpath(upper_bld_path, "../tc1/group/../dependent_1/group").normpath(),
       
   573                            path.joinpath(upper_bld_path, "../tc1/group/../dependent_2/group").normpath(),
       
   574                            path.joinpath(upper_bld_path, "../tc1/group/../subtest/group").normpath(),
       
   575                            path.joinpath(upper_bld_path, "../tc1/group/../subtest/group/../if_test/group").normpath(),
       
   576                            path.joinpath(upper_bld_path, "../tc2/group").normpath(),
       
   577                            path.joinpath(upper_bld_path, "../tc3/group").normpath(),
       
   578                            ]
       
   579 
       
   580 
       
   581     def test_testmmp_files_with_full_path(self):
       
   582         """Test if mmp file is returned with its full path"""
       
   583         self.mmp_file_path = [path.joinpath(TSRC_DIR, "tsrc", "tc1", "group", "tc1.mmp").normpath()]
       
   584         assert self.tcp.get_test_mmp_files(os.path.normpath(os.path.join(self.path_list[0], "bld.inf"))) == self.mmp_file_path
       
   585         
       
   586         
       
   587 
       
   588     def test_testmmp_files(self):
       
   589         """Tests if test mmp files are included"""
       
   590         self.lst_test_mmp = []
       
   591         
       
   592         for p in self.path_list:
       
   593             self.lst_test_mmp.append(self.tcp.get_test_mmp_files(os.path.normpath(os.path.join(p, "bld.inf")), False))
       
   594 
       
   595         assert self.lst_test_mmp == self.test_mmp_files
       
   596         
       
   597     def test_ignore_comments(self):
       
   598         """ Test if comments are ignored correctly. """
       
   599         for input_, output in [
       
   600             ("abc.mmp /* apuva.mmp */ xyz.mmp", ("abc.mmp xyz.mmp")),
       
   601             ("abc.mmp /* apuva.mmp */", ("abc.mmp")),
       
   602             ("/* apuva.mmp */", ""),
       
   603             ("  // apuva.mmp", ""),
       
   604             ("   apuva.mmp", "apuva.mmp"),
       
   605             ("xyz.mmp // apuva.mmp", "xyz.mmp"),
       
   606             ("abc.mmp /* apuva.mmp */ xyz.mmp //rst.mmp", ("abc.mmp xyz.mmp")),
       
   607             ]:
       
   608             assert self.tcp.ignore_comments_from_input(input_) == output
       
   609         
       
   610     def test_broken_path(self):
       
   611         """Tests if 'None' is returned when path is broken"""
       
   612         upper_bld_path = os.path.dirname(self.bld_path)
       
   613         assert self.tcp.get_test_mmp_files(os.path.normpath(os.path.join(upper_bld_path, "../tc99/group"))) == None
       
   614     
       
   615     def test_empty_parameter(self):
       
   616         """Tests if 'None' is returned when bld file path is empty"""
       
   617         upper_bld_path = os.path.dirname(self.bld_path)
       
   618         assert self.tcp.get_test_mmp_files("") == None
       
   619 
       
   620     
       
   621 class TestMmpFileParser(mocker.MockerTestCase):
       
   622     """Testing MmpFileParser Class"""
       
   623     def __init__(self, methodName="runTest"):
       
   624         mocker.MockerTestCase.__init__(self, methodName)
       
   625         
       
   626     def setUp(self):
       
   627         self.bld_path = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "group", "bld.inf"))
       
   628         upper_bld_path = os.path.dirname(self.bld_path)
       
   629         self.tcp = ats3.parsers.MmpFileParser()
       
   630         self.tc1_type = "dll"
       
   631         self.tc1_name = "tc1.dll"
       
   632         self.tc1_dll_type = "executable"
       
   633         self.tc1_harness = "STIF"
       
   634         self.tc1_libraries = ['stiftestinterface.lib', 'user.lib']
       
   635         self.tc1_all = (self.tc1_name, self.tc1_type, self.tc1_libraries, self.tc1_harness)
       
   636         self.tc1_no_harness = (self.tc1_name, self.tc1_type, self.tc1_libraries)
       
   637         self.tc1_name_type = (self.tc1_name, self.tc1_type) 
       
   638         self.tc1_iftest_harness = "STIFUNIT"
       
   639         self.tc1_iftest_name = "tc1_if.dll"
       
   640         self.tc1_iftest_type = "dll"
       
   641         
       
   642         self.test_mmp_files = [['tc1.mmp'], ['dependent_1.mmp', 'onemore.mmp'], ['dependent_2.mmp'], ['sub_test.mmp'], ['if_test.mmp'], 
       
   643                                ['tc2.mmp'], ["tc3.mmp"]]
       
   644 
       
   645         self.path_list = [os.path.normpath(os.path.join(upper_bld_path, "../tc1/group")),
       
   646                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_1/group")),
       
   647                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_2/group")),
       
   648                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group")),
       
   649                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group/../if_test/group")),
       
   650                            os.path.normpath(os.path.join(upper_bld_path, "../tc2/group")),
       
   651                            os.path.normpath(os.path.join(upper_bld_path, "../tc3/group")),
       
   652                            ]
       
   653     
       
   654     def test_get_dlltype(self):
       
   655         """Test if get_filetype returns right type for given mmp"""
       
   656         assert self.tc1_dll_type == self.tcp.get_dll_type(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp'))) 
       
   657     
       
   658     def test_get_target_filename(self):
       
   659         """Test if get_filename returns right name for dll for given mmp"""
       
   660         assert self.tc1_name == self.tcp.get_target_filename(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')))
       
   661     
       
   662     def test_get_libraries(self):
       
   663         """Test if get_harness returns right harness for given mmp"""
       
   664         assert self.tc1_libraries == self.tcp.get_libraries(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')))
       
   665     
       
   666     def test_get_harness(self):
       
   667         """Test if get_harness returns right harness for given mmp"""
       
   668         assert self.tc1_harness == self.tcp.get_harness(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')))
       
   669     
       
   670     def test_read_information_method(self):
       
   671         """Test if read_information_from_mmp returns wanted output for given parameter and mmp-file"""
       
   672         assert self.tc1_all == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 0)
       
   673         assert self.tc1_no_harness == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 1)
       
   674         assert self.tc1_name_type == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 2)
       
   675         assert self.tc1_name == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 3)
       
   676         assert self.tc1_type == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 4) 
       
   677         assert self.tc1_libraries == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 5)
       
   678         assert self.tc1_harness == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 6)
       
   679         assert self.tc1_iftest_name == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[4], 'if_test.mmp')), 3)
       
   680         assert self.tc1_iftest_type == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[4], 'if_test.mmp')), 4) 
       
   681         assert self.tc1_iftest_harness == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[4], 'if_test.mmp')), 6)
       
   682 
       
   683 class TestParsers(mocker.MockerTestCase):
       
   684     """Testing Parsers functionality"""
       
   685     def __init__(self, methodName="runTest"):
       
   686         mocker.MockerTestCase.__init__(self, methodName)
       
   687         
       
   688     def setUp(self):
       
   689         pass