1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package libcore.java.io;
18
19import java.io.ByteArrayOutputStream;
20import java.io.DataOutputStream;
21import junit.framework.TestCase;
22
23/**
24 * Basic tests for DataOutputStreams.
25 */
26public class OldAndroidDataOutputStreamTest extends TestCase {
27
28    public void testDataOutputStream() throws Exception {
29        String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
30        ByteArrayOutputStream aa = new ByteArrayOutputStream();
31        DataOutputStream a = new DataOutputStream(aa);
32
33        try {
34            a.write(str.getBytes(), 0, 26);
35            a.write('A');
36
37            assertEquals(27, aa.size());
38            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzA", aa.toString());
39
40            a.writeByte('B');
41            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzAB", aa.toString());
42            a.writeBytes("BYTES");
43            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzABBYTES", aa.toString());
44        } finally {
45            a.close();
46        }
47    }
48}
49