# Copyright (c) 2019 <NAME>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""
Verifies that the libft4222 module contains the expected contents.
"""

import ctypes
import enum
import types
import nose


from ft4222_test.support import check_identity, check_in, check_isinstance
from ft4222 import libft4222

_CONTENTS = {"FT4222_UnInitialize": "ctype-function",
             "FT4222_SetClock": "ctype-function",
             "FT4222_GetClock": "ctype-function",
             "FT4222_SetSuspendOut": "ctype-function",
             "FT4222_SetWakeUpInterrupt": "ctype-function",
             "FT4222_SetInterruptTrigger": "ctype-function",
             "FT4222_GetMaxTransferSize": "ctype-function",
             "FT4222_SetEventNotification": "ctype-function",
             "FT4222_GetVersion": "ctype-function",
             "FT4222_ChipReset": "ctype-function",
             "FT4222_SPIMaster_Init": "ctype-function",
             "FT4222_SPIMaster_SetLines": "ctype-function",
             "FT4222_SPIMaster_SingleRead": "ctype-function",
             "FT4222_SPIMaster_SingleWrite": "ctype-function",
             "FT4222_SPIMaster_SingleReadWrite": "ctype-function",
             "FT4222_SPIMaster_MultiReadWrite": "ctype-function",
             "FT4222_SPISlave_Init": "ctype-function",
             "FT4222_SPISlave_InitEx": "ctype-function",
             "FT4222_SPISlave_SetMode": "ctype-function",
             "FT4222_SPISlave_GetRxStatus": "ctype-function",
             "FT4222_SPISlave_Read": "ctype-function",
             "FT4222_SPISlave_Write": "ctype-function",
             "FT4222_SPISlave_RxQuickResponse": "ctype-function",
             "FT4222_SPI_ResetTransaction": "ctype-function",
             "FT4222_SPI_Reset": "ctype-function",
             "FT4222_SPI_SetDrivingStrength": "ctype-function",
             "FT4222_I2CMaster_Init": "ctype-function",
             "FT4222_I2CMaster_Read": "ctype-function",
             "FT4222_I2CMaster_Write": "ctype-function",
             "FT4222_I2CMaster_WriteEx": "ctype-function",
             "FT4222_I2CMaster_ReadEx": "ctype-function",
             "FT4222_I2CMaster_GetStatus": "ctype-function",
             "FT4222_I2CMaster_Reset": "ctype-function",
             "FT4222_I2CSlave_Init": "ctype-function",
             "FT4222_I2CSlave_GetAddress": "ctype-function",
             "FT4222_I2CSlave_SetAddress": "ctype-function",
             "FT4222_I2CSlave_GetRxStatus": "ctype-function",
             "FT4222_I2CSlave_Read": "ctype-function",
             "FT4222_I2CSlave_Write": "ctype-function",
             "FT4222_I2CSlave_Reset": "ctype-function",
             "FT4222_I2CSlave_SetClockStretch": "ctype-function",
             "FT4222_I2CSlave_SetRespWord": "ctype-function",
             "FT4222_GPIO_Init": "ctype-function",
             "FT4222_GPIO_Read": "ctype-function",
             "FT4222_GPIO_Write": "ctype-function",
             "FT4222_GPIO_SetInputTrigger": "ctype-function",
             "FT4222_GPIO_GetTriggerStatus": "ctype-function",
             "FT4222_GPIO_ReadTriggerQueue": "ctype-function",
             "FT4222_GPIO_SetWaveFormMode": "ctype-function",
             "DWORD": "generic",
             "uint8": "generic",
             "uint16": "generic",
             "uint32": "generic",
             "int8": "generic",
             "int16": "generic",
             "int32": "generic",
             "cbool": "generic",
             "FT4222_Status": "generic",
             "FT4222_ClockRate": "generic",
             "FT4222_SPIMode": "generic",
             "FT4222_SPIClock": "generic",
             "FT4222_SPICPOL": "generic",
             "FT4222_SPICPHA": "generic",
             "SPI_DrivingStrength": "generic",
             "GPIO_Port": "generic",
             "GPIO_Dir": "generic",
             "GPIO_Trigger": "generic",
             "GPIO_Output": "generic",
             "I2C_MasterFlag": "generic",
             "FT4222_Version": "generic",
             "SPI_Slave_Header": "generic",
             "get__libft4222": "generic"}


def test_generate_attribute_identity_tests():
    """
    Verifies that libft4222 exports the correct attributes.
    """
    for name in _CONTENTS:
        # Attributes labeled as "ctype-function" are checked for identity
        # with the same-named object in the libft4222 CDLL object.
        if _CONTENTS[name] == "ctype-function":
            yield (check_identity,
                   getattr(libft4222, name),
                   getattr(libft4222.get__libft4222(), name),
                   "libft4222.{0} is libft4222._libft4222.{0}".format(name))
        # Attributes labeled as "generic" are allowed, but not checked
        # further.  Other tests must verify that they are the expected object.
        elif _CONTENTS[name] == "generic":
            pass
        else:
            raise RuntimeError("Unknown object type in _CONTENTS")


def test_generate_module_content_tests():
    """
    Verifies that all attributes of libft4222, other than those prefixed by a
    '_', are included in the list of expected contents.
    """
    for name in libft4222.__dict__:
        # Ignore attributes beginning with a '_'.
        if name[0] == '_':
            continue
        # Ignore modules.
        if isinstance(getattr(libft4222, name), types.ModuleType):
            continue
        # For everything else, check that it is on the list of expected 
        # attributes.
        yield (check_in,
               name,
               _CONTENTS.keys(),
               "{0} is an expected export of libft4222".format(name))


if __name__ == '__main__':
    import os
    # Defining UNIT_TEST in the environment enables some unit-test specific
    # features.
    os.environ["UNIT_TEST"] = "1"
    nose.main()

# Copyright (c) 2019 <NAME>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""
Verifies that the libft4222 module contains the expected contents.
"""

