-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide autoreleas_pool to restrict memory usage (#76)
- Loading branch information
Showing
9 changed files
with
118 additions
and
106 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,77 +1,89 @@ | ||
def test_ns_string(emu_ios, objc): | ||
string = objc.msg_send("NSString", "stringWithUTF8String:", "chomper") | ||
with objc.autorelease_pool(): | ||
string = objc.msg_send("NSString", "stringWithUTF8String:", "chomper") | ||
|
||
assert string | ||
assert string | ||
|
||
|
||
def test_ns_array(emu_ios, objc): | ||
array = objc.msg_send("NSMutableArray", "array") | ||
with objc.autorelease_pool(): | ||
array = objc.msg_send("NSMutableArray", "array") | ||
|
||
assert array | ||
assert array | ||
|
||
string = objc.msg_send("NSString", "stringWithUTF8String:", "chomper") | ||
objc.msg_send(array, "addObject:", string) | ||
string = objc.msg_send("NSString", "stringWithUTF8String:", "chomper") | ||
objc.msg_send(array, "addObject:", string) | ||
|
||
|
||
def test_ns_dictionary(emu_ios, objc): | ||
dictionary = objc.msg_send("NSMutableDictionary", "dictionary") | ||
with objc.autorelease_pool(): | ||
dictionary = objc.msg_send("NSMutableDictionary", "dictionary") | ||
|
||
assert dictionary | ||
assert dictionary | ||
|
||
string = objc.msg_send("NSString", "stringWithUTF8String:", "chomper") | ||
objc.msg_send(dictionary, "setObject:forKey:", string, string) | ||
string = objc.msg_send("NSString", "stringWithUTF8String:", "chomper") | ||
objc.msg_send(dictionary, "setObject:forKey:", string, string) | ||
|
||
|
||
def test_ns_data(emu_ios, objc): | ||
data_bytes = b"chomper" | ||
with objc.autorelease_pool(): | ||
data_bytes = b"chomper" | ||
|
||
buffer = emu_ios.create_buffer(len(data_bytes)) | ||
emu_ios.write_bytes(buffer, data_bytes) | ||
buffer = emu_ios.create_buffer(len(data_bytes)) | ||
emu_ios.write_bytes(buffer, data_bytes) | ||
|
||
data = objc.msg_send("NSData", "dataWithBytes:length:", buffer, len(data_bytes)) | ||
data = objc.msg_send("NSData", "dataWithBytes:length:", buffer, len(data_bytes)) | ||
|
||
assert data | ||
assert data | ||
|
||
|
||
def test_ns_url(emu_ios, objc): | ||
string = objc.msg_send("NSString", "stringWithUTF8String:", "https://google.com") | ||
with objc.autorelease_pool(): | ||
string = objc.msg_send( | ||
"NSString", "stringWithUTF8String:", "https://google.com" | ||
) | ||
|
||
url = objc.msg_send("NSURL", "alloc") | ||
objc.msg_send(url, "initWithString:", string) | ||
url = objc.msg_send("NSURL", "alloc") | ||
objc.msg_send(url, "initWithString:", string) | ||
|
||
assert url | ||
assert url | ||
|
||
|
||
def test_ns_request(emu_ios, objc): | ||
string = objc.msg_send("NSString", "stringWithUTF8String:", "https://google.com") | ||
with objc.autorelease_pool(): | ||
string = objc.msg_send( | ||
"NSString", "stringWithUTF8String:", "https://google.com" | ||
) | ||
|
||
url = objc.msg_send("NSURL", "alloc") | ||
objc.msg_send(url, "initWithString:", string) | ||
url = objc.msg_send("NSURL", "alloc") | ||
objc.msg_send(url, "initWithString:", string) | ||
|
||
request = objc.msg_send("NSMutableURLRequest", "requestWithURL:", url) | ||
request = objc.msg_send("NSMutableURLRequest", "requestWithURL:", url) | ||
|
||
assert request | ||
assert request | ||
|
||
|
||
def test_ns_locale(emu_ios, objc): | ||
preferred_languages = objc.msg_send("NSLocale", "preferredLanguages") | ||
with objc.autorelease_pool(): | ||
preferred_languages = objc.msg_send("NSLocale", "preferredLanguages") | ||
|
||
assert preferred_languages | ||
assert preferred_languages | ||
|
||
preferred_language = objc.msg_send(preferred_languages, "firstObject") | ||
str_ptr = objc.msg_send(preferred_language, "cStringUsingEncoding:", 4) | ||
preferred_language = objc.msg_send(preferred_languages, "firstObject") | ||
str_ptr = objc.msg_send(preferred_language, "cStringUsingEncoding:", 4) | ||
|
||
assert len(emu_ios.read_string(str_ptr)) > 0 | ||
assert len(emu_ios.read_string(str_ptr)) > 0 | ||
|
||
|
||
def test_ns_user_defaults(emu_ios, objc): | ||
user_defaults = objc.msg_send("NSUserDefaults", "standardUserDefaults") | ||
with objc.autorelease_pool(): | ||
user_defaults = objc.msg_send("NSUserDefaults", "standardUserDefaults") | ||
|
||
assert user_defaults | ||
assert user_defaults | ||
|
||
key = objc.msg_send("NSString", "stringWithUTF8String:", "AppleLocale") | ||
key = objc.msg_send("NSString", "stringWithUTF8String:", "AppleLocale") | ||
|
||
apple_locale = objc.msg_send(user_defaults, "stringForKey:", key) | ||
str_ptr = objc.msg_send(apple_locale, "cStringUsingEncoding:", 4) | ||
apple_locale = objc.msg_send(user_defaults, "stringForKey:", key) | ||
str_ptr = objc.msg_send(apple_locale, "cStringUsingEncoding:", 4) | ||
|
||
assert len(emu_ios.read_string(str_ptr)) > 0 | ||
assert len(emu_ios.read_string(str_ptr)) > 0 |