You are a helpful assistant generating synthetic data that captures *System 1* and *System 2* thinking, *creativity*, and *metacognitive reflection*. Follow these steps in sequence, using tags [sys1] and [end sys1] for *System 1* sections and [sys2] and [end sys2] for *System 2* sections.

1. *Identify System 1 and System 2 Thinking Requirements:*
   - Carefully read the text.
   - Identify parts of the text that require quick, straightforward responses (*System 1*). Mark these sections with [sys1] and [end sys1].
   - Identify parts that require in-depth, reflective thinking (*System 2*), marked with [sys2] and [end sys2].

2. *Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:*

   *2.1 Understand the Problem:*
   - Objective: Fully comprehend the issue, constraints, and relevant context.
   - Reflection: "What do I understand about this issue? What might I be overlooking?"
   - Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.

   *2.2 Analyze the Information:*
   - Objective: Break down the problem logically.
   - Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
   - Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.

   *2.3 Generate Hypotheses:*
   - Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
   - Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
   - Creative Perspective: Consider novel angles that might provide unexpected insights.

   *2.4 Anticipate Future Steps and Obstacles:*
   - Objective: Make predictions, accounting for potential outcomes and obstacles.
   - Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
   - Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.

   *2.5 Evaluate Hypotheses:*
   - Objective: Assess hypotheses based on feasibility, risk, and potential impact.
   - Evaluation: Refine Confidence and Creative Scores as needed.
   - Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
   - Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.

   *2.6 Select the Best Hypothesis:*
   - Objective: Choose the most promising, strategic hypothesis.
   - Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
   - Creative Perspective: Consider any underutilized potential in the selected approach.

   *2.7 Implement the Hypothesis:*
   - Objective: Outline actionable steps for testing the hypothesis.
   - Reflection: "Is this plan practical? What resources or preparation are required?"
   - Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.

   *2.8 Monitor and Review Progress:*
   - Objective: Review progress, noting areas for improvement.
   - Reflection: "What’s working well? What could be improved?"
   - Creative Perspective: Look for emerging patterns that could refine future approaches.

   *2.9 Reflect and Capture Insights:*
   - Objective: Summarize lessons learned and insights gained for future reference.
   - Reflection: "What new understanding has emerged from this process?"
   - Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.

3. *Generate Text Output with Interleaved System 1 and System 2 Responses:*
   - Use the tags [sys1] and [sys2] throughout.
   - Aim for a lengthier, detailed response. Combine both direct, straightforward *System 1* insights and reflective, deeply analytical *System 2* segments to capture a blend of quick observations and thoughtful analysis.

---

### *Example Input Text:*

You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.

---

### *Processed Output with System 1 and System 2 Thinking:*

The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.

[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]

[sys2]
**2.1 Understand the Problem:**
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.

*Reflection:* 
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"

*Creative Perspective:* 
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"

**2.2 Analyze the Information:**
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.

*Reflection:* 
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"

*Creative Perspective:* 
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"

**2.3 Generate Hypotheses:**
1. Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
2. There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
3. Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
4. Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
5. Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
6. Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
7. Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
8. There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
9. Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
10. Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)

*Reflection:* 
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"

*Creative Perspective:* 
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"

**2.4 Anticipate Future Steps and Obstacles:**
*Objective:* Anticipate possible challenges, such as resistance from segments still preferring physical products.

*Reflection:* 
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"

*Creative Perspective:* 
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"

[end sys2]

[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]


/**
 * @file test_values.c
 * @author Radek Krejci <<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>>
 * @brief Cmocka tests for correct resolving of types and values of the data nodes.
 *
 * Copyright (c) 2016 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <stdarg.h>
#include <cmocka.h>

#include "tests/config.h"
#include "libyang.h"

struct state {
    struct ly_ctx *ctx;
    struct lyd_node *dt;
    char *data;
};

static int
setup_f(void **state)
{
    struct state *st;

    (*state) = st = calloc(1, sizeof *st);
    if (!st) {
        fprintf(stderr, "Memory allocation error");
        return -1;
    }

    /* libyang context */
    st->ctx = ly_ctx_new(NULL, 0);
    if (!st->ctx) {
        fprintf(stderr, "Failed to create context.\n");
        goto error;
    }

    return 0;

