mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-03 21:58:59 +00:00
Keyed archiving preserves view hierarchies created in code. Decoded views retain their content, subviews and state, and each view class is verified against its own description before archiving. * CPAccordionView: Add CPCoding to CPAccordionView and CPAccordionViewItem. * CPBox: * Encode the content, title and box views unconditionally. * Clear the superviews of the box and title views during decoding. * CPButton: Initialize the value to CPOffState. * CPMapTable: Add CPCoding. * CPPopUpButton: Clear the inherited button value. * CPSearchField: Update the cancel button when the object value changes. * CPSplitView: Return nil from dividerColor when the theme defines no divider image. * CPStepper: Discard the decoded buttons before recreating them. * CPTabView: * Encode the current tab view items. * Exclude the tabs from the encoded subviews. * CPTokenField: * Discard the decoded scroll view before recreating it. * Add the decoded tokens to the new document view. * CPVisualEffectView: Resolve the backdrop filter property only when a DOM is available. * CPBoxTest: Verify preservation of the content view, hierarchy and title, and decoding of an untitled box without warnings. * CPButtonTest: Verify the initial value of a button. * CPMapTableTest: Verify preservation of entries through archiving. * DropInArchiveFixtures: Add populated view fixtures, tree comparison, and round trip and saved archive helpers. * DropInArchiveGenerator: Save cib descriptions and view archives, and write no archive data if any view fails its round trip. * DropInArchiveTest: Verify new archives, saved archives and reference cibs, and treat decoding warnings as failures. * DropInSnapshot: * Describe the view hierarchy through private views, with state and content. * Add DropInWithFixedScrollerStyle. * DropInArchives, DropInCibs: Add saved view archives, cib descriptions and reference cibs.
168 lines
5.0 KiB
Plaintext
168 lines
5.0 KiB
Plaintext
@import <Foundation/CPMapTable.j>
|
|
@import <Foundation/CPDictionary.j>
|
|
@import <Foundation/CPEnumerator.j>
|
|
@import <Foundation/CPKeyedArchiver.j>
|
|
@import <Foundation/CPKeyedUnarchiver.j>
|
|
@import <Foundation/CPMutableArray.j>
|
|
@import <OJUnit/OJTestCase.j>
|
|
|
|
@implementation CPMapTableTest : OJTestCase
|
|
{
|
|
CPMapTable map_table;
|
|
id objectKey;
|
|
}
|
|
|
|
- (void)setUp
|
|
{
|
|
map_table = [[CPMapTable alloc] init];
|
|
objectKey = [[CPObject alloc] init];
|
|
}
|
|
|
|
- (void)testInit
|
|
{
|
|
[self assert:[map_table count] equals:0];
|
|
}
|
|
|
|
- (void)testSetObjectForKey
|
|
{
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[self assert:[map_table count] equals:1];
|
|
[self assert:[map_table objectForKey:@"key1"] equals:@"value1"];
|
|
|
|
[map_table setObject:@"value2" forKey:123];
|
|
[self assert:[map_table count] equals:2];
|
|
[self assert:[map_table objectForKey:123] equals:@"value2"];
|
|
|
|
[map_table setObject:@"value3" forKey:objectKey];
|
|
[self assert:[map_table count] equals:3];
|
|
[self assert:[map_table objectForKey:objectKey] equals:@"value3"];
|
|
|
|
// Test overriding a value
|
|
[map_table setObject:@"newValue" forKey:@"key1"];
|
|
[self assert:[map_table count] equals:3];
|
|
[self assert:[map_table objectForKey:@"key1"] equals:@"newValue"];
|
|
}
|
|
|
|
- (void)testObjectForKey
|
|
{
|
|
[self assertNull:[map_table objectForKey:@"nonExistentKey"]];
|
|
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[self assert:[map_table objectForKey:@"key1"] equals:@"value1"];
|
|
}
|
|
|
|
- (void)testCount
|
|
{
|
|
[self assert:[map_table count] equals:0];
|
|
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[self assert:[map_table count] equals:1];
|
|
|
|
[map_table setObject:@"value2" forKey:@"key2"];
|
|
[self assert:[map_table count] equals:2];
|
|
|
|
[map_table removeObjectForKey:@"key1"];
|
|
[self assert:[map_table count] equals:1];
|
|
}
|
|
|
|
- (void)testRemoveObjectForKey
|
|
{
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[map_table setObject:@"value2" forKey:123];
|
|
|
|
[map_table removeObjectForKey:@"key1"];
|
|
[self assert:[map_table count] equals:1];
|
|
[self assertNull:[map_table objectForKey:@"key1"]];
|
|
[self assert:[map_table objectForKey:123] equals:@"value2"];
|
|
|
|
[map_table removeObjectForKey:123];
|
|
[self assert:[map_table count] equals:0];
|
|
[self assertNull:[map_table objectForKey:123]];
|
|
}
|
|
|
|
- (void)testRemoveAllObjects
|
|
{
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[map_table setObject:@"value2" forKey:@"key2"];
|
|
|
|
[map_table removeAllObjects];
|
|
[self assert:[map_table count] equals:0];
|
|
[self assertNull:[map_table objectForKey:@"key1"]];
|
|
[self assertNull:[map_table objectForKey:@"key2"]];
|
|
}
|
|
|
|
- (void)testKeyEnumeratorOnEmptyMap
|
|
{
|
|
[self assert:[map_table count] equals:0 message:@"Pre-condition failed: map should be empty."];
|
|
[self assertNull:[[map_table keyEnumerator] nextObject]];
|
|
}
|
|
|
|
- (void)testKeyEnumeratorOnPopulatedMap
|
|
{
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[map_table setObject:@"value2" forKey:123];
|
|
[map_table setObject:@"value3" forKey:objectKey];
|
|
|
|
var foundKeys = [CPMutableArray array],
|
|
enumerator = [map_table keyEnumerator],
|
|
aKey;
|
|
|
|
while (aKey = [enumerator nextObject])
|
|
[foundKeys addObject:aKey];
|
|
|
|
[self assert:[foundKeys count] equals:3];
|
|
[self assertTrue:[foundKeys containsObject:@"key1"]];
|
|
[self assertTrue:[foundKeys containsObject:123]];
|
|
[self assertTrue:[foundKeys containsObject:objectKey]];
|
|
}
|
|
|
|
- (void)testObjectEnumeratorOnEmptyMap
|
|
{
|
|
[self assert:[map_table count] equals:0 message:@"Pre-condition failed: map should be empty."];
|
|
[self assertNull:[[map_table objectEnumerator] nextObject]];
|
|
}
|
|
|
|
- (void)testObjectEnumeratorOnPopulatedMap
|
|
{
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[map_table setObject:@"value2" forKey:123];
|
|
[map_table setObject:@"value3" forKey:objectKey];
|
|
|
|
var foundValues = [CPMutableArray array],
|
|
enumerator = [map_table objectEnumerator],
|
|
aValue;
|
|
|
|
while (aValue = [enumerator nextObject])
|
|
[foundValues addObject:aValue];
|
|
|
|
[self assert:[foundValues count] equals:3];
|
|
[self assertTrue:[foundValues containsObject:@"value1"]];
|
|
[self assertTrue:[foundValues containsObject:@"value2"]];
|
|
[self assertTrue:[foundValues containsObject:@"value3"]];
|
|
}
|
|
|
|
- (void)testArchivingPreservesEntries
|
|
{
|
|
[map_table setObject:@"first" forKey:@"one"];
|
|
[map_table setObject:@"second" forKey:@"two"];
|
|
|
|
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:map_table]];
|
|
|
|
[self assert:2 equals:[decoded count]];
|
|
[self assert:@"first" equals:[decoded objectForKey:@"one"]];
|
|
[self assert:@"second" equals:[decoded objectForKey:@"two"]];
|
|
}
|
|
|
|
- (void)testDictionaryRepresentation
|
|
{
|
|
[map_table setObject:@"value1" forKey:@"key1"];
|
|
[map_table setObject:@"value2" forKey:@"key2"];
|
|
|
|
var dictionary = [map_table dictionaryRepresentation];
|
|
[self assert:[dictionary count] equals:2];
|
|
[self assert:[dictionary objectForKey:@"key1"] equals:@"value1"];
|
|
[self assert:[dictionary objectForKey:@"key2"] equals:@"value2"];
|
|
}
|
|
|
|
@end
|