Add LICENSE.BSD-3-Clause file
[platform/upstream/libxkbcommon.git] / test / rules-file.c
index c52ff23..d217ba9 100644 (file)
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
+#include "config.h"
 
-#include "xkbcommon/xkbcommon.h"
-#include "rules.h"
 #include "test.h"
+#include "xkbcomp/xkbcomp-priv.h"
+#include "xkbcomp/rules.h"
 
 struct test_data {
     /* Rules file */
@@ -50,14 +47,6 @@ struct test_data {
     bool should_fail;
 };
 
-static inline bool
-streq(const char *s1, const char *s2)
-{
-    if (s1 == NULL || s2 == NULL)
-        return s1 == s2;
-    return strcmp(s1, s2) == 0;
-}
-
 static bool
 test_rules(struct xkb_context *ctx, struct test_data *data)
 {
@@ -65,54 +54,46 @@ test_rules(struct xkb_context *ctx, struct test_data *data)
     const struct xkb_rule_names rmlvo = {
         data->rules, data->model, data->layout, data->variant, data->options
     };
-    struct xkb_component_names *kccgst;
+    struct xkb_component_names kccgst;
 
     fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
             data->model, data->layout, data->variant, data->options);
 
     if (data->should_fail)
-        fprintf(stderr, "Expecting: NULL\n");
+        fprintf(stderr, "Expecting: FAILURE\n");
     else
         fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
                 data->keycodes, data->types, data->compat, data->symbols);
 
-    kccgst = xkb_components_from_rules(ctx, &rmlvo);
-    if (!kccgst) {
-        fprintf(stderr, "Received: NULL\n");
+    if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst)) {
+        fprintf(stderr, "Received : FAILURE\n");
         return data->should_fail;
     }
 
     fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
-            kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols);
+            kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
 
-    passed = streq(kccgst->keycodes, data->keycodes) &&
-             streq(kccgst->types, data->types) &&
-             streq(kccgst->compat, data->compat) &&
-             streq(kccgst->symbols, data->symbols);
+    passed = streq(kccgst.keycodes, data->keycodes) &&
+             streq(kccgst.types, data->types) &&
+             streq(kccgst.compat, data->compat) &&
+             streq(kccgst.symbols, data->symbols);
 
-    free(kccgst->keycodes);
-    free(kccgst->types);
-    free(kccgst->compat);
-    free(kccgst->symbols);
-    free(kccgst);
+    free(kccgst.keycodes);
+    free(kccgst.types);
+    free(kccgst.compat);
+    free(kccgst.symbols);
 
     return passed;
 }
 
 int
-main(void)
+main(int argc, char *argv[])
 {
     struct xkb_context *ctx;
-    const char *srcdir = getenv("srcdir");
-    char *path;
 
-    ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
+    ctx = test_get_context(0);
     assert(ctx);
 
-    assert(asprintf(&path, "%s/test/data", srcdir ? srcdir : ".") > 0);
-    assert(xkb_context_include_path_append(ctx, test_get_path("")));
-    free(path);
-
     struct test_data test1 = {
         .rules = "simple",
 
@@ -120,7 +101,7 @@ main(void)
         .options = "my_option",
 
         .keycodes = "my_keycodes", .types = "my_types",
-        .compat = "my_compat+some:compat",
+        .compat = "my_compat|some:compat",
         .symbols = "my_symbols+extra_variant",
     };
     assert(test_rules(ctx, &test1));