SVGKit_iOS_Tests.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // SVGKit_iOS_Tests.m
  3. // SVGKit-iOS Tests
  4. //
  5. // Created by C.W. Betts on 10/13/14.
  6. // Copyright (c) 2014 na. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import <XCTest/XCTest.h>
  10. #import "SVGKit.h"
  11. #if !__has_feature(objc_arc)
  12. #error This test file must be compiled with ARC.
  13. #endif
  14. @interface SVGKit_iOS_ARCRetainTests : XCTestCase
  15. @property (strong) NSBundle *pathsToSVGs;
  16. @end
  17. @implementation SVGKit_iOS_ARCRetainTests
  18. - (void)setUp {
  19. [super setUp];
  20. self.pathsToSVGs = [NSBundle bundleForClass:[self class]];
  21. }
  22. - (void)tearDown {
  23. // Put teardown code here. This method is called after the invocation of each test method in the class.
  24. [super tearDown];
  25. }
  26. - (void)testReleasing {
  27. @try {
  28. @autoreleasepool {
  29. SVGKImage *image = [[SVGKImage alloc] initWithContentsOfFile:[self.pathsToSVGs pathForResource:@"Note" ofType:@"svg"]];
  30. // Yes, this is ARC, yes we do this to quiet a warning
  31. NSLog(@"description: %@", [image description]);
  32. [image class];
  33. XCTAssertNoThrow(image = nil);
  34. }
  35. XCTAssertTrue(YES);
  36. }
  37. @catch (NSException *exception) {
  38. XCTFail(@"Exception Thrown: %@", exception);
  39. }
  40. }
  41. - (void)testReplacing {
  42. @try {
  43. @autoreleasepool {
  44. SVGKImage *image = [[SVGKImage alloc] initWithContentsOfFile:[self.pathsToSVGs pathForResource:@"CurvedDiamond" ofType:@"svg"]];
  45. // Yes, this is ARC, yes we do this to quiet a warning
  46. NSLog(@"description: %@", [image description]);
  47. [image class];
  48. XCTAssertNoThrow(image = [SVGKImage imageWithContentsOfFile:[self.pathsToSVGs pathForResource:@"Lion" ofType:@"svg"]]);
  49. NSLog(@"description: %@", [image description]);
  50. [image class];
  51. }
  52. XCTAssertTrue(YES);
  53. }
  54. @catch (NSException *exception) {
  55. XCTFail(@"Exception Thrown: %@", exception);
  56. }
  57. }
  58. - (void)testSameFileTwice {
  59. @try {
  60. @autoreleasepool {
  61. SVGKImage *image = [SVGKImage imageWithContentsOfFile:[self.pathsToSVGs pathForResource:@"Monkey" ofType:@"svg"]];
  62. SVGKImage *image2 = [SVGKImage imageWithContentsOfFile:[self.pathsToSVGs pathForResource:@"Monkey" ofType:@"svg"]];
  63. // Yes, this is ARC, yes we do this to quiet a warning
  64. NSString *image1Desc = [image description];
  65. NSString *image2Desc = [image2 description];
  66. NSLog(@"image1: %@, image 2: %@", image1Desc, image2Desc);
  67. }
  68. XCTAssertTrue(YES);
  69. }
  70. @catch (NSException *exception) {
  71. XCTFail(@"Exception Thrown: %@", exception);
  72. }
  73. }
  74. - (void)testSettingImageMultipleTimes {
  75. @try {
  76. @autoreleasepool {
  77. SVGKFastImageView *imageView = [[SVGKFastImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
  78. imageView.image = nil;
  79. imageView.image = [[SVGKImage alloc] initWithContentsOfFile:[self.pathsToSVGs pathForResource:@"Note" ofType:@"svg"]];
  80. imageView.image = [[SVGKImage alloc] initWithContentsOfFile:[self.pathsToSVGs pathForResource:@"Note" ofType:@"svg"]];
  81. // Yes, this is ARC, yes we do this to quiet a warning
  82. XCTAssertNoThrow(imageView = nil);
  83. }
  84. XCTAssertTrue(YES);
  85. }
  86. @catch (NSException *exception) {
  87. XCTFail(@"Exception Thrown: %@", exception);
  88. }
  89. }
  90. @end