package Cases;

import java.io.*;
import java.io.File;

import neustore.base.DBIndex;//because we create a object of index.java
import neustore.base.LRUBuffer;//because we create an object of it




public class TestCase3 {

	
	public static void main(String[] args)throws IOException {
		
		//all the pages will be stored under this file name
		String filename3="TESTFILE3";
		File file= new File(filename3);
		if(file.delete())
		{
			 System.out.println("The old file with that name has been deleted");
			 
		}
		else
		{
			System.out.println("The file was not found");
		}
		
		//'buf' is an object of XMLBuffer class. Passews 2 arguments  5=Buffer size and 2048=page size in bytes
		XMLBuffer buf3= new XMLBuffer(5,2048);
		
		//Creating an object of XMLContent class and passing the 'buf3'(buffer) , filename and boolean value 'true' (indicating a new file has to be created with the passed filename)
		//If we do not plan to create a new file for Structure index, then the Constructor of the XMLContent class should send 'false' to its super class
		
		
		//creating an object of XMLContent class to test its methods
		XMLContent XC=new XMLContent(buf3,filename3,1);
		
		//(STATE 7)
		//This code would append the content
		String s=new String("New String");
		DiskAddress addr=XC.appendContent(s);
		
		System.out.println("The appened content adress has Pageid="+addr.PageId+" and starts from "+addr.RecordNumber);
        //in our case should return pageid=4 and starts from 31(if you start addressing the page starting from 1)
		
		
		//This code will test the getContent method
		String str=XC.getContent(addr,10);
		
		System.out.println("The returned string is "+str);
		if(str.equals(s)) //Check wether the arguments passed are correct depending upon your scheme of layout of pages
		{
			System.out.println("The getContent method runs fine");
		}
		else
		{
			System.out.println("The getContent method did not return what we intended");
		}
		
		
		//this code will get the size of the whole content
		int x=XC.getSize();
		System.out.println("The total size of the content is"+x); //this should return 40.(we must insert the content for the first 30 bytes to get this value)
		
		x=XC.deleteContent(addr,10);
		System.out.println("This Exit status of deleteContent is"+x);
		
//		XC.close();//remove the comments if the file needs to be closed before exiting
		
	}//end of main() method
}//end of TestCase3