Skip to content

Commit

Permalink
Split out signal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Dec 5, 2024
1 parent 93f18fe commit d74265e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 42 deletions.
42 changes: 0 additions & 42 deletions Tests/SwiftGodotTests/MarshalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,6 @@ final class MarshalTests: GodotTestCase {
return [TestNode.self]
}

func testVarArgs() {
let node = TestNode()

node.probe ()
XCTAssertEqual (node.receivedInt, 22, "Integers should have been the same")
XCTAssertEqual (node.receivedString, "Joey", "Strings should have been the same")
}

func testBuiltInSignalWithNoArgument() {
let node = TestNode()
var signalReceived = false
node.ready.connect {
signalReceived = true
}
node.emitSignal("ready")
XCTAssertTrue (signalReceived, "signal should have been received")
}

func testBuiltInSignalWithArgument() {
let node = TestNode()
var signalReceived = false
node.childExitingTree.connect { nodeParameter in
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, oldName, newName in
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")
}

func testClassesMethodsPerformance() {
let node = TestNode()
let child = TestNode()
Expand Down
67 changes: 67 additions & 0 deletions Tests/SwiftGodotTests/SignalTests.swift
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")
}
}

0 comments on commit d74265e

Please sign in to comment.