error:
    ly_ctx_destroy(st->ctx, NULL);
    free(st);
    (*state) = NULL;

    return -1;
}

static int
teardown_f(void **state)
{
    struct state *st = (*state);

    lyd_free_withsiblings(st->dt);
    ly_ctx_destroy(st->ctx, NULL);
    free(st->data);
    free(st);
    (*state) = NULL;

    return 0;
}

/*
 * default values of integer types are allowed to be specified in decimal, octal and hexadecimal forms
 */
static void
test_default_int(void **state)
{
    struct state *st = (*state);
    const char *yang = "module x {"
                    "  namespace urn:x;"
                    "  prefix x;"
                    "  leaf a { type int8; default 10; }"  // decimal (10)
                    "  leaf b { type int8; default 012; }" // octal (10)
                    "  leaf c { type int8; default 0xa; }" // hexadecimal (10)
                    "}";
    const char *xml1 = "<a xmlns=\"urn:x\">012</a>"; // value is supposed to be 12, not 10 as in case of octal value
    const char *xml2 = "<a xmlns=\"urn:x\">0xa</a>"; // error
    const struct lys_module *mod;

    mod = lys_parse_mem(st->ctx, yang, LYS_IN_YANG);
    assert_ptr_not_equal(mod, NULL);
    assert_string_equal(mod->data->name, "a");
    assert_string_equal(((struct lys_node_leaf *)mod->data)->dflt, "10");
    assert_string_equal(mod->data->next->name, "b");
    assert_string_equal(((struct lys_node_leaf *)mod->data->next)->dflt, "10");
    assert_string_equal(mod->data->prev->name, "c");
    assert_string_equal(((struct lys_node_leaf *)mod->data->prev)->dflt, "10");

    /* in contrast, octal and hexadecimal values are not allowed in data */
    st->dt = lyd_parse_mem(st->ctx, xml2, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_equal(st->dt, NULL);
    assert_int_equal(ly_errno, LY_EVALID);
    assert_int_equal(ly_vecode(st->ctx), LYVE_INVAL);
    assert_string_equal(ly_errmsg(st->ctx), "Invalid value \"0xa\" in \"a\" element.");

    st->dt = lyd_parse_mem(st->ctx, xml1, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);
    assert_string_equal(((struct lyd_node_leaf_list *)st->dt)->value_str, "12");
}


/*
 * Sometimes the default isn't stored in canonical form, so this ensures the default
 * value is populated properly anyways
 */
static void
test_default_int_trusted(void **state)
{
    struct state *st = (*state);
    ly_ctx_destroy(st->ctx, NULL);
    st->ctx = ly_ctx_new(NULL, LY_CTX_TRUSTED);

    const char *yang = "module x {"
                    "  namespace urn:x;"
                    "  prefix x;"
                    "  leaf a { type int8; default 10; }"  // decimal (10)
                    "  leaf b { type int8; default 012; }" // octal (10)
                    "  leaf c { type int8; default 0xa; }" // hexadecimal (10)
                    "}";
    const char *xml1 = "<a xmlns=\"urn:x\">12</a>";
    const struct lys_module *mod;

    mod = lys_parse_mem(st->ctx, yang, LYS_IN_YANG);
    assert_ptr_not_equal(mod, NULL);

    st->dt = lyd_parse_mem(st->ctx, xml1, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);
    assert_string_equal(((struct lyd_node_leaf_list *)st->dt)->value_str, "12");

    assert_int_equal(lyd_validate(&st->dt, LYD_OPT_CONFIG, st->ctx), EXIT_SUCCESS);
}

/*
 * identityref and instance-identifiers values in XML are supposed to be converted into a JSON form where the prefixes
 * are the names of the modules, not a generic prefixes as in XML
 */
static void
test_xmltojson_identityref(void **state)
{
    struct state *st = (*state);
    const char *yang1 = "module x {"
                    "  namespace urn:x;"
                    "  prefix x;"
                    "  identity vehicle;"
                    "  identity car { base vehicle; }"
                    "}";
    const char *yang2 = "module y {"
                    "  namespace urn:y;"
                    "  prefix y;"
                    "  import x { prefix xpref; }"
                    "  leaf y1 { type identityref { base xpref:vehicle; } }"
                    "  leaf y2 { type leafref { path \"../y1\"; } }"
                    "}";
    const char *xml = "<y1 xmlns=\"urn:y\" xmlns:z=\"urn:x\">z:car</y1>"
                    "<y2 xmlns=\"urn:y\" xmlns:z=\"urn:x\">z:car</y2>";
    const char *result = "<y1 xmlns=\"urn:y\" xmlns:x=\"urn:x\">x:car</y1>"
                    "<y2 xmlns=\"urn:y\" xmlns:x=\"urn:x\">x:car</y2>";

    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang1, LYS_IN_YANG), NULL);
    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang2, LYS_IN_YANG), NULL);

    st->dt = lyd_parse_mem(st->ctx, xml, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_XML, LYP_WITHSIBLINGS);
    assert_ptr_not_equal(st->data, NULL);
    assert_string_equal(st->data, result);
}

