[PATCH libinput 2/2] test: Add test for mouse dpi tag parser
Peter Hutterer
peter.hutterer at who-t.net
Mon Nov 24 23:35:17 PST 2014
On Mon, Nov 24, 2014 at 03:53:37PM -0600, Derek Foreman wrote:
> Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
> ---
> test/Makefile.am | 7 ++++-
> test/mouse_dpi_parser.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 75 insertions(+), 1 deletion(-)
> create mode 100644 test/mouse_dpi_parser.c
> diff --git a/test/Makefile.am b/test/Makefile.am
> index 0abd695..1f124a3 100644
> --- a/test/Makefile.am
> +++ b/test/Makefile.am
> @@ -41,7 +41,8 @@ run_tests = \
> test-trackpoint \
> test-misc \
> test-keyboard \
> - test-device
> + test-device \
> + test-mouse_dpi_parser
any reason you didn't add this to misc.c?
I prefer having the tests roughly grouped over a separate file for each
small test.
> build_tests = \
> test-build-cxx \
> test-build-linker \
> @@ -93,6 +94,10 @@ test_device_SOURCES = device.c
> test_device_LDADD = $(TEST_LIBS)
> test_device_LDFLAGS = -no-install
>
> +test_mouse_dpi_parser_SOURCES = mouse_dpi_parser.c
> +test_mouse_dpi_parser_LDADD = $(TEST_LIBS)
> +test_mouse_dpi_parser_LDFLAGS = -no-install
> +
> # build-test only
> test_build_pedantic_c99_SOURCES = build-pedantic.c
> test_build_pedantic_c99_CFLAGS = -std=c99 -pedantic -Werror
> diff --git a/test/mouse_dpi_parser.c b/test/mouse_dpi_parser.c
> new file mode 100644
> index 0000000..bde71cb
> --- /dev/null
> +++ b/test/mouse_dpi_parser.c
> @@ -0,0 +1,69 @@
> +/*
> + * Copyright © 2014 Samsung
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and
> + * its documentation for any purpose is hereby granted without fee, provided
> + * that the above copyright notice appear in all copies and that both that
> + * copyright notice and this permission notice appear in supporting
> + * documentation, and that the name of the copyright holders not be used in
> + * advertising or publicity pertaining to distribution of the software
> + * without specific, written prior permission. The copyright holders make
> + * no representations about the suitability of this software for any
> + * purpose. It is provided "as is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
> + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
> + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
> + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
> + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
> + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
> + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <config.h>
> +
> +#include <check.h>
> +#include <libinput.h>
> +#include <libinput-util.h>
> +
> +#include "litest.h"
> +
> +struct parser_test {
> + char *tag;
> + int expected_dpi;
> +};
> +
> +START_TEST(udev_dpi_parser)
> +{
> + struct parser_test tests[] = {
> + { "450 *1800 3200", 1800 },
> + { "*450 1800 3200", 450 },
> + { "450 1800 *3200", 3200 },
> + { "450 1800 *failboat", 0 },
> + { "0 450 1800 *3200", 0 },
> + { "450 at 37 1800 at 12 *3200 at 6", 3200 },
> + { "450 at 125 1800 at 125 *3200 at 125 ", 3200 },
> + { "450 at 125 *1800 at 125 3200 at 125", 1800 },
> + { "*this @string fails", 0 },
> + { "12 at 34 *45@", 0 },
> + { " * 12, 450, 800", 0 },
> + { " *12, 450, 800", 12 },
> + { "*12, *450, 800", 12 },
pls add the empty string "" too, and tests for negative numbers.
Cheers,
Peter
> + { NULL }
> + };
> + int i, dpi;
> +
> + for (i = 0; tests[i].tag != NULL; i++) {
> + dpi = udev_parse_mouse_dpi_property(tests[i].tag);
> + ck_assert(dpi == tests[i].expected_dpi);
> + }
> +}
> +END_TEST
> +
> +int
> +main(int argc, char **argv)
> +{
> + litest_add_no_device("udev:dpi parser", udev_dpi_parser);
> +
> + return litest_run(argc, argv);
> +}
> --
> 2.1.3
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
More information about the wayland-devel
mailing list