void Client::sendClipboard(ClipboardID id) { // note -- m_mutex must be locked on entry assert(m_screen != NULL); assert(m_server != NULL); // get clipboard data. set the clipboard time to the last // clipboard time before getting the data from the screen // as the screen may detect an unchanged clipboard and // avoid copying the data. Clipboard clipboard; if (clipboard.open(m_timeClipboard[id])) { clipboard.close(); } m_screen->getClipboard(id, &clipboard); // check time if (m_timeClipboard[id] == 0 || clipboard.getTime() != m_timeClipboard[id]) { // save new time m_timeClipboard[id] = clipboard.getTime(); // marshall the data String data = clipboard.marshall(); // save and send data if different or not yet sent if (!m_sentClipboard[id] || data != m_dataClipboard[id]) { m_sentClipboard[id] = true; m_dataClipboard[id] = data; m_server->onClipboardChanged(id, &clipboard); } } }
TEST(ClipboardTests, getTime_openWithNoEmpty_returnsZero) { Clipboard clipboard; clipboard.open(1); Clipboard::Time actual = clipboard.getTime(); EXPECT_EQ(0, actual); }
TEST(ClipboardTests, getTime_openAndEmpty_returnsOne) { Clipboard clipboard; clipboard.open(1); clipboard.empty(); Clipboard::Time actual = clipboard.getTime(); EXPECT_EQ(1, actual); }