Blame tests/dane-strcodes.c

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2017 Red Hat
Packit 549fdc
 *
Packit 549fdc
 * Author: Nikos Mavrogiannopoulos
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * GnuTLS is free software; you can redistribute it and/or modify it
Packit 549fdc
 * under the terms of the GNU General Public License as published by
Packit 549fdc
 * the Free Software Foundation; either version 3 of the License, or
Packit 549fdc
 * (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * GnuTLS is distributed in the hope that it will be useful, but
Packit 549fdc
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 549fdc
 * General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU General Public License
Packit 549fdc
 * along with GnuTLS; if not, write to the Free Software Foundation,
Packit 549fdc
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#ifdef HAVE_CONFIG_H
Packit 549fdc
#include <config.h>
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
#include <stdlib.h>
Packit 549fdc
#include <stdio.h>
Packit 549fdc
#include <string.h>
Packit 549fdc
#include <gnutls/gnutls.h>
Packit 549fdc
#include <gnutls/dane.h>
Packit 549fdc
Packit 549fdc
#include "utils.h"
Packit 549fdc
Packit 549fdc
/* Check whether the DANE string functions will return a non-repeated and
Packit 549fdc
 * non null value.
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
static
Packit 549fdc
void _check_unique_non_null(int line, int i, const char *val)
Packit 549fdc
{
Packit 549fdc
	static char previous_val[128];
Packit 549fdc
Packit 549fdc
	if (val == NULL)
Packit 549fdc
		fail("issue in line %d, item %d\n", line, i);
Packit 549fdc
Packit 549fdc
	if (strcmp(val, previous_val)==0) {
Packit 549fdc
		fail("issue in line %d, item %d: %s\n", line, i, val);
Packit 549fdc
	} 
Packit 549fdc
Packit 549fdc
	snprintf(previous_val, sizeof(previous_val), "%s", val);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
#define check_unique_non_null(x) _check_unique_non_null(__LINE__, i, x)
Packit 549fdc
Packit 549fdc
void doit(void)
Packit 549fdc
{
Packit 549fdc
	int ret;
Packit 549fdc
	int i;
Packit 549fdc
Packit 549fdc
	ret = global_init();
Packit 549fdc
	if (ret < 0) {
Packit 549fdc
		fail("global_init\n");
Packit 549fdc
		exit(1);
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	for (i=0;i<4;i++)
Packit 549fdc
		check_unique_non_null(dane_cert_usage_name(i));
Packit 549fdc
Packit 549fdc
	for (i=0;i<1;i++)
Packit 549fdc
		check_unique_non_null(dane_cert_type_name(i));
Packit 549fdc
Packit 549fdc
	for (i=0;i<3;i++)
Packit 549fdc
		check_unique_non_null(dane_match_type_name(i));
Packit 549fdc
Packit 549fdc
	for (i=-14;i<=0;i++) {
Packit 549fdc
		check_unique_non_null(dane_strerror(i));
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	gnutls_global_deinit();
Packit 549fdc
}