PageRenderTime 59ms CodeModel.GetById 14ms app.highlight 42ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 167 lines | 114 code | 39 blank | 14 comment | 0 complexity | 82be539fc31442a28d55cacd2a2f7c9b MD5 | raw file
  1// Copyright 2008 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 "KSCheckAction.h"
 17#import "KSActionProcessor.h"
 18#import "KSExistenceChecker.h"
 19#import "KSTicket.h"
 20#import "KSUpdateEngine.h"
 21
 22
 23@interface KSCheckActionTest : SenTestCase
 24@end
 25
 26
 27@implementation KSCheckActionTest
 28
 29- (void)testCreation {
 30  KSCheckAction *action = [[[KSCheckAction alloc] init] autorelease];
 31  STAssertNotNil(action, nil);
 32  STAssertEquals([action subActionsProcessed], 0, nil);
 33
 34  action = [[[KSCheckAction alloc] initWithTickets:nil] autorelease];
 35  STAssertNotNil(action, nil);
 36  STAssertEquals([action subActionsProcessed], 0, nil);
 37
 38  action = [KSCheckAction actionWithTickets:nil];
 39  STAssertNotNil(action, nil);
 40  STAssertEquals([action subActionsProcessed], 0, nil);
 41
 42  action = [KSCheckAction actionWithTickets:[NSArray array]];
 43  STAssertNotNil(action, nil);
 44  STAssertEquals([action subActionsProcessed], 0, nil);
 45
 46  NSDictionary *params = [NSDictionary dictionary];
 47  action = [KSCheckAction actionWithTickets:[NSArray array]
 48                                     params:params];
 49  STAssertNotNil(action, nil);
 50  STAssertEquals([action valueForKey:@"params_"], params, nil);
 51
 52  KSUpdateEngine *engine = [KSUpdateEngine engineWithDelegate:self];
 53  action =
 54    [KSCheckAction actionWithTickets:[NSArray array]
 55                              params:params
 56                              engine:engine];
 57  STAssertNotNil(action, nil);
 58  STAssertEquals([action valueForKey:@"params_"], params, nil);
 59  STAssertEquals([action valueForKey:@"engine_"], engine, nil);
 60}
 61
 62- (void)testSingleURL {
 63  KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
 64
 65  KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
 66                                       version:@"1"
 67                              existenceChecker:xc
 68                                     serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
 69
 70  NSArray *tickets = [NSArray arrayWithObject:t1];
 71
 72  KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
 73  STAssertNotNil(action, nil);
 74  STAssertEquals([action subActionsProcessed], 0, nil);
 75
 76  KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
 77  [ap enqueueAction:action];
 78  [ap startProcessing];
 79  [ap stopProcessing];
 80
 81  STAssertFalse([action isRunning], nil);
 82  STAssertEquals([action subActionsProcessed], 1, nil);
 83}
 84
 85- (void)testSameURL {
 86  KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
 87
 88  KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
 89                                       version:@"1"
 90                              existenceChecker:xc
 91                                     serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
 92
 93  KSTicket *t2 = [KSTicket ticketWithProductID:@"bar"
 94                                       version:@"1"
 95                              existenceChecker:xc
 96                                     serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
 97
 98  NSArray *tickets = [NSArray arrayWithObjects:t1, t2, nil];
 99
100  KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
101  STAssertNotNil(action, nil);
102  STAssertEquals([action subActionsProcessed], 0, nil);
103
104  KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
105  [ap enqueueAction:action];
106  [ap startProcessing];
107  [ap stopProcessing];
108
109  STAssertFalse([action isRunning], nil);
110  STAssertEquals([action subActionsProcessed], 1, nil);
111}
112
113- (void)testDifferentURL {
114  KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
115
116  KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
117                                       version:@"1"
118                              existenceChecker:xc
119                                     serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
120
121  KSTicket *t2 = [KSTicket ticketWithProductID:@"bar"
122                                       version:@"1"
123                              existenceChecker:xc
124                                     serverURL:[NSURL URLWithString:@"https://b.www.google.com"]];
125
126  NSArray *tickets = [NSArray arrayWithObjects:t1, t2, nil];
127
128  KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
129  STAssertNotNil(action, nil);
130  STAssertEquals([action subActionsProcessed], 0, nil);
131
132  KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
133  [ap enqueueAction:action];
134  [ap startProcessing];
135  [ap stopProcessing];
136
137  STAssertFalse([action isRunning], nil);
138  STAssertEquals([action subActionsProcessed], 2, nil);
139}
140
141- (void)testBadXC {
142  KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:
143                            @"/DoesNotExist-123431f123asdvaweliznvliz"];
144
145  KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
146                                       version:@"1"
147                              existenceChecker:xc
148                                     serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
149
150  NSArray *tickets = [NSArray arrayWithObject:t1];
151
152  KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
153  STAssertNotNil(action, nil);
154  STAssertEquals([action subActionsProcessed], 0, nil);
155
156  KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
157  [ap enqueueAction:action];
158  [ap startProcessing];
159  [ap stopProcessing];
160
161  STAssertFalse([action isRunning], nil);
162
163  // Should not have any subactions because the xc failed
164  STAssertEquals([action subActionsProcessed], 0, nil);
165}
166
167@end