From 3055522645b55a4839ea5c901ed690b4482c1d94 Mon Sep 17 00:00:00 2001 From: Seth Buntin Date: Thu, 15 Oct 2009 21:40:25 -0500 Subject: [PATCH 01/11] implement CPDictionary Tests --- Tests/Foundation/CPDictionaryTest.j | 176 ++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Tests/Foundation/CPDictionaryTest.j diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j new file mode 100644 index 000000000..f3936b26b --- /dev/null +++ b/Tests/Foundation/CPDictionaryTest.j @@ -0,0 +1,176 @@ +@import + +@implementation CPDictionaryTest : OJTestCase +{ +} + +- (void)setUp +{ + json = { + "key1": ['1', '2', '3'], + "key2": "This is a string", + "key3": { + "another": "object" + } + } + + string_dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + json_dict = [CPDictionary dictionaryWithJSObject:json recursively:YES]; +} + +- (void)testInitWithDictionary +{ + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + + var new_dict = [[CPDictionary alloc] initWithDictionary:dict]; + [self assert:[new_dict objectForKey:@"key1"] equals:[dict objectForKey:@"key1"]]; + [self assert:[new_dict objectForKey:@"key2"] equals:[dict objectForKey:@"key2"]]; + + var new_dict_cm = [CPDictionary dictionaryWithDictionary:dict]; + [self assert:[new_dict_cm objectForKey:@"key1"] equals:[dict objectForKey:@"key1"]]; + [self assert:[new_dict_cm objectForKey:@"key2"] equals:[dict objectForKey:@"key2"]]; +} + +- (void)testInitWithObjects +{ + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + [self assert:[dict objectForKey:@"key1"] equals:@"1"]; + [self assert:[dict objectForKey:@"key2"] equals:@"2"]; + [self assert:[dict count] equals:2]; + + var dict_cm = [CPDictionary dictionaryWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; + [self assert:[dict_cm objectForKey:@"key1"] equals:@"1"]; + [self assert:[dict_cm objectForKey:@"key2"] equals:@"2"]; + [self assert:[dict_cm count] equals:2]; +} + +- (void)testDictionaryWithObject +{ + var dict = [CPDictionary dictionaryWithObject:@"1" forKey:@"key1"]; + [self assert:[dict objectForKey:@"key1"] equals:@"1"]; + [self assert:[dict count] equals:1]; +} + +- (void)testDictionaryWithJSObjectRecursive +{ + var dict = [CPDictionary dictionaryWithJSObject:json recursively:YES]; + [self assert:[dict count] equals:3]; + [self assert:[[dict objectForKey:@"key3"] count] equals:1]; +} + +- (void)testDictionaryWithJSObjectNonRecursive +{ + var non_recursive_dict = [CPDictionary dictionaryWithJSObject:json recursively:NO]; + [self assertThrows:[non_recursive_dict objectForKey:@"key3"]]; +} + +- (void)testCopy +{ + var copy = [string_dict copy]; + [self assert:copy notSame:string_dict]; + [self assert:[copy objectForKey:@"key1"] equals:[string_dict objectForKey:@"key1"]]; +} + +- (void)testCount +{ + [self assert:[string_dict count] equals:2]; + [self assert:[json_dict count] equals:3]; +} + +- (void)testAllKeys +{ + [self assert:[string_dict allKeys] equals:[@"key2", @"key1"]]; + [self assert:[json_dict allKeys] equals:[@"key1", @"key2", @"key3"]]; +} + +- (void)testAllValues +{ + [self assert:[string_dict allValues] equals:[@"1", @"2"]]; + // Had to get object from key to get test passing + [self assert:[json_dict allValues] equals:[[json_dict objectForKey:@"key3"], @"This is a string", ['1', '2', '3']]]; +} + +- (void)testObjectForKey +{ + [self assert:[string_dict objectForKey:@"key1"] equals:"1"]; + [self assert:[json_dict objectForKey:@"key1"] equals:['1', '2', '3']]; +} + +- (void)testKeyEnumerator +{ + var dict = [[CPDictionary alloc] init]; + [self assertNull:[[dict keyEnumerator] nextObject]]; + [self assertNotNull:[[dict keyEnumerator] allObjects]]; + + [self assertNotNull:[[string_dict keyEnumerator] nextObject]]; + [self assertNotNull:[[json_dict keyEnumerator] nextObject]]; + [self assertNotNull:[[string_dict keyEnumerator] allObjects]]; + [self assertNotNull:[[json_dict keyEnumerator] allObjects]]; +} + +- (void)testObjectEnumerator +{ + var dict = [[CPDictionary alloc] init]; + [self assertNull:[[dict objectEnumerator] nextObject]]; + [self assertNotNull:[[dict objectEnumerator] allObjects]]; + + [self assertNotNull:[[string_dict objectEnumerator] nextObject]]; + [self assertNotNull:[[json_dict objectEnumerator] nextObject]]; + [self assertNotNull:[[string_dict objectEnumerator] allObjects]]; + [self assertNotNull:[[json_dict objectEnumerator] allObjects]]; +} + +- (void)testIsEqualToDictionary +{ + [self assertTrue:[string_dict isEqualToDictionary:[string_dict copy]]]; + [self assertTrue:[json_dict isEqualToDictionary:[json_dict copy]]]; + [self assertFalse:[json_dict isEqualToDictionary:[string_dict copy]]]; +} + +- (void)testRemoveAllObjects +{ + [string_dict removeAllObjects]; + [json_dict removeAllObjects]; + [self assert:[string_dict count] equals:0]; + [self assert:[json_dict count] equals:0]; +} + +- (void)testRemoveObjectForKey +{ + [string_dict removeObjectForKey:@"key1"]; + [json_dict removeObjectForKey:@"key1"]; + [self assert:[string_dict count] equals:1]; + [self assert:[json_dict count] equals:2]; + [self assertThrows:[string_dict objectForKey:@"key1"]]; + [self assertThrows:[json_dict objectForKey:@"key1"]]; +} + +- (void)testRemoveObjectsForKeys +{ + [string_dict removeObjectsForKeys:[@"key1"]]; + [json_dict removeObjectsForKeys:[@"key1", @"key2"]]; + [self assert:[string_dict count] equals:1]; + [self assert:[json_dict count] equals:1]; + [self assertThrows:[string_dict objectForKey:@"key1"]]; + [self assertThrows:[json_dict objectForKey:@"key1"]]; + [self assertThrows:[json_dict objectForKey:@"key2"]]; +} + +- (void)testSetObjectForKey +{ + var dict = [[CPDictionary alloc] init]; + [dict setObject:@"setObjectForKey test" forKey:@"key1"]; + [self assert:[dict objectForKey:@"key1"] equals:@"setObjectForKey test"]; + [self assert:[dict count] equals:1]; +} + +- (void)testAddEntriesFromDictionary +{ + var dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key4", @"key5"]]; + [string_dict addEntriesFromDictionary:dict] + [json_dict addEntriesFromDictionary:dict] + [self assert:[string_dict count] equals:4]; + [self assert:[json_dict count] equals:5]; +} + +@end \ No newline at end of file From f2e95f7e63201bf1387406f9d56f1c1c4f090a82 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Thu, 15 Oct 2009 23:27:15 -0700 Subject: [PATCH 02/11] Fix a broken import which caused all tests to fail. --- Tests/Foundation/CPURLTest.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Foundation/CPURLTest.j b/Tests/Foundation/CPURLTest.j index 2df97011d..ea6ee8452 100644 --- a/Tests/Foundation/CPURLTest.j +++ b/Tests/Foundation/CPURLTest.j @@ -1,4 +1,4 @@ -@import "CPURL.j" +@import var exampleProtocol = "http", exampleUser = "foo", From f925585475bc415dfffc0a7f75eb2b2c97b8fdf7 Mon Sep 17 00:00:00 2001 From: tlrobinson Date: Fri, 16 Oct 2009 13:29:22 -0700 Subject: [PATCH 03/11] Fixed objj command line importing. --- Objective-J/Tools/objj/lib-js/objj/objj.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objective-J/Tools/objj/lib-js/objj/objj.js b/Objective-J/Tools/objj/lib-js/objj/objj.js index 51263f401..41431ace3 100644 --- a/Objective-J/Tools/objj/lib-js/objj/objj.js +++ b/Objective-J/Tools/objj/lib-js/objj/objj.js @@ -134,7 +134,7 @@ var objj_eval = exports.objj_eval = function(code) } // prepocesses Objective-J code into JavaScript, which will perform imports synchronously when eval'd -var objj_preprocess_sync = function(code, path) +window.objj_preprocess_sync = function(code, path) { var fragments = objj_preprocess(code, new objj_bundle(), new objj_file(), OBJJ_PREPROCESSOR_DEBUG_SYMBOLS) @@ -153,7 +153,7 @@ var objj_preprocess_sync = function(code, path) } // synchronously perform an import -var objj_import_sync = function(pathOrPaths, isLocal) +window.objj_import_sync = function(pathOrPaths, isLocal) { var context = new objj_context(); context.pushFragment(fragment_create_file(pathOrPaths, new objj_bundle(), isLocal, NULL)); From 42775cb152edd21ab64957862266e02ec528a6df Mon Sep 17 00:00:00 2001 From: tlrobinson Date: Fri, 16 Oct 2009 13:29:40 -0700 Subject: [PATCH 04/11] Limit tests to those that end with *Test.j --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 05a81dfee..695a67f7e 100644 --- a/Rakefile +++ b/Rakefile @@ -118,7 +118,7 @@ task :install => [:tools_download] do end task :test => [:build] do - tests = "'" + FileList['Tests/**/*.j'].join("' '") + "'" + tests = "'" + FileList['Tests/**/*Test.j'].join("' '") + "'" build_result = %x{ojtest #{tests} } if build_result.match(/Test suite failed/i) From ea252323d2eebbd8aee9762c87fc8a41ecc19989 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 16 Oct 2009 14:34:35 -0700 Subject: [PATCH 05/11] Cleaned up the test to better fit the xUnit standard Conflicts: Tests/AppKit/CPCollectionViewTest.j --- Tests/AppKit/CPCollectionViewTest.j | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Tests/AppKit/CPCollectionViewTest.j b/Tests/AppKit/CPCollectionViewTest.j index fc6eeafe2..485a8a4c8 100644 --- a/Tests/AppKit/CPCollectionViewTest.j +++ b/Tests/AppKit/CPCollectionViewTest.j @@ -2,15 +2,30 @@ @import @implementation CPCollectionViewTest : OJTestCase +{ + CPCollectionView _collectionView; +} + +- (void)setUp +{ + _collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()]; +} - (void)testItemPrototypeActuallyReturnsTheItemPrototype { - var propertiesCollectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()], - itemPrototype = [[CPCollectionViewItem alloc] init]; - - [propertiesCollectionView setItemPrototype:itemPrototype]; + var itemPrototype = [[CPCollectionViewItem alloc] init]; + [_collectionView setItemPrototype:itemPrototype]; - [self assert:[CPCollectionViewItem class] equals:[[propertiesCollectionView itemPrototype] class]]; + [self assert:[CPCollectionViewItem class] equals:[[_collectionView itemPrototype] class]]; +} + +- (void)testIsSelectableActuallyReturnsSelectableStatus +{ + [_collectionView setSelectable:YES]; + [self assertTrue:[_collectionView isSelectable]]; + + [_collectionView setSelectable:NO]; + [self assertFalse:[_collectionView isSelectable]]; } @end From ea15b247d328a7c45edaefd263eec1d74b1d6f13 Mon Sep 17 00:00:00 2001 From: Andreas Falk Date: Sat, 10 Oct 2009 00:17:40 +0200 Subject: [PATCH 06/11] Made the item prototype test in the CPCollectionView test check for identity instead of equality --- Tests/AppKit/CPCollectionViewTest.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/AppKit/CPCollectionViewTest.j b/Tests/AppKit/CPCollectionViewTest.j index 485a8a4c8..220ca42df 100644 --- a/Tests/AppKit/CPCollectionViewTest.j +++ b/Tests/AppKit/CPCollectionViewTest.j @@ -16,7 +16,7 @@ var itemPrototype = [[CPCollectionViewItem alloc] init]; [_collectionView setItemPrototype:itemPrototype]; - [self assert:[CPCollectionViewItem class] equals:[[_collectionView itemPrototype] class]]; + [self assert:itemPrototype same:[_collectionView itemPrototype]]; } - (void)testIsSelectableActuallyReturnsSelectableStatus From 666ac4acd1a9b27b64a4884426818b69a4d05647 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 16 Oct 2009 14:37:58 -0700 Subject: [PATCH 07/11] Added test for 09858caaedfdc9211b7ee7355e104890b67d0d5e Conflicts: Tests/AppKit/CPCollectionViewTest.j --- Tests/AppKit/CPCollectionViewTest.j | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Tests/AppKit/CPCollectionViewTest.j b/Tests/AppKit/CPCollectionViewTest.j index 220ca42df..d9c0c6bfb 100644 --- a/Tests/AppKit/CPCollectionViewTest.j +++ b/Tests/AppKit/CPCollectionViewTest.j @@ -19,13 +19,15 @@ [self assert:itemPrototype same:[_collectionView itemPrototype]]; } -- (void)testIsSelectableActuallyReturnsSelectableStatus +- (void)testIsSelectableGetter { - [_collectionView setSelectable:YES]; - [self assertTrue:[_collectionView isSelectable]]; + var collectionView = [[CPCollectionView alloc] initWithFrame:CGRectMakeZero()]; - [_collectionView setSelectable:NO]; - [self assertFalse:[_collectionView isSelectable]]; + [collectionView setSelectable:YES]; + [self assertTrue:[collectionView isSelectable]]; + + [collectionView setSelectable:NO]; + [self assertFalse:[collectionView isSelectable]]; } @end From c7520593da0f35b630b68f1e8068aa84cfa9d47e Mon Sep 17 00:00:00 2001 From: Andreas Falk Date: Fri, 9 Oct 2009 22:01:28 +0200 Subject: [PATCH 08/11] Added getter for isSelectable and removed the getter for isSelected --- AppKit/CPCollectionView.j | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index b59710e75..0fbb7b219 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -250,11 +250,11 @@ /*! Returns \c YES if the collection view is - selected, and \c NO otherwise. + selectable, and \c NO otherwise. */ -- (BOOL)isSelected +- (BOOL)isSelectable { - return _isSelected; + return _isSelectable; } /*! From 41cb21cd0f1354ab457c7bad6020d7bc9357f182 Mon Sep 17 00:00:00 2001 From: Andreas Falk Date: Fri, 9 Oct 2009 21:42:07 +0200 Subject: [PATCH 09/11] Made CPCollectionView encode and decode the isSelectable property to the cib --- AppKit/CPCollectionView.j | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 0fbb7b219..d671f5aff 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -675,6 +675,7 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", CPCollectionViewMaxItemSizeKey = @"CPCollectionViewMaxItemSizeKey", CPCollectionViewVerticalMarginKey = @"CPCollectionViewVerticalMarginKey", + CPCollectionViewSelectable = @"CPCollectionViewSelectable", CPCollectionViewBackgroundColorsKey = @"CPCollectionViewBackgroundColorsKey"; @@ -695,7 +696,10 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", _minItemSize = [aCoder decodeSizeForKey:CPCollectionViewMinItemSizeKey] || CGSizeMakeZero(); _maxItemSize = [aCoder decodeSizeForKey:CPCollectionViewMaxItemSizeKey] || CGSizeMakeZero(); + _verticalMargin = [aCoder decodeFloatForKey:CPCollectionViewVerticalMarginKey]; + + _isSelectable = [aCoder decodeBoolForKey:CPCollectionViewSelectable]; [self setBackgroundColors:[aCoder decodeObjectForKey:CPCollectionViewBackgroundColorsKey]]; @@ -704,7 +708,6 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", _selectionIndexes = [CPIndexSet indexSet]; _allowsEmptySelection = YES; - _isSelectable = YES; } return self; @@ -716,10 +719,12 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", if (!CGSizeEqualToSize(_minItemSize, CGSizeMakeZero())) [aCoder encodeSize:_minItemSize forKey:CPCollectionViewMinItemSizeKey]; - + if (!CGSizeEqualToSize(_maxItemSize, CGSizeMakeZero())) [aCoder encodeSize:_maxItemSize forKey:CPCollectionViewMaxItemSizeKey]; - + + [aCoder encodeBool:_isSelectable forKey:CPCollectionViewSelectable]; + [aCoder encodeFloat:_verticalMargin forKey:CPCollectionViewVerticalMarginKey]; [aCoder encodeObject:_backgroundColors forKey:CPCollectionViewBackgroundColorsKey]; From 385bec74000048260857871f758c7e7fe542bfae Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 16 Oct 2009 15:22:12 -0700 Subject: [PATCH 10/11] Corrects a style issue. --- AppKit/CPCollectionView.j | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index d671f5aff..2dbab4bfe 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -675,7 +675,7 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", CPCollectionViewMaxItemSizeKey = @"CPCollectionViewMaxItemSizeKey", CPCollectionViewVerticalMarginKey = @"CPCollectionViewVerticalMarginKey", - CPCollectionViewSelectable = @"CPCollectionViewSelectable", + CPCollectionViewSelectableKey = @"CPCollectionViewSelectableKey", CPCollectionViewBackgroundColorsKey = @"CPCollectionViewBackgroundColorsKey"; @@ -699,7 +699,7 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", _verticalMargin = [aCoder decodeFloatForKey:CPCollectionViewVerticalMarginKey]; - _isSelectable = [aCoder decodeBoolForKey:CPCollectionViewSelectable]; + _isSelectable = [aCoder decodeBoolForKey:CPCollectionViewSelectableKey]; [self setBackgroundColors:[aCoder decodeObjectForKey:CPCollectionViewBackgroundColorsKey]]; @@ -723,7 +723,7 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", if (!CGSizeEqualToSize(_maxItemSize, CGSizeMakeZero())) [aCoder encodeSize:_maxItemSize forKey:CPCollectionViewMaxItemSizeKey]; - [aCoder encodeBool:_isSelectable forKey:CPCollectionViewSelectable]; + [aCoder encodeBool:_isSelectable forKey:CPCollectionViewSelectableKey]; [aCoder encodeFloat:_verticalMargin forKey:CPCollectionViewVerticalMarginKey]; From 6076185da7bdd76edc1b2b8fc861a3b4ad72fc00 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Sun, 18 Oct 2009 17:35:53 -0700 Subject: [PATCH 11/11] Added application activation. Reviewed by me. --- AppKit/CPApplication.j | 5 +++++ AppKit/CPWindow/CPWindow.j | 2 ++ AppKit/Platform/CPPlatform.j | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 72f88a420..717d02993 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -298,6 +298,11 @@ CPRunContinuesResponse = -1002; [CPPlatform terminateApplication]; } +- (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps +{ + [CPPlatform activateIgnoringOtherApps:shouldIgnoreOtherApps]; +} + /*! Calls \c -finishLaunching method which results in starting the main event loop. diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 2c0c0693d..58f051a88 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -1264,6 +1264,8 @@ CPTexturedBackgroundWindowMask if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder]) [self makeFirstResponder:_leftMouseDownView]; + [CPApp activateIgnoringOtherApps:YES]; + var theWindow = [anEvent window]; if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded]) diff --git a/AppKit/Platform/CPPlatform.j b/AppKit/Platform/CPPlatform.j index 851e538bc..a5eac3712 100644 --- a/AppKit/Platform/CPPlatform.j +++ b/AppKit/Platform/CPPlatform.j @@ -45,4 +45,12 @@ window.cpTerminate(); } ++ (void)activateIgnoringOtherApps:(BOOL)shouldIgnoreOtherApps +{ +#if PLATFORM(DOM) + if (typeof window["cpActivateIgnoringOtherApps"] === "function") + window.cpActivateIgnoringOtherApps(!!shouldIgnoreOtherApps); +#endif +} + @end