PageRenderTime 35ms CodeModel.GetById 2ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Tests/GDataNormalPlayTimeTest.m

http://macfuse.googlecode.com/
Objective C | 79 lines | 41 code | 15 blank | 23 comment | 3 complexity | 582d550d8baa25708f953a6d179d8f61 MD5 | raw file
 1/* Copyright (c) 2007 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
16//
17//  GDataNormalPlayTimeTest.m
18//
19
20#define typeof __typeof__ // fixes http://www.brethorsting.com/blog/2006/02/stupid-issue-with-ocunit.html
21
22#import <SenTestingKit/SenTestingKit.h>
23
24#import "GDataNormalPlayTime.h"
25
26@interface GDataNormalPlayTimeTest : SenTestCase
27@end
28
29@implementation GDataNormalPlayTimeTest
30
31- (void)testGDataNormalPlayTime {
32  struct NPTTestRecord {
33    NSString *str;
34    long long ms;
35    BOOL isNow;
36    NSString *secondsStr;
37    NSString *hhmmssStr;
38  };
39  
40  struct NPTTestRecord tests[] = {
41    { @"123", 123000, NO, @"123", @"0:02:03" },
42    { @"123.45", 123450, NO, @"123.450", @"0:02:03.450" },
43    { @"123.4567", 123456, NO, @"123.456", @"0:02:03.456" },
44    { @"0:02:03.456", 123456, NO, @"123.456", @"0:02:03.456" },
45    { @"now", -1, YES, @"now", @"now" },
46    { @"flubber", 0, NO, @"0", @"0:00:00" },
47    { nil, 0, 0, 0, 0 }
48  };
49  
50  int idx;
51  for (idx = 0; tests[idx].str != nil; idx++) {
52    
53    // make an NPT object from the string
54    GDataNormalPlayTime *npt = [GDataNormalPlayTime normalPlayTimeWithString:tests[idx].str];
55    
56    // ensure the ms are as expected
57    long long ms = [npt timeOffsetInMilliseconds];
58    STAssertEquals(ms, tests[idx].ms, @"unexpected ms for NPT %@", tests[idx].str);
59    
60    // ensure seconds string is as expected
61    NSString *secondsStr = [npt secondsString];  // seconds.fraction or "now"
62    STAssertEqualObjects(secondsStr, tests[idx].secondsStr, @"unexpected seconds string for NPT %@", tests[idx].str);
63    
64    // ensure the HMS strings is as expected
65    NSString *hhmmssStr = [npt HHMMSSString];  // hh:mm:ss.fraction or "now"
66    STAssertEqualObjects(hhmmssStr, tests[idx].hhmmssStr, @"unexpected HHMMSS string for NPT %@",  tests[idx].str);
67    
68    // ensure "is now" flag is correct
69    BOOL isNow = [npt isNow];
70    STAssertTrue(isNow == tests[idx].isNow, @"isNow unexpected for NPT %@", tests[idx].isNow);
71  }
72  
73  // garbage in, zero out
74  GDataNormalPlayTime *npt = [GDataNormalPlayTime normalPlayTimeWithString:@"hooyah"];
75  STAssertEquals([npt timeOffsetInMilliseconds], 0ll,
76                 @"NPT should return 0 for garbage string 'hooyah', got %@ (%qd ms)",
77                 npt, [npt timeOffsetInMilliseconds]);
78}
79@end