Esempio n. 1
0
void test_ByteArray_GetSlice_should_return_a_subarray_of_the_ByteArray(void)
{
    uint8_t data[] = {0x1u, 0x2u, 0x3u, 0x4u};
    size_t len = sizeof(data);
    ByteArray array = {.data = data, .len = len};
    size_t sliceLen;

    // Validate slice of full array
    ByteArray slice0 = ByteArray_GetSlice(array, 0, len);
    TEST_ASSERT_EQUAL_PTR(data, slice0.data);
    TEST_ASSERT_EQUAL(len, slice0.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(data, slice0.data, len);

    // Validate slice from beginning of array
    sliceLen = len - 1;
    ByteArray slice1 = ByteArray_GetSlice(array, 0, sliceLen);
    TEST_ASSERT_EQUAL_PTR(data, slice1.data);
    TEST_ASSERT_EQUAL(sliceLen, slice1.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(data, slice1.data, sliceLen);

    // Validate slice from non-start to the end of the array
    sliceLen = len - 1;
    ByteArray slice2 = ByteArray_GetSlice(array, 1, sliceLen);
    TEST_ASSERT_EQUAL_PTR(&data[1], slice2.data);
    TEST_ASSERT_EQUAL(sliceLen, slice2.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(&data[1], slice2.data, sliceLen);

    // Validate slice from middle of the array
    sliceLen = len - 2;
    ByteArray slice3 = ByteArray_GetSlice(array, 1, sliceLen);
    TEST_ASSERT_EQUAL_PTR(&data[1], slice3.data);
    TEST_ASSERT_EQUAL(sliceLen, slice3.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(&data[1], slice3.data, sliceLen);
}
Esempio n. 2
0
void testEqualHEX8Arrays(void)
{
    unsigned short p0[] = {1, 8, 254u, 123};
    unsigned short p1[] = {1, 8, 254u, 123};
    unsigned short p2[] = {1, 8, 254u, 2};
    unsigned short p3[] = {1, 23, 25, 26};

    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p0, 1);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p0, 4);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p1, 4);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p2, 3);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p3, 1);
}
Esempio n. 3
0
tusb_error_t stub_control_xfer(uint8_t addr, uint8_t bmRequestType, uint8_t bRequest,
                               uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data, int num_call )
{
  TEST_ASSERT_EQUAL(p_comm_interface->bInterfaceNumber, wIndex);
  TEST_ASSERT_EQUAL(0, wValue);
  TEST_ASSERT_EQUAL(dev_addr, addr);

  switch(num_call)
  {
    case 0:
      TEST_ASSERT_EQUAL(0x21, bmRequestType);
      TEST_ASSERT_EQUAL(SEND_ENCAPSULATED_COMMAND, bRequest);
      TEST_ASSERT_EQUAL(0x18, wLength);
      TEST_ASSERT_EQUAL_HEX8_ARRAY(&msg_init, data, wLength);
    break;

    case 1:
      TEST_ASSERT_EQUAL(0xA1, bmRequestType);
      TEST_ASSERT_EQUAL(GET_ENCAPSULATED_RESPONSE, bRequest);
      TEST_ASSERT( wLength >= 0x0400 ); // Microsoft Specs
      memcpy(data, &msg_init_cmplt, 0x30);
    break;

    default:
    return TUSB_ERROR_OSAL_TIMEOUT;
  }

  return TUSB_ERROR_NONE;
}
Esempio n. 4
0
void testNotEqualHEX8Arrays3(void)
{
    unsigned char p0[] = {1, 8, 254u, 253u};
    unsigned char p1[] = {1, 8, 255u, 253u};

    EXPECT_ABORT_BEGIN
    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p1, 4);
    VERIFY_FAILS_END
}
Esempio n. 5
0
void test_ByteArray_CreateWithCString_should_create_ByteArray_using_C_string(void)
{
    char* str = "some string";
    size_t len = strlen(str);

    ByteArray array = ByteArray_CreateWithCString(str);

    TEST_ASSERT_EQUAL_PTR(str, array.data);
    TEST_ASSERT_EQUAL(len, array.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(str, array.data, len);
}
Esempio n. 6
0
void test_ByteArray_Create_should_create_a_byte_array(void)
{
    uint8_t data[] = {0x1u, 0x2u, 0x3u, 0x4u};
    size_t len = sizeof(data);

    ByteArray array = ByteArray_Create(data, len);

    TEST_ASSERT_EQUAL_PTR(data, array.data);
    TEST_ASSERT_EQUAL(len, array.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(data, array.data, len);
}
Esempio n. 7
0
void test_ByteArray_FillWithDummyData_should_fill_an_array_with_dummy_data(void)
{
    uint8_t data[4];
    const size_t len = sizeof(data);
    memset(data, 0xFFu, len);
    ByteArray array = {.data = data, .len = len};
    uint8_t expected[] = {0x00, 0x01, 0x02, 0x03};

    ByteArray_FillWithDummyData(array);

    TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, array.data, len);
}
Esempio n. 8
0
void test_ByteBuffer_Create_should_create_ByteBuffer_with_specified_array_and_max_length_and_used_bytes(void)
{
    uint8_t data[] = {0x1u, 0x2u, 0x3u, 0x4u};
    size_t len = sizeof(data);

    ByteBuffer buffer = ByteBuffer_Create(data, len, 2);

    TEST_ASSERT_EQUAL_PTR(data, buffer.array.data);
    TEST_ASSERT_EQUAL(len, buffer.array.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(data, buffer.array.data, len);
    TEST_ASSERT_EQUAL(2, buffer.bytesUsed);
}
Esempio n. 9
0
void test_ByteBuffer_CreateWithArray_should_create_an_empty_ByteBuffer_with_specified_ByteArray(void)
{
    uint8_t data[] = {0x1u, 0x2u, 0x3u, 0x4u};
    size_t len = sizeof(data);
    ByteArray array = {.data = data, .len = len};

    ByteBuffer buffer = ByteBuffer_CreateWithArray(array);

    TEST_ASSERT_EQUAL_PTR(data, buffer.array.data);
    TEST_ASSERT_EQUAL(len, buffer.array.len);
    TEST_ASSERT_EQUAL_PTR(array.data, buffer.array.data);
    TEST_ASSERT_EQUAL(array.len, buffer.array.len);
    TEST_ASSERT_EQUAL_HEX8_ARRAY(data, buffer.array.data, len);
    TEST_ASSERT_EQUAL(0, buffer.bytesUsed);
}
Esempio n. 10
0
void testNotEqualHEX8Arrays3(void)
{
    unsigned char p0[] = {1, 8, 254u, 253u};
    unsigned char p1[] = {1, 8, 255u, 253u};

    int failed;

    EXPECT_ABORT_BEGIN
    TEST_ASSERT_EQUAL_HEX8_ARRAY(p0, p1, 4);
    EXPECT_ABORT_END

    failed = Unity.CurrentTestFailed;
    Unity.CurrentTestFailed = 0;

    VERIFY_FAILURE_WAS_CAUGHT
}