File indexing completed on 2024-05-12 05:42:41
0001 #include <cutehmi/Messenger.hpp> 0002 #include <cutehmi/Message.hpp> 0003 0004 #include <cutehmi/test/random.hpp> 0005 0006 #include <QtTest/QtTest> 0007 0008 namespace cutehmi { 0009 0010 class test_Messenger: 0011 public QObject 0012 { 0013 Q_OBJECT 0014 0015 private slots: 0016 void initTestCase(); 0017 0018 void noAdvertiser(); 0019 0020 void advertise(); 0021 }; 0022 0023 class AdvertiserMock: 0024 public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 Message::Button response; 0030 0031 public slots: 0032 void createDialog(QVariant message); 0033 }; 0034 0035 void test_Messenger::initTestCase() 0036 { 0037 } 0038 0039 void test_Messenger::noAdvertiser() 0040 { 0041 Message message(Message::INFO, "Message", Message::BUTTON_APPLY | Message::BUTTON_CANCEL); 0042 try { 0043 Messenger::Instance().advertise(& message); 0044 } catch (const Messenger::NoAdvertiserException & e) { 0045 QCOMPARE(e.message()->type(), Message::INFO); 0046 QCOMPARE(e.message()->text(), "Message"); 0047 QCOMPARE(e.message()->buttons(), Message::BUTTON_APPLY | Message::BUTTON_CANCEL); 0048 } 0049 } 0050 0051 void test_Messenger::advertise() 0052 { 0053 Message message(Message::INFO, "Message", Message::BUTTON_APPLY | Message::BUTTON_CANCEL); 0054 AdvertiserMock advertiserMock; 0055 advertiserMock.response = Message::BUTTON_CANCEL; 0056 Messenger::Instance().resetAdvertiser(& advertiserMock); 0057 Messenger::Instance().advertise(& message); 0058 QCOMPARE(message.response(), advertiserMock.response); 0059 } 0060 0061 void AdvertiserMock::createDialog(QVariant message) 0062 { 0063 Q_UNUSED(message) 0064 0065 message.value<Message *>()->acceptResponse(response); 0066 } 0067 0068 } 0069 0070 QTEST_MAIN(cutehmi::test_Messenger) 0071 #include "test_Messenger.moc" 0072 0073 //(c)C: Copyright © 2019-2020, Michał Policht <michal@policht.pl>. All rights reserved. 0074 //(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT 0075 //(c)C: This file is a part of CuteHMI. 0076 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 0077 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 0078 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>. 0079 //(c)C: Additionally, this file is licensed under terms of MIT license as expressed below. 0080 //(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 0081 //(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 0082 //(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.