/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. #import <SenTestingKit/SenTestingKit.h>
  15. #import "KSCheckAction.h"
  16. #import "KSActionProcessor.h"
  17. #import "KSExistenceChecker.h"
  18. #import "KSTicket.h"
  19. #import "KSUpdateEngine.h"
  20. @interface KSCheckActionTest : SenTestCase
  21. @end
  22. @implementation KSCheckActionTest
  23. - (void)testCreation {
  24. KSCheckAction *action = [[[KSCheckAction alloc] init] autorelease];
  25. STAssertNotNil(action, nil);
  26. STAssertEquals([action subActionsProcessed], 0, nil);
  27. action = [[[KSCheckAction alloc] initWithTickets:nil] autorelease];
  28. STAssertNotNil(action, nil);
  29. STAssertEquals([action subActionsProcessed], 0, nil);
  30. action = [KSCheckAction actionWithTickets:nil];
  31. STAssertNotNil(action, nil);
  32. STAssertEquals([action subActionsProcessed], 0, nil);
  33. action = [KSCheckAction actionWithTickets:[NSArray array]];
  34. STAssertNotNil(action, nil);
  35. STAssertEquals([action subActionsProcessed], 0, nil);
  36. NSDictionary *params = [NSDictionary dictionary];
  37. action = [KSCheckAction actionWithTickets:[NSArray array]
  38. params:params];
  39. STAssertNotNil(action, nil);
  40. STAssertEquals([action valueForKey:@"params_"], params, nil);
  41. KSUpdateEngine *engine = [KSUpdateEngine engineWithDelegate:self];
  42. action =
  43. [KSCheckAction actionWithTickets:[NSArray array]
  44. params:params
  45. engine:engine];
  46. STAssertNotNil(action, nil);
  47. STAssertEquals([action valueForKey:@"params_"], params, nil);
  48. STAssertEquals([action valueForKey:@"engine_"], engine, nil);
  49. }
  50. - (void)testSingleURL {
  51. KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
  52. KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
  53. version:@"1"
  54. existenceChecker:xc
  55. serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
  56. NSArray *tickets = [NSArray arrayWithObject:t1];
  57. KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
  58. STAssertNotNil(action, nil);
  59. STAssertEquals([action subActionsProcessed], 0, nil);
  60. KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
  61. [ap enqueueAction:action];
  62. [ap startProcessing];
  63. [ap stopProcessing];
  64. STAssertFalse([action isRunning], nil);
  65. STAssertEquals([action subActionsProcessed], 1, nil);
  66. }
  67. - (void)testSameURL {
  68. KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
  69. KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
  70. version:@"1"
  71. existenceChecker:xc
  72. serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
  73. KSTicket *t2 = [KSTicket ticketWithProductID:@"bar"
  74. version:@"1"
  75. existenceChecker:xc
  76. serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
  77. NSArray *tickets = [NSArray arrayWithObjects:t1, t2, nil];
  78. KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
  79. STAssertNotNil(action, nil);
  80. STAssertEquals([action subActionsProcessed], 0, nil);
  81. KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
  82. [ap enqueueAction:action];
  83. [ap startProcessing];
  84. [ap stopProcessing];
  85. STAssertFalse([action isRunning], nil);
  86. STAssertEquals([action subActionsProcessed], 1, nil);
  87. }
  88. - (void)testDifferentURL {
  89. KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:@"/"];
  90. KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
  91. version:@"1"
  92. existenceChecker:xc
  93. serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
  94. KSTicket *t2 = [KSTicket ticketWithProductID:@"bar"
  95. version:@"1"
  96. existenceChecker:xc
  97. serverURL:[NSURL URLWithString:@"https://b.www.google.com"]];
  98. NSArray *tickets = [NSArray arrayWithObjects:t1, t2, nil];
  99. KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
  100. STAssertNotNil(action, nil);
  101. STAssertEquals([action subActionsProcessed], 0, nil);
  102. KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
  103. [ap enqueueAction:action];
  104. [ap startProcessing];
  105. [ap stopProcessing];
  106. STAssertFalse([action isRunning], nil);
  107. STAssertEquals([action subActionsProcessed], 2, nil);
  108. }
  109. - (void)testBadXC {
  110. KSExistenceChecker *xc = [KSPathExistenceChecker checkerWithPath:
  111. @"/DoesNotExist-123431f123asdvaweliznvliz"];
  112. KSTicket *t1 = [KSTicket ticketWithProductID:@"foo"
  113. version:@"1"
  114. existenceChecker:xc
  115. serverURL:[NSURL URLWithString:@"https://a.www.google.com"]];
  116. NSArray *tickets = [NSArray arrayWithObject:t1];
  117. KSCheckAction *action = [KSCheckAction actionWithTickets:tickets];
  118. STAssertNotNil(action, nil);
  119. STAssertEquals([action subActionsProcessed], 0, nil);
  120. KSActionProcessor *ap = [[[KSActionProcessor alloc] init] autorelease];
  121. [ap enqueueAction:action];
  122. [ap startProcessing];
  123. [ap stopProcessing];
  124. STAssertFalse([action isRunning], nil);
  125. // Should not have any subactions because the xc failed
  126. STAssertEquals([action subActionsProcessed], 0, nil);
  127. }
  128. @end