4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
30 import SCons.Tool.JavaCommon
32 class parse_javaTestCase(unittest.TestCase):
34 def test_bare_bones(self):
35 """Test a bare-bones class"""
37 pkg_dir, classes = SCons.Tool.JavaCommon.parse_java("""\
43 public static void main(String[] args)
46 /* This tests a former bug where strings would eat later code. */
47 String hello1 = new String("Hello, world!");
53 assert pkg_dir == os.path.join('com', 'sub', 'bar'), pkg_dir
54 assert classes == ['Foo'], classes
56 def test_inner_classes(self):
57 """Test parsing various forms of inner classes"""
59 pkg_dir, classes = SCons.Tool.JavaCommon.parse_java("""\
64 public void execute();
73 public void execute() {
74 System.out.println("In Inner");
78 String s1 = "class A";
79 String s2 = "new Listener() { }";
81 /* new Listener() { } */
84 public static void main(String[] args) {
90 public void execute() {
92 public void execute() {
93 System.out.println("Inside execute()");
102 void use(Listener l) {
110 public void execute() {
117 assert pkg_dir is None, pkg_dir
129 assert classes == expect, classes
131 def test_comments(self):
132 """Test a class with comments"""
134 pkg_dir, classes = SCons.Tool.JavaCommon.parse_java("""\
137 import java.rmi.Naming;
138 import java.rmi.RemoteException;
139 import java.rmi.RMISecurityManager;
140 import java.rmi.server.UnicastRemoteObject;
142 public class Example1 extends UnicastRemoteObject implements Hello {
144 public Example1() throws RemoteException {
148 public String sayHello() {
149 return "Hello World!";
152 public static void main(String args[]) {
153 if (System.getSecurityManager() == null) {
154 System.setSecurityManager(new RMISecurityManager());
158 Example1 obj = new Example1();
160 Naming.rebind("//myhost/HelloServer", obj);
162 System.out.println("HelloServer bound in registry");
163 } catch (Exception e) {
164 System.out.println("Example1 err: " + e.getMessage());
171 assert pkg_dir == os.path.join('com', 'sub', 'foo'), pkg_dir
172 assert classes == ['Example1'], classes
174 def test_arrays(self):
175 """Test arrays of class instances"""
177 pkg_dir, classes = SCons.Tool.JavaCommon.parse_java("""\
179 MyClass abc = new MyClass();
180 MyClass xyz = new MyClass();
181 MyClass _array[] = new MyClass[] {
187 assert pkg_dir == None, pkg_dir
188 assert classes == ['Test'], classes
190 def test_backslash(self):
191 """Test backslash handling"""
193 pkg_dir, classes = SCons.Tool.JavaCommon.parse_java("""\
196 private class MyInternal
199 private final static String PATH = "images\\\\";
202 assert pkg_dir == None, pkg_dir
203 assert classes == ['MyTabs$MyInternal', 'MyTabs'], classes
205 if __name__ == "__main__":
206 suite = unittest.TestSuite()
207 tclasses = [ parse_javaTestCase ]
208 for tclass in tclasses:
209 names = unittest.getTestCaseNames(tclass, 'test_')
210 suite.addTests(map(tclass, names))
211 if not unittest.TextTestRunner().run(suite).wasSuccessful():