Sha256: 95cb2edf3af168d191447d76d3223aaa7704267197bd123ef83658ba14ef78d4

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require 'rubygems'
begin
  require 'rspec' # rspec2
rescue LoadError
  require 'spec' # rspec1
  require 'spec/autorun'
end

# some useful utilities...

require 'sane'
require 'benchmark'
Thread.abort_on_exception = true
require 'timeout'
require 'fileutils'
require 'pathname'

Dir.chdir File.dirname(__FILE__) # always run from the right dir...

begin
  require 'hitimes'
  Benchmark.module_eval {
    def self.realtime
      Hitimes::Interval.measure { yield }
    end
  }
rescue LoadError
  if RUBY_PLATFORM =~ /java/
    require 'java'
    Benchmark.module_eval {
      def self.realtime
        beginy = java.lang.System.nano_time
        yield
        (java.lang.System.nano_time - beginy)/1000000000.0
      end
    }
  else
    puts 'no hitimes available...'
  end
    
end

#for file in Dir[File.dirname(__FILE__) + "/../lib/*"] do
  # don't load them here in case one or other fails...
  # require file
#end

require 'ffi'

module GetPid
  extend FFI::Library
  ffi_lib 'user32', 'kernel32'
  ffi_convention :stdcall
  attach_function :get_process_id_old, :GetProcessId, [ :ulong ], :uint
  
  attach_function :GetWindowThreadProcessId, [:ulong, :pointer], :uint

  def self.get_process_id_from_window hwnd
    out = FFI::MemoryPointer.new(:uint)
    GetWindowThreadProcessId(hwnd, out) # does translation automatically to ptr for us
    out.get_uint32(0) # read_uint
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensible-cinema-0.10.2 spec/common.rb
sensible-cinema-0.10.1 spec/common.rb