001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.modelimpl.trace;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.io.PrintStream;
047: import java.net.InetAddress;
048: import java.net.UnknownHostException;
049: import org.netbeans.modules.cnd.modelimpl.test.ModelImplBaseTestCase;
050: import org.openide.filesystems.FileUtil;
051: import org.openide.util.Utilities;
052:
053: /**
054: * dummy tests
055: * @author vv159170
056: */
057: public class IOTestCase extends ModelImplBaseTestCase {
058:
059: public IOTestCase(String testName) {
060: super (testName);
061: }
062:
063: public void testOut() throws IOException {
064: File output = new File(getWorkDir(), "file.dat"); // NOI18N
065: PrintStream streamOut = new PrintStream(output);
066: PrintStream oldOut = System.out;
067: System.out.println("output in standard before redirect");
068: try {
069: // redirect output
070: System.setOut(streamOut);
071:
072: System.out.println("output in file");
073: } finally {
074: streamOut.close();
075: System.setOut(oldOut);
076: }
077: System.out.println("output in standard after redirect");
078: }
079:
080: public void testErr() throws IOException {
081: File error = new File(getWorkDir(), "file.err"); // NOI18N
082: PrintStream streamErr = new PrintStream(error);
083: PrintStream oldErr = System.err;
084: System.err.println("err in standard before redirect");
085: try {
086: // redirect
087: System.setErr(streamErr);
088:
089: System.err.println("err in file");
090: } finally {
091: streamErr.close();
092: System.setErr(oldErr);
093: }
094: System.err.println("err in standard after redirect");
095: }
096:
097: public void testPath() throws IOException {
098: System.err.println("ipAddr");
099: String path = "/net/endif/export/home3/ide/mars";
100: System.err.println("canonical path " + path + " is "
101: + new File(path).getCanonicalPath());
102: path = "/set/ide/mars";
103: System.err.println("canonical path " + path + " is "
104: + new File(path).getCanonicalPath());
105: path = "/home/vv159170";
106: System.err.println("canonical path " + path + " is "
107: + new File(path).getCanonicalPath());
108: path = "/net/localhost/home/vv159170";
109: System.err.println("canonical path " + path + " is "
110: + new File(path).getCanonicalPath());
111: System.err.println("nonProxy is "
112: + System.getProperty("http.nonProxyHosts"));
113: System.err.println("host is " + System.getenv("env-host"));
114: }
115:
116: public void testIPAndHost() {
117: System.err.println("testIPAndHost");
118: long time = System.currentTimeMillis();
119: try {
120: InetAddress addr = InetAddress.getLocalHost();
121:
122: // Get IP Address
123: byte[] ipAddr = addr.getAddress();
124: System.err.println("IP addreass is "
125: + ((int) ipAddr[0] & 0xFF) + "."
126: + ((int) ipAddr[1] & 0xFF) + "."
127: + ((int) ipAddr[2] & 0xFF) + "."
128: + ((int) ipAddr[3] & 0xFF));
129: // Get hostname
130: String hostname = addr.getHostName();
131: System.err.println("host name is " + hostname);
132: } catch (UnknownHostException e) {
133: }
134: time = System.currentTimeMillis() - time;
135: System.err.println("getting IP and host took " + time + "ms");
136: }
137:
138: public void testWindows() {
139: System.setProperty("os.name", "Windows NT");
140: assertTrue("must be Windows", Utilities.isWindows());
141: }
142:
143: }
|