Add and update test code

Signed-off-by: zhaoyuan17 <zhaoyuan17@huawei.com>
This commit is contained in:
zhaoyuan17 2021-12-04 15:01:32 +00:00
parent ba739b1601
commit 402f7643de
10 changed files with 104 additions and 21 deletions

View File

@ -39,7 +39,7 @@ struct FormCustomizeData {
struct FormWindow {
int32_t designWidth;
bool autoDesignWidth;
bool autoDesignWidth = false;
};
struct FormInfo : public Parcelable {
@ -55,7 +55,7 @@ struct FormInfo : public Parcelable {
std::string deepLink;
std::string formConfigAbility;
std::string scheduledUpateTime = "0:0";
std::string layout;
std::string src;
FormWindow window;
int32_t descriptionId = 0;
int32_t updateDuration = 0;

View File

@ -55,6 +55,10 @@ const std::string JSON_KEY_FORM_VISIBLE_NOTIFY = "formVisibleNotify";
const std::string JSON_KEY_RELATED_BUNDLE_NAME = "relatedBundleName";
const std::string JSON_KEY_DEFAULT_FLAG = "defaultFlag";
const std::string JSON_KEY_PORTRAIT_LAYOUTS = "portraitLayouts";
const std::string JSON_KEY_SRC = "src";
const std::string JSON_KEY_WINDOW = "window";
const std::string JSON_KEY_DESIGN_WIDTH = "designWidth";
const std::string JSON_KEY_AUTO_DESIGN_WIDTH = "autoDesignWidth";
} // namespace
bool FormInfo::ReadFromParcel(Parcel &parcel)
@ -71,6 +75,7 @@ bool FormInfo::ReadFromParcel(Parcel &parcel)
relatedBundleName = Str16ToStr8(parcel.ReadString16());
originalBundleName = Str16ToStr8(parcel.ReadString16());
deepLink = Str16ToStr8(parcel.ReadString16());
src = Str16ToStr8(parcel.ReadString16());
updateEnabled = parcel.ReadBool();
defaultFlag = parcel.ReadBool();
formVisibleNotify = parcel.ReadBool();
@ -115,6 +120,9 @@ bool FormInfo::ReadFromParcel(Parcel &parcel)
customizeData.value = customizeValue;
customizeDatas.emplace_back(customizeData);
}
window.designWidth = parcel.ReadInt32();
window.autoDesignWidth = parcel.ReadBool();
return true;
}
@ -142,6 +150,7 @@ bool FormInfo::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(relatedBundleName));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(originalBundleName));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deepLink));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(src));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, updateEnabled);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, defaultFlag);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, formVisibleNotify);
@ -175,6 +184,9 @@ bool FormInfo::Marshalling(Parcel &parcel) const
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(customizeDatas[i].name));
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(customizeDatas[i].value));
}
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, window.designWidth);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, window.autoDesignWidth);
return true;
}
@ -186,6 +198,12 @@ void to_json(nlohmann::json &jsonObject, const FormCustomizeData &customizeDatas
};
}
void to_json(nlohmann::json &jsonObject, const FormWindow &formWindow)
{
jsonObject[JSON_KEY_DESIGN_WIDTH] = formWindow.designWidth;
jsonObject[JSON_KEY_AUTO_DESIGN_WIDTH] = formWindow.autoDesignWidth;
}
void to_json(nlohmann::json &jsonObject, const FormInfo &formInfo)
{
jsonObject = nlohmann::json{
@ -198,6 +216,7 @@ void to_json(nlohmann::json &jsonObject, const FormInfo &formInfo)
{JSON_KEY_RELATED_BUNDLE_NAME, formInfo.relatedBundleName},
{JSON_KEY_JS_COMPONENT_NAME, formInfo.jsComponentName},
{JSON_KEY_DEEP_LINK, formInfo.deepLink},
{JSON_KEY_SRC, formInfo.src},
{JSON_KEY_FORMCONFIG_ABILITY, formInfo.formConfigAbility},
{JSON_KEY_SCHEDULED_UPDATE_TIME, formInfo.scheduledUpateTime},
{JSON_KEY_ORIGINAL_BUNDLE_NAME, formInfo.originalBundleName},
@ -212,7 +231,8 @@ void to_json(nlohmann::json &jsonObject, const FormInfo &formInfo)
{JSON_KEY_SUPPORT_DIMENSIONS, formInfo.supportDimensions},
{JSON_KEY_CUSTOMIZE_DATA, formInfo.customizeDatas},
{JSON_KEY_LANDSCAPE_LAYOUTS, formInfo.landscapeLayouts},
{JSON_KEY_PORTRAIT_LAYOUTS, formInfo.portraitLayouts}
{JSON_KEY_PORTRAIT_LAYOUTS, formInfo.portraitLayouts},
{JSON_KEY_WINDOW, formInfo.window}
};
}
@ -222,6 +242,12 @@ void from_json(const nlohmann::json &jsonObject, FormCustomizeData &customizeDat
customizeDatas.value = jsonObject.at(JSON_KEY_VALUE).get<std::string>();
}
void from_json(const nlohmann::json &jsonObject, FormWindow &formWindow)
{
formWindow.designWidth = jsonObject.at(JSON_KEY_DESIGN_WIDTH).get<int32_t>();
formWindow.autoDesignWidth = jsonObject.at(JSON_KEY_AUTO_DESIGN_WIDTH).get<bool>();
}
void from_json(const nlohmann::json &jsonObject, FormInfo &formInfo)
{
formInfo.bundleName = jsonObject.at(JSON_KEY_BUNDLE_NAME).get<std::string>();
@ -235,6 +261,7 @@ void from_json(const nlohmann::json &jsonObject, FormInfo &formInfo)
formInfo.deepLink = jsonObject.at(JSON_KEY_DEEP_LINK).get<std::string>();
formInfo.formConfigAbility = jsonObject.at(JSON_KEY_FORMCONFIG_ABILITY).get<std::string>();
formInfo.scheduledUpateTime = jsonObject.at(JSON_KEY_SCHEDULED_UPDATE_TIME).get<std::string>();
formInfo.src = jsonObject.at(JSON_KEY_SRC).get<std::string>();
formInfo.originalBundleName = jsonObject.at(JSON_KEY_ORIGINAL_BUNDLE_NAME).get<std::string>();
formInfo.descriptionId = jsonObject.at(JSON_KEY_DESCRIPTION_ID).get<int32_t>();
formInfo.updateDuration = jsonObject.at(JSON_KEY_UPDATE_DURATION).get<int32_t>();
@ -248,6 +275,7 @@ void from_json(const nlohmann::json &jsonObject, FormInfo &formInfo)
formInfo.customizeDatas = jsonObject.at(JSON_KEY_CUSTOMIZE_DATA).get<std::vector<FormCustomizeData>>();
formInfo.landscapeLayouts = jsonObject.at(JSON_KEY_LANDSCAPE_LAYOUTS).get<std::vector<std::string>>();
formInfo.portraitLayouts = jsonObject.at(JSON_KEY_PORTRAIT_LAYOUTS).get<std::vector<std::string>>();
formInfo.window = jsonObject.at(JSON_KEY_WINDOW).get<FormWindow>();
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -838,10 +838,10 @@ static void ConvertFormInfo(napi_env env, napi_value objformInfo, const FormInfo
}
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objformInfo, "customizeDatas", nCustomizeDatas));
napi_value nLayout;
NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, formInfo.layout.c_str(), NAPI_AUTO_LENGTH, &nLayout));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objformInfo, "layout", nLayout));
HILOG_INFO("ConvertFormInfo layout=%{public}s.", formInfo.layout.c_str());
napi_value nSrc;
NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, formInfo.src.c_str(), NAPI_AUTO_LENGTH, &nSrc));
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objformInfo, "src", nSrc));
HILOG_INFO("ConvertFormInfo src=%{public}s.", formInfo.src.c_str());
napi_value nWindow;
NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &nWindow));

