!3299 fuzz用例修改

Merge pull request !3299 from 陈涵韬/local
This commit is contained in:
openharmony_ci 2023-08-11 01:16:21 +00:00 committed by Gitee
commit c4d8971e32
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -207,6 +207,33 @@ size_t GetObject(T &object, const uint8_t *data, size_t size)
return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0;
}
bool DoSomethingInterestingWithMyAPI1(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
std::string name = "WindowFuzzTest1";
sptr<WindowOption> option = nullptr;
sptr<Window> window = new Window();
if (window == nullptr) {
return false;
}
size_t startPos = 0;
sptr<IOccupiedAreaChangeListener> iOccupiedAreaChangeListener = new IOccupiedAreaChangeListener();
OHOS::Rosen::Rect rect_ = {0, 0, 0, 0};
window->RegisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
int32_t safeHeight = 80;
startPos += GetObject<int32_t>(safeHeight, data + startPos, size - startPos);
sptr<OHOS::Rosen::OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(
OccupiedAreaType::TYPE_INPUT, rect_, safeHeight);
iOccupiedAreaChangeListener->OnSizeChange(info, nullptr);
window->UnregisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
sptr<IVisibilityChangedListener> visibilityChangedListener = new VisibilityChangedListener();
std::vector<sptr<WindowVisibilityInfo>> infos;
visibilityChangedListener->OnWindowVisibilityChanged(infos);
return true;
}
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
@ -214,16 +241,27 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
}
std::string name = "WindowFuzzTest";
sptr<WindowOption> option = nullptr;
sptr<Window> window = Window::Create(name, option);
sptr<Window> window = new Window();
if (window == nullptr) {
return false;
}
std::string windowName = "window test";
window->Find(windowName);
size_t startPos = 0;
std::shared_ptr<AbilityRuntime::Context> context = nullptr;
startPos += GetObject(context, data + startPos, size - startPos);
window->GetTopWindowWithContext(context);
uint32_t mainWinId = 1;
startPos += GetObject<uint32_t>(mainWinId, data + startPos, size - startPos);
window->GetTopWindowWithId(mainWinId);
uint32_t parentId = 1;
startPos += GetObject<uint32_t>(parentId, data + startPos, size - startPos);
window->GetSubWindow(parentId);
std::shared_ptr<AppExecFwk::Configuration> configuration = nullptr;
startPos += GetObject(configuration, data + startPos, size - startPos);
window->UpdateConfigurationForAll(configuration);
window->Show(0);
Orientation orientation = static_cast<Orientation>(data[0]);
window->SetRequestedOrientation(static_cast<Orientation>(data[0]));
if (window->GetRequestedOrientation() != orientation) {
return false;
}
window->Hide(0);
window->Destroy();
sptr<IFocusChangedListener> focusChangedListener = new FocusChangedListener();
@ -240,19 +278,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
iInputEventConsumer->OnInputEvent(keyEvent);
iInputEventConsumer->OnInputEvent(pointerEvent);
iInputEventConsumer->OnInputEvent(axisEvent);
sptr<IOccupiedAreaChangeListener> iOccupiedAreaChangeListener = new IOccupiedAreaChangeListener();
OHOS::Rosen::Rect rect_ = {0, 0, 0, 0};
window->RegisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
int32_t safeHeight = 80;
size_t startPos = 0;
startPos += GetObject<int32_t>(safeHeight, data + startPos, size - startPos);
sptr<OHOS::Rosen::OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(
OccupiedAreaType::TYPE_INPUT, rect_, safeHeight);
iOccupiedAreaChangeListener->OnSizeChange(info, nullptr);
window->UnregisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
sptr<IVisibilityChangedListener> visibilityChangedListener = new VisibilityChangedListener();
std::vector<sptr<WindowVisibilityInfo>> infos;
visibilityChangedListener->OnWindowVisibilityChanged(infos);
DoSomethingInterestingWithMyAPI1(data, size);
return true;
}