|
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 # unit tests for featurevariantmap.pm |
|
18 |
|
19 use strict; |
|
20 use Test; |
|
21 use File::Basename; |
|
22 use File::Spec; |
|
23 use lib "../../e32util"; # run from e32toolp/test/featuervariantmap |
|
24 use lib "../e32util"; # run from e32toolp/test |
|
25 use featurevariantmap; |
|
26 use File::Copy; |
|
27 use Digest::MD5; |
|
28 |
|
29 # how many tests do we plan to run? |
|
30 BEGIN { plan tests => 56 } |
|
31 |
|
32 # where is the test data |
|
33 my $dir = File::Spec->rel2abs(dirname($0)); |
|
34 print "# running in $dir\n"; |
|
35 |
|
36 # Copy the features lists needed for this test to the right place |
|
37 mkdir("$ENV{EPOCROOT}epoc32/include/variant/featurelists/"); |
|
38 unlink "$ENV{EPOCROOT}epoc32/include/variant/featurelists/featnames.txt"; |
|
39 copy("$dir/featnames.txt", "$ENV{EPOCROOT}epoc32/include/variant/featurelists/featnames.txt"); |
|
40 |
|
41 ############################################################################### |
|
42 # tests for Find # |
|
43 ############################################################################### |
|
44 |
|
45 # we wont find a non-existent file |
|
46 ok(featurevariantmap->Find("non-existant-file", "myvar"), ""); |
|
47 |
|
48 # we will find a real file (with no vmap) |
|
49 ok(featurevariantmap->Find("$dir/fred.dll", "myvar"), "$dir/fred.dll"); |
|
50 |
|
51 # we wont find a non-existent feature variant |
|
52 print "# expect an ERROR from this test\n"; |
|
53 ok(featurevariantmap->Find("$dir/john.dll", "not-a-variant"), ""); |
|
54 |
|
55 # we will find a real feature variant |
|
56 ok(featurevariantmap->Find("$dir/john.dll", "myvar"), |
|
57 "$dir/john.12345678901234567890123456789012.dll"); |
|
58 |
|
59 # the feature variant name should not depend on case |
|
60 ok(featurevariantmap->Find("$dir/john.dll", "MyVar"), |
|
61 "$dir/john.12345678901234567890123456789012.dll"); |
|
62 |
|
63 ############################################################################### |
|
64 # tests for Save # |
|
65 ############################################################################### |
|
66 |
|
67 # create a .vmap from scratch |
|
68 unlink("$dir/tony.dll.vmap"); |
|
69 |
|
70 ok(! featurevariantmap->Save("$dir/tony.dll", |
|
71 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a_phone", "features_for_a")); |
|
72 |
|
73 ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a")); |
|
74 |
|
75 # add to an existing .vmap file |
|
76 ok(! featurevariantmap->Save("$dir/tony.dll", |
|
77 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "b_phone", "features_for_b1")); |
|
78 |
|
79 ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a")); |
|
80 ok(check("$dir/tony.dll.vmap", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","b_phone","features_for_b1")); |
|
81 |
|
82 # change an entry in an existing .vmap file |
|
83 ok(! featurevariantmap->Save("$dir/tony.dll", |
|
84 "babababababababababababababababa", "b_phone", "features_for_b2")); |
|
85 |
|
86 ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a")); |
|
87 ok(check("$dir/tony.dll.vmap", "babababababababababababababababa","b_phone","features_for_b2")); |
|
88 |
|
89 # change with one case and check with another |
|
90 ok(! featurevariantmap->Save("$dir/tony.dll", |
|
91 "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbba", "B_PhOnE", "features_for_b3")); |
|
92 |
|
93 ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a")); |
|
94 ok(check("$dir/tony.dll.vmap", "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbba","b_phone","features_for_b3")); |
|
95 |
|
96 # add an entry and a hint to an existing .vmap file |
|
97 my @hints = ("FEATUREVARIANT"); |
|
98 ok(! featurevariantmap->Save("$dir/tony.dll", |
|
99 "cccccccccccccccccccccccccccccccc", "c_phone", "features_for_c", \@hints)); |
|
100 |
|
101 ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a")); |
|
102 ok(check("$dir/tony.dll.vmap", "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbba","b_phone","features_for_b3")); |
|
103 ok(check("$dir/tony.dll.vmap", "cccccccccccccccccccccccccccccccc","c_phone","features_for_c")); |
|
104 ok(check("$dir/tony.dll.vmap", "FEATUREVARIANT")); |
|
105 |
|
106 ############################################################################### |
|
107 # tests for Hash # |
|
108 ############################################################################### |
|
109 |
|
110 # test the hash key for an invalid feature variant |
|
111 my @src = ("$dir/a.cpp", "$dir/b.cpp"); |
|
112 my %var = ('NAME' => 'something', 'VALID' => 0); |
|
113 |
|
114 ok(featurevariantmap->Hash(\@src, \%var), ""); |
|
115 ok(featurevariantmap->HashAndFeatures(\@src, \%var), ""); |
|
116 |
|
117 # test the hash key for a valid feature variant with missing headers |
|
118 $var{'VALID'} = 1; |
|
119 ok(featurevariantmap->Hash(\@src, \%var), qr/^[0-9a-f]{32}$/); |
|
120 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined'); |
|
121 |
|
122 # test the hash key for a working feature variant |
|
123 $var{'BUILD_INCLUDES'} = ["$dir/inc_jack"]; |
|
124 my $h1 = featurevariantmap->Hash(\@src, \%var); |
|
125 ok($h1, qr/^[0-9a-f]{32}$/); |
|
126 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,JACK=undefined'); |
|
127 |
|
128 # test the hash key for a different working feature variant |
|
129 $var{'BUILD_INCLUDES'} = ["$dir/inc_noel", "$dir/inc_fake"]; |
|
130 my $h2 = featurevariantmap->Hash(\@src, \%var); |
|
131 ok($h2, qr/^[0-9a-f]{32}$/); |
|
132 ok($h1 ne $h2); |
|
133 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,NOEL=undefined'); |
|
134 |
|
135 # test the hash key for a working feature variant with a pre-include |
|
136 $var{'PREINCLUDE'} = "$dir/jack.hrh"; |
|
137 $var{'BUILD_INCLUDES'} = ["$dir/inc_jack"]; |
|
138 my $h3 = featurevariantmap->Hash(\@src, \%var); |
|
139 ok($h3, qr/^[0-9a-f]{32}$/); |
|
140 ok($h3 ne $h2); |
|
141 ok($h3 ne $h1); |
|
142 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,JACK=defined'); |
|
143 |
|
144 # test that we get the same hash value when we should (jack2.hrh ~ jack.hrh) |
|
145 $var{'PREINCLUDE'} = "$dir/jack2.hrh"; |
|
146 my $h3a = featurevariantmap->Hash(\@src, \%var); |
|
147 ok($h3a, $h3); |
|
148 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,JACK=defined'); |
|
149 |
|
150 # test the hash key for a different working feature variant with a pre-include |
|
151 $var{'PREINCLUDE'} = "$dir/noel.hrh"; |
|
152 $var{'BUILD_INCLUDES'} = ["$dir/inc_noel"]; |
|
153 my $h4 = featurevariantmap->Hash(\@src, \%var); |
|
154 ok($h4, qr/^[0-9a-f]{32}$/); |
|
155 ok($h4 ne $h3); |
|
156 ok($h4 ne $h2); |
|
157 ok($h4 ne $h1); |
|
158 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,NOEL=defined'); |
|
159 |
|
160 # test the hash key for a different working feature variant with extra macros |
|
161 $var{'PREINCLUDE'} = "$dir/noel.hrh"; |
|
162 $var{'BUILD_INCLUDES'} = ["$dir/inc_noel"]; |
|
163 $var{'MACROS'} = ["ADEF"]; |
|
164 my $h5 = featurevariantmap->Hash(\@src, \%var); |
|
165 ok($h5, qr/^[0-9a-f]{32}$/); |
|
166 ok($h5 ne $h4); |
|
167 ok($h5 ne $h3); |
|
168 ok($h5 ne $h2); |
|
169 ok($h5 ne $h1); |
|
170 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=\'1\',BDEF=undefined,NOEL=defined'); |
|
171 |
|
172 $var{'MACROS'} = ["ADEF", "BDEF"]; |
|
173 my $h6 = featurevariantmap->Hash(\@src, \%var); |
|
174 ok($h6, qr/^[0-9a-f]{32}$/); |
|
175 ok($h6 ne $h5); |
|
176 ok($h6 ne $h4); |
|
177 ok($h6 ne $h3); |
|
178 ok($h6 ne $h2); |
|
179 ok($h6 ne $h1); |
|
180 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=\'1\',BDEF=\'1\',NOEL=defined'); |
|
181 |
|
182 # test verbose mode |
|
183 $featurevariantmap::verbose = 1; |
|
184 print "# this test is verbose\n"; |
|
185 my $h7 = featurevariantmap->Hash(\@src, \%var); |
|
186 ok($h7, $h6); |
|
187 print "# this test is verbose\n"; |
|
188 ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=\'1\',BDEF=\'1\',NOEL=defined'); |
|
189 |
|
190 ############################################################################### |
|
191 # END OF TESTS # |
|
192 ############################################################################### |
|
193 |
|
194 # utility functions |
|
195 |
|
196 sub check |
|
197 { |
|
198 my $file = shift; |
|
199 my $arg1 = shift; |
|
200 my $arg2 = shift; |
|
201 my $feat = shift; |
|
202 |
|
203 if ($arg2) |
|
204 { |
|
205 return checkHash($file, $arg1, $arg2, $feat); |
|
206 } |
|
207 return checkHint($file, $arg1); |
|
208 } |
|
209 |
|
210 sub checkHash |
|
211 { |
|
212 my $file = shift; |
|
213 my $hash = shift; |
|
214 my $name = shift; |
|
215 my $feat = shift; |
|
216 |
|
217 open(FILE, $file) or return 0; |
|
218 my $hit = 0; # found hash with the right name |
|
219 my $bad = 0; # found hash with the wrong name |
|
220 while (<FILE>) |
|
221 { |
|
222 if (/^$hash\s+(\w+)\s+$feat$/) |
|
223 { |
|
224 if (uc($1) eq uc($name)) |
|
225 { |
|
226 $hit = 1; |
|
227 } |
|
228 else |
|
229 { |
|
230 $bad = 1; |
|
231 } |
|
232 } |
|
233 } |
|
234 close(FILE); |
|
235 return ($hit && !$bad); |
|
236 } |
|
237 |
|
238 sub checkHint |
|
239 { |
|
240 my $file = shift; |
|
241 my $hint = shift; |
|
242 |
|
243 open(FILE, $file) or return 0; |
|
244 while (<FILE>) |
|
245 { |
|
246 if (/^$hint\s*$/) |
|
247 { |
|
248 close(FILE); |
|
249 return 1; |
|
250 } |
|
251 } |
|
252 close(FILE); |
|
253 return 0; |
|
254 } |
|
255 |
|
256 # Check hash and feature list matches |
|
257 sub CompareHashAndFeatures |
|
258 { |
|
259 return if !$_[0] || !$_[1]; |
|
260 return $_[1] if $_[0] eq Digest::MD5::md5_hex($_[1]); |
|
261 } |