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 |
|
|
** airStrlen |
30 |
|
|
** airStrdup |
31 |
|
|
** airStrcpy |
32 |
|
|
** |
33 |
|
|
** Also uses: |
34 |
|
|
** airMopNew, airMopAdd, airMopError, airMopDone |
35 |
|
|
*/ |
36 |
|
|
|
37 |
|
|
/* random test strings */ |
38 |
|
|
#define STR_A1 "The facts of life: To make an alteration in the evolvement of an organic life system is fatal. A coding sequence cannot be revised once it's been established." |
39 |
|
|
#define STR_A2 "Because by the second day of incubation, any cells that have undergone reversion mutations give rise to revertant colonies like rats leaving a sinking ship; then the ship sinks." |
40 |
|
|
#define STR_A (STR_A1 " " STR_A2) |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
#define STR_B1 "We've already tried it. Ethyl methane sulfonate is an alkylating agent and a potent mutagen. It created a virus so lethal the subject was dead before he left the table." |
44 |
|
|
#define STR_B2 "Wouldn't obstruct replication, but it does give rise to an error in replication so that the newly formed DNA strand carries a mutation and you've got a virus again. But this - all of this is academic. You were made as well as we could make you." |
45 |
|
|
#define STR_B (STR_B1 " " STR_B2) |
46 |
|
|
|
47 |
|
|
#define STR_AB (STR_A " " STR_B) |
48 |
|
|
|
49 |
|
|
int |
50 |
|
|
main(int argc, const char *argv[]) { |
51 |
|
|
airArray *mop; |
52 |
|
|
const char *me; |
53 |
|
|
char *aa, *aaCopy, *ab; |
54 |
|
|
size_t aaSize, abSize; |
55 |
|
|
|
56 |
|
|
AIR_UNUSED(argc); |
57 |
|
2 |
me = argv[0]; |
58 |
|
1 |
mop = airMopNew(); |
59 |
|
|
|
60 |
✗✓ |
1 |
if (0 != airStrlen(NULL)) { |
61 |
|
|
fprintf(stderr, "%s: 0 != airStrlen(NULL)\n", me); |
62 |
|
|
airMopError(mop); |
63 |
|
|
exit(1); |
64 |
|
|
} |
65 |
✗✓ |
1 |
if (0 != airStrlen("")) { |
66 |
|
|
fprintf(stderr, "%s: 0 != airStrlen(\"\")\n", me); |
67 |
|
|
airMopError(mop); |
68 |
|
|
exit(1); |
69 |
|
|
} |
70 |
✗✓ |
1 |
if (1 != airStrlen("A")) { |
71 |
|
|
fprintf(stderr, "%s: 1 != airStrlen(\"A\")\n", me); |
72 |
|
|
airMopError(mop); |
73 |
|
|
exit(1); |
74 |
|
|
} |
75 |
✗✓ |
1 |
if (NULL != airStrdup(NULL)) { |
76 |
|
|
fprintf(stderr, "%s: NULL != airStrdup(NULL)\n", me); |
77 |
|
|
airMopError(mop); |
78 |
|
|
exit(1); |
79 |
|
|
} |
80 |
✗✓ |
1 |
if (strlen(STR_A) != airStrlen(STR_A)) { |
81 |
|
|
fprintf(stderr, "%s: strlen %u != airStrlen %u of |%s|\n", me, |
82 |
|
|
AIR_CAST(unsigned int, strlen(STR_A)), |
83 |
|
|
AIR_CAST(unsigned int, airStrlen(STR_A)), STR_A); |
84 |
|
|
airMopError(mop); |
85 |
|
|
exit(1); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
1 |
aa = airStrdup(STR_A); |
89 |
|
1 |
airMopAdd(mop, aa, airFree, airMopAlways); |
90 |
✗✓ |
1 |
if (strcmp(aa, STR_A)) { |
91 |
|
|
fprintf(stderr, "%s: airStrdup failure: |%s| != |%s|\n", me, |
92 |
|
|
aa, STR_A); |
93 |
|
|
airMopError(mop); |
94 |
|
|
exit(1); |
95 |
|
|
} |
96 |
|
1 |
aaSize = strlen(aa)+1; |
97 |
|
1 |
aaCopy = AIR_CALLOC(aaSize, char); |
98 |
|
1 |
airMopAdd(mop, aaCopy, airFree, airMopAlways); |
99 |
|
|
|
100 |
|
|
abSize = strlen(STR_A) + strlen(" ") + strlen(STR_B) + 1; |
101 |
|
1 |
ab = AIR_CALLOC(abSize, char); |
102 |
|
1 |
airMopAdd(mop, ab, airFree, airMopAlways); |
103 |
|
1 |
sprintf(ab, "%s %s", STR_A, STR_B); |
104 |
|
|
|
105 |
|
|
#define TEST(COPY, COMP) \ |
106 |
|
|
airStrcpy(aaCopy, aaSize, COPY); \ |
107 |
|
|
if (strcmp(aaCopy, COMP)) { \ |
108 |
|
|
fprintf(stderr, "%s: airStrcpy failure: |%s| != |%s|\n", \ |
109 |
|
|
me, aaCopy, COMP); \ |
110 |
|
|
airMopError(mop); \ |
111 |
|
|
exit(1); \ |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
/* different args (to copy) to airStrcpy */ |
115 |
|
|
/* arg to copy is smaller than dest */ |
116 |
✗✓ |
1 |
TEST("", ""); |
117 |
✗✓ |
1 |
TEST(NULL, ""); /* depends on previous test result */ |
118 |
✗✓ |
1 |
TEST(STR_A1, STR_A1); |
119 |
✗✓ |
1 |
TEST(STR_A2, STR_A2); |
120 |
|
|
/* arg to copy is same size as dest */ |
121 |
✗✓ |
1 |
TEST(STR_A, STR_A); |
122 |
✗✓ |
1 |
TEST(aa, aa); |
123 |
|
|
/* arg to copy is bigger than dest */ |
124 |
✗✓ |
1 |
TEST(ab, aa); |
125 |
|
|
|
126 |
|
1 |
airMopOkay(mop); |
127 |
|
1 |
exit(0); |
128 |
|
|
} |