-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import XCTest | ||
import SwiftGodotTestability | ||
@testable import SwiftGodot | ||
|
||
@Godot | ||
private class TestNode: Node { | ||
#signal("mySignal", arguments: ["age": Int.self, "name": String.self]) | ||
var receivedInt: Int? = nil | ||
var receivedString: String? = nil | ||
@Callable func receiveSignal (_ age: Int, name: String) { | ||
receivedInt = age | ||
receivedString = name | ||
} | ||
} | ||
final class SignalTests: GodotTestCase { | ||
override static var godotSubclasses: [Wrapped.Type] { | ||
return [TestNode.self] | ||
} | ||
func testUserDefinedSignal() { | ||
let node = TestNode() | ||
node.connect (signal: TestNode.mySignal, to: node, method: "receiveSignal") | ||
node.emit (signal: TestNode.mySignal, 22, "Joey") | ||
|
||
XCTAssertEqual (node.receivedInt, 22, "Integers should have been the same") | ||
XCTAssertEqual (node.receivedString, "Joey", "Strings should have been the same") | ||
} | ||
|
||
func testBuiltInSignalWithNoArgument() { | ||
let node = Node() | ||
var signalReceived = false | ||
node.ready.connect { | ||
signalReceived = true | ||
} | ||
node.emitSignal("ready") | ||
XCTAssertTrue (signalReceived, "signal should have been received") | ||
} | ||
|
||
func testBuiltInSignalWithArgument() { | ||
let node = Node() | ||
var signalReceived = false | ||
node.childExitingTree.connect { (nodeParameter: Node?) in // full signature is specified here to check that it's being generated with the right types | ||
signalReceived = true | ||
XCTAssertEqual(node, nodeParameter) | ||
} | ||
node.emitSignal("child_exiting_tree", Variant(node)) | ||
XCTAssertTrue (signalReceived, "signal should have been received") | ||
} | ||
|
||
func testBuiltInSignalWithPrimitiveArguments() { | ||
let node = AnimationNode() | ||
var signalReceived = false | ||
node.animationNodeRenamed.connect { (id: Int64, oldName: String, newName: String) in // full signature is specified here to check that it's being generated with the right types | ||
signalReceived = true | ||
XCTAssertEqual(id, 123) | ||
XCTAssertEqual(oldName, "old name") | ||
XCTAssertEqual(newName, "new name") | ||
} | ||
node.emitSignal("animation_node_renamed", Variant(123), Variant("old name"), Variant("new name")) | ||
XCTAssertTrue (signalReceived, "signal should have been received") | ||
} | ||
} | ||
|