1 #============================================================================ |
|
2 #Name : test_policy_validator.py |
|
3 #Part of : Helium |
|
4 |
|
5 #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 #All rights reserved. |
|
7 #This component and the accompanying materials are made available |
|
8 #under the terms of the License "Eclipse Public License v1.0" |
|
9 #which accompanies this distribution, and is available |
|
10 #at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 #Initial Contributors: |
|
13 #Nokia Corporation - initial contribution. |
|
14 # |
|
15 #Contributors: |
|
16 # |
|
17 #Description: |
|
18 #=============================================================================== |
|
19 |
|
20 """Test the integration.quality module.""" |
|
21 |
|
22 import os |
|
23 import unittest |
|
24 import sys |
|
25 import time |
|
26 import shutil |
|
27 |
|
28 import integration.quality |
|
29 import logging |
|
30 |
|
31 import test.test_fileutils |
|
32 |
|
33 |
|
34 _logger = logging.getLogger('test.archive') |
|
35 |
|
36 |
|
37 _test_file_paths = [ |
|
38 's60/Distribution.Policy.S60', |
|
39 's60/ADO/Distribution.Policy.S60', |
|
40 's60/ADO/group/Distribution.Policy.S60', |
|
41 's60/ADO/internal/Distribution.Policy.S60', |
|
42 's60/ADO/internal/good/Distribution.Policy.S60', |
|
43 's60/ADO/internal/bad/Distribution.Policy.S60', |
|
44 's60/ADO/tsrc/Distribution.Policy.S60', |
|
45 's60/ADO/tsrc/group/Distribution.Policy.S60', |
|
46 's60/ADO/tsrc/private/Distribution.Policy.S60', |
|
47 's60/component_public/Distribution.Policy.S60', |
|
48 's60/component_public/component_public_file.txt', |
|
49 's60/component_private/Distribution.Policy.S60', |
|
50 's60/component_private/component_private_file.txt', |
|
51 's60/missing/to_be_removed_9999.txt', |
|
52 's60/missing/subdir/Distribution.Policy.S60', |
|
53 's60/missing/subdir/to_be_removed_9999.txt', |
|
54 's60/invalid/Distribution.Policy.S60', |
|
55 's60/invalid/comment/Distribution.Policy.S60', |
|
56 's60/invalid/utf16/Distribution.Policy.S60', |
|
57 's60/invalid/letter/Distribution.Policy.S60', |
|
58 ] |
|
59 |
|
60 _test_file_content = { |
|
61 's60/Distribution.Policy.S60': '0', |
|
62 's60/missing/subdir/Distribution.Policy.S60' : '0', |
|
63 's60/component_public/Distribution.Policy.S60': '0', |
|
64 's60/component_private/Distribution.Policy.S60': '1', |
|
65 's60/ADO/Distribution.Policy.S60': '0', |
|
66 's60/ADO/group/Distribution.Policy.S60': '0', |
|
67 's60/ADO/internal/Distribution.Policy.S60': '1', |
|
68 's60/ADO/internal/good/Distribution.Policy.S60': '1', |
|
69 's60/ADO/internal/bad/Distribution.Policy.S60': '0', |
|
70 's60/ADO/tsrc/Distribution.Policy.S60': '950', |
|
71 's60/ADO/tsrc/group/Distribution.Policy.S60': '0', |
|
72 's60/ADO/tsrc/private/Distribution.Policy.S60': '0', |
|
73 's60/invalid/Distribution.Policy.S60': '0', |
|
74 's60/invalid/comment/Distribution.Policy.S60': '0 ; some comment', |
|
75 's60/invalid/utf16/Distribution.Policy.S60': '\xFF\xFE\x30\x00\x0D\x00\x0D\x00\x0D\x00\x0A\x00', |
|
76 's60/invalid/letter/Distribution.Policy.S60': '9A0', |
|
77 } |
|
78 |
|
79 """ Used by test_archive. """ |
|
80 root_test_dir = "_test_" + str(time.strftime("%H.%M.%S")) |
|
81 |
|
82 def _testpath(subpath): |
|
83 """ Normalised path for test paths. """ |
|
84 return os.path.normpath(os.path.join(root_test_dir, subpath)) |
|
85 |
|
86 def setup_module(): |
|
87 """ Setup files test config. |
|
88 |
|
89 This creates a number of empty files in a temporary directory structure |
|
90 for testing various file selection and archiving operations. |
|
91 """ |
|
92 #print 'setup_module()' |
|
93 #print _test_file_content.keys() |
|
94 for child_path in _test_file_paths: |
|
95 path = os.path.join(root_test_dir, child_path) |
|
96 path_dir = path |
|
97 path_dir = os.path.dirname(path) |
|
98 |
|
99 if (not os.path.exists(path_dir)): |
|
100 _logger.debug('Creating dir: ' + path_dir) |
|
101 os.makedirs(path_dir) |
|
102 |
|
103 if(not path.endswith('/') and not path.endswith('\\')): |
|
104 _logger.debug('Creating file: ' + path) |
|
105 handle = open(path, 'w') |
|
106 # Write any file content that is needed |
|
107 if _test_file_content.has_key(child_path): |
|
108 handle.write(_test_file_content[child_path]) |
|
109 handle.close() |
|
110 |
|
111 def teardown_module(): |
|
112 """ Teardown test config. """ |
|
113 shutil.rmtree(root_test_dir) |
|
114 |
|
115 |
|
116 class PolicyValidatorTest(unittest.TestCase): |
|
117 EXEC_FILE = "archive_create.ant.xml" |
|
118 |
|
119 def test_policy_validator(self): |
|
120 """ Testing the policy validator behaviour. """ |
|
121 validator = integration.quality.PolicyValidator() |
|
122 errors = [] |
|
123 errors.extend(validator.validate(_testpath('s60'))) |
|
124 errors.sort() |
|
125 print errors |
|
126 assert len(errors) == 4 |
|
127 |
|
128 |
|
129 # Invalid encoding: contains other stuff than policy id. |
|
130 assert errors[0][0] == "invalidencoding" |
|
131 assert errors[0][1].lower() == _testpath('s60' + os.sep + 'invalid' + os.sep + 'comment' + os.sep + 'distribution.policy.s60') |
|
132 assert errors[0][2] == None |
|
133 |
|
134 # Invalid encoding: ID contains a letter. |
|
135 assert errors[1][0] == "invalidencoding" |
|
136 assert errors[1][1].lower() == _testpath('s60' + os.sep + 'invalid' + os.sep + 'letter' + os.sep + 'distribution.policy.s60') |
|
137 assert errors[1][2] == None |
|
138 |
|
139 # Invalid encoding: not ascii. |
|
140 assert errors[2][0] == "invalidencoding" |
|
141 assert errors[2][1].lower() == _testpath('s60' + os.sep + 'invalid' + os.sep + 'utf16' + os.sep + 'distribution.policy.s60') |
|
142 assert errors[2][2] == None |
|
143 |
|
144 # Policy file is missing |
|
145 assert errors[3][0] == "missing" |
|
146 assert errors[3][1].lower() == _testpath('s60' + os.sep + 'missing') |
|
147 assert errors[3][2] == None |
|
148 |
|