source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/record/TestBuffer.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.record;
20
21import junit.framework.*;
22
23/**
24 * A Unit test for Record I/O Buffer class
25 */
26public class TestBuffer extends TestCase {
27 
28  public TestBuffer(String testName) {
29    super(testName);
30  }
31 
32  /**
33   * Test of set method, of class org.apache.hadoop.record.Buffer.
34   */
35  public void testSet() {
36    final byte[] bytes = new byte[10];
37    final Buffer instance = new Buffer();
38   
39    instance.set(bytes);
40   
41    assertEquals("set failed", bytes, instance.get());
42  }
43 
44  /**
45   * Test of copy method, of class org.apache.hadoop.record.Buffer.
46   */
47  public void testCopy() {
48    final byte[] bytes = new byte[10];
49    final int offset = 6;
50    final int length = 3;
51    for (int idx = 0; idx < 10; idx ++) {
52      bytes[idx] = (byte) idx;
53    }
54    final Buffer instance = new Buffer();
55   
56    instance.copy(bytes, offset, length);
57   
58    assertEquals("copy failed", 3, instance.getCapacity());
59    assertEquals("copy failed", 3, instance.get().length);
60    for (int idx = 0; idx < 3; idx++) {
61      assertEquals("Buffer content corrupted", idx+6, instance.get()[idx]);
62    }
63  }
64 
65  /**
66   * Test of getCount method, of class org.apache.hadoop.record.Buffer.
67   */
68  public void testGetCount() {
69    final Buffer instance = new Buffer();
70   
71    final int expResult = 0;
72    final int result = instance.getCount();
73    assertEquals("getSize failed", expResult, result);
74  }
75 
76  /**
77   * Test of getCapacity method, of class org.apache.hadoop.record.Buffer.
78   */
79  public void testGetCapacity() {
80    final Buffer instance = new Buffer();
81   
82    final int expResult = 0;
83    final int result = instance.getCapacity();
84    assertEquals("getCapacity failed", expResult, result);
85   
86    instance.setCapacity(100);
87    assertEquals("setCapacity failed", 100, instance.getCapacity());
88  }
89 
90  /**
91   * Test of truncate method, of class org.apache.hadoop.record.Buffer.
92   */
93  public void testTruncate() {
94    final Buffer instance = new Buffer();
95    instance.setCapacity(100);
96    assertEquals("setCapacity failed", 100, instance.getCapacity());
97   
98    instance.truncate();
99    assertEquals("truncate failed", 0, instance.getCapacity());
100  }
101 
102  /**
103   * Test of append method, of class org.apache.hadoop.record.Buffer.
104   */
105  public void testAppend() {
106    final byte[] bytes = new byte[100];
107    final int offset = 0;
108    final int length = 100;
109    for (int idx = 0; idx < 100; idx++) {
110      bytes[idx] = (byte) (100-idx);
111    }
112   
113    final Buffer instance = new Buffer();
114   
115    instance.append(bytes, offset, length);
116   
117    assertEquals("Buffer size mismatch", 100, instance.getCount());
118   
119    for (int idx = 0; idx < 100; idx++) {
120      assertEquals("Buffer contents corrupted", 100-idx, instance.get()[idx]);
121    }
122   
123  }
124}
Note: See TracBrowser for help on using the repository browser.