You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

350 lines
9.2 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This file is under GNU Affero General Public License 3.0
# see LICENSE.txt
import pytest
import lib_test
from lib_test import *
# // Int
# // ===
# // By Value
def test_func_V_args_V():
(ret,) = func_V_args_V()
assert(ret == None)
def test_func_Pi_args_V():
(ret,) = func_Pi_args_V()
print("RESULT:", ret)
assert (ret == 23)
def test_func_V_args_Pi():
(ret,arg1) = func_V_args_Pi(23)
print("RESULT:", ret, arg1)
assert(ret == None)
assert(arg1 == 23)
def test_func_Pi_args_Pi():
(ret,arg1) = func_Pi_args_Pi(22)
print("RESULT:", ret, arg1)
assert (ret == 23)
assert (arg1 == 22)
@pytest.mark.skip("")
def test_func_V_args_pPi():
(ret,arg1) = func_V_args_pPi(22)
print("RESULT:", ret, arg1)
assert (ret == None)
assert (arg1 == 23)
@pytest.mark.skip("")
def test_func_Pi_args_Pi_pPi_pPi():
(ret, arg1, arg2, arg3) = func_Pi_args_Pi_pPi_pPi(23, 22, 22)
print("RESULT:", ret, arg1, arg2, arg3)
assert (ret == 23)
assert (arg1 == 23)
assert (arg2 == 23)
assert (arg3 == 23)
# // Char
# // ====
# // By Value
def test_func_Pc_args_V():
(ret,) = func_Pc_args_V()
print("RESULT:", ret)
assert (ret == "A")
def test_func_V_args_Pc():
(ret,arg1) = func_V_args_Pc('A')
print("RESULT:", ret, arg1)
assert(ret == None)
assert(arg1 == 'A')
def test_func_V_args_Pc_with_Str():
with pytest.raises(Exception):
(ret,arg1) = func_V_args_Pc('pEp')
def test_func_Pc_args_Pc():
(ret,arg1) = func_Pc_args_Pc('a')
print("RESULT:", ret, arg1)
assert (ret == 'A')
assert (arg1 == 'a')
# // Char*
def test_func_pPcStr_args_V():
(ret,) = func_pPcStr_args_V()
print("RESULT:", ret)
assert (ret == "pEp")
def test_func_V_args_pPcChr():
(ret,arg1) = func_V_args_pPcChr('a')
print("RESULT:", ret, arg1)
assert (ret == None)
assert (arg1 == 'A')
def test_func_V_args_pPcChr_with_Str():
(ret,arg1) = func_V_args_pPcChr('pep')
print("RESULT:", ret, arg1)
assert (ret == None)
assert (arg1 == 'Pep')
def test_func_V_args_pPcStr():
(ret,arg1) = func_V_args_pPcStr('pep')
print("RESULT:", ret, arg1)
assert (ret == None)
assert (arg1 == 'PEP')
def test_func_Pc_args_Pc_pPc_pPc():
(ret, arg1, arg2, arg3) = func_Pc_args_Pc_pPc_pPc('A', 'a','a')
print("RESULT:", ret, arg1, arg2, arg3)
assert (ret == 'A')
assert (arg1 == 'A')
assert (arg2 == 'A')
assert (arg3 == 'A')
# // String-by-value (const char*)
def test_func_pPcc_args_V():
(ret,) = func_pPcc_args_V()
print("RESULT:", ret)
assert (ret == "pEp")
def test_func_V_args_pPcc():
instr = "pEp"
(ret,arg1) = func_V_args_pPcc(instr)
print("RESULT:", ret,arg1)
assert (ret == None)
assert (arg1 == instr)
def test_func_pPcc_args_pPcc():
instr = "pEp"
(ret,arg1) = func_pPcc_args_pPcc(instr)
print("RESULT:", ret,arg1)
assert (ret == instr)
assert (arg1 == instr)
def test_func_pPcc_args_pPcc_pPcc():
instr = "pEp"
instr2 = "pEp"
(ret,arg1,arg2) = func_pPcc_args_pPcc_pPcc(instr,instr2)
print("RESULT:", ret,arg1,arg2)
assert (ret == instr)
assert (arg1 == instr)
assert (arg2 == instr)
# // String-by-ref (char**)
def test_func_ppPc_args_V():
(ret,) = func_ppPc_args_V()
print("RESULT:", ret)
assert (ret == "pEp")
def test_func_pppPc_args_V():
(ret,) = func_pppPc_args_V()
print("RESULT:", ret)
assert (ret == "pEp")
def test_func_V_args_ppPc():
instr = "orig"
instr = "orig"
(ret,arg1) = func_V_args_ppPc(instr)
print("RESULT:", ret,arg1)
assert (ret == None)
assert (arg1 == "pEp")
def test_func_pppPc_args_pppPc():
instr = "orig"
(ret,arg1) = func_pppPc_args_pppPc(instr)
print("RESULT:", ret,arg1)
assert (ret == "pEp")
assert (arg1 == "pEp")
def test_func_pppPc_args_pppPc_ppPc():
instr = "orig"
instr2 = "orig"
(ret,arg1,arg2) = func_pppPc_args_pppPc_ppPc(instr,instr2)
print("RESULT:", ret,arg1,arg2)
assert (ret == "pEp")
assert (arg1 == "pEp")
assert (arg2 == "pEp")\
# // Structs
# // =======
# // By value
def test_func__PS_args_V():
(ret,) = func__PS_args_V()
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
def test_func__PS_args__PS():
ps = lib_test._PS()
ps.field__P_1 = 3
ps.field__P_2 = 3
(ret,psout) = func__PS_args__PS(ps)
print("ret:",PS_to_string(ret))
print("psout:",PS_to_string(psout))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
assert(psout.field__P_1 == 3)
assert(psout.field__P_2 == 3)
def test_func_TTAPS_args_V():
(ret,) = func_TTAPS_args_V()
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
def test_func_TTAPS_args_TTAPS():
ps = PS()
ps.field__P_1 = 3
ps.field__P_2 = 3
(ret,psout) = func_TTAPS_args_TTAPS(ps)
print("ret:",PS_to_string(ret))
print("psout:",PS_to_string(psout))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
assert(psout.field__P_1 == 3)
assert(psout.field__P_2 == 3)
# // By pointer
def test_func_pTAPS_args_V():
(ret,) = func_pTAPS_args_V()
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
def test_func_ppTAPS_args_V():
(ret,) = func_ppTAPS_args_V()
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
def test_func_pppTAPS_args_V():
(ret,) = func_ppTAPS_args_V()
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(ret.field__P_2 == 23)
def test_func_V_args_pTAPS():
ps = PS()
print(PS_to_string(ps))
(ret,psnew) = func_V_args_pTAPS(ps)
print(PS_to_string(psnew))
assert(ret == None)
assert(psnew.field__P_1 == 23)
assert(psnew.field__P_2 == 23)
def test_func_ppTAPS_args_ppTAPS():
ps = PS()
print(PS_to_string(ps))
(ret,inout) = func_ppTAPS_args_ppTAPS(ps)
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(inout.field__P_1 == 23)
assert(inout.field__P_2 == 23)
def test_func_pppTAPS_args_pppTAPS():
ps = PS()
print(PS_to_string(ps))
(ret,inout) = func_pppTAPS_args_pppTAPS(ps)
print(PS_to_string(ret))
assert(ret.field__P_1 == 23)
assert(inout.field__P_1 == 23)
assert(inout.field__P_2 == 23)
# // PSa - Primitive Structs containing array
# // PSa contains a char[4] (which is an array of bytes, NOT a string)
# // By value
def test_func_TTAPSa_args_V():
(ret,) = func_TTAPSa_args_V()
assert(ret.field__Pa_1 == b"pEp\x00")
def test_func_TTAPSa_args_TTAPSa():
psa = PSa()
psa.field__Pa_1 = b'pEp'
(ret,inout) = func_TTAPSa_args_TTAPSa(psa)
assert(ret.field__Pa_1 == b'pEp\x00')
assert(inout.field__Pa_1 == b'pEp\x00')
# // By pointer
def test_func_V_args_pTTAPSa():
psa = PSa()
(ret,inout) = func_V_args_pTTAPSa(psa)
assert(ret == None)
assert(inout.field__Pa_1 == b'pEp\x00')
def test_func_ppTTAPSa_args_ppTTAPSa():
psa = PSa()
(ret,inout) = func_ppTTAPSa_args_ppTTAPSa(psa)
assert(ret.field__Pa_1 == b'pEp\x00')
assert(inout.field__Pa_1 == b'pEp\x00')
def test_func_pppTTAPSa_args_pppTTAPSa():
psa = PSa()
(ret,inout) = func_pppTTAPSa_args_pppTTAPSa(psa)
assert(ret.field__Pa_1 == b'pEp\x00')
assert(inout.field__Pa_1 == b'pEp\x00')
def test_struct_field_array_of_char_get_set():
a = PSa()
a.field__Pa_1 = b''
assert(a.field__Pa_1 == b'\x00\x00\x00\x00')
assert(len(a.field__Pa_1) == 4 )
a.field__Pa_1 = b'pEp'
assert(a.field__Pa_1 == b'pEp\x00')
assert(len(a.field__Pa_1) == 4 )
a.field__Pa_1 = b'pEpTooLong'
assert(a.field__Pa_1 == b'pEpT')
assert(len(a.field__Pa_1) == 4 )
a.field__Pa_1 = b'p'
assert(a.field__Pa_1 == b'p\x00\x00\x00')
assert(len(a.field__Pa_1) == 4 )
# // CS - Complex Structs containing array
# // CS contains a PS[3] (which is an array of structs)
# // By value
# TACS func_TACS_args_V(); // MISSING
#
# TACS func_TACS_args_TACS(TACS arg1_TACS); // MISSING
#
# // By pointer
# void func_V_args_pTACS(TACS* arg1_pTACS); // MISSING
#
# TACS** func_ppTACS_args_ppTACS(TACS** arg1_ppTACS); // MISSING
#
# TACS*** func_pppTACS_args_pppTACS(TACS*** arg1_pppTACS); // MISSING
def test_struct_field_array_of_structs_set_get():
a = CS()
b = PS()
b.field__P_1 = 23
b.field__P_2 = 23
a.field_APS_1 = [b]
assert(a.field_APS_1[0].field__P_1 == 23)
assert(a.field_APS_1[0].field__P_2 == 23)
def test_struct_field_array_of_structs_immutable_len():
a = CS()
b = PS()
assert(len(a.field_APS_1) == 3)
a.field_APS_1 = [b]
assert(len(a.field_APS_1) == 3)
a.field_APS_1 = [b,b]
assert(len(a.field_APS_1) == 3)
a.field_APS_1 = [b,b,b]
assert(len(a.field_APS_1) == 3)
a.field_APS_1 = []
assert(len(a.field_APS_1) == 3)
@pytest.mark.skip("throw exception instead of warnning")
def test_struct_field_array_of_structs_accept_unityped_arr_only():
a = CS()
b = PS()
with pytest.raises(Exception):
a.field_APS_1 = [b,"invalid_type"]
def PS_to_string(ps):
ret = "{}\n".format(type(ps))
ret += "field__P_1: {}\n".format(ps.field__P_1)
ret += "field__P_2: {}".format(ps.field__P_2)
return ret