rework of tests in main

This commit is contained in:
Aleksei Chubukov 2023-11-23 23:06:22 +04:00
parent 92b42aa8ec
commit 678dbd0846
5 changed files with 59 additions and 13 deletions

View File

@ -18,8 +18,8 @@ clean:
.PHONY: all norme clean
.SECONDEXPANSION:
build/c%: $(OFFSHORE_PROJECTS)/c$$*/*.c $$(OFFSHORE_MAINS)/c$$*.c
build/c%: $(OFFSHORE_PROJECTS)/c$$*/*.c $$(OFFSHORE_MAINS)/c$$*.c $$(wildcard $(OFFSHORE_MAINS)/common/*.c)
mkdir -p $(@D)
$(CC) -o $@ $(CFLAGS_MANDATORY) $(CFLAGS) $^
$(CC) -o $@ $(CFLAGS_MANDATORY) -Icommon $(CFLAGS) $^
norme: $$(wildcard $(OFFSHORE_PROJECTS)/c*)
norminette -R CheckForbiddenSourceHeader $^

View File

@ -1,4 +1,4 @@
#include "common.c"
#include "tests.h"
char *ft_strcpy(char *dest, char *src);
int main(void)
{

41
c02/ex01.c Normal file
View File

@ -0,0 +1,41 @@
#include "tests.h"
char *ft_strncpy(char*, char*, size_t);
int main(void)
{
char s1[100] = TEST_SOURCE;
char d1[100] = TEST_DESTINATION;
char*r1;
char s2[100] = TEST_SOURCE;
char d2[100] = TEST_DESTINATION;
char*r2;
char s3[100] = TEST_SOURCE;
char d3[100] = TEST_DESTINATION;
char*r3;
char s4[100] = TEST_SOURCE;
char d4[100] = TEST_DESTINATION;
char*r4;
printf("initial strings:\n");
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
r1 = strncpy(d1 ,s1, 4);
printf("strncpy(d, s, 4):\n");
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
r2 = ft_strncpy(d2, s2, 4);
printf("ft_strncpy(d, s, 4:\n");
dump(s2, TEST_SOURCE_LENGHT);
dump(d2, TEST_DESTINATION_LENGHT);
printf("buffers comparison: s:%i d:%i\n", bufcmp(s1, s2, TEST_SOURCE_LENGHT), bufcmp(d1, d2, TEST_DESTINATION_LENGHT));
r3 = strncpy(d3 ,s3, 20);
printf("strncpy(d, s, 20):\n");
dump(s3, TEST_SOURCE_LENGHT);
dump(d3, TEST_DESTINATION_LENGHT);
r4 = ft_strncpy(d4, s4, 20);
printf("ft_strncpy(d, s, 20):\n");
dump(s4, TEST_SOURCE_LENGHT);
dump(d4, TEST_DESTINATION_LENGHT);
printf("buffers comparison: s:%i d:%i\n", bufcmp(s3, s4, TEST_SOURCE_LENGHT), bufcmp(d3, d4, TEST_DESTINATION_LENGHT));
printf("return values comparison: %li %li %li %li\n", d1 - r1, d2 -r2, d3 - r3, d4 - r4);
}

View File

@ -1,13 +1,4 @@
#include <string.h>
#include <stdio.h>
#define TEST_SOURCE "HeLlo world!\0It's a\tBEAUTIFUL\tday!"
#define TEST_SOURCE_LENGHT 35
#define TEST_DESTINATION "GooDBye\0and thanks \tfor\rall the fish!"
#define TEST_DESTINATION_LENGHT 38
#define FG_WHT "\x1B[37m"
#define FG_MAG "\x1B[35m"
#define COLOR_RESET "\x1B[0m"
#include "tests.h"
void dump(char *data, int len)

14
common/tests.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef TESTS_H
#define TESTS_H
#include <string.h>
#include <stdio.h>
#define TEST_SOURCE "HeLlo world!\0It's a\tBEAUTIFUL\tday!"
#define TEST_SOURCE_LENGHT 35
#define TEST_DESTINATION "GooDBye\0and thanks \tfor\rall the fish!"
#define TEST_DESTINATION_LENGHT 38
#define FG_WHT "\x1B[37m"
#define FG_MAG "\x1B[35m"
#define COLOR_RESET "\x1B[0m"
#endif
int bufcmp(char *this, char *other, int len);
void dump(char *data, int len);