Index: iPhone/GTMABAddressBookTest.m |
=================================================================== |
--- iPhone/GTMABAddressBookTest.m (revision 70) |
+++ iPhone/GTMABAddressBookTest.m (working copy) |
@@ -500,6 +500,66 @@ |
} |
+- (void)testPeopleWithName { |
+ GTMABPerson *person1 = [GTMABPerson personWithFirstName:@"Bart" |
+ lastName:@"Simpson"]; |
+ GTMABPerson *person2 = [GTMABPerson personWithFirstName:@"Bart" |
+ lastName:nil]; |
+ STAssertNotNil(person1, nil); |
+ STAssertNotNil(person2, nil); |
+ STAssertTrue([person1 setValue:@"Mr." |
+ forProperty:kABPersonPrefixProperty], nil); |
+ STAssertTrue([person2 setValue:@"Mr." |
+ forProperty:kABPersonPrefixProperty], nil); |
+ STAssertEqualObjects([person1 compositeName], @"Mr. Bart Simpson", nil); |
+ STAssertEqualObjects([person2 compositeName], @"Mr. Bart", nil); |
+ |
+ NSArray *people = [book_ people]; |
+ STAssertFalse([people containsObject:person1], nil); |
+ STAssertFalse([people containsObject:person2], nil); |
+ STAssertTrue([book_ addRecord:person1], nil); |
+ STAssertTrue([book_ addRecord:person2], nil); |
+ STAssertTrue([book_ save], nil); |
+ |
+ people = [book_ people]; |
+ STAssertTrue([people containsObject:person1], nil); |
+ STAssertTrue([people containsObject:person2], nil); |
+ |
+ NSArray *matched = [book_ peopleWithName:@"WrongName"]; |
+ int count = [matched count]; |
+ STAssertNotNil(matched, nil); |
+ STAssertEquals(count, 0, nil); |
+ |
+ // This really should match both contacts, but because of |
+ // Radar 6425729: ABAddressBookCopyPeopleWithName() does not |
+ // correctly match by composite name |
+ // it doesn't match either of them (because of the prefix) |
+ matched = [book_ peopleWithName:@"Mr. Bart*"]; |
+ count = [matched count]; |
+ STAssertNotNil(matched, nil); |
+ STAssertEquals(count, 0, nil); |
+ STAssertFalse([matched containsObject:person1], nil); |
+ STAssertFalse([matched containsObject:person2], nil); |
+ |
+ matched = [book_ peopleWithName:@"Bart*"]; |
+ count = [matched count]; |
+ STAssertNotNil(matched, nil); |
+ STAssertEquals(count, 2, nil); |
+ STAssertTrue([matched containsObject:person1], nil); |
+ STAssertTrue([matched containsObject:person2], nil); |
+ |
+ matched = [book_ peopleWithName:@"Bart Simpson"]; |
+ count = [matched count]; |
+ STAssertNotNil(matched, nil); |
+ STAssertEquals(count, 1, nil); |
+ STAssertTrue([matched containsObject:person1], nil); |
+ STAssertFalse([matched containsObject:person2], nil); |
+ |
+ STAssertTrue([book_ removeRecord:person1], nil); |
+ STAssertTrue([book_ removeRecord:person2], nil); |
+ STAssertTrue([book_ save], nil); |
+} |
+ |
- (void)testRadar6208390 { |
ABPropertyType types[] = { |
kABStringPropertyType, |