import ctypes
import enum
import types
import nose


from ft4222_test.support import check_identity, check_in, check_isinstance
from ft4222 import libft4222

_CONTENTS = {"FT4222_UnInitialize": "ctype-function",
             "FT4222_SetClock": "ctype-function",
             "FT4222_GetClock": "ctype-function",
             "FT4222_SetSuspendOut": "ctype-function",
             "FT4222_SetWakeUpInterrupt": "ctype-function",
             "FT4222_SetInterruptTrigger": "ctype-function",
             "FT4222_GetMaxTransferSize": "ctype-function",
             "FT4222_SetEventNotification": "ctype-function",
             "FT4222_GetVersion": "ctype-function",
             "FT4222_ChipReset": "ctype-function",
             "FT4222_SPIMaster_Init": "ctype-function",
             "FT4222_SPIMaster_SetLines": "ctype-function",
             "FT4222_SPIMaster_SingleRead": "ctype-function",
             "FT4222_SPIMaster_SingleWrite": "ctype-function",
             "FT4222_SPIMaster_SingleReadWrite": "ctype-function",
             "FT4222_SPIMaster_MultiReadWrite": "ctype-function",
             "FT4222_SPISlave_Init": "ctype-function",
             "FT4222_SPISlave_InitEx": "ctype-function",
             "FT4222_SPISlave_SetMode": "ctype-function",
             "FT4222_SPISlave_GetRxStatus": "ctype-function",
             "FT4222_SPISlave_Read": "ctype-function",
             "FT4222_SPISlave_Write": "ctype-function",
             "FT4222_SPISlave_RxQuickResponse": "ctype-function",
             "FT4222_SPI_ResetTransaction": "ctype-function",
             "FT4222_SPI_Reset": "ctype-function",
             "FT4222_SPI_SetDrivingStrength": "ctype-function",
             "FT4222_I2CMaster_Init": "ctype-function",
             "FT4222_I2CMaster_Read": "ctype-function",
             "FT4222_I2CMaster_Write": "ctype-function",
             "FT4222_I2CMaster_WriteEx": "ctype-function",
             "FT4222_I2CMaster_ReadEx": "ctype-function",
             "FT4222_I2CMaster_GetStatus": "ctype-function",
             "FT4222_I2CMaster_Reset": "ctype-function",
             "FT4222_I2CSlave_Init": "ctype-function",
             "FT4222_I2CSlave_GetAddress": "ctype-function",
             "FT4222_I2CSlave_SetAddress": "ctype-function",
             "FT4222_I2CSlave_GetRxStatus": "ctype-function",
             "FT4222_I2CSlave_Read": "ctype-function",
             "FT4222_I2CSlave_Write": "ctype-function",
             "FT4222_I2CSlave_Reset": "ctype-function",
             "FT4222_I2CSlave_SetClockStretch": "ctype-function",
             "FT4222_I2CSlave_SetRespWord": "ctype-function",
             "FT4222_GPIO_Init": "ctype-function",
             "FT4222_GPIO_Read": "ctype-function",
             "FT4222_GPIO_Write": "ctype-function",
             "FT4222_GPIO_SetInputTrigger": "ctype-function",
             "FT4222_GPIO_GetTriggerStatus": "ctype-function",
             "FT4222_GPIO_ReadTriggerQueue": "ctype-function",
             "FT4222_GPIO_SetWaveFormMode": "ctype-function",
             "DWORD": "generic",
             "uint8": "generic",
             "uint16": "generic",
             "uint32": "generic",
             "int8": "generic",
             "int16": "generic",
             "int32": "generic",
             "cbool": "generic",
             "FT4222_Status": "generic",
             "FT4222_ClockRate": "generic",
             "FT4222_SPIMode": "generic",
             "FT4222_SPIClock": "generic",
             "FT4222_SPICPOL": "generic",
             "FT4222_SPICPHA": "generic",
             "SPI_DrivingStrength": "generic",
             "GPIO_Port": "generic",
             "GPIO_Dir": "generic",
             "GPIO_Trigger": "generic",
             "GPIO_Output": "generic",
             "I2C_MasterFlag": "generic",
             "FT4222_Version": "generic",
             "SPI_Slave_Header": "generic",
             "get__libft4222": "generic"}


