Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

44 test add test for parse texture #47

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions includes/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jeongwpa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/01 17:41:02 by jeongwpa #+# #+# */
/* Updated: 2024/08/23 01:03:31 by jeongwpa ### ########.fr */
/* Updated: 2024/08/26 09:59:15 by jeongwpa ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -26,8 +26,7 @@
# define ERROR_INVALID_RATIO "Ratio must be between 0 and 1"
# define ERROR_INVALID_TEXTURE_OPTION "Invalid texture option"
# define ERROR_OPEN_XPM_FILE "Failed to open the xpm file"
# define ERROR_DUPLICATE_TEXTURE "Checker_board and Texture_map \
cannot be used together"
# define ERROR_TEXTURE_DUPLICATE "Texture can not be duplicated"
# define ERROR_TEXTURE_NOT_FOUND "Texture not found"

void error_exit(char *message);
Expand Down
9 changes: 7 additions & 2 deletions srcs/parse/minirt_parse_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jeongwpa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/22 17:18:26 by jeongwpa #+# #+# */
/* Updated: 2024/08/23 02:36:06 by jeongwpa ### ########.fr */
/* Updated: 2024/08/26 10:00:04 by jeongwpa ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -46,6 +46,7 @@ void parse_texture(t_rt *rt, t_hit *data, char const **ptr)
t_texture_parser texture_parser;

line = *ptr;
data->texture.enable = FALSE;
move_to_next_param(&line);
while (*line)
{
Expand All @@ -61,6 +62,7 @@ void parse_texture(t_rt *rt, t_hit *data, char const **ptr)
t_texture_parser parse_texture_adapter(t_hit *data, char const *line)
{
int pos;
int option;
const char *options = "ctb";
const t_texture_parser parsers[] = {
parse_checkerboard,
Expand All @@ -74,7 +76,10 @@ t_texture_parser parse_texture_adapter(t_hit *data, char const *line)
if (*line == *options)
{
pos = options - "ctb";
data->texture.enable |= 1 << pos;
option = 1 << pos;
if (data->texture.enable & option)
error_exit(ERROR_TEXTURE_DUPLICATE);
data->texture.enable |= option;
return (parsers[pos]);
}
options++;
Expand Down
4 changes: 2 additions & 2 deletions srcs/shape/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jeongwpa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/23 00:57:47 by jeongwpa #+# #+# */
/* Updated: 2024/08/24 01:41:22 by jeongwpa ### ########.fr */
/* Updated: 2024/08/26 09:58:55 by jeongwpa ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -42,7 +42,7 @@ t_color uv_texture_map(t_hit *obj, t_record *rec, t_uv_map uv_map)
t_color_map uv_color_map_adapter(t_texture texture)
{
if ((texture.enable & 0b00000011) == (CHECKER_BOARD | TEXTURE_MAP))
error_exit(ERROR_DUPLICATE_TEXTURE);
error_exit(ERROR_TEXTURE_DUPLICATE);
if (texture.enable & CHECKER_BOARD)
return (uv_pattern_map);
if (texture.enable & TEXTURE_MAP)
Expand Down
13 changes: 13 additions & 0 deletions test/color_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ TEST(color_test, color_to_int) {
EXPECT_FLOAT_EQ(int_color, 0xFFA500);
}

TEST(color_test, int_to_color) {
int r = 255;
int g = 165;
int b = 0;
unsigned int int_color = r << 16 | g << 8 | b;

t_color color = int_to_color(int_color);

EXPECT_FLOAT_EQ(color.x, r / 255.0);
EXPECT_FLOAT_EQ(color.y, g / 255.0);
EXPECT_FLOAT_EQ(color.z, b / 255.0);
}

TEST(color_test, 성공) {
t_color color = {181, 129, 112};
normalize_color_value(&color);
Expand Down
17 changes: 17 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ void clear_get_next_line_buffer(int fd) {
}
}

extern "C" void *mlx_xpm_file_to_image(void *xvar,char *file,int *width,int *height)
{
(void)xvar;
(void)file;
*width = 42;
*height = 42;
return ((void *)42);
}

extern "C" void *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel, int *size_line, int *endian) {
(void)img_ptr;
*bits_per_pixel = 42;
*size_line = 42;
*endian = 42;
return ((void *)42);
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
2 changes: 1 addition & 1 deletion test/parse_cone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TEST(parse_cone_test, 성공)
rt.world = init_hittable_list(10);
char *line = (char *)"co 0,0,20 0,0,1 10 5 255,255,255";

parse_cylinder(line, &rt);
parse_cone(line, &rt);
t_hit *result = rt.world->objects[0];
ASSERT_EQ(result->shape, CYLINDER);
t_cone *cone = (t_cone *)result;
Expand Down
Loading
Loading