test.c/test/unit/gpio_read.c

46 lines
966 B
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>
#include <stdio.h>
UTEST(gpio_read, invalid_params) {
ASSERT_EQ(gpio_read(NULL, NULL), EXIT_FAILURE);
}
UTEST(gpio_read, value_0) {
unsigned int result;
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;
ftdi_obj.status_mask = ~0x08;
gpio_1.pin = 0x08;
gpio_1.ftdi_dev = &ftdi_obj;
ASSERT_EQ(gpio_read(&gpio_1, &result), EXIT_SUCCESS);
result = ((ftdi_obj.status_mask) & (gpio_1.pin)) >> 3;
ASSERT_EQ(result, 0)
}
UTEST(gpio_read, value_1) {
unsigned int result;
struct gpio gpio_1;
struct ftdi_dev ftdi_obj;
ftdi_obj.status_mask = 0x08;
gpio_1.pin = 0x08;
gpio_1.ftdi_dev = &ftdi_obj;
ASSERT_EQ(gpio_read(&gpio_1, &result), EXIT_SUCCESS);
result = ((ftdi_obj.status_mask) & (gpio_1.pin)) >> 3;
ASSERT_EQ(result, 1)
}