Continue rename to NetNewsWire.

This commit is contained in:
Brent Simmons
2018-08-28 22:18:24 -07:00
parent 062d531ed9
commit 141ae5cc2f
256 changed files with 816 additions and 518 deletions

View File

@@ -0,0 +1,67 @@
//
// AppleScriptXCTestCase.swift
// NetNewsWireUITests
//
// Created by Olof Hellman on 2/10/18.
// Copyright © 2018 Ranchero Software. All rights reserved.
//
import XCTest
class AppleScriptXCTestCase: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
/*
@function doIndividualScript
@param filename -- name of a .applescript (sans extention) 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:"applescript", subdirectory:"TestScripts")
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"]
}
}

View File

@@ -0,0 +1,95 @@
//
// ScriptingTests.swift
// NetNewsWireTests
//
// Created by Olof Hellman on 1/7/18.
// Copyright © 2018 Olof Hellman. All rights reserved.
//
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")
}
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 pices 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.
*/
func testCurrentArticleScripts() {
doIndividualScriptWithExpectation(filename: "uiScriptingTestSetup")
doIndividualScriptWithExpectation(filename: "establishMainWindowStartingState")
doIndividualScriptWithExpectation(filename: "selectAFeed")
doIndividualScriptWithExpectation(filename: "testCurrentArticleIsNil")
doIndividualScriptWithExpectation(filename: "selectAnArticle")
doIndividualScriptWithExpectation(filename: "testURLsOfCurrentArticle")
}
}

View File

@@ -0,0 +1,37 @@
property uparrowKeyCode : 126
property downarrowKeyCode : 125
property rightarrowKeyCode : 124
property leftarrowKeyCode : 123
to activateNetNewsWire()
tell application "NetNewsWire"
activate
end tell
end activateNetNewsWire
to multipleKeyCodes(keycode, numberOfKeys)
tell application "System Events"
tell process "NetNewsWire"
repeat numberOfKeys times
key code keycode
end repeat
end tell
end tell
end multipleKeyCodes
to establishMainWindowStartingState()
activateNetNewsWire()
multipleKeyCodes(downarrowKeyCode, 2)
multipleKeyCodes(rightarrowKeyCode, 2)
multipleKeyCodes(leftarrowKeyCode, 2)
multipleKeyCodes(uparrowKeyCode, 50)
end establishMainWindowStartingState
try
establishMainWindowStartingState()
-- hit the down arrow a few times to get into the feeds
on error message
return {test_result:false, script_result:message}
end try
return {test_result:true, script_result:"established starting state"}

View File

@@ -0,0 +1,32 @@
property uparrowKeyCode : 126
property downarrowKeyCode : 125
property rightarrowKeyCode : 124
property leftarrowKeyCode : 123
to activateNetNewsWire()
tell application "NetNewsWire"
activate
end tell
end activateNetNewsWire
to multipleKeyCodes(keycode, numberOfKeys)
tell application "System Events"
tell process "NetNewsWire"
repeat numberOfKeys times
key code keycode
end repeat
end tell
end tell
end multipleKeyCodes
try
activateNetNewsWire()
multipleKeyCodes(downarrowKeyCode, 9)
multipleKeyCodes(uparrowKeyCode, 1)
on error message
return {test_result:false, script_result:message}
end try
return {test_result:true, script_result:"selected feed"}

View File

@@ -0,0 +1,31 @@
property uparrowKeyCode : 126
property downarrowKeyCode : 125
property rightarrowKeyCode : 124
property leftarrowKeyCode : 123
to activateNetNewsWire()
tell application "NetNewsWire"
activate
end tell
end activateNetNewsWire
to multipleKeyCodes(keycode, numberOfKeys)
tell application "System Events"
tell process "NetNewsWire"
repeat numberOfKeys times
key code keycode
end repeat
end tell
end tell
end multipleKeyCodes
try
activateNetNewsWire()
multipleKeyCodes(rightarrowKeyCode, 1)
on error message
return {test_result:false, script_result:message}
end try
return {test_result:true, script_result:"selected an article"}

View File

@@ -0,0 +1,23 @@
-- this script tests that it is possible to get the url property of the current article
-- it uses system event accessibility scripting to set up the main window
-- one needs to authorize scripting accessibility control in the System Preferences'
-- Privacy and security pane
try
tell application "NetNewsWire"
set shouldBeMissingValue to current article
end tell
--verify that the current article is in fact 'missing vcalue'
if shouldBeMissingValue is missing value then
set the_message to "passed tests"
set the_result to true
else
set the_message to "expected current article to be 'missing value'"
set the_result to false
end if
on error message
return {test_result:false, script_result:message}
end try
return {test_result:the_result, script_result:the_message}

View File

@@ -0,0 +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}

View File

@@ -0,0 +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}

View File

@@ -0,0 +1,13 @@
-- NetNewsWire scripting unit tests expect a dictionary to be returned from a script
-- containing either
-- {test_result:true}
-- to indicate success or
-- {test_result:false}
-- to indicate failure
-- Data can be passed back to unit test code by including a script_result field
-- for example this script returns "Geoducks!" as the result
-- this can be used as part of XCTest verification
-- see the testGenericScript() function in the ScriptingTests XCTestCase
return {test_result:true, script_result:"Geoducks!"}

View File

@@ -0,0 +1,19 @@
try
tell application "NetNewsWire"
open location "http://scripting.com/rss"
end tell
on error message
return {test_result:false, script_result:message}
end
-- open location is not expected to return a value
-- trying to access result should trigger an error, and that indicates a successful test
try
set getURLResult to the result
set testResult to false
on error message
set testResult to true
end try
return {test_result:testResult}

View File

@@ -0,0 +1,27 @@
try
tell application "NetNewsWire"
tell account id "OnMyMac"
repeat 3 times
set newFeed to make new feed with data "https://boingboing.net/feed"
delete newFeed
end repeat
set newFolder to make new folder with properties {name:"XCTest folder"}
repeat 3 times
set newFeed to make new feed in newFolder with data "https://boingboing.net/feed"
delete newFeed
end repeat
delete newFolder
end tell
end tell
set test_result to true
set script_result to "Success"
on error message
return {test_result:false, script_result:message}
end try
return {test_result:test_result, script_result:script_result}

View File

@@ -0,0 +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}

View File

@@ -0,0 +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}

View File

@@ -0,0 +1,11 @@
-- this script just tests that no error was generated from the script
try
tell application "NetNewsWire"
name of every folder of every account
end tell
on error message
return {test_result:false, script_result:message}
end try
return {test_result:true}

View File

@@ -0,0 +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}

View File

@@ -0,0 +1,14 @@
-- this script tests that it is possible to get the url property of the current article
-- it uses system event accessibility scripting to set up the main window
-- one needs to authorize scripting accessibility control in the System Preferences'
-- Privacy and security pane
try
tell application "NetNewsWire"
{url, permalink, external url} of current article
end tell
on error message
return {test_result:false, script_result:message}
end try
return {test_result:true, script_result:"tests passed"}

View File

@@ -0,0 +1,18 @@
-- this script sets up NetNewsWire so it is ready to be tested
-- to get a current article
to activateNetNewsWire()
tell application "NetNewsWire"
activate
end tell
end activateNetNewsWire
tell application "System Events"
set isFrontmost to frontmost of process "NetNewsWire"
repeat while isFrontmost is false
my activateNetNewsWire()
set isFrontmost to frontmost of process "NetNewsWire"
end repeat
end tell
return {test_result:true, script_result:"finished"}