diff --git a/src/rpcclient/rpcclient/darwin/consts.py b/src/rpcclient/rpcclient/darwin/consts.py index f61c1b45..a07600c3 100644 --- a/src/rpcclient/rpcclient/darwin/consts.py +++ b/src/rpcclient/rpcclient/darwin/consts.py @@ -58,3 +58,32 @@ class CFStringEncoding(Enum): kCFStringEncodingUTF32 = 0x0c000100 # kTextEncodingUnicodeDefault + kUnicodeUTF32Format kCFStringEncodingUTF32BE = 0x18000100 # kTextEncodingUnicodeDefault + kUnicodeUTF32BEFormat kCFStringEncodingUTF32LE = 0x1c000100 # kTextEncodingUnicodeDefault + kUnicodeUTF32LEFormat + + +class NSStringEncoding(Enum): + NSASCIIStringEncoding = 1 # 0..127 only + NSNEXTSTEPStringEncoding = 2 + NSJapaneseEUCStringEncoding = 3 + NSUTF8StringEncoding = 4 + NSISOLatin1StringEncoding = 5 + NSSymbolStringEncoding = 6 + NSNonLossyASCIIStringEncoding = 7 + NSShiftJISStringEncoding = 8 # kCFStringEncodingDOSJapanese + NSISOLatin2StringEncoding = 9 + NSUnicodeStringEncoding = 10 + NSWindowsCP1251StringEncoding = 11 # Cyrillic; same as AdobeStandardCyrillic + NSWindowsCP1252StringEncoding = 12 # WinLatin1 + NSWindowsCP1253StringEncoding = 13 # Greek + NSWindowsCP1254StringEncoding = 14 # Turkish + NSWindowsCP1250StringEncoding = 15 # WinLatin2 + NSISO2022JPStringEncoding = 21 # ISO 2022 Japanese encoding for e-mail + NSMacOSRomanStringEncoding = 30 + + NSUTF16StringEncoding = NSUnicodeStringEncoding # An alias for NSUnicodeStringEncoding + + NSUTF16BigEndianStringEncoding = 0x90000100 # NSUTF16StringEncoding encoding with explicit endianness specified + NSUTF16LittleEndianStringEncoding = 0x94000100 # NSUTF16StringEncoding encoding with explicit endianness specified + + NSUTF32StringEncoding = 0x8c000100 + NSUTF32BigEndianStringEncoding = 0x98000100 # NSUTF32StringEncoding encoding with explicit endianness specified + NSUTF32LittleEndianStringEncoding = 0x9c000100 # NSUTF32StringEncoding encoding with explicit endianness specified diff --git a/src/rpcclient/tests/conftest.py b/src/rpcclient/tests/conftest.py index 94932181..006931b6 100644 --- a/src/rpcclient/tests/conftest.py +++ b/src/rpcclient/tests/conftest.py @@ -1,15 +1,14 @@ +from contextlib import closing + import pytest -from rpcclient.client_factory import create_client +from rpcclient.client_factory import create_client, DarwinClient @pytest.fixture def client(): - try: - c = create_client('127.0.0.1') + with closing(create_client('127.0.0.1')) as c: yield c - finally: - c.close() def pytest_addoption(parser): @@ -21,13 +20,20 @@ def pytest_configure(config): 'markers', '''local_only: marks tests that require features the CI lacks (deselect with '-m "not local_only"')''' ) + config.addinivalue_line('markers', 'darwin: marks tests that require darwin platform to run') def pytest_collection_modifyitems(config, items): - if not config.getoption('--ci'): - # --ci given in cli: skip local only tests. - return skip_local_only = pytest.mark.skip(reason='remove --ci option to run') + skip_not_darwin = pytest.mark.skip(reason='Darwin system is required for this test') + + with closing(create_client('127.0.0.1')) as c: + is_darwin = isinstance(c, DarwinClient) + for item in items: - if 'local_only' in item.keywords: + if 'local_only' in item.keywords and config.getoption('--ci'): + # --ci given in cli: skip local only tests. item.add_marker(skip_local_only) + if 'darwin' in item.keywords and not is_darwin: + # Skip test that require Darwin on non Darwin system + item.add_marker(skip_not_darwin) diff --git a/src/rpcclient/tests/test_objc.py b/src/rpcclient/tests/test_objc.py deleted file mode 100644 index bbea5745..00000000 --- a/src/rpcclient/tests/test_objc.py +++ /dev/null @@ -1,8 +0,0 @@ -def test_objc(client): - d = client.symbols.objc_getClass('NSMutableDictionary').objc_call('new').objc_symbol - - # call method - d.setObject_forKey_(client.cf('value'), client.cf('key')) - - # call property - assert '{\n key = value;\n}' == d.description.py diff --git a/src/rpcclient/tests/test_objc_symbol.py b/src/rpcclient/tests/test_objc_symbol.py new file mode 100644 index 00000000..87a36d50 --- /dev/null +++ b/src/rpcclient/tests/test_objc_symbol.py @@ -0,0 +1,23 @@ +import pytest + +from rpcclient.darwin.consts import NSStringEncoding + + +@pytest.mark.darwin +def test_method_by_method_name(client): + NSString = client.objc_get_class('NSString') + ascii_encoding = NSStringEncoding.NSASCIIStringEncoding + str1 = NSString.stringWithCString_encoding_('Taylor Swift', ascii_encoding).objc_symbol + assert str1.cStringUsingEncoding_(ascii_encoding).peek_str() == 'Taylor Swift' + assert str1.length == len('Taylor Swift') + assert str1.lowercaseString().cStringUsingEncoding_(ascii_encoding).peek_str() == 'taylor swift' + assert str1.uppercaseString().cStringUsingEncoding_(ascii_encoding).peek_str() == 'TAYLOR SWIFT' + + +@pytest.mark.darwin +def test_calling_property(client): + d = client.symbols.objc_getClass('NSMutableDictionary').objc_call('new').objc_symbol + # call method + d.setObject_forKey_(client.cf('value'), client.cf('key')) + # call property + assert '{\n key = value;\n}' == d.description.py