From 13c6c36107378e54b5b718cbcb5ce27c9a81edcd Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 9 May 2011 00:28:45 +0000 Subject: [PATCH] merged 1.4 r982:983 into trunk --- .../CMSWindowsClientTaskBarReceiver.cpp | 16 ++-- .../CMSWindowsServerTaskBarReceiver.cpp | 16 ++-- src/lib/arch/CArch.cpp | 4 +- src/lib/arch/CArch.h | 2 +- src/lib/arch/CArchConsoleStd.cpp | 10 ++- src/lib/arch/CArchConsoleStd.h | 2 +- src/lib/arch/IArchConsole.h | 3 +- src/lib/arch/IArchLog.h | 13 +-- src/lib/base/CLog.h | 19 ----- src/lib/base/CMakeLists.txt | 1 + src/lib/base/ELevel.h | 40 +++++++++ src/lib/base/ILogOutputter.h | 3 +- src/lib/base/LogOutputters.cpp | 32 +------ src/lib/synergy/CKeyState.h | 2 + src/test/integtests/Main.cpp | 3 + src/test/unittests/CMakeLists.txt | 3 +- src/test/unittests/Main.cpp | 41 +++++++++ src/test/unittests/synergy/CKeyStateTests.cpp | 84 +++++++++++++++++++ 18 files changed, 208 insertions(+), 86 deletions(-) create mode 100644 src/lib/base/ELevel.h create mode 100644 src/test/unittests/Main.cpp create mode 100644 src/test/unittests/synergy/CKeyStateTests.cpp diff --git a/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp b/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp index ca672765..d84ac309 100644 --- a/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp +++ b/src/cmd/synergyc/CMSWindowsClientTaskBarReceiver.cpp @@ -152,7 +152,7 @@ CMSWindowsClientTaskBarReceiver::runMenu(int x, int y) SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE); HMENU logLevelMenu = GetSubMenu(menu, 3); CheckMenuRadioItem(logLevelMenu, 0, 6, - CLOG->getFilter() - CLog::kERROR, MF_BYPOSITION); + CLOG->getFilter() - kERROR, MF_BYPOSITION); int n = TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | @@ -176,31 +176,31 @@ CMSWindowsClientTaskBarReceiver::runMenu(int x, int y) break; case IDC_TASKBAR_LOG_LEVEL_ERROR: - CLOG->setFilter(CLog::kERROR); + CLOG->setFilter(kERROR); break; case IDC_TASKBAR_LOG_LEVEL_WARNING: - CLOG->setFilter(CLog::kWARNING); + CLOG->setFilter(kWARNING); break; case IDC_TASKBAR_LOG_LEVEL_NOTE: - CLOG->setFilter(CLog::kNOTE); + CLOG->setFilter(kNOTE); break; case IDC_TASKBAR_LOG_LEVEL_INFO: - CLOG->setFilter(CLog::kINFO); + CLOG->setFilter(kINFO); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG: - CLOG->setFilter(CLog::kDEBUG); + CLOG->setFilter(kDEBUG); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG1: - CLOG->setFilter(CLog::kDEBUG1); + CLOG->setFilter(kDEBUG1); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG2: - CLOG->setFilter(CLog::kDEBUG2); + CLOG->setFilter(kDEBUG2); break; case IDC_TASKBAR_QUIT: diff --git a/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp b/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp index 93f3cc7e..1e9c8d74 100644 --- a/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp +++ b/src/cmd/synergys/CMSWindowsServerTaskBarReceiver.cpp @@ -167,7 +167,7 @@ CMSWindowsServerTaskBarReceiver::runMenu(int x, int y) SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE); HMENU logLevelMenu = GetSubMenu(menu, 3); CheckMenuRadioItem(logLevelMenu, 0, 6, - CLOG->getFilter() - CLog::kERROR, MF_BYPOSITION); + CLOG->getFilter() - kERROR, MF_BYPOSITION); int n = TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | @@ -206,31 +206,31 @@ CMSWindowsServerTaskBarReceiver::runMenu(int x, int y) break; case IDC_TASKBAR_LOG_LEVEL_ERROR: - CLOG->setFilter(CLog::kERROR); + CLOG->setFilter(kERROR); break; case IDC_TASKBAR_LOG_LEVEL_WARNING: - CLOG->setFilter(CLog::kWARNING); + CLOG->setFilter(kWARNING); break; case IDC_TASKBAR_LOG_LEVEL_NOTE: - CLOG->setFilter(CLog::kNOTE); + CLOG->setFilter(kNOTE); break; case IDC_TASKBAR_LOG_LEVEL_INFO: - CLOG->setFilter(CLog::kINFO); + CLOG->setFilter(kINFO); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG: - CLOG->setFilter(CLog::kDEBUG); + CLOG->setFilter(kDEBUG); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG1: - CLOG->setFilter(CLog::kDEBUG1); + CLOG->setFilter(kDEBUG1); break; case IDC_TASKBAR_LOG_LEVEL_DEBUG2: - CLOG->setFilter(CLog::kDEBUG2); + CLOG->setFilter(kDEBUG2); break; case IDC_TASKBAR_QUIT: diff --git a/src/lib/arch/CArch.cpp b/src/lib/arch/CArch.cpp index 1a932b8a..4186c084 100644 --- a/src/lib/arch/CArch.cpp +++ b/src/lib/arch/CArch.cpp @@ -189,9 +189,9 @@ CArch::showConsole(bool showIfEmpty) } void -CArch::writeConsole(const char* str) +CArch::writeConsole(ELevel level, const char* str) { - m_console->writeConsole(str); + m_console->writeConsole(level, str); } void diff --git a/src/lib/arch/CArch.h b/src/lib/arch/CArch.h index e286708f..7d36eb15 100644 --- a/src/lib/arch/CArch.h +++ b/src/lib/arch/CArch.h @@ -77,7 +77,7 @@ public: virtual void openConsole(const char*); virtual void closeConsole(); virtual void showConsole(bool showIfEmpty); - virtual void writeConsole(const char*); + virtual void writeConsole(ELevel, const char*); // IArchDaemon overrides virtual void installDaemon(const char* name, diff --git a/src/lib/arch/CArchConsoleStd.cpp b/src/lib/arch/CArchConsoleStd.cpp index 63414b5e..b579bc0a 100644 --- a/src/lib/arch/CArchConsoleStd.cpp +++ b/src/lib/arch/CArchConsoleStd.cpp @@ -16,12 +16,16 @@ */ #include "CArchConsoleStd.h" +#include "CLog.h" #include void -CArchConsoleStd::writeConsole(const char* str) +CArchConsoleStd::writeConsole(ELevel level, const char* str) { - // TODO: we need to use cerr also somehow - std::cout << str << std::endl; + if ((level >= kFATAL) && (level <= kWARNING)) + std::cerr << str << std::endl; + else + std::cout << str << std::endl; + std::cout.flush(); } \ No newline at end of file diff --git a/src/lib/arch/CArchConsoleStd.h b/src/lib/arch/CArchConsoleStd.h index ead16b8c..1863d2a3 100644 --- a/src/lib/arch/CArchConsoleStd.h +++ b/src/lib/arch/CArchConsoleStd.h @@ -29,5 +29,5 @@ public: virtual void openConsole(const char* title) { } virtual void closeConsole() { } virtual void showConsole(bool) { } - virtual void writeConsole(const char*); + virtual void writeConsole(ELevel level, const char*); }; diff --git a/src/lib/arch/IArchConsole.h b/src/lib/arch/IArchConsole.h index 4eb0b6c9..f70efdfc 100644 --- a/src/lib/arch/IArchConsole.h +++ b/src/lib/arch/IArchConsole.h @@ -19,6 +19,7 @@ #define IARCHCONSOLE_H #include "IInterface.h" +#include "ELevel.h" //! Interface for architecture dependent console output /*! @@ -59,7 +60,7 @@ public: /*! Writes the given string to the console, opening it if necessary. */ - virtual void writeConsole(const char*) = 0; + virtual void writeConsole(ELevel, const char*) = 0; //@} }; diff --git a/src/lib/arch/IArchLog.h b/src/lib/arch/IArchLog.h index 60f8f747..12fd4731 100644 --- a/src/lib/arch/IArchLog.h +++ b/src/lib/arch/IArchLog.h @@ -19,6 +19,7 @@ #define IARCHLOG_H #include "IInterface.h" +#include "ELevel.h" //! Interface for architecture dependent logging /*! @@ -27,18 +28,6 @@ synergy. Each architecture must implement this interface. */ class IArchLog : public IInterface { public: - //! Log levels - /*! - The logging priority levels in order of highest to lowest priority. - */ - enum ELevel { - kERROR, //!< For serious or fatal errors - kWARNING, //!< For minor errors and warnings - kNOTE, //!< For messages about notable events - kINFO, //!< For informational messages - kDEBUG //!< For debugging messages - }; - //! @name manipulators //@{ diff --git a/src/lib/base/CLog.h b/src/lib/base/CLog.h index 7592704e..61660507 100644 --- a/src/lib/base/CLog.h +++ b/src/lib/base/CLog.h @@ -38,25 +38,6 @@ LOGC() provide convenient access. */ class CLog { public: - //! Log levels - /*! - The logging priority levels in order of highest to lowest priority. - */ - enum ELevel { - kPRINT = -1, //!< For print only (no file or time) - kFATAL, //!< For fatal errors - kERROR, //!< For serious errors - kWARNING, //!< For minor errors and warnings - kNOTE, //!< For messages about notable events - kINFO, //!< For informational messages - kDEBUG, //!< For important debugging messages - kDEBUG1, //!< For verbosity +1 debugging messages - kDEBUG2, //!< For verbosity +2 debugging messages - kDEBUG3, //!< For verbosity +3 debugging messages - kDEBUG4, //!< For verbosity +4 debugging messages - kDEBUG5 //!< For verbosity +5 debugging messages - }; - ~CLog(); //! @name manipulators diff --git a/src/lib/base/CMakeLists.txt b/src/lib/base/CMakeLists.txt index 41e7e608..d207ba44 100644 --- a/src/lib/base/CMakeLists.txt +++ b/src/lib/base/CMakeLists.txt @@ -34,6 +34,7 @@ set(inc TMethodEventJob.h TMethodJob.h XBase.h + ELevel.h ) set(src diff --git a/src/lib/base/ELevel.h b/src/lib/base/ELevel.h new file mode 100644 index 00000000..1552d40a --- /dev/null +++ b/src/lib/base/ELevel.h @@ -0,0 +1,40 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file COPYING that should have accompanied this file. + * + * This package 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ELEVEL_H +#define ELEVEL_H + +//! Log levels +/*! +The logging priority levels in order of highest to lowest priority. +*/ +enum ELevel { + kPRINT = -1, //!< For print only (no file or time) + kFATAL, //!< For fatal errors + kERROR, //!< For serious errors + kWARNING, //!< For minor errors and warnings + kNOTE, //!< For messages about notable events + kINFO, //!< For informational messages + kDEBUG, //!< For important debugging messages + kDEBUG1, //!< For verbosity +1 debugging messages + kDEBUG2, //!< For verbosity +2 debugging messages + kDEBUG3, //!< For verbosity +3 debugging messages + kDEBUG4, //!< For verbosity +4 debugging messages + kDEBUG5 //!< For verbosity +5 debugging messages +}; + +#endif diff --git a/src/lib/base/ILogOutputter.h b/src/lib/base/ILogOutputter.h index 67c6f441..6aa8b0b3 100644 --- a/src/lib/base/ILogOutputter.h +++ b/src/lib/base/ILogOutputter.h @@ -20,6 +20,7 @@ #include "IInterface.h" #include "CLog.h" +#include "ELevel.h" //! Outputter interface /*! @@ -29,8 +30,6 @@ directly or indirectly. */ class ILogOutputter : public IInterface { public: - typedef CLog::ELevel ELevel; - //! @name manipulators //@{ diff --git a/src/lib/base/LogOutputters.cpp b/src/lib/base/LogOutputters.cpp index 8a5d5802..14189de4 100644 --- a/src/lib/base/LogOutputters.cpp +++ b/src/lib/base/LogOutputters.cpp @@ -92,8 +92,8 @@ CConsoleLogOutputter::show(bool showIfEmpty) bool CConsoleLogOutputter::write(ELevel level, const char* msg) { - ARCH->writeConsole(msg); - return true; // wtf? + ARCH->writeConsole(level, msg); + return true; } void @@ -138,31 +138,7 @@ CSystemLogOutputter::show(bool showIfEmpty) bool CSystemLogOutputter::write(ELevel level, const char* msg) { - IArchLog::ELevel archLogLevel; - switch (level) { - case CLog::kFATAL: - case CLog::kERROR: - archLogLevel = IArchLog::kERROR; - break; - - case CLog::kWARNING: - archLogLevel = IArchLog::kWARNING; - break; - - case CLog::kNOTE: - archLogLevel = IArchLog::kNOTE; - break; - - case CLog::kINFO: - archLogLevel = IArchLog::kINFO; - break; - - default: - archLogLevel = IArchLog::kDEBUG; - break; - - }; - ARCH->writeLog(archLogLevel, msg); + ARCH->writeLog(level, msg); return true; } @@ -266,7 +242,7 @@ CFileLogOutputter::~CFileLogOutputter() } bool -CFileLogOutputter::write(ILogOutputter::ELevel level, const char *message) +CFileLogOutputter::write(ELevel level, const char *message) { std::ofstream m_handle; m_handle.open(m_fileName.c_str(), std::fstream::app); diff --git a/src/lib/synergy/CKeyState.h b/src/lib/synergy/CKeyState.h index 67540b59..7638b2d1 100644 --- a/src/lib/synergy/CKeyState.h +++ b/src/lib/synergy/CKeyState.h @@ -80,6 +80,8 @@ public: virtual SInt32 pollActiveGroup() const = 0; virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const = 0; + SInt32 getKeyState(KeyButton keyButton) { return m_keys[keyButton]; } + protected: typedef CKeyMap::Keystroke Keystroke; diff --git a/src/test/integtests/Main.cpp b/src/test/integtests/Main.cpp index 32f32c1b..c778e67a 100644 --- a/src/test/integtests/Main.cpp +++ b/src/test/integtests/Main.cpp @@ -18,6 +18,7 @@ #include #include #include "CArch.h" +#include "CLog.h" #if SYSAPI_WIN32 #include "CArchMiscWindows.h" @@ -69,6 +70,8 @@ main(int argc, char **argv) CArch arch; + CLOG->setFilter(kDEBUG2); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/src/test/unittests/CMakeLists.txt b/src/test/unittests/CMakeLists.txt index e6943a46..ee396831 100644 --- a/src/test/unittests/CMakeLists.txt +++ b/src/test/unittests/CMakeLists.txt @@ -14,8 +14,9 @@ # along with this program. If not, see . set(src - ../../../tools/gtest-1.6.0/src/gtest_main.cc + Main.cpp synergy/CClipboardTests.cpp + synergy/CKeyStateTests.cpp ) set(inc diff --git a/src/test/unittests/Main.cpp b/src/test/unittests/Main.cpp new file mode 100644 index 00000000..24f1efb9 --- /dev/null +++ b/src/test/unittests/Main.cpp @@ -0,0 +1,41 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file COPYING that should have accompanied this file. + * + * This package 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "CArch.h" +#include "CLog.h" + +#if SYSAPI_WIN32 +#include "CArchMiscWindows.h" +#endif + +int +main(int argc, char **argv) +{ +#if SYSAPI_WIN32 + // HACK: shouldn't be needed, but logging fails without this. + CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL)); +#endif + + CArch arch; + + CLOG->setFilter(kDEBUG2); + + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/src/test/unittests/synergy/CKeyStateTests.cpp b/src/test/unittests/synergy/CKeyStateTests.cpp new file mode 100644 index 00000000..6110bba9 --- /dev/null +++ b/src/test/unittests/synergy/CKeyStateTests.cpp @@ -0,0 +1,84 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2011 Chris Schoeneman, Nick Bolton, Sorin Sbarnea + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file COPYING that should have accompanied this file. + * + * This package 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "CKeyState.h" + +enum { + kAKey = 30 +}; + +class CKeyStateImpl : public CKeyState +{ +protected: + virtual SInt32 pollActiveGroup() const + { + throw std::exception("The method or operation is not implemented."); + } + + virtual KeyModifierMask pollActiveModifiers() const + { + throw std::exception("The method or operation is not implemented."); + } + + virtual bool fakeCtrlAltDel() + { + throw std::exception("The method or operation is not implemented."); + } + + virtual void getKeyMap( CKeyMap& keyMap ) + { + throw std::exception("The method or operation is not implemented."); + } + + virtual void fakeKey( const Keystroke& keystroke ) + { + throw std::exception("The method or operation is not implemented."); + } + + virtual void pollPressedKeys( KeyButtonSet& pressedKeys ) const + { + throw std::exception("The method or operation is not implemented."); + } +}; + +TEST(CKeyStateTests, onKey_aKeyPressed_keyStateOne) +{ + CKeyStateImpl keyState; + + keyState.onKey(kAKey, true, KeyModifierAlt); + + EXPECT_EQ(1, keyState.getKeyState(kAKey)); +} + +TEST(CKeyStateTests, onKey_validButtonUp_keyStateZero) +{ + CKeyStateImpl keyState; + + keyState.onKey(0, true, KeyModifierAlt); + + EXPECT_EQ(0, keyState.getKeyState(0)); +} + +TEST(CKeyStateTests, onKey_bogusButtonDown_keyStateZero) +{ + CKeyStateImpl keyState; + + keyState.onKey(0, true, KeyModifierAlt); + + EXPECT_EQ(0, keyState.getKeyState(0)); +}