CodeCheck问题修改. Signed-off-by: <wanglongjin1@huawei.com>

This commit is contained in:
wanglongjin
2022-05-13 11:00:04 +08:00
parent 10d59f561c
commit ccdb894091
9 changed files with 55 additions and 55 deletions
+1 -1
View File
@@ -36,7 +36,7 @@
#define FORCE_INLINE __attribute__((always_inline)) inline
namespace OHOS::uitest {
using CStr = const char*;
using CStr = const char *;
constexpr size_t INDEX_ZERO = 0;
constexpr size_t INDEX_ONE = 1;
constexpr size_t INDEX_TWO = 2;
+5 -5
View File
@@ -14,8 +14,8 @@
*/
#include <sstream>
#include "frontend_api_handler.h"
#include "ui_driver.h"
#include "frontend_api_handler.h"
namespace OHOS::uitest {
using namespace std;
@@ -101,8 +101,8 @@ namespace OHOS::uitest {
{
static const map<string, nlohmann::detail::value_t> typeMap = {
{"int", nlohmann::detail::value_t::number_unsigned}, {"float", nlohmann::detail::value_t::number_float},
{"bool", nlohmann::detail::value_t::boolean}, {"string", nlohmann::detail::value_t::string},
{"By", nlohmann::detail::value_t::string}, {"UiComponent", nlohmann::detail::value_t::string},
{"bool", nlohmann::detail::value_t::boolean}, {"string", nlohmann::detail::value_t::string},
{"By", nlohmann::detail::value_t::string}, {"UiComponent", nlohmann::detail::value_t::string},
{"UiDriver", nlohmann::detail::value_t::string},
}; // complex-object should be passed with objRef (string type)
constexpr size_t BUF_LEN = 32;
@@ -144,7 +144,7 @@ namespace OHOS::uitest {
auto paramTypes = vector<nlohmann::detail::value_t>();
auto hasDefaultArg = false;
ParseMethodSignature(methodDef.signature_, paramTypes, hasDefaultArg);
sApiArgTypesMap.insert({string(methodDef.name_), {paramTypes, hasDefaultArg}});
sApiArgTypesMap.insert(make_pair(string(methodDef.name_), make_pair(paramTypes, hasDefaultArg)));
}
}
}
@@ -480,7 +480,7 @@ namespace OHOS::uitest {
auto &driver = GetBoundUiDriver(in.callerObjRef_);
WidgetOp op = WidgetOp::CLICK;
UiOpArgs uiOpArgs;
// // these methods accept one option integer argument
// these methods accept one option integer argument
if (in.apiId_ == "UiComponent.click") {
op = WidgetOp::CLICK;
} else if (in.apiId_ == "UiComponent.longClick") {
+1 -1
View File
@@ -83,7 +83,7 @@ namespace OHOS::uitest {
static void RemoveAllControllers();
/**Install UiControllers with registered provider.*/
/**Install UiControllers with registered controllerProvider.*/
static void InstallFromProvider();
/**The the currently active UiController, returns null if none is available.*/
+11 -11
View File
@@ -24,7 +24,7 @@ namespace OHOS::uitest {
class TreeSnapshotTaker : public WidgetVisitor {
public:
explicit TreeSnapshotTaker(stringstream &receiver) : receiver_(receiver){};
explicit TreeSnapshotTaker(stringstream &receiver) : receiver_(receiver) {};
~TreeSnapshotTaker() {}
@@ -204,10 +204,10 @@ namespace OHOS::uitest {
vector<KeyEvent> events;
if (!origText.empty()) {
for (size_t index = 0; index < origText.size(); index++) {
events.emplace_back(KeyEvent{ActionStage::DOWN, 2015, typeCharTimeMs});
events.emplace_back(KeyEvent{ActionStage::UP, 2015, 0});
events.emplace_back(KeyEvent{ActionStage::DOWN, 2055, typeCharTimeMs});
events.emplace_back(KeyEvent{ActionStage::UP, 2055, 0});
events.emplace_back(KeyEvent {ActionStage::DOWN, 2015, typeCharTimeMs});
events.emplace_back(KeyEvent {ActionStage::UP, 2015, 0});
events.emplace_back(KeyEvent {ActionStage::DOWN, 2055, typeCharTimeMs});
events.emplace_back(KeyEvent {ActionStage::UP, 2055, 0});
}
}
if (!text.empty()) {
@@ -224,12 +224,12 @@ namespace OHOS::uitest {
}
for (auto &pair : keyCodes) {
if (pair.second != KEYCODE_NONE) {
events.emplace_back(KeyEvent{ActionStage::DOWN, pair.second, 0});
events.emplace_back(KeyEvent {ActionStage::DOWN, pair.second, 0});
}
events.emplace_back(KeyEvent{ActionStage::DOWN, pair.first, typeCharTimeMs});
events.emplace_back(KeyEvent{ActionStage::UP, pair.first, 0});
events.emplace_back(KeyEvent {ActionStage::DOWN, pair.first, typeCharTimeMs});
events.emplace_back(KeyEvent {ActionStage::UP, pair.first, 0});
if (pair.second != KEYCODE_NONE) {
events.emplace_back(KeyEvent{ActionStage::UP, pair.second, 0});
events.emplace_back(KeyEvent {ActionStage::UP, pair.second, 0});
}
}
}
@@ -334,8 +334,8 @@ namespace OHOS::uitest {
}
auto boundsFrom = widgetFrom->GetBounds();
auto boundsTo = widgetTo->GetBounds();
auto centerFrom = Point{boundsFrom.GetCenterX(), boundsFrom.GetCenterY()};
auto centerTo = Point{boundsTo.GetCenterX(), boundsTo.GetCenterY()};
auto centerFrom = Point(boundsFrom.GetCenterX(), boundsFrom.GetCenterY());
auto centerTo = Point(boundsTo.GetCenterX(), boundsTo.GetCenterY());
InjectGenericSwipe(PointerOp::DRAG_P, centerFrom, centerTo, *uiController_, opt);
}
+4 -4
View File
@@ -47,10 +47,10 @@ namespace OHOS::uitest {
const UiOpArgs& opt, ApiCallErr &err);
/**Scroll widget to the end.*/
void ScrollToEnd(const Widget &img, bool scrollUp, const UiOpArgs& opt, ApiCallErr &err);
void ScrollToEnd(const Widget &widget, bool scrollUp, const UiOpArgs& opt, ApiCallErr &err);
/**Drag widget-A to widget-B.*/
void DragIntoWidget(const Widget &imgA, const Widget &imgB, const UiOpArgs& opt, ApiCallErr &err);
void DragIntoWidget(const Widget &wa, const Widget &wb, const UiOpArgs& opt, ApiCallErr &err);
/**Wait for the matching widget appear in the given timeout.*/
std::unique_ptr<Widget> WaitForWidget(const WidgetSelector &select, const UiOpArgs& opt, ApiCallErr &err);
@@ -62,7 +62,7 @@ namespace OHOS::uitest {
void PerformClick(PointerOp op, const Point &point, const UiOpArgs& opt, ApiCallErr &err);
/**Perform generic-swipe on raw points.*/
void PerformSwipe(PointerOp op, const Point &p0, const Point &p1, const UiOpArgs& opt, ApiCallErr &err);
void PerformSwipe(PointerOp op, const Point &from, const Point &to, const UiOpArgs& opt, ApiCallErr &err);
/**Delay current thread for given duration.*/
static void DelayMs(uint32_t ms);
@@ -80,7 +80,7 @@ namespace OHOS::uitest {
void UpdateUi(bool updateUiTree, ApiCallErr &error);
/**Retrieve widget represented by the given widget from updated UI.*/
const Widget *RetrieveWidget(const Widget &img, ApiCallErr &err, bool updateUi = true);
const Widget *RetrieveWidget(const Widget &widget, ApiCallErr &err, bool updateUi = true);
/**Find scroll widget on current UI. <b>(without updating UI objects)</b>*/
const Widget *FindScrollWidget(const Widget &img) const;
+1 -1
View File
@@ -242,7 +242,7 @@ namespace OHOS::uitest {
}
// notify backend objects deleting
if (g_backendObjsAboutToDelete.size() >= BACKEND_OBJ_CLEAN_THRESHOLD) {
auto gcCall = ApiCallInfo{.apiId_ = "BackendObjectsCleaner"};
auto gcCall = ApiCallInfo {.apiId_ = "BackendObjectsCleaner"};
auto gcReply = ApiReplyInfo();
for (auto& ref : g_unCalledJsFuncNames) {
gcCall.paramList_.emplace_back(ref);
+1 -1
View File
@@ -22,7 +22,7 @@ namespace OHOS::uitest {
/**The default UiController of ohos, which is effective for all apps.*/
class SysUiController final : public UiController {
public:
SysUiController(std::string_view name);
explicit SysUiController(std::string_view name);
~SysUiController();
+13 -13
View File
@@ -61,7 +61,7 @@ static string GenerateUniqueId()
TEST_F(FrontendApiHandlerTest, noInvocationHandler)
{
static auto apiId = GenerateUniqueId();
auto call = ApiCallInfo{.apiId_ = "wyz"};
auto call = ApiCallInfo {.apiId_ = "wyz"};
auto reply = ApiReplyInfo();
FrontendApiServer::Get().Call(call, reply);
ASSERT_EQ(INTERNAL_ERROR, reply.exception_.code_);
@@ -80,7 +80,7 @@ TEST_F(FrontendApiHandlerTest, addRemoveHandler)
ASSERT_TRUE(server.HasHandlerFor(apiId));
json caller;
auto call = ApiCallInfo{.apiId_ = apiId};
auto call = ApiCallInfo {.apiId_ = apiId};
auto reply = ApiReplyInfo();
server.Call(call, reply);
ASSERT_EQ(NO_ERROR, reply.exception_.code_);
@@ -100,7 +100,7 @@ TEST_F(FrontendApiHandlerTest, inOutDataTransfer)
};
server.AddHandler(apiId, handler);
auto call = ApiCallInfo{.apiId_ = apiId};
auto call = ApiCallInfo {.apiId_ = apiId};
auto reply = ApiReplyInfo();
call.paramList_.emplace_back("wyz");
call.paramList_.emplace_back(10);
@@ -118,7 +118,7 @@ TEST_F(FrontendApiHandlerTest, jsonExceptionDefance)
};
server.AddHandler(apiId, handler);
auto call = ApiCallInfo{.apiId_ = apiId};
auto call = ApiCallInfo {.apiId_ = apiId};
auto reply = ApiReplyInfo();
server.Call(call, reply);
// json exception should be caught and reported properly
@@ -133,7 +133,7 @@ TEST_F(FrontendApiHandlerTest, apiErrorDeliver)
auto handler = [](const ApiCallInfo &in, ApiReplyInfo &out) { out.exception_.code_ = ErrCode::USAGE_ERROR; };
server.AddHandler(apiId, handler);
auto call = ApiCallInfo{.apiId_ = apiId};
auto call = ApiCallInfo {.apiId_ = apiId};
auto reply = ApiReplyInfo();
server.Call(call, reply);
// api error should be delivered out to caller
@@ -155,7 +155,7 @@ TEST_F(FrontendApiHandlerTest, commonPreprocessor)
};
server.AddCommonPreprocessor("dummyProcessor", processor);
auto call = ApiCallInfo{.apiId_ = apiId};
auto call = ApiCallInfo {.apiId_ = apiId};
auto reply = ApiReplyInfo();
// handler should be called if preprocessing passed
call.paramList_.emplace_back("nice");
@@ -188,7 +188,7 @@ TEST_F(FrontendApiHandlerTest, callApiE2E)
{
const auto& server = FrontendApiServer::Get();
// create by1 with seed
auto call0 = ApiCallInfo{.apiId_ = "By.text", .callerObjRef_ = string(REF_SEED_BY)};
auto call0 = ApiCallInfo {.apiId_ = "By.text", .callerObjRef_ = string(REF_SEED_BY)};
call0.paramList_.emplace_back("wyz");
auto reply0 = ApiReplyInfo();
server.Call(call0, reply0);
@@ -198,7 +198,7 @@ TEST_F(FrontendApiHandlerTest, callApiE2E)
const auto ref0 = reply0.resultValue_.get<string>();
ASSERT_TRUE(ref0.find("By#") != string::npos);
// go on creating combine by: isAfter (after ref0)
auto call1 = ApiCallInfo{.apiId_ = "By.isAfter", .callerObjRef_ = string(REF_SEED_BY)};
auto call1 = ApiCallInfo {.apiId_ = "By.isAfter", .callerObjRef_ = string(REF_SEED_BY)};
call1.paramList_.emplace_back(ref0);
auto reply1 = ApiReplyInfo();
server.Call(call1, reply1);
@@ -215,13 +215,13 @@ TEST_F(FrontendApiHandlerTest, parameterPreChecks)
{
const auto& server = FrontendApiServer::Get();
// call with argument missing
auto call0 = ApiCallInfo{.apiId_ = "By.type", .callerObjRef_ = string(REF_SEED_BY)};
auto call0 = ApiCallInfo {.apiId_ = "By.type", .callerObjRef_ = string(REF_SEED_BY)};
auto reply0 = ApiReplyInfo();
server.Call(call0, reply0);
ASSERT_EQ(ErrCode::USAGE_ERROR, reply0.exception_.code_);
ASSERT_TRUE(reply0.exception_.message_.find("Illegal argument count") != string::npos);
// call with argument redundant
auto call1 = ApiCallInfo{.apiId_ = "By.type", .callerObjRef_ = string(REF_SEED_BY)};
auto call1 = ApiCallInfo {.apiId_ = "By.type", .callerObjRef_ = string(REF_SEED_BY)};
auto reply1 = ApiReplyInfo();
call1.paramList_.emplace_back("wyz");
call1.paramList_.emplace_back("zl");
@@ -229,20 +229,20 @@ TEST_F(FrontendApiHandlerTest, parameterPreChecks)
ASSERT_EQ(ErrCode::USAGE_ERROR, reply1.exception_.code_);
ASSERT_TRUE(reply1.exception_.message_.find("Illegal argument count") != string::npos);
// call with argument of wrong type
auto call2 = ApiCallInfo{.apiId_ = "By.type", .callerObjRef_ = string(REF_SEED_BY)};
auto call2 = ApiCallInfo {.apiId_ = "By.type", .callerObjRef_ = string(REF_SEED_BY)};
auto reply2 = ApiReplyInfo();
call2.paramList_.emplace_back(1);
server.Call(call2, reply2);
ASSERT_EQ(ErrCode::USAGE_ERROR, reply2.exception_.code_);
ASSERT_TRUE(reply2.exception_.message_.find("Illegal argument type") != string::npos);
// call with argument defaulted (bool=true)
auto call3 = ApiCallInfo{.apiId_ = "By.enabled", .callerObjRef_ = string(REF_SEED_BY)};
auto call3 = ApiCallInfo {.apiId_ = "By.enabled", .callerObjRef_ = string(REF_SEED_BY)};
auto reply3 = ApiReplyInfo();
call3.paramList_.emplace_back(true); // no defaulted
server.Call(call3, reply3);
ASSERT_EQ(ErrCode::NO_ERROR, reply3.exception_.code_)<<reply3.exception_.message_;
auto call4 = ApiCallInfo{.apiId_ = "By.enabled", .callerObjRef_ = string(REF_SEED_BY)};
auto call4 = ApiCallInfo {.apiId_ = "By.enabled", .callerObjRef_ = string(REF_SEED_BY)};
auto reply4 = ApiReplyInfo(); // defaulted
server.Call(call4, reply4);
ASSERT_EQ(ErrCode::NO_ERROR, reply4.exception_.code_)<<reply4.exception_.message_;
+18 -18
View File
@@ -64,7 +64,7 @@ protected:
TEST_F(MessageTransceiverTest, checkMessageContent)
{
auto emitted = TransactionMessage{};
auto emitted = TransactionMessage {};
transceiver_.SetEmitter([&emitted](const TransactionMessage &msg) {
emitted.id_ = msg.id_; // Sniff the emitted message
emitted.type_ = msg.type_;
@@ -92,7 +92,7 @@ TEST_F(MessageTransceiverTest, checkMessageContent)
TEST_F(MessageTransceiverTest, enqueueDequeueMessage)
{
auto message = TransactionMessage{};
auto message = TransactionMessage {};
// case1: no message in queue, polling timeout, check status and delayed time
uint64_t startMs = GetCurrentMillisecond();
auto status = transceiver_.PollCallReply(message, pollTimeoutMs_);
@@ -100,7 +100,7 @@ TEST_F(MessageTransceiverTest, enqueueDequeueMessage)
ASSERT_EQ(MessageTransceiver::PollStatus::ABORT_WAIT_TIMEOUT, status);
ASSERT_NEAR(pollTimeoutMs_, endMs - startMs, TIME_DIFF_TOLERANCE_MS) << "Incorrect polling time";
// case2: message in queue, should return immediately
auto tempMessage = TransactionMessage{.id_ = 1234, .type_ = CALL};
auto tempMessage = TransactionMessage {.id_ = 1234, .type_ = CALL};
transceiver_.OnReceiveMessage(tempMessage);
startMs = GetCurrentMillisecond();
status = transceiver_.PollCallReply(message, pollTimeoutMs_);
@@ -123,7 +123,7 @@ TEST_F(MessageTransceiverTest, enqueueDequeueMessage)
TEST_F(MessageTransceiverTest, checkMessageFilter)
{
auto message = TransactionMessage{.type_ = CALL};
auto message = TransactionMessage {.type_ = CALL};
// without filter, message should be accepted
transceiver_.OnReceiveMessage(message);
auto status = transceiver_.PollCallReply(message, pollTimeoutMs_);
@@ -138,13 +138,13 @@ TEST_F(MessageTransceiverTest, checkMessageFilter)
TEST_F(MessageTransceiverTest, checkAnwserHandshakeAtomatically)
{
auto emitted = TransactionMessage{};
auto emitted = TransactionMessage {};
transceiver_.SetEmitter([&emitted](const TransactionMessage &msg) {
emitted.id_ = msg.id_; // Sniff the emitted message
emitted.type_ = msg.type_;
emitted.dataParcel_ = msg.dataParcel_;
});
auto handshake = TransactionMessage{.id_ = 1234, .type_ = HANDSHAKE};
auto handshake = TransactionMessage {.id_ = 1234, .type_ = HANDSHAKE};
transceiver_.OnReceiveMessage(handshake);
// should emit ack automatically on receiving handshake
ASSERT_EQ(TransactionType::ACK, emitted.type_);
@@ -153,7 +153,7 @@ TEST_F(MessageTransceiverTest, checkAnwserHandshakeAtomatically)
TEST_F(MessageTransceiverTest, immediateExitHandling)
{
auto message = TransactionMessage{.type_ = TransactionType::EXIT};
auto message = TransactionMessage {.type_ = TransactionType::EXIT};
// EXIT-message comes at sometime before timeout, should end polling and return it
constexpr uint64_t delayMs = 10;
asyncWork_ = async(launch::async, [this, delayMs, message]() {
@@ -171,7 +171,7 @@ TEST_F(MessageTransceiverTest, immediateConnectionDiedHandling)
{
transceiver_.ScheduleCheckConnection(false);
// connection died before timeout, should end polling and return it
auto message = TransactionMessage{};
auto message = TransactionMessage {};
const uint64_t startMs = GetCurrentMillisecond();
auto status = transceiver_.PollCallReply(message, WATCH_DOG_TIMEOUT_MS * 2);
const uint64_t endMs = GetCurrentMillisecond();
@@ -184,11 +184,11 @@ TEST_F(MessageTransceiverTest, checkScheduleHandshake)
{
transceiver_.ScheduleCheckConnection(false);
// connection died before timeout, should end polling and return it
auto message = TransactionMessage{};
auto message = TransactionMessage {};
constexpr uint64_t handshakeDelayMs = 1000;
asyncWork_ = async(launch::async, [this, handshakeDelayMs, message]() {
this_thread::sleep_for(chrono::milliseconds(handshakeDelayMs));
auto handshake = TransactionMessage{.type_ = TransactionType::HANDSHAKE};
auto handshake = TransactionMessage {.type_ = TransactionType::HANDSHAKE};
this->transceiver_.OnReceiveMessage(handshake);
});
const uint64_t startMs = GetCurrentMillisecond();
@@ -210,7 +210,7 @@ TEST_F(MessageTransceiverTest, ensureConnected)
static constexpr uint64_t incomingDelayMs = 60;
asyncWork_ = async(launch::async, [this]() {
this_thread::sleep_for(chrono::milliseconds(incomingDelayMs));
auto message = TransactionMessage{.type_ = TransactionType::ACK};
auto message = TransactionMessage {.type_ = TransactionType::ACK};
this->transceiver_.OnReceiveMessage(message);
});
const uint64_t startMs = GetCurrentMillisecond();
@@ -266,7 +266,7 @@ protected:
}
if (clientAsyncWork_.valid()) {
// do this to ensure asyncWork_ terminates normally
auto terminate = TransactionMessage{.type_ = TransactionType::EXIT};
auto terminate = TransactionMessage {.type_ = TransactionType::EXIT};
client_.GetTransceiver()->OnReceiveMessage(terminate);
clientAsyncWork_.get();
}
@@ -296,7 +296,7 @@ TEST_F(TransactionTest, checkApiTransaction)
for (size_t idx = 0; idx < testSetSize; idx++) {
// no wait reply, will just trigger emitting a call-message with serialized ApiCallInfo
auto call = ApiCallInfo{.apiId_ = apis.at(idx)};
auto call = ApiCallInfo {.apiId_ = apis.at(idx)};
auto reply = ApiReplyInfo();
client_.InvokeApi(call, reply);
// check the result, after a short interval (because the server runs async)
@@ -333,7 +333,7 @@ TEST_F(TransactionTest, checkResultWhenConnectionDied)
// enable connection check
client_.GetTransceiver()->ScheduleCheckConnection(false);
clientAsyncWork_ = async(launch::async, [this]() {
auto call = ApiCallInfo{.apiId_ = "wyz"};
auto call = ApiCallInfo {.apiId_ = "wyz"};
auto reply = ApiReplyInfo();
this->client_.InvokeApi(call, reply);
return move(reply);
@@ -348,7 +348,7 @@ TEST_F(TransactionTest, checkResultWhenConnectionDied)
ASSERT_NEAR(startMs, endMs, WATCH_DOG_TIMEOUT_MS * 1.02f);
// connection is already dead, should return immediately in later invocations
clientAsyncWork_ = async(launch::async, [this]() {
auto call = ApiCallInfo{.apiId_ = "zl"};
auto call = ApiCallInfo {.apiId_ = "zl"};
auto reply = ApiReplyInfo();
this->client_.InvokeApi(call, reply);
return move(reply);
@@ -365,7 +365,7 @@ TEST_F(TransactionTest, checkResultWhenConnectionDied)
TEST_F(TransactionTest, checkRejectConcurrentInvoke)
{
clientAsyncWork_ = async(launch::async, [this]() {
auto call = ApiCallInfo{.apiId_ = "zl"};
auto call = ApiCallInfo {.apiId_ = "zl"};
auto reply = ApiReplyInfo();
this->client_.InvokeApi(call, reply);
return move(reply);
@@ -373,7 +373,7 @@ TEST_F(TransactionTest, checkRejectConcurrentInvoke)
// give a short delay to ensure concurrence
this_thread::sleep_for(chrono::milliseconds(TIME_DIFF_TOLERANCE_MS));
uint64_t startMs = GetCurrentMillisecond();
auto call1 = ApiCallInfo{.apiId_ = "zl"};
auto call1 = ApiCallInfo {.apiId_ = "zl"};
auto reply1 = ApiReplyInfo();
client_.InvokeApi(call1, reply1);
uint64_t endMs = GetCurrentMillisecond();
@@ -386,7 +386,7 @@ TEST_F(TransactionTest, checkRejectConcurrentInvoke)
TEST_F(TransactionTest, checkResultAfterFinalized)
{
client_.Finalize();
auto call = ApiCallInfo{.apiId_ = "zl"};
auto call = ApiCallInfo {.apiId_ = "zl"};
auto reply = ApiReplyInfo();
uint64_t startMs = GetCurrentMillisecond();
client_.InvokeApi(call, reply);