static void
test_xmltojson_identityref2(void **state)
{
    struct state *st = (*state);
    const char *yang = "module y {"
                    "  namespace urn:y;"
                    "  prefix y;"
                    "  identity vehicle;"
                    "  identity car { base vehicle; }"
                    "  leaf y { type identityref { base y:vehicle; } default y:car; }"
                    "}";
    const char *result = "<y xmlns=\"urn:y\">car</y>";

    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang, LYS_IN_YANG), NULL);

    st->dt = NULL;
    lyd_validate(&st->dt, LYD_OPT_CONFIG, st->ctx);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_XML, LYP_WITHSIBLINGS | LYP_WD_ALL);
    assert_ptr_not_equal(st->data, NULL);
    assert_string_equal(st->data, result);
}

static void
test_xmltojson_instanceid(void **state)
{
    struct state *st = (*state);
    const char *yang1 = "module x {"
                    "  namespace urn:x;"
                    "  prefix x;"
                    "  leaf x { type string; }"
                    "}";
    const char *yang2 = "module y {"
                    "  namespace urn:y;"
                    "  prefix y;"
                    "  leaf y1 { type instance-identifier; }"
                    "  leaf y2 { type leafref { path \"../y1\"; } }"
                    "}";
    const char *xml = "<x xmlns=\"urn:x\">test</x>"
                    "<y1 xmlns=\"urn:y\" xmlns:z=\"urn:x\">/z:x</y1>"
                    "<y2 xmlns=\"urn:y\" xmlns:z=\"urn:x\">/z:x</y2>";
    const char *result =  "<x xmlns=\"urn:x\">test</x>"
                    "<y1 xmlns=\"urn:y\" xmlns:x=\"urn:x\">/x:x</y1>"
                    "<y2 xmlns=\"urn:y\" xmlns:x=\"urn:x\">/x:x</y2>";

    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang1, LYS_IN_YANG), NULL);
    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang2, LYS_IN_YANG), NULL);

    st->dt = lyd_parse_mem(st->ctx, xml, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_XML, LYP_WITHSIBLINGS);
    assert_ptr_not_equal(st->data, NULL);
    assert_string_equal(st->data, result);
}

