* ext/win32ole/win32ole_typelib.c (foletypelib_version): return

version string.

* test/win32ole/test_win32ole_typelib.rb (test_version): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2014-08-07 12:52:25 +00:00
parent b618b8685c
commit 707ff7bfb7
3 changed files with 37 additions and 32 deletions

View File

@ -1,3 +1,10 @@
Thu Aug 7 21:42:49 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole_typelib.c (foletypelib_version): return
version string.
* test/win32ole/test_win32ole_typelib.rb (test_version): ditto.
Thu Aug 7 15:13:13 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com> Thu Aug 7 15:13:13 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/cgi.rb: remove needless condition for old ruby version. * lib/cgi.rb: remove needless condition for old ruby version.

View File

@ -299,34 +299,34 @@ oletypelib_search_registry2(VALUE self, VALUE args)
RegCloseKey(hversion); RegCloseKey(hversion);
} else { } else {
fver = 0.0; fver = 0.0;
for(j = 0; ;j++) { for(j = 0; ;j++) {
ver = reg_enum_key(hguid, j); ver = reg_enum_key(hguid, j);
if (ver == Qnil) if (ver == Qnil)
break; break;
err = reg_open_vkey(hguid, ver, &hversion); err = reg_open_vkey(hguid, ver, &hversion);
if (err != ERROR_SUCCESS) if (err != ERROR_SUCCESS)
continue; continue;
tlib = reg_get_val(hversion, NULL); tlib = reg_get_val(hversion, NULL);
if (tlib == Qnil) { if (tlib == Qnil) {
RegCloseKey(hversion); RegCloseKey(hversion);
continue; continue;
} }
if (fver < atof(StringValuePtr(ver))) { if (fver < atof(StringValuePtr(ver))) {
fver = atof(StringValuePtr(ver)); fver = atof(StringValuePtr(ver));
version = ver; version = ver;
typelib = tlib; typelib = tlib;
} }
RegCloseKey(hversion); RegCloseKey(hversion);
} }
} }
RegCloseKey(hguid); RegCloseKey(hguid);
RegCloseKey(htypelib); RegCloseKey(htypelib);
if (typelib != Qnil) { if (typelib != Qnil) {
hr = oletypelib_from_guid(guid, version, &pTypeLib); hr = oletypelib_from_guid(guid, version, &pTypeLib);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
found = Qtrue; found = Qtrue;
oletypelib_set_member(self, pTypeLib); oletypelib_set_member(self, pTypeLib);
} }
} }
return found; return found;
} }
@ -472,27 +472,25 @@ make_version_str(VALUE major, VALUE minor)
/* /*
* call-seq: * call-seq:
* WIN32OLE_TYPELIB#version -> The type library version. * WIN32OLE_TYPELIB#version -> The type library version String object.
* *
* Returns the type library version. * Returns the type library version.
* *
* tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') * tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
* puts tlib.version #-> 1.3 * puts tlib.version #-> "1.3"
*/ */
static VALUE static VALUE
foletypelib_version(VALUE self) foletypelib_version(VALUE self)
{ {
TLIBATTR *pTLibAttr; TLIBATTR *pTLibAttr;
VALUE major;
VALUE minor;
ITypeLib *pTypeLib; ITypeLib *pTypeLib;
VALUE version;
pTypeLib = itypelib(self); pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr); oletypelib_get_libattr(pTypeLib, &pTLibAttr);
major = INT2NUM(pTLibAttr->wMajorVerNum); version = rb_sprintf("%d.%d", pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
minor = INT2NUM(pTLibAttr->wMinorVerNum);
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr); pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
return rb_Float(make_version_str(major, minor)); return version;
} }
/* /*

View File

@ -66,7 +66,7 @@ if defined?(WIN32OLE_TYPELIB)
def test_version def test_version
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation") tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
assert_equal(1.0, tlib.version) assert_equal("1.0", tlib.version)
end end
def test_major_version def test_major_version