tcp_cmd
add functions that need to be tested to header file
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void tcp_cmd_remove_newline(char* str, size_t len);
|
||||
char* tcp_cmd_get_filename_ext(char* filename);
|
||||
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next);
|
||||
void tcp_cmd_init(void);
|
||||
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ static void tcp_cmd_print_help(struct tcp_pcb* pcb) {
|
||||
* @brief This function removes the newline from a string the string can contain multiple lines
|
||||
* @param str The string to remove the newline from
|
||||
*/
|
||||
void remove_newline(char* str, size_t len) {
|
||||
void tcp_cmd_remove_newline(char* str, size_t len) {
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
while (str[i] != '\0' && j < len) {
|
||||
@@ -78,7 +78,7 @@ void remove_newline(char* str, size_t len) {
|
||||
* @brief This function converts a string to lowercase
|
||||
* @param str The string to convert
|
||||
*/
|
||||
void str_tolower(char* str) {
|
||||
void tcp_cmd_str_tolower(char* str) {
|
||||
int i = 0;
|
||||
while (str[i] != '\0') {
|
||||
str[i] = (char)tolower((int)str[i]);
|
||||
@@ -91,7 +91,7 @@ void str_tolower(char* str) {
|
||||
* @param filename The filename to get the extension from
|
||||
* @return char* The extension of the file
|
||||
*/
|
||||
char* get_filename_ext(char* filename) {
|
||||
char* tcp_cmd_get_filename_ext(char* filename) {
|
||||
char* dot = strrchr(filename, '.');
|
||||
if (!dot || dot == filename)
|
||||
return NULL;
|
||||
@@ -106,7 +106,7 @@ char* get_filename_ext(char* filename) {
|
||||
* @param next The next token
|
||||
* @return char* The next token
|
||||
*/
|
||||
char* get_next_token(char* input, const char* delimiters, char** next) {
|
||||
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next) {
|
||||
if (input == NULL) {
|
||||
input = *next;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,51 @@ extern "C" {
|
||||
#include "tcp_cmd.h"
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_cmd_remove_newline) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
strcpy(cmd, "help\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "help");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "help\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\nhelp\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhel\np\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_data_cb) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
std::string output;
|
||||
|
||||
Reference in New Issue
Block a user