package edu.mit.csail.uid;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import java.awt.event.InputEvent;
/**
 * Unit test for simple SikuliScript.
 */
public class SikuliScriptTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public SikuliScriptTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( SikuliScriptTest.class );
    }

    // assume the tester is on a mac
    public void _testRegion() throws Exception
    {
      Screen scr = new Screen();
      Match ret = scr.find("test-res/apple.png");
      assertEquals(ret.x,16);
      assertEquals(ret.y,0);
      Region region = new Region(10,0,200,200);
      ret = region.find("test-res/apple.png");
      assertEquals(ret.x,16);
      assertEquals(ret.y,0);
    }


    // assume the tester is on a mac
    public void testRegionClick() throws Exception
    {
      Screen scr = new Screen();
      int ret = scr.click("test-res/apple.png", 0);
      assertTrue(ret==1);
    }

    /**
     * Rigourous Test :-)
     */
    public void _testClick() throws Exception
    {
       SikuliScript script = new SikuliScript();
       int ret = script.click("test-res/apple.png", 0);
       System.out.println( "[click] returns: " + ret);
       assertTrue(ret>0);
    }

    public void _testPaste() throws Exception
    {
       SikuliScript script = new SikuliScript();
       script.switchApp("TextEdit.app");
       script.wait("test-res/textedit-untitled.png", 5000);
       int ret = script.paste(null, "test paste 中文字");
       System.out.println( "[paste] returns: " + ret);
       assertTrue(ret>0);
    }

    public void _testFind() throws Exception
    {
       SikuliScript script = new SikuliScript();
       script.switchApp("Firefox.app");
       Thread.sleep(3000);
       script.type(null, "t", InputEvent.META_MASK);
       script.type(null, "google.com\n");
       Matches ret = script.find("test-res/google.png");
       System.out.println( "[click] returns: " + ret.size());
       assertTrue(ret.size()==1);
    }

    public void _testPrompt() throws Exception {
       SikuliScript script = new SikuliScript();
       String file = script.capture();
       System.out.println("capture: " + file);
       assertNotNull(file);
    
    }
}

@@ -1196,32 +1196,308 @@
 ret==1);%0A    %7D%0A%0A
+    // assume the tester is on a mac%0A    public void testRegionClickOffset() throws Exception%0A    %7B%0A      Screen scr = new Screen();%0A      Pattern ptn = new Pattern(%22test-res/apple.png%22).targetOffset(30,-2);%0A      int ret = scr.click(ptn, 0);%0A      assertTrue(ret==1);%0A    %7D%0A%0A
     /**%0A     * R

test click a pattern with target-offset