AutoTest.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // AutoTest.swift
  3. // KdanAuto
  4. //
  5. // Created by 朱东勇 on 2022/11/25.
  6. //
  7. import Foundation
  8. import AppKit
  9. let testCaseNames = [
  10. "PDFConvert_Font_Auto_Test",
  11. "PDFConvert_Color_Auto_Test",
  12. "PDFConvert_China_Auto_Test",
  13. "PDFConvert_SpecialCharacter_Auto_Test"
  14. ]
  15. class AutoTest : NSObject, AutoTestProtocal {
  16. var reportString : NSAttributedString? = nil
  17. class func autoTestForType(_ type:NSString) -> AutoTest? {
  18. if type.isEqual(to: "PDFConvert_Font_Auto_Test") {
  19. return FontAutoTest.shared()
  20. }else if type.isEqual(to: "PDFConvert_China_Auto_Test") {
  21. return ChineseStringAutoTest.shared()
  22. }else if type.isEqual(to: "PDFConvert_Color_Auto_Test") {
  23. return TextColorAutoTest.shared()
  24. }else if type.isEqual(to: "PDFConvert_SpecialCharacter_Auto_Test") {
  25. return SpecialCharacterAutoTest.shared()
  26. }
  27. return nil
  28. }
  29. static var sharedInstance = AutoTest()
  30. class func shared() -> AutoTest? {
  31. return sharedInstance
  32. }
  33. func type() -> String {
  34. return "Base_Auto_Test"
  35. }
  36. func name() -> String {
  37. return "基础测试基类"
  38. }
  39. func keys() -> NSArray {
  40. return []
  41. }
  42. func selectedKeys() -> NSArray {
  43. let userDefaults = UserDefaults.standard
  44. let key = self.type() + ".selectedKeys"
  45. if userDefaults.value(forKey: key) != nil {
  46. return userDefaults.value(forKey: key) as! NSArray
  47. }
  48. self.setSelectedKeys(self.keys())
  49. return self.keys()
  50. }
  51. func setSelectedKeys(_ keys: NSArray) {
  52. let userDefaults = UserDefaults.standard
  53. let key = self.type() + ".selectedKeys"
  54. userDefaults.setValue(keys, forKey: key)
  55. userDefaults.synchronize()
  56. }
  57. // Auto Test
  58. func autoTest() {
  59. }
  60. func autoCheck() {
  61. }
  62. func testReport() -> NSAttributedString? {
  63. return reportString
  64. }
  65. /// Path
  66. func originFilePath() -> String {
  67. return DataModel.shared.originPath().appendingFormat("/\(self.type()).pdf")
  68. }
  69. func resultFilePath() -> String {
  70. return DataModel.shared.resultPath().appendingFormat("/\(self.type()).rtf")
  71. }
  72. func checkFilePath() -> String {
  73. return DataModel.shared.checkPath().appendingFormat("/\(self.type()).rtf")
  74. }
  75. // check File Exist
  76. func isOriginFileExist() -> Bool {
  77. if nil != self.originFilePath() {
  78. return FileManager.default.fileExists(atPath: self.originFilePath())
  79. }
  80. return false
  81. }
  82. func isResultFileExist() -> Bool {
  83. if nil != self.resultFilePath() {
  84. return FileManager.default.fileExists(atPath: self.resultFilePath())
  85. }
  86. return false
  87. }
  88. func isCheckFileExist() -> Bool {
  89. if nil != self.checkFilePath() {
  90. return FileManager.default.fileExists(atPath: self.checkFilePath())
  91. }
  92. return false
  93. }
  94. }