179
|
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 |
_logger = logging.getLogger('test.archive')
|
|
32 |
|
|
33 |
|
|
34 |
_test_file_paths = [
|
|
35 |
's60/Distribution.Policy.S60',
|
|
36 |
's60/ADO/Distribution.Policy.S60',
|
|
37 |
's60/ADO/group/Distribution.Policy.S60',
|
|
38 |
's60/ADO/internal/Distribution.Policy.S60',
|
|
39 |
's60/ADO/internal/good/Distribution.Policy.S60',
|
|
40 |
's60/ADO/internal/bad/Distribution.Policy.S60',
|
|
41 |
's60/ADO/tsrc/Distribution.Policy.S60',
|
|
42 |
's60/ADO/tsrc/group/Distribution.Policy.S60',
|
|
43 |
's60/ADO/tsrc/private/Distribution.Policy.S60',
|
|
44 |
's60/component_public/Distribution.Policy.S60',
|
|
45 |
's60/component_public/component_public_file.txt',
|
|
46 |
's60/component_private/Distribution.Policy.S60',
|
|
47 |
's60/component_private/component_private_file.txt',
|
|
48 |
's60/missing/to_be_removed_9999.txt',
|
|
49 |
's60/missing/subdir/Distribution.Policy.S60',
|
|
50 |
's60/missing/subdir/to_be_removed_9999.txt',
|
|
51 |
's60/invalid/Distribution.Policy.S60',
|
|
52 |
's60/invalid/comment/Distribution.Policy.S60',
|
|
53 |
's60/invalid/utf16/Distribution.Policy.S60',
|
|
54 |
's60/invalid/letter/Distribution.Policy.S60',
|
|
55 |
's60/new_rules/',
|
|
56 |
's60/new_rules/subdir1/invalid.txt',
|
|
57 |
's60/new_rules/subdir2/',
|
|
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 |
class PolicyValidatorTest(unittest.TestCase):
|
|
80 |
EXEC_FILE = "archive_create.ant.xml"
|
|
81 |
|
|
82 |
def _testpath(self, subpath):
|
|
83 |
""" Normalised path for test paths. """
|
|
84 |
return os.path.normpath(os.path.join(self.root_test_dir, subpath))
|
|
85 |
|
|
86 |
def setUp(self):
|
|
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 |
self.root_test_dir = "_test_" + str(time.strftime("%H.%M.%S"))
|
|
95 |
for child_path in _test_file_paths:
|
|
96 |
path = os.path.join(self.root_test_dir, child_path)
|
|
97 |
path_dir = path
|
|
98 |
path_dir = os.path.dirname(path)
|
|
99 |
|
|
100 |
if (not os.path.exists(path_dir)):
|
|
101 |
_logger.debug('Creating dir: ' + path_dir)
|
|
102 |
os.makedirs(path_dir)
|
|
103 |
|
|
104 |
if(not path.endswith('/') and not path.endswith('\\')):
|
|
105 |
_logger.debug('Creating file: ' + path)
|
|
106 |
handle = open(path, 'w')
|
|
107 |
# Write any file content that is needed
|
|
108 |
if _test_file_content.has_key(child_path):
|
|
109 |
handle.write(_test_file_content[child_path])
|
|
110 |
handle.close()
|
|
111 |
|
|
112 |
def tearDown(self):
|
|
113 |
""" Teardown test config. """
|
|
114 |
shutil.rmtree(self.root_test_dir)
|
|
115 |
|
|
116 |
def test_policy_validator(self):
|
|
117 |
""" Testing the policy validator behaviour. """
|
|
118 |
validator = integration.quality.PolicyValidator()
|
|
119 |
errors = []
|
|
120 |
errors.extend(validator.validate(self._testpath('s60')))
|
|
121 |
errors.sort()
|
|
122 |
print errors
|
|
123 |
assert len(errors) == 5
|
|
124 |
|
|
125 |
|
|
126 |
# Invalid encoding: contains other stuff than policy id.
|
|
127 |
assert errors[0][0] == "invalidencoding"
|
|
128 |
assert errors[0][1].lower() == self._testpath('s60' + os.sep + 'invalid' + os.sep + 'comment' + os.sep + 'distribution.policy.s60')
|
|
129 |
assert errors[0][2] == None
|
|
130 |
|
|
131 |
# Invalid encoding: ID contains a letter.
|
|
132 |
assert errors[1][0] == "invalidencoding"
|
|
133 |
assert errors[1][1].lower() == self._testpath('s60' + os.sep + 'invalid' + os.sep + 'letter' + os.sep + 'distribution.policy.s60')
|
|
134 |
assert errors[1][2] == None
|
|
135 |
|
|
136 |
# Invalid encoding: not ascii.
|
|
137 |
assert errors[2][0] == "invalidencoding"
|
|
138 |
assert errors[2][1].lower() == self._testpath('s60' + os.sep + 'invalid' + os.sep + 'utf16' + os.sep + 'distribution.policy.s60')
|
|
139 |
assert errors[2][2] == None
|
|
140 |
|
|
141 |
# Policy file is missing
|
|
142 |
assert errors[3][0] == "missing"
|
|
143 |
assert errors[3][1].lower() == self._testpath('s60' + os.sep + 'missing')
|
|
144 |
assert errors[3][2] == None
|
|
145 |
|
|
146 |
# Policy file is missing
|
|
147 |
assert errors[4][0] == "missing"
|
|
148 |
assert errors[4][1].lower() == self._testpath('s60' + os.sep + 'new_rules' + os.sep + 'subdir1')
|
|
149 |
assert errors[4][2] == None
|
|
150 |
|