[Unit-Tests] Fix switch_core_video test to use temporary path for generated files and clean them up. Ignore test runtime dirs.

This commit is contained in:
Andrey Volk 2021-10-22 23:43:42 +03:00
parent d197db0601
commit 6da4f147de
3 changed files with 81 additions and 41 deletions

15
tests/unit/.gitignore vendored
View File

@ -5,16 +5,13 @@
\#*
*.log
*.trs
[0-9]*/**
conf_sofia/[0-9]*/**
.libs/
perf.data
perf.data.old
Makefile.in
freeswitch.xml.fsxml.tmp
test-argb.png
test-rgb.png
images/test_patched_banner_alpha.png
images/test_patched_banner_noalpha.png
images/test_patched_signalwire_alpha.png
images/test_patched_signalwire_no_alpha.png
switch_console
switch_core
switch_core_codec
@ -42,11 +39,5 @@ switch_estimators
switch_jitter_buffer
.deps/
Makefile
cluecon-argb-write.png
cluecon-argb.png
cluecon-jpg-write.jpg
cluecon-jpg.png
cluecon-rgb-write.png
cluecon-rgb.png
conf/*/
conf_playsay/*/

View File

@ -30,8 +30,6 @@
*
*/
#include <switch.h>
#include <stdlib.h>
#include <test/switch_test.h>
#if defined(HAVE_OPENSSL)

View File

