// Path: src/test/java/com/linuxense/javadbf/mocks/NullOutputStream.java
// public class NullOutputStream extends OutputStream {
//     
// 	private long count = 0;
// 	
// 
//     /**
//      * Constructor
//      */
//     public NullOutputStream() {
//         super();
//     }
//     /**
//      * Does nothing - output to <code>/dev/null</code>.
//      * @param b The bytes to write
//      * @param off The start offset
//      * @param len The number of bytes to write
//      */
//     @Override
//     public void write(byte[] b, int off, int len) {
//         this.count+= len;
//     }
// 
//     /**
//      * Does nothing - output to <code>/dev/null</code>.
//      * @param b The byte to write
//      */
//     @Override
//     public void write(int b) {
//         this.count++;
//     }
// 
//     /**
//      * Does nothing - output to <code>/dev/null</code>.
//      * @param b The bytes to write
//      * @throws IOException never
//      */
//     @Override
//     public void write(byte[] b) throws IOException {
//         if (b != null) {
//         	this.count += b.length;
//         }
//     }
//     
//     public long getCount() {
//     	return this.count;
//     }
// 
// }


import org.junit.Assert;
import org.junit.Test;
import com.linuxense.javadbf.mocks.NullOutputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
		try {
			writer = new DBFWriter(baos, Charset.forName("CP866"));	
			DBFField fields[] = new DBFField[1];
			
			fields[0] = new DBFField();
			fields[0].setName("emp_name");
			fields[0].setType(DBFDataType.CHARACTER);
			fields[0].setLength(10);
			writer.setFields(fields);
			writer.addRecord(new Object[] { "Simon" });
			writer.addRecord(new Object[] { "Julian"});
		}
		finally {
			DBFUtils.close(writer);
		}
		byte[] data = baos.toByteArray();
		Assert.assertEquals(0x65, data[29]);
	}
	
	
	@Test
	public void testSetEncodingCP866StringConversion() throws DBFException {
		Charset charset = Charset.forName("CP866");
		String charsetString = charset.toString().toLowerCase();
		
		Assert.assertEquals("ibm866", charsetString);
	}
	
	@Test
	public void testUnicodeAsFieldName() throws IOException {
// Path: src/test/java/com/linuxense/javadbf/mocks/NullOutputStream.java
// public class NullOutputStream extends OutputStream {
//     
// 	private long count = 0;
// 	
// 
//     /**
//      * Constructor
//      */
//     public NullOutputStream() {
//         super();
//     }
//     /**
//      * Does nothing - output to <code>/dev/null</code>.
//      * @param b The bytes to write
//      * @param off The start offset
//      * @param len The number of bytes to write
//      */
//     @Override
//     public void write(byte[] b, int off, int len) {
//         this.count+= len;
//     }
// 
//     /**
//      * Does nothing - output to <code>/dev/null</code>.
//      * @param b The byte to write
//      */
//     @Override
//     public void write(int b) {
//         this.count++;
//     }
// 
//     /**
//      * Does nothing - output to <code>/dev/null</code>.
//      * @param b The bytes to write
//      * @throws IOException never
//      */
//     @Override
//     public void write(byte[] b) throws IOException {
//         if (b != null) {
//         	this.count += b.length;
//         }
//     }
//     
//     public long getCount() {
//     	return this.count;
//     }
// 
// }


// Path: src/test/java/com/linuxense/javadbf/EncodingTest.java
import org.junit.Assert;
import org.junit.Test;
import com.linuxense.javadbf.mocks.NullOutputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

		try {
			writer = new DBFWriter(baos, Charset.forName("CP866"));	
			DBFField fields[] = new DBFField[1];
			
			fields[0] = new DBFField();
			fields[0].setName("emp_name");
			fields[0].setType(DBFDataType.CHARACTER);
			fields[0].setLength(10);
			writer.setFields(fields);
			writer.addRecord(new Object[] { "Simon" });
			writer.addRecord(new Object[] { "Julian"});
		}
		finally {
			DBFUtils.close(writer);
		}
		byte[] data = baos.toByteArray();
		Assert.assertEquals(0x65, data[29]);
	}
	
	
	@Test
	public void testSetEncodingCP866StringConversion() throws DBFException {
		Charset charset = Charset.forName("CP866");
		String charsetString = charset.toString().toLowerCase();
		
		Assert.assertEquals("ibm866", charsetString);
	}
	
	@Test
	public void testUnicodeAsFieldName() throws IOException {
		NullOutputStream output = new NullOutputStream();