a la norme et sans leaks, manque le parsing

This commit is contained in:
hugogogo
2021-07-23 16:28:12 +02:00
parent 04ad40b58d
commit 3b8a88de23
130 changed files with 8652 additions and 211 deletions

View File

@@ -0,0 +1,87 @@
name: Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ${{ matrix.os }}
env:
DISPLAY: ":99"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Install mlx dependencies
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install gcc make xorg libxext-dev libbsd-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xquartz
echo "/usr/X11/bin" >> $GITHUB_PATH
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Setup x11 headless testing environment
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install xvfb xdotool valgrind
Xvfb $DISPLAY -screen 0 1280x1024x24 &
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xdotool
defaults write org.x.X11 enable_test_extensions -boolean true
sudo Xvfb $DISPLAY -screen 0 1280x1024x24 &
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Run ./configure
run: ./configure
- name: make check Linux
if: matrix.os == 'ubuntu-latest'
run: make -f Makefile.gen check
- name: make check MacOS
continue-on-error: true
if: matrix.os == 'macos-latest'
run: make -f Makefile.gen check
# Didn't find a way to simulate inputs on Macos. libxdo seem to no longer work on macos.
# It can be partially fixed writing proper unit-tests, thus avoiding the need of libxdo.
- name: Check leaks from binary "test/mlx-test"
run: |
cd test
if [ "$RUNNER_OS" == "Linux" ]; then
echo "Info: Still reachable doesn't matter. Valgrind will return success on thoses reports.
It is fine, we searching for lost pointers. Valgrind will return exit status 42 if any block is lost."
valgrind --leak-check=full --show-leak-kinds=definite,indirect,possible --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=42 ./mlx-test > /dev/null &
PID=$!
sleep 30
xdotool search --name Title3 windowfocus key Escape
xdotool search --name Title2 windowfocus key Escape
wait $PID
elif [ "$RUNNER_OS" == "macOS" ]; then
MallocStackLoggingNoCompact=1
./mlx-test &
sleep 30
leaks mlx-test
pkill mlx-test
fi
- name: Norminette, just for fun
continue-on-error: true
run: |
pip3 install Norminette
norminette *.c *.h
norminette --version

67
minilibx-linux-master/.gitignore vendored Normal file
View File

