Browse Source

Demo - 列表中显示测试结果相似度

zhudongyong 2 years ago
parent
commit
9652f7dcb1

BIN
KdanAutoTest/KdanAuto.xcodeproj/project.xcworkspace/xcuserdata/zhudongyong.xcuserdatad/UserInterfaceState.xcuserstate


+ 2 - 2
KdanAutoTest/KdanAuto.xcodeproj/xcuserdata/zhudongyong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -14,8 +14,8 @@
             filePath = "KdanAuto/Class/AutoTestCase/AutoTest.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "615"
-            endingLineNumber = "615"
+            startingLineNumber = "611"
+            endingLineNumber = "611"
             landmarkName = "stringToImage(_:)"
             landmarkType = "7">
          </BreakpointContent>

+ 12 - 16
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

@@ -20,7 +20,7 @@ class AutoTest : NSObject, AutoTestProtocal {
     var _extention : String = "rtf"
     
     var _degree : Double = 0.0
-    var _fileDegree : [Double] = []
+    var _fileDegreeInfo : [String:Double] = [:]
     
     class func autoTestFor(_ fileType:NSString ,type:NSString) -> AutoTest? {
         let key = String(fileType) + "." + String(type)
@@ -140,8 +140,8 @@ class AutoTest : NSObject, AutoTestProtocal {
             let originDirectory = self.originFileDirectory()
             let resultDirectory = self.resultFileDirectory()
             
-            var degree = Double(0);
-            var count = Int(0)
+            var tDegree = Double(0);
+            var tCount = Int(0)
             
             for fileName in files {
                 let fName = NSString(string: fileName).deletingPathExtension
@@ -238,9 +238,9 @@ class AutoTest : NSObject, AutoTestProtocal {
                             subDegree = 0.0
                         }
                         
-                        _fileDegree.append(subDegree)
-                        degree += subDegree;
-                        count += 1
+                        _fileDegreeInfo[fileName] = subDegree
+                        tDegree += subDegree;
+                        tCount += 1
                     }
                 }else {
                     reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"转档失败!\n",
@@ -248,8 +248,8 @@ class AutoTest : NSObject, AutoTestProtocal {
                 }
             }
             
-            if count != 0 {
-                _degree = degree/Double(count)
+            if tCount != 0 {
+                _degree = tDegree/Double(tCount)
             }else {
                 _degree = 0.0
             }
@@ -274,14 +274,10 @@ class AutoTest : NSObject, AutoTestProtocal {
 //    }
     
     func degreeOfFile(_ fileName:String) -> Double {
-        let files = DataModel.shared.originFilesFor(_fileType, type: _type) as [String]
-        
-        let index = files.firstIndex(of: fileName)
-        
-        if index == NSNotFound || index! >= _fileDegree.count {
-            return 0
+        if _fileDegreeInfo[fileName] != nil {
+            return _fileDegreeInfo[fileName]!
         }else {
-            return _fileDegree[index!]
+            return 0
         }
     }
     
@@ -592,7 +588,7 @@ class AutoTest : NSObject, AutoTestProtocal {
         
         
         _degree = 0.0;
-        _fileDegree.removeAll()
+        _fileDegreeInfo.removeAll()
     }
 }
 

+ 15 - 0
KdanAutoTest/KdanAuto/Class/AutoTestCase/StringAutoTest.swift

@@ -48,6 +48,10 @@ class CharacterAutoTest : AutoTest {
         let checkDirectory = self.checkFileDirectory()
         let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
+        
+        var tDegree = Double(0);
+        var tCount = Int(0)
+        
         for fileName in files {
             let fName = NSString(string: fileName).deletingPathExtension
             let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
@@ -247,6 +251,11 @@ class CharacterAutoTest : AutoTest {
                                 if fabs(degree-100.0) >= 0.01 {
                                     color = NSColor.red
                                 }
+                                
+                                self._fileDegreeInfo[fileName] = degree
+                                tDegree += degree
+                                tCount += 1
+                                
                                 self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"快照对比完成,图像相似度 \(degree)%\n",
                                                                                          attributes:[.foregroundColor : color]))
                             }
@@ -265,6 +274,12 @@ class CharacterAutoTest : AutoTest {
             
         }
         
+        if tCount != 0 {
+            _degree = tDegree / Double(tCount)
+        }else {
+            _degree = 0
+        }
+        
         NSLog("\(reportString)")
         
         

+ 15 - 0
KdanAutoTest/KdanAuto/Class/AutoTestCase/TextColorAutoTest.swift

@@ -68,6 +68,10 @@ class TextColorAutoTest : AutoTest {
         let checkDirectory = self.checkFileDirectory()
         let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
+        
+        var tDegree = Double(0);
+        var tCount = Int(0)
+        
         for fileName in files {
             let fName = NSString(string: fileName).deletingPathExtension
             let originPath = NSString(string: originDirectory).appendingPathComponent(fName+".pdf")
@@ -286,6 +290,11 @@ class TextColorAutoTest : AutoTest {
                                 if fabs(degree-100.0) >= 0.01 {
                                     color = NSColor.red
                                 }
+                                
+                                self._fileDegreeInfo[fileName] = degree
+                                tDegree += degree
+                                tCount += 1
+                                
                                 self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(fName)\"快照对比完成,图像相似度 \(degree)%\n",
                                                                                     attributes:[.foregroundColor : color]))
                             }
@@ -305,6 +314,12 @@ class TextColorAutoTest : AutoTest {
             }
         }
         
+        if tCount != 0 {
+            _degree = tDegree / Double(tCount)
+        }else {
+            _degree = 0
+        }
+        
         _status = .Finished
     }
     

+ 20 - 34
KdanAutoTest/KdanAuto/Class/Norrmal/ActivityView/ActivityView.swift

@@ -33,6 +33,7 @@ class ActivityView : NSView {
 //    var _activityView : NSView = NSView()
 //    var _angle : CGFloat = 0
 //    var _shapeLayer : CAShapeLayer = CAShapeLayer()
+    var _degree : Double = 0
     
     
     public override init(frame frameRect: NSRect) {
@@ -57,6 +58,8 @@ class ActivityView : NSView {
         super.awakeFromNib()
         
         loadSubviews()
+        
+        updateStatus()
     }
     
     
@@ -88,13 +91,12 @@ class ActivityView : NSView {
         _titleLbl.wantsLayer = true
         _titleLbl.frame = NSMakeRect(0, (height - kActivityTitleHeight) / 2.0, width, kActivityTitleHeight)
         _titleLbl.backgroundColor = NSColor.clear
+        _titleLbl.font = NSFont.systemFont(ofSize: 12.0)
         _titleLbl.layer?.backgroundColor = NSColor.clear.cgColor
         _titleLbl.autoresizingMask = .width.union(.minXMargin).union(.maxXMargin).union(.height)
         _titleLbl.alignment = .center
         _titleLbl.layer?.borderWidth = 1
         _titleLbl.layer?.cornerRadius = 4
-        _titleLbl.textColor = NSColor.gray
-        _titleLbl.layer?.borderColor = NSColor.lightGray.cgColor
         
         if nil == _activityView {
             _activityView = NSProgressIndicator.init(frame: self.bounds)
@@ -155,7 +157,7 @@ class ActivityView : NSView {
         case .Wait: do {
             _titleLbl.textColor = NSColor.gray
             _titleLbl.layer?.borderColor = NSColor.lightGray.cgColor
-            _titleLbl.stringValue = "Waiting"
+            _titleLbl.stringValue = "等待中..."
             _timer.invalidate()
             _timer = Timer()
         }
@@ -166,9 +168,16 @@ class ActivityView : NSView {
 //                                          userInfo: nil, repeats: true)
         }
         case .Finished: do {
-            _titleLbl.textColor = NSColor.blue
-            _titleLbl.layer?.borderColor = NSColor.blue.cgColor
-            _titleLbl.stringValue = "Done"
+            NSLog("_degree=\(_degree)")
+            _titleLbl.stringValue = NSString(format: "完成 %.0f%%", _degree) as String
+            
+            if fabs(_degree-100)>=0.1 {
+                _titleLbl.textColor = NSColor.red
+                _titleLbl.layer?.borderColor = NSColor.red.cgColor
+            }else {
+                _titleLbl.textColor = NSColor.blue
+                _titleLbl.layer?.borderColor = NSColor.blue.cgColor
+            }
             _timer.invalidate()
             _timer = Timer()
         }
@@ -183,34 +192,6 @@ class ActivityView : NSView {
         
     }
     
-//    @objc func updateAnge() {
-//        _angle = self._angle + Double.pi/30.0
-//
-//
-//        let width = self.frame.width
-//        let height = self.frame.height
-//
-//        let activitySize = min(width, height)
-//        var mulPath = CGMutablePath()
-//        let inRadius = activitySize/2 - 3
-//        let outRadius = activitySize/2
-//        let endRage = self._angle - Double.pi / 3.0
-//        mulPath.move(to: CGPointMake(activitySize/2.0 + inRadius*sin(self._angle),
-//                                     activitySize/2.0 + inRadius * cos(self._angle)))
-//        mulPath.addLine(to: CGPointMake(activitySize/2.0 + outRadius*sin(self._angle),
-//                                        activitySize/2.0 + outRadius * cos(self._angle)))
-//        mulPath.addArc(center: CGPoint(x: activitySize/2.0, y: activitySize/2.0),
-//                       radius: outRadius,
-//                       startAngle: self._angle, endAngle: endRage, clockwise: true)
-//        mulPath.addLine(to: CGPointMake(activitySize/2 + inRadius*sin(endRage),
-//                                        activitySize/2 + inRadius * cos(endRage)))
-//        mulPath.addArc(center: CGPoint(x: activitySize/2.0, y: activitySize/2.0),
-//                       radius: inRadius,
-//                       startAngle: endRage, endAngle: self._angle, clockwise: false)
-//        self._shapeLayer.path = mulPath
-//    }
-    
-    
     /// Setter & Getter
     ///
     func setActivityStatus(_ status:ActivityStatus) {
@@ -225,5 +206,10 @@ class ActivityView : NSView {
         return _status
     }
     
+    func setDegree(_ degree:Double) {
+        _degree = degree;
+        
+        updateStatus()
+    }
     
 }

+ 7 - 0
KdanAutoTest/KdanAuto/Class/Norrmal/AutoTestAdvanceSettingView.swift

@@ -235,6 +235,13 @@ class AutoTestAdvanceSettingView : NSView, NSTableViewDataSource, NSTableViewDel
             }else {
                 cellView?.setNeedReplaceBtn(false)
             }
+            
+            if _autoTestObj != nil && _autoTestObj?.status() == .Finished {
+                cellView?.setNeedDegreeBtn(true)
+                cellView?.setDegree((_autoTestObj?.degreeOfFile(title))!)
+            }else {
+                cellView?.setNeedDegreeBtn(false)
+            }
         }
         
         return cellView

+ 1 - 1
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestCaseCellView.swift

@@ -129,7 +129,6 @@ class TestCaseCellView : NSTableCellView {
         if nil != _autoTestObj {
             self.setTitle((_autoTestObj?.name())!)
             self.setCheckKeys((_autoTestObj?.selectedKeys())!)
-            
 
 //            self.wantsLayer = true
 //            if _autoTestObj?.isOriginFileExist() == true && _autoTestObj?.isCheckFileExist() == true {
@@ -149,6 +148,7 @@ class TestCaseCellView : NSTableCellView {
     }
     
     public func updateStatus() {
+        _activityView.setDegree(_autoTestObj?.degree() ?? 0)
         _activityView.setActivityStatus(ActivityStatus(rawValue: (_autoTestObj?.status())!.rawValue) ?? .Normal)
     }
     

+ 1 - 1
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestCaseCellView.xib

@@ -14,7 +14,7 @@
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
                 <customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xZE-kG-hKQ" customClass="ActivityView" customModule="KdanAuto" customModuleProvider="target">
-                    <rect key="frame" x="279" y="33" width="55" height="25"/>
+                    <rect key="frame" x="260" y="33" width="74" height="25"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
                 </customView>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EgA-BQ-X23">

+ 18 - 0
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestFileCellView.swift

@@ -25,6 +25,8 @@ class TestFileCellView : NSTableCellView {
     var _isExpad: Bool!
     var _typeInfo : NSDictionary!
     
+    var _degree : Double = 0
+    
     weak public var _delegate : (TestFileCellViewDelegate)?
     
     class func shared() -> TestFileCellView? {
@@ -75,6 +77,22 @@ class TestFileCellView : NSTableCellView {
         return _typeInfo
     }
     
+    public func setNeedDegreeBtn(_ needDegree:Bool) {
+        _testReportBtn.isHidden = !needDegree
+    }
+    
+    public func setDegree(_ degree:Double) {
+        _degree = degree
+        
+        if fabs(_degree - 100) > 0.01 {
+            _testReportBtn.contentTintColor = NSColor.red
+        }else {
+            _testReportBtn.contentTintColor = NSColor.gray
+        }
+        
+        _testReportBtn.title = NSString(format: "%.0f%%", _degree) as String
+    }
+    
     // IBActionn
     @IBAction func replaceAction(_ sender:NSButton) {
         if _delegate != nil {

+ 4 - 4
KdanAutoTest/KdanAuto/Class/Norrmal/Cell/TestFileCellView.xib

@@ -23,11 +23,11 @@
                     </textFieldCell>
                 </textField>
                 <customView id="Dg0-nG-U3m">
-                    <rect key="frame" x="0.0" y="0.0" width="331" height="1"/>
+                    <rect key="frame" x="0.0" y="0.0" width="339" height="1"/>
                     <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
                 </customView>
                 <button verticalHuggingPriority="750" id="1iY-9V-oMo">
-                    <rect key="frame" x="229" y="-2" width="61" height="32"/>
+                    <rect key="frame" x="227" y="-2" width="61" height="32"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
                     <buttonCell key="cell" type="push" title="替换" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fG4-an-Nhx">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -38,9 +38,9 @@
                     </connections>
                 </button>
                 <button verticalHuggingPriority="750" id="k7x-WS-SBq">
-                    <rect key="frame" x="278" y="-1" width="61" height="32"/>
+                    <rect key="frame" x="285" y="-1" width="54" height="32"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
-                    <buttonCell key="cell" type="push" title="100%" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="3nC-F1-RVr">
+                    <buttonCell key="cell" type="bevel" title="100%" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="3nC-F1-RVr">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
                     </buttonCell>