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

ruby-changes:14354

From: suke <ko1@a...>
Date: Sun, 27 Dec 2009 10:52:53 +0900 (JST)
Subject: [ruby-changes:14354] Ruby:r26184 (trunk): * ext/win32ole/win32ole.c (foleparam_initialize): add foleparam_initialize

suke	2009-12-27 10:51:54 +0900 (Sun, 27 Dec 2009)

  New Revision: 26184

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26184

  Log:
    * ext/win32ole/win32ole.c (foleparam_initialize): add foleparam_initialize
      to check argument of WIN32OLE_PARAM.new
    
    * test/win32ole/test_win32ole_param.rb (test_s_new): add some assertion
      to test WIN32OLE_PARAM.new

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/test/win32ole/test_win32ole_param.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26183)
+++ ChangeLog	(revision 26184)
@@ -1,3 +1,11 @@
+Sun Dec 27 10:45:00 2009  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (foleparam_initialize): add foleparam_initialize
+	  to check argument of WIN32OLE_PARAM.new
+
+	* test/win32ole/test_win32ole_param.rb (test_s_new): add some assertion
+	  to test WIN32OLE_PARAM.new
+
 Sun Dec 27 09:41:54 2009  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* tool/rbinstall.rb (install?(:local, :comm, :bin, :'bin-comm')):
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 26183)
+++ ext/win32ole/win32ole.c	(revision 26184)
@@ -509,6 +509,10 @@
 static VALUE ole_method_params(ITypeInfo *pTypeInfo, UINT method_index);
 static VALUE folemethod_params(VALUE self);
 static VALUE folemethod_inspect(VALUE self);
+static VALUE foleparam_s_allocate(VALUE klass);
+static VALUE oleparam_ole_param_from_index(VALUE self, ITypeInfo *pTypeInfo, UINT method_index, int param_index);
+static VALUE oleparam_ole_param(VALUE self, VALUE olemethod, int n);
+static VALUE foleparam_initialize(VALUE self, VALUE olemethod, VALUE n);
 static VALUE foleparam_name(VALUE self);
 static VALUE ole_param_ole_type(ITypeInfo *pTypeInfo, UINT method_index, UINT index);
 static VALUE foleparam_ole_type(VALUE self);
@@ -2489,7 +2493,7 @@
                     continue;
                 pName = ole_wc2mb(bstr);
                 val = ole_variant2val(V_UNION1(pVarDesc, lpvarValue));
