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