Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add Darwin mark. #93

Merged
merged 1 commit into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/rpcclient/rpcclient/darwin/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 15 additions & 9 deletions src/rpcclient/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
8 changes: 0 additions & 8 deletions src/rpcclient/tests/test_objc.py

This file was deleted.

23 changes: 23 additions & 0 deletions src/rpcclient/tests/test_objc_symbol.py
Original file line number Diff line number Diff line change
@@ -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