rewrote the tests to check the accessed addresses.

This commit is contained in:
Jake Goodwin 2023-08-31 17:43:12 -07:00
parent 68e1048a7b
commit c72415d73d
1 changed files with 12 additions and 10 deletions

View File

@ -39,12 +39,12 @@ void fake_twi_rx(uint8_t slave_addr, uint8_t *data, uint8_t size)
reg_addr_arr[0].dev_addr = slave_addr; reg_addr_arr[0].dev_addr = slave_addr;
/*Read the registers requested*/ /*Read the registers requested*/
for(; idx < size; idx++) { for(uint8_t i = 0; i < size; i++) {
/*Wridxte the register read address*/ /*Wridxte the register read address*/
reg_addr_arr[idx].addr = *(data + idx); reg_addr_arr[i + idx].addr = *(data + i);
/*Read the response value idxnto the pased data ptr*/ /*Read the response value into the pased data ptr*/
*(data + idx) = reg_addr_arr[idx].value; *(data + i) = reg_addr_arr[i + idx].value;
} }
/*Post increment the global index*/ /*Post increment the global index*/
idx++; idx++;
@ -100,16 +100,16 @@ static void test_gy521_update_accel(void **sate)
for(uint8_t i = 0; i < 6; i++) { for(uint8_t i = 0; i < 6; i++) {
reg_addr_arr[i].value = i; reg_addr_arr[i].value = i;
} }
/*Zero the global index for the TWI*/
idx = 0; idx = 0;
gy521_update_accel(m); gy521_update_accel(m);
/*Ensure the correct registers are read*/ /*Ensure the correct registers are read*/
_Bool is_correct = 1; _Bool is_correct = 1;
for(int i = 0; i < 6; i++){ assert_true(is_correct);
/*The starting address of the registers is 59 and goes to 64*/ for(uint8_t i = 0; i < 6; i++){
print_message("expected: %d, actual: %d\n", (59+i), reg_addr_arr[i].addr); /*The starting address of the registers is 59 and goes to 64*/
if((59 + i) != reg_addr_arr[i].addr) { if((59 + i) != reg_addr_arr[i].addr) {
is_correct = 0; is_correct = 0;
} }
@ -117,7 +117,9 @@ static void test_gy521_update_accel(void **sate)
assert_true(is_correct); assert_true(is_correct);
/*Check that the values are assembled correctly*/ /*Check that the values are assembled correctly*/
gy521_free(m); gy521_free(m);
} }