Files
mbed-os/storage/blockdevice/tests/UNITTESTS/doubles/BlockDevice_mock.h
Beslan 0ef1717155
Some checks failed
Basic Checks / license-check (push) Has been cancelled
Basic Checks / include-check (push) Has been cancelled
Basic Checks / style-check (push) Has been cancelled
Basic Checks / docs-check (push) Has been cancelled
Basic Checks / python-tests (push) Has been cancelled
Basic Checks / pin-validation (push) Has been cancelled
Basic Checks / cmake-checks (push) Has been cancelled
Basic Checks / frozen-tools-check (push) Has been cancelled
Publish or Update docker image for head of branch / prepare-tags (push) Has been cancelled
Release or update docker image for a released mbed-os version / prepare-tags (push) Has been cancelled
Publish or Update docker image for head of branch / build-container (push) Has been cancelled
Publish or Update docker image for head of branch / test-container (linux/amd64) (push) Has been cancelled
Publish or Update docker image for head of branch / test-container (linux/arm64) (push) Has been cancelled
Publish or Update docker image for head of branch / deploy-container (push) Has been cancelled
Release or update docker image for a released mbed-os version / build-container (push) Has been cancelled
Release or update docker image for a released mbed-os version / test-container (linux/amd64) (push) Has been cancelled
Release or update docker image for a released mbed-os version / test-container (linux/arm64) (push) Has been cancelled
Release or update docker image for a released mbed-os version / deploy-container (push) Has been cancelled
Prune temporary docker images / prune-images (push) Has been cancelled
Mirror mbed-os-6.15.0
2026-07-10 18:42:39 +03:00

65 lines
2.3 KiB
C++

/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef BLOCKDEVICEMOCK_H
#define BLOCKDEVICEMOCK_H
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "blockdevice/BlockDevice.h"
class BlockDeviceMock : public BlockDevice {
public:
MOCK_METHOD0(init, int());
MOCK_METHOD0(deinit, int());
MOCK_METHOD0(sync, int());
MOCK_METHOD3(read, int(void *, bd_addr_t, bd_size_t));
MOCK_METHOD3(program, int(const void *, bd_addr_t, bd_size_t));
MOCK_METHOD2(erase, int(bd_addr_t, bd_size_t));
MOCK_METHOD2(trim, int(bd_addr_t, bd_size_t));
MOCK_CONST_METHOD0(get_read_size, bd_size_t());
MOCK_CONST_METHOD0(get_program_size, bd_size_t());
MOCK_CONST_METHOD0(get_erase_size, bd_size_t());
MOCK_CONST_METHOD1(get_erase_size, bd_size_t(bd_addr_t));
MOCK_CONST_METHOD0(get_erase_value, int());
MOCK_CONST_METHOD0(size, bd_size_t());
MOCK_CONST_METHOD2(is_valid_read, bool(bd_addr_t, bd_size_t));
MOCK_CONST_METHOD2(is_valid_program, bool(bd_addr_t, bd_size_t));
MOCK_CONST_METHOD2(is_valid_erase, bool(bd_addr_t, bd_size_t));
MOCK_CONST_METHOD0(get_type, const char *());
};
// Can be used to compare if the data programmed by mock are correct.
MATCHER_P2(ByteBufferMatcher, buffer, length, "") {
const uint8_t *argp = static_cast<const uint8_t*>(arg);
FILE* fd = fopen("testlog.txt", "w");
for (int i = 0; i < length; i++) {
fprintf(fd, "%03d %02X %02X\n", i, argp[i], buffer[i]);
}
fclose(fd);
return 0 == memcmp(arg, buffer, length);
}
ACTION_P2(SetArg0ToCharPtr, value, size)
{
for (int i = 0; i < size; i++) {
static_cast<char *>(arg0)[i] = reinterpret_cast<const char *>(value)[i];
}
}
#endif // BLOCKDEVICEMOCK_H