This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk_test.py
77 lines (56 loc) · 1.98 KB
/
sdk_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from ctypes import *
import unittest
import sdk
import json
hexutil = CDLL('./lib/hexutil.so')
c3 = sdk.NewC3(stateFilePath = './lib/state.json')
class TestSDK(unittest.TestCase):
def test_registerAndInvokeMethod(self):
key = ""
val = ""
expectKey = "expectKey"
expectVal = "expectVal"
methodName = "foo"
inputKey = c_char_p(hexutil.EncodeString(c_char_p(expectKey.encode('utf-8')))).value.decode('utf-8')
inputVal = c_char_p(hexutil.EncodeString(c_char_p(expectVal.encode('utf-8')))).value.decode('utf-8')
def setStuff(k, v):
nonlocal key
key = k
nonlocal val
val = v
c3.registerMethod(methodName, setStuff)
c3.invoke(methodName, inputKey, inputVal)
self.assertEqual(expectKey, key)
self.assertEqual(expectVal, val)
def test_store(self):
key = "foo"
val = "bar"
c3.state[key] = val
self.assertEqual(c3.state[key], val)
del c3.state[key]
def test_state(self):
methodName = "setState"
key1 = "foo"
val1 = "bar"
key2 = "foofoo"
val2 = "barbar"
def setState(k, v):
c3.state[k] = v
c3.registerMethod(methodName, setState)
p1 = [
methodName,
c_char_p(hexutil.EncodeString(c_char_p(key1.encode('utf-8')))).value.decode('utf-8'),
c_char_p(hexutil.EncodeString(c_char_p(val1.encode('utf-8')))).value.decode('utf-8'),
]
p2 = [
methodName,
c_char_p(hexutil.EncodeString(c_char_p(key2.encode('utf-8')))).value.decode('utf-8'),
c_char_p(hexutil.EncodeString(c_char_p(val2.encode('utf-8')))).value.decode('utf-8'),
]
params = [p1, p2]
paramsJSON = json.dumps(params)
c3.process(paramsJSON)
self.assertEqual(c3.state[key1], val1)
self.assertEqual(c3.state[key2], val2)
if __name__ == '__main__':
unittest.main()