diff --git a/src/test/unittests/synergy/DpiHelperTests.cpp b/src/test/unittests/synergy/DpiHelperTests.cpp new file mode 100644 index 00000000..77527998 --- /dev/null +++ b/src/test/unittests/synergy/DpiHelperTests.cpp @@ -0,0 +1,70 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Seamless Inc. + * + * 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 LICENSE 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 "synergy/DpiHelper.h" + +#include "test/global/gtest.h" + +void resetStaticVariables() +{ + DpiHelper::s_resolutionWidth = 0; + DpiHelper::s_resolutionHeight = 0; + DpiHelper::s_primaryWidthCenter = 0; + DpiHelper::s_primaryHeightCenter = 0; + DpiHelper::s_dpi = DpiHelper::kDefaultDpi; + DpiHelper::s_dpiScaled = false; +} + +TEST(DpiHelperTests, calculateDpi_samePhysicalAndVirtualResolutions_defaultDpi) +{ + resetStaticVariables(); + + DpiHelper::s_resolutionWidth = 1920; + DpiHelper::s_resolutionHeight = 1080; + DpiHelper::s_primaryWidthCenter = 960; + DpiHelper::s_primaryHeightCenter = 540; + + DpiHelper::calculateDpi(1920, 1080); + + EXPECT_EQ(false, DpiHelper::s_dpiScaled); + EXPECT_EQ(DpiHelper::kDefaultDpi, DpiHelper::s_dpi); +} + +TEST(DpiHelperTests, calculateDpi_differentPhysicalAndVirtualResolutions_scaledDpi) +{ + resetStaticVariables(); + + DpiHelper::s_resolutionWidth = 1920; + DpiHelper::s_resolutionHeight = 1080; + DpiHelper::s_primaryWidthCenter = 960; + DpiHelper::s_primaryHeightCenter = 540; + + DpiHelper::calculateDpi(960, 540); + + EXPECT_EQ(true, DpiHelper::s_dpiScaled); + EXPECT_EQ(200, DpiHelper::s_dpi); +} + +TEST(DpiHelperTests, calculateDpi_defaultStaticValues_defaultDpi) +{ + resetStaticVariables(); + + DpiHelper::calculateDpi(1920, 1080); + + EXPECT_EQ(false, DpiHelper::s_dpiScaled); + EXPECT_EQ(DpiHelper::kDefaultDpi, DpiHelper::s_dpi); +}