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: package org.apache.harmony.drlvm.tests.regression.h1863;
019:
020: import java.io.*;
021: import junit.framework.TestCase;
022:
023: public class H1863Test extends TestCase {
024:
025: public static int NumberArgs = 50;
026: public final static String ARG_S = "arg";
027: public final static String ARG_S1 = "0123456789";
028:
029: public void test1() {
030: int len = 0;
031: String[] args = new String[NumberArgs];
032: for (int i = 0; i < NumberArgs; i++) {
033: args[i] = ARG_S + Integer.toString(i) + "_";
034: String s = "";
035: for (int j = 0; j < i; j++) {
036: s = s + ARG_S1;
037: }
038: s = s + "a";
039: args[i] = args[i] + s;
040: len += args[i].length();
041: }
042:
043: for (int k = 0; k < 8; k++) {
044: String c = "";
045: String r = "";
046: String fName = null;
047: String fs = File.separator;
048: String s = "org" + fs + "apache" + fs + "harmony" + fs
049: + "drlvm" + fs + "tests" + fs + "regression" + fs
050: + "h1863" + fs + "testExec2_App";
051: try {
052: fName = new File(ClassLoader.getSystemClassLoader()
053: .getResource(s + ".class").toURI()).toString();
054: } catch (Exception e) {
055: fail("Unexpected exception " + e);
056: }
057: String cp = fName.substring(0, fName.indexOf(s));
058: c += System.getProperty("java.home") + File.separator
059: + "bin" + File.separator + "java" + " -cp " + cp
060: + " " + s.replace(File.separatorChar, '.');
061:
062: for (int i = 0; i < NumberArgs; i++) {
063: for (int j = 0; j <= k; j++) {
064: c += " " + args[i];
065: }
066: }
067: c += " ZAPREYEV";
068: try {
069: Process p = Runtime.getRuntime().exec(c);
070: InputStream is = p.getInputStream();
071: while (is.available() == 0) {
072: Thread.sleep(10);
073: }
074: p.waitFor();
075: len = 0;
076: while (is.available() != 0) {
077: char ch = (char) is.read();
078: r += String.valueOf(ch);
079: len++;
080: }
081: int ans = p.exitValue();
082: for (int j = 0; j < 10; j++) {
083: Thread.sleep(100);
084: while (is.available() != 0) {
085: char ch = (char) is.read();
086: r += String.valueOf(ch);
087: System.out.print(ch);
088: len++;
089: }
090: }
091: if (ans != 77) {
092: System.out
093: .println("TEST FAILED: Incorrect exitValue: "
094: + ans);
095: return;
096: }
097: if (r.indexOf("ZAPREYEV") == -1) {
098: fail("Missing last argument");
099: return;
100: }
101: } catch (IOException e) {
102: // could happen on Windows - it's OK when args list is too long
103: break;
104: } catch (Exception e) {
105: e.printStackTrace();
106: fail("Unexpected exception: " + e);
107: }
108: }
109: }
110: }
111:
112: class testExec2_App {
113: public static void main(String[] args) {
114: System.out.println(args[args.length - 1]);
115: System.exit(77);
116: }
117: }
|