Rizky Ardi Maulana / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utest_specification.h Source File

utest_specification.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_SPECIFICATION_H
00020 #define UTEST_SPECIFICATION_H
00021 
00022 #include <stdint.h>
00023 #include <stdbool.h>
00024 #include <stdio.h>
00025 #include "utest/utest_types.h"
00026 #include "utest/utest_case.h"
00027 #include "utest/utest_default_handlers.h"
00028 
00029 
00030 namespace utest {
00031 /** \addtogroup frameworks */
00032 /** @{*/
00033 namespace v1 {
00034 
00035     /** Test specification containing the setup and teardown handlers and test cases.
00036      *
00037      * This class simply holds the test cases and allows you to specify default handlers, and
00038      * override setup and teardown handlers.
00039      * The order of arguments is:
00040      *  - test setup handler (optional)
00041      *  - array of test cases (required)
00042      *  - test teardown handler (optional)
00043      *  - default handlers (optional)
00044      *
00045      * @note You cannot set the size of the test case array dynamically, it is template deducted at compile
00046      *       time. Creating test specifications for unittests at runtime is explicitly not supported.
00047      */
00048     class Specification
00049     {
00050     public:
00051         template< size_t N >
00052         Specification(const Case (&cases)[N],
00053                       const handlers_t defaults = default_handlers) :
00054             setup_handler(default_handler), teardown_handler(default_handler), failure_handler(default_handler),
00055             cases(cases), length(N),
00056             defaults(defaults)
00057         {}
00058 
00059         template< size_t N >
00060         Specification(const Case (&cases)[N],
00061                       const test_failure_handler_t failure_handler,
00062                       const handlers_t defaults = default_handlers) :
00063             setup_handler(default_handler), teardown_handler(default_handler), failure_handler(failure_handler),
00064             cases(cases), length(N),
00065             defaults(defaults)
00066         {}
00067 
00068         template< size_t N >
00069         Specification(const Case (&cases)[N],
00070                       const test_teardown_handler_t teardown_handler,
00071                       const handlers_t defaults = default_handlers) :
00072             setup_handler(default_handler), teardown_handler(teardown_handler), failure_handler(default_handler),
00073             cases(cases), length(N),
00074             defaults(defaults)
00075         {}
00076 
00077         template< size_t N >
00078         Specification(const Case (&cases)[N],
00079                       const test_teardown_handler_t teardown_handler,
00080                       const test_failure_handler_t failure_handler,
00081                       const handlers_t defaults = default_handlers) :
00082             setup_handler(default_handler), teardown_handler(teardown_handler), failure_handler(failure_handler),
00083             cases(cases), length(N),
00084             defaults(defaults)
00085         {}
00086 
00087         template< size_t N >
00088         Specification(const test_setup_handler_t setup_handler,
00089                       const Case (&cases)[N],
00090                       const handlers_t defaults = default_handlers) :
00091             setup_handler(setup_handler), teardown_handler(default_handler), failure_handler(default_handler),
00092             cases(cases), length(N),
00093             defaults(defaults)
00094         {}
00095 
00096         template< size_t N >
00097         Specification(const test_setup_handler_t setup_handler,
00098                       const Case (&cases)[N],
00099                       const test_failure_handler_t failure_handler,
00100                       const handlers_t defaults = default_handlers) :
00101             setup_handler(setup_handler), teardown_handler(default_handler), failure_handler(failure_handler),
00102             cases(cases), length(N),
00103             defaults(defaults)
00104         {}
00105 
00106         template< size_t N >
00107         Specification(const test_setup_handler_t setup_handler,
00108                       const Case (&cases)[N],
00109                       const test_teardown_handler_t teardown_handler,
00110                       const handlers_t defaults = default_handlers) :
00111             setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(default_handler),
00112             cases(cases), length(N),
00113             defaults(defaults)
00114         {}
00115 
00116         template< size_t N >
00117         Specification(const test_setup_handler_t setup_handler,
00118                       const Case (&cases)[N],
00119                       const test_teardown_handler_t teardown_handler,
00120                       const test_failure_handler_t failure_handler,
00121                       const handlers_t defaults = default_handlers) :
00122             setup_handler(setup_handler), teardown_handler(teardown_handler), failure_handler(failure_handler),
00123             cases(cases), length(N),
00124             defaults(defaults)
00125         {}
00126 
00127     private:
00128         const test_setup_handler_t setup_handler;
00129         const test_teardown_handler_t teardown_handler;
00130         const test_failure_handler_t failure_handler;
00131         const Case *const cases;
00132         const size_t length;
00133         const handlers_t defaults;
00134 
00135         friend class Harness;
00136     };
00137 
00138 }   // namespace v1
00139 }   // namespace utest
00140 
00141  #endif // UTEST_SPECIFICATION_H
00142 
00143 /** @}*/