From e3fa07fe1c19b360b127163bdc5871e9270d0d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Tue, 8 Apr 2014 15:02:56 +0200 Subject: [PATCH] Add tests for WeakRef change. --- test/test/Rakefile | 2 +- test/test/spec/weakref_spec.rb | 53 ++++++++++++++++++++++++++++++++-- vm | 2 +- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/test/test/Rakefile b/test/test/Rakefile index 0f92d01c..84421a34 100644 --- a/test/test/Rakefile +++ b/test/test/Rakefile @@ -7,7 +7,7 @@ ENV['output'] ||= 'pretty_spec_dox' Motion::Project::App.setup do |app| # Use `rake config' to see complete project settings. app.name = 'test' - app.frameworks += ['AddressBook', 'AddressBookUI', 'CoreData', 'CoreMIDI', 'GameKit', 'AudioToolbox'] + app.frameworks += ['AddressBook', 'AddressBookUI', 'AudioToolbox', 'AVFoundation', 'CoreData', 'CoreMIDI', 'GameKit'] app.vendor_project('vendor/code', :static) app.spec_files.insert(1, *FileList['../helpers/*.rb']) diff --git a/test/test/spec/weakref_spec.rb b/test/test/spec/weakref_spec.rb index 5b1f104a..4ca4c32f 100644 --- a/test/test/spec/weakref_spec.rb +++ b/test/test/spec/weakref_spec.rb @@ -108,9 +108,58 @@ describe "WeakRef" do WeakRef.new(false).should == false end + # TODO what's the good way to determine if we're running on 10.7? + unless defined?(NSView) && ENV['deployment_target'] == '10.7' + it "allows weak references to AVFoundation classes" do + lambda { WeakRef.new(AVPlayer.new) }.should.not.raise + end + end + it "raises with classes that do not support weak references" do - obj = NSMutableParagraphStyle.new - lambda { WeakRef.new(obj) }.should.raise(WeakRef::RefError) + # iOS and OS X classes, regardless of SDK version + classes = [ + NSParagraphStyle, + NSMutableParagraphStyle, + ] + # OSX only classes + if defined?(NSView) + # Some of these are deprecated, so define a stub if necessary. + unless defined?(NSSimpleHorizontalTypesetter) + class NSSimpleHorizontalTypesetter; end + end + unless defined?(NSMenuView) + class NSMenuView; end + end + classes.concat([ + NSSimpleHorizontalTypesetter, + NSATSTypesetter, + NSColorSpace, + NSFont, + NSMenuView, + NSTextView, + ]) + # In addition, the following classes don't allow weak references on 10.7 + if ENV['deployment_target'] == '10.7' + puts 'TESTING OSX 10.7 CLASSES!' + if AVPlayer.new.allowsWeakReference + puts 'ERROR: Expected AVPlayer to not allow weak references!!' + end + classes.concat([ + AVPlayer, + NSFontManager, + NSFontPanel, + NSImage, + NSTableCellView, + NSViewController, + NSWindow, + NSWindowController, + ]) + end + end + classes.each do |klass| + puts "Testing whether allows weak references: #{klass.name}" + lambda { WeakRef.new(klass.new) }.should.raise(WeakRef::RefError) + end end end diff --git a/vm b/vm index 37c6ff62..6bbe580c 160000 --- a/vm +++ b/vm @@ -1 +1 @@ -Subproject commit 37c6ff62c49a9a64a6dff96e4ae193276684e07d +Subproject commit 6bbe580c6263c4ec567cbac66422383fd03db932