add testing of stdout both if moc's in DEBUG mode or not
This commit is contained in:
2023-11-30 21:43:51 +01:00
parent b7a924719e
commit 40662b33aa
2 changed files with 121 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ add_executable(tests)
target_compile_definitions(tests
PRIVATE
"TESTING"
"DEBUG"
)
target_sources(tests

View File

@@ -11,58 +11,178 @@ extern "C" {
TEST(TCP_CMD, tcp_data_cb) {
char* cmd = (char*)calloc(50, 1);
std::string output;
pbuf p = {.next = NULL, .payload = (void*)cmd, .tot_len = 4, .len = 0, .type_internal = 0, .flags = 0, .if_idx = 0};
strcpy(cmd, "help");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "help : shows a list of commands\r\n"
"text \"<text>\" : puts text on the lcd\r\n"
"color <r> <g> <b> : set the background color of the lcd\r\n"
"textColor <r> <g> <b> : set the color of the text\r\n"
"listImages : shows a list with images in the filesystem\r\n"
"setImage <image_name> : put an image on the screen\r\n"
"setGift <image_name> : put a gif on the screen\r\n"
"exit : closes the connection\r\n\n$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\nhelp : shows a list of commands\r\n"
"text \"<text>\" : puts text on the lcd\r\n"
"color <r> <g> <b> : set the background color of the lcd\r\n"
"textColor <r> <g> <b> : set the color of the text\r\n"
"listImages : shows a list with images in the filesystem\r\n"
"setImage <image_name> : put an image on the screen\r\n"
"setGift <image_name> : put a gif on the screen\r\n"
"exit : closes the connection\r\n\n"
"tcp_output\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "text \"This is printed on the display\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\nlcd_clear_text\nlcd_display_text @ 10 10 with color 0xFF000000 bg color 0xFF000000\nThis is printed on the display\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "color 0x555555");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "bgcolor 0xAAAAAA");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "text \"This is printed on the display\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\nlcd_clear_text\nlcd_display_text @ 10 10 with color 0xFF555555 bg color 0xFFAAAAAA\nThis is printed on the display\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "color 255 255 255");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "bgcolor 255 255 255");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "text \"This is printed on the display\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\nlcd_clear_text\nlcd_display_text @ 10 10 with color 0xFFFFFFFF bg color 0xFFFFFFFF\nThis is printed on the display\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "setImage \"test.bmp\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\nlcd_clear_images\nlcd_draw_img_from_fs\ntest.bmp @0 0\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "setImage \"test.gif\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "File is not a bmp\n\n$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\nFile is not a bmp\n\ntcp_output\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "setGif \"test.gif\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "$> \n");
#else
EXPECT_EQ(output, "tcp_recved\nlcd_clear_images\nlcd_draw_gif_from_fs\ntest.gif @0 0\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "setGif \"test.bmp\"");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "File is not a gif\n\n$> \n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\nFile is not a gif\n\ntcp_output\ntcp_write:\n$> \ntcp_output\npbuf_free\n");
#endif
strcpy(cmd, "exit");
p.tot_len = (uint16_t)strlen(cmd);
testing::internal::CaptureStdout();
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
output = testing::internal::GetCapturedStdout();
#ifndef DEBUG
EXPECT_EQ(output, "Exiting...\n\n");
#else
EXPECT_EQ(output, "tcp_recved\ntcp_write:\nExiting...\n\ntcp_output\nlcd_clear_images\nlcd_clear_text\ntcp_close\ntcp_arg\ntcp_sent\ntcp_recv\ntcp_close\npbuf_free\n");
#endif
free(cmd);
}