GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: Testing/air/strtok.c Lines: 23 30 76.7 %
Date: 2017-05-26 Branches: 7 10 70.0 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
4
  Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
5
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
6
7
  This library is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public License
9
  (LGPL) as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
  The terms of redistributing and/or modifying this software also
12
  include exceptions to the LGPL that facilitate static linking.
13
14
  This library is distributed in the hope that it will be useful,
15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
  Lesser General Public License for more details.
18
19
  You should have received a copy of the GNU Lesser General Public License
20
  along with this library; if not, write to Free Software Foundation, Inc.,
21
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
*/
23
24
25
#include "teem/air.h"
26
27
/*
28
** Tests:
29
** airStrtok
30
** airStrntok
31
**
32
** Also uses:
33
** airArrayNew, airArrayNuke, airArrayLenSet, airArrayLenIncr
34
** airMopNew, airMopAdd, airMopError, airMopDone
35
*/
36
37
#define INCR 10
38
int
39
main(int argc, const char *argv[]) {
40
  airArray *mop;
41
  const char *me;
42
2
  const char *word[] = {
43
    "There's", "a", "certain", "slant", "of", "light",
44
    "On", "winter", "afternoons",
45
    "That", "oppresses,", "like", "the", "weight",
46
    "Of", "cathedral", "tunes.",
47
    "Heavenly", "hurt", "it", "gives", "us;",
48
    "We", "can", "find", "no", "scar,",
49
    "But", "internal", "difference",
50
    "Where", "the", "meanings", "are.",
51
    "None", "may", "teach", "it", "anything,",
52
    "'T", "is", "the", "seal,", "despair,",
53
    "An", "imperial", "affliction",
54
    "Sent", "us", "of", "the", "air.",
55
    "When", "it", "comes,", "the", "landscape", "listens,",
56
    "Shadows", "hold", "their", "breath;",
57
    "When", "it", "goes,", "'t", "is", "like", "the", "distance",
58
    "On", "the", "look", "of", "death.", ""};
59
  const char *sep = " \t\n_", *ww;
60
1
  unsigned int wi, sepLen, lineLen, wordNum;
61
  airArray *lineArr;
62
1
  char wordsp[AIR_STRLEN_MED], *line, *last=NULL;
63
64
  AIR_UNUSED(argc);
65
1
  me = argv[0];
66
1
  sepLen = AIR_CAST(unsigned int, airStrlen(sep));
67
68
1
  mop = airMopNew();
69
1
  lineArr = airArrayNew((void**)(&line), &lineLen, sizeof(char), INCR);
70
1
  airMopAdd(mop, lineArr, (airMopper)airArrayNuke, airMopAlways);
71
72
  /* initialize line with "" */
73
1
  airArrayLenSet(lineArr, 1);
74
1
  strcpy(line, "");
75
76
  /* add words and separators onto line */
77
152
  for (wi=0; airStrlen(word[wi]); wi++) {
78
225
    sprintf(wordsp, "%s%c", word[wi], sep[AIR_MOD(wi, sepLen)]);
79
75
    airArrayLenIncr(lineArr, AIR_CAST(int, airStrlen(wordsp)));
80
75
    strcat(line, wordsp);
81
  }
82
83
  /* lose last sep char */
84
1
  line[strlen(line)-1] = '\0';
85
86
  /* start tokenizing and comparing */
87
1
  wordNum = airStrntok(line, sep);
88
1
  if (75 != wordNum) {
89
    fprintf(stderr, "%s: wordNum %u != 75\n", me, wordNum);
90
    airMopError(mop);
91
    return 1;
92
  }
93
  wi = 0;
94
152
  for (ww = airStrtok(line, sep, &last);
95
       ww;
96
75
       ww = airStrtok(NULL, sep, &last)) {
97
75
    if (strcmp(word[wi], ww)) {
98
      fprintf(stderr, "%s: word[%u] |%s| != parsed |%s|\n",
99
              me, wi, word[wi], ww);
100
      airMopError(mop);
101
      exit(1);
102
    }
103
75
    wi++;
104
  }
105
106
  /* we're done */
107
1
  airMopOkay(mop);
108
1
  exit(0);
109
}