Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:35

0001 #include <rtems/test.h>
0002 
0003 T_TEST_CASE(assert)
0004 {
0005     T_assert_true(true, "nix");
0006     T_assert_true(false, "test fails and we stop the test case");
0007     T_log(T_QUIET, "not reached");
0008 }
0009 
0010 static int counter;
0011 
0012 static void
0013 setup(void *ctx)
0014 {
0015     int *c;
0016 
0017     T_log(T_QUIET, "setup");
0018     T_eq_ptr(ctx, &counter);
0019     c = ctx;
0020     *c = 0;
0021 }
0022 
0023 static void
0024 stop(void *ctx)
0025 {
0026     int *c;
0027 
0028     T_log(T_QUIET, "stop");
0029     T_eq_ptr(ctx, &counter);
0030     c = ctx;
0031     ++(*c);
0032 }
0033 
0034 static void
0035 teardown(void *ctx)
0036 {
0037     int *c;
0038 
0039     T_log(T_QUIET, "teardown");
0040     T_eq_ptr(ctx, &counter);
0041     c = ctx;
0042     T_eq_int(*c, 1);
0043 }
0044 
0045 static const T_fixture fixture = {
0046     .setup = setup,
0047     .stop = stop,
0048     .teardown = teardown,
0049     .initial_context = &counter
0050 };
0051 
0052 T_TEST_CASE_FIXTURE(assert2, &fixture)
0053 {
0054     T_assert_true(true, "nix");
0055     T_assert_true(false, "test fails and we stop the test case");
0056     T_log(T_QUIET, "not reached");
0057 }
0058 
0059 #include "t-self-test.h"
0060 
0061 T_TEST_OUTPUT(assert,
0062 "B:assert\n"
0063 "P:0:0:UI1:test-assert.c:5\n"
0064 "F:1:0:UI1:test-assert.c:6:test fails and we stop the test case\n"
0065 "E:assert:N:2:F:1:D:0.001000\n");
0066 
0067 T_TEST_OUTPUT(assert2,
0068 "B:assert2\n"
0069 "L:setup\n"
0070 "P:0:0:UI1:test-assert.c:18\n"
0071 "P:1:0:UI1:test-assert.c:54\n"
0072 "F:2:0:UI1:test-assert.c:55:test fails and we stop the test case\n"
0073 "L:stop\n"
0074 "P:3:0:UI1:test-assert.c:29\n"
0075 "L:teardown\n"
0076 "P:4:0:UI1:test-assert.c:40\n"
0077 "P:5:0:UI1:test-assert.c:42\n"
0078 "E:assert2:N:6:F:1:D:0.001000\n");
0079 
0080 /*
0081  * The license is at the end of the file to be able to use the test code and
0082  * output in examples in the documentation.  This is also the reason for the
0083  * dual licensing.  The license for RTEMS documentation is CC-BY-SA-4.0.
0084  */
0085 
0086 /*
0087  * SPDX-License-Identifier: BSD-2-Clause OR CC-BY-SA-4.0
0088  *
0089  * Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG
0090  *
0091  * Redistribution and use in source and binary forms, with or without
0092  * modification, are permitted provided that the following conditions
0093  * are met:
0094  * 1. Redistributions of source code must retain the above copyright
0095  *    notice, this list of conditions and the following disclaimer.
0096  * 2. Redistributions in binary form must reproduce the above copyright
0097  *    notice, this list of conditions and the following disclaimer in the
0098  *    documentation and/or other materials provided with the distribution.
0099  *
0100  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0101  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0102  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0103  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0104  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0105  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0106  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0107  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0108  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0109  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0110  * POSSIBILITY OF SUCH DAMAGE.
0111  *
0112  * ALTERNATIVELY, this software may be distributed under the terms of the
0113  * Creative Commons Attribution-ShareAlike 4.0 International Public License as
0114  * published by Creative Commons, PO Box 1866, Mountain View, CA 94042
0115  * (https://creativecommons.org/licenses/by-sa/4.0/legalcode).
0116  */