1 /*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2012-2016 Symless Ltd.
4 * Copyright (C) 2011 Nick Bolton
5 *
6 * This package is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * found in the file LICENSE that should have accompanied this file.
9 *
10 * This package is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "platform/OSXClipboard.h"
20
21 #include "test/global/gtest.h"
22 #include <iostream>
23
TEST(OSXClipboardTests,empty_openCalled_returnsTrue)24 TEST(OSXClipboardTests, empty_openCalled_returnsTrue)
25 {
26 OSXClipboard clipboard;
27 clipboard.open(0);
28
29 bool actual = clipboard.empty();
30
31 EXPECT_EQ(true, actual);
32 }
33
TEST(OSXClipboardTests,empty_singleFormat_hasReturnsFalse)34 TEST(OSXClipboardTests, empty_singleFormat_hasReturnsFalse)
35 {
36 OSXClipboard clipboard;
37 clipboard.open(0);
38 clipboard.add(OSXClipboard::kText, "synergy rocks!");
39
40 clipboard.empty();
41
42 bool actual = clipboard.has(OSXClipboard::kText);
43 EXPECT_EQ(false, actual);
44 }
45
TEST(OSXClipboardTests,add_newValue_valueWasStored)46 TEST(OSXClipboardTests, add_newValue_valueWasStored)
47 {
48 OSXClipboard clipboard;
49 clipboard.open(0);
50
51 clipboard.add(IClipboard::kText, "synergy rocks!");
52
53 String actual = clipboard.get(IClipboard::kText);
54 EXPECT_EQ("synergy rocks!", actual);
55 }
56
TEST(OSXClipboardTests,add_replaceValue_valueWasReplaced)57 TEST(OSXClipboardTests, add_replaceValue_valueWasReplaced)
58 {
59 OSXClipboard clipboard;
60 clipboard.open(0);
61
62 clipboard.add(IClipboard::kText, "synergy rocks!");
63 clipboard.add(IClipboard::kText, "maxivista sucks"); // haha, just kidding.
64
65 String actual = clipboard.get(IClipboard::kText);
66 EXPECT_EQ("maxivista sucks", actual);
67 }
68
TEST(OSXClipboardTests,open_timeIsZero_returnsTrue)69 TEST(OSXClipboardTests, open_timeIsZero_returnsTrue)
70 {
71 OSXClipboard clipboard;
72
73 bool actual = clipboard.open(0);
74
75 EXPECT_EQ(true, actual);
76 }
77
TEST(OSXClipboardTests,open_timeIsOne_returnsTrue)78 TEST(OSXClipboardTests, open_timeIsOne_returnsTrue)
79 {
80 OSXClipboard clipboard;
81
82 bool actual = clipboard.open(1);
83
84 EXPECT_EQ(true, actual);
85 }
86
TEST(OSXClipboardTests,close_isOpen_noErrors)87 TEST(OSXClipboardTests, close_isOpen_noErrors)
88 {
89 OSXClipboard clipboard;
90 clipboard.open(0);
91
92 clipboard.close();
93
94 // can't assert anything
95 }
96
TEST(OSXClipboardTests,getTime_openWithNoEmpty_returnsOne)97 TEST(OSXClipboardTests, getTime_openWithNoEmpty_returnsOne)
98 {
99 OSXClipboard clipboard;
100 clipboard.open(1);
101
102 OSXClipboard::Time actual = clipboard.getTime();
103
104 // this behavior is different to that of Clipboard which only
105 // returns the value passed into open(t) after empty() is called.
106 EXPECT_EQ((UInt32)1, actual);
107 }
108
TEST(OSXClipboardTests,getTime_openAndEmpty_returnsOne)109 TEST(OSXClipboardTests, getTime_openAndEmpty_returnsOne)
110 {
111 OSXClipboard clipboard;
112 clipboard.open(1);
113 clipboard.empty();
114
115 OSXClipboard::Time actual = clipboard.getTime();
116
117 EXPECT_EQ((UInt32)1, actual);
118 }
119
TEST(OSXClipboardTests,has_withFormatAdded_returnsTrue)120 TEST(OSXClipboardTests, has_withFormatAdded_returnsTrue)
121 {
122 OSXClipboard clipboard;
123 clipboard.open(0);
124 clipboard.empty();
125 clipboard.add(IClipboard::kText, "synergy rocks!");
126
127 bool actual = clipboard.has(IClipboard::kText);
128
129 EXPECT_EQ(true, actual);
130 }
131
TEST(OSXClipboardTests,has_withNoFormats_returnsFalse)132 TEST(OSXClipboardTests, has_withNoFormats_returnsFalse)
133 {
134 OSXClipboard clipboard;
135 clipboard.open(0);
136 clipboard.empty();
137
138 bool actual = clipboard.has(IClipboard::kText);
139
140 EXPECT_EQ(false, actual);
141 }
142
TEST(OSXClipboardTests,get_withNoFormats_returnsEmpty)143 TEST(OSXClipboardTests, get_withNoFormats_returnsEmpty)
144 {
145 OSXClipboard clipboard;
146 clipboard.open(0);
147 clipboard.empty();
148
149 String actual = clipboard.get(IClipboard::kText);
150
151 EXPECT_EQ("", actual);
152 }
153
TEST(OSXClipboardTests,get_withFormatAdded_returnsExpected)154 TEST(OSXClipboardTests, get_withFormatAdded_returnsExpected)
155 {
156 OSXClipboard clipboard;
157 clipboard.open(0);
158 clipboard.empty();
159 clipboard.add(IClipboard::kText, "synergy rocks!");
160
161 String actual = clipboard.get(IClipboard::kText);
162
163 EXPECT_EQ("synergy rocks!", actual);
164 }
165