|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <ztest.h> |
| 18 | +#include <misc/util.h> |
| 19 | + |
| 20 | +#define TEST_DEFINE_1 1 |
| 21 | +#define TEST_DEFINE_0 0 |
| 22 | + |
| 23 | +void test_COND_CODE_1(void) |
| 24 | +{ |
| 25 | + /* Test validates that expected code has been injected. Failure would |
| 26 | + * be seen in compilation (lack of variable or ununsed variable. |
| 27 | + */ |
| 28 | + COND_CODE_1(1, (u32_t x0 = 1;), (u32_t y0;)) |
| 29 | + zassert_true((x0 == 1), NULL); |
| 30 | + |
| 31 | + COND_CODE_1(NOT_EXISTING_DEFINE, (u32_t x1 = 1;), (u32_t y1 = 1;)) |
| 32 | + zassert_true((y1 == 1), NULL); |
| 33 | + |
| 34 | + COND_CODE_1(TEST_DEFINE_1, (u32_t x2 = 1;), (u32_t y2 = 1;)) |
| 35 | + zassert_true((x2 == 1), NULL); |
| 36 | + |
| 37 | + COND_CODE_1(2, (u32_t x3 = 1;), (u32_t y3 = 1;)) |
| 38 | + zassert_true((y3 == 1), NULL); |
| 39 | +} |
| 40 | + |
| 41 | +void test_COND_CODE_0(void) |
| 42 | +{ |
| 43 | + /* Test validates that expected code has been injected. Failure would |
| 44 | + * be seen in compilation (lack of variable or ununsed variable. |
| 45 | + */ |
| 46 | + COND_CODE_0(0, (u32_t x0 = 1;), (u32_t y0;)) |
| 47 | + zassert_true((x0 == 1), NULL); |
| 48 | + |
| 49 | + COND_CODE_0(NOT_EXISTING_DEFINE, (u32_t x1 = 1;), (u32_t y1 = 1;)) |
| 50 | + zassert_true((y1 == 1), NULL); |
| 51 | + |
| 52 | + COND_CODE_0(TEST_DEFINE_0, (u32_t x2 = 1;), (u32_t y2 = 1;)) |
| 53 | + zassert_true((x2 == 1), NULL); |
| 54 | + |
| 55 | + COND_CODE_0(2, (u32_t x3 = 1;), (u32_t y3 = 1;)) |
| 56 | + zassert_true((y3 == 1), NULL); |
| 57 | +} |
| 58 | + |
| 59 | +/*test case main entry*/ |
| 60 | +void test_main(void) |
| 61 | +{ |
| 62 | + ztest_test_suite(test_ringbuffer_api, |
| 63 | + ztest_unit_test(test_COND_CODE_1), |
| 64 | + ztest_unit_test(test_COND_CODE_0) |
| 65 | + ); |
| 66 | + ztest_run_test_suite(test_ringbuffer_api); |
| 67 | +} |
0 commit comments