/core/externals/update-engine/Core/KSOutOfBandDataActionTest.m

http://macfuse.googlecode.com/ · Objective C · 90 lines · 55 code · 16 blank · 19 comment · 0 complexity · 7c9ac32fad5ff3f905c24af83e449fe6 MD5 · raw file

  1. // Copyright 2010 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <SenTestingKit/SenTestingKit.h>
  15. #import "KSActionConstants.h"
  16. #import "KSActionPipe.h"
  17. #import "KSMemoryTicketStore.h"
  18. #import "KSOutOfBandDataAction.h"
  19. #import "KSUpdateEngine.h"
  20. @interface KSOutOfBandDataActionTest : SenTestCase {
  21. KSOutOfBandDataAction *oobAction_;
  22. // Set in the delegate if the delegate is called.
  23. NSDictionary *seenOOBData_;
  24. BOOL delegateCalled_;
  25. }
  26. @end
  27. @implementation KSOutOfBandDataActionTest
  28. - (void)setUp {
  29. // Set up the life support to be able to run the action.
  30. KSTicketStore *store = [[[KSMemoryTicketStore alloc] init] autorelease];
  31. KSUpdateEngine *engine = [KSUpdateEngine engineWithTicketStore:store
  32. delegate:self];
  33. oobAction_ = [[KSOutOfBandDataAction actionWithEngine:engine] retain];
  34. KSActionPipe *inPipe = [KSActionPipe pipe];
  35. KSActionPipe *outPipe = [KSActionPipe pipe];
  36. [oobAction_ setInPipe:inPipe];
  37. [oobAction_ setOutPipe:outPipe];
  38. // Clean slate.
  39. seenOOBData_ = nil;
  40. delegateCalled_ = NO;
  41. }
  42. - (void)tearDown {
  43. [oobAction_ release];
  44. [seenOOBData_ release];
  45. }
  46. - (void)testCreation {
  47. KSUpdateEngine *engine = [KSUpdateEngine engineWithDelegate:self];
  48. KSOutOfBandDataAction *oobda =
  49. [KSOutOfBandDataAction actionWithEngine:engine];
  50. STAssertNotNil(oobda, nil);
  51. }
  52. - (void)testDelegateNotification {
  53. NSDictionary *oobData = [NSDictionary dictionaryWithObjectsAndKeys:
  54. @"snork", @"waffle", nil];
  55. NSArray *infos = [NSArray array];
  56. // Construct input with OOB data.
  57. NSDictionary *input =
  58. [NSDictionary dictionaryWithObjectsAndKeys:
  59. infos, KSActionUpdateInfosKey,
  60. oobData, KSActionOutOfBandDataKey,
  61. nil];
  62. [[oobAction_ inPipe] setContents:input];
  63. [oobAction_ performAction];
  64. STAssertTrue(delegateCalled_, nil);
  65. STAssertEquals(seenOOBData_, oobData, nil);
  66. // Make sure the out pipe gets just the updateInfos.
  67. STAssertEquals([[oobAction_ outPipe] contents], infos, nil);
  68. }
  69. // Delegate method.
  70. - (void)engine:(KSUpdateEngine *)engine hasOutOfBandData:(NSDictionary *)oob {
  71. seenOOBData_ = [oob retain];
  72. delegateCalled_ = YES;
  73. }
  74. @end