Splitting test to work with bonuses
This commit is contained in:
parent
01072e0ae6
commit
af6faffeb5
3 changed files with 187 additions and 23 deletions
14
Makefile
14
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2025/10/15 18:42:55 by lalgarra #+# #+# #
|
||||
# Updated: 2025/10/15 19:28:30 by lalgarra ### ########.fr #
|
||||
# Updated: 2025/10/18 16:30:09 by lalgarra ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -17,9 +17,11 @@ LIBDIR = ../repo_algarra
|
|||
#LIBDIR = ../vogsphere_repo
|
||||
|
||||
SOURCES = test_printf.c
|
||||
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
|
||||
SRCBONUS = test_printf_bonus.c
|
||||
OBJBONUS = $(SRCBONUS:.c=.o)
|
||||
|
||||
CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR) -O0
|
||||
|
||||
$(NAME): $(OBJECTS) $(LIBDIR)/libftprintf.a
|
||||
|
|
@ -28,16 +30,20 @@ $(NAME): $(OBJECTS) $(LIBDIR)/libftprintf.a
|
|||
$(LIBDIR)/libftprintf.a:
|
||||
$(MAKE) -C $(LIBDIR) all
|
||||
|
||||
bonus: $(OBJBONUS)
|
||||
$(MAKE) -C $(LIBDIR) fclean bonus
|
||||
$(CC) $(CFLAGS) $(OBJBONUS) -L$(LIBDIR) -lftprintf -o $@
|
||||
|
||||
.PHONY: clean fclean re
|
||||
|
||||
clean:
|
||||
#removes objects (.o)#
|
||||
rm -f $(OBJECTS)
|
||||
rm -f $(OBJECTS) $(OBJBONUS)
|
||||
$(MAKE) -C $(LIBDIR) clean
|
||||
|
||||
fclean: clean
|
||||
#removes objects (.o) and library#
|
||||
rm -f $(NAME)
|
||||
rm -f $(NAME) bonus
|
||||
$(MAKE) -C $(LIBDIR) fclean
|
||||
|
||||
all: $(NAME)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/15 18:54:32 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/17 21:04:44 by lalgarra ### ########.fr */
|
||||
/* Updated: 2025/10/18 16:22:08 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -112,23 +112,6 @@ static void test04()
|
|||
ft_printf("ret=%i\n", ret);
|
||||
}
|
||||
|
||||
static void test50()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
int ret;
|
||||
|
||||
strcpy(prefix, "test50: ");
|
||||
strcpy(sfmt, "%%#c: %#c; %%#s: %#s; %%#p: %#p; %%#d: %#d; %%#i: %#i; %%#u: %#u; %%#x: %#x; %%#X: %#X --eof; ");
|
||||
printf("%s printf(): ", prefix);
|
||||
ret = printf(sfmt, 'a', "Lorem ipsum", (void *)prefix, 125, -128, 325u, 0xfa, 0xfb);
|
||||
printf("ret=%i\n", ret);
|
||||
fflush(stdout);
|
||||
ft_printf("%sft_printf(): ", prefix);
|
||||
ret = ft_printf(sfmt, 'a', "Lorem ipsum", (void *)prefix, 125, -128, 325u, 0xfa, 0xfb);
|
||||
ft_printf("ret=%i\n", ret);
|
||||
}
|
||||
|
||||
static void test99()
|
||||
{
|
||||
char prefix[128];
|
||||
|
|
@ -152,7 +135,6 @@ int main(void)
|
|||
test02();
|
||||
test03();
|
||||
test04();
|
||||
test50();
|
||||
test99();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
176
test_printf_bonus.c
Normal file
176
test_printf_bonus.c
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_printf.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/15 18:54:32 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/18 16:07:28 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char *get_begin(void)
|
||||
{
|
||||
return "%s printf() output: [BEGIN]";
|
||||
}
|
||||
|
||||
static char *get_ftbegin(void)
|
||||
{
|
||||
return "%s ft_printf() output: [BEGIN]";
|
||||
}
|
||||
|
||||
static char *get_end(void)
|
||||
{
|
||||
return "[END]; returns: %i\n";
|
||||
}
|
||||
|
||||
static void call_printf(const char *prefix, const char *sfmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list args;
|
||||
|
||||
printf(get_begin(), prefix);
|
||||
printf("format string: \"%s\"\n", sfmt);
|
||||
printf(get_begin(), prefix);
|
||||
va_start(args, sfmt);
|
||||
ret = vprintf(sfmt, args);
|
||||
va_end(args);
|
||||
printf(get_end(), ret);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void test01()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
char arg1[128];
|
||||
int ret;
|
||||
|
||||
strcpy(prefix, "test01: ");
|
||||
strcpy(sfmt, "Hola %s Mundo");
|
||||
strcpy(arg1, "Es%sto es una \xfa prueba");
|
||||
call_printf(prefix, sfmt, arg1);
|
||||
printf(get_ftbegin(), prefix);
|
||||
fflush(stdout);
|
||||
ret = ft_printf(sfmt, arg1);
|
||||
printf(get_end(), ret);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void test_int(char *prefix, char *sfmt, int val)
|
||||
{
|
||||
int ret;
|
||||
|
||||
call_printf(prefix, sfmt, val);
|
||||
printf(get_ftbegin(), prefix);
|
||||
fflush(stdout);
|
||||
ret = ft_printf(sfmt, val);
|
||||
printf(get_end(), ret);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static void test02()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
|
||||
strcpy(prefix, "test02: ");
|
||||
strcpy(sfmt, "Entero con %%d: %d");
|
||||
test_int(prefix, sfmt, -325);
|
||||
}
|
||||
|
||||
static void test03()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
|
||||
strcpy(prefix, "test03: ");
|
||||
strcpy(sfmt, "Entero con %%i: %i");
|
||||
test_int(prefix, sfmt, 9123325);
|
||||
}
|
||||
|
||||
static void test04()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
int ret;
|
||||
|
||||
strcpy(prefix, "test04: ");
|
||||
strcpy(sfmt, "%%s: NULL %s NULL; %%p: %p %p --eof; ");
|
||||
printf("%s printf(): ", prefix);
|
||||
ret = printf(sfmt, NULL, 0, 0);
|
||||
printf("ret=%i\n", ret);
|
||||
fflush(stdout);
|
||||
ft_printf("%sft_printf(): ", prefix);
|
||||
ret = ft_printf(sfmt, NULL, 0, 0);
|
||||
ft_printf("ret=%i\n", ret);
|
||||
}
|
||||
|
||||
static void test05()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
int ret;
|
||||
|
||||
strcpy(prefix, "test05: ");
|
||||
strcpy(sfmt, "%%5x: %5x; %%-5X: %-5X; %%#-5x: %#-5x; %%#5X: %#5X--eof; ");
|
||||
printf("%s printf(): ", prefix);
|
||||
ret = printf(sfmt, 0xfafe, 0xab, 0xfafe, 0xab);
|
||||
printf("ret=%i\n", ret);
|
||||
fflush(stdout);
|
||||
ft_printf("%sft_printf(): ", prefix);
|
||||
ret = ft_printf(sfmt, 0xfafe, 0xab, 0xfafe, 0xab);
|
||||
ft_printf("ret=%i\n", ret);
|
||||
}
|
||||
|
||||
static void test50()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
int ret;
|
||||
|
||||
strcpy(prefix, "test50: ");
|
||||
strcpy(sfmt, "%%#c: %#c; %%#s: %#s; %%#p: %#p; %%#d: %#d; %%#i: %#i; %%#u: %#u; %%#x: %#x; %%#X: %#X --eof; ");
|
||||
printf("%s printf(): ", prefix);
|
||||
ret = printf(sfmt, 'a', "Lorem ipsum", (void *)prefix, 125, -128, 325u, 0xfa, 0xfb);
|
||||
printf("ret=%i\n", ret);
|
||||
fflush(stdout);
|
||||
ft_printf("%sft_printf(): ", prefix);
|
||||
ret = ft_printf(sfmt, 'a', "Lorem ipsum", (void *)prefix, 125, -128, 325u, 0xfa, 0xfb);
|
||||
ft_printf("ret=%i\n", ret);
|
||||
}
|
||||
|
||||
static void test99()
|
||||
{
|
||||
char prefix[128];
|
||||
char sfmt[128];
|
||||
int ret;
|
||||
|
||||
strcpy(prefix, "test99: ");
|
||||
strcpy(sfmt, "%%c: %c; %%s: %s; %%p: %p; %%d: %d; %%i: %i; %%u: %u; %%x: %x; %%X: %X --eof; ");
|
||||
printf("%s printf(): ", prefix);
|
||||
ret = printf(sfmt, 'a', "Lorem ipsum", (void *)prefix, 125, -128, 325u, 0xfa, 0xfb);
|
||||
printf("ret=%i\n", ret);
|
||||
fflush(stdout);
|
||||
ft_printf("%sft_printf(): ", prefix);
|
||||
ret = ft_printf(sfmt, 'a', "Lorem ipsum", (void *)prefix, 125, -128, 325u, 0xfa, 0xfb);
|
||||
ft_printf("ret=%i\n", ret);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
test50();
|
||||
test99();
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue