class MockI2cGtest

Defined at line 36 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c-gtest.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::MockI2cGtest 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

MockI2cGtest & ExpectRead (std::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 39 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c-gtest.h

MockI2cGtest & ExpectReadStop (std::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 46 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c-gtest.h

MockI2cGtest & ExpectWrite (std::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 53 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c-gtest.h

MockI2cGtest & ExpectWriteStop (std::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 61 of file ../../src/devices/i2c/testing/mock-i2c/include/lib/mock-i2c/mock-i2c-gtest.h

void VerifyAndClear ()

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

void GetName (GetNameCompleter::Sync & completer)

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

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

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