提交 df26e0e2 编写于 作者: W William Dean

去掉cpp文件中的windows ^M 换行符

Signed-off-by: NWilliam Dean <williamsukatube@gmail.com>
上级 864bd0dc
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "beget_ext.h"
#ifdef PARAM_FEATURE_DEVICEINFO
#include "device_info_kits.h"
#endif
#include "param_comm.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int AclGetDevUdid(char *udid, int size)
{
if (udid == nullptr || size < UDID_LEN) {
return -1;
}
#ifdef PARAM_FEATURE_DEVICEINFO
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetUdid(result);
if (ret == 0) {
ret = strcpy_s(udid, size, result.c_str());
}
#else
int ret = GetDevUdid_(udid, size);
#endif
BEGET_LOGI("AclGetDevUdid %s", udid);
return ret;
}
const char *AclGetSerial(void)
{
static char serialNumber[MAX_SERIAL_LEN] = {"1234567890"};
#ifdef PARAM_FEATURE_DEVICEINFO
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetSerialID(result);
if (ret == 0) {
ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str());
BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
}
#else
const char *tmpSerial = GetSerial_();
if (tmpSerial != nullptr) {
int ret = strcpy_s(serialNumber, sizeof(serialNumber), tmpSerial);
BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
}
#endif
BEGET_LOGI("AclGetSerial %s", serialNumber);
return serialNumber;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "beget_ext.h"
#ifdef PARAM_FEATURE_DEVICEINFO
#include "device_info_kits.h"
#endif
#include "param_comm.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int AclGetDevUdid(char *udid, int size)
{
if (udid == nullptr || size < UDID_LEN) {
return -1;
}
#ifdef PARAM_FEATURE_DEVICEINFO
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetUdid(result);
if (ret == 0) {
ret = strcpy_s(udid, size, result.c_str());
}
#else
int ret = GetDevUdid_(udid, size);
#endif
BEGET_LOGI("AclGetDevUdid %s", udid);
return ret;
}
const char *AclGetSerial(void)
{
static char serialNumber[MAX_SERIAL_LEN] = {"1234567890"};
#ifdef PARAM_FEATURE_DEVICEINFO
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetSerialID(result);
if (ret == 0) {
ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str());
BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
}
#else
const char *tmpSerial = GetSerial_();
if (tmpSerial != nullptr) {
int ret = strcpy_s(serialNumber, sizeof(serialNumber), tmpSerial);
BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
}
#endif
BEGET_LOGI("AclGetSerial %s", serialNumber);
return serialNumber;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "device_info_kits.h"
#include "beget_ext.h"
#include "device_info_proxy.h"
#include "idevice_info.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "securec.h"
namespace OHOS {
namespace device_info {
DeviceInfoKits::DeviceInfoKits() {}
DeviceInfoKits::~DeviceInfoKits() {}
DeviceInfoKits &DeviceInfoKits::GetInstance()
{
return DelayedRefSingleton<DeviceInfoKits>::GetInstance();
}
void DeviceInfoKits::ResetService(const wptr<IRemoteObject> &remote)
{
std::lock_guard<std::mutex> lock(lock_);
if (deviceInfoService_ != nullptr) {
sptr<IRemoteObject> object = deviceInfoService_->AsObject();
if ((object != nullptr) && (remote == object)) {
object->RemoveDeathRecipient(deathRecipient_);
deviceInfoService_ = nullptr;
}
}
}
sptr<IDeviceInfo> DeviceInfoKits::GetService()
{
std::lock_guard<std::mutex> lock(lock_);
if (deviceInfoService_ != nullptr) {
return deviceInfoService_;
}
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
DINFO_CHECK(samgr != nullptr, return nullptr, "Get samgr failed");
sptr<IRemoteObject> object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
DINFO_CHECK(object != nullptr, return nullptr, "Get device service object from samgr failed");
if (deathRecipient_ == nullptr) {
deathRecipient_ = new DeathRecipient();
}
if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) {
DINFO_LOGE("Failed to add death recipient");
}
deviceInfoService_ = iface_cast<IDeviceInfo>(object);
if (deviceInfoService_ == nullptr) {
DINFO_LOGE("device service iface_cast failed");
}
return deviceInfoService_;
}
void DeviceInfoKits::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
DelayedRefSingleton<DeviceInfoKits>::GetInstance().ResetService(remote);
}
int32_t DeviceInfoKits::GetUdid(std::string& result)
{
auto deviceService = GetService();
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager");
return deviceService->GetUdid(result);
}
int32_t DeviceInfoKits::GetSerialID(std::string& result)
{
auto deviceService = GetService();
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager");
return deviceService->GetSerialID(result);
}
} // namespace device_info
} // namespace OHOS
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "device_info_kits.h"
#include "beget_ext.h"
#include "device_info_proxy.h"
#include "idevice_info.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "securec.h"
namespace OHOS {
namespace device_info {
DeviceInfoKits::DeviceInfoKits() {}
DeviceInfoKits::~DeviceInfoKits() {}
DeviceInfoKits &DeviceInfoKits::GetInstance()
{
return DelayedRefSingleton<DeviceInfoKits>::GetInstance();
}
void DeviceInfoKits::ResetService(const wptr<IRemoteObject> &remote)
{
std::lock_guard<std::mutex> lock(lock_);
if (deviceInfoService_ != nullptr) {
sptr<IRemoteObject> object = deviceInfoService_->AsObject();
if ((object != nullptr) && (remote == object)) {
object->RemoveDeathRecipient(deathRecipient_);
deviceInfoService_ = nullptr;
}
}
}
sptr<IDeviceInfo> DeviceInfoKits::GetService()
{
std::lock_guard<std::mutex> lock(lock_);
if (deviceInfoService_ != nullptr) {
return deviceInfoService_;
}
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
DINFO_CHECK(samgr != nullptr, return nullptr, "Get samgr failed");
sptr<IRemoteObject> object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
DINFO_CHECK(object != nullptr, return nullptr, "Get device service object from samgr failed");
if (deathRecipient_ == nullptr) {
deathRecipient_ = new DeathRecipient();
}
if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) {
DINFO_LOGE("Failed to add death recipient");
}
deviceInfoService_ = iface_cast<IDeviceInfo>(object);
if (deviceInfoService_ == nullptr) {
DINFO_LOGE("device service iface_cast failed");
}
return deviceInfoService_;
}
void DeviceInfoKits::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
DelayedRefSingleton<DeviceInfoKits>::GetInstance().ResetService(remote);
}
int32_t DeviceInfoKits::GetUdid(std::string& result)
{
auto deviceService = GetService();
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager");
return deviceService->GetUdid(result);
}
int32_t DeviceInfoKits::GetSerialID(std::string& result)
{
auto deviceService = GetService();
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager");
return deviceService->GetSerialID(result);
}
} // namespace device_info
} // namespace OHOS
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "device_info_proxy.h"
#include "beget_ext.h"
#include "idevice_info.h"
#include "parcel.h"
#include "string_ex.h"
namespace OHOS {
namespace device_info {
int32_t DeviceInfoProxy::GetUdid(std::string& result)
{
MessageParcel data;
MessageParcel reply;
MessageOption option { MessageOption::TF_SYNC };
data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
int32_t ret = Remote()->SendRequest(COMMAND_GET_UDID, data, reply, option);
DINFO_CHECK(ret == ERR_NONE, return ret, "getUdid failed, error code is %d", ret);
result = Str16ToStr8(reply.ReadString16());
return ERR_OK;
}
int32_t DeviceInfoProxy::GetSerialID(std::string& result)
{
MessageParcel data;
MessageParcel reply;
MessageOption option { MessageOption::TF_SYNC };
data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
int32_t ret = Remote()->SendRequest(COMMAND_GET_SERIAL_ID, data, reply, option);
DINFO_CHECK(ret == ERR_NONE, return ret, "GetSerial failed, error code is %d", ret);
result = Str16ToStr8(reply.ReadString16());
return ERR_OK;
}
} // namespace device_info
} // namespace OHOS
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "device_info_proxy.h"
#include "beget_ext.h"
#include "idevice_info.h"
#include "parcel.h"
#include "string_ex.h"
namespace OHOS {
namespace device_info {
int32_t DeviceInfoProxy::GetUdid(std::string& result)
{
MessageParcel data;
MessageParcel reply;
MessageOption option { MessageOption::TF_SYNC };
data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
int32_t ret = Remote()->SendRequest(COMMAND_GET_UDID, data, reply, option);
DINFO_CHECK(ret == ERR_NONE, return ret, "getUdid failed, error code is %d", ret);
result = Str16ToStr8(reply.ReadString16());
return ERR_OK;
}
int32_t DeviceInfoProxy::GetSerialID(std::string& result)
{
MessageParcel data;
MessageParcel reply;
MessageOption option { MessageOption::TF_SYNC };
data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
int32_t ret = Remote()->SendRequest(COMMAND_GET_SERIAL_ID, data, reply, option);
DINFO_CHECK(ret == ERR_NONE, return ret, "GetSerial failed, error code is %d", ret);
result = Str16ToStr8(reply.ReadString16());
return ERR_OK;
}
} // namespace device_info
} // namespace OHOS
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "device_info_stub.h"
#include "beget_ext.h"
#include "idevice_info.h"
#include "ipc_skeleton.h"
#include "accesstoken_kit.h"
#include "parcel.h"
#include "string_ex.h"
#include "system_ability_definition.h"
#include "param_comm.h"
using std::u16string;
namespace OHOS {
using namespace Security;
using namespace Security::AccessToken;
namespace device_info {
REGISTER_SYSTEM_ABILITY_BY_ID(DeviceInfoService, SYSPARAM_DEVICE_SERVICE_ID, true)
int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code,
MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
std::u16string myDescripter = IDeviceInfo::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
DINFO_CHECK(myDescripter == remoteDescripter, return ERR_INVALD_DESC, "Invalid remoteDescripter");
int ret = ERR_FAIL;
switch (code) {
case COMMAND_GET_UDID: {
if (!CheckPermission(data, PERMISSION_UDID)) {
return ERR_FAIL;
}
char localDeviceInfo[UDID_LEN] = {0};
ret = GetDevUdid_(localDeviceInfo, UDID_LEN);
DINFO_CHECK(ret == 0, break, "Failed to get dev udid");
reply.WriteString16(Str8ToStr16(localDeviceInfo));
break;
}
case COMMAND_GET_SERIAL_ID: {
if (!CheckPermission(data, PERMISSION_UDID)) {
return ERR_FAIL;
}
const char *serialNumber = GetSerial_();
DINFO_CHECK(serialNumber != nullptr, break, "Failed to get serialNumber");
reply.WriteString16(Str8ToStr16(serialNumber));
break;
}
default: {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
return ret;
}
bool DeviceInfoStub::CheckPermission(MessageParcel &data, const std::string &permission)
{
AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
int32_t result = TypePermissionState::PERMISSION_GRANTED;
int32_t tokenType = AccessTokenKit::GetTokenTypeFlag(callerToken);
if (tokenType == TOKEN_NATIVE) {
result = AccessTokenKit::VerifyNativeToken(callerToken, permission);
} else if (tokenType == TOKEN_HAP) {
result = AccessTokenKit::VerifyAccessToken(callerToken, permission);
} else {
DINFO_LOGE("AccessToken type:%d, permission:%d denied!", tokenType, callerToken);
return false;
}
if (result == TypePermissionState::PERMISSION_DENIED) {
DINFO_LOGE("AccessTokenID:%d, permission:%s denied!", callerToken, permission.c_str());
return false;
}
DINFO_LOGI("tokenType %d dAccessTokenID:%d, permission:%s matched!", tokenType, callerToken, permission.c_str());
return true;
}
int32_t DeviceInfoService::GetUdid(std::string& result)
{
return 0;
}
int32_t DeviceInfoService::GetSerialID(std::string& result)
{
return 0;
}
void DeviceInfoService::OnStart(void)
{
DINFO_LOGI("WatcherManager OnStart");
bool res = Publish(this);
if (!res) {
DINFO_LOGE("WatcherManager Publish failed");
}
return;
}
void DeviceInfoService::OnStop()
{
}
} // namespace device_info
} // namespace OHOS
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "device_info_stub.h"
#include "beget_ext.h"
#include "idevice_info.h"
#include "ipc_skeleton.h"
#include "accesstoken_kit.h"
#include "parcel.h"
#include "string_ex.h"
#include "system_ability_definition.h"
#include "param_comm.h"
using std::u16string;
namespace OHOS {
using namespace Security;
using namespace Security::AccessToken;
namespace device_info {
REGISTER_SYSTEM_ABILITY_BY_ID(DeviceInfoService, SYSPARAM_DEVICE_SERVICE_ID, true)
int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code,
MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
std::u16string myDescripter = IDeviceInfo::GetDescriptor();
std::u16string remoteDescripter = data.ReadInterfaceToken();
DINFO_CHECK(myDescripter == remoteDescripter, return ERR_INVALD_DESC, "Invalid remoteDescripter");
int ret = ERR_FAIL;
switch (code) {
case COMMAND_GET_UDID: {
if (!CheckPermission(data, PERMISSION_UDID)) {
return ERR_FAIL;
}
char localDeviceInfo[UDID_LEN] = {0};
ret = GetDevUdid_(localDeviceInfo, UDID_LEN);
DINFO_CHECK(ret == 0, break, "Failed to get dev udid");
reply.WriteString16(Str8ToStr16(localDeviceInfo));
break;
}
case COMMAND_GET_SERIAL_ID: {
if (!CheckPermission(data, PERMISSION_UDID)) {
return ERR_FAIL;
}
const char *serialNumber = GetSerial_();
DINFO_CHECK(serialNumber != nullptr, break, "Failed to get serialNumber");
reply.WriteString16(Str8ToStr16(serialNumber));
break;
}
default: {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}
}
return ret;
}
bool DeviceInfoStub::CheckPermission(MessageParcel &data, const std::string &permission)
{
AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
int32_t result = TypePermissionState::PERMISSION_GRANTED;
int32_t tokenType = AccessTokenKit::GetTokenTypeFlag(callerToken);
if (tokenType == TOKEN_NATIVE) {
result = AccessTokenKit::VerifyNativeToken(callerToken, permission);
} else if (tokenType == TOKEN_HAP) {
result = AccessTokenKit::VerifyAccessToken(callerToken, permission);
} else {
DINFO_LOGE("AccessToken type:%d, permission:%d denied!", tokenType, callerToken);
return false;
}
if (result == TypePermissionState::PERMISSION_DENIED) {
DINFO_LOGE("AccessTokenID:%d, permission:%s denied!", callerToken, permission.c_str());
return false;
}
DINFO_LOGI("tokenType %d dAccessTokenID:%d, permission:%s matched!", tokenType, callerToken, permission.c_str());
return true;
}
int32_t DeviceInfoService::GetUdid(std::string& result)
{
return 0;
}
int32_t DeviceInfoService::GetSerialID(std::string& result)
{
return 0;
}
void DeviceInfoService::OnStart(void)
{
DINFO_LOGI("WatcherManager OnStart");
bool res = Publish(this);
if (!res) {
DINFO_LOGE("WatcherManager Publish failed");
}
return;
}
void DeviceInfoService::OnStop()
{
}
} // namespace device_info
} // namespace OHOS
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* 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 "param_wrapper.h"
#include <unordered_map>
#include <vector>
#include <climits>
#include "beget_ext.h"
#include "param_comm.h"
#include "init_param.h"
#include "sysparam_errno.h"
#include "securec.h"
#include "parameter.h"
#include "parameters.h"
namespace OHOS {
namespace system {
bool SetParameter(const std::string& key, const std::string& value)
{
int ret = SystemSetParameter(key.c_str(), value.c_str());
return (ret == 0) ? true : false;
}
template<typename T>
bool StringToInt(const std::string& str, T min, T max, T& out)
{
long long int result = 0;
if (StringToLL(str.c_str(), &result) != 0) {
return false;
}
if (result < min || max < result) {
return false;
}
out = static_cast<T>(result);
return true;
}
template<typename T>
bool StringToUint(const std::string& str, T max, T& out)
{
unsigned long long int result = 0;
if (StringToULL(str.c_str(), &result) != 0) {
return false;
}
if (max < result) {
return false;
}
out = static_cast<T>(result);
return true;
}
std::string GetParameter(const std::string& key, const std::string& def)
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret == 0) {
std::vector<char> value(size + 1);
ret = SystemReadParam(key.c_str(), value.data(), &size);
if (ret == 0) {
return std::string(value.data());
}
}
if (IsValidParamValue(def.c_str(), MAX_VALUE_LEN) == 1) {
return std::string(def);
}
return "";
}
bool GetBoolParameter(const std::string& key, bool def)
{
static const std::string trueMap[] = { "1", "y", "yes", "on", "true" };
static const std::string falseMap[] = { "0", "off", "n", "no", "false" };
std::string value = GetParameter(key, "");
for (size_t i = 0; i < sizeof(trueMap) / sizeof(trueMap[0]); i++) {
if (trueMap[i] == value) {
return true;
}
}
for (size_t i = 0; i < sizeof(falseMap) / sizeof(falseMap[0]); i++) {
if (falseMap[i] == value) {
return false;
}
}
return def;
}
int GetStringParameter(const std::string key, std::string &value, const std::string def)
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret == 0) {
std::vector<char> data(size + 1);
ret = SystemReadParam(key.c_str(), data.data(), &size);
if (ret == 0) {
value = std::string(data.data());
return EC_SUCCESS;
}
}
if (IsValidParamValue(def.c_str(), MAX_VALUE_LEN) == 1) {
value = std::string(def);
return EC_SUCCESS;
}
return EC_FAILURE;
}
template<typename T>
T GetIntParameter(const std::string& key, T def, T min, T max)
{
if (!std::is_signed<T>::value) {
return def;
}
T result;
std::string value = GetParameter(key, "");
if (!value.empty() && StringToInt(value, min, max, result)) {
return result;
}
return def;
}
template int8_t GetIntParameter(const std::string&, int8_t, int8_t, int8_t);
template int16_t GetIntParameter(const std::string&, int16_t, int16_t, int16_t);
template int32_t GetIntParameter(const std::string&, int32_t, int32_t, int32_t);
template int64_t GetIntParameter(const std::string&, int64_t, int64_t, int64_t);
template<typename T>
T GetUintParameter(const std::string& key, T def, T max)
{
if (!std::is_unsigned<T>::value) {
return def;
}
T result;
std::string value = GetParameter(key, "");
if (!value.empty() && StringToUint(value, max, result)) {
return result;
}
return def;
}
template uint8_t GetUintParameter(const std::string&, uint8_t, uint8_t);
template uint16_t GetUintParameter(const std::string&, uint16_t, uint16_t);
template uint32_t GetUintParameter(const std::string&, uint32_t, uint32_t);
template uint64_t GetUintParameter(const std::string&, uint64_t, uint64_t);
std::string GetDeviceType(void)
{
std::unordered_map<std::string, std::string> deviceTypeMap = {
{"watch", "wearable"},
{"fitnessWatch", "liteWearable"},
};
static const char *productType = nullptr;
const char *type = GetProperty("const.build.characteristics", &productType);
if (deviceTypeMap.count(type) != 0) {
return deviceTypeMap[type];
}
return std::string(type);
}
int GetIntParameter(const std::string key, int def)
{
return GetIntParameter(key, def, INT_MIN, INT_MAX);
}
} // namespace system
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* 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 "param_wrapper.h"
#include <unordered_map>
#include <vector>
#include <climits>
#include "beget_ext.h"
#include "param_comm.h"
#include "init_param.h"
#include "sysparam_errno.h"
#include "securec.h"
#include "parameter.h"
#include "parameters.h"
namespace OHOS {
namespace system {
bool SetParameter(const std::string& key, const std::string& value)
{
int ret = SystemSetParameter(key.c_str(), value.c_str());
return (ret == 0) ? true : false;
}
template<typename T>
bool StringToInt(const std::string& str, T min, T max, T& out)
{
long long int result = 0;
if (StringToLL(str.c_str(), &result) != 0) {
return false;
}
if (result < min || max < result) {
return false;
}
out = static_cast<T>(result);
return true;
}
template<typename T>
bool StringToUint(const std::string& str, T max, T& out)
{
unsigned long long int result = 0;
if (StringToULL(str.c_str(), &result) != 0) {
return false;
}
if (max < result) {
return false;
}
out = static_cast<T>(result);
return true;
}
std::string GetParameter(const std::string& key, const std::string& def)
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret == 0) {
std::vector<char> value(size + 1);
ret = SystemReadParam(key.c_str(), value.data(), &size);
if (ret == 0) {
return std::string(value.data());
}
}
if (IsValidParamValue(def.c_str(), MAX_VALUE_LEN) == 1) {
return std::string(def);
}
return "";
}
bool GetBoolParameter(const std::string& key, bool def)
{
static const std::string trueMap[] = { "1", "y", "yes", "on", "true" };
static const std::string falseMap[] = { "0", "off", "n", "no", "false" };
std::string value = GetParameter(key, "");
for (size_t i = 0; i < sizeof(trueMap) / sizeof(trueMap[0]); i++) {
if (trueMap[i] == value) {
return true;
}
}
for (size_t i = 0; i < sizeof(falseMap) / sizeof(falseMap[0]); i++) {
if (falseMap[i] == value) {
return false;
}
}
return def;
}
int GetStringParameter(const std::string key, std::string &value, const std::string def)
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret == 0) {
std::vector<char> data(size + 1);
ret = SystemReadParam(key.c_str(), data.data(), &size);
if (ret == 0) {
value = std::string(data.data());
return EC_SUCCESS;
}
}
if (IsValidParamValue(def.c_str(), MAX_VALUE_LEN) == 1) {
value = std::string(def);
return EC_SUCCESS;
}
return EC_FAILURE;
}
template<typename T>
T GetIntParameter(const std::string& key, T def, T min, T max)
{
if (!std::is_signed<T>::value) {
return def;
}
T result;
std::string value = GetParameter(key, "");
if (!value.empty() && StringToInt(value, min, max, result)) {
return result;
}
return def;
}
template int8_t GetIntParameter(const std::string&, int8_t, int8_t, int8_t);
template int16_t GetIntParameter(const std::string&, int16_t, int16_t, int16_t);
template int32_t GetIntParameter(const std::string&, int32_t, int32_t, int32_t);
template int64_t GetIntParameter(const std::string&, int64_t, int64_t, int64_t);
template<typename T>
T GetUintParameter(const std::string& key, T def, T max)
{
if (!std::is_unsigned<T>::value) {
return def;
}
T result;
std::string value = GetParameter(key, "");
if (!value.empty() && StringToUint(value, max, result)) {
return result;
}
return def;
}
template uint8_t GetUintParameter(const std::string&, uint8_t, uint8_t);
template uint16_t GetUintParameter(const std::string&, uint16_t, uint16_t);
template uint32_t GetUintParameter(const std::string&, uint32_t, uint32_t);
template uint64_t GetUintParameter(const std::string&, uint64_t, uint64_t);
std::string GetDeviceType(void)
{
std::unordered_map<std::string, std::string> deviceTypeMap = {
{"watch", "wearable"},
{"fitnessWatch", "liteWearable"},
};
static const char *productType = nullptr;
const char *type = GetProperty("const.build.characteristics", &productType);
if (deviceTypeMap.count(type) != 0) {
return deviceTypeMap[type];
}
return std::string(type);
}
int GetIntParameter(const std::string key, int def)
{
return GetIntParameter(key, def, INT_MIN, INT_MAX);
}
} // namespace system
} // namespace OHOS
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "begetctl.h"
#include "param_stub.h"
#include "securec.h"
#include "shell.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class BegetctlUnitTest : public testing::Test {
public:
static void SetUpTestCase(void)
{
PrepareInitUnitTestEnv();
};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
HWTEST_F(BegetctlUnitTest, TestShellInit, TestSize.Level0)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param"
};
BShellEnvDirectExecute(GetShellHandle(), 1, (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLs, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "ls"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsWithR, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "ls", "-r"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsGet, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "get"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellSet, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "set", "aaaaa", "1234567"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellGetWithKey, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "get", "aaaaa"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellWait, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "wait", "aaaaa"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellWaitFalse, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "wait"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellWaitWithKey, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "wait", "aaaaa", "12*", "30"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellParamShell, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "shell"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsWithvalue, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
BShellEnvSetParam(GetShellHandle(), PARAM_REVERESD_NAME_CURR_PARAMETER, "..a", PARAM_STRING, (void *)"..a");
const char *args[] = {
"param", "ls", PARAM_REVERESD_NAME_CURR_PARAMETER
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsWithvalueExist, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
BShellEnvSetParam(GetShellHandle(), PARAM_REVERESD_NAME_CURR_PARAMETER, "#", PARAM_STRING, (void *)"#");
const char *args[] = {
"param", "ls", "-r", PARAM_REVERESD_NAME_CURR_PARAMETER
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "begetctl.h"
#include "param_stub.h"
#include "securec.h"
#include "shell.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class BegetctlUnitTest : public testing::Test {
public:
static void SetUpTestCase(void)
{
PrepareInitUnitTestEnv();
};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
HWTEST_F(BegetctlUnitTest, TestShellInit, TestSize.Level0)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param"
};
BShellEnvDirectExecute(GetShellHandle(), 1, (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLs, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "ls"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsWithR, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "ls", "-r"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsGet, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "get"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellSet, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "set", "aaaaa", "1234567"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellGetWithKey, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "get", "aaaaa"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellWait, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "wait", "aaaaa"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellWaitFalse, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "wait"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellWaitWithKey, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "wait", "aaaaa", "12*", "30"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellParamShell, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
const char *args[] = {
"param", "shell"
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsWithvalue, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
BShellEnvSetParam(GetShellHandle(), PARAM_REVERESD_NAME_CURR_PARAMETER, "..a", PARAM_STRING, (void *)"..a");
const char *args[] = {
"param", "ls", PARAM_REVERESD_NAME_CURR_PARAMETER
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
HWTEST_F(BegetctlUnitTest, TestShellLsWithvalueExist, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
BShellEnvSetParam(GetShellHandle(), PARAM_REVERESD_NAME_CURR_PARAMETER, "#", PARAM_STRING, (void *)"#");
const char *args[] = {
"param", "ls", "-r", PARAM_REVERESD_NAME_CURR_PARAMETER
};
BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), (char **)args);
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 <sys/statvfs.h>
#include "init_cmds.h"
#include "init_reboot.h"
#include "init_param.h"
#include "param_stub.h"
#include "init_utils.h"
#include "trigger_manager.h"
#include "init_group_manager.h"
using namespace testing::ext;
using namespace std;
namespace init_ut {
class InitRebootUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp() {};
void TearDown() {};
};
HWTEST_F(InitRebootUnitTest, TestInitReboot, TestSize.Level1)
{
ExecReboot("reboot");
ExecReboot("reboot,shutdown");
ExecReboot("reboot,bootloader");
ExecReboot("reboot,updater:123");
ExecReboot("reboot,flash:123");
ExecReboot("reboot,flashd:123");
ExecReboot("reboot,suspend:123");
const char *option = nullptr;
int ret = DoReboot(option);
EXPECT_EQ(ret, 0);
option = "updater";
ret = DoReboot(option);
EXPECT_EQ(ret, 0);
ret = DoReboot(DEVICE_CMD_SUSPEND);
EXPECT_EQ(ret, 0);
ret = DoReboot(DEVICE_CMD_FREEZE);
EXPECT_EQ(ret, 0);
clearMisc();
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 <sys/statvfs.h>
#include "init_cmds.h"
#include "init_reboot.h"
#include "init_param.h"
#include "param_stub.h"
#include "init_utils.h"
#include "trigger_manager.h"
#include "init_group_manager.h"
using namespace testing::ext;
using namespace std;
namespace init_ut {
class InitRebootUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp() {};
void TearDown() {};
};
HWTEST_F(InitRebootUnitTest, TestInitReboot, TestSize.Level1)
{
ExecReboot("reboot");
ExecReboot("reboot,shutdown");
ExecReboot("reboot,bootloader");
ExecReboot("reboot,updater:123");
ExecReboot("reboot,flash:123");
ExecReboot("reboot,flashd:123");
ExecReboot("reboot,suspend:123");
const char *option = nullptr;
int ret = DoReboot(option);
EXPECT_EQ(ret, 0);
option = "updater";
ret = DoReboot(option);
EXPECT_EQ(ret, 0);
ret = DoReboot(DEVICE_CMD_SUSPEND);
EXPECT_EQ(ret, 0);
ret = DoReboot(DEVICE_CMD_FREEZE);
EXPECT_EQ(ret, 0);
clearMisc();
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "init_cmds.h"
#include "init_group_manager.h"
#include "init_hashmap.h"
#include "init_param.h"
#include "init_module_engine.h"
#include "init_cmdexecutor.h"
#include "param_stub.h"
#include "init_utils.h"
#include "securec.h"
using namespace testing::ext;
using namespace std;
namespace init_ut {
class ModuleMgrUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
int g_cmdExecId = 0;
int TestCmdExecutor(int id, const char *name, int argc, const char **argv)
{
printf("TestCmdExecutor id %d, name %s \n", id, name);
g_cmdExecId = id;
return 0;
}
HWTEST_F(ModuleMgrUnitTest, PluginAddCmd, TestSize.Level1)
{
InitServiceSpace();
const char *testName = "testCmd1";
const char *cmdContent = "testCmd1 test1 test2 test3";
const char *cmdContentNotValid = "testCmd1 t e s t 1 t e s t 2 t";
int cmdExecId1 = AddCmdExecutor(testName, TestCmdExecutor);
ASSERT_NE(cmdExecId1 > 0, 0);
int cmdExecId2 = AddCmdExecutor("testCmd2", TestCmdExecutor);
ASSERT_NE(cmdExecId2 > 0, 0);
cmdExecId2 = AddCmdExecutor("testCmd3", TestCmdExecutor);
ASSERT_NE(cmdExecId2 > 0, 0);
int cmdExecId4 = AddCmdExecutor("testCmd4", TestCmdExecutor);
ASSERT_NE(cmdExecId4 > 0, 0);
PluginExecCmd("testCmd4", 0, nullptr);
int cmdIndex = 0;
const char *cmdName = PluginGetCmdIndex(cmdContent, &cmdIndex);
ASSERT_EQ(strcmp(cmdName, testName), 0);
printf("TestCmdExecutor cmdIndex 0x%04x, name %s \n", cmdIndex, cmdName);
// exec
g_cmdExecId = -1;
PluginExecCmdByName(cmdName, cmdContent);
ASSERT_EQ(cmdExecId1, g_cmdExecId);
PluginExecCmdByName(cmdName, nullptr);
PluginExecCmdByName(cmdName, cmdContentNotValid);
g_cmdExecId = -1;
PluginExecCmdByCmdIndex(cmdIndex, cmdContent);
ASSERT_EQ(cmdExecId1, g_cmdExecId);
const char *argv[] = {"test"};
PluginExecCmd("install", 1, argv);
PluginExecCmd("uninstall", 1, argv);
// del
RemoveCmdExecutor("testCmd4", cmdExecId4);
}
HWTEST_F(ModuleMgrUnitTest, ModuleInstallTest, TestSize.Level1)
{
int ret;
int cnt;
// Create module manager
MODULE_MGR *moduleMgr = ModuleMgrCreate("init");
ASSERT_NE(moduleMgr, nullptr);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
// Install one module
ret = ModuleMgrInstall(moduleMgr, "libbootchart", 0, NULL);
ASSERT_EQ(ret, 0);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 1);
// Uninstall the module
ModuleMgrUninstall(moduleMgr, "libbootchart");
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
// Install two module
ret = ModuleMgrInstall(moduleMgr, "libbootchart", 0, NULL);
ASSERT_EQ(ret, 0);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 1);
ret = ModuleMgrInstall(moduleMgr, "notexist", 0, NULL);
ASSERT_NE(ret, 0);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 1);
// Uninstall the module
ModuleMgrUninstall(moduleMgr, "libbootchart");
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
ModuleMgrUninstall(moduleMgr, "notexist");
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
ModuleMgrDestroy(moduleMgr);
// Scan all modules
moduleMgr = ModuleMgrScan("init");
ASSERT_NE(moduleMgr, nullptr);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_NE(cnt, 0);
ModuleMgrUninstall(moduleMgr, NULL);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
ModuleMgrGetArgs();
ModuleMgrDestroy(moduleMgr);
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 "init_cmds.h"
#include "init_group_manager.h"
#include "init_hashmap.h"
#include "init_param.h"
#include "init_module_engine.h"
#include "init_cmdexecutor.h"
#include "param_stub.h"
#include "init_utils.h"
#include "securec.h"
using namespace testing::ext;
using namespace std;
namespace init_ut {
class ModuleMgrUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
};
int g_cmdExecId = 0;
int TestCmdExecutor(int id, const char *name, int argc, const char **argv)
{
printf("TestCmdExecutor id %d, name %s \n", id, name);
g_cmdExecId = id;
return 0;
}
HWTEST_F(ModuleMgrUnitTest, PluginAddCmd, TestSize.Level1)
{
InitServiceSpace();
const char *testName = "testCmd1";
const char *cmdContent = "testCmd1 test1 test2 test3";
const char *cmdContentNotValid = "testCmd1 t e s t 1 t e s t 2 t";
int cmdExecId1 = AddCmdExecutor(testName, TestCmdExecutor);
ASSERT_NE(cmdExecId1 > 0, 0);
int cmdExecId2 = AddCmdExecutor("testCmd2", TestCmdExecutor);
ASSERT_NE(cmdExecId2 > 0, 0);
cmdExecId2 = AddCmdExecutor("testCmd3", TestCmdExecutor);
ASSERT_NE(cmdExecId2 > 0, 0);
int cmdExecId4 = AddCmdExecutor("testCmd4", TestCmdExecutor);
ASSERT_NE(cmdExecId4 > 0, 0);
PluginExecCmd("testCmd4", 0, nullptr);
int cmdIndex = 0;
const char *cmdName = PluginGetCmdIndex(cmdContent, &cmdIndex);
ASSERT_EQ(strcmp(cmdName, testName), 0);
printf("TestCmdExecutor cmdIndex 0x%04x, name %s \n", cmdIndex, cmdName);
// exec
g_cmdExecId = -1;
PluginExecCmdByName(cmdName, cmdContent);
ASSERT_EQ(cmdExecId1, g_cmdExecId);
PluginExecCmdByName(cmdName, nullptr);
PluginExecCmdByName(cmdName, cmdContentNotValid);
g_cmdExecId = -1;
PluginExecCmdByCmdIndex(cmdIndex, cmdContent);
ASSERT_EQ(cmdExecId1, g_cmdExecId);
const char *argv[] = {"test"};
PluginExecCmd("install", 1, argv);
PluginExecCmd("uninstall", 1, argv);
// del
RemoveCmdExecutor("testCmd4", cmdExecId4);
}
HWTEST_F(ModuleMgrUnitTest, ModuleInstallTest, TestSize.Level1)
{
int ret;
int cnt;
// Create module manager
MODULE_MGR *moduleMgr = ModuleMgrCreate("init");
ASSERT_NE(moduleMgr, nullptr);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
// Install one module
ret = ModuleMgrInstall(moduleMgr, "libbootchart", 0, NULL);
ASSERT_EQ(ret, 0);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 1);
// Uninstall the module
ModuleMgrUninstall(moduleMgr, "libbootchart");
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
// Install two module
ret = ModuleMgrInstall(moduleMgr, "libbootchart", 0, NULL);
ASSERT_EQ(ret, 0);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 1);
ret = ModuleMgrInstall(moduleMgr, "notexist", 0, NULL);
ASSERT_NE(ret, 0);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 1);
// Uninstall the module
ModuleMgrUninstall(moduleMgr, "libbootchart");
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
ModuleMgrUninstall(moduleMgr, "notexist");
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
ModuleMgrDestroy(moduleMgr);
// Scan all modules
moduleMgr = ModuleMgrScan("init");
ASSERT_NE(moduleMgr, nullptr);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_NE(cnt, 0);
ModuleMgrUninstall(moduleMgr, NULL);
cnt = ModuleMgrGetCnt(moduleMgr);
ASSERT_EQ(cnt, 0);
ModuleMgrGetArgs();
ModuleMgrDestroy(moduleMgr);
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 <gtest/gtest.h>
#include "begetctl.h"
#include "securec.h"
#include "shell.h"
#include "shell_utils.h"
#include "shell_bas.h"
#include "init_param.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class ParamShellUnitTest : public testing::Test {
public:
ParamShellUnitTest() {};
virtual ~ParamShellUnitTest() {};
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
void TestBody(void) {};
void TestInitParamShell()
{
SystemSetParameter("aaa", "aaa");
BShellHandle bshd = GetShellHandle();
if (bshd == nullptr) {
return;
}
const char *args[] = {"paramshell", "\n"};
const ParamInfo *param = BShellEnvGetReservedParam(bshd, PARAM_REVERESD_NAME_CURR_PARAMETER);
int ret = BShellEnvSetParam(bshd, PARAM_REVERESD_NAME_CURR_PARAMETER, "..a", PARAM_STRING, (void *)"..a");
EXPECT_EQ(ret, 0);
SetParamShellPrompt(bshd, args[1]);
SetParamShellPrompt(bshd, "..");
ret = BShellEnvSetParam(bshd, param->name, param->desc, param->type, (void *)"");
SetParamShellPrompt(bshd, "..");
SetParamShellPrompt(bshd, ".a");
SetParamShellPrompt(bshd, ".");
SetParamShellPrompt(bshd, args[1]);
BShellParamCmdRegister(bshd, 1);
BShellEnvStart(bshd);
ret = BShellEnvOutputPrompt(bshd, "testprompt");
ret = BShellEnvOutputPrompt(bshd, "testprompt1111111111111111111111111111111111111111111111111111111111");
BShellEnvOutputByte(bshd, 'o');
EXPECT_EQ(ret, 0);
}
void TestParamShellCmd()
{
BShellHandle bshd = GetShellHandle();
BShellKey *key = BShellEnvGetDefaultKey('\n');
EXPECT_NE(key, nullptr);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "cd const") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
int ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "cat aaa") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testnotcmd") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
// test param start with "
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "\"ls") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
// test argc is 0
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), ",ls") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "$test$") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "exit") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
}
void TestParamShellCmd1()
{
BShellHandle bshd = GetShellHandle();
BShellKey *key = BShellEnvGetDefaultKey('\n');
EXPECT_NE(key, nullptr);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "pwd") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
int ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "help") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "dump") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "dump verbose") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
}
void TestParamShellcmdEndkey()
{
BShellHandle bshd = GetShellHandle();
bshd->input(nullptr, 0);
BShellKey *key = BShellEnvGetDefaultKey('\b');
EXPECT_NE(key, nullptr);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testbbackspace") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
bshd->cursor = strlen("testb");
int ret = key->keyHandle(bshd, '\b');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testbbackspace") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
bshd->cursor = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\b');
EXPECT_EQ(ret, 0);
key = BShellEnvGetDefaultKey('\t');
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testtab") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\t');
EXPECT_NE(key, nullptr);
BShellEnvProcessInput(bshd, (char)3); // 3 is ctrl c
BShellEnvProcessInput(bshd, '\e');
BShellEnvProcessInput(bshd, '[');
bshd->length = 1;
bshd->cursor = 1;
BShellEnvProcessInput(bshd, 'C');
BShellEnvProcessInput(bshd, 'D');
}
};
HWTEST_F(ParamShellUnitTest, TestInitParamShell, TestSize.Level1)
{
ParamShellUnitTest test;
test.TestInitParamShell();
test.TestParamShellCmd();
test.TestParamShellCmd1();
}
HWTEST_F(ParamShellUnitTest, TestParamShellInput, TestSize.Level1)
{
BShellHandle bshd = GetShellHandle();
BShellEnvProcessInput(bshd, '\n');
BShellEnvProcessInput(bshd, 'l');
bshd->length = BSH_COMMAND_MAX_LENGTH;
BShellEnvProcessInput(bshd, 'l');
bshd->length = sizeof('l');
bshd->cursor = 0;
BShellEnvProcessInput(bshd, 's');
BShellEnvProcessInput(bshd, '\n');
BShellEnvProcessInput(bshd, '\n'); // test bshd buff length is 0
int ret = BShellEnvRegisterKeyHandle(bshd, 'z', (BShellkeyHandle)(void*)0x409600); // 0x409600 construct address
EXPECT_EQ(ret, 0);
}
HWTEST_F(ParamShellUnitTest, TestParamShellcmd2, TestSize.Level1)
{
ParamShellUnitTest test;
test.TestParamShellcmdEndkey();
GetSystemCommitId();
BShellEnvLoop(nullptr);
BShellEnvErrString(GetShellHandle(), 1);
BShellEnvOutputResult(GetShellHandle(), 1);
demoExit();
}
} // namespace init_ut
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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 <gtest/gtest.h>
#include "begetctl.h"
#include "securec.h"
#include "shell.h"
#include "shell_utils.h"
#include "shell_bas.h"
#include "init_param.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
class ParamShellUnitTest : public testing::Test {
public:
ParamShellUnitTest() {};
virtual ~ParamShellUnitTest() {};
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp(void) {};
void TearDown(void) {};
void TestBody(void) {};
void TestInitParamShell()
{
SystemSetParameter("aaa", "aaa");
BShellHandle bshd = GetShellHandle();
if (bshd == nullptr) {
return;
}
const char *args[] = {"paramshell", "\n"};
const ParamInfo *param = BShellEnvGetReservedParam(bshd, PARAM_REVERESD_NAME_CURR_PARAMETER);
int ret = BShellEnvSetParam(bshd, PARAM_REVERESD_NAME_CURR_PARAMETER, "..a", PARAM_STRING, (void *)"..a");
EXPECT_EQ(ret, 0);
SetParamShellPrompt(bshd, args[1]);
SetParamShellPrompt(bshd, "..");
ret = BShellEnvSetParam(bshd, param->name, param->desc, param->type, (void *)"");
SetParamShellPrompt(bshd, "..");
SetParamShellPrompt(bshd, ".a");
SetParamShellPrompt(bshd, ".");
SetParamShellPrompt(bshd, args[1]);
BShellParamCmdRegister(bshd, 1);
BShellEnvStart(bshd);
ret = BShellEnvOutputPrompt(bshd, "testprompt");
ret = BShellEnvOutputPrompt(bshd, "testprompt1111111111111111111111111111111111111111111111111111111111");
BShellEnvOutputByte(bshd, 'o');
EXPECT_EQ(ret, 0);
}
void TestParamShellCmd()
{
BShellHandle bshd = GetShellHandle();
BShellKey *key = BShellEnvGetDefaultKey('\n');
EXPECT_NE(key, nullptr);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "cd const") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
int ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "cat aaa") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testnotcmd") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
// test param start with "
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "\"ls") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
// test argc is 0
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), ",ls") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "$test$") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "exit") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
}
void TestParamShellCmd1()
{
BShellHandle bshd = GetShellHandle();
BShellKey *key = BShellEnvGetDefaultKey('\n');
EXPECT_NE(key, nullptr);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "pwd") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
int ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "help") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "dump") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "dump verbose") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\n');
EXPECT_EQ(ret, 0);
}
void TestParamShellcmdEndkey()
{
BShellHandle bshd = GetShellHandle();
bshd->input(nullptr, 0);
BShellKey *key = BShellEnvGetDefaultKey('\b');
EXPECT_NE(key, nullptr);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testbbackspace") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
bshd->cursor = strlen("testb");
int ret = key->keyHandle(bshd, '\b');
EXPECT_EQ(ret, 0);
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testbbackspace") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
bshd->cursor = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\b');
EXPECT_EQ(ret, 0);
key = BShellEnvGetDefaultKey('\t');
if (strcpy_s(bshd->buffer, sizeof(bshd->buffer), "testtab") != EOK) {
return;
}
bshd->length = strlen(bshd->buffer);
ret = key->keyHandle(bshd, '\t');
EXPECT_NE(key, nullptr);
BShellEnvProcessInput(bshd, (char)3); // 3 is ctrl c
BShellEnvProcessInput(bshd, '\e');
BShellEnvProcessInput(bshd, '[');
bshd->length = 1;
bshd->cursor = 1;
BShellEnvProcessInput(bshd, 'C');
BShellEnvProcessInput(bshd, 'D');
}
};
HWTEST_F(ParamShellUnitTest, TestInitParamShell, TestSize.Level1)
{
ParamShellUnitTest test;
test.TestInitParamShell();
test.TestParamShellCmd();
test.TestParamShellCmd1();
}
HWTEST_F(ParamShellUnitTest, TestParamShellInput, TestSize.Level1)
{
BShellHandle bshd = GetShellHandle();
BShellEnvProcessInput(bshd, '\n');
BShellEnvProcessInput(bshd, 'l');
bshd->length = BSH_COMMAND_MAX_LENGTH;
BShellEnvProcessInput(bshd, 'l');
bshd->length = sizeof('l');
bshd->cursor = 0;
BShellEnvProcessInput(bshd, 's');
BShellEnvProcessInput(bshd, '\n');
BShellEnvProcessInput(bshd, '\n'); // test bshd buff length is 0
int ret = BShellEnvRegisterKeyHandle(bshd, 'z', (BShellkeyHandle)(void*)0x409600); // 0x409600 construct address
EXPECT_EQ(ret, 0);
}
HWTEST_F(ParamShellUnitTest, TestParamShellcmd2, TestSize.Level1)
{
ParamShellUnitTest test;
test.TestParamShellcmdEndkey();
GetSystemCommitId();
BShellEnvLoop(nullptr);
BShellEnvErrString(GetShellHandle(), 1);
BShellEnvOutputResult(GetShellHandle(), 1);
demoExit();
}
} // namespace init_ut
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册