|
1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 my $fails = 0; |
|
17 my $total = 0; |
|
18 |
|
19 # Each test has an input OBY file and an output OBY file. |
|
20 # runTest assumes there is also a <input>.oby.out file which |
|
21 # contains the expected OBY output. |
|
22 |
|
23 # Adding a "." to the feature variant name (for example using |
|
24 # the option "-DFEATUREVARIANT=.phone") means that buildrom will |
|
25 # look for the variant file in ./phone.var rather than in the |
|
26 # default location of EPOCROOT/epoc32/tools/variant/phone.var |
|
27 |
|
28 # test the minimal OBY file |
|
29 |
|
30 $fails += runTest("-s", "minimal.oby", "result.oby"); |
|
31 $total++; |
|
32 |
|
33 # test the include path from a feature-variant OBY file |
|
34 |
|
35 $fails += runTest("-s -DFEATUREVARIANT=.phone", "var1.oby", "result.oby"); |
|
36 $total++; |
|
37 |
|
38 # test the file substitutions in a feature-variant OBY file |
|
39 |
|
40 $fails += runTest("-s -DFEATUREVARIANT=.phone", "var2.oby", "result.oby"); |
|
41 $total++; |
|
42 |
|
43 # test an OBY file that is on the include path from a feature-variant |
|
44 |
|
45 $fails += runTest("-s -DFEATUREVARIANT=.phone", "varB", "result.oby"); |
|
46 $total++; |
|
47 |
|
48 # test that absolute paths work everywhere |
|
49 |
|
50 createDummyInclude($ENV{'EPOCROOT'} . "epoc32/include/test/abs.hrh"); |
|
51 createDummyInclude($ENV{'EPOCROOT'} . "epoc32/include/test/incA/absA.iby"); |
|
52 createDummyInclude($ENV{'EPOCROOT'} . "epoc32/include/test/incB/absB.iby"); |
|
53 |
|
54 $fails += runTest("-s -DFEATUREVARIANT=.abs", "var3.oby", "result.oby"); |
|
55 $total++; |
|
56 |
|
57 ########################################################################### |
|
58 # report the results and finish |
|
59 |
|
60 print "\n\n$fails test"; |
|
61 print "s" unless ($fails == 1); |
|
62 print " failed (out of $total run).\n"; |
|
63 exit 0; |
|
64 |
|
65 ########################################################################### |
|
66 |
|
67 sub runTest |
|
68 { |
|
69 my $options = shift; |
|
70 my $inFile = shift; |
|
71 my $outFile = shift; |
|
72 my $expFile = "$inFile.out"; |
|
73 |
|
74 my $command = "buildrom -fm=..\\include\\featureUIDs.xml $options $inFile"; |
|
75 |
|
76 # remove the output if it already exists |
|
77 unlink($outFile); |
|
78 |
|
79 # run the command (it will error because we do not have everything |
|
80 # required by rombuild, but we will get an output oby file which |
|
81 # shows whether buildrom did the right thing or not). |
|
82 system($command . " >nul 2>&1"); |
|
83 |
|
84 if (!open(OUTPUT, $outFile)) |
|
85 { |
|
86 print STDERR "FAILED: $command\n\t$outFile was not created\n"; |
|
87 return 1; |
|
88 } |
|
89 |
|
90 if (!open(EXPECT, $expFile)) |
|
91 { |
|
92 print STDERR "FAILED: $command\n\t$expFile was not found\n"; |
|
93 close(OUTPUT); |
|
94 return 1; |
|
95 } |
|
96 |
|
97 my $outLine; |
|
98 my $expLine; |
|
99 my $lineNumber = 1; |
|
100 my $outMissing = 0; |
|
101 my $expMissing = 0; |
|
102 my $nonMatches = 0; |
|
103 |
|
104 while ($expLine = <EXPECT>) |
|
105 { |
|
106 $expLine =~ s/^\s+//; |
|
107 $expLine =~ s/\s+$//; |
|
108 |
|
109 if ($outLine = <OUTPUT>) |
|
110 { |
|
111 $outLine =~ s/^\s+//; |
|
112 $outLine =~ s/\s+$//; |
|
113 |
|
114 if (!($expLine eq $outLine)) |
|
115 { |
|
116 print STDERR "FAILED: $command\n"; |
|
117 print STDERR "\texpected output line $lineNumber was:\n"; |
|
118 print STDERR "\t$expLine\n"; |
|
119 print STDERR "\tactual output line $lineNumber was:\n"; |
|
120 print STDERR "\t$outLine\n"; |
|
121 $nonMatches++; |
|
122 } |
|
123 } |
|
124 else |
|
125 { |
|
126 $outMissing++; |
|
127 } |
|
128 $lineNumber++; |
|
129 } |
|
130 while ($outLine = <OUTPUT>) |
|
131 { |
|
132 $expMissing++; |
|
133 } |
|
134 |
|
135 close(EXPECT); |
|
136 close(OUTPUT); |
|
137 |
|
138 if ($nonMatches) |
|
139 { |
|
140 print STDERR "FAILED: $command\n"; |
|
141 print STDERR "\t$nonMatches lines did not match\n"; |
|
142 return 1; |
|
143 } |
|
144 if ($outMissing) |
|
145 { |
|
146 print STDERR "FAILED: $command\n"; |
|
147 print STDERR "\toutput file $outFile is $outMissing lines too short\n"; |
|
148 return 1; |
|
149 } |
|
150 if ($expMissing) |
|
151 { |
|
152 print STDERR "FAILED: $command\n"; |
|
153 print STDERR "\toutput file $outFile is $expMissing lines too long\n"; |
|
154 return 1; |
|
155 } |
|
156 |
|
157 print STDERR "OK: $command\n"; |
|
158 return 0; # OK |
|
159 } |
|
160 |
|
161 use File::Basename; |
|
162 |
|
163 sub createDummyInclude |
|
164 { |
|
165 my $file = shift; |
|
166 my $dir = dirname($file); |
|
167 |
|
168 mkdir($dir) if (!-d $dir); |
|
169 |
|
170 if (open(FILE, ">$file")) |
|
171 { |
|
172 print FILE "/* test file */\n"; |
|
173 close(FILE); |
|
174 } |
|
175 else |
|
176 { |
|
177 print STDERR "could not write file $file\n"; |
|
178 } |
|
179 } |