mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add WIN32OLE_TYPE#inspect, WIN32OLE_VARIABLE#inspect
add test/win32ole and remove some test script from ext/win32ole/tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
53efc38350
commit
3ff87cc53f
6 changed files with 355 additions and 16 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Sat Apr 1 15:11:27 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c :add WIN32OLE_TYPE#inspect,
|
||||
WIN32OLE_VARIABLE#inspect
|
||||
|
||||
* remove ext/win32ole/tests/testOLEVARIABLE.rb, testOLETYPE.rb
|
||||
testOLETYPELIB.rb.
|
||||
|
||||
* testall.rb :ditto.
|
||||
|
||||
* add test/win32ole
|
||||
|
||||
Fri Mar 31 14:24:55 2006 nobuyoshi nakada <nobu@ruby-lang.org>
|
||||
|
||||
* enumerator.c (enumerator_with_index): removed suspicious return
|
||||
|
|
|
@ -2,12 +2,9 @@ require 'test/unit'
|
|||
require 'win32ole'
|
||||
puts "Now Test Win32OLE version #{WIN32OLE::VERSION}"
|
||||
require "testWIN32OLE"
|
||||
require "testOLETYPE"
|
||||
require "testOLEPARAM"
|
||||
require "testOLEMETHOD"
|
||||
require "testOLEVARIABLE"
|
||||
require "testVARIANT"
|
||||
require "testOLETYPELIB"
|
||||
require "testOLEVARIANT"
|
||||
require "testOLEEVENT"
|
||||
require "testNIL2VTEMPTY"
|
||||
|
|
|
@ -1242,6 +1242,29 @@ ole_val2variant2(val, var)
|
|||
g_nil_to = VT_ERROR;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
make_inspect(class_name, detail)
|
||||
const char *class_name;
|
||||
VALUE detail;
|
||||
{
|
||||
VALUE str;
|
||||
str = rb_str_new2("#<");
|
||||
rb_str_cat2(str, class_name);
|
||||
rb_str_cat2(str, ":");
|
||||
rb_str_concat(str, detail);
|
||||
rb_str_cat2(str, ">");
|
||||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
default_inspect(self, class_name)
|
||||
VALUE self;
|
||||
const char *class_name;
|
||||
{
|
||||
VALUE detail = rb_funcall(self, rb_intern("to_s"), 0);
|
||||
return make_inspect(class_name, detail);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ole_set_member(self, dispatch)
|
||||
VALUE self;
|
||||
|
@ -1257,6 +1280,7 @@ ole_set_member(self, dispatch)
|
|||
return self;
|
||||
}
|
||||
|
||||
|
||||
static VALUE fole_s_allocate _((VALUE));
|
||||
static VALUE
|
||||
fole_s_allocate(klass)
|
||||
|
@ -4454,13 +4478,7 @@ static VALUE
|
|||
foletypelib_inspect(self)
|
||||
VALUE self;
|
||||
{
|
||||
VALUE str;
|
||||
VALUE to_s;
|
||||
str = rb_str_new2("#<WIN32OLE_TYPELIB:");
|
||||
to_s = rb_funcall(self, rb_intern("to_s"), 0);
|
||||
rb_str_concat(str, to_s);
|
||||
rb_str_cat2(str, ">");
|
||||
return str;
|
||||
return default_inspect(self, "WIN32OLE_TYPELIB");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4999,6 +5017,13 @@ foletype_impl_ole_types(self)
|
|||
return ole_type_impl_ole_types(ptype->pTypeInfo);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
foletype_inspect(self)
|
||||
VALUE self;
|
||||
{
|
||||
return default_inspect(self, "WIN32OLE_TYPE");
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ole_variables(pTypeInfo)
|
||||
ITypeInfo *pTypeInfo;
|
||||
|
@ -5086,9 +5111,7 @@ foletype_variables(self)
|
|||
* # => ['Activate', 'Copy', 'Delete',....]
|
||||
*/
|
||||
static VALUE
|
||||
foletype_methods(argc, argv, self)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
foletype_methods(self)
|
||||
VALUE self;
|
||||
{
|
||||
struct oletypedata *ptype;
|
||||
|
@ -5409,6 +5432,16 @@ folevariable_varkind(self)
|
|||
return ole_variable_varkind(pvar->pTypeInfo, pvar->index);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
folevariable_inspect(self)
|
||||
VALUE self;
|
||||
{
|
||||
VALUE detail = rb_funcall(self, rb_intern("to_s"), 0);
|
||||
rb_str_cat2(detail, "=");
|
||||
rb_str_concat(detail, rb_funcall(rb_funcall(self, rb_intern("value"), 0), rb_intern("inspect"), 0));
|
||||
return make_inspect("WIN32OLE_VARIABLE", detail);
|
||||
}
|
||||
|
||||
/*
|
||||
* Document-class: WIN32OLE_METHOD
|
||||
*
|
||||
|
@ -7375,7 +7408,6 @@ Init_win32ole()
|
|||
rb_define_method(cWIN32OLE_TYPE, "progid", foletype_progid, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "visible?", foletype_visible, 0);
|
||||
rb_define_alias(cWIN32OLE_TYPE, "to_s", "name");
|
||||
|
||||
rb_define_method(cWIN32OLE_TYPE, "major_version", foletype_major_version, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "minor_version", foletype_minor_version, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "typekind", foletype_typekind, 0);
|
||||
|
@ -7384,9 +7416,10 @@ Init_win32ole()
|
|||
rb_define_method(cWIN32OLE_TYPE, "helpfile", foletype_helpfile, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "helpcontext", foletype_helpcontext, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "variables", foletype_variables, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "ole_methods", foletype_methods, -1);
|
||||
rb_define_method(cWIN32OLE_TYPE, "ole_methods", foletype_methods, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "ole_typelib", foletype_ole_typelib, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "implemented_ole_types", foletype_impl_ole_types, 0);
|
||||
rb_define_method(cWIN32OLE_TYPE, "inspect", foletype_inspect, 0);
|
||||
|
||||
cWIN32OLE_VARIABLE = rb_define_class("WIN32OLE_VARIABLE", rb_cObject);
|
||||
rb_define_method(cWIN32OLE_VARIABLE, "name", folevariable_name, 0);
|
||||
|
@ -7396,12 +7429,12 @@ Init_win32ole()
|
|||
rb_define_method(cWIN32OLE_VARIABLE, "visible?", folevariable_visible, 0);
|
||||
rb_define_method(cWIN32OLE_VARIABLE, "variable_kind", folevariable_variable_kind, 0);
|
||||
rb_define_method(cWIN32OLE_VARIABLE, "varkind", folevariable_varkind, 0);
|
||||
rb_define_method(cWIN32OLE_VARIABLE, "inspect", folevariable_inspect, 0);
|
||||
rb_define_alias(cWIN32OLE_VARIABLE, "to_s", "name");
|
||||
|
||||
cWIN32OLE_METHOD = rb_define_class("WIN32OLE_METHOD", rb_cObject);
|
||||
rb_define_alloc_func(cWIN32OLE_METHOD, folemethod_s_allocate);
|
||||
rb_define_method(cWIN32OLE_METHOD, "initialize", folemethod_initialize, 2);
|
||||
|
||||
rb_define_method(cWIN32OLE_METHOD, "name", folemethod_name, 0);
|
||||
rb_define_method(cWIN32OLE_METHOD, "return_type", folemethod_return_type, 0);
|
||||
rb_define_method(cWIN32OLE_METHOD, "return_vtype", folemethod_return_vtype, 0);
|
||||
|
|
143
test/win32ole/test_win32ole_type.rb
Normal file
143
test/win32ole/test_win32ole_type.rb
Normal file
|
@ -0,0 +1,143 @@
|
|||
begin
|
||||
require 'win32ole'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require "test/unit"
|
||||
|
||||
if defined?(WIN32OLE_TYPE)
|
||||
class TestWIN32OLE_TYPE < Test::Unit::TestCase
|
||||
|
||||
def test_s_progids
|
||||
progids = WIN32OLE_TYPE.progids
|
||||
assert_instance_of(Array, progids)
|
||||
assert(progids.size > 0)
|
||||
assert_instance_of(String, progids[0])
|
||||
assert(progids.include?("Shell.Application.1"))
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
assert_raise(ArgumentError) {
|
||||
WIN32OLE_TYPE.new
|
||||
}
|
||||
assert_raise(ArgumentError) {
|
||||
WIN32OLE_TYPE.new("foo")
|
||||
}
|
||||
assert_raise(WIN32OLERuntimeError) {
|
||||
WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "foo")
|
||||
}
|
||||
assert_raise(WIN32OLERuntimeError) {
|
||||
WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Application")
|
||||
}
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
|
||||
assert_instance_of(WIN32OLE_TYPE, ole_type)
|
||||
end
|
||||
|
||||
def setup
|
||||
@ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
|
||||
end
|
||||
|
||||
def test_name
|
||||
assert_equal("Shell", @ole_type.name)
|
||||
end
|
||||
|
||||
def test_ole_type
|
||||
assert_equal("Class", @ole_type.ole_type)
|
||||
end
|
||||
|
||||
def test_guid
|
||||
assert_equal("{13709620-C279-11CE-A49E-444553540000}", @ole_type.guid)
|
||||
end
|
||||
|
||||
def test_progid
|
||||
assert_equal("Shell.Application.1", @ole_type.progid)
|
||||
end
|
||||
|
||||
def test_visible?
|
||||
assert(@ole_type.visible?)
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "IShellDispatch")
|
||||
assert(!ole_type.visible?)
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
assert_equal(@ole_type.to_s, @ole_type.name)
|
||||
end
|
||||
|
||||
def test_major_version
|
||||
assert_equal(0, @ole_type.major_version)
|
||||
# ole_type = WIN32OLE_TYPE.new("Microsoft Word 11.0 Object Library", "Documents")
|
||||
# assert_equal(8, ole_type.major_version)
|
||||
end
|
||||
|
||||
def test_minor_version
|
||||
assert_equal(0, @ole_type.minor_version)
|
||||
# ole_type = WIN32OLE_TYPE.new("Microsoft Word 11.0 Object Library", "Documents")
|
||||
# assert_equal(3, ole_type.minor_version)
|
||||
end
|
||||
|
||||
def test_typekind
|
||||
assert_equal(5, @ole_type.typekind)
|
||||
end
|
||||
|
||||
def test_helpstring
|
||||
assert_equal("Shell Object Type Information", @ole_type.helpstring)
|
||||
end
|
||||
|
||||
def test_src_type
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "DriveTypeConst")
|
||||
assert_match(/__MIDL___MIDL_itf_scrrun_/, ole_type.src_type)
|
||||
assert_equal(nil, @ole_type.src_type)
|
||||
end
|
||||
|
||||
def test_helpfile
|
||||
assert_equal("", @ole_type.helpfile)
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Folders")
|
||||
assert_match(/VBENLR98\.CHM$/i, ole_type.helpfile)
|
||||
end
|
||||
|
||||
def test_helpcontext
|
||||
assert_equal(0, @ole_type.helpcontext)
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Folders")
|
||||
assert_equal(2181929, ole_type.helpcontext)
|
||||
end
|
||||
|
||||
def test_variables
|
||||
variables = @ole_type.variables
|
||||
assert_instance_of(Array, variables)
|
||||
assert(variables.size == 0)
|
||||
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
|
||||
variables = ole_type.variables
|
||||
assert_instance_of(Array, variables)
|
||||
assert(variables.size > 0)
|
||||
|
||||
assert_instance_of(WIN32OLE_VARIABLE, variables[0])
|
||||
end
|
||||
|
||||
def test_ole_methods
|
||||
methods = @ole_type.ole_methods
|
||||
assert_instance_of(Array, methods)
|
||||
assert(methods.size > 0)
|
||||
assert_instance_of(WIN32OLE_METHOD, methods[0]);
|
||||
assert(methods.collect{|m| m.name}.include?("Application"))
|
||||
end
|
||||
|
||||
def test_ole_typelib
|
||||
tlib = @ole_type.ole_typelib
|
||||
assert_instance_of(WIN32OLE_TYPELIB, tlib)
|
||||
assert_equal("Microsoft Shell Controls And Automation", tlib.name)
|
||||
end
|
||||
|
||||
def test_implemented_ole_types
|
||||
ole_types = @ole_type.implemented_ole_types
|
||||
assert_instance_of(Array, ole_types)
|
||||
assert(ole_types.size > 0)
|
||||
assert_equal("IShellDispatch", ole_types[0].name)
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
assert_equal("#<WIN32OLE_TYPE:Shell>", @ole_type.inspect)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
92
test/win32ole/test_win32ole_typelib.rb
Normal file
92
test/win32ole/test_win32ole_typelib.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
begin
|
||||
require 'win32ole'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require "test/unit"
|
||||
|
||||
if defined?(WIN32OLE_TYPELIB)
|
||||
class TestWIN32OLE_TYPELIB < Test::Unit::TestCase
|
||||
def test_s_typelibs
|
||||
tlibs = WIN32OLE_TYPELIB.typelibs
|
||||
assert_instance_of(Array, tlibs)
|
||||
assert(tlibs.size > 0)
|
||||
tlib = tlibs.find {|tlib| tlib.name == "Microsoft Shell Controls And Automation"}
|
||||
assert(tlib)
|
||||
end
|
||||
|
||||
def test_initialize
|
||||
assert_raise(ArgumentError) {
|
||||
WIN32OLE_TYPELIB.new(1,2,3,4)
|
||||
}
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_instance_of(WIN32OLE_TYPELIB, tlib)
|
||||
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation", 1.0)
|
||||
assert_instance_of(WIN32OLE_TYPELIB, tlib)
|
||||
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation", 1, 0)
|
||||
assert_instance_of(WIN32OLE_TYPELIB, tlib)
|
||||
guid = tlib.guid
|
||||
|
||||
tlib_by_guid = WIN32OLE_TYPELIB.new(guid, 1, 0)
|
||||
assert_instance_of(WIN32OLE_TYPELIB, tlib_by_guid)
|
||||
assert_equal("Microsoft Shell Controls And Automation" , tlib_by_guid.name)
|
||||
|
||||
assert_raise(WIN32OLERuntimeError) {
|
||||
WIN32OLE_TYPELIB.new("Non Exist Type Library")
|
||||
}
|
||||
end
|
||||
|
||||
def test_guid
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}", tlib.guid)
|
||||
end
|
||||
|
||||
def test_name
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal("Microsoft Shell Controls And Automation", tlib.name)
|
||||
tlib = WIN32OLE_TYPELIB.new("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}")
|
||||
assert_equal("Microsoft Shell Controls And Automation", tlib.name)
|
||||
end
|
||||
|
||||
def test_version
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal(1.0, tlib.version)
|
||||
end
|
||||
|
||||
def test_major_version
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal(1, tlib.major_version)
|
||||
end
|
||||
|
||||
def test_minor_version
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal(0, tlib.minor_version)
|
||||
end
|
||||
|
||||
def test_path
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_match(/shell32\.dll$/i, tlib.path)
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal("Microsoft Shell Controls And Automation", tlib.to_s)
|
||||
end
|
||||
|
||||
def test_ole_classes
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
ole_classes = tlib.ole_classes
|
||||
assert_instance_of(Array, ole_classes)
|
||||
assert(ole_classes.size > 0)
|
||||
assert_instance_of(WIN32OLE_TYPE, ole_classes[0])
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
assert_equal("#<WIN32OLE_TYPELIB:Microsoft Shell Controls And Automation>", tlib.inspect)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
62
test/win32ole/test_win32ole_variable.rb
Normal file
62
test/win32ole/test_win32ole_variable.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
begin
|
||||
require 'win32ole'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require "test/unit"
|
||||
|
||||
if defined?(WIN32OLE_VARIABLE)
|
||||
class TestWIN32OLE_VARIABLE < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
|
||||
@var1 = ole_type.variables.find {|v| v.name == 'ssfDESKTOP'}
|
||||
|
||||
variables = WIN32OLE_TYPE.new("Microsoft Windows Installer Object Library", "Installer").variables
|
||||
@var2 = variables.find {|v| v.name == 'UILevel'}
|
||||
end
|
||||
|
||||
def test_name
|
||||
assert_equal('ssfDESKTOP', @var1.name)
|
||||
end
|
||||
|
||||
def test_ole_type
|
||||
assert_equal('INT', @var1.ole_type)
|
||||
assert_equal('MsiUILevel', @var2.ole_type)
|
||||
end
|
||||
|
||||
def test_ole_type_detail
|
||||
assert_equal(['INT'], @var1.ole_type_detail)
|
||||
assert_equal(['USERDEFINED', 'MsiUILevel'], @var2.ole_type_detail)
|
||||
end
|
||||
|
||||
def test_ole_type_value
|
||||
assert_equal(0, @var1.value)
|
||||
assert_equal(nil, @var2.value)
|
||||
end
|
||||
|
||||
def test_ole_type_visible?
|
||||
assert(@var1.visible?)
|
||||
end
|
||||
|
||||
def test_ole_type_variable_kind
|
||||
assert_equal("CONSTANT", @var1.variable_kind)
|
||||
assert_equal("DISPATCH", @var2.variable_kind)
|
||||
end
|
||||
|
||||
def test_ole_type_varkind
|
||||
assert_equal(2, @var1.varkind)
|
||||
assert_equal(3, @var2.varkind)
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
assert_equal(@var1.name, @var1.to_s)
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
assert_equal("#<WIN32OLE_VARIABLE:ssfDESKTOP=0>", @var1.inspect)
|
||||
assert_equal("#<WIN32OLE_VARIABLE:UILevel=nil>", @var2.inspect)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue