[前][次][番号順一覧][スレッド一覧]

ruby-changes:2199

From: ko1@a...
Date: 13 Oct 2007 21:40:43 +0900
Subject: [ruby-changes:2199] suke - Ruby:r13690 (trunk): * ext/win32ole/win32ole.c (foletype_s_ole_classes,

suke	2007-10-13 21:40:24 +0900 (Sat, 13 Oct 2007)

  New Revision: 13690

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/test/win32ole/test_folderitem2_invokeverb.rb
    trunk/test/win32ole/test_win32ole_type.rb
    trunk/test/win32ole/test_win32ole_typelib.rb

  Log:
    * ext/win32ole/win32ole.c (foletype_s_ole_classes, 
      foletype_s_typelibs): refactoring.
    
    * test/win32ole/test_win32ole_type.rb: add some test. 
    
    * ext/win32ole/win32ole.c (Init_win32ole): change method name
      WIN32OLE_TYPELIB.ole_types from WIN32OLE_TYPELIB.ole_classes.
    
    * test/win32ole/test_win32ole_typelib.rb: ditto.
    
    * test/win32ole/test_folderitem2_invokeverb.rb: check create
      shortcut string more strictly (This test is invoked in Japanese
      Windows environment).
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/win32ole/test_folderitem2_invokeverb.rb?r1=13690&r2=13689
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/win32ole/test_win32ole_typelib.rb?r1=13690&r2=13689
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/win32ole/test_win32ole_type.rb?r1=13690&r2=13689
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13690&r2=13689
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/win32ole/win32ole.c?r1=13690&r2=13689

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13689)
+++ ChangeLog	(revision 13690)
@@ -1,3 +1,19 @@
+Sat Oct 13 21:23:21 2007  Masaki Suketa  <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (foletype_s_ole_classes, 
+	  foletype_s_typelibs): refactoring.
+	
+	* test/win32ole/test_win32ole_type.rb: add some test. 
+
+	* ext/win32ole/win32ole.c (Init_win32ole): change method name
+	  WIN32OLE_TYPELIB.ole_types from WIN32OLE_TYPELIB.ole_classes.
+
+	* test/win32ole/test_win32ole_typelib.rb: ditto.
+
+	* test/win32ole/test_folderitem2_invokeverb.rb: check create
+	  shortcut string more strictly (This test is invoked in Japanese
+	  Windows environment).
+
 Sat Oct 13 09:11:58 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (set_file_encoding): case-insensitive search, a patch from
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 13689)
+++ ext/win32ole/win32ole.c	(revision 13690)
@@ -116,7 +116,7 @@
 
 #define WC2VSTR(x) ole_wc2vstr((x), TRUE)
 
-#define WIN32OLE_VERSION "1.1.0"
+#define WIN32OLE_VERSION "1.1.1"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -306,7 +306,7 @@
 static VALUE ole_bind_obj(VALUE moniker, int argc, VALUE *argv, VALUE self);
 static VALUE fole_s_connect(int argc, VALUE *argv, VALUE self);
 static VALUE fole_s_const_load(int argc, VALUE *argv, VALUE self);
-static VALUE ole_classes_from_typelib(ITypeLib *pTypeLib, VALUE classes);
+static VALUE ole_types_from_typelib(ITypeLib *pTypeLib, VALUE classes);
 static ULONG reference_count(struct oledata * pole);
 static VALUE fole_s_reference_count(VALUE self, VALUE obj);
 static VALUE fole_s_free(VALUE self, VALUE obj);
@@ -384,7 +384,7 @@
 static void  oletypelib2itypelib(VALUE self, ITypeLib **ppTypeLib);
 static VALUE foletypelib_visible(VALUE self);
 static VALUE foletypelib_library_name(VALUE self);
-static VALUE foletypelib_ole_classes(VALUE self);
+static VALUE foletypelib_ole_types(VALUE self);
 static VALUE foletypelib_inspect(VALUE self);
 static VALUE foletype_initialize(VALUE self, VALUE typelib, VALUE oleclass);
 static VALUE foletype_name(VALUE self);
