mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Add additional tests to testplan.
This commit is contained in:
@@ -8,60 +8,60 @@
|
||||
|
||||
import XCTest
|
||||
|
||||
class AppleScriptXCTestCase: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
/*
|
||||
@function doIndividualScript
|
||||
@param filename -- name of a .applescript (sans extension) in the test bundle's
|
||||
Resources/TestScripts directory
|
||||
@brief given a file, loads the script and runs it. Expects a result from running
|
||||
the script of the form
|
||||
{test_result:true, script_result:<anything>}
|
||||
if the test_result is false or is missing, the test fails
|
||||
@return the value of script_result, if any
|
||||
*/
|
||||
func doIndividualScript(filename:String) -> NSAppleEventDescriptor? {
|
||||
var errorDict: NSDictionary? = nil
|
||||
let testBundle = Bundle(for: type(of: self))
|
||||
let url = testBundle.url(forResource:filename, withExtension:"scpt")
|
||||
guard let testScriptUrl = url else {
|
||||
XCTFail("Failed Getting script URL")
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let testScript = NSAppleScript(contentsOf: testScriptUrl, error: &errorDict) else {
|
||||
print ("error is \(String(describing: errorDict))")
|
||||
XCTFail("Failed initializing NSAppleScript")
|
||||
return nil
|
||||
}
|
||||
|
||||
let scriptResult = testScript.executeAndReturnError(&errorDict)
|
||||
if (errorDict != nil) {
|
||||
print ("error is \(String(describing: errorDict))")
|
||||
XCTFail("Failed executing script")
|
||||
return nil
|
||||
}
|
||||
|
||||
let usrfDictionary = scriptResult.usrfDictionary()
|
||||
guard let testResult = usrfDictionary["test_result"] else {
|
||||
XCTFail("test script didn't return test result in usrf")
|
||||
return nil
|
||||
}
|
||||
|
||||
if (testResult.booleanValue != true) {
|
||||
print("test_result was \(testResult)")
|
||||
print("script_result was \(String(describing: usrfDictionary["script_result"]))")
|
||||
}
|
||||
|
||||
XCTAssert(testResult.booleanValue == true, "test_result should be true")
|
||||
return usrfDictionary["script_result"]
|
||||
}
|
||||
}
|
||||
//class AppleScriptXCTestCase: XCTestCase {
|
||||
//
|
||||
// override func setUp() {
|
||||
// super.setUp()
|
||||
// }
|
||||
//
|
||||
// override func tearDown() {
|
||||
// super.tearDown()
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// @function doIndividualScript
|
||||
// @param filename -- name of a .applescript (sans extension) in the test bundle's
|
||||
// Resources/TestScripts directory
|
||||
// @brief given a file, loads the script and runs it. Expects a result from running
|
||||
// the script of the form
|
||||
// {test_result:true, script_result:<anything>}
|
||||
// if the test_result is false or is missing, the test fails
|
||||
// @return the value of script_result, if any
|
||||
// */
|
||||
// func doIndividualScript(filename:String) -> NSAppleEventDescriptor? {
|
||||
// var errorDict: NSDictionary? = nil
|
||||
// let testBundle = Bundle(for: type(of: self))
|
||||
// let url = testBundle.url(forResource:filename, withExtension:"scpt")
|
||||
// guard let testScriptUrl = url else {
|
||||
// XCTFail("Failed Getting script URL")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// guard let testScript = NSAppleScript(contentsOf: testScriptUrl, error: &errorDict) else {
|
||||
// print ("error is \(String(describing: errorDict))")
|
||||
// XCTFail("Failed initializing NSAppleScript")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// let scriptResult = testScript.executeAndReturnError(&errorDict)
|
||||
// if (errorDict != nil) {
|
||||
// print ("error is \(String(describing: errorDict))")
|
||||
// XCTFail("Failed executing script")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// let usrfDictionary = scriptResult.usrfDictionary()
|
||||
// guard let testResult = usrfDictionary["test_result"] else {
|
||||
// XCTFail("test script didn't return test result in usrf")
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// if (testResult.booleanValue != true) {
|
||||
// print("test_result was \(testResult)")
|
||||
// print("script_result was \(String(describing: usrfDictionary["script_result"]))")
|
||||
// }
|
||||
//
|
||||
// XCTAssert(testResult.booleanValue == true, "test_result should be true")
|
||||
// return usrfDictionary["script_result"]
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -8,94 +8,94 @@
|
||||
|
||||
import XCTest
|
||||
|
||||
class ScriptingTests: AppleScriptXCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@function testGenericScript
|
||||
@brief An example of how a script can be run as part of an XCTest
|
||||
the applescript returns
|
||||
{test_result:true, script_result:"Geoducks!"}
|
||||
doIndividualScript() verifies the test_result portion
|
||||
this code verifies the script_result portion
|
||||
*/
|
||||
func testGenericScript() {
|
||||
let scriptResult = doIndividualScript(filename: "testGenericScript")
|
||||
XCTAssert( scriptResult?.stringValue == "Geoducks!")
|
||||
}
|
||||
|
||||
func testGetUrlScript() {
|
||||
_ = doIndividualScript(filename: "testGetURL")
|
||||
}
|
||||
|
||||
func testNameAndUrlOfEveryFeedScript() {
|
||||
_ = doIndividualScript(filename: "testNameAndUrlOfEveryFeed")
|
||||
}
|
||||
|
||||
func testNameOfEveryFolderScript() {
|
||||
_ = doIndividualScript(filename: "testNameOfEveryFolder")
|
||||
}
|
||||
|
||||
func testNameOfAuthorsScript() {
|
||||
_ = doIndividualScript(filename: "testNameOfAuthors")
|
||||
}
|
||||
|
||||
func testFeedExists() {
|
||||
_ = doIndividualScript(filename: "testFeedExists")
|
||||
}
|
||||
|
||||
func testFeedOPML() {
|
||||
_ = doIndividualScript(filename: "testFeedOPML")
|
||||
}
|
||||
|
||||
// func testTitleOfArticlesWhoseScript() {
|
||||
// _ = doIndividualScript(filename: "testTitleOfArticlesWhose")
|
||||
//class ScriptingTests: AppleScriptXCTestCase {
|
||||
//
|
||||
// override func setUp() {
|
||||
// super.setUp()
|
||||
// }
|
||||
//
|
||||
// override func tearDown() {
|
||||
// super.tearDown()
|
||||
// }
|
||||
//
|
||||
// func testIterativeCreateAndDeleteScript() {
|
||||
// _ = doIndividualScriptWithExpectation(filename: "testIterativeCreateAndDeleteFeed")
|
||||
//
|
||||
// /*
|
||||
// @function testGenericScript
|
||||
// @brief An example of how a script can be run as part of an XCTest
|
||||
// the applescript returns
|
||||
// {test_result:true, script_result:"Geoducks!"}
|
||||
// doIndividualScript() verifies the test_result portion
|
||||
// this code verifies the script_result portion
|
||||
// */
|
||||
// func testGenericScript() {
|
||||
// let scriptResult = doIndividualScript(filename: "testGenericScript")
|
||||
// XCTAssert( scriptResult?.stringValue == "Geoducks!")
|
||||
// }
|
||||
|
||||
func doIndividualScriptWithExpectation(filename:String) {
|
||||
let queue = DispatchQueue(label:"testQueue")
|
||||
let scriptExpectation = self.expectation(description: filename+"expectation")
|
||||
queue.async {
|
||||
_ = self.doIndividualScript(filename:filename)
|
||||
scriptExpectation.fulfill()
|
||||
}
|
||||
self.wait(for:[scriptExpectation], timeout:60)
|
||||
}
|
||||
|
||||
/*
|
||||
@function testCurrentArticleScripts
|
||||
@brief the pieces of the test are broken up into smaller pieces because of the
|
||||
way events are delivered to the app -- I tried one single script with all the
|
||||
actions and the keystrokes aren't delivered to the app right away, so the ui
|
||||
isn't updated in time for 'current article' to be set. But, breaking them up
|
||||
in this way seems to work.
|
||||
|
||||
July 30, 2019: There's an issue where in order for a script to send keystrokes,
|
||||
The app has to be allowed to interact with the SystemEvents.app in
|
||||
System Preferences -> Security & Privacy -> Privacy -> Accessibility
|
||||
and this permission needs to be renewed every time the app is recompiled unless
|
||||
the app is codesigned. Until we figure out how to get around this limitation,
|
||||
this test is disabled.
|
||||
*/
|
||||
func disabledTestCurrentArticleScripts() {
|
||||
|
||||
doIndividualScriptWithExpectation(filename: "uiScriptingTestSetup")
|
||||
doIndividualScriptWithExpectation(filename: "establishMainWindowStartingState")
|
||||
doIndividualScriptWithExpectation(filename: "selectAFeed")
|
||||
doIndividualScriptWithExpectation(filename: "testCurrentArticleIsNil")
|
||||
doIndividualScriptWithExpectation(filename: "selectAnArticle")
|
||||
doIndividualScriptWithExpectation(filename: "testURLsOfCurrentArticle")
|
||||
}
|
||||
}
|
||||
//
|
||||
// func testGetUrlScript() {
|
||||
// _ = doIndividualScript(filename: "testGetURL")
|
||||
// }
|
||||
//
|
||||
// func testNameAndUrlOfEveryFeedScript() {
|
||||
// _ = doIndividualScript(filename: "testNameAndUrlOfEveryFeed")
|
||||
// }
|
||||
//
|
||||
// func testNameOfEveryFolderScript() {
|
||||
// _ = doIndividualScript(filename: "testNameOfEveryFolder")
|
||||
// }
|
||||
//
|
||||
// func testNameOfAuthorsScript() {
|
||||
// _ = doIndividualScript(filename: "testNameOfAuthors")
|
||||
// }
|
||||
//
|
||||
// func testFeedExists() {
|
||||
// _ = doIndividualScript(filename: "testFeedExists")
|
||||
// }
|
||||
//
|
||||
// func testFeedOPML() {
|
||||
// _ = doIndividualScript(filename: "testFeedOPML")
|
||||
// }
|
||||
//
|
||||
//// func testTitleOfArticlesWhoseScript() {
|
||||
//// _ = doIndividualScript(filename: "testTitleOfArticlesWhose")
|
||||
//// }
|
||||
////
|
||||
//// func testIterativeCreateAndDeleteScript() {
|
||||
//// _ = doIndividualScriptWithExpectation(filename: "testIterativeCreateAndDeleteFeed")
|
||||
//// }
|
||||
//
|
||||
// func doIndividualScriptWithExpectation(filename:String) {
|
||||
// let queue = DispatchQueue(label:"testQueue")
|
||||
// let scriptExpectation = self.expectation(description: filename+"expectation")
|
||||
// queue.async {
|
||||
// _ = self.doIndividualScript(filename:filename)
|
||||
// scriptExpectation.fulfill()
|
||||
// }
|
||||
// self.wait(for:[scriptExpectation], timeout:60)
|
||||
// }
|
||||
//
|
||||
///*
|
||||
// @function testCurrentArticleScripts
|
||||
// @brief the pieces of the test are broken up into smaller pieces because of the
|
||||
// way events are delivered to the app -- I tried one single script with all the
|
||||
// actions and the keystrokes aren't delivered to the app right away, so the ui
|
||||
// isn't updated in time for 'current article' to be set. But, breaking them up
|
||||
// in this way seems to work.
|
||||
//
|
||||
// July 30, 2019: There's an issue where in order for a script to send keystrokes,
|
||||
// The app has to be allowed to interact with the SystemEvents.app in
|
||||
// System Preferences -> Security & Privacy -> Privacy -> Accessibility
|
||||
// and this permission needs to be renewed every time the app is recompiled unless
|
||||
// the app is codesigned. Until we figure out how to get around this limitation,
|
||||
// this test is disabled.
|
||||
//*/
|
||||
// func disabledTestCurrentArticleScripts() {
|
||||
//
|
||||
// doIndividualScriptWithExpectation(filename: "uiScriptingTestSetup")
|
||||
// doIndividualScriptWithExpectation(filename: "establishMainWindowStartingState")
|
||||
// doIndividualScriptWithExpectation(filename: "selectAFeed")
|
||||
// doIndividualScriptWithExpectation(filename: "testCurrentArticleIsNil")
|
||||
// doIndividualScriptWithExpectation(filename: "selectAnArticle")
|
||||
// doIndividualScriptWithExpectation(filename: "testURLsOfCurrentArticle")
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
-- this script just tests that no error was generated from the script
|
||||
try
|
||||
tell application "NetNewsWire"
|
||||
exists feed 1 of account 1
|
||||
end tell
|
||||
on error message
|
||||
return {test_result:false, script_result:message}
|
||||
end try
|
||||
|
||||
return {test_result:true}
|
||||
--try
|
||||
-- tell application "NetNewsWire"
|
||||
-- exists feed 1 of account 1
|
||||
-- end tell
|
||||
--on error message
|
||||
-- return {test_result:false, script_result:message}
|
||||
--end try
|
||||
--
|
||||
--return {test_result:true}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
-- this script just tests that no error was generated from the script
|
||||
try
|
||||
tell application "NetNewsWire"
|
||||
opml representation of feed 1 of account 1
|
||||
end tell
|
||||
on error message
|
||||
return {test_result:false, script_result:message}
|
||||
end try
|
||||
|
||||
return {test_result:true}
|
||||
--try
|
||||
-- tell application "NetNewsWire"
|
||||
-- opml representation of feed 1 of account 1
|
||||
-- end tell
|
||||
--on error message
|
||||
-- return {test_result:false, script_result:message}
|
||||
--end try
|
||||
--
|
||||
--return {test_result:true}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
-- this script just tests that no error was generated from the script
|
||||
try
|
||||
tell application "NetNewsWire"
|
||||
{name, url} of every feed of every account
|
||||
end tell
|
||||
on error message
|
||||
return {test_result:false, script_result:message}
|
||||
end try
|
||||
|
||||
return {test_result:true}
|
||||
--try
|
||||
-- tell application "NetNewsWire"
|
||||
-- {name, url} of every feed of every account
|
||||
-- end tell
|
||||
--on error message
|
||||
-- return {test_result:false, script_result:message}
|
||||
--end try
|
||||
--
|
||||
--return {test_result:true}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
-- this script just tests that no error was generated from the script
|
||||
-- and that the returned list is greater than 0
|
||||
try
|
||||
tell application "NetNewsWire"
|
||||
set namesResult to name of every author of every feed of every account
|
||||
end tell
|
||||
set test_result to ((count items of namesResult) > 0)
|
||||
on error message
|
||||
return {test_result:false, script_result:message}
|
||||
end try
|
||||
|
||||
return {test_result:test_result}
|
||||
--try
|
||||
-- tell application "NetNewsWire"
|
||||
-- set namesResult to name of every author of every feed of every account
|
||||
-- end tell
|
||||
-- set test_result to ((count items of namesResult) > 0)
|
||||
--on error message
|
||||
-- return {test_result:false, script_result:message}
|
||||
--end try
|
||||
--
|
||||
--return {test_result:test_result}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
-- this script just tests that no error was generated from the script
|
||||
try
|
||||
tell application "NetNewsWire"
|
||||
title of every article of feed "Six Colors" where read is true
|
||||
end tell
|
||||
on error message
|
||||
return {test_result:false, script_result:message}
|
||||
end try
|
||||
|
||||
return {test_result:true}
|
||||
--try
|
||||
-- tell application "NetNewsWire"
|
||||
-- title of every article of feed "Six Colors" where read is true
|
||||
-- end tell
|
||||
--on error message
|
||||
-- return {test_result:false, script_result:message}
|
||||
--end try
|
||||
--
|
||||
--return {test_result:true}
|
||||
|
||||
Reference in New Issue
Block a user