56 lines
2.1 KiB
C++
56 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2023 Fancy Code.
|
|
* 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.
|
|
*/
|
|
#include "SdCardHalMock.h"
|
|
#include "GtestUsing.h"
|
|
// #include "ILog.h"
|
|
#include "LinuxApiMock.h"
|
|
#include <gmock/gmock-spec-builders.h>
|
|
#include <memory>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
extern const char *SD_CARD_DEVICE;
|
|
constexpr int FSTAT_SUCCESS = 0;
|
|
constexpr int FILE_EXIST = 0;
|
|
constexpr int FILE_NOT_EXIST = -1;
|
|
SdCardHalMock::SdCardHalMock()
|
|
{
|
|
mDevFd = -1;
|
|
}
|
|
void SdCardHalMock::SetLinuxTest(std::shared_ptr<LinuxTest> &mock)
|
|
{
|
|
mLinuxTest = mock;
|
|
mDevFd = mLinuxTest->GetHandleForMock();
|
|
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST)));
|
|
EXPECT_CALL(*mock.get(), fx_open(SD_CARD_DEVICE, _)).WillRepeatedly(DoAll((Return(mDevFd))));
|
|
auto fstatFunc = [=, &mock](int fd, struct stat *statbuf) {
|
|
statbuf->st_mode = S_IFBLK | 0600;
|
|
};
|
|
EXPECT_CALL(*mock.get(), fx_fstat(mDevFd, _))
|
|
.WillRepeatedly(DoAll(WithArgs<0, 1>(Invoke(fstatFunc)), Return(FSTAT_SUCCESS)));
|
|
}
|
|
void SdCardHalMock::MockSdCardRemove(std::shared_ptr<LinuxTest> &mock)
|
|
{
|
|
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_NOT_EXIST)));
|
|
}
|
|
void SdCardHalMock::MockSdCardInsert(std::shared_ptr<LinuxTest> &mock)
|
|
{
|
|
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST)));
|
|
}
|
|
void SdCardHalMock::MockSdCardFormatResult(std::shared_ptr<LinuxTest> &mock, const int &result)
|
|
{
|
|
// TODO: improve
|
|
// LinuxTest::SetSystemCommandResult(mock, "mkfs.vfat", result);
|
|
// LinuxTest::SetSystemCommandResult(mock, "umount", result);
|
|
} |