buildframework/helium/tools/common/python/lib/cpythontest/test_parsers.py
changeset 179 d8ac696cc51f
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         
       
   409         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': ''}}},
       
   410                                             (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'}}}, 
       
   411                                             (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'}}},
       
   412                                             (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'}, 
       
   413                                                                                                                                 (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':''}, 
       
   414                                                                                                                                 (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/dependent_2/group"))): {'pkg_files': [], 'mmp_files': ['dependent_2.mmp'], 'harness': "", 'type': 'dependent'}, 
       
   415                                                                                                                                 (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group"))): {'pkg_files': ['tc1.pkg'], 'mmp_files': ['tc1.mmp'],'harness': 'STIF', 'type': 'executable'}}}} 
       
   416         
       
   417         self.extended_path_list = [(os.path.normpath(upper_bld_path), upper_bld_path),
       
   418                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group")), upper_bld_path),
       
   419                            (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"))),
       
   420                            (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"))),
       
   421                            (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"))),
       
   422                            (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"))),
       
   423                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc2/group")), upper_bld_path),
       
   424                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc3/group")), upper_bld_path),
       
   425                            (os.path.normpath(os.path.join(upper_bld_path, "../tsrc/group/group")), upper_bld_path),
       
   426                            ]
       
   427         self.path_list = [os.path.normpath(os.path.join(upper_bld_path, "group")),
       
   428                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group")),
       
   429                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../dependent_1/group")),
       
   430                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../dependent_2/group")),
       
   431                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../subtest/group")),
       
   432                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc1/group/../subtest/group/../if_test/group")),
       
   433                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc2/group")),
       
   434                            os.path.normpath(os.path.join(upper_bld_path, "../tsrc/tc3/group")),
       
   435                            ]
       
   436         self.path_list_without_undefined = [os.path.normpath(upper_bld_path),
       
   437                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group")),
       
   438                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_1/group")),
       
   439                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_2/group")),
       
   440                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group")),
       
   441                            os.path.normpath(os.path.join(upper_bld_path, "../tc2/group")),
       
   442                            os.path.normpath(os.path.join(upper_bld_path, "../tc3/group")),
       
   443                            ]
       
   444         self.cpp_output = ['# 1 "bld.inf"', 
       
   445                            '# 1 "../tc1/group/bld.inf" 1', 
       
   446                            '# 1 "../tc1/group/../dependent_1/group/bld.inf" 1', 
       
   447                            '# 4 "../tc1/group/bld.inf" 2', 
       
   448                            '# 1 "../tc1/group/../dependent_2/group/bld.inf" 1', 
       
   449                            '# 5 "../tc1/group/bld.inf" 2', 
       
   450                            '# 1 "../tc1/group/../subtest/group/bld.inf" 1', 
       
   451                            '# 1 "../tc1/group/../subtest/group/../if_test/group/bld.inf" 1', 
       
   452                            '# 4 "../tc1/group/../subtest/group/bld.inf" 2', 
       
   453                            '# 6 "../tc1/group/bld.inf" 2', 
       
   454                            '# 3 "bld.inf" 2', 
       
   455                            '# 1 "../tc2/group/bld.inf" 1', 
       
   456                            '# 4 "bld.inf" 2', 
       
   457                            '# 1 "../tc3/group/bld.inf" 1', 
       
   458                            '# 5 "bld.inf" 2']
       
   459         
       
   460         
       
   461          
       
   462     def test_pathlist_output(self):
       
   463         """Test get_cpp_output-method using "n" -parameter"""
       
   464         assert self.path_list.sort() == self.tcp.get_cpp_output(self.bld_path, "n").sort()
       
   465         
       
   466     def test_extended_pathlist_output(self):
       
   467         """Test get_cpp_output-method using "e" -parameter"""
       
   468         assert self.extended_path_list.sort() == self.tcp.get_cpp_output(self.bld_path, "e").sort()
       
   469 
       
   470     def test_dictionary_pathlist_output(self):
       
   471         """Test get_cpp_output-method using "d" -parameter (dependent paths)"""
       
   472         output = """# 1 "bld.inf"
       
   473 
       
   474 # 1 "../tc1/group/bld.inf" 1
       
   475 
       
   476 # 1 "../tc1/group/../dependent_1/group/bld.inf" 1
       
   477 
       
   478 PRJ_TESTMMPFILES
       
   479 dependent_1.mmp
       
   480 onemore.mmp
       
   481             
       
   482 # 2 "../tc1/group/bld.inf" 2
       
   483 
       
   484 # 1 "../tc1/group/../dependent_2/group/bld.inf" 1
       
   485 
       
   486 PRJ_TESTMMPFILES
       
   487 dependent_2.mmp
       
   488             
       
   489 # 3 "../tc1/group/bld.inf" 2
       
   490 
       
   491 # 1 "../tc1/group/../subtest/group/bld.inf" 1
       
   492 
       
   493 PRJ_TESTMMPFILES
       
   494 sub_test.mmp    
       
   495 
       
   496 # 1 "../tc1/group/../subtest/group/../if_test/group/bld.inf" 1
       
   497 
       
   498 PRJ_TESTMMPFILES
       
   499 if_test.mmp
       
   500             
       
   501 # 5 "../tc1/group/../subtest/group/bld.inf" 2
       
   502 
       
   503 
       
   504             
       
   505 # 4 "../tc1/group/bld.inf" 2
       
   506 
       
   507 
       
   508 PRJ_TESTMMPFILES
       
   509 tc1.mmp
       
   510 
       
   511 PRJ_MMPFILES
       
   512 not_included.mmp
       
   513             
       
   514 # 2 "bld.inf" 2
       
   515 
       
   516 # 1 "../tc2/group/bld.inf" 1
       
   517 
       
   518 PRJ_TESTMMPFILES
       
   519 tc2.mmp
       
   520             
       
   521 # 3 "bld.inf" 2
       
   522 
       
   523 # 1 "../tc3/group/bld.inf" 1
       
   524 
       
   525 PRJ_TESTMMPFILES
       
   526 tc3.mmp
       
   527             
       
   528 # 4 "bld.inf" 2
       
   529 
       
   530 
       
   531 PRJ_TESTMMPFILES
       
   532 
       
   533             
       
   534 """
       
   535         
       
   536         result = self.tcp.create_dependency_dictionary(StringIO.StringIO(output), self.bld_path)
       
   537         print "INPUT :", self.dependent_paths_dictionary
       
   538         print "OUTPUT:", result 
       
   539 
       
   540         assert self.dependent_paths_dictionary == result
       
   541         
       
   542     def test_conditional_cpp_parsing(self):
       
   543         """Test functionality of cpp parser when removing conditionals"""
       
   544         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()
       
   545 
       
   546 class TestBldFileParser(mocker.MockerTestCase):
       
   547     """Testing BldFileParser Class"""
       
   548     
       
   549     def __init__(self, methodName="runTest"):
       
   550         mocker.MockerTestCase.__init__(self, methodName)
       
   551     
       
   552     def setUp(self):
       
   553         """Setup for BldFile parser"""
       
   554 
       
   555         self.bld_path = path.joinpath(TSRC_DIR, "tsrc", "group", "bld.inf").normpath()
       
   556         upper_bld_path = self.bld_path.dirname()
       
   557         self.tcp = ats3.parsers.BldFileParser()
       
   558         
       
   559         self.test_mmp_files = [
       
   560                                ['tc1.mmp'], 
       
   561                                ['dependent_1.mmp', 'onemore.mmp'], 
       
   562                                ['dependent_2.mmp'], 
       
   563                                ['sub_test.mmp'], 
       
   564                                ['if_test.mmp'], 
       
   565                                ['tc2.mmp'], 
       
   566                                ["tc3.mmp"],
       
   567                                ]
       
   568 
       
   569         self.path_list = [path.joinpath(upper_bld_path, "../tc1/group").normpath(),
       
   570                            path.joinpath(upper_bld_path, "../tc1/group/../dependent_1/group").normpath(),
       
   571                            path.joinpath(upper_bld_path, "../tc1/group/../dependent_2/group").normpath(),
       
   572                            path.joinpath(upper_bld_path, "../tc1/group/../subtest/group").normpath(),
       
   573                            path.joinpath(upper_bld_path, "../tc1/group/../subtest/group/../if_test/group").normpath(),
       
   574                            path.joinpath(upper_bld_path, "../tc2/group").normpath(),
       
   575                            path.joinpath(upper_bld_path, "../tc3/group").normpath(),
       
   576                            ]
       
   577 
       
   578 
       
   579     def test_testmmp_files_with_full_path(self):
       
   580         """Test if mmp file is returned with its full path"""
       
   581         self.mmp_file_path = [path.joinpath(TSRC_DIR, "tsrc", "tc1", "group", "tc1.mmp").normpath()]
       
   582         assert self.tcp.get_test_mmp_files(os.path.normpath(os.path.join(self.path_list[0], "bld.inf"))) == self.mmp_file_path
       
   583         
       
   584         
       
   585 
       
   586     def test_testmmp_files(self):
       
   587         """Tests if test mmp files are included"""
       
   588         self.lst_test_mmp = []
       
   589         
       
   590         for p in self.path_list:
       
   591             self.lst_test_mmp.append(self.tcp.get_test_mmp_files(os.path.normpath(os.path.join(p, "bld.inf")), False))
       
   592 
       
   593         assert self.lst_test_mmp == self.test_mmp_files
       
   594         
       
   595     def test_ignore_comments(self):
       
   596         """ Test if comments are ignored correctly. """
       
   597         for input_, output in [
       
   598             ("abc.mmp /* apuva.mmp */ xyz.mmp", ("abc.mmp xyz.mmp")),
       
   599             ("abc.mmp /* apuva.mmp */", ("abc.mmp")),
       
   600             ("/* apuva.mmp */", ""),
       
   601             ("  // apuva.mmp", ""),
       
   602             ("   apuva.mmp", "apuva.mmp"),
       
   603             ("xyz.mmp // apuva.mmp", "xyz.mmp"),
       
   604             ("abc.mmp /* apuva.mmp */ xyz.mmp //rst.mmp", ("abc.mmp xyz.mmp")),
       
   605             ]:
       
   606             assert self.tcp.ignore_comments_from_input(input_) == output
       
   607         
       
   608     def test_broken_path(self):
       
   609         """Tests if 'None' is returned when path is broken"""
       
   610         upper_bld_path = os.path.dirname(self.bld_path)
       
   611         assert self.tcp.get_test_mmp_files(os.path.normpath(os.path.join(upper_bld_path, "../tc99/group"))) == None
       
   612     
       
   613     def test_empty_parameter(self):
       
   614         """Tests if 'None' is returned when bld file path is empty"""
       
   615         upper_bld_path = os.path.dirname(self.bld_path)
       
   616         assert self.tcp.get_test_mmp_files("") == None
       
   617 
       
   618     
       
   619 class TestMmpFileParser(mocker.MockerTestCase):
       
   620     """Testing MmpFileParser Class"""
       
   621     def __init__(self, methodName="runTest"):
       
   622         mocker.MockerTestCase.__init__(self, methodName)
       
   623         
       
   624     def setUp(self):
       
   625         self.bld_path = os.path.normpath(os.path.join(TSRC_DIR, "tsrc", "group", "bld.inf"))
       
   626         upper_bld_path = os.path.dirname(self.bld_path)
       
   627         self.tcp = ats3.parsers.MmpFileParser()
       
   628         self.tc1_type = "dll"
       
   629         self.tc1_name = "tc1.dll"
       
   630         self.tc1_dll_type = "executable"
       
   631         self.tc1_harness = "STIF"
       
   632         self.tc1_libraries = ['stiftestinterface.lib', 'user.lib']
       
   633         self.tc1_all = (self.tc1_name, self.tc1_type, self.tc1_libraries, self.tc1_harness)
       
   634         self.tc1_no_harness = (self.tc1_name, self.tc1_type, self.tc1_libraries)
       
   635         self.tc1_name_type = (self.tc1_name, self.tc1_type) 
       
   636         self.tc1_iftest_harness = "STIFUNIT"
       
   637         self.tc1_iftest_name = "tc1_if.dll"
       
   638         self.tc1_iftest_type = "dll"
       
   639         
       
   640         self.test_mmp_files = [['tc1.mmp'], ['dependent_1.mmp', 'onemore.mmp'], ['dependent_2.mmp'], ['sub_test.mmp'], ['if_test.mmp'], 
       
   641                                ['tc2.mmp'], ["tc3.mmp"]]
       
   642 
       
   643         self.path_list = [os.path.normpath(os.path.join(upper_bld_path, "../tc1/group")),
       
   644                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_1/group")),
       
   645                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../dependent_2/group")),
       
   646                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group")),
       
   647                            os.path.normpath(os.path.join(upper_bld_path, "../tc1/group/../subtest/group/../if_test/group")),
       
   648                            os.path.normpath(os.path.join(upper_bld_path, "../tc2/group")),
       
   649                            os.path.normpath(os.path.join(upper_bld_path, "../tc3/group")),
       
   650                            ]
       
   651     
       
   652     def test_get_dlltype(self):
       
   653         """Test if get_filetype returns right type for given mmp"""
       
   654         assert self.tc1_dll_type == self.tcp.get_dll_type(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp'))) 
       
   655     
       
   656     def test_get_target_filename(self):
       
   657         """Test if get_filename returns right name for dll for given mmp"""
       
   658         assert self.tc1_name == self.tcp.get_target_filename(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')))
       
   659     
       
   660     def test_get_libraries(self):
       
   661         """Test if get_harness returns right harness for given mmp"""
       
   662         assert self.tc1_libraries == self.tcp.get_libraries(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')))
       
   663     
       
   664     def test_get_harness(self):
       
   665         """Test if get_harness returns right harness for given mmp"""
       
   666         assert self.tc1_harness == self.tcp.get_harness(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')))
       
   667     
       
   668     def test_read_information_method(self):
       
   669         """Test if read_information_from_mmp returns wanted output for given parameter and mmp-file"""
       
   670         assert self.tc1_all == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 0)
       
   671         assert self.tc1_no_harness == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 1)
       
   672         assert self.tc1_name_type == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 2)
       
   673         assert self.tc1_name == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 3)
       
   674         assert self.tc1_type == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 4) 
       
   675         assert self.tc1_libraries == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 5)
       
   676         assert self.tc1_harness == self.tcp.read_information_from_mmp(os.path.normpath(os.path.join(self.path_list[0], 'tc1.mmp')), 6)
       
   677         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)
       
   678         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) 
       
   679         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)
       
   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