0
|
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 unittest, os, shutil
|
|
18 |
|
3
|
19 |
# import __init__
|
|
20 |
from cone.public import plugin, api, utils
|
0
|
21 |
from cone.storage import filestorage
|
|
22 |
from testautomation.base_testcase import BaseTestCase
|
|
23 |
|
|
24 |
# Hardcoded value of testdata folder that must be under the current working dir
|
|
25 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
26 |
temp_dir = os.path.join(ROOT_PATH, "temp")
|
|
27 |
testdata = os.path.join(ROOT_PATH,'project')
|
|
28 |
|
|
29 |
class TestCommandPlugin(BaseTestCase):
|
|
30 |
def test_example_parse_prj(self):
|
|
31 |
fs = filestorage.FileStorage(testdata)
|
|
32 |
p = api.Project(fs)
|
|
33 |
config = p.get_configuration('product.confml')
|
|
34 |
impls = plugin.get_impl_set(config,'\.commandml$')
|
|
35 |
|
|
36 |
def test_generate(self):
|
|
37 |
orig_workdir = os.getcwd()
|
|
38 |
os.chdir(ROOT_PATH)
|
|
39 |
try:
|
|
40 |
OUTPUT_DIR = os.path.join(ROOT_PATH, 'output')
|
|
41 |
self.remove_if_exists(OUTPUT_DIR)
|
3
|
42 |
self.remove_if_exists(['hello.log', 'exec_in_output_test.log',])
|
0
|
43 |
|
|
44 |
fs = filestorage.FileStorage(testdata)
|
|
45 |
p = api.Project(fs)
|
|
46 |
config = p.get_configuration('product.confml')
|
3
|
47 |
context = plugin.GenerationContext(configuration=config,
|
|
48 |
output=OUTPUT_DIR)
|
0
|
49 |
impls = plugin.get_impl_set(config,'file2\.commandml$')
|
3
|
50 |
#impls.output = OUTPUT_DIR
|
|
51 |
impls.generate(context)
|
0
|
52 |
|
|
53 |
self.assert_file_content_equals('hello.log',
|
3
|
54 |
"Hello" + os.linesep +
|
|
55 |
"Cmd line args: ['-c', 'some_config.txt', '-d', 'some_dir', '-x']" + os.linesep)
|
0
|
56 |
|
|
57 |
self.assert_file_content_equals('exec_in_output_test.log',
|
3
|
58 |
os.path.normpath(OUTPUT_DIR) + os.linesep)
|
0
|
59 |
|
|
60 |
# Check that the log file of the command that should not be
|
|
61 |
# executed does not exist
|
|
62 |
self.assertFalse(os.path.exists("should_not_be_created.log"))
|
3
|
63 |
self.assertTrue(os.path.exists(os.path.join(OUTPUT_DIR,"helloworld.txt")))
|
|
64 |
|
|
65 |
self.assertEquals(len(context.generation_output), 1)
|
|
66 |
self.assertEquals(utils.relpath(context.generation_output[0].name, OUTPUT_DIR), 'helloworld.txt')
|
|
67 |
self.assertEquals(context.generation_output[0].implementation.ref, 'assets/s60/implml/file2.commandml')
|
0
|
68 |
finally:
|
|
69 |
os.chdir(orig_workdir)
|
3
|
70 |
|
0
|
71 |
|
|
72 |
if __name__ == '__main__':
|
|
73 |
unittest.main()
|