configurationengine/source/plugins/symbian/ConeImagePlugin/imageplugin/tests/unittest_imageml_plugin.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
import unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
import os, shutil, re
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
import sys
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
import logging
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
import shutil
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
import __init__
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
		
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
from cone.public import exceptions,plugin,api,container
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
from cone.storage import filestorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
from imageplugin import imageml
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
from testautomation.base_testcase import BaseTestCase
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
testdata  = os.path.join(ROOT_PATH,'imageproject')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
class TestGeneratorFromProject(BaseTestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
    def test_create_generator_from_project_and_generate_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
        orig_workdir = os.getcwd()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        os.chdir(ROOT_PATH)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
            output = os.path.join(ROOT_PATH, "temp/output_all")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
            self.recreate_dir(output)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
            prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject")))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
            config = prj.get_configuration('product.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
            implcontainer = plugin.get_impl_set(config, 'imageml$')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
            self.assertEquals(len(implcontainer), 4)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
            implcontainer.output = output
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
            implcontainer.generate()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
            def check_gen(p):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
                self.assert_exists_and_contains_something(os.path.join(output, p))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
            def check_not_gen(p):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
                self.assertFalse(os.path.exists(os.path.join(output, p)), "'%s' exists when it should not!" % p)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
            try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
	            check_gen('startup.mbm')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
	            check_gen('startup_mif.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
	            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
	            check_not_gen('optional1_mbm.mbm')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
	            check_gen('optional2_mbm.mbm')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
	            check_not_gen('optional3_mbm.mbm')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
	            check_not_gen('optional4_mbm.mbm')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
	            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
	            check_not_gen('optional1_mif.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
	            check_gen('optional2_mif.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
	            check_not_gen('optional3_mif.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
	            check_not_gen('optional4_mif.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
	            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
	            check_gen('resource/apps/startup.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
	            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
	            check_gen('depth_from_ref_test_mbm.mbm')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
	            check_gen('depth_from_ref_test_mif.mif')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
    	    except AssertionError:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
	            if ' ' in ROOT_PATH:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
	                self.fail("Known bug (#177)")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
	            else:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
	                raise
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
        finally:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
            os.chdir(orig_workdir)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
    def _get_impl(self, filename):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
    	prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH, "imageproject")))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
        config = prj.get_configuration('product.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
        implcontainer = plugin.get_impl_set(config, re.escape(filename) + '$')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
        self.assertEquals(len(implcontainer), 1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
        return iter(implcontainer).next()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
    def test_get_refs(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
    	impl = self._get_impl('startupmif_animation.imageml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
    	self.assertEquals(impl.get_refs(), None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
    	self.assertEquals(impl.has_ref('Foo.Bar'), None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
    	
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
    	impl = self._get_impl('optional_test.imageml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
    	self.assertEquals(impl.get_refs(), ['OptionalTest.EmptyString',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
										    'OptionalTest.EmptyString2'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
    	self.assertEquals(impl.has_ref('OptionalTest.EmptyString'), True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
    	self.assertEquals(impl.has_ref('Foo.Foo'), False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
    	
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
    	impl = self._get_impl('startup_animation.imageml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
    	self.assertEquals(impl.get_refs(), ['CVC_StartupAnimationSequence.CVC_StartupFrameLocation.localPath'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
    	self.assertEquals(impl.has_ref('CVC_StartupAnimationSequence.CVC_StartupFrameLocation.localPath'), True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
    	self.assertEquals(impl.has_ref('Foo.Foo'), False)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
    unittest.main()