1 /* 2 * Copyright (C) 2017 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 17 package com.android.dx.util; 18 19 import static org.junit.Assert.assertEquals; 20 21 import java.util.Arrays; 22 import org.junit.Test; 23 24 public final class ByteArrayAnnotatedOutputTest { 25 @Test 26 public void testArrayZeroedOut() { 27 int length = 100; 28 byte[] data = new byte[length]; 29 Arrays.fill(data, (byte) 0xFF); 30 31 ByteArrayAnnotatedOutput output = new ByteArrayAnnotatedOutput(data); 32 33 output.writeZeroes(length); 34 35 for (int i = 0; i < length; i++) { 36 assertEquals("Position " + i + " has not been zeroed out", 0, data[i]); 37 } 38 } 39 40 @Test 41 public void testArrayAligned() { 42 int length = 16; 43 byte[] data = new byte[length]; 44 Arrays.fill(data, (byte) 0xFF); 45 46 ByteArrayAnnotatedOutput output = new ByteArrayAnnotatedOutput(data); 47 48 // write at least one byte, so alignment is not correct 49 output.writeByte(0); 50 output.alignTo(length); 51 52 for (int i = 0; i < length; i++) { 53 assertEquals("Position " + i + " has not been zeroed out", 0, data[i]); 54 } 55 } 56 } 57