summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2018-04-12 17:18:53 -0300
committerLarry Jr <larry.olj@gmail.com>2018-04-12 17:21:09 -0300
commit94d8c0e8ea6ac0ca8b4103b5b5d628e1ab26279b (patch)
treea302b089d2c15637050144d44f7be0bba844b29d
parent69e0b113424eb18665c5184c758d3a0525e79f56 (diff)
Eolian: TestGenerator Mono tests [WIP]
-rwxr-xr-xsrc/scripts/pyolian/testgenerator.py61
-rw-r--r--src/scripts/pyolian/testgenerator_suite.cs.template94
2 files changed, 136 insertions, 19 deletions
diff --git a/src/scripts/pyolian/testgenerator.py b/src/scripts/pyolian/testgenerator.py
index 29ff834b0c..b46158d914 100755
--- a/src/scripts/pyolian/testgenerator.py
+++ b/src/scripts/pyolian/testgenerator.py
@@ -6,6 +6,7 @@ import datetime
6import eolian 6import eolian
7import pyratemp 7import pyratemp
8from copy import copy 8from copy import copy
9import itertools
9 10
10# Use .eo files from the source tree (not the installed ones) 11# Use .eo files from the source tree (not the installed ones)
11script_path = os.path.dirname(os.path.realpath(__file__)) 12script_path = os.path.dirname(os.path.realpath(__file__))
@@ -41,6 +42,39 @@ def load_file(filename):
41 return f.read() 42 return f.read()
42 return None 43 return None
43 44
45dicttypes = {}
46
47def cs_types():
48 dicttypes.update({"byte": "sbyte"
49 , "llong": "long"
50 , "int8": "sbyte"
51 , "int16": "short"
52 , "int32": "int"
53 , "int64": "long"
54 , "ssize": "long"
55 , "ubyte": "byte"
56 , "ullong": "ulong"
57 , "uint8": "byte"
58 , "uint16": "ushort"
59 , "uint32": "uint"
60 , "uint64": "ulong"
61 , "size": "ulong"
62 , "ptrdiff": "long"
63 , "intptr": "System.IntPtr"
64 , "uintptr": "System.IntPtr"
65 , "void_ptr": "System.IntPtr"
66 , "void": "System.intPtr" #only if is out/inout
67 , "Error": "eina.Error"
68 , "string": "System.String"
69 , "mstring": "System.String"
70 , "stringshare": "System.String"
71 , "any_value": "eina.Value"
72 , "any_value_ptr": "eina.Value"
73 })
74
75def type_convert(eotype):
76 return dicttypes.get(eotype.name, eotype.name)
77
44""" 78"""
45It will find methods and functions with owned return and without other params 79It will find methods and functions with owned return and without other params
46""" 80"""
@@ -75,6 +109,7 @@ class Template(pyratemp.Template):
75 # Build the context for the template 109 # Build the context for the template
76 ctx = {} 110 ctx = {}
77 ctx['suite'] = suite 111 ctx['suite'] = suite
112 ctx['type_convert'] = type_convert
78 113
79 # render with the augmented context 114 # render with the augmented context
80 output = self(**ctx) 115 output = self(**ctx)
@@ -97,6 +132,12 @@ class SuiteCase():
97 self.ext = os.path.splitext(filename)[1] 132 self.ext = os.path.splitext(filename)[1]
98 self.template = os.path.join(script_path, "testgenerator_suite{}.template".format(self.ext)) 133 self.template = os.path.join(script_path, "testgenerator_suite{}.template".format(self.ext))
99 self.clslist = [] 134 self.clslist = []
135 self.verbs = ["add", "get", "is", "del", "thaw", "freeze", "save", "wait", "eject", "raise", "lower", "load",
136 "dup", "reset", "unload", "close", "set", "interpolate", "has", "grab", "check", "find", "ungrab",
137 "unset", "clear", "pop", "new", "peek", "push", "update", "show", "move", "hide", "calculate",
138 "resize", "attach", "pack", "unpack", "emit", "call", "append"]
139 if self.ext == '.cs':
140 cs_types()
100 141
101 def __del__(self): 142 def __del__(self):
102 for cls in self.clslist: 143 for cls in self.clslist:
@@ -131,25 +172,31 @@ class SuiteCase():
131 cls.custom += load_file(os.path.join(filedir, func.name, "custom{}".format(self.ext))) or '' 172 cls.custom += load_file(os.path.join(filedir, func.name, "custom{}".format(self.ext))) or ''
132 func.init = load_file(os.path.join(filedir, func.name, "init{}".format(self.ext))) 173 func.init = load_file(os.path.join(filedir, func.name, "init{}".format(self.ext)))
133 func.shutdown = load_file(os.path.join(filedir, func.name, "shutdown{}".format(self.ext))) 174 func.shutdown = load_file(os.path.join(filedir, func.name, "shutdown{}".format(self.ext)))
134 func.arg_init = load_file(os.path.join(filedir, func.name, "arg_init{}".format(self.ext))) or "/* Zero/NULL args initialized */" 175 func.arg_init = load_file(os.path.join(filedir, func.name, "arg_init{}".format(self.ext))) or ''
135 func.arg_shutdown = load_file(os.path.join(filedir, func.name, "arg_shutdown{}".format(self.ext))) or '' 176 func.arg_shutdown = load_file(os.path.join(filedir, func.name, "arg_shutdown{}".format(self.ext))) or ''
136 177
137 cls.plist = [ p for p in cls.properties if p.getter_scope == p.getter_scope.PUBLIC or p.setter_scope == p.setter_scope.PUBLIC ] 178 cls.plist = [ p for p in cls.properties if p.getter_scope == p.getter_scope.PUBLIC or p.setter_scope == p.setter_scope.PUBLIC ]
138 for func in cls.plist: 179 for func in cls.plist:
139 if func.getter_scope == func.getter_scope.PUBLIC: 180 if func.getter_scope == func.getter_scope.PUBLIC:
140 cls.custom += load_file(os.path.join(filedir, '{}_get'.format(func.name), "custom{}".format(self.ext))) or "" 181 cls.custom += load_file(os.path.join(filedir, '{}_get'.format(func.name), "custom{}".format(self.ext))) or ''
141 func.get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "init{}".format(self.ext))) 182 func.get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "init{}".format(self.ext)))
142 func.get_shutdown = load_file(os.path.join(filedir, '{}_get'.format(func.name), "shutdown{}".format(self.ext))) 183 func.get_shutdown = load_file(os.path.join(filedir, '{}_get'.format(func.name), "shutdown{}".format(self.ext))) or ''
143 func.arg_get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "arg_init{}".format(self.ext))) or "/* Zero/NULL args initialized */" 184 func.arg_get_init = load_file(os.path.join(filedir, '{}_get'.format(func.name), "arg_init{}".format(self.ext))) or ''
144 func.arg_get_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown{}".format(self.ext))) or '' 185 func.arg_get_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown{}".format(self.ext))) or ''
145 186
146 if func.setter_scope == func.setter_scope.PUBLIC: 187 if func.setter_scope == func.setter_scope.PUBLIC:
147 cls.custom += load_file(os.path.join(filedir, '{}_set'.format(func.name), "custom{}".format(self.ext))) or "" 188 cls.custom += load_file(os.path.join(filedir, '{}_set'.format(func.name), "custom{}".format(self.ext))) or ''
148 func.set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "init{}".format(self.ext))) 189 func.set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "init{}".format(self.ext)))
149 func.set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "shutdown{}".format(self.ext))) 190 func.set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "shutdown{}".format(self.ext))) or ''
150 func.arg_set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_init{}".format(self.ext))) or "/* Zero/NULL args initialized */" 191 func.arg_set_init = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_init{}".format(self.ext))) or ''
151 func.arg_set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown{}".format(self.ext))) or '' 192 func.arg_set_shutdown = load_file(os.path.join(filedir, '{}_set'.format(func.name), "arg_shutdown{}".format(self.ext))) or ''
152 193
194 if self.ext == ".cs":
195 for func in itertools.chain(cls.mlist, cls.plist):
196 names = func.name.split('_')
197 if names[-1] in self.verbs:
198 names.insert(0, names.pop())
199 func.csname = ''.join([ name.capitalize() for name in names ])
153 200
154if __name__ == '__main__': 201if __name__ == '__main__':
155 import argparse 202 import argparse
diff --git a/src/scripts/pyolian/testgenerator_suite.cs.template b/src/scripts/pyolian/testgenerator_suite.cs.template
index 81214a7797..12ff935c19 100644
--- a/src/scripts/pyolian/testgenerator_suite.cs.template
+++ b/src/scripts/pyolian/testgenerator_suite.cs.template
@@ -1,52 +1,122 @@
1<!--(macro newconcrete)-->${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$ obj = new ${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$Concrete();<!--(end)--> 1<!--(macro def_obj)-->${'.'.join(param.type.namespaces).lower()}$.${param.type.short_name}$ arg_${param.name}$;<!--(end)-->
2<!--(macro def_param)-->
3 <!--(if param.type.type == param.type.type.CLASS)-->${def_obj(param=param)}$<!--(else)-->${type_convert(param.type)}$ arg_${param.name}$;<!--(end)-->
4<!--(end)-->
5<!--(macro def_params)-->
6 <!--(for p in parameters)-->
7 ${def_param(param=p)}$
8 <!--(end)-->
9<!--(end)-->
2using System; 10using System;
3 11
4namespace TestSuite 12namespace TestSuite
5{ 13{
6<!--(for cls in suite.clslist)--> 14<!--(if suite.custom)-->
15${suite.custom}$
7 16
17<!--(end)-->
18<!--(for cls in suite.clslist)-->
8/**************** TEST CASE ${cls.c_name}$ ****************/ 19/**************** TEST CASE ${cls.c_name}$ ****************/
9class Test${cls.name.replace('.','')}$ 20class Test${cls.name.replace('.','')}$
10{ 21{
11 <!--(if cls.init or suite.init)--> 22
23 ${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$ obj;
24 <!--(if cls.custom)-->
25${cls.custom}$
26 <!--(end)-->
27
12 public static void SetUp() 28 public static void SetUp()
13 { 29 {
30 <!--(if suite.init)-->
14${suite.init}$ 31${suite.init}$
32 <!--(end)-->
33 <!--(if cls.init)-->
15${cls.init}$ 34${cls.init}$
16 } 35 <!--(else)-->
36 obj = new ${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$Concrete();
17 <!--(end)--> 37 <!--(end)-->
18 <!--(if cls.shutdown or suite.shutdown)--> 38 }
39
19 public static void TearDown() 40 public static void TearDown()
20 { 41 {
42 <!--(if suite.shutdown)-->
21${suite.shutdown}$ 43${suite.shutdown}$
44 <!--(end)-->
45 <!--(if cls.shutdown)-->
22${cls.shutdown}$ 46${cls.shutdown}$
23 } 47 <!--(else)-->
48 obj.Dispose()
49 obj = null;
24 <!--(end)--> 50 <!--(end)-->
51 }
25 52
26 public static void smoke() 53 public static void smoke()
27 { 54 {
28 ${newconcrete}$
29 } 55 }
30 56
57#! METHODS
31 <!--(for func in cls.mlist)--> 58 <!--(for func in cls.mlist)-->
32 public static void ${func.name}$() 59 public static void ${func.name}$()
33 { 60 {
34 ${newconcrete}$ 61 <!--(if len(list(func.parameters)) > 0)-->
62${def_params(parameters=func.parameters)}$
63 <!--(end)-->
64 <!--(if func.init or func.arg_init)-->
65${func.arg_init}$
66${func.init}$
67 <!--(end)-->
68 <!--(if func.method_return_type)-->var r = <!--(end)-->obj.${func.csname}$(${', '.join(['arg_{}'.format(param.name) for param in func.parameters])}$);
69 <!--(if func.arg_shutdown or func.shutdown)-->
70${func.arg_shutdown}$
71${func.shutdown}$
72 <!--(end)-->
35 } 73 }
36 74
37 <!--(end)--> 75 <!--(end)-->
76#! PROPERTIES FUNCTION GET
38 <!--(for func in cls.plist)--> 77 <!--(for func in cls.plist)-->
39 <!--(if func.getter_scope == func.getter_scope.PUBLIC)--> 78 <!--(if func.getter_scope == func.getter_scope.PUBLIC)-->
40 public static void get_${func.name}$() 79 public static void ${func.name}$_pget()
41 { 80 {
42 ${newconcrete}$ 81 <!--(if len(list(func.getter_values)) > 1)-->
82${def_params(parameters=func.getter_values)}$
83 <!--(end)-->
84 <!--(if len(list(func.getter_keys)) > 0)-->
85${def_params(parameters=func.getter_keys)}$
86 <!--(end)-->
87 <!--(if func.get_init or func.arg_get_init)-->
88${func.arg_get_init}$
89${func.get_init}$
90 <!--(end)-->
91 <!--(if len(list(func.getter_values)) == 1)-->
92 var arg_${list(func.getter_values)[0].name}$ = obj.Get${func.csname}$(${', '.join(['arg_{}'.format(param.name) for param in func.getter_keys])}$);
93 <!--(else)-->
94 obj.Get${func.csname}$(${', '.join(['&arg_{}'.format(p.name) for p in func.getter_values])}$${''.join([', arg_{}'.format(p.name) for p in func.getter_keys])}$);
95 <!--(end)-->
96 <!--(if func.arg_get_shutdown or func.get_shutdown)-->
97${func.arg_get_shutdown}$
98${func.get_shutdown}$
99 <!--(end)-->
43 } 100 }
44 101
45 <!--(end)--> 102 <!--(end)-->
103#! PROPERTIES FUNCTION SET
46 <!--(if func.setter_scope == func.setter_scope.PUBLIC)--> 104 <!--(if func.setter_scope == func.setter_scope.PUBLIC)-->
47 public static void set_${func.name}$() 105 public static void ${func.name}$_pset()
48 { 106 {
49 ${newconcrete}$ 107${def_params(parameters=func.setter_values)}$
108 <!--(if len(list(func.setter_keys)) > 0)-->
109${def_params(parameters=func.setter_keys)}$
110 <!--(end)-->
111 <!--(if func.set_init or func.arg_set_init)-->
112${func.arg_set_init}$
113${func.set_init}$
114 <!--(end)-->
115 obj.Set${func.csname}$(${', '.join(['arg_{}'.format(p.name) for p in func.setter_values])}$${''.join([', arg_{}'.format(p.name) for p in func.setter_keys])}$);
116 <!--(if func.arg_set_shutdown or func.set_shutdown)-->
117${func.arg_set_shutdown}$
118${func.set_shutdown}$
119 <!--(end)-->
50 } 120 }
51 121
52 <!--(end)--> 122 <!--(end)-->