package simpledb.unittest;

import simpledb.*;
import simpledb.unittest.Utility.SkeletonFile;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import junit.framework.JUnit4TestAdapter;

public class CatalogTest {

    @Before public void setUp() throws Exception {
	Database.getCatalog().clear();
	Database.getCatalog().addTable(new SkeletonFile(-1), Utility.getTupleDesc(2));
    }

    /**
     * Unit test for Catalog.getTupleDesc()
     */
    @Test public void getTupleDesc() throws Exception {
	TupleDesc expected = Utility.getTupleDesc(2);
	TupleDesc actual = Database.getCatalog().getTupleDesc(-1);
	
	// assertEquals tries to use == here.
	assertTrue(expected.equals(actual));
    }

    /**
     * Unit test for Catalog.getDbFile()
     */
    @Test public void numPages() throws Exception {
	DbFile f = Database.getCatalog().getDbFile(-1);
	
	// NOTE(ghuo): we try not to dig too deeply into the DbFile API here; we
	// rely on HeapFileTest for that. perform some basic checks.
	assertEquals(-1, f.id());
    }

    /**
     * JUnit suite target
     */
    public static junit.framework.Test suite() {
	return new JUnit4TestAdapter(CatalogTest.class);
    }
}