@@ -2425,7 +2425,7 @@
 }
 
 static VALUE
-ole_classes_from_typelib(ITypeLib *pTypeLib, VALUE classes)
+ole_types_from_typelib(ITypeLib *pTypeLib, VALUE classes)
 {
     
     long count;
@@ -4343,34 +4343,15 @@
 static VALUE
 foletype_s_ole_classes(VALUE self, VALUE typelib)
 {
-    VALUE file, classes;
-    OLECHAR * pbuf;
-    ITypeLib *pTypeLib;
-    HRESULT hr;
+    VALUE obj;
 
     /*
     rb_warn("%s is obsolete; use %s instead.",
             "WIN32OLE_TYPE.ole_classes",
-            "WIN32OLE_TYPELIB.new(typelib).ole_classes");
+            "WIN32OLE_TYPELIB.new(typelib).ole_types");
     */
-    rb_secure(4);
-    classes = rb_ary_new();
-    if(TYPE(typelib) == T_STRING) {
-        file = typelib_file(typelib);
-        if (file == Qnil) {
-            file = typelib;
-        }
-        pbuf = ole_mb2wc(StringValuePtr(file), -1);
-        hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
-        if (FAILED(hr))
-          ole_raise(hr, eWIN32OLERuntimeError, "failed to LoadTypeLibEx");
-        SysFreeString(pbuf);
-        ole_classes_from_typelib(pTypeLib, classes);
-        OLE_RELEASE(pTypeLib);
-    } else {
-        rb_raise(rb_eTypeError, "1st argument should be TypeLib string");
-    }
-    return classes;
+    obj = rb_funcall(cWIN32OLE_TYPELIB, rb_intern("new"), 1, typelib);
+    return rb_funcall(obj, rb_intern("ole_types"), 0);
 }
 
 /*
@@ -4384,47 +4365,12 @@
 static VALUE
 foletype_s_typelibs(VALUE self)
 {
-    HKEY htypelib, hclsid;
-    double fversion;
-    DWORD i, j;
-    LONG err;
-    VALUE clsid;
-    VALUE ver;
-    VALUE v = Qnil;
-    VALUE typelibs = rb_ary_new();
-
     /*
     rb_warn("%s is obsolete. use %s instead.",
             "WIN32OLE_TYPE.typelibs",
             "WIN32OLE_TYPELIB.typelibs.collect{t|t.name}");
     */
-    err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
-    if(err != ERROR_SUCCESS) {
-        return typelibs;
-    }
-    for(i = 0; ; i++) {
-        clsid = reg_enum_key(htypelib, i);
-        if (clsid == Qnil)
-            break;
-        err = reg_open_vkey(htypelib, clsid, &hclsid);
-        if (err != ERROR_SUCCESS)
-            continue;
-        fversion = 0;
-        for(j = 0; ; j++) {
-            ver = reg_enum_key(hclsid, j);
-            if (ver == Qnil)
-                break;
-            if (fversion > atof(StringValuePtr(ver)))
-                continue;
-            fversion = atof(StringValuePtr(ver));
-            if ( (v = reg_get_val(hclsid, StringValuePtr(ver))) != Qnil ) {
-                rb_ary_push(typelibs, v);
-            }
-        }
-        RegCloseKey(hclsid);
-    }
-    RegCloseKey(htypelib);
-    return typelibs;
+    return rb_eval_string("WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}");
 }
 
 /*
@@ -5007,20 +4953,20 @@
 
 /*
  *  call-seq:
- *     WIN32OLE_TYPELIB#ole_classes -> The array of WIN32OLE_TYPE object included the type library.
+ *     WIN32OLE_TYPELIB#ole_types -> The array of WIN32OLE_TYPE object included the type library.
  *
  *  Returns the type library file path.
  *
  *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
- *     classes = tlib.ole_classes.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...] 
+ *     classes = tlib.ole_types.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...] 
  */
 static VALUE
