1. Brett Giles
  2. lqpl

Commits

Brett Giles  committed 2c4d939

Significant FEST progress

And some refactoring…

Main issue remaining is that the SWING app will NOT shut down in between scenarios. It seems to be intimately tied in with the cucumber JVM. For example, If I actually do shut it down via using the robot to do a command-Q, it stops cucumber as well.

Because it is still running, the Dump and other panels are created anew with each scenario, then when searching for them, the cucumber system finds multiple instances - and complains.

With Jemmy, I had just left the app running from scenario to scenario - not even trying to shut it down or restart the system. This, however, is somewhat anathema to the concept of clean-room testing, as is supposed to be the case with Cucumber.

Need to consider how best to address this.

Note that when running, a close of the main screen does shut down everything (added disposes of all dialogs and panels - did NOT call System.Exit).

  • Participants
  • Parent commits 29d14d7
  • Branches master

Comments (0)

Files changed (33)

File GUI/src/application_model.rb

View file
+class ModelCreateError < RuntimeError 
+end
+
+class ApplicationModel
+end

File GUI/src/com/drogar/lqpl/about/AboutDialog.java

View file
     }
 
     private void onOK() {
-// add your code here
         dispose();
     }
 
-//    public static void main(String[] args) {
-//        AboutDialog dialog = new AboutDialog();
-//        dialog.pack();
-//        dialog.setVisible(true);
-//        System.exit(0);
-//    }
 
     {
 // GUI initializer generated by IntelliJ IDEA GUI Designer

File GUI/src/com/drogar/lqpl/screens/QuantumEmulatorMainScreen.java

View file
         setUpSpinner(recursionSpinner, 1, 1, 100000, 1);
         setUpSpinner(recursionMultiplierSpinner, 10, 1, 100000, 1);
         setUpSpinner(treeDepthSpinner, 4, 1, 100, 1);
-
+        setDefaultCloseOperation(EXIT_ON_CLOSE);
         spinnerPanel.setVisible(false);
         buttonPanel.setVisible(false);
 
-        this.addWindowListener(new WindowAdapter() {
-            @Override
-            public void windowClosing(WindowEvent windowEvent) {
-                Ruby runtime = null;
-                try {
-                    runtime = Main.getRuntime();
-                } catch (Exception e) {
-                    RubyInstanceConfig config = new RubyInstanceConfig();
-                    runtime = JavaEmbedUtils.initialize(new ArrayList(0), config);
-                }
-
-                runtime.evalScriptlet("require 'exit_handler';ExitHandler.instance.close_servers");
-                System.exit(0);
-            }
-        });
+        // this.addWindowListener(new WindowAdapter() {
+        //   @Override
+        //   public void windowClosing(WindowEvent windowEvent) {
+        //     Ruby runtime = null;
+        //     try {
+        //         runtime = Main.getRuntime();
+        //     } catch (Exception e) {
+        //         RubyInstanceConfig config = new RubyInstanceConfig();
+        //         runtime = JavaEmbedUtils.initialize(new ArrayList(0), config);
+        //     }
+        // 
+        //     runtime.evalScriptlet("require 'exit_handler';ExitHandler.instance.close_servers");
+        //     System.exit(0);
+        //   }
+        //  });
 
     }
 
      * @noinspection ALL
      */
     private void $$$setupUI$$$() {
-        controlPanel = new JPanel();
-        controlPanel.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
-        spinnerPanel = new JPanel();
-        spinnerPanel.setLayout(new GridLayoutManager(4, 2, new Insets(0, 0, 0, 0), -1, -1));
+        controlPanel = new javax.swing.JPanel();
+        controlPanel.setLayout(new GridLayoutManager(3, 1, new java.awt.Insets(0, 0, 0, 0), -1, -1));
+        spinnerPanel = new javax.swing.JPanel();
+        spinnerPanel.setLayout(new GridLayoutManager(4, 2, new java.awt.Insets(0, 0, 0, 0), -1, -1));
         controlPanel.add(spinnerPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
-        stepSpinner = new JSpinner();
+        stepSpinner = new javax.swing.JSpinner();
         spinnerPanel.add(stepSpinner, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        stepLabelForSpinner = new JLabel();
-        stepLabelForSpinner.setText("Step Size");
+        stepLabelForSpinner = new javax.swing.JLabel();
         spinnerPanel.add(stepLabelForSpinner, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        recursionSpinner = new JSpinner();
+        recursionSpinner = new javax.swing.JSpinner();
         spinnerPanel.add(recursionSpinner, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        recursionLabelForSpinner = new JLabel();
-        recursionLabelForSpinner.setText("Recursion Depth");
+        recursionLabelForSpinner = new javax.swing.JLabel();
         spinnerPanel.add(recursionLabelForSpinner, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        treeDepthSpinner = new JSpinner();
+        treeDepthSpinner = new javax.swing.JSpinner();
         spinnerPanel.add(treeDepthSpinner, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        treeDepthLabelForSpinner = new JLabel();
-        treeDepthLabelForSpinner.setText("Tree Depth");
+        treeDepthLabelForSpinner = new javax.swing.JLabel();
         spinnerPanel.add(treeDepthLabelForSpinner, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        recursionMultiplierSpinner = new JSpinner();
+        recursionMultiplierSpinner = new javax.swing.JSpinner();
         spinnerPanel.add(recursionMultiplierSpinner, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        multiplierLabelForSpinner = new JLabel();
-        multiplierLabelForSpinner.setText("Recursion Multiplier");
+        multiplierLabelForSpinner = new javax.swing.JLabel();
         spinnerPanel.add(multiplierLabelForSpinner, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        buttonPanel = new JPanel();
-        buttonPanel.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1));
-        buttonPanel.setEnabled(true);
+        buttonPanel = new javax.swing.JPanel();
+        buttonPanel.setLayout(new GridLayoutManager(1, 3, new java.awt.Insets(0, 0, 0, 0), -1, -1));
         controlPanel.add(buttonPanel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        trimButton = new JButton();
-        trimButton.setText("Trim");
+        trimButton = new javax.swing.JButton();
         buttonPanel.add(trimButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        stepButton = new JButton();
-        stepButton.setText("Step");
+        stepButton = new javax.swing.JButton();
         buttonPanel.add(stepButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        goButton = new JButton();
-        goButton.setText("Go");
+        goButton = new javax.swing.JButton();
         buttonPanel.add(goButton, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
-        messagesPanel = new JPanel();
-        messagesPanel.setLayout(new BorderLayout(0, 0));
+        messagesPanel = new javax.swing.JPanel();
+        messagesPanel.setLayout(new java.awt.BorderLayout(0, 0));
         controlPanel.add(messagesPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
-        final JScrollPane scrollPane1 = new JScrollPane();
+        final javax.swing.JScrollPane scrollPane1 = new javax.swing.JScrollPane();
         messagesPanel.add(scrollPane1, BorderLayout.CENTER);
-        messagesTextArea = new JTextArea();
-        messagesTextArea.setEditable(false);
-        messagesTextArea.setName("messagesTextArea");
+        messagesTextArea = new javax.swing.JTextArea();
         scrollPane1.setViewportView(messagesTextArea);
-        stepLabelForSpinner.setLabelFor(stepSpinner);
-        recursionLabelForSpinner.setLabelFor(recursionSpinner);
-        treeDepthLabelForSpinner.setLabelFor(treeDepthSpinner);
-        multiplierLabelForSpinner.setLabelFor(recursionMultiplierSpinner);
     }
 
     /**
      * @noinspection ALL
      */
-    public JComponent $$$getRootComponent$$$() {
+    public javax.swing.JComponent $$$getRootComponent$$$() {
         return controlPanel;
     }
 }

File GUI/src/dialogs/about/about_controller.rb

View file
 class AboutController < ApplicationController
   set_model 'AboutModel'
   set_view 'AboutView'
-  set_close_action :exit
+  set_close_action :close
 
   def handleAbout(about_event)
     open

File GUI/src/exceptions/stack_descriptor_model_invalid_create.rb

-class StackDescriptorModelInvalidCreate < RuntimeError
-end

File GUI/src/lqpl/lqpl_controller.rb

View file
     add_listener :type => :action, :components => {"the_menu.help_about" => "help_about"}
   end
 
+  def close
+    puts "Called lqpl controller close"
+    all_controllers_dispose
+    file_exit_action_performed
+    super
+  end
+
   def load(*args)
     cmp = CompilerServerConnection.get_instance
     cmp.connect
     @lqpl_emulator_server_connection.connect
   end
 
-  def close()
-  end
-  
   def file_exit_action_performed
     ExitHandler.instance.close_servers
   end
     update_view
   end
 
+  def all_controllers_dispose
+    AboutController.instance.dispose
+    SimulateResultsController.instance.dispose
+    ClassicalStackController.instance.dispose
+    DumpController.instance.dispose
+    ExecutableCodeController.instance.dispose
+    StackTranslationController.instance.dispose
+    QuantumStackController.instance.dispose
+  end
+  
   def file_simulate_action_performed
 
     SimulateResultsController.instance.lqpl_emulator_server_connection = LqplEmulatorServerConnection.get_instance

File GUI/src/lqpl/lqpl_model.rb

View file
-class LqplModel
+class LqplModel < ApplicationModel
   attr_accessor :spinner_panel_visible, :button_panel_visible
   attr_accessor :step_spinner, :recursion_spinner, :recursion_multiplier_spinner, :tree_depth_spinner
   attr_accessor :go_enabled, :step_enabled

File GUI/src/main.rb

View file
 
 begin
   LqplController.instance.open
+  puts 'Returned from open/close...'
 rescue => e
-  show_error_dialog_and_exit(e)
+  show_error_dialog_and_exit("error",e.to_s)
 end

File GUI/src/manifest.rb

View file
 when Monkeybars::Resolver::IN_JAR_FILE
   # Files to be added only when run from inside a jar file
 end
+
+require 'application_model'
+require 'utility/xml_decode'
+require 'xml_based_model'
 ["server_process_not_found", "invalid_input"].each do |f|
   require "exceptions/"+f
 end

File GUI/src/panels/classical_stack/classical_stack_model.rb

View file
 require 'exceptions/quantum_stack_model_invalid_create'
 
-class ClassicalStackModel
-  include XmlDecode
+class ClassicalStackModel < XmlBasedModel
   attr_accessor :classical_stack_text
   attr_accessor :classical_stack
 
   end
 
   def classical_stack=(xml_input)
-    @classical_stack = check_and_return_value(PATTERN,in_string,ClassicalStackModel::classical_values_to_list)
+    @classical_stack = check_and_return_value(CSTACK_PATTERN,xml_input,
+      lambda { |m| ClassicalStackModel::classical_values_to_list m})
   end
 
   def self.classical_values_to_list(cvals)

File GUI/src/panels/dump/dump_model.rb

View file
 require "panels/dump/dump_call_model"
 require "panels/dump/dump_split_model"
 
-class DumpModel
-  include XmlDecode
+class DumpModel <XmlBasedModel
+
   attr_accessor :dump
   
   def dump=(in_xml)
-    @dump = check_and_return_value(DUMP_PATTERN,in_xml,DumpModel.dump_values_to_list m[1]
+    @dump = check_and_return_value(DUMP_PATTERN,in_xml,
+    lambda { |m| DumpModel::dump_values_to_list m})
   end
 
   def text=(whatev)
   end
 
   def self.dump_values_to_list(dumpvals)
-    values_to_list dumpvals[1], DUMPVALUES_PATTERN  do |ret, dv|
+    values_to_list dumpvals[1], DUMP_LIST_PATTERN  do |ret, dv|
       ret << DumpCallModel.new(dv[1]) if dv[1]
       ret << DumpSplitModel.new(dv[2]) if dv[2]
     end
   end
-  DUMPVALUES_PATTERN = Regexp.new /(<DumpCall>.*?<\/DumpCall>)|(<DumpSplit>.*?<\/DumpSplit>)/
+  DUMP_LIST_PATTERN = Regexp.new /(<DumpCall>.*?<\/DumpCall>)|(<DumpSplit>.*?<\/DumpSplit>)/
   DUMP_PATTERN= Regexp.new /<Dump>(.*?)<\/Dump>/
 end

File GUI/src/panels/dump/dump_split_model.rb

View file
-class DumpSplitModel
+class DumpSplitModel <XmlBasedModel
 
   def initialize(inx)
     self.dumpsplit=inx
 
   def dumpsplit=(in_xml)
     m = DS_PATTERN.match in_xml
-    raise QuantumStackModelInvalidCreate, "Invalid dump split: #{in_xml}" if !m
+    raise ModelCreateError, "Invalid dump split: #{in_xml}" if !m
     @ds_text= m[0]
   end
 

File GUI/src/panels/quantum_stack/descriptor/abstract_descriptor_model.rb

View file
-
-
-
-class AbstractDescriptorModel
-  include XmlDecode
+class AbstractDescriptorModel <XmlBasedModel
   attr_accessor :value
   attr_accessor :name
 
     when /^<Clas/ then ClassicalDescriptorModel.new in_string
     when /^<Qubi/ then QubitDescriptorModel.new in_string
     when /^<Alge/ then DataDescriptorModel.new in_string
-    else raise StackDescriptorModelInvalidCreate, in_string
+    else raise ModelCreateError, in_string
     end
   end
 
   def initialize
-    raise StackDescriptorModelInvalidCreate
+    raise ModelCreateError
   end
 
-  def check_and_return_value(pattern,in_string,data_parser)
-    matched = pattern.match in_string
-    raise StackDescriptorModelInvalidCreate, "Invalid input for #{self.class}: #{in_string}" if ! matched
-    data_parser matched[1]
-  end
+
   
   def length
     return @value.length

File GUI/src/panels/quantum_stack/descriptor/classical_descriptor_model.rb

View file
   LIST_PATTERN = Regexp.new /^(<cint>(-?\d+)<\/cint>)|(<cbool>(True|False)<\/cbool>)/
 
   def initialize(in_string)
-    @value = check_and_return_value(PATTERN,in_string,ClassicalDescriptorModel::parse_list)
+    @value = check_and_return_value(PATTERN,in_string,
+      lambda { |m| ClassicalDescriptorModel::parse_list m})
   end
 
   def self.parse_list(sub_string)
       ret << md[2].to_i if md[2]
       ret << (md[4] == 'True') if md[4]
     end
-    raise StackDescriptorModelInvalidCreate, sub_string if sub_string and sub_string.length > 0 and r.length == 0
+    raise ModelCreateError, sub_string if sub_string and sub_string.length > 0 and r.length == 0
     r
   end
 

File GUI/src/panels/quantum_stack/descriptor/data_descriptor_model.rb

View file
   # match 2
 
   def initialize(in_string)
-    @value = check_and_return_value(PATTERN,in_string,DataDescriptorModel::parse_pairs)
+    @value = check_and_return_value(PATTERN,in_string,
+      lambda { |m| DataDescriptorModel::parse_pairs m})
   end
 
 

File GUI/src/panels/quantum_stack/descriptor/qubit_descriptor_model.rb

View file
   # match 2 and 5
 
   def initialize(in_string)
-    @value = check_and_return_value(PATTERN,in_string,QubitDescriptorModel::parse_list)
+    @value = check_and_return_value(PATTERN,in_string,
+      lambda { |m| QubitDescriptorModel::parse_list m})
   end
 
   def length

File GUI/src/panels/quantum_stack/descriptor/value_descriptor_model.rb

View file
 
   def initialize(in_string)
     matc = PATTERN.match in_string
-    raise StackDescriptorInvalidCreate, in_string if ! matc
+    raise ModelCreateError, in_string if ! matc
     @value = matc[2]
     @name = nil
   end

File GUI/src/panels/quantum_stack/descriptor/zero_descriptor_model.rb

View file
 class ZeroDescriptorModel <AbstractDescriptorModel
 
   def initialize(in_string="<Zero/>")
-    raise StackDescriptorModelInvalidCreate, in_string if in_string != "<Zero/>"
+    raise ModelCreateError, in_string if in_string != "<Zero/>"
     @value = "0"
   end
 

File GUI/src/panels/quantum_stack/quantum_stack_model.rb

View file
 require "panels/quantum_stack/descriptor/qubit_descriptor_model"
 require "panels/quantum_stack/descriptor/data_descriptor_model"
 
-class QuantumStackModel
+class QuantumStackModel < XmlBasedModel
 
   attr_accessor :substacks
   attr_accessor :descriptor

File GUI/src/panels/stack_translation/stack_translation_model.rb

View file
 require 'exceptions/quantum_stack_model_invalid_create'
 
-class StackTranslationModel
+class StackTranslationModel < XmlBasedModel
   attr_accessor :stack_translation
   attr_accessor :text
 

File GUI/src/utility/drawing.rb

View file
   def get_string_size(g,text)
     case text
     when AttributedCharacterIterator then
-      this_font = g.font.derive_font(8.0)
+      this_font = g.font.java_send :deriveFont, [Java::float], 8.0
       this_font.get_string_bounds(text,0, text.end_index, g.font_render_context)
     else g.font.get_string_bounds(text,g.font_render_context)
     end

File GUI/src/xml_based_model.rb

View file
+class XmlBasedModel <ApplicationModel
+  include XmlDecode
+  attr_accessor :value
+  attr_accessor :name
+
+
+  def check_and_return_value(pattern,in_string,data_parser)
+    matched = pattern.match in_string
+    raise ModelCreateError, "Invalid input for #{self.class}: #{in_string}" if ! matched
+    data_parser.call matched[1]
+  end
+
+end

File features/load_an_assembled_qpo.feature

View file
   As a researcher
   I want the program allow me to choose a "*.qpo" program and load it to the server so I can execute it.
 
-  @wip
+
   Scenario:
     When I select "Load" from the "File" menu
     And I load "coin.reference.qpo" from the directory "testdata/qplprograms"

File features/show_and_hide_frames.feature

View file
   As a researcher
   I want the program allow me to show only what i want.
 
-  Background:
+  Scenario:
     When I select "Load" from the "File" menu
     And I load "coin.reference.qpo" from the directory "testdata/qplprograms"
-
-  Scenario:
     Then the frame "Executing Code" should be visible
     When I select "Hide Executing Code" from the "View" menu
     Then the frame "Executing Code" should not be visible
     When I select "Show Executing Code" from the "View" menu
     Then the frame "Executing Code" should be visible
 
+
   Scenario:
+    When I select "Load" from the "File" menu
+    And I load "coin.reference.qpo" from the directory "testdata/qplprograms"
     Then the frame "Stack Translation" should be visible
     When I select "Hide Stack Translation" from the "View" menu
     Then the frame "Stack Translation" should not be visible
     When I select "Show Stack Translation" from the "View" menu
     Then the frame "Stack Translation" should be visible
 
+	@wip
   Scenario:
+    When I select "Load" from the "File" menu
+    And I load "coin.reference.qpo" from the directory "testdata/qplprograms"
     Then the frame "Dump" should be visible
     When I select "Hide Dump" from the "View" menu
     Then the frame "Dump" should not be visible
     Then the frame "Dump" should be visible
 
   Scenario:
+    When I select "Load" from the "File" menu
+    And I load "coin.reference.qpo" from the directory "testdata/qplprograms"
     Then the frame "Classical Stack" should be visible
     When I select "Hide Classical Stack" from the "View" menu
     Then the frame "Classical Stack" should not be visible

File features/step_definitions/compile_an_lqpl_program.rb

View file
   menu_item =  $qe_frame.menu_item_with_path [menu, mitem].to_java(:string)
   menu_item.should_not be_nil
   menu_item.click()
-  sleep 2.0
+  sleep 0.5
 end
 
 

File features/step_definitions/load_an_assembled_qpo.rb

View file
   theButton = $qe_frame.button(JButtonMatcher.with_text button_text)
 
   theButton.should_not == nil
-  theButton.require_visible
+  theButton.should be_edt_visible
 end
 
 Then /^the number spinner "([\w\s]*)" should appear and have value "([\d]*)"$/ do |spinner_label, spin_value|
-
-  theLabel = $qe_frame.label(JLabelMatcher.with_text spinner_label)
-
-  theLabel.should_not == nil
-  theLabel.require_visible
-  lf = GuiActionRunner.execute(LabelForQuery.new theLabel.component)
-  theSpinner = JSpinnerFixture.new($robot,lf)
+  theSpinner = spinner_for_label(spinner_label)
   theSpinner.should_not == nil
+  theSpinner.should be_edt_visible
   theSpinner.text.should == "#{spin_value}"
 end
 
 Then /^the frame "([\w\s]*)" should (not )?be visible$/ do |frame_title,visible|
-   set_frame_ref_var(frame_title)
-   frame_fixture = eval(frame_ref_var_string frame_title)
+   # set_frame_ref_var(frame_title)
+   # frame_fixture = eval(frame_ref_var_string frame_title)
+   frame_fixture = set_and_return_frame_fixture(frame_title)
    if visible == 'not '
-     sleep_until(5) {!frame_fixture.visible?}
+     sleep_until(5) {!frame_fixture.edt_visible?}
      # tries=0
      #      while tries < 5 do
      #        sleep 0.25
      #        break if !frame_fixture.visible?
      #      end
-     frame_fixture.should_not be_visible
+     frame_fixture.should_not be_edt_visible
    else
-     sleep_until(5) {frame_fixture.visible?}
-     frame_fixture.should be_visible
+     sleep_until(5) {frame_fixture.edt_visible?}
+     frame_fixture.should be_edt_visible
    end
 end
 
-Then /^I click the spinner "([\w\s]*)" (up|down) (\d)* times? on the frame "([\w\s]*)"$/ do |spinner_label, direction, count, frm|
-  theSpinner = JSpinnerOperator.new(JLabelOperator.new(eval(frame_name_var_string frm), spinner_label).label_for)
-  spin_button = theSpinner.increase_operator
-  spin_button = theSpinner.decrease_operator if direction == "down"
-  count.to_i.times {|i| spin_button.do_click}
-
+Then /^I click the spinner "([\w\s]*)" (up|down) (\d)* times? on the frame "([\w\s]*)"$/ do |spinner_label, direction, count, frame_title|
+  frame_ref=set_and_return_frame_fixture(frame_title)
+  theSpinner = spinner_for_label(spinner_label,frame_ref)
+  theSpinner.increment(count.to_i) if direction == "up"
+  theSpinner.decrement(count.to_i) if direction == "down"
+  
 end
 
-When /^I click the button "([\w\s]*)" (\d)* times? on the frame "([\w\s]*)"$/ do |button_text, count, frm|
-  theButton = JButtonOperator.new(eval(frame_name_var_string(frm)), button_text)
-  count.to_i.times {|i| theButton.do_click}
+When /^I click the button "([\w\s]*)" (\d)* times? on the frame "([\w\s]*)"$/ do |button_text, count, frame_title|
+  frame_ref=set_and_return_frame_fixture(frame_title)
+  theButton = frame_ref.button(JButtonMatcher.with_text button_text)
+  count.to_i.times {|i| theButton.click}
 
 end
 
-Then /^the selection on the frame "([\w\s]*)" should show ---(.*?)$/ do |frame_name, selec|
-
-  theTabbedPane = JTabbedPaneOperator.new(eval(frame_name_var_string(frame_name)))
-  theTextArea = JTextAreaOperator.new(theTabbedPane.selected_component.viewport.view)
-  theTextArea.selected_text.chomp.should == selec
+Then /^the selection on the frame "([\w\s]*)" should show ---(.*?)$/ do |frame_title, selection|
+  frame_ref=set_and_return_frame_fixture(frame_title)
+  
+  theTabbedPane = frame_ref.tabbed_pane
+  theTextArea = theTabbedPane.edt_selected_component.edt_viewport.edt_view
+  theTextArea.selected_text.chomp.should == selection
 
 end
 
-Then /^the button "([\w\s]*)" on the frame "([\w\s]*)" should be (dis|en)abled$/ do |button_text, frm, dis_or_en|
-  the_button = JButtonOperator.new(eval(frame_name_var_string(frm)), button_text)
-  the_button.enabled.should == (dis_or_en == 'en')
+Then /^the button "([\w\s]*)" on the frame "([\w\s]*)" should be (dis|en)abled$/ do |button_text, frame_title, dis_or_en|
+  frame_ref=set_and_return_frame_fixture(frame_title)
+  the_button = frame_ref.button(JButtonMatcher.with_text button_text)
+  the_button.edt_enabled?.should == (dis_or_en == 'en')
 end

File features/support/component_fixture_extensions.rb

-module ComponentFixtureExtensions
-  #Class does not get into world? Why?
-  class FrameFixture
-    def visible?
-      return GuiActionRunner.execute(GuiQuery.new {
-        def executeInEDT
-          self.target.is_visible
-        end
-      })
-    end
-  end
-end
-
-#World(ComponentFixtureExtensions)

File features/support/component_query.rb

View file
   # Launch the query in the Event Dispatch Thread (EDT),
   # which is the thread reserved for user interfaces.
   #
-  def initialize(component_fixture)
+  def initialize(component)
     super()
-    @component = component_fixture.target
+    @component = component.target if component.class.to_s =~ /Fixture$/
+    @component = component if component.class.to_s =~/Javax|JavaAwt/
   end
   
 end
 
+class LabelForQuery < ComponentQuery
+  def executeInEDT
+    @component.label_for
+  end
+end
+
 class TitleQuery < ComponentQuery
   
   def executeInEDT
   end
 end
 
-# Can't just do as ComponentFixture - need to specify each fixture, it seems.
+class EnabledQuery < ComponentQuery
+  
+  def executeInEDT
+    @component.is_enabled
+  end
+end
+class SelectedComponentQuery < ComponentQuery
+  
+  def executeInEDT
+    @component.selected_component
+  end
+end
+
+
+class ViewportQuery < ComponentQuery
+  
+  def executeInEDT
+    @component.viewport
+  end
+end
+
+
+class ViewQuery < ComponentQuery
+  
+  def executeInEDT
+    @component.view
+  end
+end
+
+class SelectedTextQuery < ComponentQuery
+  
+  def executeInEDT
+    @component.selected_text
+  end
+end
 
-class FrameFixture
-  def visible?
+module EDTQuery
+  
+  def edt_visible?
     return GuiActionRunner.execute(VisibleQuery.new(self))
   end
-end
+  
+  def edt_enabled?
+    return GuiActionRunner.execute(EnabledQuery.new(self))
+  end
+    
+  def edt_title
+    return GuiActionRunner.execute(TitleQuery.new(self))
+  end
+  
+  def edt_label_for
+    return GuiActionRunner.execute(LabelForQuery.new(self))
+  end
+  
+  def edt_selected_text
+    return GuiActionRunner.execute(SelectedTextQuery.new(self))
+  end
+  
+  def edt_viewport
+    return GuiActionRunner.execute(ViewportQuery.new(self))
+  end
+  
+  def edt_selected_component
+    return GuiActionRunner.execute(SelectedComponentQuery.new(self))
+  end
+  
+  def edt_view
+    return GuiActionRunner.execute(ViewQuery.new(self))
+  end
+end
+    
+class ComponentFixture
+  include EDTQuery
+end
+
+class Component
+  include EDTQuery
+end
+
+  

File features/support/component_searches.rb

View file
     end
     found
   end
+  def spinner_for_label(label_text,frm=$qe_frame)
+    theLabel = frm.label(JLabelMatcher.with_text label_text)
+    theLabel.should_not == nil
+    theLabel.should be_edt_visible
+    label_for = theLabel.edt_label_for
+    JSpinnerFixture.new($robot,label_for) 
+  end
 end
 
 World(ComponentSearches)

File features/support/env.rb

View file
   java_import "org.fest.swing.finder."+c
 end
 
-%w{JMenuItemFixture FrameFixture JTextComponentFixture JSpinnerFixture}.each do |c|
+%w{ComponentFixture JMenuItemFixture FrameFixture JTextComponentFixture JSpinnerFixture JLabelFixture JButtonFixture}.each do |c|
   java_import "org.fest.swing.fixture."+c
 end
 
 end
 
 
+java_import java.awt.Component
 
 java_import javax.swing.JButton
 
+java_import java.awt.event.InputEvent
+java_import java.awt.event.KeyEvent
 
 
 class AppStarter < GuiQuery
   end
 end
 
+
 # consider starting up servers now and dropping during at_exit.
 Around do |sc, blk|
 
   $robot = BasicRobot.robot_with_current_awt_hierarchy
   $qe_frame = FrameFixture.new($robot, "Quantum Emulator")
   blk.call
-
+  $robot.press_modifiers(InputEvent::META_MASK)
+  $robot.press_key(KeyEvent::VK_Q)
+  $robot.release_key(KeyEvent::VK_Q)
+#  $qe_frame.close
+  
   $robot.clean_up
   $robot = nil
 
   $qe_frame = nil
-  LqplController.instance.close
+  #LqplController.instance.close
+  runner = nil
+  sleep 2
 end
 
 

File features/support/frame_addon_module.rb

View file
 module FrameAddon
   def frame_ref_var_string(frame_title)
-    case frame_title
-    when "Quantum Emulator" then "$qe_frame"
-    else "@#{frame_title.downcase.gsub(/ /,'_')}"
-    end
+    return  "$qe_frame" if frame_title == "Quantum Emulator" 
+    
+    "@#{frame_title.downcase.gsub(/ /,'_')}"
   end
 
-  def set_frame_ref_var(frame_title)
-    case frame_title
-    when "Quantum Emulator" then return
-    else 
-      # todo - Need to get all components, loop through them and check against
-      # a FrameMatcher to get the right frame, then create. 
-      # use $robot to get ComponentHierarchy - get roots, check the roots, then
-      # check the children recursively and so forth.
-      
-      fnvs = frame_ref_var_string(frame_title)
-      eval "#{fnvs} = WindowFinder.find_frame(FrameMatcher.with_title (\"#{frame_title}\")).using($robot)"
-    end
+
+
+  def set_and_return_frame_fixture(frame_title)
+    return $qe_frame if frame_title == "Quantum Emulator"
+
+    fnvs = frame_ref_var_string(frame_title)
+    eval "#{fnvs} = WindowFinder.find_frame(FrameMatcher.with_title (\"#{frame_title}\")).using($robot)"
+    eval fnvs
   end
   
 end

File features/support/label_for_query.rb

-class LabelForQuery < GuiQuery
-  # Launch the app in the Event Dispatch Thread (EDT),
-  # which is the thread reserved for user interfaces.
-  # FEST will call this method for us before the test.
-  #
-  def initialize(component)
-    super()
-    @comp = component
-  end
-  
-  def executeInEDT
-    @comp.label_for
-  end
-end

File notesOnConvertingToFest.txt

View file
 Had to "name" all the swing items I wanted to find for testing.
+
+Import the base and then extend those with desired methods (e.g., componentfixture...)