| 1 |
/* |
| 2 |
* Copyright (C) 2021 UBports foundation. |
| 3 |
* Author(s): Marius Gripsgard <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify it under |
| 6 |
* the terms of the GNU General Public License version 3, as published by |
| 7 |
* the Free Software Foundation. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
| 11 |
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <gtest/gtest.h> |
| 20 |
|
| 21 |
#include "deviceinfo.h" |
| 22 |
|
| 23 |
#include "mock_device.h" |
| 24 |
|
| 25 |
|
| 26 |
#define TEST_RETURN_FUCS(name, func, func2, ret) \ |
| 27 |
TEST(DeviceInfoTest, test##name) \ |
| 28 |
{ \ |
| 29 |
MockDevice device; \ |
| 30 |
EXPECT_CALL(device, func2) \ |
| 31 |
.Times(1) \ |
| 32 |
.WillOnce(::testing::Return(ret)); \ |
| 33 |
\ |
| 34 |
DeviceInfo di(&device); \ |
| 35 |
\ |
| 36 |
EXPECT_EQ(di.func, ret); \ |
| 37 |
} |
| 38 |
|
| 39 |
TEST_RETURN_FUCS(Name, name(), name(), "a") |
| 40 |
TEST_RETURN_FUCS(PrettyName, prettyName(), prettyName(), "a") |
| 41 |
TEST_RETURN_FUCS(DeviceType, deviceType(), deviceType(), DeviceInfo::DeviceType::Tablet) |
| 42 |
TEST_RETURN_FUCS(DriverType, driverType(), driverType(), DeviceInfo::DriverType::Halium) |
| 43 |
TEST_RETURN_FUCS(GridUnit, gridUnit(), gridUnit(), 16) |
| 44 |
|
| 45 |
TEST_RETURN_FUCS(Get, get("", ""), get("", ""), "a") |
| 46 |
TEST_RETURN_FUCS(Contains, contains(""), contains(""), true) |
| 47 |
|
| 48 |
TEST(DeviceInfoTest, testSupportedOrientations) |
| 49 |
{ |
| 50 |
MockDevice device; |
| 51 |
EXPECT_CALL(device, get("SupportedOrientations", "Portrait,InvertedPortrait,Landscape,InvertedLandscape")) |
| 52 |
.Times(1) |
| 53 |
.WillOnce(::testing::Return("Portrait,InvertedPortrait,Landscape,InvertedLandscape")); |
| 54 |
|
| 55 |
DeviceInfo di(&device); |
| 56 |
|
| 57 |
EXPECT_EQ(di.supportedOrientations(), (std::vector<std::string>{"Portrait", "InvertedPortrait", "Landscape", "InvertedLandscape"})); |
| 58 |
} |
| 59 |
|
| 60 |
TEST_RETURN_FUCS(PrimaryOrientation, primaryOrientation(), get("PrimaryOrientation", "Portrait"), "a") |
| 61 |
TEST_RETURN_FUCS(PortraitOrientation, portraitOrientation(), get("PortraitOrientation", "Portrait"), "a") |
| 62 |
TEST_RETURN_FUCS(InvertedPortraitOrientation, invertedPortraitOrientation(), get("InvertedPortraitOrientation", "InvertedPortrait"), "a") |
| 63 |
TEST_RETURN_FUCS(LandscapeOrientation, landscapeOrientation(), get("LandscapeOrientation", "Landscape"), "a") |
| 64 |
TEST_RETURN_FUCS(InvertedLandscapeOrientation, invertedLandscapeOrientation(), get("InvertedLandscapeOrientation", "InvertedLandscape"), "a") |
| 65 |
|
| 66 |
TEST(DeviceInfoTest, testDeviceTypeToString) |
| 67 |
{ |
| 68 |
EXPECT_EQ(DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType::Phone), "phone"); |
| 69 |
EXPECT_EQ(DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType::Tablet), "tablet"); |
| 70 |
EXPECT_EQ(DeviceInfo::deviceTypeToString(DeviceInfo::DeviceType::Desktop), "desktop"); |
| 71 |
} |
| 72 |
|
| 73 |
TEST(DeviceInfoTest, testdeviceTypeFromString) |
| 74 |
{ |
| 75 |
EXPECT_EQ(DeviceInfo::deviceTypeFromString("phone"), DeviceInfo::DeviceType::Phone); |
| 76 |
EXPECT_EQ(DeviceInfo::deviceTypeFromString("tablet"), DeviceInfo::DeviceType::Tablet); |
| 77 |
EXPECT_EQ(DeviceInfo::deviceTypeFromString("desktop"), DeviceInfo::DeviceType::Desktop); |
| 78 |
} |
| 79 |
|
| 80 |
TEST(DeviceInfoTest, testDriverTypeToString) |
| 81 |
{ |
| 82 |
EXPECT_EQ(DeviceInfo::driverTypeToString(DeviceInfo::DriverType::Halium), "halium"); |
| 83 |
EXPECT_EQ(DeviceInfo::driverTypeToString(DeviceInfo::DriverType::Linux), "linux"); |
| 84 |
} |
| 85 |
|
| 86 |
TEST(DeviceInfoTest, testDriverTypeFromString) |
| 87 |
{ |
| 88 |
EXPECT_EQ(DeviceInfo::driverTypeFromString("halium"), DeviceInfo::DriverType::Halium); |
| 89 |
EXPECT_EQ(DeviceInfo::driverTypeFromString("linux"), DeviceInfo::DriverType::Linux); |
| 90 |
} |