configurationengine/source/plugins/symbian/ConeHCRPlugin/hcrplugin/tests/unittest_hcrml_writer.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 
       
    17 import os, unittest
       
    18 import __init__
       
    19 
       
    20 from hcrplugin.hcrrepository import HcrRepository, HcrRecord
       
    21 from hcrplugin.hcr_writer import HcrWriter
       
    22 from hcrplugin import hcr_exceptions
       
    23 from cone.public import api, plugin
       
    24 from testautomation.base_testcase import BaseTestCase
       
    25 
       
    26 
       
    27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    28 
       
    29 class TestHCRMLWrite(BaseTestCase):
       
    30     def _run_generate_test(self, project_dir, output_dir, expected_dir, hcrml_file):
       
    31         project_dir = os.path.join(ROOT_PATH, project_dir)
       
    32         output_dir = os.path.join(ROOT_PATH, output_dir)
       
    33         if expected_dir != None:
       
    34             expected_dir = os.path.join(ROOT_PATH, expected_dir)
       
    35         
       
    36         self.remove_if_exists(output_dir)
       
    37         
       
    38         prj = api.Project(api.Storage.open(project_dir))
       
    39         config = prj.get_configuration('root.confml')
       
    40         impls = plugin.ImplFactory.get_impls_from_file(hcrml_file, config)
       
    41         self.assertEquals(len(impls), 1)
       
    42         impl = impls[0]
       
    43         impl.set_output_root(output_dir)
       
    44         impl.generate()
       
    45         
       
    46         if expected_dir != None:
       
    47             self.assert_dir_contents_equal(expected_dir, output_dir, ['.svn'])
       
    48         else:
       
    49             self.assertFalse(os.path.exists(output_dir))
       
    50     
       
    51     def test_create_hcr_dat_from_single_hcrml_file(self):
       
    52         self._run_generate_test(
       
    53             project_dir     = 'project',
       
    54             output_dir      = 'output/single_dat',
       
    55             expected_dir    = 'expected/single_dat',
       
    56             hcrml_file      = 'implml/example.hcrml')
       
    57     
       
    58     def test_create_hcr_dat_from_multiple_hcrml_files(self):
       
    59         self._run_generate_test(
       
    60             project_dir     = 'multifile_project',
       
    61             output_dir      = 'output/multi_dat',
       
    62             expected_dir    = 'expected/multi_dat',
       
    63             hcrml_file      = 'layer1/implml/hcr_dat.hcrml')
       
    64     
       
    65     def test_create_header_from_single_hcrml_file(self):
       
    66         self._run_generate_test(
       
    67             project_dir     = 'multifile_project',
       
    68             output_dir      = 'output/single_header',
       
    69             expected_dir    = 'expected/single_header',
       
    70             hcrml_file      = 'layer1/implml/test1.hcrml')
       
    71     
       
    72     def test_create_header_from_multiple_hcrml_files(self):
       
    73         self._run_generate_test(
       
    74             project_dir     = 'multifile_project',
       
    75             output_dir      = 'output/multi_header',
       
    76             expected_dir    = 'expected/multi_header',
       
    77             hcrml_file      = 'layer1/implml/multi_header.hcrml')
       
    78     
       
    79     def test_create_nothing_from_outputless_hcrml_file(self):
       
    80         self._run_generate_test(
       
    81             project_dir     = 'multifile_project',
       
    82             output_dir      = 'output/no_output',
       
    83             expected_dir    = None, # Check that there is no output
       
    84             hcrml_file      = 'layer1/implml/test3.hcrml')