View File

@ -198,7 +198,7 @@ const std::string BUNDLE_MODULE_PROFILE_FORMS_JS_COMPONENT_NAME = "jsComponentNa
const std::string BUNDLE_MODULE_PROFILE_FORMS_VALUE = "value";
const std::string BUNDLE_MODULE_PROFILE_FORMS_FORM_CONFIG_ABILITY = "formConfigAbility";
const std::string BUNDLE_MODULE_PROFILE_FORMS_FORM_VISIBLE_NOTIFY = "formVisibleNotify";
const std::string BUNDLE_MODULE_PROFILE_FORMS_LAYOUT = "layout";
const std::string BUNDLE_MODULE_PROFILE_FORMS_SRC = "src";
// sub BUNDLE_MODULE_PROFILE_KEY_JS
const std::string BUNDLE_MODULE_PROFILE_KEY_PAGES = "pages";
const std::string BUNDLE_MODULE_PROFILE_KEY_WINDOW = "window";

View File

@ -177,7 +177,7 @@ struct Forms {
int32_t descriptionId = 0;
bool isDefault = false;
std::string type;
std::string layout;
std::string src;
Window window;
std::string colorMode = "auto";
std::vector<std::string> supportDimensions;
@ -938,8 +938,8 @@ void from_json(const nlohmann::json &jsonObject, Forms &forms)
ArrayType::NOT_ARRAY);
GetValueIfFindKey<std::string>(jsonObject,
jsonObjectEnd,
BUNDLE_MODULE_PROFILE_FORMS_LAYOUT,
forms.layout,
BUNDLE_MODULE_PROFILE_FORMS_SRC,
forms.src,
JsonType::STRING,
false,
parseResult,
@ -1848,7 +1848,7 @@ bool ConvertFormInfo(FormInfo &formInfo, const ProfileReader::Forms &form)
}
formInfo.landscapeLayouts = form.landscapeLayouts;
formInfo.portraitLayouts = form.portraitLayouts;
formInfo.layout = form.layout;
formInfo.src = form.src;
formInfo.window.autoDesignWidth = form.window.autoDesignWidth;
formInfo.window.designWidth = form.window.designWidth;
return true;

View File

