~ubuntu-branches/ubuntu/trusty/serf/trusty-security

« back to all changes in this revision

Viewing changes to test/CuTest.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2013-12-31 13:17:16 UTC
  • mfrom: (1.1.8) (3.3.2 sid)
  • Revision ID: package-import@ubuntu.com-20131231131716-s862wc4uwdzxmrr1
Tags: 1.3.3-1
* Add myself to Uploaders.
* Change the watch file to better handle code.google.com.
* New upstream release.  (Closes: #716793)
  + Refresh patches/libtool
  + Update symbols
* Adapt packaging for the upstream switch to SCons.
  + control: + scons, - autotools-dev, autoconf
  + rules: Change configure/make calls to scons
* Rename libserf1 to libserf-1-1, following standard naming conventions.
* Enable hardening flags.
* Strip unnecessary RPATH from libserf.
* Honor DEB_BUILD_OPTIONS=parallel=X

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 *
24
24
 * Originally obtained from "http://cutest.sourceforge.net/" version 1.4.
25
25
 *
26
 
 * Modified for serf as follows
27
 
 *    1) added CuStringFree(), CuTestFree(), CuSuiteFree(), and
28
 
 *       CuSuiteFreeDeep()
29
 
 *    0) reformatted the whitespace (doh!)
 
26
 * See CuTest.h for a list of serf-specific modifications.
30
27
 */
31
28
#include <assert.h>
32
29
#include <setjmp.h>
146
143
    t->message = NULL;
147
144
    t->function = function;
148
145
    t->jumpBuf = NULL;
 
146
    t->setup = NULL;
 
147
    t->teardown = NULL;
 
148
    t->testBaton = NULL;
149
149
}
150
150
 
151
151
CuTest* CuTestNew(const char* name, TestFunction function)
165
165
{
166
166
    jmp_buf buf;
167
167
    tc->jumpBuf = &buf;
 
168
    if (tc->setup)
 
169
        tc->testBaton = tc->setup(tc);
168
170
    if (setjmp(buf) == 0)
169
171
    {
170
172
        tc->ran = 1;
171
173
        (tc->function)(tc);
172
174
    }
 
175
    if (tc->teardown)
 
176
        tc->teardown(tc->testBaton);
 
177
 
173
178
    tc->jumpBuf = 0;
174
179
}
175
180
 
205
210
    CuFail_Line(tc, file, line, NULL, message);
206
211
}
207
212
 
 
213
void CuAssertStrnEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
 
214
                                const char* expected, size_t explen,
 
215
                                const char* actual)
 
216
{
 
217
    CuString string;
 
218
    if ((explen == 0) ||
 
219
        (expected == NULL && actual == NULL) ||
 
220
        (expected != NULL && actual != NULL &&
 
221
         strncmp(expected, actual, explen) == 0))
 
222
    {
 
223
        return;
 
224
    }
 
225
 
 
226
    CuStringInit(&string);
 
227
    if (message != NULL)
 
228
    {
 
229
        CuStringAppend(&string, message);
 
230
        CuStringAppend(&string, ": ");
 
231
    }
 
232
    CuStringAppend(&string, "expected <");
 
233
    CuStringAppend(&string, expected);
 
234
    CuStringAppend(&string, "> but was <");
 
235
    CuStringAppend(&string, actual);
 
236
    CuStringAppend(&string, ">");
 
237
    CuFailInternal(tc, file, line, &string);
 
238
}
 
239
 
208
240
void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
209
241
    const char* expected, const char* actual)
210
242
{
227
259
    CuStringAppend(&string, "> but was <");
228
260
    CuStringAppend(&string, actual);
229
261
    CuStringAppend(&string, ">");
230
 
    CuFailInternal(tc, file, line, &string);
231
 
}
 
262
    CuFailInternal(tc, file, line, &string);}
232
263
 
233
264
void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
234
265
    int expected, int actual)
266
297
{
267
298
    testSuite->count = 0;
268
299
    testSuite->failCount = 0;
 
300
    testSuite->setup = NULL;
 
301
    testSuite->teardown = NULL;
269
302
}
270
303
 
271
304
CuSuite* CuSuiteNew(void)
296
329
    assert(testSuite->count < MAX_TEST_CASES);
297
330
    testSuite->list[testSuite->count] = testCase;
298
331
    testSuite->count++;
 
332
 
 
333
    /* CuSuiteAdd is called twice per test, don't reset the callbacks if
 
334
       already set. */
 
335
    if (!testCase->setup)
 
336
        testCase->setup = testSuite->setup;
 
337
    if (!testCase->teardown)
 
338
        testCase->teardown = testSuite->teardown;
299
339
}
300
340
 
301
341
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2)
365
405
        CuStringAppendFormat(details, "Fails: %d\n",  testSuite->failCount);
366
406
    }
367
407
}
 
408
 
 
409
void CuSuiteSetSetupTeardownCallbacks(CuSuite* testSuite, TestCallback setup,
 
410
                                      TestCallback teardown)
 
411
{
 
412
    testSuite->setup = setup;
 
413
    testSuite->teardown = teardown;
 
414
}
 
 
b'\\ No newline at end of file'