def test_generate_attribute_identity_tests():
    """
    Verifies that libft4222 exports the correct attributes.
    """
    for name in _CONTENTS:
        # Attributes labeled as "ctype-function" are checked for identity
        # with the same-named object in the libft4222 CDLL object.
        if _CONTENTS[name] == "ctype-function":
            yield (check_identity,
                   getattr(libft4222, name),
                   getattr(libft4222.get__libft4222(), name),
                   "libft4222.{0} is libft4222._libft4222.{0}".format(name))
        # Attributes labeled as "generic" are allowed, but not checked
        # further.  Other tests must verify that they are the expected object.
        elif _CONTENTS[name] == "generic":
            pass
        else:
            raise RuntimeError("Unknown object type in _CONTENTS")


def test_generate_module_content_tests():
    """
    Verifies that all attributes of libft4222, other than those prefixed by a
    '_', are included in the list of expected contents.
    """
    for name in libft4222.__dict__:
        # Ignore attributes beginning with a '_'.
        if name[0] == '_':
            continue
        # Ignore modules.
        if isinstance(getattr(libft4222, name), types.ModuleType):
            continue
        # For everything else, check that it is on the list of expected 
        # attributes.
        yield (check_in,
               name,
               _CONTENTS.keys(),
               "{0} is an expected export of libft4222".format(name))


if __name__ == '__main__':
    import os
    # Defining UNIT_TEST in the environment enables some unit-test specific
    # features.
    os.environ["UNIT_TEST"] = "1"
    nose.main()

# Copyright (c) 2019 <NAME> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. Verifies that the libft4222 module contains the expected contents. Verifies that libft4222 exports the correct attributes. # Attributes labeled as "ctype-function" are checked for identity # with the same-named object in the libft4222 CDLL object. # Attributes labeled as "generic" are allowed, but not checked # further.  Other tests must verify that they are the expected object. Verifies that all attributes of libft4222, other than those prefixed by a     '_', are included in the list of expected contents. # Ignore attributes beginning with a '_'. # Ignore modules. # For everything else, check that it is on the list of expected # attributes. # Defining UNIT_TEST in the environment enables some unit-test specific # features.