diff options
Diffstat (limited to 'spec/ruby/library/win32ole/win32ole')
20 files changed, 448 insertions, 0 deletions
diff --git a/spec/ruby/library/win32ole/win32ole/_getproperty_spec.rb b/spec/ruby/library/win32ole/win32ole/_getproperty_spec.rb new file mode 100644 index 0000000000..650a641f5b --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/_getproperty_spec.rb @@ -0,0 +1,19 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#_getproperty" do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "gets name" do + @ie._getproperty(0, [], []).should =~ /explorer/i + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb b/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb new file mode 100644 index 0000000000..c2fe9a8490 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/_invoke_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#_invoke" do + before :each do + @shell = WIN32OLESpecs.new_ole 'Shell.application' + end + + it "raises ArgumentError if insufficient number of arguments are given" do + lambda { @shell._invoke() }.should raise_error ArgumentError + lambda { @shell._invoke(0) }.should raise_error ArgumentError + lambda { @shell._invoke(0, []) }.should raise_error ArgumentError + end + + it "dispatches the method bound to a specific ID" do + @shell._invoke(0x60020002, [37], [WIN32OLE::VARIANT::VT_VARIANT]).title.should =~ /System32/i + end + + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/codepage_spec.rb b/spec/ruby/library/win32ole/win32ole/codepage_spec.rb new file mode 100644 index 0000000000..c84593871d --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/codepage_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE.codepage=" do + it "sets codepage" do + cp = WIN32OLE.codepage + WIN32OLE.codepage = WIN32OLE::CP_UTF8 + WIN32OLE.codepage.should == WIN32OLE::CP_UTF8 + WIN32OLE.codepage = cp + end + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/connect_spec.rb b/spec/ruby/library/win32ole/win32ole/connect_spec.rb new file mode 100644 index 0000000000..ee480a727c --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/connect_spec.rb @@ -0,0 +1,17 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE.connect" do + it "creates WIN32OLE object given valid argument" do + obj = WIN32OLE.connect("winmgmts:") + obj.should be_kind_of WIN32OLE + end + + it "raises TypeError when given invalid argument" do + lambda { WIN32OLE.connect 1 }.should raise_error TypeError + end + + end +end diff --git a/spec/ruby/library/win32ole/win32ole/const_load_spec.rb b/spec/ruby/library/win32ole/win32ole/const_load_spec.rb new file mode 100644 index 0000000000..a3c50f215e --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/const_load_spec.rb @@ -0,0 +1,34 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE.const_load when passed Shell.Application OLE object" do + before :each do + @win32ole = WIN32OLESpecs.new_ole 'Shell.Application' + end + + it "loads constant SsfWINDOWS into WIN32OLE namespace" do + WIN32OLE.const_defined?(:SsfWINDOWS).should be_false + WIN32OLE.const_load @win32ole + WIN32OLE.const_defined?(:SsfWINDOWS).should be_true + end + end + + describe "WIN32OLE.const_load when namespace is specified" do + before :each do + module WIN32OLE_RUBYSPEC; end + @win32ole = WIN32OLESpecs.new_ole 'Shell.Application' + end + + it "loads constants into given namespace" do + module WIN32OLE_RUBYSPEC; end + + WIN32OLE_RUBYSPEC.const_defined?(:SsfWINDOWS).should be_false + WIN32OLE.const_load @win32ole, WIN32OLE_RUBYSPEC + WIN32OLE_RUBYSPEC.const_defined?(:SsfWINDOWS).should be_true + + end + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/constants_spec.rb b/spec/ruby/library/win32ole/win32ole/constants_spec.rb new file mode 100644 index 0000000000..2a04511305 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/constants_spec.rb @@ -0,0 +1,44 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE class" do + it "defines constant CP_ACP" do + WIN32OLE::CP_ACP.should == 0 + end + + it "defines constant CP_OEMCP" do + WIN32OLE::CP_OEMCP.should == 1 + end + + it "defines constant CP_MACCP" do + WIN32OLE::CP_MACCP.should == 2 + end + + it "defines constant CP_THREAD_ACP" do + WIN32OLE::CP_THREAD_ACP.should == 3 + end + + it "defines constant CP_SYMBOL" do + WIN32OLE::CP_SYMBOL.should == 42 + end + + it "defines constant CP_UTF7" do + WIN32OLE::CP_UTF7.should == 65000 + end + + it "defines constant CP_UTF8" do + WIN32OLE::CP_UTF8.should == 65001 + end + + it "defines constant LOCALE_SYSTEM_DEFAULT" do + WIN32OLE::LOCALE_SYSTEM_DEFAULT.should == 0x0800 + end + + it "defines constant LOCALE_USER_DEFAULT" do + WIN32OLE::LOCALE_USER_DEFAULT.should == 0x0400 + end + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/create_guid_spec.rb b/spec/ruby/library/win32ole/win32ole/create_guid_spec.rb new file mode 100644 index 0000000000..17a7df10be --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/create_guid_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE.create_guid" do + it "generates guid with valid format" do + WIN32OLE.create_guid.should =~ /^\{[A-Z0-9]{8}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{4}\-[A-Z0-9]{12}/ + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/invoke_spec.rb b/spec/ruby/library/win32ole/win32ole/invoke_spec.rb new file mode 100644 index 0000000000..41752de359 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/invoke_spec.rb @@ -0,0 +1,19 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#invoke" do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "get name by invoking 'Name' OLE method" do + @ie.invoke('Name').should =~ /explorer/i + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/locale_spec.rb b/spec/ruby/library/win32ole/win32ole/locale_spec.rb new file mode 100644 index 0000000000..7cf4d9bc98 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/locale_spec.rb @@ -0,0 +1,31 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE.locale" do + it "gets locale" do + WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT + end + end + + describe "WIN32OLE.locale=" do + it "sets locale to Japanese, if available" do + begin + begin + WIN32OLE.locale = 1041 + rescue WIN32OLERuntimeError + STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_set is skipped(Japanese locale is not installed)") + return + end + + WIN32OLE.locale.should == 1041 + WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT + lambda { WIN32OLE.locale = 111 }.should raise_error WIN32OLERuntimeError + WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT + ensure + WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT + end + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/new_spec.rb b/spec/ruby/library/win32ole/win32ole/new_spec.rb new file mode 100644 index 0000000000..78f141b608 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/new_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLESpecs.new_ole" do + it "creates a WIN32OLE object from OLE server name" do + shell = WIN32OLESpecs.new_ole 'Shell.Application' + shell.should be_kind_of WIN32OLE + end + + it "creates a WIN32OLE object from valid CLSID" do + shell = WIN32OLESpecs.new_ole("{13709620-C279-11CE-A49E-444553540000}") + shell.should be_kind_of WIN32OLE + end + + it "raises TypeError if argument cannot be converted to String" do + lambda { WIN32OLESpecs.new_ole(42) }.should raise_error( TypeError ) + end + + it "raises WIN32OLERuntimeError if invalid string is given" do + lambda { WIN32OLESpecs.new_ole('foo') }.should raise_error( WIN32OLERuntimeError ) + end + + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb new file mode 100644 index 0000000000..82b5eb2680 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_func_methods" do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "raises ArgumentError if argument is given" do + lambda { @ie.ole_func_methods(1) }.should raise_error ArgumentError + end + + it "returns an array of WIN32OLE_METHODs" do + @ie.ole_func_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + end + + it "contains a 'AddRef' method for Internet Explorer" do + @ie.ole_func_methods.map { |m| m.name }.include?('AddRef').should be_true + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb new file mode 100644 index 0000000000..3ec92d3efc --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_get_methods" do + + before :each do + @win32ole = WIN32OLESpecs.new_ole('Shell.Application') + end + + it "returns an array of WIN32OLE_METHOD objects" do + @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE_METHOD}.should be_true + end + + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_method_help_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_method_help_spec.rb new file mode 100644 index 0000000000..45b8e93eac --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_method_help_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../fixtures/classes', __FILE__) +require File.expand_path('../shared/ole_method', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_method_help" do + it_behaves_like :win32ole_ole_method, :ole_method_help + + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_method_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_method_spec.rb new file mode 100644 index 0000000000..cb1d1d172b --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_method_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../fixtures/classes', __FILE__) +require File.expand_path('../shared/ole_method', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_method" do + it_behaves_like :win32ole_ole_method, :ole_method + + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb new file mode 100644 index 0000000000..bba2aa73ae --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_methods" do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "raises ArgumentError if argument is given" do + lambda { @ie.ole_methods(1) }.should raise_error ArgumentError + end + + it "returns an array of WIN32OLE_METHODs" do + @ie.ole_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + end + + it "contains a 'AddRef' method for Internet Explorer" do + @ie.ole_methods.map { |m| m.name }.include?('AddRef').should be_true + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb new file mode 100644 index 0000000000..eede93bb87 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_obj_help" do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "raises ArgumentError if argument is given" do + lambda { @ie.ole_obj_help(1) }.should raise_error ArgumentError + end + + it "returns an instance of WIN32OLE_TYPE" do + @ie.ole_obj_help.kind_of?(WIN32OLE_TYPE).should be_true + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb new file mode 100644 index 0000000000..5334e7a47d --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb @@ -0,0 +1,27 @@ +require File.expand_path('../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#ole_put_methods" do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "raises ArgumentError if argument is given" do + lambda { @ie.ole_put_methods(1) }.should raise_error ArgumentError + end + + it "returns an array of WIN32OLE_METHODs" do + @ie.ole_put_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true + end + + it "contains a 'Height' method for Internet Explorer" do + @ie.ole_put_methods.map { |m| m.name }.include?('Height').should be_true + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/setproperty_spec.rb b/spec/ruby/library/win32ole/win32ole/setproperty_spec.rb new file mode 100644 index 0000000000..ae08e63f78 --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/setproperty_spec.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../fixtures/classes', __FILE__) +require File.expand_path('../shared/setproperty', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe "WIN32OLE#setproperty" do + it_behaves_like :win32ole_setproperty, :setproperty + + end + +end diff --git a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb new file mode 100644 index 0000000000..668000c1fc --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb @@ -0,0 +1,25 @@ +require File.expand_path('../../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe :win32ole_ole_method, shared: true do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "raises ArgumentError if no argument is given" do + lambda { @ie.send(@method) }.should raise_error ArgumentError + end + + it "returns the WIN32OLE_METHOD 'Quit' if given 'Quit'" do + result = @ie.send(@method, "Quit") + result.kind_of?(WIN32OLE_METHOD).should be_true + result.name.should == 'Quit' + end + end +end diff --git a/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb b/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb new file mode 100644 index 0000000000..9703e402bf --- /dev/null +++ b/spec/ruby/library/win32ole/win32ole/shared/setproperty.rb @@ -0,0 +1,25 @@ +require File.expand_path('../../../fixtures/classes', __FILE__) + +platform_is :windows do + require 'win32ole' + + describe :win32ole_setproperty, shared: true do + before :each do + @ie = WIN32OLESpecs.new_ole('InternetExplorer.Application') + end + + after :each do + @ie.Quit + end + + it "raises ArgumentError if no argument is given" do + lambda { @ie.send(@method) }.should raise_error ArgumentError + end + + it "sets height to 500 and returns nil" do + height = 500 + result = @ie.send(@method, 'Height', height) + result.should == nil + end + end +end |