// Path: src/main/java/net/bitdroid/utils/StringUtils.java
// public class StringUtils {
// 
// 	static final byte[] HEX_CHAR_TABLE = {
// 		(byte)'0', (byte)'1', (byte)'2', (byte)'3',
// 		(byte)'4', (byte)'5', (byte)'6', (byte)'7',
// 		(byte)'8', (byte)'9', (byte)'a', (byte)'b',
// 		(byte)'c', (byte)'d', (byte)'e', (byte)'f'
// 	};
// 
// 	public static String getHexString(byte[] raw)
// 	throws UnsupportedEncodingException
// 	{
// 		byte[] hex = new byte[2 * raw.length];
// 		int index = 0;
// 
// 		for (byte b : raw) {
// 			int v = b & 0xFF;
// 			hex[index++] = HEX_CHAR_TABLE[v >>> 4];
// 			hex[index++] = HEX_CHAR_TABLE[v & 0xF];
// 		}
// 		return new String(hex, "ASCII");
// 	}
// 
// 	public static void reverse(byte[] b) {
// 		int left  = 0;          // index of leftmost element
// 		int right = b.length-1; // index of rightmost element
// 
// 		while (left < right) {
// 			// exchange the left and right elements
// 			byte temp = b[left];
// 			b[left]  = b[right];
// 			b[right] = temp;
// 
// 			// move the bounds toward the center
// 			left++;
// 			right--;
// 		}
// 	}
// 
// }


import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import net.bitdroid.utils.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
 * Copyright 2011 Christian Decker
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This file is part the BitDroidNetwork Project.
 */

package net.bitdroid.network.wire;





/**
 * @author cdecker
 *
 */
public class TestLittleEndianInputStream {

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for {@link net.bitdroid.network.wire.LittleEndianInputStream#readUnsignedShort()}.
	 * @throws IOException
	 */
	@Test
	public void testReadUnsignedShort() throws IOException {
		byte b[] = new byte[]{(byte) 0xD4, (byte)0x7B};
		LittleEndianInputStream leis = LittleEndianInputStream.wrap(b);
		assertEquals(31700, leis.readUnsignedShort());
	}

	/**
	 * Test method for {@link net.bitdroid.network.wire.LittleEndianInputStream#readUnsignedInt()}.
	 * @throws IOException
	 */
	@Test
	public void testReadUnsignedInt() throws IOException {
		byte b[] = new byte[]{(byte) 0xD4, (byte)0x7B, (byte)0x00, (byte)0x00};
		LittleEndianInputStream leis = LittleEndianInputStream.wrap(b);
		assertEquals(31700, leis.readUnsignedInt());
	}

	/**
	 * Test method for {@link net.bitdroid.network.wire.LittleEndianInputStream#readUnsignedLong()}.
	 * @throws IOException
	 */
	@Test
	public void testReadUnsignedLong() throws IOException {
		BigInteger c = new BigInteger("1311768467463790320");
		byte b[] = c.toByteArray();
// Path: src/main/java/net/bitdroid/utils/StringUtils.java
// public class StringUtils {
// 
// 	static final byte[] HEX_CHAR_TABLE = {
// 		(byte)'0', (byte)'1', (byte)'2', (byte)'3',
// 		(byte)'4', (byte)'5', (byte)'6', (byte)'7',
// 		(byte)'8', (byte)'9', (byte)'a', (byte)'b',
// 		(byte)'c', (byte)'d', (byte)'e', (byte)'f'
// 	};
// 
// 	public static String getHexString(byte[] raw)
// 	throws UnsupportedEncodingException
// 	{
// 		byte[] hex = new byte[2 * raw.length];
// 		int index = 0;
// 
// 		for (byte b : raw) {
// 			int v = b & 0xFF;
// 			hex[index++] = HEX_CHAR_TABLE[v >>> 4];
// 			hex[index++] = HEX_CHAR_TABLE[v & 0xF];
// 		}
// 		return new String(hex, "ASCII");
// 	}
// 
// 	public static void reverse(byte[] b) {
// 		int left  = 0;          // index of leftmost element
// 		int right = b.length-1; // index of rightmost element
// 
// 		while (left < right) {
// 			// exchange the left and right elements
// 			byte temp = b[left];
// 			b[left]  = b[right];
// 			b[right] = temp;
// 
// 			// move the bounds toward the center
// 			left++;
// 			right--;
// 		}
// 	}
// 
// }


// Path: src/test/java/net/bitdroid/network/wire/TestLittleEndianInputStream.java
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import net.bitdroid.utils.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Copyright 2011 Christian Decker
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This file is part the BitDroidNetwork Project.
 */

package net.bitdroid.network.wire;





/**
 * @author cdecker
 *
 */
public class TestLittleEndianInputStream {

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for {@link net.bitdroid.network.wire.LittleEndianInputStream#readUnsignedShort()}.
	 * @throws IOException
	 */
	@Test
	public void testReadUnsignedShort() throws IOException {
		byte b[] = new byte[]{(byte) 0xD4, (byte)0x7B};
		LittleEndianInputStream leis = LittleEndianInputStream.wrap(b);
		assertEquals(31700, leis.readUnsignedShort());
	}

	/**
	 * Test method for {@link net.bitdroid.network.wire.LittleEndianInputStream#readUnsignedInt()}.
	 * @throws IOException
	 */
	@Test
	public void testReadUnsignedInt() throws IOException {
		byte b[] = new byte[]{(byte) 0xD4, (byte)0x7B, (byte)0x00, (byte)0x00};
		LittleEndianInputStream leis = LittleEndianInputStream.wrap(b);
		assertEquals(31700, leis.readUnsignedInt());
	}

	/**
	 * Test method for {@link net.bitdroid.network.wire.LittleEndianInputStream#readUnsignedLong()}.
	 * @throws IOException
	 */
	@Test
	public void testReadUnsignedLong() throws IOException {
		BigInteger c = new BigInteger("1311768467463790320");
		byte b[] = c.toByteArray();
		StringUtils.reverse(b);