[v2,libinput,2/2] test: Add test for mouse dpi tag parser

Submitted by Derek Foreman on Nov. 25, 2014, 5:46 p.m.

Details

Message ID 1416937603-29589-2-git-send-email-derekf@osg.samsung.com
State Not Applicable
Headers show

Not browsing as part of any series.

Commit Message

Derek Foreman Nov. 25, 2014, 5:46 p.m.
Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
---
 test/misc.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Patch hide | download patch | download mbox

diff --git a/test/misc.c b/test/misc.c
index 4ed9dce..c8ac51f 100644
--- a/test/misc.c
+++ b/test/misc.c
@@ -548,6 +548,43 @@  START_TEST(ratelimit_helpers)
 }
 END_TEST
 
+struct parser_test {
+	char *tag;
+	int expected_dpi;
+};
+
+START_TEST(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@37 1800@12 *3200@6", 3200 },
+		{ "450@125 1800@125   *3200@125  ", 3200 },
+		{ "450@125 *1800@125  3200@125", 1800 },
+		{ "*this @string fails", 0 },
+		{ "12@34 *45@", 0 },
+		{ "                                      * 12, 450, 800", 0 },
+		{ "                                      *12, 450, 800", 12 },
+		{ "*12, *450, 800", 12 },
+		{ "*-23412, 450, 800", 0 },
+		{ "112@125, 450@125, 800@125, 900@-125", 0 },
+		{ "", 0 },
+		{ "   ", 0 },
+		{ "* ", 0 },
+		{ NULL }
+	};
+	int i, dpi;
+
+	for (i = 0; tests[i].tag != NULL; i++) {
+		dpi = 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("events:conversion", event_conversion_device_notify);
 	litest_add_no_device("events:conversion", event_conversion_pointer);
@@ -560,6 +597,7 @@  int main (int argc, char **argv) {
 
 	litest_add_no_device("misc:matrix", matrix_helpers);
 	litest_add_no_device("misc:ratelimit", ratelimit_helpers);
+	litest_add_no_device("misc:dpi parser", dpi_parser);
 
 	return litest_run(argc, argv);
 }