"Fossies" - the Fresh Open Source Software Archive

Member "hydra-3.3.2/mpl/test/strsep.c" (12 Nov 2019, 1842 Bytes) of package /linux/misc/hydra-3.3.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "strsep.c": 3.3.1_vs_3.3.2.

    1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
    2 /*
    3  *  (C) 2011 by Argonne National Laboratory.
    4  *      See COPYRIGHT in top-level directory.
    5  */
    6 
    7 #include <stdio.h>
    8 #include <stdlib.h>
    9 #include <string.h>
   10 #include <assert.h>
   11 #include "mpl.h"
   12 
   13 int main(void)
   14 {
   15     char *orig;
   16     char *str;
   17     char *next;
   18 
   19     str = NULL;
   20     next = MPL_strsep(&str, "|");
   21     assert(next == NULL);
   22     assert(str == NULL);
   23 
   24     orig = MPL_strdup("");
   25     str = orig;
   26     next = MPL_strsep(&str, "|");
   27     assert(str == NULL);
   28     assert(next == orig);
   29     MPL_free(orig);
   30 
   31     orig = MPL_strdup("a|b|c");
   32     str = orig;
   33     next = MPL_strsep(&str, "|");
   34     assert(next == orig);
   35     assert(0 == strcmp(next, "a"));
   36     next = MPL_strsep(&str, "|");
   37     assert(0 == strcmp(next, "b"));
   38     next = MPL_strsep(&str, "|");
   39     assert(0 == strcmp(next, "c"));
   40     next = MPL_strsep(&str, "|");
   41     assert(next == NULL);
   42     assert(str == NULL);
   43     MPL_free(orig);
   44 
   45     orig = MPL_strdup("a|b:c");
   46     str = orig;
   47     next = MPL_strsep(&str, ":|");
   48     assert(next == orig);
   49     assert(0 == strcmp(next, "a"));
   50     next = MPL_strsep(&str, ":|");
   51     assert(0 == strcmp(next, "b"));
   52     next = MPL_strsep(&str, ":|");
   53     assert(0 == strcmp(next, "c"));
   54     next = MPL_strsep(&str, ":|");
   55     assert(next == NULL);
   56     assert(str == NULL);
   57     MPL_free(orig);
   58 
   59     orig = MPL_strdup("a|:b:c");
   60     str = orig;
   61     next = MPL_strsep(&str, ":|");
   62     assert(next == orig);
   63     assert(0 == strcmp(next, "a"));
   64     next = MPL_strsep(&str, ":|");
   65     assert(0 == strcmp(next, ""));
   66     next = MPL_strsep(&str, ":|");
   67     assert(0 == strcmp(next, "b"));
   68     next = MPL_strsep(&str, ":|");
   69     assert(0 == strcmp(next, "c"));
   70     next = MPL_strsep(&str, ":|");
   71     assert(next == NULL);
   72     assert(str == NULL);
   73     MPL_free(orig);
   74 
   75     return 0;
   76 }