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