class MockI2c

Defined at line 34 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

This class mocks an addressed I2C device by providing a fuchsia.hardware.i2c WireServer

implementation. Users can set expectations that either return specified data on read or verify

data on write. After the test, use VerifyAndClear to reset the object and verify that all

expectations were satisfied. See the following example test:

mock_i2c::MockI2c i2c;

i2c

.ExpectWrite({0x18})

.ExpectReadStop({0x3a, 0x07})

.ExpectWriteStop({0x18, 0x57});

auto endpoints = fidl::CreateEndpoints

<fuchsia

_hardware_i2c::Device>();

fidl::BindServer(dispatcher(), std::move(endpoints->server),

&i

2c);

SomeDriver dut(std::move(endpoints->client));

EXPECT_OK(dut.SomeMethod());

EXPECT_TRUE(i2c.VerifyAndClear());

Public Methods

MockI2c & ExpectRead (fbl::Vector<uint8_t> buf, zx_status_t status)

Checks that the next operation is a read and returns the contents of buf.

Defined at line 37 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

MockI2c & ExpectReadStop (fbl::Vector<uint8_t> buf, zx_status_t status)

Checks that the next operation is a read followed by a stop and returns the contents of buf.

Defined at line 44 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

MockI2c & ExpectWrite (fbl::Vector<uint8_t> buf, zx_status_t status)

Checks that the next operation is a write and that the data matches the contents of buf.

Defined at line 51 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

MockI2c & ExpectWriteStop (fbl::Vector<uint8_t> buf, zx_status_t status)

Checks that the next operation is a write followed by a stop and that the data matches the

contents of buf.

Defined at line 59 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

void VerifyAndClear ()

Defined at line 65 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

void GetName (GetNameCompleter::Sync & completer)

Defined at line 71 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h

void Transfer (TransferRequestView request, TransferCompleter::Sync & completer)

Defined at line 75 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c.h