Source

lqpl / GUI / spec / communications / lqpl_emulator_server_connection_spec.rb

require 'spec/spec_helper'

describe LqplEmulatorServerConnection do
  context "creation" do
    context "enforce singleton" do
      before(:each) do
        @sc = nil
      end
      after(:each) do
        @sc.close_down if @sc
      end
      it "gives an error when trying to create with 'new'" do
        expect {@sc=LqplEmulatorServerConnection.new}.to raise_error NoMethodError
      end
      it "allows default creation with a port of 9502" do
        @sc = LqplEmulatorServerConnection.instance
        @sc.port.should == 9502
      end
    end
    context "connection" do
      before :each do
        @sc = LqplEmulatorServerConnection.get_instance
      end
      after(:all) do
        @sc.close_down if @sc
      end
      it "connects to the lqpl-serv process when created" do
        @sc.connect
        @sc.should be_connected
      end
    end
  end
  context "interfaces with the lqpl-serv" do
    before :each do
        @sc = LqplEmulatorServerConnection.get_instance
        @sc.connect
      end
    
    after :all do
      @sc.close_down if @sc
    end
    it "sends QPO code to the lqpl-serv and gets 'Assembled' back" do
      fname = "#{TEST_QP_PATH}/min.reference.qpo"
      flag = @sc.send_load_from_file(10,fname)
      flag.should =~ /Assembled/
    end
  end
  context "execution control" do
    before(:each) do
      @sc = LqplEmulatorServerConnection.get_instance
      @sc.connect
      fname = "#{TEST_QP_PATH}/coin.reference.qpo"
      flag = @sc.send_load_from_file(10,fname)
    end
    after :all do
      @sc.close_down if @sc
    end
    it "allows depth multiples to be set" do
      @sc.send_set_depth_multiplier.should =~ /reset/
    end
    it "steps through a program" do
      @sc.do_step.should =~ /Stepped/
      @sc.do_step(5).should =~ /Stepped/
    end
    it "steps through a program and gives a different status when at the end" do
      @sc.do_step(40).should =~ /executed/
    end
    it "runs a program and gets the status 'executed'" do
      @sc.do_run.should =~ /executed/
    end

    it "trims a stack and gets the status 'trimmed'" do
      @sc.do_trim.should =~ /trimmed/
    end
    it "should allow a step or another run after a run and stil return executed" do
      @sc.do_run
      @sc.do_step.should =~ /executed/
      @sc.do_run.should =~ /executed/
    end
  end
  context "gets the data" do
    before(:each) do
      @sc = LqplEmulatorServerConnection.instance
      @sc.connect
      fname = "#{TEST_QP_PATH}/coin.reference.qpo"
      flag = @sc.send_load_from_file(10,fname)
      @sc.do_step(10) # down one branch of the measure
    end
    after :all do
      @sc.close_down if @sc
    end
    it "returns the qstack" do
      @sc.get_qstack.should =~ /<Qstack/
    end
    it "returns the classical_stack" do
      @sc.get_classical_stack.should =~ /<Classical/
    end
    it "returns the dump" do
      @sc.get_dump.should =~ /<Dump/
    end
    it "returns the code pointer" do
      @sc.code_pointer.should =~ /<pair/
    end
    it "returns the code" do
      @sc.loaded_code.should =~ /<Code/
    end
    it "returns the stack translation" do
      @sc.get_stack_translation.should =~ /<MMap/
    end
    it "returns a simulation" do
      @sc.get_simulate_results.should =~ /<Simulated><double/
    end

  end
end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.