예제 #1
0
    def test_TextFieldName(self):
        """
        generator/transformers/common_producer.py	34%
        generator/transformers/enums_producer.py	98%
        """
        elements = OrderedDict()
        elements['SUCCESS'] = EnumElement(name='SUCCESS')
        elements['mainField1'] = EnumElement(name='mainField1')
        elements['H264'] = EnumElement(name='H264')
        elements['UNSUPPORTED_REQUEST'] = EnumElement(
            name='UNSUPPORTED_REQUEST')
        item = Enum(name='TextFieldName', elements=elements)

        expected = OrderedDict()
        expected['origin'] = 'TextFieldName'
        expected['name'] = 'SDLTextFieldName'
        expected['imports'] = {'.h': {'SDLEnum'}, '.m': {'SDLEnum'}}
        expected['params'] = (self.producer.param_named(description=[],
                                                        name='Success',
                                                        origin='SUCCESS',
                                                        since=None,
                                                        deprecated=False),
                              self.producer.param_named(description=[],
                                                        name='MainField1',
                                                        origin='mainField1',
                                                        since=None,
                                                        deprecated=False),
                              self.producer.param_named(description=[],
                                                        name='H264',
                                                        origin='H264',
                                                        since=None,
                                                        deprecated=False),
                              self.producer.param_named(
                                  description=[],
                                  name='UnsupportedRequest',
                                  origin='UNSUPPORTED_REQUEST',
                                  since=None,
                                  deprecated=False))

        actual = self.producer.transform(item)
        self.assertDictEqual(expected, actual)
예제 #2
0
    def test_PredefinedWindows(self):
        elements = OrderedDict()
        elements['DEFAULT_WINDOW'] = EnumElement(name='DEFAULT_WINDOW', value=0)
        elements['PRIMARY_WIDGET'] = EnumElement(name='PRIMARY_WIDGET', value=1)
        item = Enum(name='PredefinedWindows', elements=elements)
        expected = {
            'kind': 'simple',
            'package_name': 'com.smartdevicelink.proxy.rpc.enums',
            'class_name': 'PredefinedWindows',
            'params': (self.producer.params(name='DEFAULT_WINDOW', origin='DEFAULT_WINDOW',
                                            internal=0, description=None, since=None, value=None,
                                            deprecated=None),
                       self.producer.params(name='PRIMARY_WIDGET', origin='PRIMARY_WIDGET',
                                            internal=1, description=None, since=None, value=None,
                                            deprecated=None)),
            'since': None,
            'history': None,
            'deprecated': None
        }
        actual = self.producer.transform(item)

        self.comparison(expected, actual)
예제 #3
0
    def test_SystemCapabilityType(self):
        elements = OrderedDict()
        elements['DISPLAYS'] = EnumElement(name='DISPLAYS')
        elements['NAVIGATION'] = EnumElement(name='NAVIGATION')

        item = Enum(name='SystemCapabilityType', elements=elements)
        expected = {
            'kind': 'simple',
            'package_name': 'com.smartdevicelink.proxy.rpc.enums',
            'class_name': 'SystemCapabilityType',
            'params': (
                self.producer.params(deprecated=None, value=None, description=None,
                                     name='DISPLAYS', origin='DISPLAYS', since=None, internal=None),
                self.producer.params(deprecated=None, value=None, description=None,
                                     name='NAVIGATION', origin='NAVIGATION', since=None, internal=None)),
            'since': None,
            'history': None,
            'deprecated': None,
        }
        actual = self.producer.transform(item)

        self.comparison(expected, actual)
예제 #4
0
    def test_Dimension(self):
        item = Enum(name='Dimension', elements={
            'NO_FIX': EnumElement(name='NO_FIX', internal_name='Dimension_NO_FIX'),
            '2D': EnumElement(name='2D', internal_name='Dimension_2D')
        })
        expected = {
            'kind': 'custom',
            'package_name': 'com.smartdevicelink.proxy.rpc.enums',
            'class_name': 'Dimension',
            'params': (
                self.producer.params(deprecated=None, value=None, description=None,
                                     name='NO_FIX', origin='NO_FIX', since=None, internal='"NO_FIX"'),
                self.producer.params(deprecated=None, value=None, description=None,
                                     name='_2D', origin='2D', since=None, internal='"2D"'),),
            'since': None,
            'history': None,
            'deprecated': None,
            'imports': {'java.util.EnumSet'}
        }
        actual = self.producer.transform(item)

        self.comparison(expected, actual)