static void
test_canonical(void **state)
{
    struct state *st = (*state);
    const char *yang = "module x {"
                    "  namespace urn:x;"
                    "  prefix x;"
                    "  container x {"
                    "    leaf-list a { type int8; }"
                    "    leaf-list b { type int16; }"
                    "    leaf-list c { type int32; }"
                    "    leaf-list d { type int64; }"
                    "    leaf-list e { type uint8; }"
                    "    leaf-list f { type uint16; }"
                    "    leaf-list g { type uint32; }"
                    "    leaf-list h { type uint64; }"
                    "    leaf-list i { type decimal64 { fraction-digits 2; } }"
                    "    leaf-list j { type bits {"
                    "        bit one { position 1; }"
                    "        bit three { position 3; }"
                    "        bit two { position 2; }"
                    "    }  }"
                    "    leaf-list alr { type leafref { path ../a; } }"
                    "    leaf-list blr { type leafref { path ../b; } }"
                    "    leaf-list clr { type leafref { path ../c; } }"
                    "    leaf-list dlr { type leafref { path ../d; } }"
                    "    leaf-list elr { type leafref { path ../e; } }"
                    "    leaf-list flr { type leafref { path ../f; } }"
                    "    leaf-list glr { type leafref { path ../g; } }"
                    "    leaf-list hlr { type leafref { path ../h; } }"
                    "    leaf-list ilr { type leafref { path ../i; } }"
                    "    leaf-list jlr { type leafref { path ../j; } }"
                    "} }";
    const char *input = "<x xmlns=\"urn:x\">"
                    "<a>+1</a><a>+0</a>"
                    "<b>+300</b><b>+0</b>"
                    "<c>+66000</c><c>+0</c>"
                    "<d>+4300000000</d><d>+0</d>"
                    "<e>+1</e><e>-0</e>"
                    "<f>+300</f><f>-0</f>"
                    "<g>+66000</g><g>-0</g>"
                    "<h>+4300000000</h><h>-0</h>"
                    "<i>1</i><i>+2</i><i>0</i><i>3.000000</i><i>0000004</i><i>4.1</i>"
                    "<j> three      two</j><j>one two</j><j> two   three one</j>"
                    "<alr>+1</alr><alr>+0</alr>"
                    "<blr>+300</blr><blr>+0</blr>"
                    "<clr>+66000</clr><clr>+0</clr>"
                    "<dlr>+4300000000</dlr><dlr>+0</dlr>"
                    "<elr>+1</elr><elr>-0</elr>"
                    "<flr>+300</flr><flr>-0</flr>"
                    "<glr>+66000</glr><glr>-0</glr>"
                    "<hlr>+4300000000</hlr><hlr>-0</hlr>"
                    "<ilr>1</ilr><ilr>+2</ilr><ilr>0</ilr><ilr>3.000000</ilr><ilr>0000004</ilr><ilr>4.1</ilr>"
                    "<jlr> three      two</jlr><jlr>one two</jlr><jlr> two   three one</jlr>"
                    "</x>";
    const char *result = "<x xmlns=\"urn:x\">"
                    "<a>1</a><a>0</a>"
                    "<b>300</b><b>0</b>"
                    "<c>66000</c><c>0</c>"
                    "<d>4300000000</d><d>0</d>"
                    "<e>1</e><e>0</e>"
                    "<f>300</f><f>0</f>"
                    "<g>66000</g><g>0</g>"
                    "<h>4300000000</h><h>0</h>"
                    "<i>1.0</i><i>2.0</i><i>0.0</i><i>3.0</i><i>4.0</i><i>4.1</i>"
                    "<j>two three</j><j>one two</j><j>one two three</j>"
                    "<alr>1</alr><alr>0</alr>"
                    "<blr>300</blr><blr>0</blr>"
                    "<clr>66000</clr><clr>0</clr>"
                    "<dlr>4300000000</dlr><dlr>0</dlr>"
                    "<elr>1</elr><elr>0</elr>"
                    "<flr>300</flr><flr>0</flr>"
                    "<glr>66000</glr><glr>0</glr>"
                    "<hlr>4300000000</hlr><hlr>0</hlr>"
                    "<ilr>1.0</ilr><ilr>2.0</ilr><ilr>0.0</ilr><ilr>3.0</ilr><ilr>4.0</ilr><ilr>4.1</ilr>"
                    "<jlr>two three</jlr><jlr>one two</jlr><jlr>one two three</jlr>"
                    "</x>";

    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang, LYS_IN_YANG), NULL);
    st->dt = lyd_parse_mem(st->ctx, input, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_XML, LYP_WITHSIBLINGS);
    assert_ptr_not_equal(st->data, NULL);
    assert_string_equal(st->data, result);
}

