Browse Source

Added test for the model constructor

Yentl Van Tendeloo 9 years ago
parent
commit
176b45bb2e

+ 39 - 0
integration/test_constructors_models_compiled.py

@@ -0,0 +1,39 @@
+import unittest
+import sys
+import os
+
+from utils import execute, kill, run_file, run_barebone
+sys.path.append("interface/HUTN")
+from hutn_compiler.compiler import main as do_compile
+
+def model_compile(filename):
+    return do_compile(filename, "interface/HUTN/grammars/modelling.g", "M")
+
+def conformance_call(operation, model, metamodel):
+    return [
+            '"output"',
+                '"call"',
+                    '"access"', '"resolve"', '"%s"' % operation,
+                    '3',
+                    '"call"', '"access"', '"resolve"', '"import_node"', '1', '"const"', '"models/example_M"', 'false',
+                    '"const"', '"%s"' % model,
+                    '"const"', '"%s"' % metamodel,
+                'false',
+            'true',
+            ]
+
+def conformance_check(node):
+    return [
+            '"output"',
+                '"call"',
+                    '"access"', '"resolve"', '"conformance_scd"',
+                    '1',
+                    '"call"', '"access"', '"resolve"', '"import_node"', '1', '"const"', '"%s"' % (node), 'false',
+                    'false',
+                'true',
+            ]
+
+class TestConstructorsModelsCompiled(unittest.TestCase):
+    def test_constructors_petrinets(self):
+        commands = model_compile("interface/HUTN/test/modelling_language/code/petrinets.mvc") + conformance_check("models/PetriNets") + ['"return"', 'false']
+        self.assertTrue(run_barebone(commands, ["OK"], 1))

+ 4 - 2
interface/HUTN/hutn_compiler/model_visitor.py

@@ -26,8 +26,10 @@ class ModelVisitor(Visitor):
             raise AttributeError()
 
     def visit_start(self, tree):
+        self.constructors.append('"model"')
         for t in tree.get_tail():
             self.visit(t)
+        self.constructors.append('"exit"')
 
     def visit_import(self, tree):
         url = tree.get_children("MV_URL")[0]
@@ -73,8 +75,8 @@ class ModelVisitor(Visitor):
             # is definition
             attr_name = children[0].get_text()
             attr_type = children[1].get_text()
-            self.constructors.extend(['"instantiate_link"', jsonstr("Association"), jsonstr(self.current_element + "_" + attr_name), jsonstr(self.current_element), jsonstr(attr_type)])
-            self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_element + "_" + attr_name), jsonstr("name"), jsonstr(attr_name)])
+            self.constructors.extend(['"instantiate_link"', jsonstr(self.current_model), jsonstr("Association"), jsonstr(self.current_element + "_" + attr_name), jsonstr(self.current_element), jsonstr(attr_type)])
+            self.constructors.extend(['"instantiate_attribute"', jsonstr(self.current_model), jsonstr(self.current_element + "_" + attr_name), jsonstr("name"), jsonstr(attr_name)])
         else:
             # is assign
             attr_name = children[0].get_text()

File diff suppressed because it is too large
+ 1 - 1
interface/HUTN/test/modelling_language/expected/simpleclassdiagrams