Change POINTER_ICON_STYLE enum to a type safe enum class
Test: Current tests all pass, this is a static type change, not
a functional change.
Change-Id: I8f0e8e43ea64f5abab163e4ef5444a8cb3d4fa78
diff --git a/libs/input/tests/PointerController_test.cpp b/libs/input/tests/PointerController_test.cpp
index f9752ed..a6a4115 100644
--- a/libs/input/tests/PointerController_test.cpp
+++ b/libs/input/tests/PointerController_test.cpp
@@ -14,17 +14,18 @@
* limitations under the License.
*/
-#include "mocks/MockSprite.h"
-#include "mocks/MockSpriteController.h"
-
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
#include <input/PointerController.h>
#include <input/SpriteController.h>
#include <atomic>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
#include <thread>
+#include "input/Input.h"
+#include "mocks/MockSprite.h"
+#include "mocks/MockSpriteController.h"
+
namespace android {
enum TestCursorType {
@@ -39,7 +40,6 @@
using ::testing::AllOf;
using ::testing::Field;
-using ::testing::Mock;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::Test;
@@ -52,10 +52,12 @@
public:
virtual void loadPointerIcon(SpriteIcon* icon, int32_t displayId) override;
virtual void loadPointerResources(PointerResources* outResources, int32_t displayId) override;
- virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
- std::map<int32_t, PointerAnimation>* outAnimationResources, int32_t displayId) override;
- virtual int32_t getDefaultPointerIconId() override;
- virtual int32_t getCustomPointerIconId() override;
+ virtual void loadAdditionalMouseResources(
+ std::map<PointerIconStyle, SpriteIcon>* outResources,
+ std::map<PointerIconStyle, PointerAnimation>* outAnimationResources,
+ int32_t displayId) override;
+ virtual PointerIconStyle getDefaultPointerIconId() override;
+ virtual PointerIconStyle getCustomPointerIconId() override;
virtual void onPointerDisplayIdChanged(int32_t displayId, float xPos, float yPos) override;
bool allResourcesAreLoaded();
@@ -85,34 +87,33 @@
}
void MockPointerControllerPolicyInterface::loadAdditionalMouseResources(
- std::map<int32_t, SpriteIcon>* outResources,
- std::map<int32_t, PointerAnimation>* outAnimationResources,
- int32_t) {
+ std::map<PointerIconStyle, SpriteIcon>* outResources,
+ std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, int32_t) {
SpriteIcon icon;
PointerAnimation anim;
// CURSOR_TYPE_ADDITIONAL doesn't have animation resource.
int32_t cursorType = CURSOR_TYPE_ADDITIONAL;
loadPointerIconForType(&icon, cursorType);
- (*outResources)[cursorType] = icon;
+ (*outResources)[static_cast<PointerIconStyle>(cursorType)] = icon;
// CURSOR_TYPE_ADDITIONAL_ANIM has animation resource.
cursorType = CURSOR_TYPE_ADDITIONAL_ANIM;
loadPointerIconForType(&icon, cursorType);
anim.animationFrames.push_back(icon);
anim.durationPerFrame = 10;
- (*outResources)[cursorType] = icon;
- (*outAnimationResources)[cursorType] = anim;
+ (*outResources)[static_cast<PointerIconStyle>(cursorType)] = icon;
+ (*outAnimationResources)[static_cast<PointerIconStyle>(cursorType)] = anim;
additionalMouseResourcesLoaded = true;
}
-int32_t MockPointerControllerPolicyInterface::getDefaultPointerIconId() {
- return CURSOR_TYPE_DEFAULT;
+PointerIconStyle MockPointerControllerPolicyInterface::getDefaultPointerIconId() {
+ return static_cast<PointerIconStyle>(CURSOR_TYPE_DEFAULT);
}
-int32_t MockPointerControllerPolicyInterface::getCustomPointerIconId() {
- return CURSOR_TYPE_CUSTOM;
+PointerIconStyle MockPointerControllerPolicyInterface::getCustomPointerIconId() {
+ return static_cast<PointerIconStyle>(CURSOR_TYPE_CUSTOM);
}
bool MockPointerControllerPolicyInterface::allResourcesAreLoaded() {
@@ -124,7 +125,7 @@
}
void MockPointerControllerPolicyInterface::loadPointerIconForType(SpriteIcon* icon, int32_t type) {
- icon->style = type;
+ icon->style = static_cast<PointerIconStyle>(type);
std::pair<float, float> hotSpot = getHotSpotCoordinatesForType(type);
icon->hotSpotX = hotSpot.first;
icon->hotSpotY = hotSpot.second;
@@ -205,11 +206,11 @@
std::pair<float, float> hotspot = getHotSpotCoordinatesForType(CURSOR_TYPE_DEFAULT);
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
- EXPECT_CALL(*mPointerSprite, setIcon(
- AllOf(
- Field(&SpriteIcon::style, CURSOR_TYPE_DEFAULT),
- Field(&SpriteIcon::hotSpotX, hotspot.first),
- Field(&SpriteIcon::hotSpotY, hotspot.second))));
+ EXPECT_CALL(*mPointerSprite,
+ setIcon(AllOf(Field(&SpriteIcon::style,
+ static_cast<PointerIconStyle>(CURSOR_TYPE_DEFAULT)),
+ Field(&SpriteIcon::hotSpotX, hotspot.first),
+ Field(&SpriteIcon::hotSpotY, hotspot.second))));
mPointerController->reloadPointerResources();
}
@@ -222,12 +223,11 @@
std::pair<float, float> hotspot = getHotSpotCoordinatesForType(type);
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
- EXPECT_CALL(*mPointerSprite, setIcon(
- AllOf(
- Field(&SpriteIcon::style, type),
- Field(&SpriteIcon::hotSpotX, hotspot.first),
- Field(&SpriteIcon::hotSpotY, hotspot.second))));
- mPointerController->updatePointerIcon(type);
+ EXPECT_CALL(*mPointerSprite,
+ setIcon(AllOf(Field(&SpriteIcon::style, static_cast<PointerIconStyle>(type)),
+ Field(&SpriteIcon::hotSpotX, hotspot.first),
+ Field(&SpriteIcon::hotSpotY, hotspot.second))));
+ mPointerController->updatePointerIcon(static_cast<PointerIconStyle>(type));
}
TEST_F(PointerControllerTest, setCustomPointerIcon) {
@@ -239,17 +239,16 @@
float hotSpotY = 20;
SpriteIcon icon;
- icon.style = style;
+ icon.style = static_cast<PointerIconStyle>(style);
icon.hotSpotX = hotSpotX;
icon.hotSpotY = hotSpotY;
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
- EXPECT_CALL(*mPointerSprite, setIcon(
- AllOf(
- Field(&SpriteIcon::style, style),
- Field(&SpriteIcon::hotSpotX, hotSpotX),
- Field(&SpriteIcon::hotSpotY, hotSpotY))));
+ EXPECT_CALL(*mPointerSprite,
+ setIcon(AllOf(Field(&SpriteIcon::style, static_cast<PointerIconStyle>(style)),
+ Field(&SpriteIcon::hotSpotX, hotSpotX),
+ Field(&SpriteIcon::hotSpotY, hotSpotY))));
mPointerController->setCustomPointerIcon(icon);
}