PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 16ms RepoModel.GetById 0ms app.codeStats 1ms

/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
15#import <SenTestingKit/SenTestingKit.h>
16#import "KSActionConstants.h"
17#import "KSActionPipe.h"
18#import "KSMemoryTicketStore.h"
19#import "KSOutOfBandDataAction.h"
20#import "KSUpdateEngine.h"
21
22
23@interface KSOutOfBandDataActionTest : SenTestCase {
24  KSOutOfBandDataAction *oobAction_;
25
26  // Set in the delegate if the delegate is called.
27  NSDictionary *seenOOBData_;
28  BOOL delegateCalled_;
29}
30@end
31
32
33@implementation KSOutOfBandDataActionTest
34
35- (void)setUp {
36  // Set up the life support to be able to run the action.
37  KSTicketStore *store = [[[KSMemoryTicketStore alloc] init] autorelease];
38  KSUpdateEngine *engine = [KSUpdateEngine engineWithTicketStore:store
39                                                        delegate:self];
40  oobAction_ = [[KSOutOfBandDataAction actionWithEngine:engine] retain];
41  KSActionPipe *inPipe = [KSActionPipe pipe];
42  KSActionPipe *outPipe = [KSActionPipe pipe];
43  [oobAction_ setInPipe:inPipe];
44  [oobAction_ setOutPipe:outPipe];
45
46  // Clean slate.
47  seenOOBData_ = nil;
48  delegateCalled_ = NO;
49}
50
51- (void)tearDown {
52  [oobAction_ release];
53  [seenOOBData_ release];
54}
55
56- (void)testCreation {
57  KSUpdateEngine *engine = [KSUpdateEngine engineWithDelegate:self];
58  KSOutOfBandDataAction *oobda =
59    [KSOutOfBandDataAction actionWithEngine:engine];
60  STAssertNotNil(oobda, nil);
61}
62
63- (void)testDelegateNotification {
64  NSDictionary *oobData = [NSDictionary dictionaryWithObjectsAndKeys:
65                                          @"snork", @"waffle", nil];
66  NSArray *infos = [NSArray array];
67
68  // Construct input with OOB data.
69  NSDictionary *input =
70    [NSDictionary dictionaryWithObjectsAndKeys:
71                  infos, KSActionUpdateInfosKey,
72                  oobData, KSActionOutOfBandDataKey,
73                  nil];
74  [[oobAction_ inPipe] setContents:input];
75
76  [oobAction_ performAction];
77  STAssertTrue(delegateCalled_, nil);
78  STAssertEquals(seenOOBData_, oobData, nil);
79
80  // Make sure the out pipe gets just the updateInfos.
81  STAssertEquals([[oobAction_ outPipe] contents], infos, nil);
82}
83
84// Delegate method.
85- (void)engine:(KSUpdateEngine *)engine hasOutOfBandData:(NSDictionary *)oob {
86  seenOOBData_ = [oob retain];
87  delegateCalled_ = YES;
88}
89
90@end