refactor: port OSXClipboardTests to QtTests
This commit is contained in:
parent
139dbf61f3
commit
b8c6d1b58f
5 changed files with 71 additions and 168 deletions
|
|
@ -1,144 +0,0 @@
|
||||||
/*
|
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
|
||||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
||||||
* SPDX-FileCopyrightText: (C) 2011 Nick Bolton
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: fix failing tests (e.g. add_newValue_valueWasStored)
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
#include "platform/OSXClipboard.h"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, empty_openCalled_returnsTrue) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
|
|
||||||
bool actual = clipboard.empty();
|
|
||||||
|
|
||||||
EXPECT_EQ(true, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, empty_singleFormat_hasReturnsFalse) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
clipboard.add(OSXClipboard::kText, "synergy rocks!");
|
|
||||||
|
|
||||||
clipboard.empty();
|
|
||||||
|
|
||||||
bool actual = clipboard.has(OSXClipboard::kText);
|
|
||||||
EXPECT_EQ(false, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, add_newValue_valueWasStored) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
|
|
||||||
clipboard.add(IClipboard::kText, "synergy rocks!");
|
|
||||||
|
|
||||||
std::string actual = clipboard.get(IClipboard::kText);
|
|
||||||
EXPECT_EQ("synergy rocks!", actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, add_replaceValue_valueWasReplaced) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
|
|
||||||
clipboard.add(IClipboard::kText, "synergy rocks!");
|
|
||||||
clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding.
|
|
||||||
|
|
||||||
std::string actual = clipboard.get(IClipboard::kText);
|
|
||||||
EXPECT_EQ("maxivista sucks", actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, open_timeIsZero_returnsTrue) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
|
|
||||||
bool actual = clipboard.open(0);
|
|
||||||
|
|
||||||
EXPECT_EQ(true, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, open_timeIsOne_returnsTrue) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
|
|
||||||
bool actual = clipboard.open(1);
|
|
||||||
|
|
||||||
EXPECT_EQ(true, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, close_isOpen_noErrors) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
|
|
||||||
clipboard.close();
|
|
||||||
|
|
||||||
// can't assert anything
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, getTime_openWithNoEmpty_returnsOne) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(1);
|
|
||||||
|
|
||||||
OSXClipboard::Time actual = clipboard.getTime();
|
|
||||||
|
|
||||||
// this behavior is different to that of Clipboard which only
|
|
||||||
// returns the value passed into open(t) after empty() is called.
|
|
||||||
EXPECT_EQ((uint32_t)1, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, getTime_openAndEmpty_returnsOne) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(1);
|
|
||||||
clipboard.empty();
|
|
||||||
|
|
||||||
OSXClipboard::Time actual = clipboard.getTime();
|
|
||||||
|
|
||||||
EXPECT_EQ((uint32_t)1, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, has_withFormatAdded_returnsTrue) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
clipboard.empty();
|
|
||||||
clipboard.add(IClipboard::kText, "synergy rocks!");
|
|
||||||
|
|
||||||
bool actual = clipboard.has(IClipboard::kText);
|
|
||||||
|
|
||||||
EXPECT_EQ(true, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, has_withNoFormats_returnsFalse) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
clipboard.empty();
|
|
||||||
|
|
||||||
bool actual = clipboard.has(IClipboard::kText);
|
|
||||||
|
|
||||||
EXPECT_EQ(false, actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, get_withNoFormats_returnsEmpty) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
clipboard.empty();
|
|
||||||
|
|
||||||
std::string actual = clipboard.get(IClipboard::kText);
|
|
||||||
|
|
||||||
EXPECT_EQ("", actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardTests, get_withFormatAdded_returnsExpected) {
|
|
||||||
OSXClipboard clipboard;
|
|
||||||
clipboard.open(0);
|
|
||||||
clipboard.empty();
|
|
||||||
clipboard.add(IClipboard::kText, "synergy rocks!");
|
|
||||||
|
|
||||||
std::string actual = clipboard.get(IClipboard::kText);
|
|
||||||
|
|
||||||
EXPECT_EQ("synergy rocks!", actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
/*
|
|
||||||
* Deskflow -- mouse and keyboard sharing utility
|
|
||||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
||||||
* SPDX-FileCopyrightText: (C) 2011 Nick Bolton
|
|
||||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "platform/OSXClipboardUTF8Converter.h"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
TEST(OSXClipboardUTF8ConverterTests, test_Format)
|
|
||||||
{
|
|
||||||
OSXClipboardUTF8Converter converter;
|
|
||||||
EXPECT_EQ(IClipboard::kText, converter.getFormat());
|
|
||||||
EXPECT_EQ(CFSTR("public.utf8-plain-text"), converter.getOSXFormat());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(OSXClipboardUTF8ConverterTests, test_readWriteClipboard)
|
|
||||||
{
|
|
||||||
OSXClipboardUTF8Converter converter;
|
|
||||||
EXPECT_EQ("test data\r", converter.fromIClipboard("test data\n"));
|
|
||||||
EXPECT_EQ("test data\n", converter.toIClipboard("test data\r"));
|
|
||||||
}
|
|
||||||
|
|
@ -10,6 +10,13 @@ if (WIN32)
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/platform"
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/platform"
|
||||||
)
|
)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
|
create_test(
|
||||||
|
NAME OSXClipboardTests
|
||||||
|
DEPENDS platform
|
||||||
|
LIBS base arch
|
||||||
|
SOURCE OSXClipboardTests.cpp
|
||||||
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/platform"
|
||||||
|
)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
create_test(
|
create_test(
|
||||||
NAME XWindowsClipboardTests
|
NAME XWindowsClipboardTests
|
||||||
|
|
|
||||||
41
src/unittests/platform/OSXClipboardTests.cpp
Normal file
41
src/unittests/platform/OSXClipboardTests.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||||
|
* SPDX-FileCopyrightText: (C) 2011 Nick Bolton
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "OSXClipboardTests.h"
|
||||||
|
|
||||||
|
#include "../../lib/platform/OSXClipboard.h"
|
||||||
|
|
||||||
|
#include "platform/OSXClipboardUTF8Converter.h"
|
||||||
|
|
||||||
|
void OSXClipboardTests::open()
|
||||||
|
{
|
||||||
|
OSXClipboard clipboard;
|
||||||
|
QVERIFY(clipboard.open(0));
|
||||||
|
QVERIFY(clipboard.empty());
|
||||||
|
clipboard.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSXClipboardTests::singleFormat()
|
||||||
|
{
|
||||||
|
OSXClipboard clipboard;
|
||||||
|
QVERIFY(clipboard.empty());
|
||||||
|
clipboard.add(OSXClipboard::kText, m_testString);
|
||||||
|
QVERIFY(clipboard.has(OSXClipboard::kText));
|
||||||
|
QCOMPARE(clipboard.get(OSXClipboard::kText), m_testString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSXClipboardTests::formatConvert_UTF8()
|
||||||
|
{
|
||||||
|
OSXClipboardUTF8Converter converter;
|
||||||
|
QCOMPARE(IClipboard::kText, converter.getFormat());
|
||||||
|
QCOMPARE(converter.getOSXFormat(), CFSTR("public.utf8-plain-text"));
|
||||||
|
QCOMPARE(converter.fromIClipboard("test data\n"), "test data\r");
|
||||||
|
QCOMPARE(converter.toIClipboard("test data\r"), "test data\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(OSXClipboardTests)
|
||||||
23
src/unittests/platform/OSXClipboardTests.h
Normal file
23
src/unittests/platform/OSXClipboardTests.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
*/
|
||||||
|
#include "base/Log.h"
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
class OSXClipboardTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
// Test are run in order top to bottom
|
||||||
|
void open();
|
||||||
|
void singleFormat();
|
||||||
|
void formatConvert_UTF8();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Arch m_arch;
|
||||||
|
Log m_log;
|
||||||
|
const std::string m_testString = "deskflow test string";
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue