configurationengine/source/plugins/symbian/integration-test/unittest_generate.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 # *-* coding: utf-8 *-*
       
     2 #
       
     3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of "Eclipse Public License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description: 
       
    16 #
       
    17 
       
    18 import sys, os, shutil, unittest
       
    19 import __init__
       
    20 from testautomation.base_testcase import BaseTestCase
       
    21 from testautomation import zip_dir
       
    22 
       
    23 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    24 
       
    25 if sys.platform == "win32":
       
    26     CONE_SCRIPT = "cone.cmd"
       
    27 else:
       
    28     CONE_SCRIPT = "cone.sh"
       
    29 
       
    30 def get_cmd(action='generate'):
       
    31     """Return the command used to run the ConE sub-action"""
       
    32     if 'CONE_PATH' in os.environ:
       
    33         CONE_CMD = os.path.join(os.environ['CONE_PATH'], CONE_SCRIPT)
       
    34         if not os.path.exists(CONE_CMD):
       
    35             raise RuntimeError("'%s' does not exist!" % CONE_CMD)
       
    36         return '"%s" %s' % (CONE_CMD, action)
       
    37     else:
       
    38         SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..'))
       
    39         assert os.path.split(SOURCE_ROOT)[1] == 'source'
       
    40         cmd = 'python "%s" %s' % (os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts/cone_tool.py')), action)
       
    41         return cmd
       
    42 
       
    43 class TestSymbianGenerateAllImplsOnLastLayer(BaseTestCase):
       
    44     
       
    45     def _prepare_workdir(self, workdir):
       
    46         workdir = os.path.join(ROOT_PATH, workdir)
       
    47         self.recreate_dir(workdir)
       
    48         
       
    49         # Get the binaries needed for ImageML to work
       
    50         bin_target_dir = os.path.join(workdir, "bin")
       
    51         self.recreate_dir(bin_target_dir)
       
    52         bin_source_dir = os.path.join(ROOT_PATH, "testdata/generate/imageplugin_bin")
       
    53         for name in os.listdir(bin_source_dir):
       
    54             source_path = os.path.join(bin_source_dir, name)
       
    55             target_path = os.path.join(bin_target_dir, name)
       
    56             if os.path.isfile(source_path):
       
    57                 shutil.copy2(source_path, target_path)
       
    58         
       
    59         # Create the mock carbide.ui directory
       
    60         target_dir = os.path.join(workdir, "mock_carbide_ui")
       
    61         self.recreate_dir(target_dir)
       
    62         def copy_file(file_name):
       
    63             source_file = os.path.join(ROOT_PATH, "testdata/generate/mock_carbide_ui", file_name)
       
    64             target_file = os.path.join(target_dir, file_name)
       
    65             shutil.copy2(source_file, target_file)
       
    66         copy_file('makepackage.bat')
       
    67         copy_file('makepackage.py')
       
    68         
       
    69         return workdir
       
    70     
       
    71     def test_generate_all_impls_on_last_layer_on_file_storage(self):
       
    72         project_dir = os.path.join(ROOT_PATH, "testdata/generate/project")
       
    73         self.assert_exists_and_contains_something(project_dir)
       
    74         self._run_test_generate_all_impls_on_last_layer('temp/gen_ll1', project_dir)
       
    75     
       
    76     def test_generate_all_impls_on_last_layer_on_zip_storage(self):
       
    77         project_dir = os.path.join(ROOT_PATH, "testdata/generate/project")
       
    78         self.assert_exists_and_contains_something(project_dir)
       
    79         
       
    80         project_zip = os.path.join(ROOT_PATH, "temp/generation_test_project.zip")
       
    81         self.remove_if_exists(project_zip)
       
    82         zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN])
       
    83         self.assert_exists_and_contains_something(project_zip)
       
    84         
       
    85         self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip)
       
    86     
       
    87     def _run_test_generate_all_impls_on_last_layer(self, workdir, project):
       
    88         # Create a temp workdir and go there to run the test
       
    89         orig_workdir = os.getcwd()
       
    90         workdir = self._prepare_workdir(workdir)
       
    91         os.chdir(workdir)
       
    92         
       
    93         try:
       
    94             # Run the generation command
       
    95             cmd = '%s -p "%s" --output output --layer -1 --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project)
       
    96             self.run_command(cmd)
       
    97             
       
    98             # Check that all expected output files are generated
       
    99             def check(path):
       
   100                 self.assert_exists_and_contains_something("output/" + path)
       
   101             
       
   102             try:
       
   103                 check("content/animations/anim1.mbm")
       
   104                 check("content/animations/anim2.mif")
       
   105             except AssertionError:
       
   106                 if ' ' in ROOT_PATH:
       
   107                     self.fail("Known bug (#177)")
       
   108                 else:
       
   109                     raise
       
   110             
       
   111             check("content/data/sounds/test.mp3")
       
   112             check("content/data/sequence_setting_test.txt")
       
   113             check("content/private/10202BE9/10000000.txt")
       
   114             check("content/private/10202BE9/12341001.txt")
       
   115             check("content/private/10202BE9/12341002.txt")
       
   116             check("content/private/10202BE9/20000000.txt")
       
   117             check("content/sound_folder/test2.mp3")
       
   118             check("hcr_test.h")
       
   119             check("content/private/10207114/import/12340001/themepackage.mbm")
       
   120             check("content/private/10207114/import/12340001/themepackage.mif")
       
   121             check("content/private/10207114/import/12340001/themepackage.skn")
       
   122             
       
   123             # Check that files that should not have been generated are not
       
   124             def check_not_gen(path):
       
   125                 self.assertFalse(os.path.exists("output/" + path),
       
   126                                  "'%s' was generated when it should not have been!" % path)
       
   127             check_not_gen("content/private/10202BE9/ABCD0000.txt")
       
   128             check_not_gen("content/private/10202BE9/12341000.txt")
       
   129             
       
   130             # Check that the data has been generated correctly
       
   131             self.assert_file_contains(
       
   132                 "output/content/private/10202BE9/12341002.txt",
       
   133                 "0x1 int 42 0 cap_rd=alwayspass cap_wr=WriteDeviceData",
       
   134                 encoding='utf-16')
       
   135             self.assert_file_contains(
       
   136                 "output/content/private/10202BE9/10000000.txt",
       
   137                 r'0x1 string "Z:\\data\\sounds\\test.mp3" 0 cap_rd=alwayspass cap_wr=WriteDeviceData',
       
   138                 encoding='utf-16')
       
   139             self.assert_file_contains(
       
   140                 "output/content/private/10202BE9/12341001.txt",
       
   141                 u'0x1 string "default string カタカナ <&> カタカナ" 0 cap_rd=alwayspass cap_wr=WriteDeviceData',
       
   142                 encoding='utf-16')
       
   143             self.assert_file_contains(
       
   144                 "output/content/private/10202BE9/20000000.txt",
       
   145                 ['0x11 string "305397761" 0',
       
   146                  '0x12 string "305397761" 0',
       
   147                  '0x13 string "305397761" 0',
       
   148                  '0x21 string "305397762" 0',
       
   149                  '0x22 string "305397762" 0'],
       
   150                 encoding='utf-16')
       
   151         finally:
       
   152             os.chdir(orig_workdir)
       
   153 
       
   154 if __name__ == '__main__':
       
   155       unittest.main()