PageRenderTime 56ms CodeModel.GetById 27ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/AppKit/GTMLoginItemsTest.m

http://macfuse.googlecode.com/
Objective C | 137 lines | 66 code | 33 blank | 38 comment | 2 complexity | eddb977d0b4d01a1509c479295cec5df MD5 | raw file
  1//
  2//  GTMLoginItemsTest.m
  3//
  4//  Copyright 2006-2008 Google Inc.
  5//
  6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7//  use this file except in compliance with the License.  You may obtain a copy
  8//  of the License at
  9// 
 10//  http://www.apache.org/licenses/LICENSE-2.0
 11// 
 12//  Unless required by applicable law or agreed to in writing, software
 13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 15//  License for the specific language governing permissions and limitations under
 16//  the License.
 17//
 18
 19#import <SenTestingKit/SenTestingKit.h>
 20#import "GTMSenTestCase.h"
 21#import "GTMLoginItems.h"
 22
 23  // we don't really run this test because if someone had it in some automated
 24  // tests, then if something did fail, it could leave things in the login items
 25  // on the computer which could be a nasty surprise.
 26#define MODIFICATION_TESTS_ENABLED 0
 27
 28
 29@interface GTMLoginItemsTest : GTMTestCase
 30@end
 31
 32static BOOL ItemsListHasPath(NSArray *items, NSString *path) {
 33  NSDictionary *item = nil;
 34  GTM_FOREACH_OBJECT(item, items) {
 35    NSString *itemPath = [item objectForKey:kGTMLoginItemsPathKey];
 36    if (itemPath && [itemPath isEqual:path]) {
 37      return YES;
 38    }
 39  }
 40  return NO;
 41}
 42
 43@implementation GTMLoginItemsTest
 44
 45- (void)testNoModification {
 46
 47  NSError *error = nil;
 48  NSString *bogusAppPath = @"/Applications/AppThatDoesNotExist.app";
 49  NSString *bogusAppName = @"AppThatDoesNotExist";
 50  
 51  // fetch the starting values
 52  NSArray *initialItems = [GTMLoginItems loginItems:&error];
 53  STAssertNotNil(initialItems, @"shouldn't be nil (%@)", error);
 54  STAssertFalse(ItemsListHasPath(initialItems, bogusAppPath),
 55                @"bogusApp shouldn't be in list to start for test (%@)", initialItems);
 56  
 57  // check by path
 58  STAssertFalse([GTMLoginItems pathInLoginItems:bogusAppPath], nil);
 59  
 60  // check by name
 61  STAssertFalse([GTMLoginItems itemWithNameInLoginItems:bogusAppName], nil);
 62  
 63  // remove it by path
 64  [GTMLoginItems removePathFromLoginItems:bogusAppPath];
 65  NSArray *curItems = [GTMLoginItems loginItems:nil];
 66  STAssertEqualObjects(initialItems, curItems, nil);
 67  
 68  // remove it by name
 69  [GTMLoginItems removeItemWithNameFromLoginItems:bogusAppName];
 70  curItems = [GTMLoginItems loginItems:nil];
 71  STAssertEqualObjects(initialItems, curItems, nil);
 72
 73}
 74
 75- (void)testModification {
 76
 77#if MODIFICATION_TESTS_ENABLED
 78  
 79  NSError *error = nil;
 80  NSString *textEditPath = @"/Applications/TextEdit.app";
 81  NSString *textEditName = @"TextEdit";
 82  
 83  // fetch the starting values
 84  NSArray *initialItems = [GTMLoginItems loginItems:&error];
 85  STAssertNotNil(initialItems, @"shouldn't be nil (%@)", error);
 86  STAssertFalse(ItemsListHasPath(initialItems, textEditPath),
 87                @"textedit shouldn't be in list to start for test (%@)", initialItems);
 88  
 89  // add textedit
 90  [GTMLoginItems addPathToLoginItems:textEditPath hide:NO];
 91  NSArray *curItems = [GTMLoginItems loginItems:nil];
 92  STAssertNotEqualObjects(initialItems, curItems, nil);
 93  
 94  // check by path
 95  STAssertTrue([GTMLoginItems pathInLoginItems:textEditPath], nil);
 96  
 97  // check by name
 98  STAssertTrue([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
 99  
100  // remove it by path
101  [GTMLoginItems removePathFromLoginItems:textEditPath];
102  curItems = [GTMLoginItems loginItems:nil];
103  STAssertEqualObjects(initialItems, curItems, nil);
104  
105  // check by path
106  STAssertFalse([GTMLoginItems pathInLoginItems:textEditPath], nil);
107  
108  // check by name
109  STAssertFalse([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
110  
111  // add textedit
112  [GTMLoginItems addPathToLoginItems:textEditPath hide:NO];
113  curItems = [GTMLoginItems loginItems:nil];
114  STAssertNotEqualObjects(initialItems, curItems, nil);
115  
116  // check by path
117  STAssertTrue([GTMLoginItems pathInLoginItems:textEditPath], nil);
118  
119  // check by name
120  STAssertTrue([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
121  
122  // remove it by name
123  [GTMLoginItems removeItemWithNameFromLoginItems:textEditName];
124  curItems = [GTMLoginItems loginItems:nil];
125  STAssertEqualObjects(initialItems, curItems, nil);
126  
127  // check by path
128  STAssertFalse([GTMLoginItems pathInLoginItems:textEditPath], nil);
129  
130  // check by name
131  STAssertFalse([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
132  
133#endif // MODIFICATION_TESTS_ENABLED
134
135}
136
137@end