-foletypelib_ole_classes(VALUE self)
+foletypelib_ole_types(VALUE self)
 {
     ITypeLib *pTypeLib = NULL;
     VALUE classes = rb_ary_new();
     oletypelib2itypelib(self, &pTypeLib);
-    ole_classes_from_typelib(pTypeLib, classes);
+    ole_types_from_typelib(pTypeLib, classes);
     OLE_RELEASE(pTypeLib);
     return classes;
 }
@@ -8122,7 +8068,8 @@
     rb_define_method(cWIN32OLE_TYPELIB, "major_version", foletypelib_major_version, 0);
     rb_define_method(cWIN32OLE_TYPELIB, "minor_version", foletypelib_minor_version, 0);
     rb_define_method(cWIN32OLE_TYPELIB, "path", foletypelib_path, 0);
-    rb_define_method(cWIN32OLE_TYPELIB, "ole_classes", foletypelib_ole_classes, 0);
+    rb_define_method(cWIN32OLE_TYPELIB, "ole_types", foletypelib_ole_types, 0);
+    rb_define_alias(cWIN32OLE_TYPELIB, "ole_classes", "ole_types");
     rb_define_method(cWIN32OLE_TYPELIB, "visible?", foletypelib_visible, 0);
     rb_define_method(cWIN32OLE_TYPELIB, "library_name", foletypelib_library_name, 0);
     rb_define_alias(cWIN32OLE_TYPELIB, "to_s", "name");
Index: test/win32ole/test_win32ole_type.rb
===================================================================
--- test/win32ole/test_win32ole_type.rb	(revision 13689)
+++ test/win32ole/test_win32ole_type.rb	(revision 13690)
@@ -158,6 +158,20 @@
     def test_inspect
       assert_equal("#<WIN32OLE_TYPE:Shell>", @ole_type.inspect)
     end
+    # WIN32OLE_TYPE.typelibs will be obsoleted.
+    def test_s_typelibs
+      tlibs = WIN32OLE_TYPE.typelibs.sort
+      tlibs2 = WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}.sort
+      assert_equal(tlibs2, tlibs)
+    end
 
+    # WIN32OLE_TYPE.ole_classes will be obsoleted.
+    def test_s_ole_classes
+      ots1 = WIN32OLE_TYPE.ole_classes("Microsoft Shell Controls And Automation")
+      ots2 = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation").ole_types
+      otns1 = ots1.collect{|t| t.name}.sort
+      otns2 = ots2.collect{|t| t.name}.sort
+      assert_equal(otns2, otns1)
+    end
   end
 end
Index: test/win32ole/test_folderitem2_invokeverb.rb
===================================================================
--- test/win32ole/test_folderitem2_invokeverb.rb	(revision 13689)
+++ test/win32ole/test_folderitem2_invokeverb.rb	(revision 13690)
@@ -29,7 +29,7 @@
       @shortcut = nil
 
       #
-      # Search the 'Create Shortcut (&S)' string.
+      # Search the 'Create Shortcut (&S)' string in Japanese.
       # Yes, I know the string in the Windows 2000 Japanese Edition.
       # But I do not know about the string in any other Windows.
       # 
@@ -38,7 +38,8 @@
       @shortcut = verbs.collect{|verb| 
         verb.name
       }.find {|name|
-        /.*\(\&S\)$/ =~ name
+        name.unpack("C*") == [131, 86, 131, 135, 129, 91, 131, 103, 131, 74, 131, 98, 131, 103, 130, 204, 141, 236, 144, 172, 40, 38, 83, 41]
+        # /.*\(\&S\)$/ =~ name
       }
     end
 
Index: test/win32ole/test_win32ole_typelib.rb
===================================================================
--- test/win32ole/test_win32ole_typelib.rb	(revision 13689)
+++ test/win32ole/test_win32ole_typelib.rb	(revision 13690)
@@ -88,12 +88,12 @@
       assert_equal("Microsoft Shell Controls And Automation", tlib.to_s)
     end
 
-    def test_ole_classes
+    def test_ole_types
       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])
+      ole_types = tlib.ole_types
+      assert_instance_of(Array, ole_types)
+      assert(ole_types.size > 0)
+      assert_instance_of(WIN32OLE_TYPE, ole_types[0])
     end
 
     def test_inspect

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]