2021-10-20 22:28:34 +02:00
|
|
|
/*
|
|
|
|
* boxes - Command line filter to draw/remove ASCII boxes around text
|
2023-03-26 21:32:08 +02:00
|
|
|
* Copyright (c) 1999-2023 Thomas Jensen and the boxes contributors
|
2021-10-20 22:28:34 +02:00
|
|
|
*
|
2022-09-18 14:56:30 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License, version 3, as published by the Free Software Foundation.
|
|
|
|
* This program 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 General Public License for more
|
|
|
|
* details.
|
|
|
|
* You should have received a copy of the GNU General Public License along with this program.
|
|
|
|
* If not, see <https://www.gnu.org/licenses/>.
|
2021-10-20 22:28:34 +02:00
|
|
|
*
|
2022-09-18 14:56:30 +02:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2021-10-20 22:28:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mocks of boxes' global variables.
|
|
|
|
*/
|
|
|
|
|
2021-10-28 09:01:14 +02:00
|
|
|
#include "config.h"
|
2023-05-01 21:41:02 +02:00
|
|
|
|
2021-10-28 09:01:14 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <uniconv.h>
|
2023-05-01 21:41:02 +02:00
|
|
|
|
2021-10-20 22:28:34 +02:00
|
|
|
#include "boxes.h"
|
2021-10-28 09:01:14 +02:00
|
|
|
#include "unicode.h"
|
|
|
|
#include "tools.h"
|
2023-05-01 21:41:02 +02:00
|
|
|
#include "global_mock.h"
|
|
|
|
|
|
|
|
|
2021-10-20 22:28:34 +02:00
|
|
|
|
|
|
|
design_t *designs = NULL;
|
|
|
|
|
|
|
|
int num_designs = 0;
|
|
|
|
|
|
|
|
opt_t opt;
|
|
|
|
|
|
|
|
input_t input;
|
2021-10-28 09:01:14 +02:00
|
|
|
|
2023-05-08 21:12:00 +02:00
|
|
|
int color_output_enabled = 1;
|
|
|
|
|
2021-10-28 09:01:14 +02:00
|
|
|
char **collect_out = NULL;
|
|
|
|
int collect_out_size = 0;
|
|
|
|
|
|
|
|
char **collect_err = NULL;
|
|
|
|
int collect_err_size = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void collect_reset()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < collect_out_size; i++) {
|
|
|
|
BFREE(collect_out[i]);
|
|
|
|
}
|
|
|
|
BFREE(collect_out);
|
|
|
|
|
|
|
|
for (int i = 0; i < collect_err_size; i++) {
|
|
|
|
BFREE(collect_err[i]);
|
|
|
|
}
|
|
|
|
BFREE(collect_err);
|
|
|
|
|
|
|
|
collect_out_size = 0;
|
|
|
|
collect_err_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-01 14:19:52 +01:00
|
|
|
* Mock of the `bx_fprintf()` function which records its output instead of printing it. Assumes that no output string
|
2022-09-17 16:02:42 +02:00
|
|
|
* of our test cases will be longer than 512 characters.
|
2021-11-01 14:19:52 +01:00
|
|
|
* @param stream `stdout` or `stderr`
|
|
|
|
* @param format the format string, followed by the arguments
|
2021-10-28 09:01:14 +02:00
|
|
|
*/
|
2021-11-01 14:19:52 +01:00
|
|
|
void __wrap_bx_fprintf(FILE *stream, const char *format, ...)
|
2021-10-28 09:01:14 +02:00
|
|
|
{
|
2021-11-01 14:19:52 +01:00
|
|
|
char **collect = stream == stdout ? collect_out : collect_err;
|
|
|
|
int collect_size = stream == stdout ? collect_out_size : collect_err_size;
|
2021-10-28 09:01:14 +02:00
|
|
|
collect = (char **) realloc(collect, ++collect_size * sizeof(char *));
|
|
|
|
|
|
|
|
char *s = (char *) malloc(512);
|
|
|
|
va_list va;
|
2021-11-01 14:19:52 +01:00
|
|
|
va_start(va, format);
|
|
|
|
vsprintf(s, format, va);
|
2021-10-28 09:01:14 +02:00
|
|
|
va_end(va);
|
|
|
|
collect[collect_size - 1] = s;
|
|
|
|
|
2021-11-01 14:19:52 +01:00
|
|
|
if (stream == stdout) {
|
2021-10-28 09:01:14 +02:00
|
|
|
collect_out = collect;
|
|
|
|
collect_out_size = collect_size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
collect_err = collect;
|
|
|
|
collect_err_size = collect_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setup_mocks()
|
|
|
|
{
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
encoding = check_encoding("UTF-8", locale_charset());
|
|
|
|
collect_reset();
|
2023-11-25 19:35:06 +01:00
|
|
|
set_bx_fprintf(__wrap_bx_fprintf);
|
2021-10-28 09:01:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void teardown()
|
|
|
|
{
|
|
|
|
collect_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*EOF*/ /* vim: set cindent sw=4: */
|