Source Code Cross Referenced for CharArrayReaderTest.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.CharArrayReader;
021:        import java.io.IOException;
022:
023:        public class CharArrayReaderTest extends junit.framework.TestCase {
024:
025:            char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
026:
027:            CharArrayReader cr;
028:
029:            /**
030:             * @tests java.io.CharArrayReader#CharArrayReader(char[])
031:             */
032:            public void test_Constructor$C() throws IOException {
033:                cr = new CharArrayReader(hw);
034:                assertTrue("Failed to create reader", cr.ready());
035:            }
036:
037:            /**
038:             * @tests java.io.CharArrayReader#CharArrayReader(char[], int, int)
039:             */
040:            public void test_Constructor$CII() throws IOException {
041:                cr = new CharArrayReader(hw, 5, 5);
042:                assertTrue("Failed to create reader", cr.ready());
043:
044:                int c = cr.read();
045:                assertTrue("Created incorrect reader--returned '" + (char) c
046:                        + "' intsead of 'W'", c == 'W');
047:            }
048:
049:            /**
050:             * @tests java.io.CharArrayReader#close()
051:             */
052:            public void test_close() {
053:                cr = new CharArrayReader(hw);
054:                cr.close();
055:                try {
056:                    cr.read();
057:                    fail("Failed to throw exception on read from closed stream");
058:                } catch (IOException e) {
059:                    // Expected
060:                }
061:
062:                // No-op
063:                cr.close();
064:            }
065:
066:            /**
067:             * @tests java.io.CharArrayReader#mark(int)
068:             */
069:            public void test_markI() throws IOException {
070:                cr = new CharArrayReader(hw);
071:                cr.skip(5L);
072:                cr.mark(100);
073:                cr.read();
074:                cr.reset();
075:                assertEquals("Failed to mark correct position", 'W', cr.read());
076:            }
077:
078:            /**
079:             * @tests java.io.CharArrayReader#markSupported()
080:             */
081:            public void test_markSupported() {
082:                cr = new CharArrayReader(hw);
083:                assertTrue("markSupported returned false", cr.markSupported());
084:            }
085:
086:            /**
087:             * @tests java.io.CharArrayReader#read()
088:             */
089:            public void test_read() throws IOException {
090:                cr = new CharArrayReader(hw);
091:                assertEquals("Read returned incorrect char", 'H', cr.read());
092:                cr = new CharArrayReader(new char[] { '\u8765' });
093:                assertTrue("Incorrect double byte char", cr.read() == '\u8765');
094:            }
095:
096:            /**
097:             * @tests java.io.CharArrayReader#read(char[], int, int)
098:             */
099:            public void test_read$CII() throws IOException {
100:                char[] c = new char[11];
101:                cr = new CharArrayReader(hw);
102:                cr.read(c, 1, 10);
103:                assertTrue("Read returned incorrect chars",
104:                        new String(c, 1, 10).equals(new String(hw, 0, 10)));
105:            }
106:
107:            /**
108:             * @tests java.io.CharArrayReader#ready()
109:             */
110:            public void test_ready() throws IOException {
111:                cr = new CharArrayReader(hw);
112:                assertTrue("ready returned false", cr.ready());
113:                cr.skip(1000);
114:                assertTrue("ready returned true", !cr.ready());
115:                cr.close();
116:
117:                try {
118:                    cr.ready();
119:                    fail("No exception 1");
120:                } catch (IOException e) {
121:                    // expected
122:                }
123:                try {
124:                    cr = new CharArrayReader(hw);
125:                    cr.close();
126:                    cr.ready();
127:                    fail("No exception 2");
128:                } catch (IOException e) {
129:                    // expected
130:                }
131:            }
132:
133:            /**
134:             * @tests java.io.CharArrayReader#reset()
135:             */
136:            public void test_reset() throws IOException {
137:                cr = new CharArrayReader(hw);
138:                cr.skip(5L);
139:                cr.mark(100);
140:                cr.read();
141:                cr.reset();
142:                assertEquals("Reset failed to return to marker position", 'W',
143:                        cr.read());
144:
145:                // Regression for HARMONY-4357
146:                String str = "offsetHello world!";
147:                char[] data = new char[str.length()];
148:                str.getChars(0, str.length(), data, 0);
149:                int offsetLength = 6;
150:                int length = data.length - offsetLength;
151:
152:                CharArrayReader reader = new CharArrayReader(data,
153:                        offsetLength, length);
154:                reader.reset();
155:                for (int i = 0; i < length; i++) {
156:                    assertEquals(data[offsetLength + i], (char) reader.read());
157:                }
158:            }
159:
160:            /**
161:             * @tests java.io.CharArrayReader#skip(long)
162:             */
163:            public void test_skipJ() throws IOException {
164:                cr = new CharArrayReader(hw);
165:                long skipped = cr.skip(5L);
166:
167:                assertEquals("Failed to skip correct number of chars", 5L,
168:                        skipped);
169:                assertEquals("Skip skipped wrong chars", 'W', cr.read());
170:            }
171:
172:            /**
173:             * Tears down the fixture, for example, close a network connection. This
174:             * method is called after a test is executed.
175:             */
176:            protected void tearDown() {
177:                if (cr != null)
178:                    cr.close();
179:            }
180:        }
ww__w_.__j___av__a__2_s___.__c_om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.