gpio_ftdi/test/unit/test_gpio.c

47 lines
1.3 KiB
C

#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <sys/syscall.h>
#include <fff.h>
#include <utest.h>
#include <ftdi_dev.h>
#include <gpio.h>
DEFINE_FFF_GLOBALS;
FAKE_VOID_FUNC(ftdi_free, struct ftdi_context *);
FAKE_VALUE_FUNC(int, ftdi_usb_open, struct ftdi_context *, int, int);
FAKE_VALUE_FUNC(int, ftdi_usb_close, struct ftdi_context *);
FAKE_VALUE_FUNC(struct ftdi_context *, ftdi_new);
FAKE_VALUE_FUNC(const char *, ftdi_get_error_string, struct ftdi_context *);
FAKE_VALUE_FUNC(int, ftdi_set_bitmode, struct ftdi_context *, unsigned char, unsigned char);
FAKE_VALUE_FUNC(int, ftdi_read_data, struct ftdi_context *, unsigned char *, int);
FAKE_VALUE_FUNC(int, ftdi_write_data, struct ftdi_context *, const unsigned char *, int);
UTEST_MAIN();
UTEST(gpio, gpio_open) {
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;
struct ftdi_context ftdi_ctx;
ftdi_obj.ftdi = NULL,
ftdi_obj.is_open = false,
ftdi_obj.vendor_id = 0x0403,
ftdi_obj.product_id = 0x6001,
ftdi_obj.bit_mask = 0,
ftdi_obj.status_mask = 0,
gpio_1.pin = 0x08;
gpio_1.ftdi_dev = &ftdi_obj;
ASSERT_EQ(gpio_open(NULL), EXIT_FAILURE);
ftdi_new_fake.return_val = &ftdi_ctx;
ASSERT_EQ(gpio_open(&gpio_1), EXIT_SUCCESS);
}