Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

c/example.c.tests/example.c.tests.c

Demonstrates the minimal use of a test runner with test case functions.

/* /////////////////////////////////////////////////////////////////////////
 * File:        examples/c/example.c.tests/example.c.tests.c
 *
 * Purpose:     Implementation file for the example.c.tests project.
 *
 * Created:     20th February 2008
 * Updated:     23rd February 2008
 *
 * Status:      Wizard-generated
 *
 * License:     (Licensed under the Synesis Software Open License)
 *
 *              Copyright (c) 2008, Synesis Software Pty Ltd.
 *              All rights reserved.
 *
 *              www:        http://www.synesis.com.au/software
 *
 * ////////////////////////////////////////////////////////////////////// */


/* xTests Header Files */
#include <xtests/xtests.h>

/* STLSoft Header Files */
#include <stlsoft/stlsoft.h>

/* Standard C Header Files */
#include <stdlib.h>

/* ////////////////////////////////////////////////////////////////////// */

static void test_1(void);
static void test_2(void);
static void test_3(void);
static void test_4(void);

/* ////////////////////////////////////////////////////////////////////// */

int main(int argc, char **argv)
{
    int retCode = EXIT_SUCCESS;
    int verbosity;

    XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);

    if(XTESTS_START_RUNNER("example.c.tests", verbosity))
    {
        XTESTS_RUN_CASE_WITH_DESC(test_1, "checking sizes of different integer types");
        XTESTS_RUN_CASE_WITH_DESC(test_2, "checking equality of sizes of signed and unsigned integer types");
        XTESTS_RUN_CASE_WITH_DESC(test_3, "tests that always pass");
        XTESTS_RUN_CASE_WITH_DESC(test_4, "evaluating relationships between numbers");

        XTESTS_PRINT_RESULTS();

        XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
    }

    return retCode;
}

/* ////////////////////////////////////////////////////////////////////// */

static void test_1(void)
{
    XTESTS_TEST_INTEGER_LESS_OR_EQUAL(sizeof(char), sizeof(short));
    XTESTS_TEST_INTEGER_LESS_OR_EQUAL(sizeof(short), sizeof(int));
    XTESTS_TEST_INTEGER_LESS_OR_EQUAL(sizeof(int), sizeof(long));
}

static void test_2(void)
{
    XTESTS_TEST_INTEGER_EQUAL_EXACT(sizeof(signed char), sizeof(unsigned char));
    XTESTS_TEST_INTEGER_EQUAL_EXACT(sizeof(signed short), sizeof(unsigned short));
    XTESTS_TEST_INTEGER_EQUAL_EXACT(sizeof(signed int), sizeof(unsigned int));
    XTESTS_TEST_INTEGER_EQUAL_EXACT(sizeof(signed long), sizeof(unsigned long));
}

static void test_3(void)
{
    XTESTS_TEST_PASSED();
}

static void test_4(void)
{
    { int i; for(i = -1000; i != 1000; ++i)
    {
        { int j; for(j = -1000; j != 1000; ++j)
        {
            if(i == j)
            {
                XTESTS_TEST_INTEGER_EQUAL(i, j);
                XTESTS_TEST_INTEGER_EQUAL_EXACT(i, j);

                XTESTS_TEST_INTEGER_LESS_OR_EQUAL(j, i);
                XTESTS_TEST_INTEGER_GREATER_OR_EQUAL(j, i);
            }
            else
            {
                XTESTS_TEST_INTEGER_NOT_EQUAL(i, j);

                if(i < j)
                {
                    XTESTS_TEST_INTEGER_LESS(j, i);
                    XTESTS_TEST_INTEGER_LESS_OR_EQUAL(j, i);
                }
                else
                {
                    XTESTS_TEST_INTEGER_GREATER(j, i);
                    XTESTS_TEST_INTEGER_GREATER_OR_EQUAL(j, i);
                }
            }
        }}
    }}
}

/* //////////////////////////// end of file ///////////////////////////// */

xTests Library documentation Matthew Wilson and Synesis Software Pty Ltd, 1999-2009 SourceForge.net Logo