config: Remove use of %m sscanf format specifier
The %m format specifier isn't defined by the C standards and so produces
an error under CFLAGS=`-pedantic -Werror`.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I7fd818582472ced3f8e6adc2ea5d545b5b7dc020
diff --git a/test/test-config-parse.c b/test/test-config-parse.c
new file mode 100644
index 0000000..6392bd9
--- /dev/null
+++ b/test/test-config-parse.c
@@ -0,0 +1,74 @@
+
+#include <assert.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#ifndef SYSCONFDIR
+// Bypass compilation error due to -DSYSCONFDIR not provided
+#define SYSCONFDIR
+#endif
+
+#include "config.c"
+
+static void execute_test(const char *input, const char *key, const char *expected)
+{
+ struct config *ctx;
+ const char *found;
+ char *buf;
+
+ ctx = calloc(1, sizeof(*ctx));
+ buf = strdup(input);
+ config_parse(ctx, buf);
+ free(buf);
+ found = config_get_value(ctx, key);
+ if (!expected)
+ assert(!found);
+ if (expected) {
+ assert(found);
+ assert(!strcmp(expected, found));
+ }
+ config_fini(ctx);
+}
+
+static void test_config_parse_basic(void)
+{
+ execute_test("tty = ttyS0", "tty", "ttyS0");
+}
+
+static void test_config_parse_no_key(void)
+{
+ execute_test("= ttyS0", "tty", NULL);
+}
+
+static void test_config_parse_no_value(void)
+{
+ execute_test("tty =", "tty", NULL);
+}
+
+static void test_config_parse_no_operator(void)
+{
+ execute_test("tty ttyS0", "tty", NULL);
+}
+
+static void test_config_parse_no_spaces(void)
+{
+ execute_test("tty=ttyS0", "tty", "ttyS0");
+}
+
+static void test_config_parse_empty(void)
+{
+ execute_test("", "tty", NULL);
+}
+
+int main(void)
+{
+ test_config_parse_basic();
+ test_config_parse_no_key();
+ test_config_parse_no_value();
+ test_config_parse_no_operator();
+ test_config_parse_no_spaces();
+ test_config_parse_empty();
+
+ return EXIT_SUCCESS;
+}