Source Code Cross Referenced for RuntimeAdditionalTest0.java in  » Apache-Harmony-Java-SE » java-package » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Serguei S.Zapreyev
020:         * @version $Revision$
021:         */package java.lang;
022:
023:        import java.io.BufferedReader;
024:        import java.io.InputStreamReader;
025:        import java.io.File;
026:
027:        import junit.framework.TestCase;
028:
029:        /*
030:         * Created on March 29, 2006
031:         *
032:         * This RuntimeAdditionalTest class is used to test the Core API Runtime class
033:         * 
034:         */
035:
036:        /**
037:         * ###############################################################################
038:         * ###############################################################################
039:         * TODO: 1.
040:         * ###############################################################################
041:         * ###############################################################################
042:         */
043:
044:        public class RuntimeAdditionalTest0 extends TestCase {
045:            public static String os;
046:
047:            public static String cm = null;
048:            public static String javaStarter = "java";
049:            public static String catStarter = null;
050:            public static String treeStarter = null;
051:            public static String psStarter = null;
052:            public static String killStarter = null;
053:            static {
054:                if (System.getProperty("os.name").toLowerCase().indexOf(
055:                        "windows") != -1) {
056:                    os = "Win";
057:                    String pathList = System.getProperty("java.library.path");
058:                    String[] paths = pathList.split(File.pathSeparator);
059:                    int ind1;
060:                    for (ind1 = 0; ind1 < paths.length; ind1++) {
061:                        if (paths[ind1] == null) {
062:                            continue;
063:                        }
064:                        File asf = new java.io.File(paths[ind1]
065:                                + File.separator + "cmd.exe");
066:                        if (asf.exists()) {
067:                            cm = paths[ind1] + File.separator + "cmd.exe";
068:                            break;
069:                        }
070:                        asf = new java.io.File(paths[ind1] + File.separator
071:                                + "cat.exe");
072:                        if (asf.exists()) {
073:                            catStarter = paths[ind1] + File.separator
074:                                    + "cat.exe";
075:                            break;
076:                        }
077:                        asf = new java.io.File(paths[ind1] + File.separator
078:                                + "tree.com");
079:                        if (asf.exists()) {
080:                            treeStarter = paths[ind1] + File.separator
081:                                    + "tree.com";
082:                            break;
083:                        }
084:                        asf = new java.io.File(paths[ind1] + File.separator
085:                                + "ps.exe");
086:                        if (asf.exists()) {
087:                            psStarter = paths[ind1] + File.separator + "ps.exe";
088:                            break;
089:                        }
090:                        asf = new java.io.File(paths[ind1] + File.separator
091:                                + "kill.exe");
092:                        if (asf.exists()) {
093:                            killStarter = paths[ind1] + File.separator
094:                                    + "kill.exe";
095:                            break;
096:                        }
097:                    }
098:
099:                    if (cm == null) {
100:                        if (new java.io.File(
101:                                (cm = "C:\\WINNT\\system32\\cmd.exe")).exists()) {
102:                        } else if (new java.io.File(
103:                                (cm = "C:\\WINDOWS\\system32\\cmd.exe"))
104:                                .exists()) {
105:                        } else {
106:                            cm = "cmd.exe";
107:                            System.out
108:                                    .println("### WARNING: cmd.exe hasn't been found! Please, set the path to cmd.exe via java.library.path property.");
109:                        }
110:                    }
111:
112:                    if (catStarter == null) {
113:                        if (new java.io.File(
114:                                (catStarter = "C:\\WINNT\\system32\\cat.exe"))
115:                                .exists()) {
116:                        } else if (new java.io.File(
117:                                (catStarter = "C:\\WINDOWS\\system32\\cat.exe"))
118:                                .exists()) {
119:                        } else if (new java.io.File(
120:                                (catStarter = "C:\\CygWin\\bin\\cat.exe"))
121:                                .exists()) {
122:                        } else {
123:                            cm = "cat.exe";
124:                            System.out
125:                                    .println("### WARNING: cat.exe hasn't been found! Please, set the path to cat.exe via java.library.path property.");
126:                        }
127:                    }
128:
129:                    if (treeStarter == null) {
130:                        if (new java.io.File(
131:                                (treeStarter = "C:\\WINNT\\system32\\tree.com"))
132:                                .exists()) {
133:                        } else if (new java.io.File(
134:                                (treeStarter = "C:\\WINDOWS\\system32\\tree.com"))
135:                                .exists()) {
136:                        } else {
137:                            treeStarter = "tree.com";
138:                            System.out
139:                                    .println("### WARNING: tree.com hasn't been found! Please, set the path to tree.com via java.library.path property.");
140:                        }
141:                    }
142:
143:                    if (psStarter == null) {
144:                        if (new java.io.File(
145:                                (psStarter = "C:\\WINNT\\system32\\ps.exe"))
146:                                .exists()) {
147:                        } else if (new java.io.File(
148:                                (psStarter = "C:\\WINDOWS\\system32\\ps.exe"))
149:                                .exists()) {
150:                        } else if (new java.io.File(
151:                                (psStarter = "C:\\CygWin\\bin\\ps.exe"))
152:                                .exists()) {
153:                        } else {
154:                            psStarter = "ps.exe";
155:                            System.out
156:                                    .println("### WARNING: ps.exe hasn't been found! Please, set the path to ps.exe via java.library.path property.");
157:                        }
158:                    }
159:
160:                    if (killStarter == null) {
161:                        if (new java.io.File(
162:                                (killStarter = "C:\\WINNT\\system32\\kill.exe"))
163:                                .exists()) {
164:                        } else if (new java.io.File(
165:                                (killStarter = "C:\\WINDOWS\\system32\\kill.exe"))
166:                                .exists()) {
167:                        } else if (new java.io.File(
168:                                (killStarter = "C:\\CygWin\\bin\\kill.exe"))
169:                                .exists()) {
170:                        } else {
171:                            killStarter = "kill.exe";
172:                            System.out
173:                                    .println("### WARNING: kill.exe hasn't been found! Please, set the path to kill.exe via java.library.path property.");
174:                        }
175:                    }
176:
177:                    javaStarter = "java";
178:                } else if (System.getProperty("os.name").toLowerCase().indexOf(
179:                        "linux") != -1) {
180:                    os = "Lin";
181:                    cm = "/bin/sh";
182:
183:                    try {
184:                        Process proc = null;
185:                        try {
186:                            proc = Runtime.getRuntime().exec(
187:                                    new String[] { "find", "/usr", "-name",
188:                                            "java" });
189:                        } catch (java.io.IOException e) {
190:                            proc = Runtime.getRuntime().exec(
191:                                    new String[] { "/usr/bin/find", "/usr",
192:                                            "-name", "java" });
193:                        }
194:                        java.io.BufferedReader br = new java.io.BufferedReader(
195:                                new java.io.InputStreamReader(proc
196:                                        .getInputStream()));
197:                        String rV;
198:                        while ((rV = br.readLine()) != null
199:                                && !rV.endsWith("/jre/bin/java")) {
200:                        }
201:                        if (rV != null) {
202:                            javaStarter = "/usr/jrockit-j2sdk1.4.2_04/jre/bin/java";
203:                            javaStarter = "/usr/lib/java/jre/bin/java";
204:                            javaStarter = rV;
205:                        } else {
206:                            /*
207:                            String pathList = System.getProperty("java.library.path");
208:                            String[] paths = pathList.split(File.pathSeparator);
209:                            int ind1;
210:                            for (ind1 = 0; ind1 < paths.length; ind1++) {
211:                            	if (paths[ind1] == null) {
212:                            		continue;
213:                            	}
214:                            	File asf = new java.io.File(paths[ind1] + File.separator
215:                            			+ "java");
216:                            	if (asf.exists()) {
217:                            		javaStarter = paths[ind1] + File.separator + "java";
218:                            		break;
219:                            	}
220:                            }
221:                             */
222:                            javaStarter = "/usr/lib/java/jre/bin/java"; // last hope :)
223:                        }
224:                        System.out.println(javaStarter);
225:                    } catch (java.io.IOException e) {
226:                        System.out
227:                                .println("### WARNING: Some needed external java hasn't been found! A lot of RuntimeAdditionalTest* can fail due to this reason!");
228:                        //System.out
229:                        //        .println("### WARNING: java hasn't been found! You can set the path to java, for example, via java.library.path property.");
230:                    }
231:
232:                    try {
233:                        Process proc = null;
234:                        try {
235:                            proc = Runtime.getRuntime().exec(
236:                                    new String[] { "find", "/usr", "-name",
237:                                            "tree" });
238:                        } catch (java.io.IOException e) {
239:                            proc = Runtime.getRuntime().exec(
240:                                    new String[] { "/usr/bin/find", "/usr",
241:                                            "-name", "tree" });
242:                        }
243:                        java.io.BufferedReader br = new java.io.BufferedReader(
244:                                new java.io.InputStreamReader(proc
245:                                        .getInputStream()));
246:                        String rV;
247:                        while ((rV = br.readLine()) != null
248:                                && !rV.endsWith("/bin/tree")) {
249:                        }
250:                        if (rV != null) {
251:                            treeStarter = rV;
252:                        } else {
253:                            treeStarter = "/usr/bin/tree"; // last hope
254:                        }
255:                        System.out.println(treeStarter);
256:                    } catch (java.io.IOException e) {
257:                        System.out
258:                                .println("### WARNING: tree command hasn't been found! A lot of RuntimeAdditionalTest* can fail due to this reason!");
259:                    }
260:
261:                    try {
262:                        Process proc = null;
263:                        try {
264:                            proc = Runtime.getRuntime().exec(
265:                                    new String[] { "find", "/usr", "-name",
266:                                            "cat" });
267:                        } catch (java.io.IOException e) {
268:                            proc = Runtime.getRuntime().exec(
269:                                    new String[] { "/usr/bin/find", "/usr",
270:                                            "-name", "cat" });
271:                        }
272:                        java.io.BufferedReader br = new java.io.BufferedReader(
273:                                new java.io.InputStreamReader(proc
274:                                        .getInputStream()));
275:                        String rV;
276:                        while ((rV = br.readLine()) != null
277:                                && !rV.endsWith("/bin/cat")) {
278:                        }
279:                        if (rV != null) {
280:                            catStarter = rV;
281:                        } else {
282:                            catStarter = "/bin/cat"; // last hope
283:                        }
284:                        System.out.println(catStarter);
285:                    } catch (java.io.IOException e) {
286:                        System.out
287:                                .println("### WARNING: tree command hasn't been found! A lot of RuntimeAdditionalTest* can fail due to this reason!");
288:                    }
289:
290:                    try {
291:                        Process proc = null;
292:                        try {
293:                            proc = Runtime.getRuntime().exec(
294:                                    new String[] { "find", "/usr", "-name",
295:                                            "ps" });
296:                        } catch (java.io.IOException e) {
297:                            proc = Runtime.getRuntime().exec(
298:                                    new String[] { "/usr/bin/find", "/usr",
299:                                            "-name", "ps" });
300:                        }
301:                        java.io.BufferedReader br = new java.io.BufferedReader(
302:                                new java.io.InputStreamReader(proc
303:                                        .getInputStream()));
304:                        String rV;
305:                        while ((rV = br.readLine()) != null
306:                                && !rV.endsWith("/bin/ps")) {
307:                        }
308:                        if (rV != null) {
309:                            psStarter = rV;
310:                        } else {
311:                            psStarter = "/bin/ps"; // last hope
312:                        }
313:                        //psStarter = "/bin/ps"; // last hope
314:                        System.out.println(psStarter);
315:                    } catch (java.io.IOException e) {
316:                        System.out
317:                                .println("### WARNING: tree command hasn't been found! A lot of RuntimeAdditionalTest* can fail due to this reason!");
318:                    }
319:
320:                    try {
321:                        Process proc = null;
322:                        try {
323:                            proc = Runtime.getRuntime().exec(
324:                                    new String[] { "find", "/usr", "-name",
325:                                            "kill" });
326:                        } catch (java.io.IOException e) {
327:                            proc = Runtime.getRuntime().exec(
328:                                    new String[] { "/usr/bin/find", "/usr",
329:                                            "-name", "kill" });
330:                        }
331:                        java.io.BufferedReader br = new java.io.BufferedReader(
332:                                new java.io.InputStreamReader(proc
333:                                        .getInputStream()));
334:                        String rV;
335:                        while ((rV = br.readLine()) != null
336:                                && !rV.endsWith("/bin/kill")) {
337:                        }
338:                        if (rV != null) {
339:                            killStarter = rV;
340:                        } else {
341:                            killStarter = "/bin/kill"; // last hope
342:                        }
343:                        System.out.println(killStarter);
344:                    } catch (java.io.IOException e) {
345:                        System.out
346:                                .println("### WARNING: tree command hasn't been found! A lot of RuntimeAdditionalTest* can fail due to this reason!");
347:                    }
348:
349:                } else {
350:                    os = "Unk";
351:                }
352:
353:            }
354:
355:            private static File seekFileInDirsHierarchic(File dirToFind,
356:                    String extension, int size) {
357:                File af[] = dirToFind.listFiles();
358:                if (af == null)
359:                    return null;
360:                File dirs[] = new File[af.length];
361:                File res = null;
362:                int j = 0;
363:                int i = 0;
364:                try {
365:                    for (i = 0; i < af.length; i++) {
366:                        if (af[i].isFile()
367:                                && af[i].getName().endsWith(extension)
368:                                && af[i].getName().indexOf(" ") == -1
369:                                && af[i].length() > size
370:                                && (1.5 * size) > af[i].length()) {
371:                            return af[i];
372:                        } else if (af[i].isDirectory()) {
373:                            dirs[j++] = af[i];
374:                        }
375:                    }
376:                    for (i = 0; i < j; i++) {
377:                        if ((res = seekFileInDirsHierarchic(dirs[i], extension,
378:                                size)) != null) {
379:                            return res;
380:                        }
381:                    }
382:                } catch (NullPointerException e) {
383:                    e.printStackTrace();
384:                }
385:                return null;
386:            }
387:
388:            public static String textFile;
389:            static int fileLength = 7000 / (os.equals("Lin") ? 2 : 1); //10000; //50000;
390:            static {
391:                File f = null;
392:                if (os.equals("Win")) {
393:                    if ((f = seekFileInDirsHierarchic(new File(
394:                            "C:\\Program Files"), ".txt", fileLength)) != null) {
395:                        textFile = f.getAbsolutePath();
396:                    }
397:                } else if (os.equals("Lin")) {
398:                    if ((f = seekFileInDirsHierarchic(new File("/opt"), ".txt",
399:                            fileLength)) != null) {
400:                        textFile = f.getAbsolutePath();
401:                    }
402:                    if (textFile == null) {
403:                        if ((f = seekFileInDirsHierarchic(new File("/usr"),
404:                                ".txt", fileLength)) != null) {
405:                            textFile = f.getAbsolutePath();
406:                        }
407:                    }
408:                } else {
409:                    textFile = null;
410:                }
411:                if (textFile == null)
412:                    System.out
413:                            .println("### WARNING: *.txt file hasn't been found! Tests aren't able for correct run.");
414:                System.out.println(textFile);
415:            }
416:
417:            public static String libFile;
418:            static {
419:                File f = null;
420:                if (os.equals("Win")) {
421:                    if ((f = seekFileInDirsHierarchic(new File(
422:                            "C:\\Program Files"), ".dll", fileLength)) != null) {
423:                        libFile = f.getAbsolutePath();
424:                    }
425:                } else if (os.equals("Lin")) {
426:                    if ((f = seekFileInDirsHierarchic(new File("/opt"), ".so",
427:                            fileLength)) != null) {
428:                        libFile = f.getAbsolutePath();
429:                    }
430:                    if (libFile == null) {
431:                        if ((f = seekFileInDirsHierarchic(new File("/usr"),
432:                                ".so", fileLength)) != null) {
433:                            libFile = f.getAbsolutePath();
434:                        }
435:                    }
436:                    if (libFile == null) {
437:                        if ((f = seekFileInDirsHierarchic(new File("/lib"),
438:                                ".so", fileLength)) != null) {
439:                            libFile = f.getAbsolutePath();
440:                        }
441:                    }
442:                } else {
443:                    libFile = null;
444:                }
445:                if (libFile == null)
446:                    System.out
447:                            .println("### WARNING: *.dll|so file hasn't been found! Tests aren't able for correct run.");
448:                System.out.println(libFile);
449:            }
450:
451:            /*
452:             * static String exeFile; static { File f = null; if (os.equals("Win")) { if
453:             * ((f = seekFileInDirsHierarchic(new File("C:\\Program Files"), ".exe",
454:             * fileLength)) != null ) { exeFile = f.getAbsolutePath(); } } else if
455:             * (os.equals("Lin")){ if ((f = seekFileInDirsHierarchic(new File("/opt"),
456:             * ".exe", fileLength)) != null ) { exeFile = f.getAbsolutePath(); } if (exeFile ==
457:             * null) { if ((f = seekFileInDirsHierarchic(new File("/usr"), ".exe",
458:             * fileLength)) != null ) { exeFile = f.getAbsolutePath(); } } } else { exeFile =
459:             * null; } if (exeFile == null) System.out.println("### WARNING: *.exe file
460:             * hasn't been found! Tests aren't able for correct run.");
461:             * System.out.println(exeFile); }
462:             */
463:
464:            protected void setUp() throws Exception {
465:            }
466:
467:            protected void tearDown() throws Exception {
468:            }
469:
470:            /**
471:             * using the InputStream.read, OutputStream.write; chain of Process.waitFor,
472:             * Process.destroy, Process.waitFor, Process.exitValue
473:             */
474:            public void test_1() {
475:                System.out.println("==test_1===");
476:                String cmnd = null;
477:                if (os.equals("Win")) {
478:                    cmnd = cm + " /C date";
479:                } else if (os.equals("Lin")) {
480:                    cmnd = "sh -c \"sh -version\"";
481:                } else {
482:                    fail("WARNING (test_1): unknown operating system.");
483:                }
484:
485:                if (os.equals("Win")) {
486:                    try {
487:                        Process pi3 = Runtime.getRuntime().exec(cmnd);
488:                        try {
489:                            Thread.sleep(2000);
490:                        } catch (Exception e) {
491:                        }
492:                        java.io.OutputStream os = pi3.getOutputStream();
493:                        pi3.getErrorStream();
494:                        java.io.InputStream is = pi3.getInputStream();
495:                        if (is.available() < 1) {
496:                            fail("ERROR (test_1): input stream is empty(1).");
497:                        }
498:                        int ia = is.available();
499:                        byte[] bb = new byte[ia];
500:                        is.read(bb);
501:                        String r1 = new String(bb);
502:                        if (r1.indexOf("The current date is") == -1
503:                                || r1.indexOf("Enter the new date") == -1) {
504:                            fail("ERROR (test_1): unexpected message(1).");
505:                        }
506:                        for (int ii = 0; ii < ia; ii++) {
507:                            bb[ii] = (byte) 0;
508:                        }
509:
510:                        os.write('x');
511:                        os.write('x');
512:                        os.write('-');
513:                        os.write('x');
514:                        os.write('x');
515:                        os.write('-');
516:                        os.write('x');
517:                        os.write('x');
518:                        os.write('\n');
519:                        os.flush();
520:
521:                        try {
522:                            Thread.sleep(2000);
523:                        } catch (Exception e) {
524:                        }
525:                        if (is.available() < 1) {
526:                            fail("ERROR (test_1): input stream is empty(2).");
527:                        }
528:                        ia = is.available();
529:                        byte[] bbb = new byte[ia];
530:                        is.read(bbb);
531:                        r1 = new String(bbb);
532:                        if (r1
533:                                .indexOf("The system cannot accept the date entered") == -1
534:                                && r1.indexOf("Enter the new date") == -1) {
535:                            fail("ERROR (test_1): unexpected message(2).");
536:                        }
537:                        os.write('\n');
538:                        try {
539:                            pi3.exitValue();
540:                        } catch (IllegalThreadStateException e) {
541:                            os.flush();
542:                            try {
543:                                pi3.waitFor();
544:                            } catch (InterruptedException ee) {
545:                            }
546:                        }
547:                        /*System.out.println(*/pi3.waitFor()/*)*/;
548:                        pi3.destroy();
549:                        /*System.out.println(*/pi3.waitFor()/*)*/;
550:                        /*System.out.println(*/pi3.exitValue()/*)*/;
551:                    } catch (Exception eeee) {
552:                        eeee.printStackTrace();
553:                        fail("ERROR (test_1): unexpected exception.");
554:                    }
555:                } else if (os.equals("Lin")) {
556:                    try {
557:                        //Process pi3 = Runtime.getRuntime().exec("sh -c \"sh
558:                        // -version\"");
559:                        Process pi3 = Runtime.getRuntime().exec("sh -c date");
560:                        pi3.getOutputStream();
561:                        pi3.getErrorStream();
562:                        java.io.InputStream is = pi3.getInputStream();
563:                        try {
564:                            Thread.sleep(1000);
565:                        } catch (Exception e) {
566:                        }
567:                        if (is.available() < 1) {
568:                            fail("ERROR (test_1): input stream is empty(1).");
569:                        }
570:                        int ia = is.available();
571:                        byte[] bb = new byte[ia];
572:                        is.read(bb);
573:                        String r1 = new String(bb);
574:                        if (r1.indexOf("S") == -1 && r1.indexOf("M") == -1
575:                                && r1.indexOf("T") == -1
576:                                && r1.indexOf("W") == -1
577:                                && r1.indexOf("F") == -1) {
578:                            fail("ERROR (test_1): unexpected message(1)." + r1);
579:                        }
580:                        for (int ii = 0; ii < ia; ii++) {
581:                            bb[ii] = (byte) 0;
582:                        }
583:
584:                        Process pi4 = Runtime.getRuntime().exec("sh -c sh");
585:                        java.io.OutputStream os4 = pi4.getOutputStream();
586:                        pi4.getErrorStream();
587:                        pi4.getInputStream();
588:
589:                        try {
590:                            Thread.sleep(1000);
591:                        } catch (Exception e) {
592:                        }
593:                        try {
594:                            pi4.exitValue();
595:                            fail("ERROR (test_1): process should exist.");
596:                        } catch (IllegalThreadStateException e) {
597:                        }
598:                        os4.write('e');
599:                        os4.write('x');
600:                        os4.write('i');
601:                        os4.write('t');
602:                        os4.write('\n');
603:                        os4.flush();
604:                        try {
605:                            Thread.sleep(1000);
606:                        } catch (Exception e) {
607:                        }
608:                        try {
609:                            pi4.exitValue();
610:                        } catch (IllegalThreadStateException e) {
611:                            fail("ERROR (test_1): process should be destroyed.");
612:                        }
613:                        /*System.out.println(*/pi4.waitFor()/*)*/;
614:                        pi4.destroy();
615:                        /*System.out.println(*/pi4.waitFor()/*)*/;
616:                        /*System.out.println(*/pi4.exitValue()/*)*/;
617:                    } catch (Exception eeee) {
618:                        eeee.printStackTrace();
619:                        fail("ERROR (test_1): unexpected exception.");
620:                    }
621:                }
622:            }
623:
624:            ////////////// Common additional service: ///////////////
625:            static java.io.DataOutputStream ps = null;
626:            static {
627:                try {
628:                    //String str = ":>";
629:                    File fff = null;
630:                    //fff = new java.io.File("C:\\IJE\\orp\\ZSS\\___ttttt"+System.getProperty("java.vm.name")+".txt");
631:                    //fff = new java.io.File("/nfs/ins/proj/drl/coreapi/ZSS/DRL_VM/___ttttt"+System.getProperty("java.vm.name")+".txt");
632:                    fff = new File(System.getProperty("java.io.tmpdir")
633:                            + File.separator
634:                            + "_messageOf_"
635:                            + ((System.getProperty("java.vm.name").indexOf(
636:                                    "DRL") != -1) ? System
637:                                    .getProperty("java.vm.name") : "XXX") + "_"
638:                            + System.getProperty("user.name") + ".txt");
639:                    fff.createNewFile();
640:                    ps = new java.io.DataOutputStream(
641:                            new java.io.FileOutputStream(fff));
642:                    //ps.writeBytes(System.getProperties().toString());
643:                    //new Throwable().printStackTrace(ps);
644:                } catch (Throwable e) {
645:                    //if(System.getProperty("java.vm.name").indexOf("DRL")!=-1){int i=0,j=0; i=i/j;}
646:                }
647:            }
648:
649:            static void doMessage(String mess) {
650:                //ps.println(mess);
651:                try {
652:                    ps.writeBytes(mess);
653:                } catch (java.io.IOException ee) {
654:                }
655:            }
656:
657:            static void killCat() {
658:                try {
659:                    //String cmnd1 = RuntimeAdditionalTest0.os.equals("Win")?RuntimeAdditionalTest0.cm + " /C ps -Ws":RuntimeAdditionalTest0.cm + " -c \"ps -ef\"";
660:                    //String cmnd1 = RuntimeAdditionalTest0.os.equals("Win")?"C:\\CygWin\\bin\\ps -Ws":RuntimeAdditionalTest0.cm + " -c \"ps -ef\"";
661:                    //String cmnd1 = RuntimeAdditionalTest0.psStarter+(RuntimeAdditionalTest0.os.equals("Win")?" -Ws":" -ef");
662:                    /**/String cmnd1 = RuntimeAdditionalTest0.psStarter
663:                            + (RuntimeAdditionalTest0.os.equals("Win") ? " -Ws"
664:                                    : " -U " + System.getProperty("user.name"));
665:                    Process pi5 = Runtime.getRuntime().exec(cmnd1);
666:                    BufferedReader br = new BufferedReader(
667:                            new InputStreamReader(pi5.getInputStream()));
668:                    boolean flg = true;
669:                    String procValue = null;
670:                    while (!br.ready()) {
671:                    }
672:                    while ((procValue = br.readLine()) != null) {
673:                        RuntimeAdditionalTest0.doMessage("9:" + procValue
674:                                + "\n");
675:                        if (procValue.indexOf("cat") != -1 /*&& (RuntimeAdditionalTest0.os.equals("Win")?true:procValue.indexOf(System.getProperty("user.name")) != -1)*/) {
676:                            flg = false;
677:                            break;
678:                        }
679:                    }
680:                    if (!flg) {
681:                        String as[] = procValue.split(" ");
682:                        RuntimeAdditionalTest0.doMessage("XX:" + procValue
683:                                + "\n");
684:                        for (int i = 0; i < as.length; i++) {
685:                            if (as[i].matches("\\d+")) {
686:                                //cmnd1 = RuntimeAdditionalTest0.os.equals("Win")?RuntimeAdditionalTest0.cm + " /C kill "+as[i]:RuntimeAdditionalTest0.cm + " -c \"kill "+as[i]+"\"";
687:                                //cmnd1 = RuntimeAdditionalTest0.os.equals("Win")?"C:\\WINNT\\system32\\kill "+as[i]:RuntimeAdditionalTest0.cm + " -c \"kill "+as[i]+"\"";
688:                                cmnd1 = RuntimeAdditionalTest0.killStarter
689:                                        + (RuntimeAdditionalTest0.os
690:                                                .equals("Win") ? "" : " -9")
691:                                        + " " + as[i];
692:                                RuntimeAdditionalTest0.doMessage("XXX:" + cmnd1
693:                                        + "\n");
694:                                Runtime.getRuntime().exec(cmnd1);
695:                                Thread.sleep(3000);
696:                            }
697:                        }
698:                    }
699:                } catch (Exception e) {
700:                    fail("ERROR killCat: unexpected exception: " + e.toString());
701:                }
702:            }
703:
704:            static void killTree() {
705:                try {
706:                    //String cmnd1 = RuntimeAdditionalTest0.os.equals("Win")?RuntimeAdditionalTest0.cm + " /C ps -Ws":RuntimeAdditionalTest0.cm + " -c \"ps -ef\"";
707:                    //String cmnd1 = RuntimeAdditionalTest0.psStarter+(RuntimeAdditionalTest0.os.equals("Win")?" -Ws":" -ef");
708:                    /**/String cmnd1 = RuntimeAdditionalTest0.psStarter
709:                            + (RuntimeAdditionalTest0.os.equals("Win") ? " -Ws"
710:                                    : " -U " + System.getProperty("user.name"));
711:                    Process pi5 = Runtime.getRuntime().exec(cmnd1);
712:                    BufferedReader br = new BufferedReader(
713:                            new InputStreamReader(pi5.getInputStream()));
714:                    boolean flg = true;
715:                    String procValue = null;
716:                    while (!br.ready()) {
717:                    }
718:                    while ((procValue = br.readLine()) != null) {
719:                        if (procValue.indexOf("tree") != -1 /*&& (RuntimeAdditionalTest0.os.equals("Win")?true:procValue.indexOf(System.getProperty("user.name")) != -1)*/) {
720:                            flg = false;
721:                            break;
722:                        }
723:                    }
724:                    if (!flg) {
725:                        String as[] = procValue.split(" ");
726:                        for (int i = 0; i < as.length; i++) {
727:                            if (as[i].matches("\\d+")) {
728:                                //cmnd1 = RuntimeAdditionalTest0.os.equals("Win")?RuntimeAdditionalTest0.cm + " /C kill "+as[i]:RuntimeAdditionalTest0.cm + " -c \"kill "+as[i]+"\"";
729:                                cmnd1 = RuntimeAdditionalTest0.killStarter
730:                                        + (RuntimeAdditionalTest0.os
731:                                                .equals("Win") ? "" : " -9")
732:                                        + " " + as[i];
733:                                Runtime.getRuntime().exec(cmnd1);
734:                                Thread.sleep(3000);
735:                            }
736:                        }
737:                    }
738:                } catch (Exception e) {
739:                    fail("ERROR killTree: unexpected exception: "
740:                            + e.toString());
741:                }
742:            }
743:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.