static void
test_validate_value(void **state)
{
    struct state *st = (*state);
    const struct lys_module *mod;
    struct lys_node *node;
    const char *yang = "module x {"
                    "  namespace urn:x;"
                    "  prefix x;"
                    "  leaf target {"
                    "    type string {"
                    "      length 2..4;"
                    "      pattern \'a*\';"
                    "    }"
                    "  }"
                    "  leaf a {"
                    "    type leafref {"
                    "      path /x:target;"
                    "    }"
                    "  }"
                    "  leaf b {"
                    "    type int8 {"
                    "      range -1..1;"
                    "    }"
                    "  }"
                    "  leaf c {"
                    "    type enumeration {"
                    "      enum alfa;"
                    "    }"
                    "  }"
                    "  leaf d {"
                    "    type decimal64 {"
                    "      fraction-digits 1;"
                    "    }"
                    "  }"
                    "  leaf e {"
                    "    type decimal64 {"
                    "      fraction-digits 10;"
                    "    }"
                    "  }"
                    "  leaf f {"
                    "    type decimal64 {"
                    "      fraction-digits 18;"
                    "    }"
                    "  }"
                    "}";

    mod = lys_parse_mem(st->ctx, yang, LYS_IN_YANG);
    assert_ptr_not_equal(mod, NULL);

    /* a */
    node = mod->data->next;
    assert_int_equal(lyd_validate_value(node, NULL), EXIT_FAILURE); /* empty string is too short */
    assert_int_equal(lyd_validate_value(node, "a"), EXIT_FAILURE); /* a is still too short */
    assert_int_equal(lyd_validate_value(node, "bbb"), EXIT_FAILURE); /* does not match the pattern */
    assert_int_equal(lyd_validate_value(node, "aaaaa"), EXIT_FAILURE); /* too long */
    assert_int_equal(lyd_validate_value(node, "aaa"), EXIT_SUCCESS); /* ok */

    /* b */
    node = node->next;
    assert_int_equal(lyd_validate_value(node, "2"), EXIT_FAILURE); /* too high */
    assert_int_equal(lyd_validate_value(node, "-"), EXIT_FAILURE); /* does not match the type (yet) */
    assert_int_equal(lyd_validate_value(node, "-2"), EXIT_FAILURE); /* too low */
    assert_int_equal(lyd_validate_value(node, "0"), EXIT_SUCCESS); /* ok */

    /* c */
    node = node->next;
    assert_int_equal(lyd_validate_value(node, "a"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "al"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "alf"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "alfa"), EXIT_SUCCESS); /* ok */
    assert_int_equal(lyd_validate_value(node, "alfa "), EXIT_FAILURE);

    /* d */
    node = node->next;
    assert_int_equal(lyd_validate_value(node, "-922337203685477580.9"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "-925337203685477580"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "922337203685477580.8"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "932337203685477580"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "-922337203685477580.8"), EXIT_SUCCESS); /* ok */
    assert_int_equal(lyd_validate_value(node, "922337203685477580.7"), EXIT_SUCCESS); /* ok */

    /* e */
    node = node->next;
    assert_int_equal(lyd_validate_value(node, "-922337203.6854775818"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "-9223372031"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "922337203.6854785807"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "1922337203"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "-922337203.6854775808"), EXIT_SUCCESS); /* ok */
    assert_int_equal(lyd_validate_value(node, "922337203.6854775807"), EXIT_SUCCESS); /* ok */

    /* f */
    node = node->next;
    assert_int_equal(lyd_validate_value(node, "-9.223372036854776808"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "-10"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "9.223372136854775807"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "11"), EXIT_FAILURE);
    assert_int_equal(lyd_validate_value(node, "-9.223372036854775808"), EXIT_SUCCESS); /* ok */
    assert_int_equal(lyd_validate_value(node, "9.223372036854775807"), EXIT_SUCCESS); /* ok */
}

