multi_conformance.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import sys
  2. sys.path.append("wrappers")
  3. from modelverse import *
  4. init()
  5. login("admin", "admin")
  6. mm = \
  7. """
  8. include "primitives.alh"
  9. SimpleAttribute integer {
  10. constraint = $
  11. String function constraint(value : Element):
  12. if is_physical_int(value):
  13. return "OK"!
  14. else:
  15. return "Expected integer value instead of '" + cast_string(value) + "'"!
  16. $
  17. }
  18. SimpleAttribute string {
  19. constraint = $
  20. String function constraint(value : Element):
  21. if is_physical_string(value):
  22. return "OK"!
  23. else:
  24. return "Expected string value instead of '" + cast_string(value) + "'"!
  25. $
  26. }
  27. Class A {
  28. d : integer
  29. name = "A"
  30. }
  31. Class B {
  32. d : string
  33. name = "B"
  34. }
  35. Class C {
  36. name = "C"
  37. }
  38. Inheritance (C, A) {}
  39. Inheritance (C, B) {}
  40. """
  41. model_string = \
  42. """
  43. C {
  44. d = "a"
  45. }
  46. """
  47. model_integer = \
  48. """
  49. C {
  50. d = 1
  51. }
  52. """
  53. model_add("formalisms/simple_mm", "formalisms/SimpleClassDiagrams", mm)
  54. model_add("models/model_string", "formalisms/simple_mm", model_string)
  55. model_add("models/model_integer", "formalisms/simple_mm", model_integer)
  56. transformation_add_AL({"model": "formalisms/Bottom", "metamodel": "formalisms/SimpleClassDiagrams", "type_mapping": "formalisms/TypeMapping"}, {}, "models/conformance_AToMPM", open("models/Conformance/AToMPM.alc", 'r').read())
  57. transformation_add_AL({"model": "formalisms/Bottom", "metamodel": "formalisms/SimpleClassDiagrams", "type_mapping": "formalisms/TypeMapping"}, {}, "models/conformance_MetaDepth", open("models/Conformance/MetaDepth.alc", 'r').read())
  58. print("Checking conformance of model with Integer in AToMPM semantics:")
  59. print(transformation_execute_AL("models/conformance_AToMPM", {"model": "models/model_integer", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_integer").pop()[1]}, {}))
  60. print("Checking conformance of model with String in AToMPM semantics:")
  61. print(transformation_execute_AL("models/conformance_AToMPM", {"model": "models/model_string", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_string").pop()[1]}, {}))
  62. print("Checking conformance of model with Integer in MetaDepth semantics:")
  63. print(transformation_execute_AL("models/conformance_MetaDepth", {"model": "models/model_integer", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_integer").pop()[1]}, {}))
  64. print("Checking conformance of model with String in MetaDepth semantics:")
  65. print(transformation_execute_AL("models/conformance_MetaDepth", {"model": "models/model_string", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_string").pop()[1]}, {}))