2015-12-09 08:04:30 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2016-01-07 01:34:52 +01:00
|
|
|
#include "uitest/uiobject_impl.hxx"
|
2016-01-09 02:01:43 +01:00
|
|
|
#include "uitest/factory.hxx"
|
2015-12-09 08:04:30 +01:00
|
|
|
|
2016-01-06 21:39:52 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2016-01-09 04:55:34 +01:00
|
|
|
#define DUMP_UITEST(x) SAL_INFO("vcl.uitest", x)
|
2016-01-09 02:01:43 +01:00
|
|
|
|
2015-12-09 08:04:30 +01:00
|
|
|
UIObject::~UIObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-06 21:39:52 +01:00
|
|
|
StringMap UIObject::get_state()
|
2015-12-09 08:04:30 +01:00
|
|
|
{
|
2016-01-06 21:39:52 +01:00
|
|
|
StringMap aMap;
|
2015-12-09 08:04:30 +01:00
|
|
|
aMap["NotImplemented"] = "NotImplemented";
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIObject::execute(const OUString& /*rAction*/,
|
2016-01-06 21:39:52 +01:00
|
|
|
const StringMap& /*rParameters*/)
|
2015-12-09 08:04:30 +01:00
|
|
|
{
|
|
|
|
// should never be called
|
|
|
|
throw std::exception();
|
|
|
|
}
|
|
|
|
|
2016-01-06 21:39:52 +01:00
|
|
|
UIObjectType UIObject::getType() const
|
2015-12-09 08:04:30 +01:00
|
|
|
{
|
|
|
|
return UIObjectType::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2016-01-06 21:39:52 +01:00
|
|
|
std::unique_ptr<UIObject> UIObject::get_child(const OUString&)
|
|
|
|
{
|
|
|
|
return std::unique_ptr<UIObject>();
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:01:43 +01:00
|
|
|
void UIObject::dumpState() const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIObject::dumpHierarchy() const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isDialogWindow(vcl::Window* pWindow)
|
|
|
|
{
|
|
|
|
WindowType nType = pWindow->GetType();
|
|
|
|
if (nType >= 0x13a && nType <= 0x13c)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vcl::Window* get_dialog_parent(vcl::Window* pWindow)
|
|
|
|
{
|
|
|
|
if (isDialogWindow(pWindow))
|
|
|
|
return pWindow;
|
|
|
|
|
|
|
|
vcl::Window* pParent = pWindow->GetParent();
|
|
|
|
if (!pParent)
|
|
|
|
return pWindow;
|
|
|
|
|
|
|
|
return get_dialog_parent(pParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-06 21:39:52 +01:00
|
|
|
WindowUIObject::WindowUIObject(VclPtr<vcl::Window> xWindow):
|
|
|
|
mxWindow(xWindow)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringMap WindowUIObject::get_state()
|
|
|
|
{
|
|
|
|
StringMap aMap;
|
|
|
|
aMap["Visible"] = OUString::boolean(mxWindow->IsVisible());
|
|
|
|
aMap["Enabled"] = OUString::boolean(mxWindow->IsEnabled());
|
2016-01-09 02:01:43 +01:00
|
|
|
aMap["WindowType"] = OUString::number(mxWindow->GetType(), 16);
|
2016-01-06 21:39:52 +01:00
|
|
|
if (mxWindow->GetParent())
|
|
|
|
aMap["Parent"] = mxWindow->GetParent()->get_id();
|
|
|
|
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowUIObject::execute(const OUString& rAction,
|
|
|
|
const StringMap& rParameters)
|
|
|
|
{
|
|
|
|
if (rAction == "SET")
|
|
|
|
{
|
|
|
|
for (auto itr = rParameters.begin(); itr != rParameters.end(); ++itr)
|
|
|
|
{
|
|
|
|
std::cout << itr->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UIObjectType WindowUIObject::getType() const
|
|
|
|
{
|
|
|
|
return UIObjectType::WINDOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
vcl::Window* findChild(vcl::Window* pParent, const OUString& rID)
|
|
|
|
{
|
|
|
|
if (!pParent)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
size_t nCount = pParent->GetChildCount();
|
|
|
|
for (size_t i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
vcl::Window* pChild = pParent->GetChild(i);
|
|
|
|
if (pChild && pChild->get_id() == rID)
|
|
|
|
return pChild;
|
|
|
|
|
|
|
|
vcl::Window* pResult = findChild(pChild, rID);
|
|
|
|
if (pResult)
|
|
|
|
return pResult;
|
|
|
|
}
|
2016-01-07 01:34:23 +01:00
|
|
|
|
|
|
|
return nullptr;
|
2016-01-06 21:39:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<UIObject> WindowUIObject::get_child(const OUString& rID)
|
|
|
|
{
|
2016-01-09 02:01:43 +01:00
|
|
|
vcl::Window* pDialogParent = get_dialog_parent(mxWindow.get());
|
|
|
|
vcl::Window* pWindow = findChild(pDialogParent, rID);
|
2016-01-06 21:39:52 +01:00
|
|
|
|
2016-01-09 02:01:43 +01:00
|
|
|
return UITestWrapperFactory::createObject(pWindow);
|
|
|
|
}
|
2016-01-07 01:34:23 +01:00
|
|
|
|
2016-01-09 02:01:43 +01:00
|
|
|
OUString WindowUIObject::get_name() const
|
|
|
|
{
|
|
|
|
return OUString("WindowUIObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowUIObject::dumpState() const
|
|
|
|
{
|
|
|
|
DUMP_UITEST(get_name() << " " << mxWindow->get_id());
|
|
|
|
StringMap aState = const_cast<WindowUIObject*>(this)->get_state();
|
|
|
|
for (auto itr = aState.begin(), itrEnd = aState.end(); itr != itrEnd; ++itr)
|
|
|
|
{
|
|
|
|
DUMP_UITEST("Property: " << itr->first << " with value: " << itr->second);
|
|
|
|
}
|
|
|
|
size_t nCount = mxWindow->GetChildCount();
|
|
|
|
if (nCount)
|
|
|
|
DUMP_UITEST("With " << nCount << " Children:");
|
|
|
|
|
|
|
|
for (size_t i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
vcl::Window* pChild = mxWindow->GetChild(i);
|
|
|
|
// TODO: moggi: we need to go through a factory for the new objects
|
|
|
|
std::unique_ptr<UIObject> pChildWrapper =
|
|
|
|
UITestWrapperFactory::createObject(pChild);
|
|
|
|
pChildWrapper->dumpState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowUIObject::dumpHierarchy() const
|
|
|
|
{
|
|
|
|
vcl::Window* pDialogParent = get_dialog_parent(mxWindow.get());
|
|
|
|
std::unique_ptr<UIObject> pParentWrapper =
|
|
|
|
UITestWrapperFactory::createObject(pDialogParent);
|
|
|
|
pParentWrapper->dumpState();
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonUIObject::ButtonUIObject(VclPtr<Button> xButton):
|
|
|
|
WindowUIObject(xButton),
|
|
|
|
mxButton(xButton)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringMap ButtonUIObject::get_state()
|
|
|
|
{
|
|
|
|
StringMap aMap = WindowUIObject::get_state();
|
|
|
|
// Move that to a Contrl base class
|
|
|
|
aMap["Label"] = mxButton->GetDisplayText();
|
|
|
|
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIObjectType ButtonUIObject::getType() const
|
|
|
|
{
|
|
|
|
return UIObjectType::BUTTON;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonUIObject::execute(const OUString& rAction,
|
|
|
|
const StringMap& rParameters)
|
|
|
|
{
|
|
|
|
if (rAction == "CLICK")
|
|
|
|
mxButton->Click();
|
|
|
|
else
|
|
|
|
WindowUIObject::execute(rAction, rParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString ButtonUIObject::get_name() const
|
|
|
|
{
|
|
|
|
return OUString("ButtonUIObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogUIObject::DialogUIObject(VclPtr<Dialog> xDialog):
|
|
|
|
WindowUIObject(xDialog),
|
|
|
|
mxDialog(xDialog)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringMap DialogUIObject::get_state()
|
|
|
|
{
|
|
|
|
StringMap aMap = WindowUIObject::get_state();
|
|
|
|
aMap["Modal"] = OUString::boolean(mxDialog->IsModalInputMode());
|
|
|
|
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString DialogUIObject::get_name() const
|
|
|
|
{
|
|
|
|
return OUString("DialogUIObject");
|
|
|
|
}
|
|
|
|
|
|
|
|
UIObjectType DialogUIObject::getType() const
|
|
|
|
{
|
|
|
|
return UIObjectType::DIALOG;
|
2016-01-06 21:39:52 +01:00
|
|
|
}
|
|
|
|
|
2016-01-09 04:56:47 +01:00
|
|
|
EditUIObject::EditUIObject(VclPtr<Edit> xEdit):
|
|
|
|
WindowUIObject(xEdit),
|
|
|
|
mxEdit(xEdit)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditUIObject::execute(const OUString& rAction,
|
|
|
|
const StringMap& rParameters)
|
|
|
|
{
|
|
|
|
if (rAction == "SET")
|
|
|
|
{
|
|
|
|
if (rParameters.find("TEXT") != rParameters.end())
|
|
|
|
{
|
|
|
|
assert(rParameters.size() == 1); // only the text
|
|
|
|
mxEdit->SetText(rParameters.find("TEXT")->second);
|
|
|
|
}
|
|
|
|
else if (rParameters.find("SELECTION") != rParameters.end())
|
|
|
|
{
|
|
|
|
// TODO: moggi: add code
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SAL_WARN("vcl.uitest", "unkown set parameters for EditUIObject");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SAL_WARN("vcl.uitest", "unknown action for EditUIObject: " << rAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringMap EditUIObject::get_state()
|
|
|
|
{
|
|
|
|
StringMap aMap = WindowUIObject::get_state();
|
|
|
|
aMap["MaxTextLength"] = OUString::number(mxEdit->GetMaxTextLen());
|
|
|
|
aMap["SelectedText"] = mxEdit->GetSelected();
|
|
|
|
aMap["Text"] = mxEdit->GetText();
|
|
|
|
|
|
|
|
return aMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIObjectType EditUIObject::getType() const
|
|
|
|
{
|
|
|
|
return UIObjectType::EDIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString EditUIObject::get_name() const
|
|
|
|
{
|
|
|
|
return OUString("EditUIObject");
|
|
|
|
}
|
|
|
|
|
2015-12-09 08:04:30 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|