joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utest_default_handlers.h Source File

utest_default_handlers.h

00001 /****************************************************************************
00002  * Copyright (c) 2015, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  ****************************************************************************
00017  */
00018 
00019 #ifndef UTEST_DEFAULT_HANDLER_H
00020 #define UTEST_DEFAULT_HANDLER_H
00021 
00022 #include <stdint.h>
00023 #include <stdbool.h>
00024 #include <stdio.h>
00025 #include "utest/utest_types.h"
00026 
00027 
00028 namespace utest {
00029 namespace v1 {
00030 
00031     /** Default handler hint.
00032      *
00033      * Use this handler to indicate the you want the default handler to be called.
00034      * This type automatically casts itself into the appropriate handler type, when possible.
00035      * Use the constants to default a handler unambigously.
00036      */
00037     static const struct
00038     {
00039         operator test_setup_handler_t()    const { return test_setup_handler_t(1); }
00040         operator test_teardown_handler_t() const { return test_teardown_handler_t(1); }
00041         operator test_failure_handler_t()  const { return test_failure_handler_t(1); }
00042 
00043         operator case_setup_handler_t()    const { return case_setup_handler_t(1); }
00044         operator case_teardown_handler_t() const { return case_teardown_handler_t(1); }
00045         operator case_failure_handler_t()  const { return case_failure_handler_t(1); }
00046     } default_handler;
00047 
00048     /** Ignore handler hint.
00049      *
00050      * Use this handler to indicate the you want to ignore this handler and it will not be called.
00051      * This type automatically casts itself into the appropriate handler type, when possible.
00052      * Use the constants to ignore a handler unambigously.
00053      */
00054     static const struct
00055     {
00056         operator case_handler_t()            const { return case_handler_t(NULL); }
00057         operator case_control_handler_t()    const { return case_control_handler_t(NULL); }
00058         operator case_call_count_handler_t() const { return case_call_count_handler_t(NULL); }
00059 
00060         operator test_setup_handler_t()    const { return test_setup_handler_t(NULL); }
00061         operator test_teardown_handler_t() const { return test_teardown_handler_t(NULL); }
00062         operator test_failure_handler_t()  const { return test_failure_handler_t(NULL); }
00063 
00064         operator case_setup_handler_t()    const { return case_setup_handler_t(NULL); }
00065         operator case_teardown_handler_t() const { return case_teardown_handler_t(NULL); }
00066         operator case_failure_handler_t()  const { return case_failure_handler_t(NULL); }
00067     } ignore_handler;
00068 
00069     /** A table of handlers.
00070      *
00071      * This structure stores all modifyable handlers and provides accessors to
00072      * filter out the default handler.
00073      * So if this structure contains handlers, and you want to use these handlers
00074      * as a default backup, you can use the `get_handler` function to choose the right handler.
00075      *
00076      * Example:
00077      * @code
00078      * const handler_t defaults = { ... }; // your default handlers
00079      * // will return the handler in defaults.
00080      * test_setup_handler_t handler = defaults.get_handler(default_handler);
00081      * // you will still need to manually check the handler before executing it
00082      * if (handler != ignore_handler) handler(...);
00083      *
00084      * extern test_teardown_handler_t custom_handler(...);
00085      * // will return `custom_handler`
00086      * test_teardown_handler_t handler = defaults.get_handler(custom_handler);
00087      * // you will still need to manually check the handler before executing it
00088      * if (handler != ignore_handler) handler(...);
00089      * @endcode
00090      */
00091     struct handlers_t
00092     {
00093         test_setup_handler_t test_setup;
00094         test_teardown_handler_t test_teardown;
00095         test_failure_handler_t test_failure;
00096 
00097         case_setup_handler_t case_setup;
00098         case_teardown_handler_t case_teardown;
00099         case_failure_handler_t case_failure;
00100 
00101         inline test_setup_handler_t get_handler(test_setup_handler_t handler) const {
00102             if (handler == default_handler) return test_setup;
00103             return handler;
00104         }
00105         inline test_teardown_handler_t get_handler(test_teardown_handler_t handler) const {
00106             if (handler == default_handler) return test_teardown;
00107             return handler;
00108         }
00109         inline test_failure_handler_t get_handler(test_failure_handler_t handler) const {
00110             if (handler == default_handler) return test_failure;
00111             return handler;
00112         }
00113 
00114         inline case_setup_handler_t get_handler(case_setup_handler_t handler) const {
00115             if (handler == default_handler) return case_setup;
00116             return handler;
00117         }
00118         inline case_teardown_handler_t get_handler(case_teardown_handler_t handler) const {
00119             if (handler == default_handler) return case_teardown;
00120             return handler;
00121         }
00122         inline case_failure_handler_t get_handler(case_failure_handler_t handler) const {
00123             if (handler == default_handler) return case_failure;
00124             return handler;
00125         }
00126     };
00127 
00128     /// Prints the number of tests to run and continues.
00129     utest::v1::status_t verbose_test_setup_handler   (const size_t number_of_cases);
00130     /// Prints the number of tests that passed and failed with a reason if provided.
00131     void     verbose_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure);
00132     /// Prints the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` and then dies.
00133     void     verbose_test_failure_handler (const failure_t failure);
00134 
00135     /// Prints the index and description of the case being run and continues.
00136     utest::v1::status_t verbose_case_setup_handler   (const Case *const source, const size_t index_of_case);
00137     /// Prints the number of tests that passed and failed with a reason if provided within this case and continues.
00138     utest::v1::status_t verbose_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure);
00139     /// Prints the reason of the failure and continues, unless the teardown handler failed, for which it aborts.
00140     utest::v1::status_t verbose_case_failure_handler (const Case *const source, const failure_t reason);
00141 
00142     /// Default greentea test case set up handler
00143     #define UTEST_DEFAULT_GREENTEA_TIMEOUT  10  //Seconds
00144     #define UTEST_DEFAULT_HOST_TEST_NAME    "default_auto"
00145 
00146     utest::v1::status_t default_greentea_test_setup_handler   (const size_t number_of_cases);
00147 
00148     /// Requests the start test case from greentea and continues.
00149     /// Example usage:
00150     /// utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
00151     ///    GREENTEA_SETUP(5, "default_auto");
00152     ///    return greentea_test_setup_handler(number_of_cases);
00153     /// }
00154     ///
00155     /// Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
00156     utest::v1::status_t greentea_test_setup_handler   (const size_t number_of_cases);
00157 
00158     /// Reports the test results to greentea.
00159     void     greentea_test_teardown_handler(const size_t passed, const size_t failed, const failure_t failure);
00160     /// Reports the failure for `REASON_TEST_SETUP` and `REASON_TEST_TEARDOWN` to greentea and then dies.
00161     void     greentea_test_failure_handler (const failure_t failure);
00162 
00163     /// Registers the test case setup with greentea.
00164     utest::v1::status_t greentea_case_setup_handler   (const Case *const source, const size_t index_of_case);
00165     /// Registers the test case teardown with greentea.
00166     utest::v1::status_t greentea_case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t failure);
00167     /// Reports the failure to greentea and then aborts.
00168     utest::v1::status_t greentea_case_failure_abort_handler   (const Case *const source, const failure_t reason);
00169     /// Reports the failure to greentea and then continues.
00170     utest::v1::status_t greentea_case_failure_continue_handler(const Case *const source, const failure_t reason);
00171 
00172     /// Notify greentea of testcase name.
00173     void greentea_testcase_notification_handler(const char *testcase);
00174 
00175     /// The verbose default handlers that always continue on failure
00176     extern const handlers_t verbose_continue_handlers;
00177 
00178     /// The greentea default handlers that always abort on the first encountered failure
00179     extern const handlers_t greentea_abort_handlers;
00180 
00181     /// The greentea default handlers that always continue on failure
00182     extern const handlers_t greentea_continue_handlers;
00183 
00184     /// The selftest default handlers that always abort on _any_ assertion failure, otherwise continue
00185     extern const handlers_t selftest_handlers;
00186 
00187     /// The greentea aborting handlers are the default
00188     extern const handlers_t& default_handlers;
00189 
00190 }   // namespace v1
00191 }   // namespace utest
00192 
00193 #endif // UTEST_DEFAULT_HANDLER_H