Source Code Cross Referenced for ByteArrayOutputStreamTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » io » 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 » org package » org.apache.harmony.luni.tests.java.io 
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:        package org.apache.harmony.luni.tests.java.io;
019:
020:        import java.io.ByteArrayOutputStream;
021:        import java.io.FileDescriptor;
022:        import java.io.FileOutputStream;
023:        import java.io.IOException;
024:
025:        import junit.framework.TestCase;
026:
027:        /**
028:         * Automated Test Suite for class java.io.ByteArrayOutputStream
029:         * 
030:         * @see java.io.ByteArrayOutputStream
031:         */
032:        public class ByteArrayOutputStreamTest extends TestCase {
033:
034:            ByteArrayOutputStream bos = null;
035:
036:            public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
037:
038:            /**
039:             * Tears down the fixture, for example, close a network connection. This
040:             * method is called after a test is executed.
041:             */
042:            protected void tearDown() throws Exception {
043:                try {
044:                    bos.close();
045:                } catch (Exception ignore) {
046:                }
047:                super .tearDown();
048:            }
049:
050:            /**
051:             * @tests java.io.ByteArrayOutputStream#ByteArrayOutputStream(int)
052:             */
053:            public void test_ConstructorI() {
054:                bos = new ByteArrayOutputStream(100);
055:                assertEquals("Failed to create stream", 0, bos.size());
056:            }
057:
058:            /**
059:             * @tests java.io.ByteArrayOutputStream#ByteArrayOutputStream()
060:             */
061:            public void test_Constructor() {
062:                bos = new ByteArrayOutputStream();
063:                assertEquals("Failed to create stream", 0, bos.size());
064:            }
065:
066:            /**
067:             * @tests java.io.ByteArrayOutputStream#close()
068:             */
069:            public void test_close() {
070:                // close() does nothing for this implementation of OutputSteam
071:
072:                // The spec seems to say that a closed output stream can't be written
073:                // to. We don't throw an exception if attempt is made to write.
074:                // Right now our implementation doesn't do anything testable but
075:                // should we decide to throw an exception if a closed stream is
076:                // written to, the appropriate test is commented out below.
077:
078:                /***********************************************************************
079:                 * java.io.ByteArrayOutputStream bos = new
080:                 * java.io.ByteArrayOutputStream(); bos.write (fileString.getBytes(), 0,
081:                 * 100); try { bos.close(); } catch (java.io.IOException e) {
082:                 * fail("IOException closing stream"); } try { bos.write
083:                 * (fileString.getBytes(), 0, 100); bos.toByteArray(); fail("Wrote to
084:                 * closed stream"); } catch (Exception e) { }
085:                 **********************************************************************/
086:            }
087:
088:            /**
089:             * @tests java.io.ByteArrayOutputStream#reset()
090:             */
091:            public void test_reset() {
092:                bos = new java.io.ByteArrayOutputStream();
093:                bos.write(fileString.getBytes(), 0, 100);
094:                bos.reset();
095:                assertEquals("reset failed", 0, bos.size());
096:            }
097:
098:            /**
099:             * @tests java.io.ByteArrayOutputStream#size()
100:             */
101:            public void test_size() {
102:                bos = new java.io.ByteArrayOutputStream();
103:                bos.write(fileString.getBytes(), 0, 100);
104:                assertEquals("size test failed", 100, bos.size());
105:                bos.reset();
106:                assertEquals("size test failed", 0, bos.size());
107:            }
108:
109:            /**
110:             * @tests java.io.ByteArrayOutputStream#toByteArray()
111:             */
112:            public void test_toByteArray() {
113:                byte[] bytes;
114:                byte[] sbytes = fileString.getBytes();
115:                bos = new java.io.ByteArrayOutputStream();
116:                bos.write(fileString.getBytes(), 0, fileString.length());
117:                bytes = bos.toByteArray();
118:                for (int i = 0; i < fileString.length(); i++) {
119:                    assertTrue("Error in byte array", bytes[i] == sbytes[i]);
120:                }
121:            }
122:
123:            /**
124:             * @tests java.io.ByteArrayOutputStream#toString(java.lang.String)
125:             */
126:            public void test_toStringLjava_lang_String() throws IOException {
127:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
128:
129:                bos.write(fileString.getBytes(), 0, fileString.length());
130:                assertTrue("Returned incorrect 8859-1 String", bos.toString(
131:                        "8859_1").equals(fileString));
132:
133:                bos = new ByteArrayOutputStream();
134:                bos.write(fileString.getBytes(), 0, fileString.length());
135:                assertTrue("Returned incorrect 8859-2 String", bos.toString(
136:                        "8859_2").equals(fileString));
137:            }
138:
139:            /**
140:             * @tests java.io.ByteArrayOutputStream#toString()
141:             */
142:            public void test_toString() {
143:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
144:                bos.write(fileString.getBytes(), 0, fileString.length());
145:                assertTrue("Returned incorrect String", bos.toString().equals(
146:                        fileString));
147:            }
148:
149:            /**
150:             * @tests java.io.ByteArrayOutputStream#toString(int)
151:             */
152:            @SuppressWarnings("deprecation")
153:            public void test_toStringI() {
154:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
155:                bos.write(fileString.getBytes(), 0, fileString.length());
156:                assertTrue("Returned incorrect String", bos.toString(5)
157:                        .length() == fileString.length());
158:            }
159:
160:            /**
161:             * @tests java.io.ByteArrayOutputStream#write(int)
162:             */
163:            public void test_writeI() {
164:                bos = new ByteArrayOutputStream();
165:                bos.write('t');
166:                byte[] result = bos.toByteArray();
167:                assertEquals("Wrote incorrect bytes", "t", new String(result,
168:                        0, result.length));
169:            }
170:
171:            /**
172:             * @tests java.io.ByteArrayOutputStream#write(byte[], int, int)
173:             */
174:            public void test_write$BII() {
175:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
176:                bos.write(fileString.getBytes(), 0, 100);
177:                byte[] result = bos.toByteArray();
178:                assertTrue("Wrote incorrect bytes", new String(result, 0,
179:                        result.length).equals(fileString.substring(0, 100)));
180:            }
181:
182:            /**
183:             * @tests java.io.ByteArrayOutputStream#write(byte[], int, int)
184:             */
185:            public void test_write$BII_2() {
186:                // Regression for HARMONY-387
187:                ByteArrayOutputStream obj = new ByteArrayOutputStream();
188:                try {
189:                    obj.write(new byte[] { (byte) 0x00 }, -1, 0);
190:                    fail("IndexOutOfBoundsException expected");
191:                } catch (IndexOutOfBoundsException t) {
192:                    assertEquals(
193:                            "IndexOutOfBoundsException rather than a subclass expected",
194:                            IndexOutOfBoundsException.class, t.getClass());
195:                }
196:            }
197:
198:            /**
199:             * @tests java.io.ByteArrayOutputStream#writeTo(java.io.OutputStream)
200:             */
201:            public void test_writeToLjava_io_OutputStream() throws Exception {
202:                ByteArrayOutputStream bos = new ByteArrayOutputStream();
203:                ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
204:                bos.write(fileString.getBytes(), 0, 100);
205:                bos.writeTo(bos2);
206:                assertTrue("Returned incorrect String", bos2.toString().equals(
207:                        fileString.substring(0, 100)));
208:
209:                // Regression test for HARMONY-834
210:                // no exception expected
211:                new ByteArrayOutputStream().writeTo(new FileOutputStream(
212:                        new FileDescriptor()));
213:            }
214:        }
w__ww_.__ja_va___2___s_.c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.