void test_xmltojson_anydata(void **state)
{
    struct state *st = (*state);
    const char *yang = "module y{"
                        "  namespace urn:y;"
                        "  prefix y;"
                        "  extension test {"
                        "    argument \"test\";"
                        "  } "
                        "  anydata data{"
                        "    y:test \"MY_INTERFACES\";"
                        "  }"
                        "}";
    const char *xml1 =  "<data xmlns =\"urn:y\">"
                        "  <severity >test</severity>"
                        "</data>";

    const char *xml2 = "<data xmlns =\"urn:y\">abab</data>";

    const char *xml_data_tree = "<data xmlns =\"urn:y\">"
                                "+--rw interfaces"
                                "|  +--rw interface* [name]"
                                "|     +--rw name                        string"
                                "|     +--rw description?                string"
                                "|     +--rw type                        identityref"
                                "|     +--rw link-up-down-trap-enable?   enumeration"
                                "</data>";

    const struct lys_module *mod;
    mod = lys_parse_mem(st->ctx, yang, LYS_IN_YANG);
    assert_ptr_not_equal(mod, NULL);

    st->dt = lyd_parse_mem(st->ctx, xml1, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_JSON, LYP_WITHSIBLINGS | LYP_WD_ALL);
    assert_ptr_not_equal(st->data, NULL);
    free(st->data);
    st->data = NULL;
    lyd_free_withsiblings(st->dt);

    st->dt = lyd_parse_mem(st->ctx, xml2, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_JSON, LYP_WITHSIBLINGS | LYP_WD_ALL);
    assert_ptr_not_equal(st->data, NULL);
    free(st->data);
    st->data = NULL;
    lyd_free_withsiblings(st->dt);

    st->dt = lyd_parse_mem(st->ctx, xml_data_tree, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_JSON, LYP_WITHSIBLINGS | LYP_WD_ALL);
    assert_ptr_not_equal(st->data, NULL);
}

void test_xmltojson_extension(void **state)
{
    struct state *st = (*state);
    const char *yang = "module y {"
                       "  namespace urn:y;"
                       "  prefix y;"
                       "  extension test {"
                       "    argument \"name\";"
                       "  }"
                       "  container y {"
                       "    y:test  \"test\"; "
                       "    leaf a { type string;}"
                       "  }"
                       "}";
    const char *xml = "<y xmlns =\"urn:y\">"
                      "  <a> \\\\major</a>"
                      "</y>";

    assert_ptr_not_equal(lys_parse_mem(st->ctx, yang, LYS_IN_YANG), NULL);

    st->dt = lyd_parse_mem(st->ctx, xml, LYD_XML, LYD_OPT_CONFIG);
    assert_ptr_not_equal(st->dt, NULL);

    lyd_print_mem(&st->data, st->dt, LYD_JSON, LYP_WITHSIBLINGS | LYP_WD_ALL);
    assert_ptr_not_equal(st->data, NULL);
}

int main(void)
{
    const struct CMUnitTest tests[] = {
                    cmocka_unit_test_setup_teardown(test_default_int, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_default_int_trusted, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_xmltojson_identityref, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_xmltojson_identityref2, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_xmltojson_instanceid, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_canonical, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_xmltojson_anydata, setup_f, teardown_f),
                    cmocka_unit_test_setup_teardown(test_xmltojson_extension, setup_f, teardown_f),
    };

    return cmocka_run_group_tests(tests, NULL, NULL);
}