-                *pName = toupper(*pName);
+                *pName = toupper((int)*pName);
                 id = rb_intern(pName);
                 if (rb_is_const_id(id)) {
                     rb_define_const(klass, pName, val);
@@ -7159,7 +7163,75 @@
  *   <code>WIN32OLE_PARAM</code> objects represent param information of 
  *   the OLE method.
  */
+static VALUE foleparam_s_allocate(VALUE klass)
+{
+    struct oleparamdata *pparam;
+    VALUE obj;
+    obj = Data_Make_Struct(klass, 
+                           struct oleparamdata,
+                           0, oleparam_free, pparam);
+    pparam->pTypeInfo = NULL;
+    pparam->method_index = 0;
+    pparam->index = 0;
+    return obj;
+}
 
+static VALUE 
+oleparam_ole_param_from_index(VALUE self, ITypeInfo *pTypeInfo, UINT method_index, int param_index)
+{
+    FUNCDESC *pFuncDesc;
+    HRESULT hr;
+    BSTR *bstrs;
+    UINT len;
+    struct oleparamdata *pparam;
+    hr = pTypeInfo->lpVtbl->GetFuncDesc(pTypeInfo, method_index, &pFuncDesc);
+    if (FAILED(hr)) 
+        ole_raise(hr, rb_eRuntimeError, "fail to ITypeInfo::GetFuncDesc");
+
+    len = 0;
+    bstrs = ALLOCA_N(BSTR, pFuncDesc->cParams + 1);
+    hr = pTypeInfo->lpVtbl->GetNames(pTypeInfo, pFuncDesc->memid, 
+                                     bstrs, pFuncDesc->cParams + 1,
+                                     &len);
+    if (FAILED(hr)) {
+        pTypeInfo->lpVtbl->ReleaseFuncDesc(pTypeInfo, pFuncDesc);
+        ole_raise(hr, rb_eRuntimeError, "fail to ITypeInfo::GetNames");
+    }
+    SysFreeString(bstrs[0]);
+    if (param_index < 1 || len <= (UINT)param_index)
+    {
+        pTypeInfo->lpVtbl->ReleaseFuncDesc(pTypeInfo, pFuncDesc);
+        rb_raise(rb_eIndexError, "index of param must be in 1..%d", len);
+    }
+
+    Data_Get_Struct(self, struct oleparamdata, pparam);
+    pparam->pTypeInfo = pTypeInfo;
+    OLE_ADDREF(pTypeInfo);
+    pparam->method_index = method_index;
+    pparam->index = param_index - 1;
+    rb_ivar_set(self, rb_intern("name"), WC2VSTR(bstrs[param_index]));
+
+    pTypeInfo->lpVtbl->ReleaseFuncDesc(pTypeInfo, pFuncDesc);
+    return self;
+}
+
+static VALUE oleparam_ole_param(VALUE self, VALUE olemethod, int n)
+{
+    struct olemethoddata *pmethod;
+    Data_Get_Struct(olemethod, struct olemethoddata, pmethod);
+    return oleparam_ole_param_from_index(self, pmethod->pTypeInfo, pmethod->index, n);
+}
+
+static VALUE foleparam_initialize(VALUE self, VALUE olemethod, VALUE n)
+{
+    int idx;
+    if (!rb_obj_is_kind_of(olemethod, cWIN32OLE_METHOD)) {
+        rb_raise(rb_eTypeError, "1st parameter must be WIN32OLE_METHOD object");
+    }
+    idx = FIX2INT(n);
+    return oleparam_ole_param(self, olemethod, idx);
+}
+
 /*
  *  call-seq:
  *     WIN32OLE_PARAM#name
@@ -9127,6 +9199,8 @@
     rb_define_method(cWIN32OLE_METHOD, "inspect", folemethod_inspect, 0);
 
     cWIN32OLE_PARAM = rb_define_class("WIN32OLE_PARAM", rb_cObject);
+    rb_define_alloc_func(cWIN32OLE_PARAM, foleparam_s_allocate);
+    rb_define_method(cWIN32OLE_PARAM, "initialize", foleparam_initialize, 2);
     rb_define_method(cWIN32OLE_PARAM, "name", foleparam_name, 0);
     rb_define_method(cWIN32OLE_PARAM, "ole_type", foleparam_ole_type, 0);
     rb_define_method(cWIN32OLE_PARAM, "ole_type_detail", foleparam_ole_type_detail, 0);
Index: test/win32ole/test_win32ole_param.rb
===================================================================
--- test/win32ole/test_win32ole_param.rb	(revision 26183)
+++ test/win32ole/test_win32ole_param.rb	(revision 26184)
@@ -33,9 +33,24 @@
       assert_raise(ArgumentError) {
         WIN32OLE_PARAM.new("hoge")
       }
+      ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
+      m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
+      assert_raise(IndexError) {
+        WIN32OLE_PARAM.new(m_copyfile, 4);
+      }
+      assert_raise(IndexError) {
+        WIN32OLE_PARAM.new(m_copyfile, 0);
+      }
+      assert_raise(IndexError) {
+        WIN32OLE_PARAM.new(m_copyfile, 0);
+      }
+      param = WIN32OLE_PARAM.new(m_copyfile, 3)
+      assert_equal("OverWriteFiles", param.name)
+      assert_equal(WIN32OLE_PARAM, param.class)
+      assert_equal(true, param.default)
+      assert_equal("#<WIN32OLE_PARAM:OverWriteFiles=true>", param.inspect)
     end
 
-
     def test_name
       assert_equal('URL', @param_url.name)
       assert_equal('Flags', @param_flags.name)

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

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