@ -180,7 +180,7 @@ protected:
"signatureKey": "",
"supportedModes": 0,
"debug": false,
"singleUser": true
"singleUser": false
},
"compatibleVersion": 3,
"cpuAbi": "",
@ -293,6 +293,11 @@ protected:
"supportDimensions": [
1
],
"src": "src/code",
"window": {
"designWidth": 750,
"autoDesignWidth": false
},
"landscapeLayouts": [],
"portraitLayouts": [],
"customizeData": [
@ -300,7 +305,12 @@ protected:
"name": "originWidgetName",
"value": "com.weather.testWidget"
}
]
],
"src": "cards/card/index",
"windows": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
},
@ -323,6 +333,26 @@ protected:
"label": "$string:mainability_description"
}
},
"commonEvents": {
"com.example.myapplication1com.example.myapplication.h1id": {
"name": ".MainAbility",
"bundleName": "com.example.myapplication1",
"permission": "permission_test",
"uid": -1,
"data": [
"data_one",
"data_two"
],
"type": [
"type_one",
"typea_two"
],
"events": [
"events_one",
"events_two"
]
}
},
"uid": 10000,
"userId_": 0,
"canUninstall": true

View File

@ -125,7 +125,7 @@ const std::string FORM_PORTRAIT_LAYOUTS1 = "port1";
const std::string FORM_PORTRAIT_LAYOUTS2 = "port2";
const std::string FORM_LANDSCAPE_LAYOUTS1 = "land1";
const std::string FORM_LANDSCAPE_LAYOUTS2 = "land2";
const std::string FORM_LAYOUT = "page/card/index";
const std::string FORM_SRC = "page/card/index";
constexpr int32_t FORM_JS_WINDOW_DESIGNWIDTH = 720;
const std::string SHORTCUT_TEST_ID = "shortcutTestId";
const std::string SHORTCUT_DEMO_ID = "shortcutDemoId";
@ -359,7 +359,7 @@ FormInfo BmsBundleKitServiceTest::MockFormInfo(
formInfo.scheduledUpateTime = FORM_SCHEDULED_UPDATE_TIME;
formInfo.updateEnabled = true;
formInfo.jsComponentName = FORM_JS_COMPONENT_NAME;
formInfo.layout = FORM_LAYOUT;
formInfo.src = FORM_SRC;
formInfo.window.autoDesignWidth = true;
formInfo.window.designWidth = FORM_JS_WINDOW_DESIGNWIDTH;
for (auto &info : formInfo.customizeDatas) {
@ -800,7 +800,7 @@ void BmsBundleKitServiceTest::CheckFormInfoTest(const std::vector<FormInfo> &for
EXPECT_EQ(info.name, FORM_CUSTOMIZE_DATAS_NAME);
EXPECT_EQ(info.value, FORM_CUSTOMIZE_DATAS_VALUE);
}
EXPECT_EQ(formInfo.layout, FORM_LAYOUT);
EXPECT_EQ(formInfo.src, FORM_SRC);
EXPECT_EQ(formInfo.window.designWidth, FORM_JS_WINDOW_DESIGNWIDTH);
EXPECT_EQ(formInfo.window.autoDesignWidth, true);
}
@ -829,7 +829,7 @@ void BmsBundleKitServiceTest::CheckFormInfoDemo(const std::vector<FormInfo> &for
EXPECT_EQ(formInfo.scheduledUpateTime, FORM_SCHEDULED_UPDATE_TIME);
EXPECT_EQ(formInfo.jsComponentName, FORM_JS_COMPONENT_NAME);
EXPECT_EQ(formInfo.updateEnabled, true);
EXPECT_EQ(formInfo.layout, FORM_LAYOUT);
EXPECT_EQ(formInfo.src, FORM_SRC);
EXPECT_EQ(formInfo.window.designWidth, FORM_JS_WINDOW_DESIGNWIDTH);
for (auto &info : formInfo.customizeDatas) {
EXPECT_EQ(info.name, FORM_CUSTOMIZE_DATAS_NAME);

View File

@ -60,7 +60,7 @@ const nlohmann::json CONFIG_JSON = R"(
},
"deviceConfig": {
"default": {
"keepAlive":true,
"keepAlive":true
}
},
"module": {
@ -120,7 +120,7 @@ const nlohmann::json CONFIG_JSON = R"(
"portraitLayouts": [
"$layout:ability_form"
],
"layout": "pages/card/index",
"src": "pages/card/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true

View File

@ -360,7 +360,12 @@ protected:
"name": "originWidgetName",
"value": "com.weather.testWidget"
}
]
],
"src": "cards/card/index",
"windows": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
},
@ -383,6 +388,26 @@ protected:
"label": "$string:mainability_description"
}
},
"commonEvents": {
"com.example.myapplication1com.example.myapplication.h1id": {
"name": ".MainAbility",
"bundleName": "com.example.myapplication1",
"permission": "permission_test",
"uid": -1,
"data": [
"data_one",
"data_two"
],
"type": [
"type_one",
"typea_two"
],
"events": [
"events_one",
"events_two"
]
}
},
"uid": 2103,
"userId_": 0,
"canUninstall": true