2008-08-19 19:30:36 +00:00
|
|
|
/* Authors: Christopher Ashworth <cashworth@tresys.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tresys Technology, LLC
|
2019-06-12 08:03:54 +00:00
|
|
|
* Copyright (C) 2019 Red Hat, Inc.
|
2008-08-19 19:30:36 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2019-06-12 08:03:54 +00:00
|
|
|
#ifndef __UTILITIES_H__
|
|
|
|
#define __UTILITIES_H__
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2019-06-12 08:03:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <fts.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <CUnit/Basic.h>
|
|
|
|
|
|
|
|
#include "semanage/semanage.h"
|
|
|
|
|
|
|
|
#define CU_ASSERT_CONTEXT_EQUAL(CON1,CON2) \
|
|
|
|
do { \
|
|
|
|
char *__str; \
|
|
|
|
char *__str2; \
|
|
|
|
CU_ASSERT(semanage_context_to_string(sh, CON1, &__str) >= 0); \
|
|
|
|
CU_ASSERT(semanage_context_to_string(sh, CON2, &__str2) >= 0); \
|
|
|
|
CU_ASSERT_STRING_EQUAL(__str, __str2); \
|
2021-10-19 15:11:23 +00:00
|
|
|
free(__str2); \
|
|
|
|
free(__str); \
|
2019-06-12 08:03:54 +00:00
|
|
|
} while (0)
|
|
|
|
|
2019-09-26 22:04:05 +00:00
|
|
|
|
|
|
|
/* Override CU_*_FATAL() in order to help static analyzers by really asserting that an assertion holds */
|
|
|
|
#ifdef __CHECKER__
|
|
|
|
|
|
|
|
#undef CU_ASSERT_FATAL
|
|
|
|
#define CU_ASSERT_FATAL(value) do { \
|
|
|
|
int _value = (value); \
|
|
|
|
CU_ASSERT(_value); \
|
|
|
|
assert(_value); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#undef CU_FAIL_FATAL
|
|
|
|
#define CU_FAIL_FATAL(msg) do { \
|
|
|
|
CU_FAIL(msg); \
|
|
|
|
assert(0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#undef CU_ASSERT_PTR_NOT_NULL_FATAL
|
|
|
|
#define CU_ASSERT_PTR_NOT_NULL_FATAL(value) do { \
|
|
|
|
const void *_value = (value); \
|
|
|
|
CU_ASSERT_PTR_NOT_NULL(_value); \
|
|
|
|
assert(_value != NULL); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#endif /* __CHECKER__ */
|
|
|
|
|
2019-06-12 08:03:54 +00:00
|
|
|
#define I_NULL -1
|
|
|
|
#define I_FIRST 0
|
|
|
|
#define I_SECOND 1
|
|
|
|
#define I_THIRD 2
|
|
|
|
|
|
|
|
typedef enum { SH_NULL, SH_HANDLE, SH_CONNECT, SH_TRANS } level_t;
|
|
|
|
|
|
|
|
void test_msg_handler(void *varg, semanage_handle_t *handle, const char *fmt,
|
2008-08-19 19:30:36 +00:00
|
|
|
...);
|
2019-06-12 08:03:54 +00:00
|
|
|
|
|
|
|
void setup_handle(level_t level);
|
|
|
|
void cleanup_handle(level_t level);
|
|
|
|
void setup_handle_invalid_store(level_t level);
|
|
|
|
|
|
|
|
void helper_handle_create(void);
|
|
|
|
void helper_handle_destroy(void);
|
|
|
|
void helper_connect(void);
|
|
|
|
void helper_disconnect(void);
|
|
|
|
void helper_begin_transaction(void);
|
|
|
|
void helper_commit(void);
|
|
|
|
|
|
|
|
int create_test_store(void);
|
|
|
|
int write_test_policy_from_file(const char *filename);
|
|
|
|
int write_test_policy_src(unsigned char *data, unsigned int data_len);
|
|
|
|
int destroy_test_store(void);
|
|
|
|
void enable_test_store(void);
|
|
|
|
void disable_test_store(void);
|
|
|
|
|
|
|
|
#endif
|