Menu

find error in this progrm

Developers
richa
2007-04-04
2013-05-20
  • richa

    richa - 2007-04-04

    Hi there!!

    i've made two clsses one with SwtTest and other is SwtTestTest..
    however, when i try to run this prg as Junit test, i dont get any error n i've to forcibly terminate the error.
    n yes one time it gave me an error at ArrestionError at getinstrumented
    please check the code n do let me know wht the prob is.. where i'm wrong..

    the code is as follows..
    for class SwtTest

    package testexamples;

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.layout.RowData;
    import org.eclipse.swt.layout.RowLayout;
    import org.eclipse.swt.widgets.*;

    public class SwtTest {
        final static String TEXT = "text";
        final static String TEXT1 = "text1";
        final static String TEXT2 = "text2";
        public final  Text text;
        public static Text text2;
        public final Text text1;
        public static final String BUTTON_TEXT = lookupString("button.text");
        public static final String FRAME_TITLE = "frame.title";
        public Shell shell;
        public SwtTest(Display display)
        {
             shell = new Shell (display);
             Label label = new Label (shell, SWT.NONE);
             label.setText ("Enter your name:");
             text = new Text (shell, SWT.BORDER);
             tag(text, TEXT);
             text.setLayoutData (new RowData (100, SWT.DEFAULT));
              text1 = new Text(shell,SWT.BORDER);
                 tag(text1, TEXT1);
             text1.setLayoutData(new RowData(110,SWT.DEFAULT));
              text2 = new Text(shell,SWT.BORDER);
                 tag(text2, TEXT2);
             text2.setLayoutData(new RowData(100,SWT.DEFAULT));
             Button Add = new Button (shell, SWT.PUSH);
             Add.setText ("ADD");
             Add.addSelectionListener(new SelectionAdapter()
             {
                public void widgetSelected(SelectionEvent e)
                {
    //                text.setText("ok");   
                    calculatevalues();
                }

            });
            Button Subtract = new Button (shell, SWT.PUSH);
            Subtract.setText ("Subtract");
            Subtract.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    String s = text.getText();
                    int i = Integer.parseInt(s);
                    System.out.println(s);
                    String s1 = text1.getText();
                    int i1 = Integer.parseInt(s1);
                    System.out.println(s1);
                    int i3 = i-i1;
                    String s2 = ""+i3;
                    System.out.println(s2);
                    text2.setText(s2);
                    System.out.println("Subtracted successfully");
                }
            });
            shell.setDefaultButton (Subtract);
            shell.setLayout (new RowLayout ());
            shell.pack ();
            shell.open ();
        }
       
        public static void main(String[] args)
        {
             Display display = new Display ();
             SwtTest swttest = new SwtTest(display);
            while (!swttest.shell.isDisposed ()) {
                if (!display.readAndDispatch ())
                    display.sleep ();
            }
            display.dispose ();
        }

        public static String formattext2(String i) {
            text2.setText("6");
            return i;
        }
        public static void tag(Widget tagged, String data){
            tagged.setData("name", data); //$NON-NLS-1$
        }
        public void calculatevalues()
        {
            String s = text.getText();
            int i = Integer.parseInt(s);
            System.out.println(s);
            String s1 = text1.getText();
            int i1 = Integer.parseInt(s1);
            System.out.println(s1);
            int i3 = i+i1;
            String s2 = ""+i3;
            System.out.println(s2);
            text2.setText(s2);
            System.out.println("ADD");

        }
         public static String lookupString(String key) {
                return SwtTestStrings.getString(key);
            }
    }

    not the test class n tht is SwtTestTest

    public class SwtTestTest extends SWTTestCase
    {
         protected Shell shell;
         protected WidgetFinder finder;
         private Text text;
         private Text text1;
         private Text text2;
         private Button Add;
         private Button Subtract;
         protected ShellTester shellTester = ShellTester.getShellTester();
         protected ButtonTester buttonTester = ButtonTester.getButtonTester();
         protected TextTester textTester = TextTester.getTextTester();
             
        public SwtTestTest()
         {
             super();
         }
         public static Test Suite()
         {
             return new TestSuite(SwtTestTest.class, SwtTestTest.class.getName());
         }
         protected final Text getTextt() throws WidgetNotFoundException,MultipleWidgetsFoundException
         {
             if (text == null)
             text = findTextt();
             return text;
         }
         protected Text findTextt() throws WidgetNotFoundException, MultipleWidgetsFoundException
         {
            return TextTester.getInstrumentedText(SwtTest.TEXT, SwtTest.FRAME_TITLE);
         }
         protected final Text getText1()throws WidgetNotFoundException,MultipleWidgetsFoundException
         {
             if(text1 == null)
             text1 = findText1();
             return text1;
         }
         protected final Text findText1()throws WidgetNotFoundException, MultipleWidgetsFoundException
         {
            return TextTester.getInstrumentedText(SwtTest.TEXT1, SwtTest.FRAME_TITLE);
         }
         protected final Text getText2() throws WidgetNotFoundException,MultipleWidgetsFoundException
         {
             if(text2 == null)
                 text2 = findText2();
             return text2;
         }
         protected final Text findText2() throws WidgetNotFoundException, MultipleWidgetsFoundException
         {
             return TextTester.getInstrumentedText(SwtTest.TEXT2, SwtTest.FRAME_TITLE);
         }
         protected final Button getAddButton()throws WidgetNotFoundException, MultipleWidgetsFoundException
         {
             if(Add == null)
                 Add = findAddButton();
             return Add;
         }
         protected final Button findAddButton() throws WidgetNotFoundException,MultipleWidgetsFoundException
         {
             return ButtonTester.getInstrumentedButton(SwtTest.BUTTON_TEXT, SwtTest.FRAME_TITLE);
         }
         protected void setup() throws Exception
         {
            assertNull(finder);
            assertNull(shell);
            final Display display = getDisplay();
            finder = BasicFinder.getDefault();
            display.syncExec(new Runnable() {
                public void run() {
                    new SwtTest(display);
                }
            });
    //        WidgetTester.waitForShellShowing(SwtTest.FRAME_TITLE);
            shell = (Shell) finder.find(new TextMatcher(SwtTest.FRAME_TITLE));
            shellTester.actionFocus(shell);
         }
         protected void tearDown() throws Exception
         {
             text = null;
             text1 = null;
             Add = null;
             if (shell != null && !shell.isDisposed())
                    shellTester.close(shell);
                shell = null;
                finder = null;
         }
         public void testAnyNumber() throws Exception
         {
             textTester.actionEnterText(getTextt(), "2");
             textTester.actionEnterText(getText1(), "4");
             buttonTester.actionClick(getAddButton());
             String wanted = SwtTest.formattext2("6");
             String got = textTester.getText(getText2());
            assertEquals("Added correctly", wanted.trim(), got.trim());        
         }
       
    }

    any help!!!!

    thanx:)

     
    • Barrie Treloar

      Barrie Treloar - 2007-04-04

      Have you run this on a command line?
      If you are on windows, when it hangs, press Ctrl+Break and you will get a dump of all running threads.  It should be obvious which thread is stuck, then you need to work out why it is stuck and how to fix it.

       
    • richa

      richa - 2007-04-05

      thanx Barrie for the suggestion.. but i;m running the prg in eclipse as JUnit test.
      n ctrl+Break is not working for me. n my prg do give an error but takes a long time .. like after an hour or so...

      However, i've a doubt, i'm getting a null pointer exception at the line..
      Text ttext1 = (Text)(finder.find(shell, new ClassMatcher(Text.class)));
      assertSame(super.findText1(), ttext1);
      n i'm not able to make out y..
      now finder is the reference variable WidgetFinder class..

      and what is the link between CCT and CCfindingTest??? like how and where is actually CCT calling CCFT??

      last question.. can you tell me if there is any link for abbot.swt api..

      thanx a lot
      regards richa

       

Log in to post a comment.