2013-11-11 10:49:28 +11:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2013-11-11 10:49:28 +11:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2013-11-11 10:49:28 +11:00
|
|
|
*/
|
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-10-23 22:33:45 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2013-11-11 10:49:28 +11:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2013-11-11 10:49:28 +11:00
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/lex.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2019-11-09 14:01:08 +01:00
|
|
|
#include "isctest.h"
|
|
|
|
|
2020-08-04 00:16:50 +10:00
|
|
|
#define AS_STR(x) (x).value.as_textregion.base
|
|
|
|
|
2020-08-01 01:25:37 +10:00
|
|
|
static bool debug = false;
|
|
|
|
|
2019-11-09 14:01:08 +01:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2019-11-09 14:01:08 +01:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = isc_test_begin(NULL, true, 0);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2019-11-09 14:01:08 +01:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
isc_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
/* check handling of 0xff */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
lex_0xff(void **state) {
|
2013-11-11 10:49:28 +11:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_lex_t *lex = NULL;
|
2013-11-11 10:49:28 +11:00
|
|
|
isc_buffer_t death_buf;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_token_t token;
|
2013-11-11 10:49:28 +11:00
|
|
|
|
|
|
|
unsigned char death[] = { EOF, 'A' };
|
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
UNUSED(state);
|
2013-11-11 10:49:28 +11:00
|
|
|
|
2019-11-09 14:01:08 +01:00
|
|
|
result = isc_lex_create(test_mctx, 1024, &lex);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-11-11 10:49:28 +11:00
|
|
|
|
|
|
|
isc_buffer_init(&death_buf, &death[0], sizeof(death));
|
|
|
|
isc_buffer_add(&death_buf, sizeof(death));
|
|
|
|
|
|
|
|
result = isc_lex_openbuffer(lex, &death_buf);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2013-11-11 10:49:28 +11:00
|
|
|
|
|
|
|
result = isc_lex_gettoken(lex, 0, &token);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2018-11-19 07:47:05 +01:00
|
|
|
|
|
|
|
isc_lex_destroy(&lex);
|
2013-11-11 10:49:28 +11:00
|
|
|
}
|
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
/* check setting of source line */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
lex_setline(void **state) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_lex_t *lex = NULL;
|
2016-08-25 18:08:26 -07:00
|
|
|
unsigned char text[] = "text\nto\nbe\nprocessed\nby\nlexer";
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_buffer_t buf;
|
|
|
|
isc_token_t token;
|
2016-08-25 18:08:26 -07:00
|
|
|
unsigned long line;
|
2020-02-13 14:44:37 -08:00
|
|
|
int i;
|
2016-08-25 18:08:26 -07:00
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
UNUSED(state);
|
2016-08-25 18:08:26 -07:00
|
|
|
|
2019-11-09 14:01:08 +01:00
|
|
|
result = isc_lex_create(test_mctx, 1024, &lex);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-08-25 18:08:26 -07:00
|
|
|
|
|
|
|
isc_buffer_init(&buf, &text[0], sizeof(text));
|
|
|
|
isc_buffer_add(&buf, sizeof(text));
|
|
|
|
|
|
|
|
result = isc_lex_openbuffer(lex, &buf);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-08-25 18:08:26 -07:00
|
|
|
|
|
|
|
result = isc_lex_setsourceline(lex, 100);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-08-25 18:08:26 -07:00
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
result = isc_lex_gettoken(lex, 0, &token);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2016-08-25 18:08:26 -07:00
|
|
|
|
|
|
|
line = isc_lex_getsourceline(lex);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(line, 100U + i);
|
2016-08-25 18:08:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
result = isc_lex_gettoken(lex, 0, &token);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(result, ISC_R_EOF);
|
2016-08-25 18:08:26 -07:00
|
|
|
|
|
|
|
line = isc_lex_getsourceline(lex);
|
2018-10-23 22:33:45 -07:00
|
|
|
assert_int_equal(line, 105U);
|
2018-11-19 07:47:05 +01:00
|
|
|
|
|
|
|
isc_lex_destroy(&lex);
|
2016-08-25 18:08:26 -07:00
|
|
|
}
|
|
|
|
|
2020-08-04 00:16:50 +10:00
|
|
|
static struct {
|
|
|
|
const char *text;
|
|
|
|
const char *string_value;
|
|
|
|
isc_result_t string_result;
|
|
|
|
isc_tokentype_t string_type;
|
|
|
|
const char *qstring_value;
|
|
|
|
isc_result_t qstring_result;
|
|
|
|
isc_tokentype_t qstring_type;
|
|
|
|
const char *qvpair_value;
|
|
|
|
isc_result_t qvpair_result;
|
|
|
|
isc_tokentype_t qvpair_type;
|
|
|
|
} parse_tests[] = {
|
|
|
|
{ "", "", ISC_R_SUCCESS, isc_tokentype_eof, "", ISC_R_SUCCESS,
|
|
|
|
isc_tokentype_eof, "", ISC_R_SUCCESS, isc_tokentype_eof },
|
|
|
|
{ "1234", "1234", ISC_R_SUCCESS, isc_tokentype_string, "1234",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_string, "1234", ISC_R_SUCCESS,
|
|
|
|
isc_tokentype_string },
|
|
|
|
{ "1234=", "1234=", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"1234=", ISC_R_SUCCESS, isc_tokentype_string, "1234=", ISC_R_SUCCESS,
|
|
|
|
isc_tokentype_vpair },
|
|
|
|
{ "1234=foo", "1234=foo", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"1234=foo", ISC_R_SUCCESS, isc_tokentype_string, "1234=foo",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_vpair },
|
|
|
|
{ "1234=\"foo", "1234=\"foo", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"1234=\"foo", ISC_R_SUCCESS, isc_tokentype_string, NULL,
|
|
|
|
ISC_R_UNEXPECTEDEND, 0 },
|
|
|
|
{ "1234=\"foo\"", "1234=\"foo\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"1234=\"foo\"", ISC_R_SUCCESS, isc_tokentype_string, "1234=foo",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_qvpair },
|
|
|
|
{ "key", "key", ISC_R_SUCCESS, isc_tokentype_string, "key",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_string, "key", ISC_R_SUCCESS,
|
|
|
|
isc_tokentype_string },
|
|
|
|
{ "\"key=", "\"key=", ISC_R_SUCCESS, isc_tokentype_string, NULL,
|
|
|
|
ISC_R_UNEXPECTEDEND, 0, "\"key=", ISC_R_SUCCESS,
|
|
|
|
isc_tokentype_vpair },
|
|
|
|
{ "\"key=\"", "\"key=\"", ISC_R_SUCCESS, isc_tokentype_string, "key=",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_qstring, NULL, ISC_R_UNEXPECTEDEND, 0 },
|
|
|
|
{ "key=\"\"", "key=\"\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=\"\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=", ISC_R_SUCCESS, isc_tokentype_qvpair },
|
|
|
|
{ "key=\"a b\"", "key=\"a", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=\"a", ISC_R_SUCCESS, isc_tokentype_string, "key=a b",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_qvpair },
|
|
|
|
{ "key=\"a\tb\"", "key=\"a", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=\"a", ISC_R_SUCCESS, isc_tokentype_string, "key=a\tb",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_qvpair },
|
|
|
|
/* double quote not immediately after '=' is not special. */
|
|
|
|
{ "key=c\"a b\"", "key=c\"a", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=c\"a", ISC_R_SUCCESS, isc_tokentype_string, "key=c\"a",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_vpair },
|
|
|
|
/* remove special meaning for '=' by escaping */
|
|
|
|
{ "key\\=", "key\\=", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\=", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\=", ISC_R_SUCCESS, isc_tokentype_string },
|
|
|
|
{ "key\\=\"a\"", "key\\=\"a\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\=\"a\"", ISC_R_SUCCESS, isc_tokentype_string, "key\\=\"a\"",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_string },
|
|
|
|
{ "key\\=\"a \"", "key\\=\"a", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\=\"a", ISC_R_SUCCESS, isc_tokentype_string, "key\\=\"a",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_string },
|
|
|
|
/* vpair with a key of 'key\=' (would need to be deescaped) */
|
|
|
|
{ "key\\==", "key\\==", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\==", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\==", ISC_R_SUCCESS, isc_tokentype_vpair },
|
|
|
|
{ "key\\==\"\"", "key\\==\"\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\==\"\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key\\==", ISC_R_SUCCESS, isc_tokentype_qvpair },
|
|
|
|
{ "key=\\\\\\\\", "key=\\\\\\\\", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=\\\\\\\\", ISC_R_SUCCESS, isc_tokentype_string, "key=\\\\\\\\",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_vpair },
|
|
|
|
{ "key=\\\\\\\"", "key=\\\\\\\"", ISC_R_SUCCESS, isc_tokentype_string,
|
|
|
|
"key=\\\\\\\"", ISC_R_SUCCESS, isc_tokentype_string, "key=\\\\\\\"",
|
|
|
|
ISC_R_SUCCESS, isc_tokentype_vpair },
|
|
|
|
/* incomplete escape sequence */
|
|
|
|
{ "key=\\\"\\", NULL, ISC_R_UNEXPECTEDEND, isc_tokentype_string, NULL,
|
|
|
|
ISC_R_UNEXPECTEDEND, 0, NULL, ISC_R_UNEXPECTEDEND, 0 },
|
|
|
|
/* incomplete escape sequence */
|
|
|
|
{ "key=\\", NULL, ISC_R_UNEXPECTEDEND, isc_tokentype_string, NULL,
|
|
|
|
ISC_R_UNEXPECTEDEND, 0, NULL, ISC_R_UNEXPECTEDEND, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/*%
|
|
|
|
* string
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
lex_string(void **state) {
|
|
|
|
isc_buffer_t buf;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_token_t token;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
|
|
|
|
result = isc_lex_create(test_mctx, 1024, &lex);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
isc_buffer_constinit(&buf, parse_tests[i].text,
|
|
|
|
strlen(parse_tests[i].text));
|
|
|
|
isc_buffer_add(&buf, strlen(parse_tests[i].text));
|
|
|
|
|
|
|
|
result = isc_lex_openbuffer(lex, &buf);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = isc_lex_setsourceline(lex, 100);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
memset(&token, 0, sizeof(token));
|
|
|
|
result = isc_lex_getmastertoken(lex, &token,
|
|
|
|
isc_tokentype_string, true);
|
|
|
|
if (debug) {
|
2021-08-19 10:19:32 +10:00
|
|
|
fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n",
|
2020-08-04 00:16:50 +10:00
|
|
|
parse_tests[i].text, isc_result_toid(result),
|
|
|
|
isc_result_toid(parse_tests[i].string_result),
|
|
|
|
token.type, parse_tests[i].string_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_int_equal(result, parse_tests[i].string_result);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
switch (token.type) {
|
|
|
|
case isc_tokentype_string:
|
|
|
|
case isc_tokentype_qstring:
|
|
|
|
case isc_tokentype_vpair:
|
|
|
|
case isc_tokentype_qvpair:
|
|
|
|
if (debug) {
|
|
|
|
fprintf(stdout, "# value='%s'\n",
|
|
|
|
AS_STR(token));
|
|
|
|
}
|
|
|
|
assert_int_equal(token.type,
|
|
|
|
parse_tests[i].string_type);
|
|
|
|
assert_string_equal(
|
|
|
|
AS_STR(token),
|
|
|
|
parse_tests[i].string_value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert_int_equal(token.type,
|
|
|
|
parse_tests[i].string_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*%
|
|
|
|
* qstring
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
lex_qstring(void **state) {
|
|
|
|
isc_buffer_t buf;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_token_t token;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
|
|
|
|
result = isc_lex_create(test_mctx, 1024, &lex);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
isc_buffer_constinit(&buf, parse_tests[i].text,
|
|
|
|
strlen(parse_tests[i].text));
|
|
|
|
isc_buffer_add(&buf, strlen(parse_tests[i].text));
|
|
|
|
|
|
|
|
result = isc_lex_openbuffer(lex, &buf);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = isc_lex_setsourceline(lex, 100);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
memset(&token, 0, sizeof(token));
|
|
|
|
result = isc_lex_getmastertoken(lex, &token,
|
|
|
|
isc_tokentype_qstring, true);
|
|
|
|
if (debug) {
|
2021-08-19 10:19:32 +10:00
|
|
|
fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n",
|
2020-08-04 00:16:50 +10:00
|
|
|
parse_tests[i].text, isc_result_toid(result),
|
|
|
|
isc_result_toid(parse_tests[i].qstring_result),
|
|
|
|
token.type, parse_tests[i].qstring_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_int_equal(result, parse_tests[i].qstring_result);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
switch (token.type) {
|
|
|
|
case isc_tokentype_string:
|
|
|
|
case isc_tokentype_qstring:
|
|
|
|
case isc_tokentype_vpair:
|
|
|
|
case isc_tokentype_qvpair:
|
|
|
|
if (debug) {
|
|
|
|
fprintf(stdout, "# value='%s'\n",
|
|
|
|
AS_STR(token));
|
|
|
|
}
|
|
|
|
assert_int_equal(token.type,
|
|
|
|
parse_tests[i].qstring_type);
|
|
|
|
assert_string_equal(
|
|
|
|
AS_STR(token),
|
|
|
|
parse_tests[i].qstring_value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert_int_equal(token.type,
|
|
|
|
parse_tests[i].qstring_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-01 01:25:37 +10:00
|
|
|
/*%
|
|
|
|
* keypair is <string>=<qstring>. This has implications double quotes
|
|
|
|
* in key names.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
lex_keypair(void **state) {
|
|
|
|
isc_buffer_t buf;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_token_t token;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
UNUSED(state);
|
|
|
|
|
2020-08-04 00:16:50 +10:00
|
|
|
for (i = 0; i < ARRAY_SIZE(parse_tests); i++) {
|
2020-08-01 01:25:37 +10:00
|
|
|
result = isc_lex_create(test_mctx, 1024, &lex);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2020-08-04 00:16:50 +10:00
|
|
|
isc_buffer_constinit(&buf, parse_tests[i].text,
|
|
|
|
strlen(parse_tests[i].text));
|
|
|
|
isc_buffer_add(&buf, strlen(parse_tests[i].text));
|
2020-08-01 01:25:37 +10:00
|
|
|
|
|
|
|
result = isc_lex_openbuffer(lex, &buf);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
result = isc_lex_setsourceline(lex, 100);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
memset(&token, 0, sizeof(token));
|
|
|
|
result = isc_lex_getmastertoken(lex, &token,
|
|
|
|
isc_tokentype_qvpair, true);
|
|
|
|
if (debug) {
|
2021-08-19 10:19:32 +10:00
|
|
|
fprintf(stdout, "# '%s' -> result=%s/%s, type=%d/%d\n",
|
2020-08-04 00:16:50 +10:00
|
|
|
parse_tests[i].text, isc_result_toid(result),
|
|
|
|
isc_result_toid(parse_tests[i].qvpair_result),
|
|
|
|
token.type, parse_tests[i].qvpair_type);
|
2020-08-01 01:25:37 +10:00
|
|
|
}
|
|
|
|
|
2020-08-04 00:16:50 +10:00
|
|
|
assert_int_equal(result, parse_tests[i].qvpair_result);
|
2020-08-01 01:25:37 +10:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
switch (token.type) {
|
|
|
|
case isc_tokentype_string:
|
|
|
|
case isc_tokentype_qstring:
|
|
|
|
case isc_tokentype_vpair:
|
|
|
|
case isc_tokentype_qvpair:
|
|
|
|
if (debug) {
|
|
|
|
fprintf(stdout, "# value='%s'\n",
|
|
|
|
AS_STR(token));
|
|
|
|
}
|
2020-08-04 00:16:50 +10:00
|
|
|
assert_int_equal(token.type,
|
|
|
|
parse_tests[i].qvpair_type);
|
|
|
|
assert_string_equal(
|
|
|
|
AS_STR(token),
|
|
|
|
parse_tests[i].qvpair_value);
|
2020-08-01 01:25:37 +10:00
|
|
|
break;
|
|
|
|
default:
|
2020-08-04 00:16:50 +10:00
|
|
|
assert_int_equal(token.type,
|
|
|
|
parse_tests[i].qvpair_type);
|
2020-08-01 01:25:37 +10:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 22:33:45 -07:00
|
|
|
int
|
2020-08-01 01:25:37 +10:00
|
|
|
main(int argc, char *argv[]) {
|
2018-10-23 22:33:45 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
2020-08-04 00:16:50 +10:00
|
|
|
cmocka_unit_test(lex_0xff), cmocka_unit_test(lex_keypair),
|
|
|
|
cmocka_unit_test(lex_setline), cmocka_unit_test(lex_string),
|
|
|
|
cmocka_unit_test(lex_qstring),
|
2018-10-23 22:33:45 -07:00
|
|
|
};
|
|
|
|
|
2020-08-01 01:25:37 +10:00
|
|
|
UNUSED(argv);
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
debug = true;
|
|
|
|
}
|
|
|
|
|
2019-11-09 14:01:08 +01:00
|
|
|
return (cmocka_run_group_tests(tests, _setup, _teardown));
|
2018-10-23 22:33:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-23 22:33:45 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
2021-01-18 19:15:44 +01:00
|
|
|
return (SKIPPED_TEST_EXIT_CODE);
|
2013-11-11 10:49:28 +11:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|