gpio_ftdi/test/unit/gpio_write.c

61 lines
1.3 KiB
C
Raw Normal View History

2019-07-16 14:40:42 +00:00
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <sys/syscall.h>
#include <utest.h>
#include <mock_ftdi.h>
#include <ftdi_dev.h>
#include <gpio.h>
UTEST(gpio_write, invalid_params) {
ASSERT_EQ(gpio_write(NULL, 0), EXIT_FAILURE);
}
UTEST(gpio_write, value_0) {
unsigned int result;
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;
ftdi_obj.status_mask = 0xff;
gpio_1.pin = 0x08;
gpio_1.ftdi_dev = &ftdi_obj;
ftdi_write_data_fake.return_val = 0;
ASSERT_EQ(gpio_write(&gpio_1, 0), EXIT_SUCCESS);
result = ((ftdi_obj.status_mask) & (gpio_1.pin)) >> 3;
ASSERT_EQ(result, 0)
}
UTEST(gpio_write, value_1) {
unsigned int result;
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;
ftdi_obj.status_mask = 0;
gpio_1.pin = 0x08;
gpio_1.ftdi_dev = &ftdi_obj;
ftdi_write_data_fake.return_val = 0;
ASSERT_EQ(gpio_write(&gpio_1, 1), EXIT_SUCCESS);
result = ((ftdi_obj.status_mask) | (gpio_1.pin)) >> 3;
ASSERT_EQ(result, 1)
}
UTEST(gpio_write, ftdi_write_data_failed) {
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;
ftdi_obj.status_mask = 0;
gpio_1.pin = 0x08;
gpio_1.ftdi_dev = &ftdi_obj;
ftdi_write_data_fake.return_val = -1;
ASSERT_EQ(gpio_write(&gpio_1, 0), EXIT_FAILURE);
}