当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 1

zhuchen99899/sh-vm
关闭

forked from 李昂/sh-vm
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.cpp 6.11 KB
一键复制 编辑 原始数据 按行查看 历史
lyon 提交于 2021-03-19 00:57 . modefy
#include <iostream>
#include "mimiTest.h"
extern "C"
{
// tools
#include "mimiStr.h"
#include "mimiTest.h"
#include <string.h>
#include "dataLink.h"
// cores
#include "mimiSH_core.h"
#include "mimiVM_core.h"
// shApps
#include "shApp_argv.h"
#include "shApp_cmdNoFound.h"
#include "shApp_test.h"
// shDrivers
#include "shDriver_sendTo.h"
#include "shDriver_uart.h"
}
int shell_test_tool(char *cmd, int isShow)
{
sh_t *sh = ShellCore_init();
char *cmdOut;
unsigned short int cmdOutSize;
cmdOut = sh->cmd(sh, cmd);
cmdOutSize = strGetSize(cmdOut);
if (isShow)
{
std::cout << "cmdOut : " << std::endl
<< "<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
std::cout << cmdOut;
std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
std::cout << "The Size of cmdOut is : " << cmdOutSize << std::endl;
}
return cmdOutSize;
}
int TEST_sendTo(int isShow)
{
if (shell_test_tool((char *)"to com1 srting test", isShow) != 77)
{
return 1;
}
if (shell_test_tool((char *)"to com2 srting test 4iix", isShow) != 87)
{
return 2;
}
return 0;
}
int TEST_strGetArgs(int isShow)
{
char cmd[] = "test the str get args";
char *argv[16];
// sign in memory to argv
for (int i = 0; i < 16; i++)
{
argv[i] = (char *)malloc(sizeof(char) * 16);
}
int argc;
argc = strGetArgs(cmd, argv);
if (isShow)
{
for (int i = 0; i < argc; i++)
{
std::cout << argv[i] << std::endl;
}
}
if (strGetSize(argv[0]) != 4)
{
return 1;
}
if (strGetSize(argv[1]) != 3)
{
return 2;
}
if (strGetSize(argv[2]) != 3)
{
return 3;
}
for (int i = 0; i < 16; i++)
{
free(argv[i]);
}
return 0;
}
int TEST_app_argv_by_Shell(int isShow)
{
if (shell_test_tool((char *)"argv testtt", isShow) != 48)
{
return 1;
}
if (shell_test_tool((char *)"argv testtt afe ckx 123j 'Iz -34", isShow) != 135)
{
return 2;
}
return 0;
}
int TEST_app_argv(int isShow)
{
int argc = 4;
char *argv[] = {(char *)"a", (char *)"bcd", (char *)"efg", (char *)"hig"};
char *Strout;
Strout = app_argv_main(argc, argv);
int strOutSize = strGetSize(Strout);
if (isShow)
{
std::cout << "app test output: " << std::endl
<< "<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
std::cout << Strout << std::endl;
std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
std::cout << "The Size of cmdOut is : " << strOutSize << std::endl;
}
if (strOutSize != 50)
{
return 1;
}
return 0;
}
int TEST_BaseShellFunction(int isShow)
{
sh_t *sh = ShellCore_init();
unsigned short int cmdOutSize;
char cmd_1[] = "test testtt";
char cmd_2[] = "test open";
char cmd_3[] = "te";
for (int i = 0; i < 3; i++)
{
char *cmdOut;
if (i == 0)
{
cmdOut = sh->cmd(sh, cmd_1);
}
if (i == 1)
{
cmdOut = sh->cmd(sh, cmd_2);
}
if (i == 2)
{
cmdOut = sh->cmd(sh, cmd_3);
}
cmdOutSize = strGetSize(cmdOut);
if (isShow)
{
std::cout << "cmdOut : " << std::endl
<< "<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
std::cout << cmdOut;
std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
std::cout << "The Size of cmdOut is : " << cmdOutSize << std::endl;
}
if (i == 0)
{
if (cmdOutSize != 130)
{
return 1;
}
}
if (i == 1)
{
if (cmdOutSize != 82)
{
return 2;
}
}
if (i == 2)
{
if (cmdOutSize != 55)
{
return 3;
}
}
}
return 0;
}
struct VM_t *VM_simulator_main(int argc, char **argv)
{
sh_t *sh = ShellCore_init();
if ((strcmp(argv[0], "com1") == 0) || (strcmp(argv[0], "com2") == 0))
{
struct com_t *pcom;
int VM_IT_name;
if (0 == strcmp(argv[0], "com1"))
{
pcom = &VM.com1;
VM_IT_name = VM_IT_COM1;
}
if (0 == strcmp(argv[0], (char *)"com2"))
{
pcom = &VM.com2;
VM_IT_name = VM_IT_COM2;
}
char *strOut;
strOut = sh->cmd(sh, (char *)"uart init");
free(strOut);
char *VM_com_input = argv[1];
for (int i = 0; i < 1000; i++)
{
// simulate the VM_com data input with IT.
if (i < strGetSize(VM_com_input))
{
*VM_com_RX_Char_pget(pcom) = VM_com_input[i];
VM_IT(VM_IT_name);
}
VM_vIT();
VM_main();
}
return 0;
}
return NULL;
}
int TEST_singleLine_callBack(int isShow)
{
// char * argv[] = {"com1", "test ttfefe \r\ntest i\r\nargv fjeiow if io - \r\nto com1 tetr\r\nto com2 fiii\r\n"};
// char * argv[] = {"com2", "test ttfefe \r\ntest i\r\nargv fjeiow if io - \r\nto com1 tetr\r\nto com2 fiii\r\n"};
char *argv[] = {(char *)"com1", (char *)"to com2 test jjt\r\n"};
VM_simulator_main(2, argv);
return 0;
}
int TEST_dataLink(int isShow)
{
dataLink_t *Head;
Head = dataLink_init();
return Head->test(Head, isShow);
}
int TEST_Shellcore(int isShow)
{
sh_t *sh = ShellCore_init();
return sh->test(sh, isShow);
}
void test()
{
std::cout << "Test starting..." << std::endl
<< "================================" << std::endl;
ASSERT_RETURN(TEST_singleLine_callBack, 0);
ASSERT_RETURN(TEST_app_argv_by_Shell, 0);
ASSERT_RETURN(TEST_BaseShellFunction, 0);
ASSERT_RETURN(TEST_app_argv, 0);
ASSERT_RETURN(TEST_strGetArgs, 0);
ASSERT_RETURN(TEST_sendTo, 0);
ASSERT_RETURN(TEST_dataLink, 0);
ASSERT_RETURN(TEST_Shellcore, 0);
std::cout << "Test Finished! " << std::endl
<< "================================" << std::endl;
}
int main()
{
test();
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhuchen99899/sh-vm.git
git@gitee.com:zhuchen99899/sh-vm.git
zhuchen99899
sh-vm
sh-vm
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385