summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-03-30 09:15:34 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-04-08 11:42:58 +1000
commit2110435235c371da647a58647535cf8e268fb603 (patch)
tree170db1a88316b66f2c69c43a296cd16aa5637620
parent6e10b33b25ac99280b387f8692e46e55d6d9ca8e (diff)
downloadxf86-input-wacom-2110435235c371da647a58647535cf8e268fb603.tar.gz
Don't accept invalid device types.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/wcmConfig.c16
-rw-r--r--test/fake-symbols.c2
-rw-r--r--test/wacom-tests.c80
3 files changed, 90 insertions, 8 deletions
diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index 0f9631b..5fa8271 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -159,12 +159,7 @@ static int wcmSetType(InputInfoPtr pInfo, const char *type)
WacomDevicePtr priv = pInfo->private;
if (!type)
- {
- xf86Msg(X_ERROR, "%s: No type or invalid type specified.\n"
- "Must be one of stylus, touch, cursor, eraser, or pad\n",
- pInfo->name);
- return 0;
- }
+ goto invalid;
if (xf86NameCmp(type, "stylus") == 0)
{
@@ -191,7 +186,8 @@ static int wcmSetType(InputInfoPtr pInfo, const char *type)
{
priv->flags = ABSOLUTE_FLAG|PAD_ID;
pInfo->type_name = WACOM_PROP_XI_TYPE_PAD;
- }
+ } else
+ goto invalid;
/* Set the device id of the "last seen" device on this tool */
priv->old_device_id = wcmGetPhyDeviceID(priv);
@@ -202,6 +198,12 @@ static int wcmSetType(InputInfoPtr pInfo, const char *type)
priv->tool->typeid = DEVICE_ID(priv->flags); /* tool type (stylus/touch/eraser/cursor/pad) */
return 1;
+
+invalid:
+ xf86Msg(X_ERROR, "%s: No type or invalid type specified.\n"
+ "Must be one of stylus, touch, cursor, eraser, or pad\n",
+ pInfo->name);
+ return 0;
}
int wcmGetPhyDeviceID(WacomDevicePtr priv)
diff --git a/test/fake-symbols.c b/test/fake-symbols.c
index 8e53c2a..1b0cc92 100644
--- a/test/fake-symbols.c
+++ b/test/fake-symbols.c
@@ -81,7 +81,7 @@ xf86OptionValue(pointer opt)
_X_EXPORT int
xf86NameCmp(const char *s1, const char *s2)
{
- return 0;
+ return strcasecmp(s1, s2);
}
_X_EXPORT char *
diff --git a/test/wacom-tests.c b/test/wacom-tests.c
index f7b0fcc..8e2d352 100644
--- a/test/wacom-tests.c
+++ b/test/wacom-tests.c
@@ -443,6 +443,85 @@ test_mod_buttons(void)
assert(mod_buttons(0, sizeof(int), 1) == 0);
}
+static void test_set_type(void)
+{
+ InputInfoRec info = {0};
+ WacomDeviceRec priv = {0};
+ WacomTool tool = {0};
+ WacomCommonRec common = {0};
+ int rc;
+
+#define reset(_info, _priv, _tool, _common) \
+ memset(&(_info), 0, sizeof(_info)); \
+ memset(&(_priv), 0, sizeof(_priv)); \
+ memset(&(_tool), 0, sizeof(_tool)); \
+ (_info).private = &(_priv); \
+ (_priv).tool = &(_tool); \
+ (_priv).common = &(_common);
+
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, NULL);
+ assert(rc == 0);
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, "stylus");
+ assert(rc == 1);
+ assert(is_absolute(&info));
+ assert(IsStylus(&priv));
+ assert(!IsTouch(&priv));
+ assert(!IsEraser(&priv));
+ assert(!IsCursor(&priv));
+ assert(!IsPad(&priv));
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, "touch");
+ assert(rc == 1);
+ /* only some touch screens are absolute */
+ assert(!is_absolute(&info));
+ assert(!IsStylus(&priv));
+ assert(IsTouch(&priv));
+ assert(!IsEraser(&priv));
+ assert(!IsCursor(&priv));
+ assert(!IsPad(&priv));
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, "eraser");
+ assert(rc == 1);
+ assert(is_absolute(&info));
+ assert(!IsStylus(&priv));
+ assert(!IsTouch(&priv));
+ assert(IsEraser(&priv));
+ assert(!IsCursor(&priv));
+ assert(!IsPad(&priv));
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, "cursor");
+ assert(rc == 1);
+ assert(!is_absolute(&info));
+ assert(!IsStylus(&priv));
+ assert(!IsTouch(&priv));
+ assert(!IsEraser(&priv));
+ assert(IsCursor(&priv));
+ assert(!IsPad(&priv));
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, "pad");
+ assert(rc == 1);
+ assert(is_absolute(&info));
+ assert(!IsStylus(&priv));
+ assert(!IsTouch(&priv));
+ assert(!IsEraser(&priv));
+ assert(!IsCursor(&priv));
+ assert(IsPad(&priv));
+
+ reset(info, priv, tool, common);
+ rc = wcmSetType(&info, "foobar");
+ assert(rc == 0);
+
+#undef reset
+}
+
int main(int argc, char** argv)
{
test_common_ref();
@@ -452,6 +531,7 @@ int main(int argc, char** argv)
test_initial_size();
test_tilt_to_rotation();
test_mod_buttons();
+ test_set_type();
return 0;
}