@@ -0,0 +1,67 @@
## Mlx related
Makefile.gen
/test/mlx-test
## Editor
.vscode/*
*~
\#*\#
## Other
.DS_STORE
## Template from https://github.com/github/gitignore
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

View File

@@ -0,0 +1,25 @@
BSD 2-Clause License
Copyright (c) 2021, Ecole 42
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,6 +1,4 @@
INC=/usr/include
HT=Linux
DOCP=do_cp
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
##
@@ -15,9 +13,11 @@ DOCP=do_cp
CC = gcc
NAME = libmlx.a
NAME = libmlx.a
NAME_UNAME = libmlx_$(shell uname).a
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
@@ -31,18 +31,33 @@ SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \
mlx_destroy_display.c
OBJ =$(SRC:.c=.o)
OBJ_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
CFLAGS = -O3 -I$(INC)
all : $(NAME) $(DOCP)
all : $(NAME)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
$(NAME) : $(OBJ)
ar -r $(NAME) $(OBJ)
ranlib $(NAME)
cp $(NAME) $(NAME_UNAME)
do_cp :
cp $(NAME) libmlx_$(HT).a
check: all
@test/run_tests.sh
show:
@printf "NAME : $(NAME)\n"
@printf "NAME_UNAME : $(NAME_UNAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"
clean :
rm -f $(OBJ) $(NAME) libmlx_$(HT).a *~ core *.core
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core
.PHONY: all check show clean

View File

@@ -12,12 +12,12 @@
INC =%%%%
HT =%%%%
DOCP =%%%%
CC = gcc
NAME = libmlx.a
NAME = libmlx.a
NAME_UNAME = libmlx_$(shell uname).a
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
@@ -31,18 +31,33 @@ SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \
mlx_destroy_display.c
OBJ =$(SRC:.c=.o)
OBJ_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
CFLAGS = -O3 -I$(INC)
all : $(NAME) $(DOCP)
all : $(NAME)
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
$(NAME) : $(OBJ)
ar -r $(NAME) $(OBJ)
ranlib $(NAME)
cp $(NAME) $(NAME_UNAME)
do_cp :
cp $(NAME) libmlx_$(HT).a
check: all
@test/run_tests.sh
show:
@printf "NAME : $(NAME)\n"
@printf "NAME_UNAME : $(NAME_UNAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"
clean :
rm -f $(OBJ) $(NAME) libmlx_$(HT).a *~ core *.core
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core
.PHONY: all check show clean

View File

@@ -1,3 +1,4 @@
[![Build](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml/badge.svg)](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml)
This is the MinilibX, a simple X-Window (X11R6) programming API
in C, designed for students, suitable for X-beginners.
@@ -12,8 +13,7 @@ Contents
- a public include file mlx.h
- a tiny configure script to generate an appropriate Makefile.gen
Requirements
Requirements for Linux
- MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth)
- gcc
@@ -23,6 +23,18 @@ Requirements
- Utility functions from BSD systems - development files (package libbsd-dev)
- **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)**
Requirements for MacOS
- [Xquartz](https://www.xquartz.org/)
```bash
➜ ~ Brew install Xquartz
➜ ~ reboot
➜ ~ xeyes # run an hello world X11 app
```
MlX Color Opacity / Transparency / Alpha (32 bits depth)
- 0xFF (fully transparent) or 0x00 (fully opaque)
Compile MinilibX
- run ./configure or make

196
minilibx-linux-master/configure vendored Executable file → Normal file
View File

@@ -1,95 +1,121 @@
#!/bin/sh
set -e
if [ -n "$1" -a "$1" = "--help" ] ; then
echo "Usage : $0\n Auto-configure and make MinilibX"
exit
fi
BOLD="\e[1m"
RESET="\e[0m"
LIGHT_RED="\e[91m"
LIGHT_GREEN="\e[92m"
LIGHT_CYAN="\e[96m"
logging(){
local type=$1; shift
printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*"
}
log_info(){
logging "${LIGHT_GREEN}info${RESET}" "$@"
}
log_error(){
logging "${LIGHT_RED}error${RESET}" "$@" >&2
}
conf_inc=NO
# find and print x11 header path
get_xlib_include_path(){
local result=""
for inc in \
/usr/X11/include \
/usr/X11R6/include \
/usr/X11R5/include \
/usr/X11R4/include \
\
/usr/include \
/usr/include/X11 \
/usr/include/X11R6 \
/usr/include/X11R5 \
/usr/include/X11R4 \
\
/usr/local/X11/include \
/usr/local/X11R6/include \
/usr/local/X11R5/include \
/usr/local/X11R4/include \
\
/usr/local/include/X11 \
/usr/local/include/X11R6 \
/usr/local/include/X11R5 \
/usr/local/include/X11R4 \
\
/usr/X386/include \
/usr/x386/include \
/usr/XFree86/include/X11 \
\
/usr/include \
/usr/local/include \
/usr/athena/include \
/usr/local/x11r5/include \
/usr/lpp/Xamples/include \
\
/usr/openwin/include \
/usr/openwin/share/include
do
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
conf_inc=$inc
break
for inc in \
/usr/X11/include \
/usr/X11R6/include \
/usr/X11R5/include \
/usr/X11R4/include \
\
/usr/include \
/usr/include/X11 \
/usr/include/X11R6 \
/usr/include/X11R5 \
/usr/include/X11R4 \
\
/usr/local/X11/include \
/usr/local/X11R6/include \
/usr/local/X11R5/include \
/usr/local/X11R4/include \
\
/usr/local/include/X11 \
/usr/local/include/X11R6 \
/usr/local/include/X11R5 \
/usr/local/include/X11R4 \
\
/usr/X386/include \
/usr/x386/include \
/usr/XFree86/include/X11 \
\
/usr/local/include \
/usr/athena/include \
/usr/local/x11r5/include \
/usr/lpp/Xamples/include \
\
/usr/openwin/include \
/usr/openwin/share/include
do
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
result=$inc
break
fi
done
echo $result
}
show_help(){
cat <<EOF
Usage :
$0 Auto-configure and make MinilibX
$0 clean Execute the clean rule of both Makefile.gen
EOF
}
clean(){
log_info 'Execute "make clean" from "makefile.gen"'
make -f Makefile.gen clean
log_info 'Execute "make clean" from "test/makefile.gen"'
make -f Makefile.gen -C test/ --no-print-directory clean
}
parse_args(){
case "$1" in
--help | -h)
show_help
exit 0;;
clean)
clean
exit 0;;
"") return;;
*)
log_error "unknown command \"$1\"\nRun \"./configure --help\" for usage."
exit 1;;
esac
}
main(){
local xlib_inc="$(get_xlib_include_path)"
parse_args "$@"
if [ -z "$xlib_inc" ]; then
log_error "Can't find a suitable X11 include directory."
exit 1
fi
done
log_info "Found X11 include path directory: $xlib_inc"
log_info 'Generate "makefile.gen" from template "makefile.mk"'
echo "INC=$xlib_inc" > Makefile.gen
cat Makefile.mk | grep -v %%%% >> Makefile.gen
log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"'
echo "INC=$xlib_inc" > test/Makefile.gen
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
if [ "$conf_inc" = "NO" ]; then
echo "Can't find a suitable X11 include directory."
exit
else
echo "X11 include dir : $conf_inc"
fi
log_info 'Execute "make all" from file "makefile.gen"'
make -f Makefile.gen all
log_info 'Execute "make all" from file "test/makefile.gen"'
(cd test ; make -f Makefile.gen all )
}
if [ -z "$HOSTTYPE" ]; then
conf_ht=`uname -s`
else
conf_ht=$HOSTTYPE
fi
if [ -z "$conf_ht" ]; then
conf_docp=""
else
conf_docp="do_cp"
echo "lib_$conf_ht generation"
fi
/bin/echo "INC=$conf_inc" > Makefile.gen
/bin/echo "HT=$conf_ht" >> Makefile.gen
/bin/echo "DOCP=$conf_docp" >> Makefile.gen
cat Makefile.mk | grep -v %%%% >> Makefile.gen
/bin/echo "INC=$conf_inc" > test/Makefile.gen
/bin/echo "HT=$conf_ht" >> test/Makefile.gen
/bin/echo "DOCP=$conf_docp" >> test/Makefile.gen
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
if [ -n "$1" -a "$1" = "clean" ] ; then
echo "Now make it clean."
make -f Makefile.gen clean
(cd test ; make -f Makefile.gen clean)
exit
fi
echo "Now make it."
make -f Makefile.gen all
(cd test ; make -f Makefile.gen all )
main "$@"

Binary file not shown.

Binary file not shown.

View File

@@ -87,7 +87,7 @@ int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param);
int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param);
int mlx_loop (void *mlx_ptr);
int mlx_loop_end (void *mlx_ptr);
/*
** hook funct are called as follow :
@@ -115,7 +115,7 @@ int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
int mlx_destroy_dispaly(void *mlx_ptr);
int mlx_destroy_display(void *mlx_ptr);
/*
** generic hook system for all events, and minilibX functions that

Binary file not shown.

View File

@@ -38,11 +38,13 @@ void *mlx_init()
xvar->loop_param = (void *)0;
xvar->do_flush = 1;
xvar->wm_delete_window = XInternAtom (xvar->display, "WM_DELETE_WINDOW", False);
xvar->wm_protocols = XInternAtom (xvar->display, "WM_PROTOCOLS", False);
mlx_int_deal_shm(xvar);
if (xvar->private_cmap)
xvar->cmap = XCreateColormap(xvar->display,xvar->root,
xvar->visual,AllocNone);
mlx_int_rgb_conversion(xvar);
xvar->end_loop = 0;
return (xvar);
}

Binary file not shown.

View File

@@ -114,6 +114,8 @@ typedef struct s_xvar
int do_flush;
int decrgb[6];
Atom wm_delete_window;
Atom wm_protocols;
int end_loop;
} t_xvar;

Binary file not shown.

View File

@@ -13,31 +13,50 @@
extern int (*(mlx_int_param_event[]))();
static int win_count(t_xvar *xvar)
{
int i;
t_win_list *win;
int mlx_loop(t_xvar *xvar)
i = 0;
win = xvar->win_list;
while (win)
{
win = win->next;
++i;
}
return (i);
}
int mlx_loop_end(t_xvar *xvar)
{
xvar->end_loop = 1;
return (1);
}
int mlx_loop(t_xvar *xvar)
{
XEvent ev;
t_win_list *win;
mlx_int_set_win_event_mask(xvar);
xvar->do_flush = 0;
while (42)
while (win_count(xvar) && !xvar->end_loop)
{
while (!xvar->loop_hook || XPending(xvar->display))
while (!xvar->end_loop && (!xvar->loop_hook || XPending(xvar->display)))
{
XNextEvent(xvar->display,&ev);
win = xvar->win_list;
while (win && (win->window!=ev.xany.window))
win = win->next;
if (win && ev.type < MLX_MAX_EVENT)
{
if (ev.type == ClientMessage && (Atom)ev.xclient.data.l[0] == xvar->wm_delete_window)
XDestroyWindow(xvar->display, win->window);
if (win->hooks[ev.type].hook)
mlx_int_param_event[ev.type](xvar, &ev, win);
}
if (win && ev.type == ClientMessage && ev.xclient.message_type == xvar->wm_protocols && ev.xclient.data.l[0] == xvar->wm_delete_window && win->hooks[DestroyNotify].hook)
win->hooks[DestroyNotify].hook(win->hooks[DestroyNotify].param);
if (win && ev.type < MLX_MAX_EVENT && win->hooks[ev.type].hook)
mlx_int_param_event[ev.type](xvar, &ev, win);
}
XSync(xvar->display, False);
xvar->loop_hook(xvar->loop_param);
}
return (0);
}

Binary file not shown.

Binary file not shown.

View File

@@ -108,9 +108,13 @@ void *mlx_int_new_image(t_xvar *xvar,int width, int height,int format)
{
t_img *img;
if (!(img = malloc(sizeof(*img))) ||
!(img->data = malloc((width+32)*height*4)))
if (!(img = malloc(sizeof(*img))))
return ((void *)0);
if (!(img->data = malloc((width+32)*height*4)))
{
free(img);
return ((void *)0);
}
bzero(img->data,(width+32)*height*4);
img->image = XCreateImage(xvar->display,xvar->visual,xvar->depth,format,0,
img->data,width,height,32,0);

Binary file not shown.

Binary file not shown.

View File

@@ -15,7 +15,7 @@ extern struct s_col_name mlx_col_name[];
#define RETURN { if (colors) free(colors); if (tab) free(tab); \
if (colors_direct) free(colors_direct); \
tab = (void *)0; if (colors_direct) free(colors_direct); \
if (img) {XDestroyImage(img->image); \
XFreePixmap(xvar->display,img->pix);free(img);} \
return ((void *)0);}
@@ -117,24 +117,17 @@ int mlx_int_get_text_rgb(char *name, char *end)
int mlx_int_xpm_set_pixel(t_img *img, char *data, int opp, int col, int x)
{
int dec;
unsigned int ucol;
if (opp == 4 && img->image->byte_order)
ucol = col | 0x000000FF;
else if (opp == 4)
ucol = col | 0xFF000000;
else
ucol = col;
int dec;
dec = opp;
while (dec--)
{
if (img->image->byte_order)
*(data+x*opp+dec) = ucol&0xFF;
else
*(data+x*opp+opp-dec-1) = ucol&0xFF;
ucol >>= 8;
}
while (dec--)
{
if (img->image->byte_order)
*(data+x*opp+dec) = col&0xFF;
else
*(data+x*opp+opp-dec-1) = col&0xFF;
col >>= 8;
}
}
@@ -201,26 +194,28 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
if (!tab[j])
RETURN;
rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]);
/*
if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1)
{
if (!(clip_data = malloc(4*width*height)) || /* ok, nice size .. */
if (!(clip_data = malloc(4*width*height)) || ok, nice size ..
!(clip_img = XCreateImage(xvar->display, xvar->visual,
1, XYPixmap, 0, clip_data,
width, height, 8, (width+7)/8)) )
RETURN;
memset(clip_data, 0xFF, 4*width*height);
}
*/
if (method)
colors_direct[mlx_int_get_col_name(line,cpp)] =
rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col;
// rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col;
else
{
colors[i].name = mlx_int_get_col_name(line,cpp);
colors[i].col = rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
colors[i].col = rgb_col; //rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col;
}
free(tab);
tab = (void *)0;
}
if (!(img = mlx_new_image(xvar,width,height)))
@@ -251,14 +246,21 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
j = 0;
}
}
/*
if (col==-1)
XPutPixel(clip_img, x, height-1-i, 0);
else
mlx_int_xpm_set_pixel(img, data, opp, col, x);
x ++;
*/
if (col==-1)
col = 0xFF000000;
mlx_int_xpm_set_pixel(img, data, opp, col, x);
++x;
}
data += img->size_line;
}
/*
if (clip_data)
{
if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root,
@@ -276,6 +278,7 @@ void *mlx_int_parse_xpm(t_xvar *xvar,void *info,int info_size,char *(*f)())
XSync(xvar->display, False);
XDestroyImage(clip_img);
}
*/
if (colors)
free(colors);
if (colors_direct)

