|
@@ -169,92 +169,94 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
if hasOriginFile() {
|
|
if hasOriginFile() {
|
|
//目录中有需要执行对照的文件
|
|
//目录中有需要执行对照的文件
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- self._status = .Process
|
|
|
|
- self.reportString = NSMutableAttributedString.init(string: "\n【\(String(self.fileType())) - \(self.name())】快照比对开始!\n",
|
|
|
|
- attributes:[.foregroundColor : NSColor.blue])
|
|
|
|
- let files = DataModel.shared.originFilesFor(self.fileType(), type: self.type()) as [String]
|
|
|
|
- self.testFiles = NSArray(array: files);
|
|
|
|
-
|
|
|
|
- let checkDirectory = self.checkFileDirectory()
|
|
|
|
- let originDirectory = self.originFileDirectory()
|
|
|
|
- let resultDirectory = self.resultFileDirectory()
|
|
|
|
-
|
|
|
|
- if (files.count > 0) {
|
|
|
|
- try? FileManager.default.createDirectory(atPath: checkDirectory, withIntermediateDirectories: true);
|
|
|
|
- try? FileManager.default.createDirectory(atPath: resultDirectory, withIntermediateDirectories: true);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var tDegree = Double(0);
|
|
|
|
- var tCount = Int(0)
|
|
|
|
- var fileIndex = 0
|
|
|
|
- var compareIndex = 0;
|
|
|
|
- var convertFinished = false;
|
|
|
|
-
|
|
|
|
- // 用 Block 递归调用形式,确保转档单任务执行
|
|
|
|
- var convertFileBlock = { (files:[String]) in }
|
|
|
|
- convertFileBlock = { (files:[String]) in
|
|
|
|
- if (fileIndex >= files.count) {
|
|
|
|
- convertFinished = true;
|
|
|
|
- return
|
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ self._status = .Process
|
|
|
|
+ self.reportString = NSMutableAttributedString.init(string: "\n【\(String(self.fileType())) - \(self.name())】快照比对开始!\n",
|
|
|
|
+ attributes:[.foregroundColor : NSColor.blue])
|
|
|
|
+ let files = DataModel.shared.originFilesFor(self.fileType(), type: self.type()) as [String]
|
|
|
|
+ self.testFiles = NSArray(array: files);
|
|
|
|
+
|
|
|
|
+ let checkDirectory = self.checkFileDirectory()
|
|
|
|
+ let originDirectory = self.originFileDirectory()
|
|
|
|
+ let resultDirectory = self.resultFileDirectory()
|
|
|
|
+
|
|
|
|
+ if (files.count > 0) {
|
|
|
|
+ try? FileManager.default.createDirectory(atPath: checkDirectory, withIntermediateDirectories: true);
|
|
|
|
+ try? FileManager.default.createDirectory(atPath: resultDirectory, withIntermediateDirectories: true);
|
|
}
|
|
}
|
|
|
|
|
|
- //
|
|
|
|
- let fileName = files[fileIndex];
|
|
|
|
- autoreleasepool {
|
|
|
|
- let checkDirectory = self.checkFileDirectory()
|
|
|
|
- let originDirectory = self.originFileDirectory()
|
|
|
|
- let resultDirectory = self.resultFileDirectory()
|
|
|
|
-
|
|
|
|
- let fName = NSString(string: fileName).deletingPathExtension
|
|
|
|
- let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
|
|
|
|
- let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+self.extention())
|
|
|
|
- // let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
|
|
|
|
-// attributes:[.foregroundColor : NSColor.blue]))
|
|
|
|
- // ...
|
|
|
|
- // 执行异步转换过程
|
|
|
|
- let index = self.testFiles.index(of: fileName);
|
|
|
|
- if (index != NSNotFound) {
|
|
|
|
- self.convertProgress = Double(index) / Double(self.testFiles.count)
|
|
|
|
|
|
+ var tDegree = Double(0);
|
|
|
|
+ var tCount = Int(0)
|
|
|
|
+ var fileIndex = 0
|
|
|
|
+ var compareIndex = 0;
|
|
|
|
+ var convertFinished = false;
|
|
|
|
+
|
|
|
|
+ // 用 Block 递归调用形式,确保转档单任务执行
|
|
|
|
+ var convertFileBlock = { (files:[String]) in }
|
|
|
|
+ convertFileBlock = { (files:[String]) in
|
|
|
|
+ if (fileIndex >= files.count) {
|
|
|
|
+ convertFinished = true;
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- self.convertFiles.add(fileName);
|
|
|
|
- self.testlog("开始转换:"+fileName, (self.compareProgress + self.convertProgress)/2.0)
|
|
|
|
- self.process(originPath, resultPath: resultPath) { status in
|
|
|
|
- DispatchQueue.global().async {
|
|
|
|
- Thread.sleep(forTimeInterval: 0.3)
|
|
|
|
- fileIndex += 1;
|
|
|
|
- convertFileBlock(files)
|
|
|
|
-
|
|
|
|
- self.compareResult(fileName, resultPath: resultPath, status: status, needCompare: needCompare) { degree in
|
|
|
|
- autoreleasepool {
|
|
|
|
- if (degree >= 0.0) {
|
|
|
|
- tDegree += degree;
|
|
|
|
- tCount += 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- compareIndex += 1;
|
|
|
|
- if (convertFinished && compareIndex >= files.count) {
|
|
|
|
- //所有任务已经执行完成
|
|
|
|
- TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
|
|
|
|
- fileType: self.fileType(),
|
|
|
|
- type: self.type())
|
|
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ let fileName = files[fileIndex];
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ let checkDirectory = self.checkFileDirectory()
|
|
|
|
+ let originDirectory = self.originFileDirectory()
|
|
|
|
+ let resultDirectory = self.resultFileDirectory()
|
|
|
|
+
|
|
|
|
+ let fName = NSString(string: fileName).deletingPathExtension
|
|
|
|
+ let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
|
|
|
|
+ let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+self.extention())
|
|
|
|
+ // let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
|
|
|
|
+ // attributes:[.foregroundColor : NSColor.blue]))
|
|
|
|
+ // ...
|
|
|
|
+ // 执行异步转换过程
|
|
|
|
+ let index = self.testFiles.index(of: fileName);
|
|
|
|
+ if (index != NSNotFound) {
|
|
|
|
+ self.convertProgress = Double(index) / Double(self.testFiles.count)
|
|
|
|
+ }
|
|
|
|
+ self.convertFiles.add(fileName);
|
|
|
|
+ self.testlog("开始转换:"+fileName, (self.compareProgress + self.convertProgress)/2.0)
|
|
|
|
+ self.process(originPath, resultPath: resultPath) { status in
|
|
|
|
+ DispatchQueue.global().async {
|
|
|
|
+ Thread.sleep(forTimeInterval: 0.3)
|
|
|
|
+ fileIndex += 1;
|
|
|
|
+ convertFileBlock(files)
|
|
|
|
+
|
|
|
|
+ self.compareResult(fileName, resultPath: resultPath, status: status, needCompare: needCompare) { degree in
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ if (degree >= 0.0) {
|
|
|
|
+ tDegree += degree;
|
|
|
|
+ tCount += 1;
|
|
|
|
+ }
|
|
|
|
|
|
- self._status = .Finished
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- complention(self, self.reportString);
|
|
|
|
|
|
+ compareIndex += 1;
|
|
|
|
+ if (convertFinished && compareIndex >= files.count) {
|
|
|
|
+ //所有任务已经执行完成
|
|
|
|
+ TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
|
|
|
|
+ fileType: self.fileType(),
|
|
|
|
+ type: self.type())
|
|
|
|
+
|
|
|
|
+ self._status = .Finished
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
+ complention(self, self.reportString);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+ };
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+ // 启动第0号任务
|
|
|
|
+ convertFileBlock(files);
|
|
}
|
|
}
|
|
- // 启动第0号任务
|
|
|
|
- convertFileBlock(files);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -262,7 +264,9 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
_status = .Normal
|
|
_status = .Normal
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
- complention(self, nil)
|
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ complention(self, nil)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -410,8 +414,10 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
compareCount += 1
|
|
compareCount += 1
|
|
if (compareCount >= subImages.count) {
|
|
if (compareCount >= subImages.count) {
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- itemIndex += 1
|
|
|
|
- processItemBlock(items)
|
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ itemIndex += 1
|
|
|
|
+ processItemBlock(items)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -421,8 +427,10 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
if (subImages.count == 0) {
|
|
if (subImages.count == 0) {
|
|
// complention
|
|
// complention
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- itemIndex += 1
|
|
|
|
- processItemBlock(items)
|
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ itemIndex += 1
|
|
|
|
+ processItemBlock(items)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -435,8 +443,10 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
fileName: fileName, refFilePath: subFileName+".jpg")
|
|
fileName: fileName, refFilePath: subFileName+".jpg")
|
|
|
|
|
|
if degree == -1 {
|
|
if degree == -1 {
|
|
|
|
+ objc_sync_enter(self)
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比失败,生成快照失败或无比对文件\n",
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比失败,生成快照失败或无比对文件\n",
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
+ objc_sync_exit(self)
|
|
}else {
|
|
}else {
|
|
var color = NSColor.black
|
|
var color = NSColor.black
|
|
if fabs(degree-100.0) >= 0.01 {
|
|
if fabs(degree-100.0) >= 0.01 {
|
|
@@ -445,25 +455,33 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
subDegree += degree
|
|
subDegree += degree
|
|
subCount += 1
|
|
subCount += 1
|
|
|
|
|
|
|
|
+ objc_sync_enter(self)
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比完成,图像相似度 \(degree)%\n",
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比完成,图像相似度 \(degree)%\n",
|
|
attributes:[.foregroundColor : color]))
|
|
attributes:[.foregroundColor : color]))
|
|
|
|
+ objc_sync_exit(self)
|
|
}
|
|
}
|
|
|
|
|
|
// complention
|
|
// complention
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- itemIndex += 1
|
|
|
|
- processItemBlock(items)
|
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ itemIndex += 1
|
|
|
|
+ processItemBlock(items)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
|
|
+ objc_sync_enter(self)
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照生成失败\n",
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照生成失败\n",
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
+ objc_sync_exit(self)
|
|
|
|
|
|
// complention
|
|
// complention
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
- itemIndex += 1
|
|
|
|
- processItemBlock(items)
|
|
|
|
|
|
+ autoreleasepool {
|
|
|
|
+ itemIndex += 1
|
|
|
|
+ processItemBlock(items)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -481,14 +499,20 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
if (status == 0) {
|
|
if (status == 0) {
|
|
|
|
+ objc_sync_enter(self)
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
+ objc_sync_exit(self)
|
|
}else if (status == -1 || status == -2) {
|
|
}else if (status == -1 || status == -2) {
|
|
|
|
+ objc_sync_enter(self)
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"文档无法打开!\n",
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"文档无法打开!\n",
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
+ objc_sync_exit(self)
|
|
}else if (status == -3) {
|
|
}else if (status == -3) {
|
|
|
|
+ objc_sync_enter(self)
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档中 Crash!\n",
|
|
self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档中 Crash!\n",
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
attributes:[.foregroundColor : NSColor.red]))
|
|
|
|
+ objc_sync_exit(self)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -497,11 +521,14 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
// 执行下一个文件转档
|
|
// 执行下一个文件转档
|
|
NSLog("结束识别:\(fileName)");
|
|
NSLog("结束识别:\(fileName)");
|
|
|
|
|
|
|
|
+ objc_sync_exit(self)
|
|
let index = self.testFiles.index(of: fileName);
|
|
let index = self.testFiles.index(of: fileName);
|
|
if (index != NSNotFound) {
|
|
if (index != NSNotFound) {
|
|
self.compareProgress = Double(index) / Double(self.testFiles.count)
|
|
self.compareProgress = Double(index) / Double(self.testFiles.count)
|
|
}
|
|
}
|
|
self.compareFinishedFiles.add(fileName);
|
|
self.compareFinishedFiles.add(fileName);
|
|
|
|
+ objc_sync_exit(self)
|
|
|
|
+
|
|
self.testlog("对比完成:"+fileName, (self.compareProgress + self.convertProgress)/2.0)
|
|
self.testlog("对比完成:"+fileName, (self.compareProgress + self.convertProgress)/2.0)
|
|
complention(0)
|
|
complention(0)
|
|
}
|
|
}
|
|
@@ -542,7 +569,7 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
// let originDirectory = self.originFileDirectory()
|
|
// let originDirectory = self.originFileDirectory()
|
|
let resultDirectory = self.resultFileDirectory()
|
|
let resultDirectory = self.resultFileDirectory()
|
|
|
|
|
|
- for fileName in files {
|
|
|
|
|
|
+ for fileName:String in files {
|
|
let fName = NSString(string: fileName).deletingPathExtension
|
|
let fName = NSString(string: fileName).deletingPathExtension
|
|
// let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
|
|
// let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
|
|
let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
|
|
let resultPath = NSString(string: resultDirectory).appendingPathComponent(fName+"."+_extention)
|
|
@@ -566,7 +593,7 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
items.add(fName)
|
|
items.add(fName)
|
|
}
|
|
}
|
|
|
|
|
|
- for item in items {
|
|
|
|
|
|
+ for item in NSArray(array: items) {
|
|
let subFileName = item as! String
|
|
let subFileName = item as! String
|
|
let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
@@ -625,7 +652,7 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
items.add(fName)
|
|
items.add(fName)
|
|
}
|
|
}
|
|
|
|
|
|
- for item in items {
|
|
|
|
|
|
+ for item in NSArray(array: items) {
|
|
let subFileName = item as! String
|
|
let subFileName = item as! String
|
|
let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
@@ -675,7 +702,7 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
items.add(fName)
|
|
items.add(fName)
|
|
}
|
|
}
|
|
|
|
|
|
- for item in items {
|
|
|
|
|
|
+ for item in NSArray(array: items) {
|
|
let subFileName = item as! String
|
|
let subFileName = item as! String
|
|
let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
|
|
@@ -724,8 +751,8 @@ class AutoTest : NSObject, AutoTestProtocal {
|
|
// compare screenshoot between result file with check file
|
|
// compare screenshoot between result file with check file
|
|
let items = NSMutableArray()
|
|
let items = NSMutableArray()
|
|
if (isDirectory.boolValue) {
|
|
if (isDirectory.boolValue) {
|
|
- let searchItems = try! FileManager.default.contentsOfDirectory(atPath: resultPath)
|
|
|
|
- for item in NSArray(array: searchItems) {
|
|
|
|
|
|
+ let searchItems = try? FileManager.default.contentsOfDirectory(atPath: resultPath)
|
|
|
|
+ for item in NSArray(array: searchItems ?? []) {
|
|
let ext = NSString(string: item as! String).pathExtension.lowercased()
|
|
let ext = NSString(string: item as! String).pathExtension.lowercased()
|
|
if (NSArray(array: [_extention]).contains(ext) &&
|
|
if (NSArray(array: [_extention]).contains(ext) &&
|
|
!NSString(string: item as! String).contains("_cover.png")) {
|
|
!NSString(string: item as! String).contains("_cover.png")) {
|