network/gru_uri_test_opt.c

URI parsing example

#include <network/gru_uri.h>

// amqp://localhost:61613/queue amq localhost 61613 queue
int test_with_strip(int argc, char **argv) {
    gru_uri_t uri = {0};
    gru_status_t status = gru_status_new();

    if (argc < 3) {
        fprintf(stderr, "Missing arguments\n");
        return EXIT_FAILURE;
    }

    uri = gru_uri_parse_ex(argv[1], GRU_URI_PARSE_STRIP, &status);

    if (gru_status_error(&status)) {
        fprintf(stderr, "%s", status.message);

        goto err_exit;
    }

    if (strcmp(uri.scheme, argv[2]) != 0) {
        fprintf(stderr,
            "Expected scheme '%s' does not match returned one '%s'\n", argv[2], uri.scheme);

        goto err_exit;
    }

    if (strcmp(uri.host, argv[3]) != 0) {
        fprintf(
            stderr, "Expected host '%s' does not match returned one '%s'\n", argv[3], uri.host);

        goto err_exit;
    }

    if (uri.port != atoi(argv[4])) {
        fprintf(
            stderr, "Expected port '%s' does not match returned one '%d'\n", argv[2], uri.port);

        goto err_exit;
    }

    if (strcmp(uri.path, argv[5]) != 0) {
        fprintf(
            stderr, "Expected path '%s' does not match returned one '%s'\n", argv[5], uri.path);

        goto err_exit;
    }

    gru_uri_cleanup(&uri);
    return EXIT_SUCCESS;

err_exit:
    gru_uri_cleanup(&uri);
    return EXIT_FAILURE;
}

int main(int argc, char **argv) {
    return test_with_strip(argc, argv);
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 7 Jan 2019 for GRU - Generic Reusable Utilities by  doxygen 1.6.1