RE: Greener test

37 views
Skip to first unread message

Dušan D. Majkić

unread,
Jun 27, 2012, 2:35:20 PM6/27/12
to rubyin...@googlegroups.com
This one is about 3 failures I have in "test_win32ole_variant.rb".
Those are:

test_s_array
test_conversion_str2num
test_conversion_ole_variant2ole_variant

After looking at the win32ole.c, I see that the default locale
is LOCALE_SYSTEM_DEFAULT. That means that the locale
is from the Windows, and is not affected by the console settings.

Since I am using "Serbian Latin", which sets coma as decimal
separator (eg. 123456,78), all three tests fail simply because
Windows API tires to convert string to number using wrong locale.
String is in US locale, but conversion API uses system default.

Since WIN32OLE.locale= exists, setting it to 1033 (US English),
solves all three tests as "pass". It looks like this:

def test_conversion_str2num
WIN32OLE.locale = 1033 # set US-Eng locale - number with decimal point
obj = WIN32OLE_VARIANT.new("12.345", WIN32OLE::VARIANT::VT_R8)
assert_equal(12.345, obj.value)
end

Luis Lavena

unread,
Jun 27, 2012, 4:23:42 PM6/27/12
to rubyin...@googlegroups.com
Hello Dusan,
Interesting analysis, I think that controlling the specific locale
under which those tests are performed is the way to go.

For example, I have those failures too because I'm with Spanish
(Argentina) which also uses comma to separate decimals.

I'll give a test and let you know, but if you create a patch, don't
forget to send to Ruby redmine ;-)

Thank you!
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Dušan D. Majkić

unread,
Jun 27, 2012, 6:29:06 PM6/27/12
to rubyin...@googlegroups.com
Also this one: test_s_codepage_changed

It fails with "OLE error code:800A0005 in <Unknown>" which is
CTL_E_ILLEGALFUNCTIONCALL.

After googleing about similar errors, it looks like the tested OLE function

Scripting.FileSystemObject.opentextfile(fname, 2 true).write(some_string)

this fails with given error if some_string contains binary data.
Line that fails is this:

file.write [0x3042].pack("U*").force_encoding("UTF-8")

If I change "UTF-8" to "UTF-16" (or "Windows-1250") it writes data
without error, but data written is different than expected utf-8
string. At least there is no OLE error.

IMHO it looks like unfortunate choice of OLE object for this test, not
a ruby error.

Boško Ivanišević

unread,
Jun 28, 2012, 2:13:15 AM6/28/12
to rubyin...@googlegroups.com
Fix for this is already submitted (http://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/35030). I would say that this is not unfortunate choice of OLE object but a false presumption that FSO can deal with UTF-8 encoding. FSO is limited only to ANSI and UTF-16LE encoding.

--
Regards,
Boško Ivanišević

Dušan D. Majkić

unread,
Jun 28, 2012, 10:38:50 AM6/28/12
to rubyin...@googlegroups.com
> Fix for this is already submitted
> (http://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/35030).
> I would say that this is not unfortunate choice of OLE object but a false
> presumption that FSO can deal with UTF-8 encoding.

True.

I see that #6650 is marked as resolved - good job

Hiroshi Shirosaki

unread,
Jul 29, 2012, 9:19:37 PM7/29/12
to rubyin...@googlegroups.com
Hello,
I created a patch based on your analysis and worked as expected on my
box which default locale is Japanese.

https://gist.github.com/3202976

Can you confirm this with your environment?


--
Hiroshi Shirosaki

Oleg Sukhodolsky

unread,
Jul 29, 2012, 11:14:40 PM7/29/12
to rubyin...@googlegroups.com
Hi  Hiroshi,

the patch works fine in my Russian environment.
Just one question: it looks like whole test is supposed to be executed with
English locale, perhaps it would be better (for future modification of the file to set English locale in
setup() and reset it in teardown().  What do you think?

Regards, Oleg.
 


--
Hiroshi Shirosaki

--
You received this message because you are subscribed to the Google Groups "RubyInstaller" group.
To post to this group, send email to rubyin...@googlegroups.com.
To unsubscribe from this group, send email to rubyinstalle...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyinstaller?hl=en.


Hiroshi Shirosaki

unread,
Jul 30, 2012, 12:08:37 AM7/30/12
to rubyin...@googlegroups.com
Hi Oleg,

On Mon, Jul 30, 2012 at 12:14 PM, Oleg Sukhodolsky <os9...@gmail.com> wrote:
> the patch works fine in my Russian environment.
> Just one question: it looks like whole test is supposed to be executed with
> English locale, perhaps it would be better (for future modification of the
> file to set English locale in
> setup() and reset it in teardown(). What do you think?
>

Thank you for test.

I'm not sure, but that wide change might affect other tests badly. If
test-all passes with that setup/teardown fix, it would be ok.

IMO, this patch clarifies these three tests depend on specific locale.
Another test which depend on specific locale exist.
https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_variant.rb#L394


--
Hiroshi Shirosaki

Oleg Sukhodolsky

unread,
Jul 30, 2012, 11:09:26 AM7/30/12
to rubyin...@googlegroups.com
Well, taking into account this information I'm withdrawing my suggestion.

Regard, Oleg.

Dušan D. Majkić

unread,
Jul 31, 2012, 12:22:33 PM7/31/12
to rubyin...@googlegroups.com
> Can you confirm this with your environment?

Hiroshi, it works ok on Win1250.

Regards.

Hiroshi Shirosaki

unread,
Jul 31, 2012, 4:34:23 PM7/31/12
to rubyin...@googlegroups.com
On Wed, Aug 1, 2012 at 1:22 AM, Dušan D. Majkić <dma...@gmail.com> wrote:
>> Can you confirm this with your environment?
>
> Hiroshi, it works ok on Win1250.
>

Dušan, thank you. I submitted it to ruby-core.

https://bugs.ruby-lang.org/issues/6814
Reply all
Reply to author
Forward
0 new messages