@ -36,7 +36,7 @@
FST_CORE_BEGIN("./conf")
{
FST_SUITE_BEGIN(switch_ivr_originate)
FST_SUITE_BEGIN(switch_core_video)
{
FST_SETUP_BEGIN()
{
@ -51,6 +51,8 @@ FST_CORE_BEGIN("./conf")
FST_TEST_BEGIN(data_url_test)
{
char *data_url = NULL;
char *rgb_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test-rgb.png", SWITCH_GLOBAL_dirs.temp_dir);
char *argb_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test-argb.png", SWITCH_GLOBAL_dirs.temp_dir);
switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 120, 60, 1);
switch_image_t *argb_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, 120, 60, 1);
switch_rgb_color_t color = { 0 };
@ -60,7 +62,7 @@ FST_CORE_BEGIN("./conf")
switch_img_fill(img, 0, 0, img->d_w, img->d_h, &color);
switch_img_add_text(img->planes[0], img->d_w, 10, 10, "-1234567890");
switch_img_write_png(img, "images/test-rgb.png");
switch_img_write_png(img, rgb_filename);
switch_img_data_url_png(img, &data_url);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "I420: %s\n", data_url);
@ -74,7 +76,7 @@ FST_CORE_BEGIN("./conf")
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%d %d %d %d\n", *p, *(p+1), *(p+2), *(p+3));
}
switch_img_write_png(argb_img, "images/test-argb.png");
switch_img_write_png(argb_img, argb_filename);
switch_img_data_url_png(argb_img, &data_url);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ARGB: %s\n", data_url);
free(data_url);
@ -82,36 +84,46 @@ FST_CORE_BEGIN("./conf")
switch_img_free(&img);
switch_img_free(&argb_img);
unlink(rgb_filename);
unlink(argb_filename);
}
FST_TEST_END()
FST_TEST_BEGIN(img_patch)
{
char *filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test.png", SWITCH_GLOBAL_dirs.temp_dir);
char *text_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_text.png", SWITCH_GLOBAL_dirs.temp_dir);
char *patch_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched.png", SWITCH_GLOBAL_dirs.temp_dir);
int width = 320;
int height = 240;
switch_status_t status;
switch_image_t *img = NULL;
switch_rgb_color_t bgcolor = {0, 0, 0}; // red
switch_image_t *timg = switch_img_write_text_img(width, height, SWITCH_FALSE, "#ffffff:transparent:FreeMono.ttf:24:This is a test!");
fst_requires(timg != NULL);
switch_status_t status = switch_img_write_png(timg, "images/test_text.png");
status = switch_img_write_png(timg, text_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(text_filename);
width *=2;
height *=2;
switch_rgb_color_t bgcolor = {0, 0, 0}; // red
bgcolor.b = 255;
switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
fst_requires(img);
switch_img_fill(img, 0, 0, width, height, &bgcolor);
status = switch_img_write_png(img, "images/test.png");
status = switch_img_write_png(img, filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(filename);
switch_img_patch(img, timg, 0, 0);
status = switch_img_write_png(img, "images/test_patched.png");
status = switch_img_write_png(img, patch_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(patch_filename);
switch_img_free(&img);
switch_img_free(&timg);
@ -120,20 +132,37 @@ FST_CORE_BEGIN("./conf")
FST_TEST_BEGIN(img_patch_alpha)
{
switch_image_t *timg = switch_img_read_png("images/test_text.png", SWITCH_IMG_FMT_ARGB);
char *text_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_text.png", SWITCH_GLOBAL_dirs.temp_dir);
char *patch_filename_alpha = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched_alpha.png", SWITCH_GLOBAL_dirs.temp_dir);
char *patch_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched_noalpha.png", SWITCH_GLOBAL_dirs.temp_dir);
int width = 320;
int height = 240;
switch_image_t *img = NULL;
switch_status_t status;
switch_image_t *timg = switch_img_write_text_img(width, height, SWITCH_FALSE, "#ffffff:transparent:FreeMono.ttf:24:This is a test!");
fst_requires(timg != NULL);
status = switch_img_write_png(timg, text_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
switch_img_free(&timg);
timg = switch_img_read_png(text_filename, SWITCH_IMG_FMT_ARGB);
unlink(text_filename);
fst_requires(timg != NULL);
switch_image_t *img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
fst_requires(img);
switch_img_patch(img, timg, 0, 0);
switch_status_t status = switch_img_write_png(img, "images/test_patched_alpha.png");
status = switch_img_write_png(img, patch_filename_alpha);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(patch_filename_alpha);
switch_img_free(&img);
img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
switch_img_patch_rgb(img, timg, 0, 0, SWITCH_TRUE);
status = switch_img_write_png(img, "images/test_patched_noalpha.png");
status = switch_img_write_png(img, patch_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(patch_filename);
switch_img_free(&img);
switch_img_free(&timg);
@ -142,20 +171,24 @@ FST_CORE_BEGIN("./conf")
FST_TEST_BEGIN(img_patch_banner_alpha)
{
char *patch_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched_banner_noalpha.png", SWITCH_GLOBAL_dirs.temp_dir);
char *patch_filename_alpha = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched_banner_alpha.png", SWITCH_GLOBAL_dirs.temp_dir);
switch_status_t status;
switch_image_t *img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
switch_image_t *img2 = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
fst_requires(img);
fst_requires(img2);
switch_img_patch(img, img2, 80, 20);
status = switch_img_write_png(img, "images/test_patched_banner_alpha.png");
status = switch_img_write_png(img, patch_filename_alpha);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(patch_filename_alpha);
switch_img_free(&img);
img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
switch_img_patch_rgb(img, img2, 80, 20, SWITCH_TRUE);
status = switch_img_write_png(img, "images/test_patched_banner_noalpha.png");
status = switch_img_write_png(img, patch_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(patch_filename);
switch_img_free(&img);
switch_img_free(&img2);
@ -164,50 +197,56 @@ FST_CORE_BEGIN("./conf")
FST_TEST_BEGIN(img_patch_signalwire_alpha)
{
char *patch_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched_signalwire_alpha.png", SWITCH_GLOBAL_dirs.temp_dir);
switch_image_t *timg_small = NULL;
switch_image_t *timg = switch_img_read_png("images/signalwire.png", SWITCH_IMG_FMT_ARGB);
fst_requires(timg != NULL);
switch_image_t *img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
switch_status_t status;
fst_requires(timg != NULL);
fst_requires(img);
switch_img_scale(timg, &timg_small, timg->d_w / 5, timg->d_h / 5);
switch_img_patch(img, timg_small, 80, 20);
switch_status_t status = switch_img_write_png(img, "images/test_patched_signalwire_alpha.png");
status = switch_img_write_png(img, patch_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
switch_img_free(&img);
switch_img_free(&timg);
switch_img_free(&timg_small);
unlink(patch_filename);
}
FST_TEST_END()
FST_TEST_BEGIN(img_patch_signalwire_no_alpha)
{
char *patch_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "test_patched_signalwire_no_alpha.png", SWITCH_GLOBAL_dirs.temp_dir);
switch_image_t *timg_small = NULL;
switch_image_t *timg = switch_img_read_png("images/signalwire.png", SWITCH_IMG_FMT_ARGB);
fst_requires(timg != NULL);
switch_image_t *img = switch_img_read_png("images/banner.png", SWITCH_IMG_FMT_ARGB);
switch_status_t status;
fst_requires(timg != NULL);
fst_requires(img);
switch_img_scale(timg, &timg_small, timg->d_w / 5, timg->d_h / 5);
switch_img_patch_rgb(img, timg_small, 80, 20, SWITCH_TRUE);
switch_status_t status = switch_img_write_png(img, "images/test_patched_signalwire_no_alpha.png");
status = switch_img_write_png(img, patch_filename);
fst_check(status == SWITCH_STATUS_SUCCESS);
switch_img_free(&img);
switch_img_free(&timg);
switch_img_free(&timg_small);
unlink(patch_filename);
}
FST_TEST_END()
FST_TEST_BEGIN(stb_data_url)
{
switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 120, 60, 1);
char *data_url = NULL;
switch_rgb_color_t color = { 0 };
color.r = 255;
// color.g = 255;
// color.b = 255;
char *data_url = NULL;
switch_img_fill(img, 0, 0, img->d_w, img->d_h, &color);
switch_img_add_text(img->planes[0], img->d_w, 10, 10, "-1234567890");
@ -228,21 +267,27 @@ FST_CORE_BEGIN("./conf")
FST_TEST_BEGIN(read_from_file)
{
switch_image_t *img;
char *rgb_write_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "cluecon-rgb.png", SWITCH_GLOBAL_dirs.temp_dir);
char *argb_write_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "cluecon-argb.png", SWITCH_GLOBAL_dirs.temp_dir);
char *jpg_write_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "cluecon-jpg.png", SWITCH_GLOBAL_dirs.temp_dir);
img = switch_img_read_from_file("../../images/cluecon.png", SWITCH_IMG_FMT_I420);
fst_requires(img);
switch_img_write_png(img, "cluecon-rgb.png");
switch_img_write_png(img, rgb_write_filename);
switch_img_free(&img);
unlink(rgb_write_filename);
img = switch_img_read_from_file("../../images/cluecon.png", SWITCH_IMG_FMT_ARGB);
fst_requires(img);
switch_img_write_png(img, "cluecon-argb.png");
switch_img_write_png(img, argb_write_filename);
switch_img_free(&img);
unlink(argb_write_filename);
img = switch_img_read_from_file("../../images/cluecon.jpg", SWITCH_IMG_FMT_I420);
fst_requires(img);
switch_img_write_png(img, "cluecon-jpg.png");
switch_img_write_png(img, jpg_write_filename);
switch_img_free(&img);
unlink(jpg_write_filename);
}
FST_TEST_END()
@ -250,24 +295,30 @@ FST_CORE_BEGIN("./conf")
{
switch_image_t *img;
switch_status_t status;
char *rgb_write_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "cluecon-rgb-write.png", SWITCH_GLOBAL_dirs.temp_dir);
char *argb_write_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "cluecon-argb-write.png", SWITCH_GLOBAL_dirs.temp_dir);
char *jpg_write_filename = switch_core_sprintf(fst_pool, "%s" SWITCH_PATH_SEPARATOR "cluecon-jpg-write.png", SWITCH_GLOBAL_dirs.temp_dir);
img = switch_img_read_from_file("../../images/cluecon.png", SWITCH_IMG_FMT_I420);
fst_requires(img);
status = switch_img_write_to_file(img, "cluecon-rgb-write.png", 0);
status = switch_img_write_to_file(img, rgb_write_filename, 0);
switch_img_free(&img);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(rgb_write_filename);
img = switch_img_read_from_file("../../images/cluecon.png", SWITCH_IMG_FMT_ARGB);
fst_requires(img);
status = switch_img_write_to_file(img, "cluecon-argb-write.png", 0);
status = switch_img_write_to_file(img, argb_write_filename, 0);
switch_img_free(&img);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(argb_write_filename);
img = switch_img_read_from_file("../../images/cluecon.jpg", SWITCH_IMG_FMT_I420);
fst_requires(img);
status = switch_img_write_to_file(img, "cluecon-jpg-write.jpg", 100);
status = switch_img_write_to_file(img, jpg_write_filename, 100);
switch_img_free(&img);
fst_check(status == SWITCH_STATUS_SUCCESS);
unlink(jpg_write_filename);
}
FST_TEST_END()
}