예제 #5
0
    def test_Result(self):
        elements = OrderedDict()
        elements['SUCCESS'] = EnumElement(name='SUCCESS', description=['The request succeeded'])
        elements['VEHICLE_DATA_NOT_AVAILABLE'] = EnumElement(name='VEHICLE_DATA_NOT_AVAILABLE', since='2.0.0')
        item = Enum(name='Result', elements=elements)
        expected = {
            'kind': 'simple',
            'package_name': 'com.smartdevicelink.proxy.rpc.enums',
            'class_name': 'Result',
            'params': (
                self.producer.params(name='SUCCESS', origin='SUCCESS', internal=None,
                                     description=['The request succeeded'],
                                     since=None, value=None, deprecated=None),
                self.producer.params(name='VEHICLE_DATA_NOT_AVAILABLE', origin='VEHICLE_DATA_NOT_AVAILABLE',
                                     internal=None, description=None, since='2.0.0', value=None, deprecated=None)),
            'since': None,
            'history': None,
            'deprecated': None
        }
        actual = self.producer.transform(item)

        self.comparison(expected, actual)
 def test_OnEncodedSyncPDataNotification(self):
     params = OrderedDict()
     params['URL'] = Param(name='URL',
                           param_type=String(),
                           description=['\n                If '])
     item = Function(name='OnEncodedSyncPData',
                     function_id=Enum(name='OnEncodedSyncPDataID'),
                     description=['\n           Callback including \n'],
                     message_type=EnumElement(name='notification'),
                     params=params)
     expected = OrderedDict()
     expected['file_name'] = 'OnEncodedSyncPData'
     expected['name'] = 'OnEncodedSyncPData'
     expected['imports'] = {
         self.producer.imports(what='RpcNotification',
                               wherefrom='../RpcNotification.js'),
         self.producer.imports(what='FunctionID',
                               wherefrom='../enums/FunctionID.js')
     }
     expected['methods'] = (self.producer.methods(key='KEY_URL',
                                                  method_title='URL',
                                                  external=None,
                                                  description=['If'],
                                                  param_name='url',
                                                  type='String',
                                                  param_values={},
                                                  since=None,
                                                  history=None,
                                                  deprecated=None), )
     expected['params'] = (self.producer.params(key='KEY_URL',
                                                value="'URL'"), )
     expected['description'] = ['Callback including']
     expected['since'] = None
     expected['history'] = None
     expected['deprecated'] = None
     expected['func'] = 'OnEncodedSyncPData'
     expected['extend'] = 'RpcNotification'
     result = self.producer.transform(item)
     self.assertDictEqual(expected, result)
 def test_UnregisterAppInterfaceRequest(self):
     item = Function(name='UnregisterAppInterface',
                     function_id=Enum(name='UnregisterAppInterfaceID'),
                     message_type=EnumElement(name='request'),
                     params=OrderedDict())
     expected = OrderedDict()
     expected['file_name'] = 'UnregisterAppInterface'
     expected['name'] = 'UnregisterAppInterface'
     expected['imports'] = {
         self.producer.imports(what='RpcRequest',
                               wherefrom='../RpcRequest.js'),
         self.producer.imports(what='FunctionID',
                               wherefrom='../enums/FunctionID.js')
     }
     expected['methods'] = ()
     expected['params'] = ()
     expected['since'] = None
     expected['history'] = None
     expected['deprecated'] = None
     expected['func'] = 'UnregisterAppInterface'
     expected['extend'] = 'RpcRequest'
     result = self.producer.transform(item)
     self.assertDictEqual(expected, result)
예제 #8
0
 def test_RegisterAppInterfaceResponse(self):
     params = OrderedDict()
     params['language'] = Param(name='language',
                                param_type=Enum(name='Language'))
     params['success'] = Param(name='success', param_type=Boolean())
     item = Function(name='RegisterAppInterface',
                     function_id=None,
                     message_type=EnumElement(name='response'),
                     params=params)
     expected = self.expected_template.copy()
     expected['kind'] = 'response'
     expected['function_id'] = 'REGISTER_APP_INTERFACE'
     expected['class_name'] = 'RegisterAppInterfaceResponse'
     expected['extends_class'] = 'RPCResponse'
     expected['history'] = None
     expected['imports'] = [
         'androidx.annotation.NonNull', '',
         'com.smartdevicelink.protocol.enums.FunctionID',
         'com.smartdevicelink.proxy.RPCResponse',
         'com.smartdevicelink.proxy.rpc.enums.Language',
         'com.smartdevicelink.proxy.rpc.enums.Result', '',
         'java.util.Hashtable'
     ]
     expected['params'] = (self.producer.params(deprecated=None,
                                                key='KEY_LANGUAGE',
                                                last='language',
                                                mandatory=True,
                                                origin='language',
                                                return_type='Language',
                                                since=None,
                                                title='Language',
                                                description=None,
                                                SuppressWarnings=None,
                                                param_doc=None,
                                                name=None), )
     actual = self.producer.transform(item)
     self.comparison(expected, actual)
예제 #9
0
    def test_FunctionID(self):
        """
        generator/transformers/common_producer.py	34%
        generator/transformers/enums_producer.py	80%
        """
        elements = OrderedDict()
        elements['RESERVED'] = EnumElement(name='RESERVED', value=0)
        elements['RegisterAppInterfaceID'] = EnumElement(
            name='RegisterAppInterfaceID', hex_value=1)
        elements['PerformAudioPassThruID'] = EnumElement(
            name='PerformAudioPassThruID', hex_value=10)

        item = Enum(name='FunctionID', elements=elements)
        expected = OrderedDict()
        expected['origin'] = 'FunctionID'
        expected['name'] = 'SDLFunctionID'
        expected['imports'] = {'.h': {'SDLEnum'}, '.m': {'SDLEnum'}}
        expected['params'] = (
            self.producer.param_named(description=[],
                                      name='Reserved',
                                      origin='RESERVED',
                                      since=None,
                                      deprecated=False),
            self.producer.param_named(description=[],
                                      name='RegisterAppInterface',
                                      origin='RegisterAppInterfaceID',
                                      since=None,
                                      deprecated=False),
            self.producer.param_named(description=[],
                                      name='PerformAudioPassThru',
                                      origin='PerformAudioPassThruID',
                                      since=None,
                                      deprecated=False),
        )

        actual = self.producer.transform(item)
        self.assertDictEqual(expected, actual)
예제 #10
0
    def test_ButtonName(self):
        item = Enum(name='ButtonName', elements={'OK': EnumElement(name='OK')})
        expected = {
            'kind':
            'simple',
            'package_name':
            'com.smartdevicelink.proxy.rpc.enums',
            'class_name':
            'ButtonName',
            'params': (self.producer.params(deprecated=None,
                                            value=None,
                                            description=None,
                                            name='OK',
                                            origin='OK',
                                            since=None,
                                            internal=None), ),
            'since':
            None,
            'deprecated':
            None
        }
        actual = self.producer.transform(item)

        self.comparison(expected, actual)
예제 #11
0
    def test_full_generation(self):
        """Test full generation using SDLPRC SmartSchema generator.

        Creates output files which is captured by the mock and compare them
        with sample files with correct code. This test requires valid
        test_expected_sdlrpc.h and test_expected_sdlrpc.cc in the same as
        this module.

        """
        self.maxDiff = None
        expected_h_file_content = Path(__file__).parents[0].joinpath('test_expected_sdlrpc.h').read_text()
        expected_cc_file_content = Path(__file__).parents[0].joinpath('test_expected_sdlrpc.cc').read_text()

        generator = SmartFactorySDLRPC.CodeGenerator()

        message_type_elements = collections.OrderedDict()
        message_type_elements[u"request"] = EnumElement(name=u"request")
        message_type_elements[u"response"] = EnumElement(
            name=u"response")
        message_type_elements[u"notification"] = EnumElement(
            name=u"notification")

        message_type = Enum(name=u"messageType",
                            elements=message_type_elements)

        elements1 = collections.OrderedDict()
        elements1[u"name1"] = EnumElement(
            name=u"name1",
            design_description=DESIGN_DESCRIPTION,
            todos=TODOS,
            value=u"1")
        elements1[u"name2"] = EnumElement(
            name="name2",
            description=DESCRIPTION,
            issues=ISSUES,
            internal_name=u"internal_name2")

        enum1 = Enum(name=u"Enum1",
                     todos=TODOS,
                     elements=elements1)

        elements2 = collections.OrderedDict()
        elements2[u"xxx"] = EnumElement(name=u"xxx",
                                        internal_name=u"val_1")
        elements2[u"yyy"] = EnumElement(name=u"yyy",
                                        internal_name=u"val_2",
                                        value=u"100")
        elements2[u"zzz"] = EnumElement(name=u"val_3")

        enum2 = Enum(name=u"E2",
                     elements=elements2)

        elements3 = collections.OrderedDict()
        elements3["1"] = EnumElement(name="xxx",
                                     internal_name="_1")
        elements3["2"] = EnumElement(name="xxx",
                                     internal_name="_2")
        elements3["3"] = EnumElement(name="xxx",
                                     internal_name="_3")
        enum3 = Enum(name="Enum_new2",
                     elements=elements3)

        elements4 = collections.OrderedDict()
        elements4["name1"] = EnumElement(name="xxx",
                                         internal_name="_11")
        elements4["name2"] = EnumElement(name="xxx",
                                         internal_name="_22")
        enum4 = Enum(name="Enum_new4",
                     elements=elements4)

        enums = collections.OrderedDict()
        enums["Enum1"] = enum1
        enums["Enum2"] = enum2
        enums["Enum3"] = enum3
        enums["Enum4"] = enum4
        enums["messageType"] = message_type

        params1 = collections.OrderedDict()
        params1["1"] = Param(
            name="param1",
            design_description=DESIGN_DESCRIPTION,
            description=DESCRIPTION,
            issues=ISSUES,
            todos=TODOS,
            param_type=enum4,
            default_value=elements4["name1"])
        params1["2"] = Param(
            name="param2",
            param_type=EnumSubset(
                name="sub1",
                enum=enum1,
                allowed_elements={"e1": elements1["name1"]}),
            default_value=elements1["name1"])

        functions = collections.OrderedDict()
        functions["Function1"] = Function(
            name="Function1",
            function_id=elements1["name1"],
            message_type=message_type_elements["request"],
            params=params1)
        functions["Function2"] = Function(
            name="Function2",
            function_id=elements2["xxx"],
            message_type=message_type_elements["response"])
        functions["Function3"] = Function(
            name="Function2",
            function_id=elements2["yyy"],
            message_type=message_type_elements["notification"])

        members1 = collections.OrderedDict()
        members1["m1"] = Param(name="intParam",
                               param_type=Integer(max_value=2))
        members1["m11"] = Param(name="doubleParam",
                                param_type=Float(min_value=0.333),
                                is_mandatory=False)
        members1["m222"] = Param(name="boolParam",
                                 param_type=Boolean())
        members1["m2"] = Param(name="structParam",
                               param_type=Struct(name="Struct2"))
        members1["aaa"] = Param(name="enumParam",
                                param_type=enum1)
        members1["bbb"] = Param(name="enumParam1",
                                param_type=enum1)
        members1["xxx"] = Param(
            name="enumSubset1",
            param_type=EnumSubset(
                name="sub",
                enum=enum1,
                allowed_elements={"e1": elements1["name1"]}),
            is_mandatory=False)
        members1["1"] = Param(
            name="arrayOfInt",
            param_type=Array(min_size=0,
                             max_size=20,
                             element_type=Boolean()),
            is_mandatory=False)
        members1["2"] = Param(
            name="arrayOfEnum1",
            param_type=Array(min_size=0,
                             max_size=20,
                             element_type=enum1),
            is_mandatory=False)
        members1["3"] = Param(
            name="arrayOfEnum3",
            param_type=Array(min_size=10,
                             max_size=40,
                             element_type=enum3),
            is_mandatory=True)
        members1["4"] = Param(
            name="arrayOfEnum4",
            param_type=Array(
                min_size=10,
                max_size=41,
                element_type=EnumSubset(
                    name="sub1",
                    enum=enum1,
                    allowed_elements={"e1": elements1["name1"]})))
        members1["5"] = Param(
            name="arrayOfEnum5",
            param_type=Array(
                min_size=10,
                max_size=42,
                element_type=EnumSubset(
                    name="sub2",
                    enum=enum1,
                    allowed_elements={"e1": elements1["name2"]})))
        members1["6"] = Param(
            name="arrayOfEnum6",
            param_type=Array(
                min_size=10,
                max_size=43,
                element_type=EnumSubset(
                    name="sub3",
                    enum=enum4,
                    allowed_elements={"e1": elements4["name2"]})))

        structs = collections.OrderedDict()
        structs["Struct1"] = Struct(
            name="Struct1",
            design_description=DESIGN_DESCRIPTION,
            issues=ISSUES,
            members=members1)
        structs["Struct2"] = Struct(name="Struct2",
                                    issues=ISSUES)

        interface = Interface(enums=enums,
                              structs=structs,
                              functions=functions,
                              params={"param1": "value1",
                                      "param2": "value2"})

        os.path.exists = MagicMock(return_value=True)
        uuid.uuid1 = MagicMock(
            return_value=uuid.UUID("12345678123456781234567812345678"))
        codecs.open = MagicMock()

        generator.generate(interface=interface,
                           filename="Test.xml",
                           namespace="XXX::YYY::ZZZ",
                           destination_dir="/some/test/dir")

        os.path.exists.assert_has_calls([call('/some/test/dir')])

        open_result = codecs.open
        mock_calls = open_result.mock_calls

        self.assertEqual(mock_calls[0],
                         call('/some/test/dir/Test.h',
                              mode='w',
                              encoding='utf-8'),
                         "Invalid header file creation")

        self.assertEqual(mock_calls[4],
                         call('/some/test/dir/Test_schema.h',
                              mode='w',
                              encoding='utf-8'),
                         "Invalid source file creation")
        try:
            self.assertSequenceEqual(str(mock_calls[2])[27:-2].replace("\\n", "\n"),
                                     expected_h_file_content,
                                     "Invalid header file content")

            self.assertSequenceEqual(str(mock_calls[6])[27:-2].replace("\\n", "\n"),
                                     expected_cc_file_content,
                                     "Invalid source file content")
        except AssertionError as message:
            print(message)
예제 #12
0
    def test_RegisterAppInterfaceResponse(self):
        """
        generator/transformers/common_producer.py		82%
        generator/transformers/functions_producer.py	63%
        """
        params = OrderedDict()
        params['success'] = Param(name='success',
                                  param_type=Boolean(),
                                  description=[' True if '],
                                  is_mandatory=False)
        params['language'] = Param(
            name='language',
            is_mandatory=False,
            param_type=Enum(name='Language',
                            elements={
                                'EN-US':
                                EnumElement(name='EN-US',
                                            description=['English - US'])
                            }),
            description=['The currently'])
        params['supportedDiagModes'] = Param(
            name='supportedDiagModes',
            is_mandatory=False,
            description=['\n                Specifies the'],
            param_type=Array(element_type=Integer(max_value=255, min_value=0),
                             max_size=100,
                             min_size=1))
        params['hmiZoneCapabilities'] = Param(
            name='hmiZoneCapabilities',
            is_mandatory=False,
            param_type=Array(element_type=Enum(name='HmiZoneCapabilities'),
                             max_size=100,
                             min_size=1))

        item = Function(name='RegisterAppInterface',
                        function_id=EnumElement(name='RegisterAppInterfaceID'),
                        description=['The response '],
                        message_type=EnumElement(name='response'),
                        params=params)

        expected = OrderedDict()
        expected['origin'] = 'RegisterAppInterface'
        expected['name'] = 'SDLRegisterAppInterfaceResponse'
        expected['extends_class'] = 'SDLRPCResponse'
        expected['imports'] = {
            '.h': {
                'enum': {'SDLRPCResponse', 'SDLLanguage'},
                'struct': set()
            },
            '.m': {'SDLLanguage'}
        }
        expected['description'] = ['The response']
        expected['params'] = (
            self.producer.param_named(constructor_argument='language',
                                      constructor_argument_override=None,
                                      constructor_prefix='Language',
                                      deprecated=False,
                                      description=['The currently'],
                                      for_name='enum',
                                      mandatory=False,
                                      method_suffix='Language',
                                      modifier='strong',
                                      of_class='',
                                      origin='language',
                                      since=None,
                                      type_native='SDLLanguage ',
                                      type_sdl='SDLLanguage '),
            self.producer.param_named(
                constructor_argument='supportedDiagModes',
                constructor_argument_override=None,
                constructor_prefix='SupportedDiagModes',
                deprecated=False,
                description=['Specifies the'],
                for_name='objects',
                mandatory=False,
                method_suffix='SupportedDiagModes',
                modifier='strong',
                of_class='NSNumber.class',
                origin='supportedDiagModes',
                since=None,
                type_native='NSArray<NSNumber<SDLUInt> *> *',
                type_sdl='NSArray<NSNumber<SDLUInt> *> *'),
            self.producer.param_named(
                constructor_argument='hmiZoneCapabilities',
                constructor_argument_override=None,
                constructor_prefix='HmiZoneCapabilities',
                deprecated=False,
                description=[],
                for_name='enums',
                mandatory=False,
                method_suffix='HmiZoneCapabilities',
                modifier='strong',
                of_class='',
                origin='hmiZoneCapabilities',
                since=None,
                type_native='NSArray<SDLHmiZoneCapabilities> *',
                type_sdl='NSArray<SDLHmiZoneCapabilities> *'))

        arguments = [
            self.producer.argument_named(variable='language',
                                         deprecated=False,
                                         origin='language',
                                         constructor_argument='language'),
            self.producer.argument_named(
                variable='supportedDiagModes',
                deprecated=False,
                origin='supportedDiagModes',
                constructor_argument='supportedDiagModes'),
            self.producer.argument_named(
                variable='hmiZoneCapabilities',
                deprecated=False,
                origin='hmiZoneCapabilities',
                constructor_argument='hmiZoneCapabilities')
        ]

        expected['constructors'] = (self.producer.constructor_named(
            all=arguments,
            arguments=arguments,
            deprecated=False,
            init=
            'Language:(nullable SDLLanguage)language supportedDiagModes:(nullable NSArray<NSNumber<SDLUInt> *>'
            ' *)supportedDiagModes hmiZoneCapabilities:(nullable NSArray<SDLHmiZoneCapabilities> *)'
            'hmiZoneCapabilities',
            self=''), )

        actual = self.producer.transform(item)
        self.assertDictEqual(expected, actual)
예제 #13
0
    def generate(self, interface, filename, namespace, destination_dir):
        """ Generate SmartFactory source files.

        Generates source code files at destination directory in
        accordance with given model in specified namespace.

        Keyword arguments:
        interface -- model of the interface to generate source code for.
        filename -- name of initial XML file.
        namespace -- name of destination namespace.
        destination_dir -- directory to create source files.

        """

        if interface is None:
            raise GenerateError("Given interface is None.")

        params_set = set()
        for func in interface.functions.values():
            for param in func.params:
                params_set.add(param)
        parameter_enum = Enum('Parameter')

        for item in params_set:
            parameter_enum.elements[item.upper()] = EnumElement(item)

        required_enums_for_policy = [
            "HMILevel", "FunctionID", "HybridAppPreference", "AppHMIType",
            "RequestType", "ModuleType", "Common_AppPriority", "Parameter"
        ]

        self.required_empty_value = ["RequestType", "ModuleType", "Parameter"]

        self.enum_items_naming_conversion_ = {
            "HMILevel":
            lambda item_name: "HL_" + item_name.replace("HMI_", ""),
            "AppHMIType":
            lambda item_name: "AHT_" + item_name,
            "FunctionID":
            lambda item_name: item_name,
            "HybridAppPreference":
            lambda item_name: item_name,
            "RequestType":
            lambda item_name: "RT_" + item_name,
            "ModuleType":
            lambda item_name: "MT_" + item_name,
            "Common_AppPriority":
            lambda item_name: "P_" + item_name
            if not item_name == "VOICE_COMMUNICATION" else "P_VOICECOM",
            "Parameter":
            lambda item_name: "P_" + to_snake_case(item_name).upper()
        }

        self.enum_items_string_naming_conversion_ = {
            "HMILevel":
            lambda item_name: item_name,
            "AppHMIType":
            lambda item_name: item_name,
            "FunctionID":
            lambda item_name: item_name[:item_name.rfind("ID")],
            "HybridAppPreference":
            lambda item_name: item_name,
            "RequestType":
            lambda item_name: item_name,
            "ModuleType":
            lambda item_name: item_name,
            "Common_AppPriority":
            lambda item_name: item_name
            if not item_name == "VOICE_COMMUNICATION" else "VOICECOM",
            "Parameter":
            lambda item_name: item_name
        }

        self.enum_naming_conversion_ = {
            "HMILevel": "HmiLevel",
            "AppHMIType": "AppHMIType",
            "FunctionID": "FunctionID",
            "HybridAppPreference": "HybridAppPreference",
            "RequestType": "RequestType",
            "ModuleType": "ModuleType",
            "Common_AppPriority": "Priority",
            "Parameter": "Parameter"
        }

        # In case if "." is in FunctionID name this is HMI_API function ID and should not be included in Policy  enums

        required_enum_values = list(
            filter(
                lambda e: e.name in required_enums_for_policy and "." not in
                list(e.elements.values())[0].name,
                list(interface.enums.values())))

        if filename == "MOBILE_API":
            self._write_cc_with_enum_schema_factory(filename, namespace,
                                                    destination_dir,
                                                    interface.enums.values())

            # Params should be generated as enum for MOBILE_API to validate RPCSpec parameters
            required_enum_values.append(parameter_enum)

        self._write_header_with_enums(filename, namespace, destination_dir,
                                      required_enum_values)
        self._write_cc_with_enums(filename, namespace, destination_dir,
                                  required_enum_values)
    def test_RegisterAppInterfaceRequest(self):
        params = OrderedDict()
        params['syncMsgVersion'] = Param(name='syncMsgVersion',
                                         param_type=Struct(
                                             name='SyncMsgVersion',
                                             description=['Specifies the'],
                                             members={
                                                 'majorVersion':
                                                 Param(name='majorVersion',
                                                       param_type=Integer())
                                             }),
                                         description=['See SyncMsgVersion'])
        params['fullAppID'] = Param(name='fullAppID',
                                    description=['ID used'],
                                    param_type=String())
        params['dayColorScheme'] = Param(
            name='dayColorScheme',
            param_type=Struct(
                name='TemplateColorScheme',
                description=[
                    '\n            A color scheme for all display layout templates.\n        '
                ]))
        params['ttsName'] = Param(
            name='ttsName',
            description=['\n      TTS string for'],
            param_type=Array(element_type=Struct(name='TTSChunk',
                                                 description=['A TTS chunk'])))

        item = Function(name='RegisterAppInterface',
                        function_id=Enum(name='RegisterAppInterfaceID'),
                        message_type=EnumElement(name='request'),
                        params=params)
        expected = OrderedDict()
        expected['file_name'] = 'RegisterAppInterface'
        expected['name'] = 'RegisterAppInterface'
        expected['imports'] = {
            self.producer.imports(what='SdlMsgVersion',
                                  wherefrom='../structs/SdlMsgVersion.js'),
            self.producer.imports(
                what='TemplateColorScheme',
                wherefrom='../structs/TemplateColorScheme.js'),
            self.producer.imports(what='TTSChunk',
                                  wherefrom='../structs/TTSChunk.js'),
            self.producer.imports(what='RpcRequest',
                                  wherefrom='../RpcRequest.js'),
            self.producer.imports(what='FunctionID',
                                  wherefrom='../enums/FunctionID.js')
        }
        expected['methods'] = (
            self.producer.methods(key='KEY_SDL_MSG_VERSION',
                                  method_title='SdlMsgVersion',
                                  external='SdlMsgVersion',
                                  description=['See SyncMsgVersion'],
                                  param_name='version',
                                  type='SdlMsgVersion',
                                  param_values={},
                                  since=None,
                                  history=None,
                                  deprecated=None),
            self.producer.methods(key='KEY_FULL_APP_ID',
                                  method_title='FullAppID',
                                  external=None,
                                  description=['ID used'],
                                  param_name='id',
                                  type='String',
                                  param_values={},
                                  since=None,
                                  history=None,
                                  deprecated=None),
            self.producer.methods(
                key='KEY_DAY_COLOR_SCHEME',
                param_name='scheme',
                method_title='DayColorScheme',
                external='TemplateColorScheme',
                description=[
                    'A color scheme for all display layout templates.'
                ],
                type='TemplateColorScheme',
                param_values={},
                since=None,
                history=None,
                deprecated=None),
            self.producer.methods(key='KEY_TTS_NAME',
                                  param_name='name',
                                  method_title='TtsName',
                                  external='TTSChunk',
                                  description=['TTS string for'],
                                  type='TTSChunk[]',
                                  param_values={},
                                  since=None,
                                  history=None,
                                  deprecated=None))
        expected['params'] = (self.producer.params(key='KEY_SDL_MSG_VERSION',
                                                   value="'syncMsgVersion'"),
                              self.producer.params(key='KEY_FULL_APP_ID',
                                                   value="'fullAppID'"),
                              self.producer.params(key='KEY_DAY_COLOR_SCHEME',
                                                   value="'dayColorScheme'"),
                              self.producer.params(key='KEY_TTS_NAME',
                                                   value="'ttsName'"),
                              self.producer.params(key='APP_ID_MAX_LENGTH',
                                                   value=10))
        expected['since'] = None
        expected['history'] = None
        expected['deprecated'] = None
        expected['func'] = 'RegisterAppInterface'
        expected['extend'] = 'RpcRequest'

        result = self.producer.transform(item)
        self.assertDictEqual(expected, result)
    def test_RegisterAppInterfaceResponse(self):
        params = OrderedDict()
        params['success'] = Param(name='success',
                                  param_type=Boolean(),
                                  description=[' true if '])
        params['language'] = Param(
            name='language',
            param_type=Enum(name='Language',
                            elements={
                                'EN-US':
                                EnumElement(name='EN-US',
                                            description=['English - US'])
                            }),
            description=['The currently'])
        params['supportedDiagModes'] = Param(
            name='supportedDiagModes',
            param_type=Array(element_type=Integer()),
            description=['\n                Specifies the'])

        item = Function(name='RegisterAppInterface',
                        function_id=Enum(name='RegisterAppInterfaceID'),
                        description=['The response '],
                        message_type=EnumElement(name='response'),
                        params=params)
        expected = OrderedDict()
        expected['file_name'] = 'RegisterAppInterfaceResponse'
        expected['name'] = 'RegisterAppInterfaceResponse'
        expected['imports'] = {
            self.producer.imports(what='Language',
                                  wherefrom='../enums/Language.js'),
            self.producer.imports(what='RpcResponse',
                                  wherefrom='../RpcResponse.js'),
            self.producer.imports(what='FunctionID',
                                  wherefrom='../enums/FunctionID.js')
        }
        expected['methods'] = (self.producer.methods(
            key='KEY_LANGUAGE',
            method_title='Language',
            external='Language',
            description=['The currently'],
            param_name='language',
            type='Language',
            param_values={},
            since=None,
            history=None,
            deprecated=None),
                               self.producer.methods(
                                   key='KEY_SUPPORTED_DIAG_MODES',
                                   method_title='SupportedDiagModes',
                                   external=None,
                                   description=['Specifies the'],
                                   param_name='modes',
                                   type='Number[]',
                                   param_values={},
                                   since=None,
                                   history=None,
                                   deprecated=None))
        expected['params'] = (self.producer.params(key='KEY_LANGUAGE',
                                                   value="'language'"),
                              self.producer.params(
                                  key='KEY_SUPPORTED_DIAG_MODES',
                                  value="'supportedDiagModes'"))
        expected['description'] = ['The response']
        expected['since'] = None
        expected['history'] = None
        expected['deprecated'] = None
        expected['func'] = 'RegisterAppInterface'
        expected['extend'] = 'RpcResponse'
        result = self.producer.transform(item)
        self.assertDictEqual(expected, result)