Skip to content

Commit

Permalink
An OJTest for the table view's content binding
Browse files Browse the repository at this point in the history
  • Loading branch information
cacaodev committed Jun 22, 2012
1 parent 086c0e6 commit 539a8f0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Tests/AppKit/CPTableViewTest.j
Expand Up @@ -217,6 +217,35 @@
[self assert:2 * visibleRows equals:[allViews count] message:"only as many data views as necessary should be present (2)"];
}

- (void)testContentBinding
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0, 0, 200, 150)
styleMask:CPWindowNotSizable],
contentBindingTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
tableColumn = [[CPTableColumn alloc] initWithIdentifier:@"A"],
delegate = [ContentBindingTableDelegate new];

[contentBindingTable addTableColumn:tableColumn];
[delegate setTester:self];
[contentBindingTable setDelegate:delegate];

[delegate setTableEntries:[[@"A1", @"B1"], [@"A2", @"B2"], [@"A3", @"B3"]]];
[contentBindingTable bind:@"content" toObject:delegate withKeyPath:@"tableEntries" options:nil];

// The following should also work:
//var ac = [[CPArrayController alloc] initWithContent:[delegate tableEntries]];
//[contentBindingTable bind:@"content" toObject:ac withKeyPath:@"arrangedObjects" options:nil];

[[theWindow contentView] addSubview:contentBindingTable];
[theWindow makeFirstResponder:contentBindingTable];

[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];

// Set the model again with different values
[delegate setTableEntries:[[@"C1", @"D1"], [@"C2", @"D2"], [@"C3", @"D3"]]];
[contentBindingTable reloadData];
}

@end

@implementation TestDataSource : CPObject
Expand Down Expand Up @@ -252,6 +281,21 @@

@end

@implementation ContentBindingTableDelegate : CPObject
{
// For the purpose of this test, the delegate contains the model (!).
CPArray tableEntries @accessors;
CPTableViewTest tester @accessors;
}

- (void)tableView:(CPTableView)aTableView willDisplayView:(CPView)aView forTableColumn:(CPTableColumn)tableColumn row:(int)row
{
// Make sure each view contains the full row in its objectValue
[tester assert:tableEntries[row] equals:[aView objectValue]];
}

@end

@implementation CustomTextView0 : CPTextField
@end

Expand Down

0 comments on commit 539a8f0

Please sign in to comment.