|
1 # ################################################################# |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # |
|
5 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
6 # |
|
7 # * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
8 # * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
9 # * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. |
|
10 # |
|
11 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
12 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
|
13 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
14 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
15 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.# |
|
16 # |
|
17 # ################################################################# |
|
18 #!/usr/bin/python |
|
19 |
|
20 |
|
21 # experimentation |
|
22 |
|
23 # ############################################################# |
|
24 class CRendererBase: |
|
25 def RegisterSelf( self, aName, aDescription, aRendererManager ): |
|
26 self.iName = aName |
|
27 self.iDescription = aDescription |
|
28 aRendererManager.AddRenderer( self ) |
|
29 |
|
30 def DoBeginTest( self, aTestName ): |
|
31 return |
|
32 |
|
33 def DoEndTest( self, aTestName ): |
|
34 return |
|
35 |
|
36 def DoReportError( self, aFile, aLine, aResult ): |
|
37 return |
|
38 |
|
39 iName = "CRendererBase!" |
|
40 iDescription = "" |
|
41 |
|
42 |
|
43 class CRendererManager: |
|
44 def __init__( self ): |
|
45 # declare associative list of renderers |
|
46 self.iRendererList = {} |
|
47 |
|
48 def AddRenderer( self, aRenderer ): |
|
49 self.iRendererList[ aRenderer.iName ] = aRenderer |
|
50 print( "Added " + aRenderer.iName ) |
|
51 |
|
52 def ListRenderers( self ): |
|
53 print( "Renderers:" ) |
|
54 for name, renderer in self.iRendererList.items(): |
|
55 print( "\t" + name + "\t" + renderer.iDescription ) |
|
56 |
|
57 print( "" ) |
|
58 |
|
59 |
|
60 def BeginTest( self, aTestName ): |
|
61 for name, renderer in self.iRendererList.items(): |
|
62 renderer.DoBeginTest( aTestName ) |
|
63 |
|
64 def EndTest( self, aTestName ): |
|
65 for name, renderer in self.iRendererList.items(): |
|
66 renderer.DoEndTest( aTestName ) |
|
67 |
|
68 def ReportError( self, aFile, aLine, aResult ): |
|
69 for name, renderer in self.iRendererList.items(): |
|
70 renderer.DoReportError( aFile, aLine, aResult ) |
|
71 |
|
72 |
|
73 # ############################################################# |
|
74 |
|
75 |
|
76 # renderers are to be dropped in arbitarily, much like test scripts, images and embedded files |
|
77 # rest of linescanners uses them via the RendererManager instance. |
|
78 |
|
79 # ############################################################# |
|
80 class CHtmlRenderer( CRendererBase ): |
|
81 def __init__( self, aRendererManager ): |
|
82 self.RegisterSelf( "html", "Classic CodeScanner browsable HTML tree", aRendererManager ) |
|
83 |
|
84 def DoBeginTest( self, aTestName ): |
|
85 self.iFileHandle = open( aTestName + ".html", "w" ) |
|
86 self.iFileHandle.write( "<html>\n<body>\n<h1>" + aTestName + "</h1>\n" ) |
|
87 |
|
88 def DoEndTest( self, aTestName ): |
|
89 self.iFileHandle.write( "</body>\n</html>\n" ) |
|
90 self.iFileHandle.close() |
|
91 |
|
92 def DoReportError( self, aFile, aLine, aResult ): |
|
93 self.iFileHandle.write( "<i>" + aResult + "</i> at " + str( aLine ) + "<br/>\n" ) |
|
94 |
|
95 # ############################################################# |
|
96 |
|
97 |
|
98 |
|
99 # ############################################################# |
|
100 class CMsdevRenderer( CRendererBase ): |
|
101 def __init__( self, aRendererManager ): |
|
102 self.RegisterSelf( "msdev", "Classic MIScan plugin for MSDEV", aRendererManager ) |
|
103 |
|
104 def DoBeginTest( self, aTestName ): |
|
105 self.iErrorCount = 0 |
|
106 return |
|
107 |
|
108 def DoEndTest( self, aTestName ): |
|
109 print( "\n\n" + str( self.iErrorCount ) + " total errors" ) |
|
110 return |
|
111 |
|
112 def DoReportError( self, aFile, aLine, aResult ): |
|
113 self.iErrorCount += 1 |
|
114 # :\Series60Ex\menu\src\aknexmenusubcontainer.cpp(126) : warning: to do comment |
|
115 print( aFile + "(" + str( aLine ) + ") : " + aResult ) |
|
116 |
|
117 |
|
118 # ############################################################# |
|
119 |
|
120 # objects register themselves with rendererManager |
|
121 rendererManager = CRendererManager() |
|
122 |
|
123 CHtmlRenderer( rendererManager ) |
|
124 CMsdevRenderer( rendererManager ) |
|
125 |
|
126 rendererManager.ListRenderers() |
|
127 |
|
128 |
|
129 errorCasesFiles = [ "moose.cpp", |
|
130 "lama.cpp", |
|
131 "underflow.cpp", |
|
132 "wankers.cpp" ] |
|
133 |
|
134 errorCasesLines = [ 56, |
|
135 23, |
|
136 67, |
|
137 42 ] |
|
138 |
|
139 errorCasesMessages = [ "moose farmer in field", |
|
140 "lama shags sheep", |
|
141 "out of budget", |
|
142 "DELL are bad people" ] |
|
143 |
|
144 |
|
145 |
|
146 rendererManager.BeginTest( "arbitarytest case" ) |
|
147 for file, line, error in zip( errorCasesFiles, errorCasesLines, errorCasesMessages ): |
|
148 rendererManager.ReportError( file, line, error ) |
|
149 |
|
150 rendererManager.EndTest( "test harness" ) |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |