MatTestObjc.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // MatTests.m
  3. //
  4. // Created by Giles Payne on 2020/01/25.
  5. //
  6. #import <XCTest/XCTest.h>
  7. #import <OpenCV/OpenCV.h>
  8. #define CV_8U 0
  9. #define CV_16S 3
  10. #define CV_32S 4
  11. #define CV_32F 5
  12. #define CV_CN_SHIFT 3
  13. #define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
  14. #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
  15. #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
  16. #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
  17. #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
  18. #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
  19. #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
  20. #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
  21. @interface MatTestsObjc : XCTestCase
  22. @end
  23. @implementation MatTestsObjc
  24. // XCTAssertThrows only works in Objective-C so these tests are separate from the main MatTest.swift
  25. - (void)testBadData {
  26. Mat* m1 = [[Mat alloc] initWithRows:5 cols:5 type:CV_8UC3];
  27. Mat* m2 = [[Mat alloc] initWithSizes:@[@5, @5, @5] type:CV_8UC3];
  28. Mat* m3 = [[Mat alloc] initWithRows:5 cols:5 type:CV_32FC3];
  29. Mat* m4 = [[Mat alloc] initWithSizes:@[@5, @5, @5] type:CV_32FC3];
  30. Mat* m5 = [[Mat alloc] initWithRows:5 cols:5 type:CV_32SC3];
  31. Mat* m6 = [[Mat alloc] initWithSizes:@[@5, @5, @5] type:CV_32SC3];
  32. Mat* m7 = [[Mat alloc] initWithRows:5 cols:5 type:CV_16SC3];
  33. Mat* m8 = [[Mat alloc] initWithSizes:@[@5, @5, @5] type:CV_16SC3];
  34. NSMutableArray<NSNumber*>* badData7 = [NSMutableArray arrayWithArray: @[@0, @0, @0, @0, @0, @0, @0]];
  35. NSMutableArray<NSNumber*>* badData5 = [NSMutableArray arrayWithArray: @[@0, @0, @0, @0, @0]];
  36. XCTAssertThrows([m1 get: 2 col: 2 data: badData7]);
  37. XCTAssertThrows([m1 put: 2 col: 2 data: badData5]);
  38. XCTAssertThrows([m2 put:(@[@2, @2, @0]) data: badData5]);
  39. XCTAssertThrows([m3 put: 2 col: 2 data: badData5]);
  40. XCTAssertThrows([m4 put:(@[@4, @2, @2]) data: badData5]);
  41. XCTAssertThrows([m5 put: 2 col: 2 data: badData5]);
  42. XCTAssertThrows([m6 put:(@[@2, @2, @0]) data: badData5]);
  43. XCTAssertThrows([m7 put: 2 col: 2 data: badData5]);
  44. XCTAssertThrows([m8 put:(@[@2, @2, @0]) data: badData5]);
  45. }
  46. - (void)testRelease {
  47. Mat* m = [[Mat alloc] initWithRows:5 cols:5 type:CV_8UC3];
  48. XCTAssertNoThrow(m = nil);
  49. }
  50. @end