araz45661

first 6 tests formatted message

Oct 27th, 2025
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 19.03 KB | None | 0 0
  1. """
  2. Test Message
  3. TestPlan: Message VERSION X
  4. """
  5. from itertools import product
  6.  
  7. from tests_rpl.rpltests.expressions import expression_testing
  8. from tests_rpl.rpltests.rpl_cases import RplCaseProgram, check_success_cases
  9. from tests_rpl.rpltests.rpl_testing import (
  10.     RplTestProgram,
  11.     check_compile_issues,
  12.     IssueCode,
  13. )
  14.  
  15.  
  16. class TestMessageDeclaration:
  17.     """Validates message declaration right behavior for correct and incorrect cases."""
  18.  
  19.     success_case_programs = []
  20.  
  21.     def collect_cases_a_1_declared_matched_name_matched_type(self):
  22.         # Requirement: RPL-MSG-D01
  23.         """
  24.        Verifies that messages declared in the Messages module can be correctly sent and received
  25.        when both the message name and data type matches.
  26.        """
  27.         for idx, (t, v) in enumerate(
  28.             expression_testing.ALL_TYPES_VALUES_EXAMPLES.items(), start=1
  29.         ):
  30.             common_program = RplCaseProgram(
  31.                 additional_sources=[
  32.                     "actor EmptyActor;",
  33.                     f"""\
  34.                    module Messages;
  35.                    import EmptyActor;
  36.  
  37.                    {expression_testing.ENUM_TYPE_ALIAS}
  38.                    message SendMessage_a_{idx} contains {t};
  39.                    message SendMessage_b_{idx} contains {{}};
  40.                    message SendMessage_c_{idx} contains {t};
  41.  
  42.                    message WaitMessage_b_{idx} contains {t};
  43.                    message WaitMessage_c_{idx} contains {t};
  44.                    """,
  45.                     f"""\
  46.                    actor MyActor;
  47.                    import EmptyActor;
  48.                    import Messages;
  49.  
  50.                    {expression_testing.ENUM_TYPE_ALIAS}
  51.                    {expression_testing.EMPTY_ACTOR_VARIABLES}
  52.                    on SendMessage_a_{idx}(s, d) {{}}
  53.                    on SendMessage_b_{idx}(s, d) {{send WaitMessage_b_{idx}({v}) >> s;}}
  54.                    on SendMessage_c_{idx}(s, d) {{send WaitMessage_c_{idx}(d) >> s;}}
  55.                    """,
  56.                 ],
  57.                 test_actor_imports="""\
  58.                import EmptyActor;
  59.                import Messages;
  60.                import MyActor;
  61.                """,
  62.                 defs_block=f"""\
  63.                var myactor = create MyActor();
  64.                {expression_testing.ENUM_TYPE_ALIAS}
  65.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  66.                """,
  67.                 main_body=f"""\
  68.                send SendMessage_a_{idx}({v}) >> myactor;
  69.  
  70.                send SendMessage_b_{idx} >> myactor;
  71.                var result_b_{idx} = wait WaitMessage_b_{idx} << myactor;
  72.  
  73.                send SendMessage_c_{idx}({v}) >> myactor;
  74.                var result_c_{idx} = wait WaitMessage_c_{idx} << myactor;
  75.  
  76.                Testing.complete();
  77.                """,
  78.             )
  79.  
  80.             self.success_case_programs.append(common_program)
  81.  
  82.     def test_a_2_undeclared_matched_name_matched_type(self):
  83.         # Requirement: RPL-MSG-D01
  84.         """
  85.        Verifies that attempting to send or receive a message that was never declared,
  86.        even if the name and data type matches leads to CTE E_Undefined.
  87.        """
  88.         for _, v in expression_testing.ALL_TYPES_VALUES_EXAMPLES.items():
  89.             program_a = RplTestProgram(
  90.                 additional_sources=[
  91.                     "actor EmptyActor;",
  92.                     "module Messages;",
  93.                     """
  94.                    actor MyActor;
  95.                    import Messages;
  96.                    on SendMessage(s, d) {}
  97.                    """,
  98.                 ],
  99.                 test_actor_imports="""\
  100.                import EmptyActor;
  101.                import Messages;
  102.                import MyActor;
  103.                """,
  104.                 test_actor_contents=f"""\
  105.                var myactor = create MyActor();
  106.                {expression_testing.ENUM_TYPE_ALIAS}
  107.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  108.                """,
  109.                 main_body=f"""\
  110.                send SendMessage({v}) >> myactor;
  111.                """,
  112.             )
  113.             check_compile_issues(program_a, IssueCode.E_Undefined)
  114.  
  115.             program_b = RplTestProgram(
  116.                 additional_sources=[
  117.                     "actor EmptyActor;",
  118.                     "module Messages;",
  119.                     f"""\
  120.                    actor MyActor;
  121.                    import Messages;
  122.                    import EmptyActor;
  123.                    {expression_testing.ENUM_TYPE_ALIAS}
  124.                    {expression_testing.EMPTY_ACTOR_VARIABLES}
  125.                    on SendMessage(s, d) {{
  126.                        send WaitMessage({v}) >> s;
  127.                    }}
  128.                    """,
  129.                 ],
  130.                 test_actor_imports="""\
  131.                import EmptyActor;
  132.                import Messages;
  133.                import MyActor;
  134.                """,
  135.                 test_actor_contents=f"""\
  136.                var myactor = create MyActor();
  137.                {expression_testing.ENUM_TYPE_ALIAS}
  138.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  139.                """,
  140.                 main_body="""\
  141.                send SendMessage >> myactor;
  142.                var result = wait WaitMessage << myactor;
  143.                """,
  144.             )
  145.             check_compile_issues(program_b, IssueCode.E_Undefined)
  146.  
  147.             program_c = RplTestProgram(
  148.                 additional_sources=[
  149.                     "actor EmptyActor;",
  150.                     "module Messages;",
  151.                     """
  152.                    actor MyActor;
  153.                    import Messages;
  154.                    on SendMessage(s, d) {
  155.                        send WaitMessage(d) >> s;
  156.                    }
  157.                    """,
  158.                 ],
  159.                 test_actor_imports="""\
  160.                import EmptyActor;
  161.                import Messages;
  162.                import MyActor;
  163.                """,
  164.                 test_actor_contents=f"""\
  165.                var myactor = create MyActor();
  166.                {expression_testing.ENUM_TYPE_ALIAS}
  167.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  168.                """,
  169.                 main_body=f"""\
  170.                send SendMessage({v}) >> myactor;
  171.                var result = wait WaitMessage << myactor;
  172.                """,
  173.             )
  174.             check_compile_issues(program_c, IssueCode.E_Undefined)
  175.  
  176.     def test_a_3_declared_undeclared_matched_name_matched_type(self):
  177.         # Requirement: RPL-MSG-D01
  178.         """
  179.        Verifies that if one of the messages for send or wait is undeclared while the other one is declared
  180.        with a matching name and type it leads to CTE E_Undefined.
  181.        """
  182.         for t, v in expression_testing.ALL_TYPES_VALUES_EXAMPLES.items():
  183.             program_a = RplTestProgram(
  184.                 additional_sources=[
  185.                     "actor EmptyActor;",
  186.                     f"""\
  187.                    module Messages;
  188.                    import EmptyActor;
  189.                    {expression_testing.ENUM_TYPE_ALIAS}
  190.                    message WaitMessage contains {t};
  191.                    """,
  192.                     """
  193.                    actor MyActor;
  194.                    import Messages;
  195.                    on SendMessage(s, d) {
  196.                        send WaitMessage(d) >> s;
  197.                    }
  198.                    """,
  199.                 ],
  200.                 test_actor_imports="""\
  201.                import EmptyActor;
  202.                import Messages;
  203.                import MyActor;
  204.                """,
  205.                 test_actor_contents=f"""\
  206.                var myactor = create MyActor();
  207.                {expression_testing.ENUM_TYPE_ALIAS}
  208.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  209.                """,
  210.                 main_body=f"""\
  211.                send SendMessage({v}) >> myactor;
  212.                var result = wait WaitMessage << myactor;
  213.                """,
  214.             )
  215.             check_compile_issues(program_a, IssueCode.E_Undefined)
  216.  
  217.             program_b = RplTestProgram(
  218.                 additional_sources=[
  219.                     "actor EmptyActor;",
  220.                     f"""\
  221.                    module Messages;
  222.                    import EmptyActor;
  223.                    {expression_testing.ENUM_TYPE_ALIAS}
  224.                    message SendMessage contains {t};
  225.                    """,
  226.                     """
  227.                    actor MyActor;
  228.                    import Messages;
  229.                    on SendMessage(s, d) {
  230.                        send WaitMessage(d) >> s;
  231.                    }
  232.                    """,
  233.                 ],
  234.                 test_actor_imports="""\
  235.                import EmptyActor;
  236.                import Messages;
  237.                import MyActor;
  238.                """,
  239.                 test_actor_contents=f"""\
  240.                var myactor = create MyActor();
  241.                {expression_testing.ENUM_TYPE_ALIAS}
  242.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  243.                """,
  244.                 main_body=f"""\
  245.                send SendMessage({v}) >> myactor;
  246.                var result = wait WaitMessage << myactor;
  247.                """,
  248.             )
  249.             check_compile_issues(program_b, IssueCode.E_Undefined)
  250.  
  251.     def test_a_4_declared_unmatched_name_matched_type(self):
  252.         # Requirement: RPL-MSG-D01
  253.         """
  254.        Verifies that if a message name used in send or wait does not match
  255.        the declared name, even if the data type matches it leads to CTE E_Undefined.
  256.        """
  257.         for t, v in expression_testing.ALL_TYPES_VALUES_EXAMPLES.items():
  258.             program_a = RplTestProgram(
  259.                 additional_sources=[
  260.                     "actor EmptyActor;",
  261.                     f"""\
  262.                    module Messages;
  263.                    import EmptyActor;
  264.                    {expression_testing.ENUM_TYPE_ALIAS}
  265.                    message SendMessage contains {t};
  266.                    """,
  267.                     """
  268.                    actor MyActor;
  269.                    import Messages;
  270.                    on SendMessage(s, d) {}
  271.                    """,
  272.                 ],
  273.                 test_actor_imports="""\
  274.                import EmptyActor;
  275.                import Messages;
  276.                import MyActor;
  277.                """,
  278.                 test_actor_contents=f"""\
  279.                var myactor = create MyActor();
  280.                {expression_testing.ENUM_TYPE_ALIAS}
  281.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  282.                """,
  283.                 main_body=f"""\
  284.                send SendMessageNew({v}) >> myactor;
  285.                """,
  286.             )
  287.             check_compile_issues(program_a, IssueCode.E_Undefined)
  288.  
  289.             program_b = RplTestProgram(
  290.                 additional_sources=[
  291.                     "actor EmptyActor;",
  292.                     f"""\
  293.                    module Messages;
  294.                    import EmptyActor;
  295.                    {expression_testing.ENUM_TYPE_ALIAS}
  296.                    message SendMessage contains {{}};
  297.                    message WaitMessage contains {t};
  298.                    """,
  299.                     f"""\
  300.                    actor MyActor;
  301.                    import Messages;
  302.                    import EmptyActor;
  303.                    {expression_testing.ENUM_TYPE_ALIAS}
  304.                    {expression_testing.EMPTY_ACTOR_VARIABLES}
  305.                    on SendMessage(s, d) {{
  306.                        send WaitMessage({v}) >> s;
  307.                    }}
  308.                    """,
  309.                 ],
  310.                 test_actor_imports="""\
  311.                import EmptyActor;
  312.                import Messages;
  313.                import MyActor;
  314.                """,
  315.                 test_actor_contents=f"""\
  316.                var myactor = create MyActor();
  317.                {expression_testing.ENUM_TYPE_ALIAS}
  318.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  319.                """,
  320.                 main_body="""\
  321.                send SendMessage >> myactor;
  322.                var result = wait WaitMessageNew << myactor;
  323.                """,
  324.             )
  325.             check_compile_issues(program_b, IssueCode.E_Undefined)
  326.  
  327.     def test_a_5_declared_matched_name_unmatched_type(self):
  328.         # Requirement: RPL-MSG-D01
  329.         """
  330.        Verifies that if a message name matches but the data type differs from the declared type
  331.        it leads to CTE E_TypeCastError.
  332.        """
  333.         for (t2, v2), (t1, _) in product(
  334.             expression_testing.ALL_TYPES_VALUES_EXAMPLES.items(),
  335.             expression_testing.ALL_TYPES_VALUES_EXAMPLES.items(),
  336.         ):
  337.             if (
  338.                 t2 == t1
  339.                 or (t2, t1) in expression_testing.IMPLICITLY_CASTABLE_TYPES_PAIRS
  340.             ):
  341.                 continue
  342.  
  343.             program_a = RplTestProgram(
  344.                 additional_sources=[
  345.                     "actor EmptyActor;",
  346.                     f"""\
  347.                    module Messages;
  348.                    import EmptyActor;
  349.                    {expression_testing.ENUM_TYPE_ALIAS}
  350.                    message SendMessage contains {t1};
  351.                    """,
  352.                     """
  353.                    actor MyActor;
  354.                    import Messages;
  355.                    on SendMessage(s, d) {}
  356.                    """,
  357.                 ],
  358.                 test_actor_imports="""\
  359.                import EmptyActor;
  360.                import Messages;
  361.                import MyActor;
  362.                """,
  363.                 test_actor_contents=f"""\
  364.                var myactor = create MyActor();
  365.                {expression_testing.ENUM_TYPE_ALIAS}
  366.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  367.                """,
  368.                 main_body=f"""\
  369.                send SendMessage({v2}) >> myactor;
  370.                """,
  371.             )
  372.             check_compile_issues(program_a, IssueCode.E_TypeCastError)
  373.  
  374.             program_b = RplTestProgram(
  375.                 additional_sources=[
  376.                     "actor EmptyActor;",
  377.                     f"""\
  378.                    module Messages;
  379.                    import EmptyActor;
  380.                    {expression_testing.ENUM_TYPE_ALIAS}
  381.                    message SendMessage contains {{}};
  382.                    message WaitMessage contains {t1};
  383.                    """,
  384.                     f"""\
  385.                    actor MyActor;
  386.                    import EmptyActor;
  387.                    import Messages;
  388.                    {expression_testing.ENUM_TYPE_ALIAS}
  389.                    {expression_testing.EMPTY_ACTOR_VARIABLES}
  390.                    on SendMessage(s, d) {{
  391.                        send WaitMessage({v2}) >> s;
  392.                    }}
  393.                    """,
  394.                 ],
  395.                 test_actor_imports="""\
  396.                import EmptyActor;
  397.                import Messages;
  398.                import MyActor;
  399.                """,
  400.                 test_actor_contents=f"""\
  401.                var myactor = create MyActor();
  402.                {expression_testing.ENUM_TYPE_ALIAS}
  403.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  404.                """,
  405.                 main_body="""\
  406.                send SendMessage >> myactor;
  407.                var result = wait WaitMessage << myactor;
  408.                """,
  409.             )
  410.             check_compile_issues(program_b, IssueCode.E_TypeCastError)
  411.  
  412.     def test_a_6_declared_unmatched_name_unmatched_type(self):
  413.         # Requirement: RPL-MSG-D01
  414.         """
  415.        Verifies that messages with name and data type differing
  416.        from the declaration one leads to CTE issues:
  417.        - Undefined when a message name does not match
  418.        - TypeCastError when a message type does not match
  419.  
  420.        """
  421.         for (t2, v2), (t1, _) in product(
  422.             expression_testing.ALL_TYPES_VALUES_EXAMPLES.items(),
  423.             expression_testing.ALL_TYPES_VALUES_EXAMPLES.items(),
  424.         ):
  425.             if (
  426.                 t2 == t1
  427.                 or (t2, t1) in expression_testing.IMPLICITLY_CASTABLE_TYPES_PAIRS
  428.             ):
  429.                 continue
  430.  
  431.             program_a = RplTestProgram(
  432.                 additional_sources=[
  433.                     "actor EmptyActor;",
  434.                     f"""\
  435.                    module Messages;
  436.                    import EmptyActor;
  437.                    {expression_testing.ENUM_TYPE_ALIAS}
  438.                    message SendMessage contains {t1};
  439.                    """,
  440.                     """
  441.                    actor MyActor;
  442.                    import Messages;
  443.                    on SendMessage(s, d) {}
  444.                    """,
  445.                 ],
  446.                 test_actor_imports="""\
  447.                import EmptyActor;
  448.                import Messages;
  449.                import MyActor;
  450.                """,
  451.                 test_actor_contents=f"""\
  452.                var myactor = create MyActor();
  453.                {expression_testing.ENUM_TYPE_ALIAS}
  454.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  455.                """,
  456.                 main_body=f"""\
  457.                send SendMessageNew({v2}) >> myactor;
  458.                """,
  459.             )
  460.             check_compile_issues(program_a, IssueCode.E_Undefined)
  461.  
  462.             program_b = RplTestProgram(
  463.                 additional_sources=[
  464.                     "actor EmptyActor;",
  465.                     f"""\
  466.                    module Messages;
  467.                    import EmptyActor;
  468.                    {expression_testing.ENUM_TYPE_ALIAS}
  469.                    message SendMessage contains {{}};
  470.                    message WaitMessage contains {t1};
  471.                    """,
  472.                     f"""\
  473.                    actor MyActor;
  474.                    import EmptyActor;
  475.                    import Messages;
  476.                    {expression_testing.ENUM_TYPE_ALIAS}
  477.                    {expression_testing.EMPTY_ACTOR_VARIABLES}
  478.                    on SendMessage(s, d) {{
  479.                        send WaitMessage({v2}) >> s;
  480.                    }}
  481.                    """,
  482.                 ],
  483.                 test_actor_imports="""\
  484.                import EmptyActor;
  485.                import Messages;
  486.                import MyActor;
  487.                """,
  488.                 test_actor_contents=f"""\
  489.                var myactor = create MyActor();
  490.                {expression_testing.ENUM_TYPE_ALIAS}
  491.                {expression_testing.EMPTY_ACTOR_VARIABLES}
  492.                """,
  493.                 main_body="""\
  494.                send SendMessage >> myactor;
  495.                var result = wait WaitMessageNew << myactor;
  496.                """,
  497.             )
  498.             check_compile_issues(program_b, IssueCode.E_TypeCastError)
  499.  
  500.     def test_success_cases(self):
  501.         """General executor for all success cases."""
  502.         self.collect_cases_a_1_declared_matched_name_matched_type()
  503.         check_success_cases(
  504.             {
  505.                 f"case_{num}": case
  506.                 for num, case in enumerate(self.success_case_programs, start=1)
  507.             }
  508.         )
Advertisement
Add Comment
Please, Sign In to add comment