Exploration Through Example

Example-driven development, Agile testing, context-driven testing, Agile programming, Ruby, and other things of interest to Brian Marick
191.8 167.2 186.2 183.6 184.0 183.2 184.6

Sun, 22 Jan 2006

The right way to put Unicode on the pasteboard

The previous solution to my copy-Unicode problem turns out not to work for non-Unicode characters, at least not for the sort of screwy characters testers like to paste into apps. So I had to solve it right. I put the solution here in hopes that it'll be found in a web search someday and save someone some time.

require 'osx/cocoa'

UTF8_ENCODING=4

#Example: unicopy %w{ 03b4 03d4 03a6 }
def unicopy(hex_string_array)
  copy_with_encoding(utf8(hex_string_array), UTF8_ENCODING)
  true
end

# Utilities

def utf8(hex_string_array)
  number_array = hex_string_array.collect do | hex_name |
    hex_name.to_i(16)
  end
  number_array.pack("U*")
end

def copy_with_encoding(string, encoding)
  data = OSX::NSData.dataWithRubyString(string)
  ns_string = OSX::NSString.alloc.initWithData(data, :encoding, encoding)
  pb = OSX::NSPasteboard.generalPasteboard
  pb.declareTypes(["NSStringPboardType"], :owner, nil)
  pb.setString(ns_string, :forType, "NSStringPboardType")
end

For the Windows version and for copying non-Unicode, look here: http://www.exampler.com/testing-com/review-copies/test-strings-0.1.zip. That's an alpha version of a collection of utility methods oriented toward helping testers mess with text fields. They're inspired by James Bach and Danny Faught's perlclip. They work on both the Mac and Windows. The source will eventually live on the Scripting for Testers site.

## Posted at 21:52 in category /ruby [permalink] [top]

About Brian Marick
I consult mainly on Agile software development, with a special focus on how testing fits in.

Contact me here: marick@exampler.com.

 

Syndication

 

Agile Testing Directions
Introduction
Tests and examples
Technology-facing programmer support
Business-facing team support
Business-facing product critiques
Technology-facing product critiques
Testers on agile projects
Postscript

Permalink to this list

 

Working your way out of the automated GUI testing tarpit
  1. Three ways of writing the same test
  2. A test should deduce its setup path
  3. Convert the suite one failure at a time
  4. You should be able to get to any page in one step
  5. Extract fast tests about single pages
  6. Link checking without clicking on links
  7. Workflow tests remain GUI tests
Permalink to this list

 

Design-Driven Test-Driven Design
Creating a test
Making it (barely) run
Views and presenters appear
Hooking up the real GUI

 

Popular Articles
A roadmap for testing on an agile project: When consulting on testing in Agile projects, I like to call this plan "what I'm biased toward."

Tacit knowledge: Experts often have no theory of their work. They simply perform skillfully.

Process and personality: Every article on methodology implicitly begins "Let's talk about me."

 

Related Weblogs

Wayne Allen
James Bach
Laurent Bossavit
William Caputo
Mike Clark
Rachel Davies
Esther Derby
Michael Feathers
Developer Testing
Chad Fowler
Martin Fowler
Alan Francis
Elisabeth Hendrickson
Grig Gheorghiu
Andy Hunt
Ben Hyde
Ron Jeffries
Jonathan Kohl
Dave Liebreich
Jeff Patton
Bret Pettichord
Hiring Johanna Rothman
Managing Johanna Rothman
Kevin Rutherford
Christian Sepulveda
James Shore
Jeff Sutherland
Pragmatic Dave Thomas
Glenn Vanderburg
Greg Vaughn
Eugene Wallingford
Jim Weirich

 

Where to Find Me


Software Practice Advancement

 

Archives
All of 2006
All of 2005
All of 2004
All of 2003

 

Join!

Agile Alliance Logo