/*
 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <assert.h>
#include <camkes.h>
#include "heap_check.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int run(void)
{

#ifdef NDEBUG
    printf("WARNING: ASSERTIONS DISABLED; NOTHING WILL BE TESTED\n");
#endif

    const char *name = get_instance_name();

    printf("%s: Calling p_foo()...\n", name);
    char *s = p_foo();
    printf("%s: Received \"%s\"\n", name, s);

    printf("\n");

    const char *s1[] = {"hello", "world"};
    size_t s1_sz = sizeof(s1) / sizeof(s1[0]);
    printf("%s: Calling p_bar(%u, {\"%s\", \"%s\"})...\n", name, s1_sz, s1[0],
           s1[1]);
    p_bar(s1_sz, s1);

    printf("\n");

    char **s2 = NULL;
    size_t s2_sz;
    printf("%s: Calling p_baz(&s2_sz, &s2)...\n", name);
    p_baz(&s2_sz, &s2);
    assert(s2 != NULL);
    printf("%s: Received s2_sz = %u, s2 = {", name, s2_sz);
    for (unsigned int i = 0; i < s2_sz; i++) {
        printf("\"%s\", ", s2[i]);
        safe_free(s2[i]);
    }
    printf("}\n");
    safe_free(s2);

    printf("\n");

    size_t s3_sz = 2;
    char **s3 = calloc(s2_sz, sizeof(char *));
    assert(s3 != NULL);
    s3[0] = strdup("ciao");
    assert(s3[0] != NULL);
    s3[1] = strdup("mondo");
    assert(s3[1] != NULL);
    printf("%s: s3_sz = %u, s3 = {", name, s3_sz);
    for (unsigned int i = 0; i < s3_sz; i++) {
        printf("\"%s\", ", s3[i]);
    }
    printf("}\n");
    printf("%s: Calling p_qux(&s3_sz, &s3)...\n", name);
    p_qux(&s3_sz, &s3);
    assert(s3 != NULL);
    printf("%s: Received s3_sz = %u, s3 = {", name, s3_sz);
    for (unsigned int i = 0; i < s3_sz; i++) {
        printf("\"%s\", ", s3[i]);
        safe_free(s3[i]);
    }
    printf("}\n");
    safe_free(s3);

    printf("\n");

    const char *s4[] = { "bonjour", "le", "monde" };
    size_t s4_sz = sizeof(s4) / sizeof(s4[0]);
    char **s5 = NULL;
    size_t s5_sz;
    size_t s6_sz = 2;
    char **s6 = calloc(s6_sz, sizeof(char *));
    assert(s6 != NULL);
    s6[0] = strdup("ahoj");
    assert(s6[0] != NULL);
    s6[1] = strdup("svete");
    assert(s6[1] != NULL);
    printf("%s: s6_sz = %u, s6 = {", name, s6_sz);
    for (unsigned int i = 0; i < s6_sz; i++) {
        printf("\"%s\", ", s6[i]);
    }
    printf("}\n");
    printf("%s: Calling p_quux(%u, {\"%s\", \"%s\", \"%s\"}, &s5_sz, &s5, "
           "&s6_sz, &s6)...\n", name, s4_sz, s4[0], s4[1], s4[2]);
    p_quux(s4_sz, s4, &s5_sz, &s5, &s6_sz, &s6);
    assert(s5 != NULL);
    printf("%s: Received s5_sz = %u, s5 = {", name, s5_sz);
    for (unsigned int i = 0; i < s5_sz; i++) {
        printf("\"%s\", ", s5[i]);
        safe_free(s5[i]);
    }
    printf("}, s6_sz = %u, s6 = {", s6_sz);
    for (unsigned int i = 0; i < s6_sz; i++) {
        printf("\"%s\", ", s6[i]);
        safe_free(s6[i]);
    }
    printf("}\n");

    printf("\n");

    /* This last case makes no real sense, but we still test that it works. */
    size_t s7_sz = 2;
    char ***s7 = malloc(sizeof(char **));
    assert(s7 != NULL);
    *s7 = malloc(s7_sz * sizeof(char *));
    assert(*s7 != NULL);
    (*s7)[0] = strdup("konnichiwa");
    assert((*s7)[0] != NULL);
    (*s7)[1] = strdup("sekai");
    assert((*s7)[1] != NULL);
    printf("%s: Calling p_corge(%u, {\"%s\", \"%s\"})...\n", name, s7_sz,
           (*s7)[0], (*s7)[1]);
    p_corge(&s7_sz, s7);
    safe_free((*s7)[0]);
    safe_free((*s7)[1]);
    safe_free(*s7);
    safe_free(s7);

    printf("\n");

    printf("All OK\n");
    return 0;
}
