1/* $NetBSD: cmocka.h,v 1.3 2022/09/23 12:15:33 christos Exp $ */ 2 3/* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16/*! \file isc/cmocka.h */ 17 18#pragma once 19 20#include <cmocka.h> 21 22#include <isc/lang.h> 23 24ISC_LANG_BEGINDECLS 25 26/* 27 * Copy the test identified by 'name' from 'tests' to 'selected'. 28 */ 29#define cmocka_add_test_byname(tests, name, selected) \ 30 _cmocka_add_test_byname(tests, sizeof(tests) / sizeof(tests[0]), name, \ 31 selected, \ 32 sizeof(selected) / sizeof(selected[0])) 33 34static inline bool 35_cmocka_add_test_byname(const struct CMUnitTest *tests, size_t ntests, 36 const char *name, struct CMUnitTest *selected, 37 size_t nselected) { 38 size_t i, j; 39 40 for (i = 0; i < ntests && tests[i].name != NULL; i++) { 41 if (strcmp(tests[i].name, name) != 0) { 42 continue; 43 } 44 for (j = 0; j < nselected && selected[j].name != NULL; j++) { 45 if (strcmp(tests[j].name, name) == 0) { 46 break; 47 } 48 } 49 if (j < nselected && selected[j].name == NULL) { 50 selected[j] = tests[i]; 51 } 52 return (true); 53 } 54 return (false); 55} 56 57ISC_LANG_ENDDECLS 58