From 5412bf666e5875364227957d7d47966e11c9fa24 Mon Sep 17 00:00:00 2001 From: hunili Date: Mon, 21 Aug 2023 16:00:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BF=A1=E5=9C=88=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E5=BA=A6=E4=BF=AE=E6=94=B9=20issue:=20https://gitee.com/openha?= =?UTF-8?q?rmony/ability=5Fdmsfwk/issues/I7US6D=20Signed-off-by:=20hunili?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../distributedWant/distributed_want.h | 2 + .../distributedWant/distributed_want_params.h | 2 + .../src/distributedWant/distributed_want.cpp | 23 +- .../distributed_want_params.cpp | 22 +- .../distributedWant/distributed_want_test.cpp | 213 +++++++++++------- 5 files changed, 163 insertions(+), 99 deletions(-) diff --git a/services/dtbschedmgr/include/distributedWant/distributed_want.h b/services/dtbschedmgr/include/distributedWant/distributed_want.h index 3d0e9a87..b332cff8 100644 --- a/services/dtbschedmgr/include/distributedWant/distributed_want.h +++ b/services/dtbschedmgr/include/distributedWant/distributed_want.h @@ -836,6 +836,8 @@ private: bool ReadFromParcel(Parcel& parcel); static bool CheckAndSetParameters( DistributedWant& want, const std::string& key, std::string& prop, const std::string& value); + static bool CheckAndSetNumberParameters( + DistributedWant& want, const std::string& key, std::string& prop, const std::string& value); OHOS::Uri GetLowerCaseScheme(const OHOS::Uri& uri); void GenerateUriString(std::string& uriString) const; void ToUriStringInner(std::string& uriString) const; diff --git a/services/dtbschedmgr/include/distributedWant/distributed_want_params.h b/services/dtbschedmgr/include/distributedWant/distributed_want_params.h index e7f640c3..06c52605 100644 --- a/services/dtbschedmgr/include/distributedWant/distributed_want_params.h +++ b/services/dtbschedmgr/include/distributedWant/distributed_want_params.h @@ -59,6 +59,8 @@ public: static int GetDataType(const sptr iIt); + static int GetNumberDataType(const sptr iIt); + static std::string GetStringByType(const sptr iIt, int typeId); void SetParam(const std::string& key, AAFwk::IInterface* value); diff --git a/services/dtbschedmgr/src/distributedWant/distributed_want.cpp b/services/dtbschedmgr/src/distributedWant/distributed_want.cpp index a2ae4bbd..8887ba28 100644 --- a/services/dtbschedmgr/src/distributedWant/distributed_want.cpp +++ b/services/dtbschedmgr/src/distributedWant/distributed_want.cpp @@ -1477,7 +1477,22 @@ bool DistributedWant::CheckAndSetParameters(DistributedWant& want, const std::st return false; } want.parameters_.SetParam(key, valueObj); - } else if (prop[0] == AAFwk::Short::SIGNATURE && prop[1] == '.') { + } else if (prop[0] == AAFwk::Array::SIGNATURE && prop[1] == '.') { + sptr valueObj = AAFwk::Array::Parse(value); + if (valueObj == nullptr) { + return false; + } + want.parameters_.SetParam(key, valueObj); + } else if (!CheckAndSetNumberParameters(want, key, prop, value)) { + return false; + } + return true; +} + +bool DistributedWant::CheckAndSetNumberParameters(DistributedWant& want, const std::string& key, + std::string& prop, const std::string& value) +{ + if (prop[0] == AAFwk::Short::SIGNATURE && prop[1] == '.') { sptr valueObj = AAFwk::Short::Parse(value); if (valueObj == nullptr) { return false; @@ -1507,12 +1522,6 @@ bool DistributedWant::CheckAndSetParameters(DistributedWant& want, const std::st return false; } want.parameters_.SetParam(key, valueObj); - } else if (prop[0] == AAFwk::Array::SIGNATURE && prop[1] == '.') { - sptr valueObj = AAFwk::Array::Parse(value); - if (valueObj == nullptr) { - return false; - } - want.parameters_.SetParam(key, valueObj); } return true; } diff --git a/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp b/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp index 3f0dc958..bc876516 100644 --- a/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp +++ b/services/dtbschedmgr/src/distributedWant/distributed_want_params.cpp @@ -251,7 +251,20 @@ int DistributedWantParams::GetDataType(const sptr iIt) return VALUE_TYPE_BYTE; } else if (iIt != nullptr && AAFwk::IChar::Query(iIt) != nullptr) { return VALUE_TYPE_CHAR; - } else if (iIt != nullptr && AAFwk::IShort::Query(iIt) != nullptr) { + } else if (iIt != nullptr && AAFwk::IString::Query(iIt) != nullptr) { + return VALUE_TYPE_STRING; + } else if (iIt != nullptr && AAFwk::IArray::Query(iIt) != nullptr) { + return VALUE_TYPE_ARRAY; + } else if (iIt != nullptr && IDistributedWantParams::Query(iIt) != nullptr) { + return VALUE_TYPE_WANTPARAMS; + } else { + return GetNumberDataType(iIt); + } +} + +int DistributedWantParams::GetNumberDataType(const sptr iIt) +{ + if (iIt != nullptr && AAFwk::IShort::Query(iIt) != nullptr) { return VALUE_TYPE_SHORT; } else if (iIt != nullptr && AAFwk::IInteger::Query(iIt) != nullptr) { return VALUE_TYPE_INT; @@ -261,14 +274,7 @@ int DistributedWantParams::GetDataType(const sptr iIt) return VALUE_TYPE_FLOAT; } else if (iIt != nullptr && AAFwk::IDouble::Query(iIt) != nullptr) { return VALUE_TYPE_DOUBLE; - } else if (iIt != nullptr && AAFwk::IString::Query(iIt) != nullptr) { - return VALUE_TYPE_STRING; - } else if (iIt != nullptr && AAFwk::IArray::Query(iIt) != nullptr) { - return VALUE_TYPE_ARRAY; - } else if (iIt != nullptr && IDistributedWantParams::Query(iIt) != nullptr) { - return VALUE_TYPE_WANTPARAMS; } - return VALUE_TYPE_NULL; } diff --git a/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp b/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp index dffa79ee..7f00f158 100644 --- a/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributedWant/distributed_want_test.cpp @@ -56,6 +56,12 @@ public: const std::shared_ptr &want2) const; bool CompareWant(const std::shared_ptr &want1, const std::shared_ptr &want2, std::map &keys) const; + bool CompareWantOthers(const std::shared_ptr& want1, + const std::shared_ptr& want2, std::map::iterator it) const; + bool CompareWantNumber(const std::shared_ptr& want1, + const std::shared_ptr& want2, std::map::iterator it) const; + bool CompareWantArray(const std::shared_ptr& want1, + const std::shared_ptr& want2, std::map::iterator it) const; void SendParcelTest(const std::shared_ptr &want, std::map &keys) const; void AddBoolParams(DistributedWant &want, std::map &keys, int loop, unsigned int flag) const; @@ -839,95 +845,134 @@ bool DistributedWantBaseTest::CompareWant(const std::shared_ptr EXPECT_EQ(want1->GetElement(), want2->GetElement()); for (auto it = keys.begin(); it != keys.end(); it++) { - if (it->second == boolType) { - bool v1 = want1->GetBoolParam(it->first, false); - bool v2 = want2->GetBoolParam(it->first, false); - EXPECT_EQ(v1, v2); - EXPECT_EQ(v1, true); - } else if (it->second == boolArrayType) { - std::vector v1 = want1->GetBoolArrayParam(it->first); - std::vector v2 = want2->GetBoolArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == byteType) { - byte v1 = want1->GetByteParam(it->first, 'j'); - byte v2 = want2->GetByteParam(it->first, 'k'); - EXPECT_EQ(v1, v2); - } else if (it->second == byteArrayType) { - std::vector v1 = want1->GetByteArrayParam(it->first); - std::vector v2 = want2->GetByteArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == charType) { - zchar v1 = want1->GetCharParam(it->first, 0x01AB); - zchar v2 = want2->GetCharParam(it->first, 0x02CD); - EXPECT_EQ(v1, v2); - } else if (it->second == charArrayType) { - std::vector v1 = want1->GetCharArrayParam(it->first); - std::vector v2 = want2->GetCharArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == shortType) { - short default1 = 123; - short default2 = 456; - short v1 = want1->GetShortParam(it->first, default1); - short v2 = want2->GetShortParam(it->first, default2); - EXPECT_EQ(v1, v2); - } else if (it->second == shortArrayType) { - std::vector v1 = want1->GetShortArrayParam(it->first); - std::vector v2 = want2->GetShortArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == intType) { - int default1 = 1230000; - int default2 = 4560000; - int v1 = want1->GetIntParam(it->first, default1); - int v2 = want2->GetIntParam(it->first, default2); - EXPECT_EQ(v1, v2); - } else if (it->second == intArrayType) { - std::vector v1 = want1->GetIntArrayParam(it->first); - std::vector v2 = want2->GetIntArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == longType) { - long default1 = 1e8; - long default2 = 2e8; - long v1 = want1->GetLongParam(it->first, default1); - long v2 = want2->GetLongParam(it->first, default2); - EXPECT_EQ(v1, v2); - } else if (it->second == longArrayType) { - std::vector v1 = want1->GetLongArrayParam(it->first); - std::vector v2 = want2->GetLongArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == floatType) { - float default1 = 12.3; - float default2 = 45.6; - float v1 = want1->GetFloatParam(it->first, default1); - float v2 = want2->GetFloatParam(it->first, default2); - EXPECT_EQ(v1, v2); - } else if (it->second == floatArrayType) { - std::vector v1 = want1->GetFloatArrayParam(it->first); - std::vector v2 = want2->GetFloatArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == doubleType) { - double default1 = 12.3; - double default2 = 45.6; - double v1 = want1->GetDoubleParam(it->first, default1); - double v2 = want2->GetDoubleParam(it->first, default2); - EXPECT_EQ(v1, v2); - } else if (it->second == doubleArrayType) { - std::vector v1 = want1->GetDoubleArrayParam(it->first); - std::vector v2 = want2->GetDoubleArrayParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == stringType) { - std::string v1 = want1->GetStringParam(it->first); - std::string v2 = want2->GetStringParam(it->first); - EXPECT_EQ(v1, v2); - } else if (it->second == stringArrayType) { - std::vector v1 = want1->GetStringArrayParam(it->first); - std::vector v2 = want2->GetStringArrayParam(it->first); - EXPECT_EQ(v1, v2); - } + if (!CompareWantNumber(want1, want2, it) && !CompareWantOthers(want1, want2, it) && + !CompareWantArray(want1, want2, it)) {}; } return true; } +bool DistributedWantBaseTest::CompareWantNumber(const std::shared_ptr& want1, + const std::shared_ptr& want2, std::map::iterator it) const +{ + if (it->second == shortType) { + short default1 = 123; + short default2 = 456; + short v1 = want1->GetShortParam(it->first, default1); + short v2 = want2->GetShortParam(it->first, default2); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == intType) { + int default1 = 1230000; + int default2 = 4560000; + int v1 = want1->GetIntParam(it->first, default1); + int v2 = want2->GetIntParam(it->first, default2); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == longType) { + long default1 = 1e8; + long default2 = 2e8; + long v1 = want1->GetLongParam(it->first, default1); + long v2 = want2->GetLongParam(it->first, default2); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == floatType) { + float default1 = 12.3; + float default2 = 45.6; + float v1 = want1->GetFloatParam(it->first, default1); + float v2 = want2->GetFloatParam(it->first, default2); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == doubleType) { + double default1 = 12.3; + double default2 = 45.6; + double v1 = want1->GetDoubleParam(it->first, default1); + double v2 = want2->GetDoubleParam(it->first, default2); + EXPECT_EQ(v1, v2); + return true; + } + return false; +} + +bool DistributedWantBaseTest::CompareWantOthers(const std::shared_ptr& want1, + const std::shared_ptr& want2, std::map::iterator it) const +{ + if (it->second == boolType) { + bool v1 = want1->GetBoolParam(it->first, false); + bool v2 = want2->GetBoolParam(it->first, false); + EXPECT_EQ(v1, v2); + EXPECT_EQ(v1, true); + return true; + } else if (it->second == byteType) { + byte v1 = want1->GetByteParam(it->first, 'j'); + byte v2 = want2->GetByteParam(it->first, 'k'); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == charType) { + zchar v1 = want1->GetCharParam(it->first, 0x01AB); + zchar v2 = want2->GetCharParam(it->first, 0x02CD); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == stringType) { + std::string v1 = want1->GetStringParam(it->first); + std::string v2 = want2->GetStringParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } + return false; +} + +bool DistributedWantBaseTest::CompareWantArray(const std::shared_ptr& want1, + const std::shared_ptr& want2, std::map::iterator it) const +{ + if (it->second == boolArrayType) { + std::vector v1 = want1->GetBoolArrayParam(it->first); + std::vector v2 = want2->GetBoolArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == byteArrayType) { + std::vector v1 = want1->GetByteArrayParam(it->first); + std::vector v2 = want2->GetByteArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == charArrayType) { + std::vector v1 = want1->GetCharArrayParam(it->first); + std::vector v2 = want2->GetCharArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == shortArrayType) { + std::vector v1 = want1->GetShortArrayParam(it->first); + std::vector v2 = want2->GetShortArrayParam(it->first); + EXPECT_EQ(v1, v2); + } else if (it->second == intArrayType) { + std::vector v1 = want1->GetIntArrayParam(it->first); + std::vector v2 = want2->GetIntArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == longArrayType) { + std::vector v1 = want1->GetLongArrayParam(it->first); + std::vector v2 = want2->GetLongArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == floatArrayType) { + std::vector v1 = want1->GetFloatArrayParam(it->first); + std::vector v2 = want2->GetFloatArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == doubleArrayType) { + std::vector v1 = want1->GetDoubleArrayParam(it->first); + std::vector v2 = want2->GetDoubleArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } else if (it->second == stringArrayType) { + std::vector v1 = want1->GetStringArrayParam(it->first); + std::vector v2 = want2->GetStringArrayParam(it->first); + EXPECT_EQ(v1, v2); + return true; + } + return false; +} + void DistributedWantBaseTest::SendParcelTest(const std::shared_ptr &want, std::map &keys) const {