From: Sung-Jin Park Date: Mon, 20 Jul 2020 11:39:13 +0000 (+0900) Subject: DSSeat & DSInput : creates a DSWaylandSeat via DSWaylandCompositor, connects a seat... X-Git-Tag: accepted/tizen/unified/20200820.213435~229 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F241646%2F1;p=platform%2Fcore%2Fuifw%2Flibds.git DSSeat & DSInput : creates a DSWaylandSeat via DSWaylandCompositor, connects a seat with a input Change-Id: I02f1c71f66d4bc78d7846564b9eccdc395ec2980 Signed-off-by: Sung-Jin Park --- diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index ab79a84..8ee2c75 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -89,14 +89,14 @@ bool DSCompositorPrivate::quit() return true; } -void DSCompositorPrivate::__initializeWlDisplay() +DSWaylandCompositor *DSCompositorPrivate::getWlCompositor() { - __wlCompositor->create(); + return __wlCompositor.get(); } -DSWaylandCompositor *DSCompositorPrivate::getWlCompositor() +void DSCompositorPrivate::__initializeWlDisplay() { - return __wlCompositor.get(); + __wlCompositor->create(); } void DSCompositorPrivate::__initializeOutputs() diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index 8cec16c..c3e4e64 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -1,5 +1,6 @@ #include "DSInput.h" #include "DSInputPrivate.h" +#include "DSSeat.h" namespace display_server { @@ -13,12 +14,14 @@ DSInputPrivate::DSInputPrivate(DSInput * p_ptr) DSInputPrivate::~DSInputPrivate() { - if (__dsLibinput) delete __dsLibinput; + if (__dsLibinput) + delete __dsLibinput; } void DSInputPrivate::Init() { __dsLibinput = new DSLibinput(this); + DS_ASSERT(__dsLibinput != nullptr); } void DSInputPrivate::PostDeviceAddEvent(std::string seat, std::string name, std::string identifier, DSInput::DeviceClass devClass) @@ -36,15 +39,27 @@ void DSInputPrivate::PostDeviceRemoveEvent(std::string seat, std::string name, s } DSInput::DSInput() - : DS_INIT_PRIVATE_PTR(DSInput) + : DS_INIT_PRIVATE_PTR(DSInput), + __seat(nullptr) { } +DSInput::DSInput(std::shared_ptr seat) + : DS_INIT_PRIVATE_PTR(DSInput), + __seat(seat) +{ + if (seat == nullptr) + { + DSLOG_ERR("DSInput", "DSSeat ptr is required."); + return; + } +} + DSInput::~DSInput() { } -void DSInput::Init() +void DSInput::init() { DS_GET_PRIV(DSInput); diff --git a/src/DSInput/DSInput.h b/src/DSInput/DSInput.h index 86931e3..e0dc9b9 100644 --- a/src/DSInput/DSInput.h +++ b/src/DSInput/DSInput.h @@ -12,6 +12,7 @@ namespace display_server { +class DSSeat; class DSInputPrivate; class DSInputDevice; @@ -30,9 +31,10 @@ public: }; public: DSInput(); + DSInput(std::shared_ptr seat); ~DSInput() override; - void Init(); + void init(); void deviceAdd(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass); void deviceRemove(std::string name, std::string identifier, DSInput::DeviceClass devClass, DSInput::DeviceSubclass devSubclass); @@ -41,6 +43,7 @@ public: void registerCallbackDeviceRemove(DSObject *slot, std::function)> func); private: + std::shared_ptr __seat; std::list devList; DSSignal> __deviceAddSignal; diff --git a/src/DSSeat/DSSeat.cpp b/src/DSSeat/DSSeat.cpp index ff5663c..d77c306 100644 --- a/src/DSSeat/DSSeat.cpp +++ b/src/DSSeat/DSSeat.cpp @@ -1,4 +1,10 @@ +#include "DSCore.h" #include "DSSeat.h" +#include "DSInput.h" +#include "DSCompositor.h" +#include "DSCompositorPrivate.h" +#include "DSWaylandSeat.h" +#include "DSWaylandCompositor.h" namespace display_server { @@ -7,11 +13,49 @@ DSSeat::DSSeat() : __input(nullptr), __keyboard(nullptr), __pointer(nullptr), - __touch(nullptr) -{} + __touch(nullptr), + __dswlSeat(nullptr), + __dswlComp(nullptr), + __compositor(nullptr), + __numPointer(0), + __numKeyboard(0), + __numTouch(0) +{ +} + +DSSeat::DSSeat(DSCompositor *compositor, std::string name) + : __input(nullptr), + __keyboard(nullptr), + __pointer(nullptr), + __touch(nullptr), + __dswlSeat(nullptr), + __dswlComp(nullptr), + __compositor(compositor), + __numPointer(0), + __numKeyboard(0), + __numTouch(0) +{ + if (!compositor) + return; + + DSCompositorPrivate *compPriv = DSCompositorPrivate::getPrivate(compositor); + DS_ASSERT(compPriv != nullptr); + + __dswlComp = compPriv->getWlCompositor(); + DS_ASSERT(__dswlComp != nullptr); + + __dswlSeat = __dswlComp->addSeat(DSWaylandSeat::capNone); + DS_ASSERT(__dswlSeat != nullptr); + + if (!name.empty()) + __dswlSeat->setName(name); +} DSSeat::~DSSeat() -{} +{ + if (__dswlComp && __dswlSeat) + __dswlComp->removeSeat(__dswlSeat); +} bool DSSeat::addInput(std::shared_ptr input) { @@ -31,12 +75,59 @@ void DSSeat::slotDeviceAdd(std::shared_ptr device) { std::cout << "DSSeat slotDeviceAdd!" << std::endl; device->print(); + + uint32_t cap = (uint32_t)__dswlSeat->getCapability(); + bool capNeedUpdate = false; + + if ((device->getClass() == DSInput::PointerClass) && (__numPointer == 0)) + { + __numPointer++; + cap = cap | DSWaylandSeat::capPointer; + capNeedUpdate = true; + } + else if ((device->getClass() == DSInput::KeyboardClass) && (__numKeyboard == 0)) + { + __numKeyboard++; + cap = cap | DSWaylandSeat::capKeyboard; + capNeedUpdate = true; + } + else if ((device->getClass() == DSInput::TouchClass) && (__numTouch == 0)) + { + __numTouch++; + cap = cap | DSWaylandSeat::capTouch; + capNeedUpdate = true; + } + + if (capNeedUpdate) + __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap); } void DSSeat::slotDeviceRemove(std::shared_ptr device) { std::cout << "DSSeat slotDeviceRemove!" << std::endl; device->print(); + + uint32_t cap = (uint32_t)__dswlSeat->getCapability(); + bool capNeedUpdate = false; + + if ((device->getClass() == DSInput::PointerClass) && ((--__numPointer) == 0)) + { + cap = cap & (~DSWaylandSeat::capPointer); + capNeedUpdate = true; + } + else if ((device->getClass() == DSInput::KeyboardClass) && ((--__numKeyboard) == 0)) + { + cap = cap & (~DSWaylandSeat::capKeyboard); + capNeedUpdate = true; + } + else if ((device->getClass() == DSInput::TouchClass) && ((--__numTouch) == 0)) + { + cap = cap & (~DSWaylandSeat::capTouch); + capNeedUpdate = true; + } + + if (capNeedUpdate) + __dswlSeat->setCapability((DSWaylandSeat::seatCapability)cap); } } // namespace display_server \ No newline at end of file diff --git a/src/DSSeat/DSSeat.h b/src/DSSeat/DSSeat.h index b4585ad..2ac4e8b 100644 --- a/src/DSSeat/DSSeat.h +++ b/src/DSSeat/DSSeat.h @@ -11,11 +11,15 @@ class DSKeyboard; class DSPointer; class DSTouch; class DSInputDevice; +class DSCompositor; +class DSWaylandSeat; +class DSWaylandCompositor; class DSSeat : public DSObject { public: DSSeat(); + DSSeat(DSCompositor *compositor, std::string name); virtual ~DSSeat(); bool addInput(std::shared_ptr input); @@ -29,6 +33,13 @@ private: DSKeyboard *__keyboard; DSPointer *__pointer; DSTouch *__touch; + DSWaylandSeat *__dswlSeat; + DSWaylandCompositor *__dswlComp; + DSCompositor *__compositor; + + uint32_t __numPointer; + uint32_t __numKeyboard; + uint32_t __numTouch; }; } diff --git a/src/DSWaylandServer/DSWaylandCompositor.cpp b/src/DSWaylandServer/DSWaylandCompositor.cpp index 0790310..4e12430 100644 --- a/src/DSWaylandServer/DSWaylandCompositor.cpp +++ b/src/DSWaylandServer/DSWaylandCompositor.cpp @@ -1,6 +1,7 @@ #include "DSWaylandCompositor.h" #include "DSWaylandCompositorPrivate.h" #include "DSWaylandClient.h" +#include "DSWaylandSeat.h" #include "DSWaylandSurface.h" #include "DSDebugLog.h" @@ -265,6 +266,38 @@ bool DSWaylandCompositor::isCreated() return priv->_created; } +DSWaylandSeat *DSWaylandCompositorPrivate::addSeat(uint32_t cap) +{ + DSWaylandSeat *dswlSeat = new DSWaylandSeat(_compositor, (DSWaylandSeat::seatCapability)cap); + + if (!dswlSeat) + { + DSLOG_ERR("DSWaylandCompositorPrivate", "Failed to create DSWaylandSeat !"); + return nullptr; + } + + //TODO : check if the client is in clients already ? + _seats.push_back(dswlSeat); + + DSLOG_INF("DSWaylandCompositorPrivate", "Seat(%p) has been added.", dswlSeat); + + //TODO : emit seatAdded signal + + return dswlSeat; +} + +void DSWaylandCompositorPrivate::removeSeat(DSWaylandSeat *dswlSeat) +{ + DS_ASSERT(dswlSeat != nullptr); + + //TODO : check if the client is in clients already ? + _seats.remove(dswlSeat); + DSLOG_INF("DSWaylandCompositorPrivate", "Seat(%p) has been removed.", dswlSeat); + + //TODO : emit seatRemoved signal before deleting a seat; + delete dswlSeat; +} + std::string DSWaylandCompositor::socketName() { DS_GET_PRIV(DSWaylandCompositor); @@ -272,7 +305,7 @@ std::string DSWaylandCompositor::socketName() return priv->_socketName; } -struct wl_display *DSWaylandCompositor::display() +struct ::wl_display *DSWaylandCompositor::display() { DS_GET_PRIV(DSWaylandCompositor); @@ -300,11 +333,11 @@ void DSWaylandCompositor::removeClient(DSWaylandClient *client) priv->removeClient(client); } -void DSWaylandCompositor::addSeat(DSWaylandSeat *seat) +DSWaylandSeat *DSWaylandCompositor::addSeat(uint32_t cap) { DS_GET_PRIV(DSWaylandCompositor); - priv->addSeat(seat); + return priv->addSeat(cap); } void DSWaylandCompositor::removeSeat(DSWaylandSeat *seat) diff --git a/src/DSWaylandServer/DSWaylandCompositor.h b/src/DSWaylandServer/DSWaylandCompositor.h index 53dae1d..37a8a15 100644 --- a/src/DSWaylandServer/DSWaylandCompositor.h +++ b/src/DSWaylandServer/DSWaylandCompositor.h @@ -14,6 +14,7 @@ class DSWaylandClient; class DSWaylandSeat; class DSWaylandSurface; class DSWaylandCompositorPrivate; + class DS_DECL_EXPORT DSWaylandCompositor : public DSObject { DS_PIMPL_USE_PRIVATE(DSWaylandCompositor); @@ -26,11 +27,11 @@ public: void addClient(DSWaylandClient *client); void removeClient(DSWaylandClient *client); - void addSeat(DSWaylandSeat *seat); + DSWaylandSeat *addSeat(uint32_t cap); void removeSeat(DSWaylandSeat *seat); std::string socketName(); - ::wl_display *display(); + struct ::wl_display *display(); uint32_t nextSerial(); std::list clients(); DSWaylandSeat *defaultSeat(); @@ -44,9 +45,9 @@ protected: private: // signals - DSSignal> __surfaceCreatedSignal; + DSSignal> __surfaceCreatedSignal; }; } -#endif //__DS_WAYLAND_COMPOSITOR_H__ \ No newline at end of file +#endif //__DS_WAYLAND_COMPOSITOR_H__ diff --git a/src/DSWaylandServer/DSWaylandCompositorPrivate.h b/src/DSWaylandServer/DSWaylandCompositorPrivate.h index f33c4b4..0e33b3e 100644 --- a/src/DSWaylandServer/DSWaylandCompositorPrivate.h +++ b/src/DSWaylandServer/DSWaylandCompositorPrivate.h @@ -28,8 +28,8 @@ public: void initSocket(std::string sName, std::string sDir); inline void addClient(DSWaylandClient *client); inline void removeClient(DSWaylandClient *client); - inline void addSeat(DSWaylandSeat *seat); - inline void removeSeat(DSWaylandSeat *seat); + DSWaylandSeat *addSeat(uint32_t cap); + void removeSeat(DSWaylandSeat *seat); static void client_created_callback(struct ::wl_listener *listener, void *data); struct ClientCreatedListener : ::wl_listener { @@ -50,7 +50,7 @@ protected: bool _created; int _socketFD; std::string _socketName; - struct wl_display *_display; + struct ::wl_display *_display; wl_event_loop *_loop; Ecore_Fd_Handler *_socket_fd_handler; DSWaylandCompositor *_compositor; @@ -81,22 +81,6 @@ void DSWaylandCompositorPrivate::removeClient(DSWaylandClient *client) DSLOG_INF("DSWaylandCompositorPrivate", "Client(%p, PID:%d) has been removed.", client, client->pid()); } -void DSWaylandCompositorPrivate::addSeat(DSWaylandSeat *seat) -{ - DS_ASSERT(seat != nullptr); - - //TODO : check if the client is in clients already ? - _seats.push_back(seat); -} - -void DSWaylandCompositorPrivate::removeSeat(DSWaylandSeat *seat) -{ - DS_ASSERT(seat != nullptr); - - //TODO : check if the client is in clients already ? - _seats.remove(seat); -} - } #endif //__DS_WAYLAND_COMPOSITOR_PRIVATE_H__ \ No newline at end of file diff --git a/src/DSWaylandServer/DSWaylandSeat.cpp b/src/DSWaylandServer/DSWaylandSeat.cpp index 1104844..6a46cc6 100644 --- a/src/DSWaylandServer/DSWaylandSeat.cpp +++ b/src/DSWaylandServer/DSWaylandSeat.cpp @@ -1,5 +1,10 @@ #include "DSWaylandSeat.h" #include "DSWaylandSeatPrivate.h" +#include "DSWaylandCompositor.h" +#include "DSWaylandClient.h" +#include "DSWaylandPointer.h" +#include "DSWaylandKeyboard.h" +#include "DSWaylandTouch.h" namespace display_server { @@ -9,63 +14,146 @@ DSWaylandSeatPrivate::DSWaylandSeatPrivate(DSWaylandCompositor *compositor, DSWa : DSObjectPrivate(seat), __p_ptr(seat), __cap(DSWaylandSeat::capNone), - __compositor(compositor) + __compositor(compositor), + __pointer(nullptr), + __keyboard(nullptr), + __touch(nullptr) { + if (!compositor) + return; + + wl_seat::init(compositor->display(), 4); } DSWaylandSeatPrivate::~DSWaylandSeatPrivate() { } +void DSWaylandSeatPrivate::sendCapabilitiesToAllClients(uint32_t cap) +{ + auto func = [&](std::pair res) + { wl_seat::send_capabilities(res.second->handle, cap); }; + auto resMap = resourceMap(); + std::for_each(resMap.begin(), resMap.end(), func); +} + void DSWaylandSeatPrivate::seat_bind_resource(Resource *resource) { + /* send capabilities */ + wl_seat::send_capabilities(resource->handle, (uint32_t)__cap); + + /* send seat name */ + if (!__seatName.empty()) + wl_seat::send_name(resource->handle, __seatName); } void DSWaylandSeatPrivate::seat_destroy_resource(Resource *resource) { + //Nothing to do as wl_seat::destroy_func has removed the resource->handle from m_resource_map } void DSWaylandSeatPrivate::seat_get_pointer(Resource *resource, uint32_t id) { + //TODO : add DSWaylandPointer here + //TODO : send pointer_enter here if this client equals to top-visible window's client + if (!__pointer) + return; + + __pointer->addClient(DSWaylandClient::fromWlClient(resource->client()), id, resource->version()); } void DSWaylandSeatPrivate::seat_get_keyboard(Resource *resource, uint32_t id) { + //TODO : add DSWaylandKeyboard here + //TODO : send repeat info to the client + //TODO : send keyboard_enter here if this client equals to focus window's client + if (!__keyboard) + return; + + __keyboard->addClient(DSWaylandClient::fromWlClient(resource->client()), id, resource->version()); } void DSWaylandSeatPrivate::seat_get_touch(Resource *resource, uint32_t id) { + //TODO : add DSWaylandTouch here + if (!__touch) + return; + + __touch->addClient(DSWaylandClient::fromWlClient(resource->client()), id, resource->version()); } void DSWaylandSeatPrivate::seat_release(Resource *resource) { + //TODO : Check if we should destroy wl_resource here. } /* Begin Public Class Implementation */ DSWaylandSeat::DSWaylandSeat(DSWaylandCompositor *compositor, DSWaylandSeat::seatCapability cap) : DSObject(), _d_ptr(std::make_unique(compositor, this)) { - DS_GET_PRIV(DSWaylandSeat); - - priv->__cap = cap; + setCapability(cap); } DSWaylandSeat::~DSWaylandSeat() { } -void DSWaylandSeat::setCapability(DSWaylandSeat::seatCapability cap) +void DSWaylandSeat::sendCapabilitiesToAllClients(uint32_t cap) { DS_GET_PRIV(DSWaylandSeat); - priv->__cap = cap; + priv->sendCapabilitiesToAllClients(cap); } -void DSWaylandSeat::updateCapability(DSWaylandSeat::seatCapability cap) +void DSWaylandSeat::setCapability(DSWaylandSeat::seatCapability cap) { DS_GET_PRIV(DSWaylandSeat); - priv->__cap = (DSWaylandSeat::seatCapability)((int)priv->__cap | cap); + DSLOG_INF("DSWaylandSeat","cap=%d, priv->__cap=%d", cap, priv->__cap); + + if (cap == priv->__cap) + { + return; + } + + DSWaylandSeat::seatCapability diff = DSWaylandSeat::seatCapability((uint32_t)priv->__cap ^ cap); + + if (diff & DSWaylandSeat::capPointer) + { + if (!priv->__pointer) + { + priv->__pointer = new DSWaylandPointer(this); + DS_ASSERT(priv->__pointer); + DSLOG_INF("DSWaylandSeat", "DSWaylandPointer has been created."); + } + } + + if (diff & DSWaylandSeat::capKeyboard) + { + if (!priv->__keyboard) + { + priv->__keyboard = new DSWaylandKeyboard(this); + DS_ASSERT(priv->__keyboard); + DSLOG_INF("DSWaylandSeat", "DSWaylandKeyboard has been created."); + } + } + + if (diff & DSWaylandSeat::capTouch) + { + if (!priv->__touch) + { + priv->__touch = new DSWaylandTouch(this); + DS_ASSERT(priv->__touch); + DSLOG_INF("DSWaylandSeat", "DSWaylandTouch has been created."); + } + } + + /* send capabilities when it is updated */ + sendCapabilitiesToAllClients((uint32_t)cap); + + //TODO : check if we should set focus if the keyboard cap has been added newly. + + priv->__cap = cap; } DSWaylandSeat::seatCapability DSWaylandSeat::getCapability(void) @@ -75,4 +163,13 @@ DSWaylandSeat::seatCapability DSWaylandSeat::getCapability(void) return priv->__cap; } +void DSWaylandSeat::setName(std::string name) +{ + DS_GET_PRIV(DSWaylandSeat); + + //TODO : check if we should send name to client(s) when it has a name. + + priv->__seatName = name; +} + } diff --git a/src/DSWaylandServer/DSWaylandSeat.h b/src/DSWaylandServer/DSWaylandSeat.h index 6d329a3..55b93d6 100644 --- a/src/DSWaylandServer/DSWaylandSeat.h +++ b/src/DSWaylandServer/DSWaylandSeat.h @@ -28,9 +28,10 @@ public: DSWaylandSeat(DSWaylandCompositor *compositor, DSWaylandSeat::seatCapability cap); ~DSWaylandSeat() override; + void sendCapabilitiesToAllClients(uint32_t cap); void setCapability(DSWaylandSeat::seatCapability cap); - void updateCapability(DSWaylandSeat::seatCapability cap); DSWaylandSeat::seatCapability getCapability(void); + void setName(std::string name); protected: diff --git a/src/DSWaylandServer/DSWaylandSeatPrivate.h b/src/DSWaylandServer/DSWaylandSeatPrivate.h index c7b6056..3ddc15f 100644 --- a/src/DSWaylandServer/DSWaylandSeatPrivate.h +++ b/src/DSWaylandServer/DSWaylandSeatPrivate.h @@ -8,6 +8,10 @@ namespace display_server { +class DSWaylandPointer; +class DSWaylandKeyboard; +class DSWaylandTouch; + class DS_DECL_EXPORT DSWaylandSeatPrivate : public DSObjectPrivate, public DSWaylandServer::wl_seat { DS_PIMPL_USE_PUBLIC(DSWaylandSeat); @@ -15,6 +19,8 @@ public: DSWaylandSeatPrivate(DSWaylandCompositor *compositor, DSWaylandSeat *seat); ~DSWaylandSeatPrivate() override; + void sendCapabilitiesToAllClients(uint32_t cap); + protected: void seat_bind_resource(Resource *resource) override; void seat_destroy_resource(Resource *resource) override; @@ -26,6 +32,11 @@ protected: private: DSWaylandSeat::seatCapability __cap; DSWaylandCompositor *__compositor; + std::string __seatName; + + DSWaylandPointer *__pointer; + DSWaylandKeyboard *__keyboard; + DSWaylandTouch *__touch; }; } diff --git a/tests/DSInput-test.cpp b/tests/DSInput-test.cpp index 75c4aaf..80d1ef4 100644 --- a/tests/DSInput-test.cpp +++ b/tests/DSInput-test.cpp @@ -1,5 +1,6 @@ #include "libds-tests.h" #include "DSInput.h" +#include "DSSeat.h" using namespace display_server; @@ -37,51 +38,63 @@ public: TEST_F(DSInputTest, NewDSInput) { - DSInput *input = new DSInput; - delete input; - ASSERT_TRUE(true); + DSInput *input = new DSInput(); + EXPECT_TRUE(input != nullptr); + + if (input) + delete input; } TEST_F(DSInputTest, DSInputInit) { - DSInput *input = new DSInput; - - input->Init(); - delete input; + DSInput *input = new DSInput(); + EXPECT_TRUE(input != nullptr); - EXPECT_TRUE(true); + if (input) + { + input->init(); + delete input; + } } TEST_F(DSInputTest, DSInputDeviceAddedRemoved) { - DSInput *input = new DSInput; + DSInput *input = new DSInput(); DSInputDevice *device = new DSInputDevice("MockTestDevice", "MockTest", DSInput::KeyboardClass, DSInput::NoneSubclass); MockInput *mockInput = new MockInput; MockInput *mockInput2 = new MockInput; - input->Init(); + EXPECT_TRUE(input != nullptr); + EXPECT_TRUE(device != nullptr); + EXPECT_TRUE(mockInput != nullptr); + EXPECT_TRUE(mockInput2 != nullptr); + + if (input) + { + input->init(); - input->registerCallbackDeviceAdd(mockInput, std::bind(&MockInput::slotDeviceAdded, mockInput, std::placeholders::_1)); - input->deviceAdd(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); - EXPECT_TRUE(*(mockInput->device.get()) == *device); + input->registerCallbackDeviceAdd(mockInput, std::bind(&MockInput::slotDeviceAdded, mockInput, std::placeholders::_1)); + input->deviceAdd(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + EXPECT_TRUE(*(mockInput->device.get()) == *device); - input->registerCallbackDeviceAdd(mockInput2, std::bind(&MockInput::slotDeviceAdded, mockInput2, std::placeholders::_1)); - input->deviceAdd(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); - EXPECT_FALSE(*(mockInput2->device.get()) == *device); + input->registerCallbackDeviceAdd(mockInput2, std::bind(&MockInput::slotDeviceAdded, mockInput2, std::placeholders::_1)); + input->deviceAdd(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + EXPECT_FALSE(*(mockInput2->device.get()) == *device); - input->registerCallbackDeviceRemove(mockInput, std::bind(&MockInput::slotDeviceRemoved, mockInput, std::placeholders::_1)); - input->deviceRemove(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); - EXPECT_TRUE(*(mockInput->device.get()) == *device); + input->registerCallbackDeviceRemove(mockInput, std::bind(&MockInput::slotDeviceRemoved, mockInput, std::placeholders::_1)); + input->deviceRemove(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + EXPECT_TRUE(*(mockInput->device.get()) == *device); - input->registerCallbackDeviceRemove(mockInput2, std::bind(&MockInput::slotDeviceRemoved, mockInput2, std::placeholders::_1)); - input->deviceRemove(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); + input->registerCallbackDeviceRemove(mockInput2, std::bind(&MockInput::slotDeviceRemoved, mockInput2, std::placeholders::_1)); + input->deviceRemove(device->getName(), device->getIdentifier(), device->getClass(), device->getSubclass()); - EXPECT_FALSE(*(mockInput2->device.get()) == *device); + EXPECT_FALSE(*(mockInput2->device.get()) == *device); - delete mockInput2; - delete mockInput; - delete device; - delete input; + delete mockInput2; + delete mockInput; + delete device; + delete input; + } } diff --git a/tests/DSSeat-test.cpp b/tests/DSSeat-test.cpp index 4cc99ac..baded98 100644 --- a/tests/DSSeat-test.cpp +++ b/tests/DSSeat-test.cpp @@ -1,5 +1,6 @@ #include "libds-tests.h" #include "DSSeat.h" +#include "DSCompositor.h" using namespace display_server; @@ -12,18 +13,59 @@ public: {} }; +class MockCompositor : public DSCompositor +{ +public: + MockCompositor() {} + ~MockCompositor() {} + + std::shared_ptr _onInitialized() override + { + auto canvas = std::make_shared(); + return canvas; + } + + void _onOutputAdded(std::shared_ptr output) override + {} + + void _onOutputRemoved(std::shared_ptr output) override + {} + + void _onInputAdded(std::shared_ptr input) override + {} + + void _onInputRemoved(std::shared_ptr input) override + {} +}; + TEST_F(DSSeatTest, NewDSSeat) { - DSSeat *seat = new DSSeat; - delete seat; - ASSERT_TRUE(true); + DSSeat *seat = new DSSeat(); + + EXPECT_TRUE(seat != nullptr); + + if (seat) + delete seat; } TEST_F(DSSeatTest, BasicMethods) { - DSSeat seat; - auto input = std::make_shared(); + std::string seatName{"default"}; + std::shared_ptr compositor = std::make_shared(); + EXPECT_TRUE(compositor != nullptr); + + if (compositor) + { + std::shared_ptr seat = std::make_shared(compositor.get(), seatName); + EXPECT_TRUE(seat != nullptr); + + auto input = std::make_shared(seat); + EXPECT_TRUE(input != nullptr); - EXPECT_TRUE(seat.addInput(input) == true); - EXPECT_TRUE(seat.removeInput(input) == true); + if (input) + { + EXPECT_TRUE(seat->addInput(input) == true); + EXPECT_TRUE(seat->removeInput(input) == true); + } + } } diff --git a/tests/DSWaylandCompositor-test.cpp b/tests/DSWaylandCompositor-test.cpp index 5b4ffa9..fc17af2 100644 --- a/tests/DSWaylandCompositor-test.cpp +++ b/tests/DSWaylandCompositor-test.cpp @@ -142,18 +142,15 @@ TEST_F(DSWaylandCompositorTest, GetDefaultSeat) res = comp->create(); EXPECT_TRUE(res == true); - DSWaylandSeat *seat = new DSWaylandSeat(comp, DSWaylandSeat::capDefault); + DSWaylandSeat *seat = comp->addSeat((uint32_t)DSWaylandSeat::capDefault); EXPECT_TRUE(seat != nullptr); if (seat) { - comp->addSeat(seat); EXPECT_TRUE(comp->defaultSeat() != nullptr); comp->removeSeat(seat); EXPECT_TRUE(comp->defaultSeat() == nullptr); - - delete seat; } delete comp; diff --git a/tests/DSWaylandSeat-test.cpp b/tests/DSWaylandSeat-test.cpp index 6152f17..e389ca0 100644 --- a/tests/DSWaylandSeat-test.cpp +++ b/tests/DSWaylandSeat-test.cpp @@ -52,10 +52,12 @@ TEST_F(DSWaylandSeatTest, SetUpdateGetCapabilities) seat->setCapability(DSWaylandSeat::capKeyboard); EXPECT_TRUE(DSWaylandSeat::capKeyboard == seat->getCapability()); - seat->updateCapability(DSWaylandSeat::capPointer); - EXPECT_TRUE(DSWaylandSeat::capKeyboard & seat->getCapability()); - EXPECT_TRUE(DSWaylandSeat::capPointer & seat->getCapability()); - + seat->setCapability(DSWaylandSeat::capPointer); + EXPECT_TRUE(DSWaylandSeat::capPointer == seat->getCapability()); + + seat->setCapability(DSWaylandSeat::capTouch); + EXPECT_TRUE(DSWaylandSeat::capTouch == seat->getCapability()); + delete seat; }