-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for GDObject handling notifications
- Loading branch information
Showing
1 changed file
with
27 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,54 @@ | ||
extends RefCounted | ||
|
||
static var ObjectiveC = Engine.get_singleton("ObjectiveC") | ||
const NOTIFICATION_NAME = "my cool notification" | ||
const NOTIFICATION_USER_INFO = { hello = "world" } | ||
|
||
var my_property = 5 | ||
var notification_called = false | ||
|
||
|
||
func test_property() -> bool: | ||
var objcObject = ObjectiveC.wrap_object(self) | ||
assert(objcObject.my_property == my_property) | ||
assert(objcObject.invoke("my_property") == my_property) | ||
var self_objc = ObjectiveC.wrap_object(self) | ||
assert(self_objc.my_property == my_property) | ||
assert(self_objc.invoke("my_property") == my_property) | ||
return true | ||
|
||
|
||
func test_method() -> bool: | ||
var objcObject = ObjectiveC.wrap_object(self) | ||
assert(objcObject.invoke("intToBool:", 1) == true) | ||
assert(objcObject.invoke("intToBool:", 0) == false) | ||
var self_objc = ObjectiveC.wrap_object(self) | ||
assert(self_objc.invoke("intToBool:", 1) == true) | ||
assert(self_objc.invoke("intToBool:", 0) == false) | ||
return true | ||
|
||
|
||
func test_notification() -> bool: | ||
var self_objc = ObjectiveC.wrap_object(self) | ||
var NSNotificationCenter = ObjectiveC.NSNotificationCenter.defaultCenter | ||
NSNotificationCenter.invoke("addObserver:selector:name:object:", self_objc, "handleNotification:", NOTIFICATION_NAME, null) | ||
NSNotificationCenter.invoke("postNotificationName:object:userInfo:", NOTIFICATION_NAME, null, NOTIFICATION_USER_INFO) | ||
NSNotificationCenter.invoke("removeObserver:", self_objc) | ||
assert(notification_called, "Notification was not called") | ||
return true | ||
|
||
|
||
func intToBool(value: int) -> bool: | ||
return bool(value) | ||
|
||
|
||
func handleNotification(notification): | ||
assert(notification.name == NOTIFICATION_NAME) | ||
assert(notification.userInfo.to_dictionary() == NOTIFICATION_USER_INFO) | ||
notification_called = true | ||
|
||
|
||
func methodSignatureForSelector(sel: String) -> String: | ||
match sel: | ||
"my_property": | ||
return "i@:" | ||
"intToBool:": | ||
return "B@:i" | ||
"handleNotification:": | ||
return "v@:@" | ||
_: | ||
return "" |