Binary file not shown.

0
minilibx-linux-master/rgb2c.pl Executable file → Normal file
View File

View File

@@ -1,26 +1,41 @@
INC=/usr/include
HT=Linux
DOCP=do_cp
INCLIB=$(INC)/../lib
CC=gcc
CFLAGS= -I$(INC) -O3 -I..
CFLAGS= -I$(INC) -O3 -I.. -g
NAME= mlx-test
SRC = main.c
OBJ = $(SRC:.c=.o)
OBJ = $(SRC:%.c=%.o)
all :$(NAME)
LFLAGS = -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm
$(NAME) :$(OBJ)
$(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm -lbsd
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
# mac
else
#Linux and others...
LFLAGS += -lbsd
endif
clean :
all: $(NAME)
$(NAME): $(OBJ)
$(CC) -o $(NAME) $(OBJ) $(LFLAGS)
show:
@printf "UNAME : $(UNAME)\n"
@printf "NAME : $(NAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "LFLAGS : $(LFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"
clean:
rm -f $(NAME) $(OBJ) *~ core *.core
re : clean all
re: clean all

View File

@@ -1,24 +1,41 @@
INC=%%%%
INCLIB=$(INC)/../lib
CC=gcc
CFLAGS= -I$(INC) -O3 -I..
CFLAGS= -I$(INC) -O3 -I.. -g
NAME= mlx-test
SRC = main.c
OBJ = $(SRC:.c=.o)
OBJ = $(SRC:%.c=%.o)
all :$(NAME)
LFLAGS = -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm
$(NAME) :$(OBJ)
$(CC) -o $(NAME) $(OBJ) -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm -lbsd
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
# mac
else
#Linux and others...
LFLAGS += -lbsd
endif
clean :
all: $(NAME)
$(NAME): $(OBJ)
$(CC) -o $(NAME) $(OBJ) $(LFLAGS)
show:
@printf "UNAME : $(UNAME)\n"
@printf "NAME : $(NAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "LFLAGS : $(LFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"
clean:
rm -f $(NAME) $(OBJ) *~ core *.core
re : clean all
re: clean all

Binary file not shown.

BIN
minilibx-linux-master/test/mlx-test Executable file → Normal file

Binary file not shown.

View File

@@ -0,0 +1,90 @@
#!/bin/sh
# This very basic script simulate user inputs for the CI
# Feel free to update, improve or remove it if proper
# intergration tests and/or unit tests are added.
set -e
BOLD="\e[1m"
RESET="\e[0m"
LIGHT_RED="\e[91m"
LIGHT_GREEN="\e[92m"
LIGHT_CYAN="\e[96m"
logging(){
local type=$1; shift
printf "${LIGHT_CYAN}${BOLD}run_tests${RESET} [%b] : %b\n" "$type" "$*"
}
log_info(){
logging "${LIGHT_GREEN}info${RESET}" "$@"
}
log_error(){
logging "${LIGHT_RED}error${RESET}" "$@" >&2
exit 1
}
PID=""
# to properly kill child process executed in background on exit
at_exit() {
status=$?
[ $status -eq 0 ] && log_info "Seem all went well" && exit 0
# Code for non-zero exit:
if ! kill -s TERM "$PID" 2>/dev/null || ! wait "$PID" ; then
log_error "Pid [$PID] died with status $status "
fi
log_error "Something went wrong. Pid [$PID] has been killed. Status code $status"
}
# to properly quit from ctrl+c (SIGINT Signal)
sigint_handler(){
kill -s TERM "$PID"
wait
log_info "Tests abort"
exit 1
}
# look at test/main.c and run ./mlx-test to understand what this function does
test_default_main(){
make -f Makefile.gen all
./mlx-test &
PID="$!"
log_info "./mlx-test running in background, pid:" $PID
i=25 # waiting 25s mlx-test to be ready for inputs.
while [ $i -gt 0 ]; do
if ! ps -p $PID > /dev/null ; then
wait $PID
fi
log_info "countdown" $i
sleep 1
i=$((i - 1))
done
log_info "Ready to \"just play\" using xdotool"
wid1=$(xdotool search --name Title1)
wid2=$(xdotool search --name Title2)
wid3=$(xdotool search --name Title3)
xdotool windowfocus $wid3
log_info "Focus Win3: Testing move mouse 100 100"
xdotool mousemove 100 100
log_info "Focus Win3: Testing move mouse 200 200"
xdotool mousemove 200 200
log_info "Focus Win3: Pressing escape to destroy window \"Win3\""
xdotool key Escape
log_info "Focus Win2: Pressing escape to stop program"
xdotool windowfocus $wid2
xdotool key Escape
}
main(){
cd $(dirname $0)
trap at_exit EXIT
trap sigint_handler INT
test_default_main
}
main "$@"