Ejemplo n.º 1
0
    def __write_test_no_new_transition(self, utest_file_descriptor, prepared_list):

        utest_file_descriptor.write("void test_NoTransistionAdded(void)\n"
                                    "{\n"
                                    "    uint8_t expectedValidTransitionNumber = " + str(len(prepared_list)) + ", actualNumber = 0;\n"
                                    "    " + state_type(self._sm_name) + " tableLine;\n"
                                    "    Transition_t actualTransition;\n\n")

        utest_file_descriptor.write("    for (" + state_enum_type(self._sm_name) + " i = " + self._priv_state_name_list[0] +
                                    "; i < " + sm_state_common(self._sm_name) + "END; i++)\n")

        utest_file_descriptor.write("    {\n"
                                    "        for ( " + condition_enum_type(self._sm_name) + " j = " +
                                    self._priv_condi_name_list[0] + "; j < " +
                                    sm_condition_common(self._sm_name) + "END; j++)\n")
        utest_file_descriptor.write("        {\n"
                                    "            tableLine = " + transition_table_name(self._sm_name) + "[i];\n"
                                    "            actualTransition = tableLine.transition[j];\n"
                                    "            if ( true == actualTransition.isTransitionValid )\n"
                                    "            {\n"
                                    "                actualNumber++;\n"
                                    "            }\n"
                                    "        }\n"
                                    "    }\n"
                                    "\n"
                                    "    TEST_ASSERT_EQUAL(expectedValidTransitionNumber, actualNumber);\n"
                                    "}\n\n")
Ejemplo n.º 2
0
    def __create_table(self, file_descriptor, prepared_list):
        file_descriptor.write("STATIC const " + state_type(self._sm_name) + " " +
                                      transition_table_name(self._sm_name) + "[" +
                                      sm_state_common(self._sm_name) + "END" + "] = {\n")

        non_empty_state_list = []
        for state in self._priv_state_name_list:
            for item in prepared_list:
                if item.from_state in state:
                    # we have something to write for this state
                    non_empty_state_list.append(item)

            if len(non_empty_state_list) != 0:  # if list is not empty
                file_descriptor.write("    [" + state + "] = {\n")
                file_descriptor.write("        .transition = {\n")

                for item in non_empty_state_list:
                    file_descriptor.write("            [" + item.condition + "] = {\n")
                    file_descriptor.write("                .pTransFunc = " + item.action + ",\n")
                    file_descriptor.write("                .nextState = " + item.to_state + ",\n")
                    file_descriptor.write("                .isTransitionValid = true,\n")
                    file_descriptor.write("            },\n")

                file_descriptor.write("        },\n")
                file_descriptor.write("    },\n")

            non_empty_state_list = []

        file_descriptor.write("};\n")
        file_descriptor.write("\n")
Ejemplo n.º 3
0
 def __write_extern(self, utest_file_descriptor):
     for item in self._priv_func_name_list:
         utest_file_descriptor.write("extern void " + item + "( void );\n")
     utest_file_descriptor.write("extern FSM_t* smHandler;\n")
     utest_file_descriptor.write("extern const " + state_type(self._sm_name) + " " +
                                 transition_table_name(self._sm_name) + "[" +
                                 sm_state_common(self._sm_name) + "END" + "];\n")
     utest_file_descriptor.write("\n")
Ejemplo n.º 4
0
 def __create_init_func(self, file_descriptor):
     file_descriptor.write("bool " + init_func_name(self._sm_name) + "(void){\n")
     file_descriptor.write("    smHandler = FSM_New((void*) " + transition_table_name(self._sm_name) + ",\n")
     file_descriptor.write("                        sizeof(" + state_type(self._sm_name) + "),\n")
     file_descriptor.write("                        " + self._priv_state_name_list[0] + ",\n")
     file_descriptor.write("                        " + self._priv_condi_name_list[0] + ",\n")
     file_descriptor.write("                        " + self._priv_state_name_list[0] + ",\n")
     file_descriptor.write("                        " + self._priv_condi_name_list[0] + ");\n")
     file_descriptor.write("    return (smHandler == NULL ) ? false : true;\n}\n")
     file_descriptor.write("\n")
Ejemplo n.º 5
0
 def __write_test_defined_transition(self, utest_file_descriptor, prepared_list):
     for item in prepared_list:
         func_name = "test_Transition_s_" + item.from_state + "_c_" + item.condition
         utest_file_descriptor.write("void " + func_name + "(void)\n")
         utest_file_descriptor.write("{\n"
                                     "    TransitionFunction expectedFunc = " + item.action + ";\n"
                                     "    " + state_enum_type(self._sm_name) + "  expectedNextState = " + item.to_state + ";\n\n")
         utest_file_descriptor.write("    " + state_type(self._sm_name) + " tableLine = " +
                                     transition_table_name(self._sm_name) + "[" + item.from_state + "];\n")
         utest_file_descriptor.write("    Transition_t actualTransition = " +
                                     "tableLine.transition[" + item.condition + "];\n\n")
         utest_file_descriptor.write("    TEST_ASSERT_EQUAL(expectedFunc, actualTransition.pTransFunc);\n"
                                     "    TEST_ASSERT_EQUAL(expectedNextState, actualTransition.nextState);\n"
                                     "    TEST_ASSERT_EQUAL(true, actualTransition.isTransitionValid);\n"
                                     "}\n\n")
Ejemplo n.º 6
0
    def __write_test_table_size(self, utest_file_descriptor):
        condition_end_name = sm_condition_common(self._sm_name) + "END"
        state_end_name = sm_state_common(self._sm_name) + "END"

        utest_file_descriptor.write("void test_LineSizeNotChange(void)\n"
                                    "{\n"
                                    "    uint32_t expectedSize = " + condition_end_name + " * sizeof(Transition_t);\n"
                                    "\n"
                                    "    TEST_ASSERT_EQUAL(expectedSize, sizeof(" + state_type(self._sm_name) + "));\n"
                                    "}\n"
                                    "\n"
                                    "void test_TableSizeNotChange(void)\n"
                                    "{\n"
                                    "    uint32_t expectedSize = " + condition_end_name +
                                    " * sizeof(Transition_t) *" + state_end_name + ";\n"
                                    "\n"
                                    "    TEST_ASSERT_EQUAL(expectedSize, sizeof(" + transition_table_name(self._sm_name) + "));\n"
                                    "}\n\n")