/* * Copyright (c) 2002, Iowa State University * * This file is part of the StickSync project and is licensed * under the BSD license. * * $Id: TestLocation.java,v 1.3 2002/10/29 05:45:16 cclifton Exp $ */ package sticksync; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.Date; /** * This is a test for the Location class. * @author Curtis Clifton * @author Gary T. Leavens * @version $Revision: 1.3 $ */ public class TestLocationNoJUnit { /** * Main method for testing Location. */ public static void main(String[] args) { TestLocationNoJUnit t = new TestLocationNoJUnit(); try { t.setUp(); t.testConstructors(); t.testAbsorbChangesFrom(); t.testCopyTo(); t.testReadable(); t.testWriteable(); t.tearDown(); } catch (IOException e) { System.err.println(e); } catch (Exception e) { System.err.println(e); } } private File[] testFiles; private Location[] testLocs; /* ------------------------------------------------------------------------- * TESTS * -------------------------------------------------------------------------*/ public void testConstructors() { for (int i=0; i < testFiles.length; i++) { Location l1 = new Location(testFiles[i].getPath()); System.out.print("l1.getPath() = "); System.out.println(l1.getPath()); System.out.print("testLocs[" + i + "].getPath() = "); System.out.println(testLocs[i].getPath()); } } public void testReadable() { for (int i=0; i < testLocs.length; i++) { System.out.print("testLocs[" + i + "].readable() = "); System.out.println(testLocs[i].readable()); } } public void testWriteable() { for (int i=0; i < testLocs.length; i++) { System.out.print("testLocs[" + i + "].writeable() = "); System.out.println(testLocs[i].writeable()); testFiles[i].setReadOnly(); System.out.print("after setReadOnly: testLocs[" + i + "].readable() = "); System.out.println(!testLocs[i].writeable()); } } public void testCopyTo() throws IOException { String orig0 = testLocs[0].contentsAsString(); String orig1 = testLocs[1].contentsAsString(); //@ assume !orig0.equals(orig1); Date d = testLocs[0].copyTo(testLocs[1]); System.out.println("Date returned by copyTo = " + d); System.out.print("contents equal after copyTo = "); System.out.println(orig0.equals(testLocs[1].contentsAsString())); System.out.print("testLocs[0].modTime() = "); System.out.println(testLocs[0].modTime()); System.out.print("testLocs[0].modTime() = "); System.out.println(testLocs[1].modTime()); } public void testAbsorbChangesFrom() throws IOException { // !E2! This test assumes merge will fail boolean result = testLocs[0].absorbChangesFrom(testLocs[1]); System.out.print("absorbChangesFrom() returns = "); System.out.println(result); System.out.print("checking contents of location and nearbylocation ..."); System.out.println(testLocs[1].contentsAsString().equals( testLocs[0].getNearbyLocation().contentsAsString())); } /* ------------------------------------------------------------------------- * TEST FIXTURE SETUP/TEARDOWN * -------------------------------------------------------------------------*/ protected void setUp() throws Exception { testFiles = configureTestFiles(2); testLocs = new Location[testFiles.length]; for (int i=0; i