[2/2] XKB: Add two tests around XkbListComponents

Submitted by Daniel Stone on Nov. 5, 2012, 4:58 a.m.

Details

Message ID 1352091523-2678-2-git-send-email-daniel@fooishbar.org
State New
Headers show

Not browsing as part of any series.

Commit Message

Daniel Stone Nov. 5, 2012, 4:58 a.m.
These require patches which aren't even in git master yet.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
---
 configure.ac          |    1 +
 tests/Makefile.am     |    2 +-
 tests/xkb/Makefile.am |    7 ++++
 tests/xkb/list.cpp    |  107 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 tests/xkb/Makefile.am
 create mode 100644 tests/xkb/list.cpp

Patch hide | download patch | download mbox

diff --git a/configure.ac b/configure.ac
index f9459a7..0456678 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,5 +93,6 @@  AC_CONFIG_FILES([Makefile
                  tests/input/Makefile
                  tests/video/Makefile
                  tests/server/Makefile
+                 tests/xkb/Makefile
                  tests/lib/Makefile])
 AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7e389e9..40c2545 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1 +1 @@ 
-SUBDIRS = common input server lib video
+SUBDIRS = common input server lib video xkb
diff --git a/tests/xkb/Makefile.am b/tests/xkb/Makefile.am
new file mode 100644
index 0000000..c7ef5b8
--- /dev/null
+++ b/tests/xkb/Makefile.am
@@ -0,0 +1,7 @@ 
+include $(top_srcdir)/tests/common/Makefile.am
+
+noinst_PROGRAMS = list
+TESTS=$(noinst_PROGRAMS)
+
+list_SOURCES = list.cpp $(common_sources)
+list_LDADD = $(GTEST_LDADDS)
diff --git a/tests/xkb/list.cpp b/tests/xkb/list.cpp
new file mode 100644
index 0000000..2359744
--- /dev/null
+++ b/tests/xkb/list.cpp
@@ -0,0 +1,107 @@ 
+#include <stdexcept>
+#include <tr1/tuple>
+
+#include "helpers.h"
+#include "device-interface.h"
+#include "xit-server-input-test.h"
+
+#include <xorg/gtest/xorg-gtest.h>
+
+#include <X11/Xlibint.h>
+#include <X11/XKBlib.h>
+#include <X11/extensions/XKBproto.h>
+
+class XKBTest : public XITServerTest {
+public:
+    virtual void SetUpConfigAndLog() {
+        config.AddDefaultScreenWithDriver();
+        config.AddInputSection("void", "--device--", "Option \"CorePointer\" \"on\"\n");
+        config.WriteConfig();
+        server.SetOption("-config", config.GetPath());
+    }
+
+    virtual void SetUp() {
+        XITServerTest::SetUp();
+        dpy = Display();
+        ASSERT_TRUE(XkbQueryExtension(dpy, &base_req, &base_ev, &base_err, NULL, NULL));
+    }
+
+    ::Display *dpy;
+    int base_req;
+    int base_ev;
+    int base_err;
+};
+
+TEST_F(XKBTest, XKBComponentListLength)
+{
+    XORG_TESTCASE("Register for the XKB extension.\n"
+                  "Construct a component list query with a malicious length.\n"
+                  "Hope the server doesn't crash.\n");
+
+    XErrorEvent *err;
+    xkbListComponentsReq *req;
+    xkbListComponentsReply rep;
+    char *str;
+    int i;
+
+    SetErrorTrap(dpy);
+
+    LockDisplay(dpy);
+    GetReq(kbListComponents, req);
+    req->reqType = base_req;
+    req->xkbReqType = X_kbListComponents;
+    req->deviceSpec = XkbUseCoreKbd;
+    req->maxNames = 1024;
+    req->length += 2;
+    BufAlloc(char *, str, 8);
+    for (i = 0; i < 6; i++)
+        *str++ = 255;
+    ASSERT_FALSE(_XReply(dpy, (xReply *) &rep, 0, xFalse));
+    UnlockDisplay(dpy);
+    SyncHandle();
+
+    err = ReleaseErrorTrap(dpy);
+    ASSERT_ERROR(err, BadLength);
+}
+
+TEST_F(XKBTest, XKBComponentListEmpty)
+{
+    XORG_TESTCASE("Register for the XKB extension.\n"
+                  "Check the listed legacy components.\n"
+                  "Ensure that no components are listed.\n");
+
+    XkbComponentListPtr list;
+    XkbComponentNamesRec patterns;
+    int max = 1024;
+
+    memset(&patterns, 0, sizeof(patterns));
+    patterns.keymap = NULL;
+    patterns.keycodes = strdup("*");
+    patterns.types = strdup("*");
+    patterns.compat = strdup("*");
+    patterns.symbols = strdup("*");
+    patterns.geometry = strdup("*");
+
+    list = XkbListComponents(Display(), XkbUseCoreKbd, &patterns, &max);
+    ASSERT_TRUE(list);
+
+    ASSERT_EQ(list->num_keymaps, 0);
+    ASSERT_EQ(list->num_keycodes, 0);
+    ASSERT_EQ(list->num_types, 0);
+    ASSERT_EQ(list->num_compat, 0);
+    ASSERT_EQ(list->num_symbols, 0);
+    ASSERT_EQ(list->num_geometry, 0);
+    ASSERT_EQ(max, 0);
+
+    free(patterns.keycodes);
+    free(patterns.types);
+    free(patterns.compat);
+    free(patterns.symbols);
+    free(patterns.geometry);
+    free(list);
+}
+
+int main(int argc, char** argv) {
+    testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}

Comments

On Mon, Nov 05, 2012 at 03:58:43PM +1100, Daniel Stone wrote:
> These require patches which aren't even in git master yet.
> 
> Signed-off-by: Daniel Stone <daniel@fooishbar.org>
> ---
>  configure.ac          |    1 +
>  tests/Makefile.am     |    2 +-
>  tests/xkb/Makefile.am |    7 ++++
>  tests/xkb/list.cpp    |  107 +++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 116 insertions(+), 1 deletion(-)
>  create mode 100644 tests/xkb/Makefile.am
>  create mode 100644 tests/xkb/list.cpp
> 
> diff --git a/configure.ac b/configure.ac
> index f9459a7..0456678 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -93,5 +93,6 @@ AC_CONFIG_FILES([Makefile
>                   tests/input/Makefile
>                   tests/video/Makefile
>                   tests/server/Makefile
> +                 tests/xkb/Makefile
>                   tests/lib/Makefile])
>  AC_OUTPUT
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 7e389e9..40c2545 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -1 +1 @@
> -SUBDIRS = common input server lib video
> +SUBDIRS = common input server lib video xkb

tbh I think the xkb tests should just be in the server directory.

> diff --git a/tests/xkb/Makefile.am b/tests/xkb/Makefile.am
> new file mode 100644
> index 0000000..c7ef5b8
> --- /dev/null
> +++ b/tests/xkb/Makefile.am
> @@ -0,0 +1,7 @@
> +include $(top_srcdir)/tests/common/Makefile.am
> +
> +noinst_PROGRAMS = list
> +TESTS=$(noinst_PROGRAMS)
> +
> +list_SOURCES = list.cpp $(common_sources)
> +list_LDADD = $(GTEST_LDADDS)
> diff --git a/tests/xkb/list.cpp b/tests/xkb/list.cpp
> new file mode 100644
> index 0000000..2359744
> --- /dev/null
> +++ b/tests/xkb/list.cpp
> @@ -0,0 +1,107 @@
> +#include <stdexcept>
> +#include <tr1/tuple>
> +
> +#include "helpers.h"
> +#include "device-interface.h"
> +#include "xit-server-input-test.h"
> +
> +#include <xorg/gtest/xorg-gtest.h>
> +
> +#include <X11/Xlibint.h>
> +#include <X11/XKBlib.h>
> +#include <X11/extensions/XKBproto.h>
> +
> +class XKBTest : public XITServerTest {
> +public:
> +    virtual void SetUpConfigAndLog() {
> +        config.AddDefaultScreenWithDriver();
> +        config.AddInputSection("void", "--device--", "Option \"CorePointer\" \"on\"\n");
> +        config.WriteConfig();
> +        server.SetOption("-config", config.GetPath());

last two lines aren't needed anymore, XITServerTest will do this
automatically.

> +    }
> +
> +    virtual void SetUp() {
> +        XITServerTest::SetUp();
> +        dpy = Display();
> +        ASSERT_TRUE(XkbQueryExtension(dpy, &base_req, &base_ev, &base_err, NULL, NULL));
> +    }
> +
> +    ::Display *dpy;

we already have a display variable in the parent class, why not use
Display()?

> +    int base_req;
> +    int base_ev;
> +    int base_err;

rename to xkb_..blah

> +};
> +
> +TEST_F(XKBTest, XKBComponentListLength)
> +{
> +    XORG_TESTCASE("Register for the XKB extension.\n"
> +                  "Construct a component list query with a malicious length.\n"

what's a malicious length? Too long? specific value?

rest looks good.

Cheers,
   Peter

> +                  "Hope the server doesn't crash.\n");
> +
> +    XErrorEvent *err;
> +    xkbListComponentsReq *req;
> +    xkbListComponentsReply rep;
> +    char *str;
> +    int i;
> +
> +    SetErrorTrap(dpy);
> +
> +    LockDisplay(dpy);
> +    GetReq(kbListComponents, req);
> +    req->reqType = base_req;
> +    req->xkbReqType = X_kbListComponents;
> +    req->deviceSpec = XkbUseCoreKbd;
> +    req->maxNames = 1024;
> +    req->length += 2;
> +    BufAlloc(char *, str, 8);
> +    for (i = 0; i < 6; i++)
> +        *str++ = 255;
> +    ASSERT_FALSE(_XReply(dpy, (xReply *) &rep, 0, xFalse));
> +    UnlockDisplay(dpy);
> +    SyncHandle();
> +
> +    err = ReleaseErrorTrap(dpy);
> +    ASSERT_ERROR(err, BadLength);
> +}
> +
> +TEST_F(XKBTest, XKBComponentListEmpty)
> +{
> +    XORG_TESTCASE("Register for the XKB extension.\n"
> +                  "Check the listed legacy components.\n"
> +                  "Ensure that no components are listed.\n");
> +
> +    XkbComponentListPtr list;
> +    XkbComponentNamesRec patterns;
> +    int max = 1024;
> +
> +    memset(&patterns, 0, sizeof(patterns));
> +    patterns.keymap = NULL;
> +    patterns.keycodes = strdup("*");
> +    patterns.types = strdup("*");
> +    patterns.compat = strdup("*");
> +    patterns.symbols = strdup("*");
> +    patterns.geometry = strdup("*");
> +
> +    list = XkbListComponents(Display(), XkbUseCoreKbd, &patterns, &max);
> +    ASSERT_TRUE(list);
> +
> +    ASSERT_EQ(list->num_keymaps, 0);
> +    ASSERT_EQ(list->num_keycodes, 0);
> +    ASSERT_EQ(list->num_types, 0);
> +    ASSERT_EQ(list->num_compat, 0);
> +    ASSERT_EQ(list->num_symbols, 0);
> +    ASSERT_EQ(list->num_geometry, 0);
> +    ASSERT_EQ(max, 0);
> +
> +    free(patterns.keycodes);
> +    free(patterns.types);
> +    free(patterns.compat);
> +    free(patterns.symbols);
> +    free(patterns.geometry);
> +    free(list);
> +}
> +
> +int main(int argc, char** argv) {
> +    testing::InitGoogleTest(&argc, argv);
> +    return RUN_ALL_TESTS();
> +}
> -- 
> 1.7.10.4
> 
> _______________________________________________
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>