/core/externals/update-engine/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. #import <SenTestingKit/SenTestingKit.h>
  19. #import "GTMSenTestCase.h"
  20. #import "GTMLoginItems.h"
  21. // we don't really run this test because if someone had it in some automated
  22. // tests, then if something did fail, it could leave things in the login items
  23. // on the computer which could be a nasty surprise.
  24. #define MODIFICATION_TESTS_ENABLED 0
  25. @interface GTMLoginItemsTest : GTMTestCase
  26. @end
  27. static BOOL ItemsListHasPath(NSArray *items, NSString *path) {
  28. NSDictionary *item = nil;
  29. GTM_FOREACH_OBJECT(item, items) {
  30. NSString *itemPath = [item objectForKey:kGTMLoginItemsPathKey];
  31. if (itemPath && [itemPath isEqual:path]) {
  32. return YES;
  33. }
  34. }
  35. return NO;
  36. }
  37. @implementation GTMLoginItemsTest
  38. - (void)testNoModification {
  39. NSError *error = nil;
  40. NSString *bogusAppPath = @"/Applications/AppThatDoesNotExist.app";
  41. NSString *bogusAppName = @"AppThatDoesNotExist";
  42. // fetch the starting values
  43. NSArray *initialItems = [GTMLoginItems loginItems:&error];
  44. STAssertNotNil(initialItems, @"shouldn't be nil (%@)", error);
  45. STAssertFalse(ItemsListHasPath(initialItems, bogusAppPath),
  46. @"bogusApp shouldn't be in list to start for test (%@)", initialItems);
  47. // check by path
  48. STAssertFalse([GTMLoginItems pathInLoginItems:bogusAppPath], nil);
  49. // check by name
  50. STAssertFalse([GTMLoginItems itemWithNameInLoginItems:bogusAppName], nil);
  51. // remove it by path
  52. [GTMLoginItems removePathFromLoginItems:bogusAppPath];
  53. NSArray *curItems = [GTMLoginItems loginItems:nil];
  54. STAssertEqualObjects(initialItems, curItems, nil);
  55. // remove it by name
  56. [GTMLoginItems removeItemWithNameFromLoginItems:bogusAppName];
  57. curItems = [GTMLoginItems loginItems:nil];
  58. STAssertEqualObjects(initialItems, curItems, nil);
  59. }
  60. - (void)testModification {
  61. #if MODIFICATION_TESTS_ENABLED
  62. NSError *error = nil;
  63. NSString *textEditPath = @"/Applications/TextEdit.app";
  64. NSString *textEditName = @"TextEdit";
  65. // fetch the starting values
  66. NSArray *initialItems = [GTMLoginItems loginItems:&error];
  67. STAssertNotNil(initialItems, @"shouldn't be nil (%@)", error);
  68. STAssertFalse(ItemsListHasPath(initialItems, textEditPath),
  69. @"textedit shouldn't be in list to start for test (%@)", initialItems);
  70. // add textedit
  71. [GTMLoginItems addPathToLoginItems:textEditPath hide:NO];
  72. NSArray *curItems = [GTMLoginItems loginItems:nil];
  73. STAssertNotEqualObjects(initialItems, curItems, nil);
  74. // check by path
  75. STAssertTrue([GTMLoginItems pathInLoginItems:textEditPath], nil);
  76. // check by name
  77. STAssertTrue([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
  78. // remove it by path
  79. [GTMLoginItems removePathFromLoginItems:textEditPath];
  80. curItems = [GTMLoginItems loginItems:nil];
  81. STAssertEqualObjects(initialItems, curItems, nil);
  82. // check by path
  83. STAssertFalse([GTMLoginItems pathInLoginItems:textEditPath], nil);
  84. // check by name
  85. STAssertFalse([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
  86. // add textedit
  87. [GTMLoginItems addPathToLoginItems:textEditPath hide:NO];
  88. curItems = [GTMLoginItems loginItems:nil];
  89. STAssertNotEqualObjects(initialItems, curItems, nil);
  90. // check by path
  91. STAssertTrue([GTMLoginItems pathInLoginItems:textEditPath], nil);
  92. // check by name
  93. STAssertTrue([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
  94. // remove it by name
  95. [GTMLoginItems removeItemWithNameFromLoginItems:textEditName];
  96. curItems = [GTMLoginItems loginItems:nil];
  97. STAssertEqualObjects(initialItems, curItems, nil);
  98. // check by path
  99. STAssertFalse([GTMLoginItems pathInLoginItems:textEditPath], nil);
  100. // check by name
  101. STAssertFalse([GTMLoginItems itemWithNameInLoginItems:textEditName], nil);
  102. #endif // MODIFICATION_TESTS_ENABLED
  103. }
  104. @end