aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2018-09-05 20:47:30 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2018-09-05 20:47:30 -0300
commit0ea64a3547f59b803d8d3365a27b282912eca749 (patch)
tree259de3e040688de0dedaa0fe13b83f218ae0b596
parenteolian: automated Test Generator [WIP] (diff)
downloadefl-0ea64a3547f59b803d8d3365a27b282912eca749.tar.gz
testgen: Fix compilation of generated csharp code
- Added macro meth_target to select between static and instance methods. - Removed deprecated ConcreteSuffix. - Use interface name inside container types to fix parameter assignment. - Some pylint improvements
-rw-r--r--src/scripts/testgen/ekeys.py36
-rwxr-xr-xsrc/scripts/testgen/testgen.py1
-rw-r--r--src/scripts/testgen/testgenerator.cs.template17
3 files changed, 26 insertions, 28 deletions
diff --git a/src/scripts/testgen/ekeys.py b/src/scripts/testgen/ekeys.py
index 20f633e159..1186e09d87 100644
--- a/src/scripts/testgen/ekeys.py
+++ b/src/scripts/testgen/ekeys.py
@@ -159,7 +159,7 @@ class EMonoKeys(EKeys):
]
def escape_keyword(self, key):
- return key in self.keywords and "kw_{}".format(key) or key
+ return "kw_{}".format(key) if key in self.keywords else key
def direction_get(self, name):
if name == "INOUT":
@@ -168,22 +168,23 @@ class EMonoKeys(EKeys):
return "out "
return None
- def klass_name(self, eo_name):
- names = eo_name.split(".")
- namespaces = [self.escape_keyword(x.lower()) for x in names[:-1]]
- k_name = names[-1]
+ def klass_name(self, eotype):
+ *namespaces, name = eotype.name.split(".")
+ namespaces = [self.escape_keyword(x.lower()) for x in namespaces]
+ is_interface = eotype.type == eotype.type.CLASS
+ k_name = ('I' if is_interface else '') + name
return ".".join(namespaces + [k_name])
def type_convert(self, eotype):
if eotype.type == eotype.type.VOID:
return "System.IntPtr"
- new_type = self.dicttypes.get(eotype.name, self.klass_name(eotype.name))
+ new_type = self.dicttypes.get(eotype.name, self.klass_name(eotype))
if new_type != "int" and eotype.base_type:
new_type = "{}<{}>".format(
new_type,
self.dicttypes.get(
- eotype.base_type.name, self.klass_name(eotype.base_type.name)
+ eotype.base_type.name, self.klass_name(eotype.base_type)
),
)
@@ -193,25 +194,20 @@ class EMonoKeys(EKeys):
r = super().print_arg(eoarg)
prefix = self.direction_get(eoarg.direction.name) or None
- if prefix == "out" and (
- eoarg.type.name == "Eina.Slice" or eoarg.type.name == "Eina.Rw_Slice"
- ):
+ if prefix == "out" and (eoarg.type.name in ("Eina.Slice", "Eina.Rw_Slice")):
prefix = "ref"
- if (
- not prefix
- and eoarg.type.is_ptr
- and eoarg.type.type == eoarg.type.type.REGULAR
- and eoarg.type.typedecl
- and eoarg.type.typedecl.type == eoarg.type.typedecl.type.STRUCT
- ):
+ if (not prefix
+ and eoarg.type.is_ptr
+ and eoarg.type.type == eoarg.type.type.REGULAR
+ and eoarg.type.typedecl
+ and eoarg.type.typedecl.type == eoarg.type.typedecl.type.STRUCT):
prefix = "ref"
- return prefix and " ".join([prefix, r]) or r
+ return " ".join([prefix, r]) if prefix else r
def GetKey(ext):
if ext == ".cs":
return EMonoKeys(ext)
- else:
- return EKeys(ext)
+ return EKeys(ext)
diff --git a/src/scripts/testgen/testgen.py b/src/scripts/testgen/testgen.py
index 007342bc99..6a2b769d47 100755
--- a/src/scripts/testgen/testgen.py
+++ b/src/scripts/testgen/testgen.py
@@ -4,7 +4,6 @@
import os
import sys
import datetime
-from copy import copy
script_path = os.path.dirname(os.path.realpath(__file__))
diff --git a/src/scripts/testgen/testgenerator.cs.template b/src/scripts/testgen/testgenerator.cs.template
index e54f09c257..ea65e10a4f 100644
--- a/src/scripts/testgen/testgenerator.cs.template
+++ b/src/scripts/testgen/testgenerator.cs.template
@@ -3,7 +3,7 @@
${mshow}$#!
<!--(end)-->
<!--(end)-->
-<!--(macro def_obj)-->${'.'.join(param.type.namespaces).lower()}$.${param.type.short_name}$ arg_${param.name}$ = null;<!--(end)-->
+<!--(macro def_obj)-->${'.'.join(param.type.namespaces).lower()}$.I${param.type.short_name}$ arg_${param.name}$ = null;<!--(end)-->
<!--(macro def_param)-->
<!--(if param.type.type == param.type.type.CLASS)-->${def_obj(param=param)}$<!--(else)-->${suite.type_convert(param.type)}$ arg_${param.name}$ = default(${suite.type_convert(param.type)}$);<!--(end)-->
<!--(end)-->
@@ -12,6 +12,9 @@ ${mshow}$#!
${def_param(param=p)}$
<!--(end)-->
<!--(end)-->
+<!--(macro meth_target)-->
+ <!--(if func.is_class)-->${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$<!--(else)-->obj<!--(end)-->
+<!--(end)-->
using System;
namespace TestSuite
@@ -22,7 +25,7 @@ namespace TestSuite
class Test${cls.name.replace('.','')}$
{
- ${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$ obj;
+ ${'.'.join(cls.namespaces).lower()}$.I${cls.short_name}$ obj;
${m_show(mshow=cls.custom)}$#!
public void SetUp()
@@ -31,7 +34,7 @@ ${m_show(mshow=suite.init)}$#!
<!--(if cls.init)-->
${cls.init}$
<!--(else)-->
- obj = new ${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$Concrete();
+ obj = new ${'.'.join(cls.namespaces).lower()}$.${cls.short_name}$();
<!--(end)-->
}
@@ -59,7 +62,7 @@ ${def_params(parameters=func.parameters)}$
<!--(end)-->
${m_show(mshow=func.arg_init)}$#!
${m_show(mshow=func.init)}$#!
- <!--(if func.method_return_type)-->var r = <!--(end)-->obj.${func.format_name}$(${', '.join([ suite.print_arg(p) for p in func.parameters])}$);
+ <!--(if func.method_return_type)-->var r = <!--(end)-->${meth_target(func=func, cls=cls)}$.${func.format_name}$(${', '.join([ suite.print_arg(p) for p in func.parameters])}$);
${m_show(mshow=func.arg_shutdown)}$#!
${m_show(mshow=func.shutdown)}$#!
}
@@ -79,9 +82,9 @@ ${def_params(parameters=func.getter_keys)}$
${m_show(mshow=func.arg_get_init)}$#!
${m_show(mshow=func.get_init)}$#!
<!--(if len(list(func.getter_values)) == 1)-->
- var arg_${list(func.getter_values)[0].name}$ = obj.Get${func.format_name}$(${', '.join(['arg_{}'.format(param.name) for param in func.getter_keys])}$);
+ var arg_${list(func.getter_values)[0].name}$ = ${meth_target(func=func, cls=cls)}$.Get${func.format_name}$(${', '.join(['arg_{}'.format(param.name) for param in func.getter_keys])}$);
<!--(else)-->
- obj.Get${func.format_name}$(${', '.join([suite.print_arg(p) for p in func.getter_keys] + ['out arg_{}'.format(p.name) for p in func.getter_values])}$);
+ ${meth_target(func=func, cls=cls)}$.Get${func.format_name}$(${', '.join([suite.print_arg(p) for p in func.getter_keys] + ['out arg_{}'.format(p.name) for p in func.getter_values])}$);
<!--(end)-->
${m_show(mshow=func.arg_get_shutdown)}$#!
${m_show(mshow=func.get_shutdown)}$#!
@@ -98,7 +101,7 @@ ${def_params(parameters=func.setter_keys)}$
<!--(end)-->
${m_show(mshow=func.arg_set_init)}$#!
${m_show(mshow=func.set_init)}$#!
- obj.Set${func.format_name}$(${', '.join([suite.print_arg(p) for p in list(func.setter_keys) + list(func.setter_values)])}$);
+ ${meth_target(func=func, cls=cls)}$.Set${func.format_name}$(${', '.join([suite.print_arg(p) for p in list(func.setter_keys) + list(func.setter_values)])}$);
${m_show(mshow=func.arg_set_shutdown)}$#!
${m_show(mshow=func.set_shutdown)}$#!
}