Skip to content

Commit

Permalink
AI automatically translates all annotation content into English
Browse files Browse the repository at this point in the history
  • Loading branch information
alexliyu7352 committed Sep 12, 2024
1 parent 53e7dec commit 6a7c50f
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 160 deletions.
30 changes: 20 additions & 10 deletions tests/test_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
using namespace std;
using namespace toolkit;

//测试onCreate和onDestory同时存在
//测试onCreate和onDestory同时存在 [AUTO-TRANSLATED:152351be]
// Test when both onCreate and onDestroy exist
class TestA {
public:
TestA() {
Expand All @@ -33,7 +34,8 @@ class TestA {
}
};

//测试只存在onCreate
//测试只存在onCreate [AUTO-TRANSLATED:721019f3]
// Test when only onCreate exists
class TestB {
public:
TestB() {
Expand All @@ -49,7 +51,8 @@ class TestB {
}
};

//测试只存在onDestory
//测试只存在onDestory [AUTO-TRANSLATED:65090f10]
// Test when only onDestroy exists
class TestC {
public:
TestC() {
Expand All @@ -65,7 +68,8 @@ class TestC {
}
};

//测试onCreate和onDestory返回值不为void时
//测试onCreate和onDestory返回值不为void时 [AUTO-TRANSLATED:cafa864e]
// Test when onCreate and onDestroy return values are not void
class TestD {
public:
TestD() {
Expand All @@ -87,7 +91,8 @@ class TestD {
}
};

//测试onCreate和onDestory都不存在时
//测试onCreate和onDestory都不存在时 [AUTO-TRANSLATED:475fb8f1]
// Test when neither onCreate nor onDestroy exist
class TestE {
public:
TestE() {
Expand All @@ -99,7 +104,8 @@ class TestE {
}
};

//测试自定义构造函数
//测试自定义构造函数 [AUTO-TRANSLATED:13ffcdcf]
// Test custom constructor
class TestF {
public:
TestF(int a, const char *b) {
Expand All @@ -111,7 +117,8 @@ class TestF {
}
};

//测试自定义onCreate函数
//测试自定义onCreate函数 [AUTO-TRANSLATED:35c11999]
// Test custom onCreate function
class TestH {
public:
TestH() {
Expand All @@ -128,7 +135,8 @@ class TestH {
}
};

//测试onDestory函数抛异常
//测试onDestory函数抛异常 [AUTO-TRANSLATED:6d70c971]
// Test onDestroy function throws an exception
class TestI {
public:
TestI() {
Expand All @@ -145,7 +153,8 @@ class TestI {
}
};

//测试自定义onDestory,onDestory将被忽略调用
//测试自定义onDestory,onDestory将被忽略调用 [AUTO-TRANSLATED:5ab2ba7d]
// Test custom onDestroy, onDestroy will be ignored when called
class TestJ {
public:
TestJ() {
Expand All @@ -162,7 +171,8 @@ class TestJ {
};

int main() {
//初始化日志系统
//初始化日志系统 [AUTO-TRANSLATED:25c549de]
// Initialize the logging system
Logger::Instance().add(std::make_shared<ConsoleChannel>());
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());

Expand Down
6 changes: 4 additions & 2 deletions tests/test_delayTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ using namespace std;
using namespace toolkit;

int main() {
//设置日志
//设置日志 [AUTO-TRANSLATED:50372045]
// Set log
Logger::Instance().add(std::make_shared<ConsoleChannel>());
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());

Expand Down Expand Up @@ -64,7 +65,8 @@ int main() {
tag1->cancel();
WarnL << "取消task 0、1";

//退出程序事件处理
//退出程序事件处理 [AUTO-TRANSLATED:80065cb7]
// Exit program event handling
static semaphore sem;
signal(SIGINT, [](int) { sem.post(); });// 设置退出信号
sem.wait();
Expand Down
7 changes: 6 additions & 1 deletion tests/test_eventPoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ using namespace toolkit;
/**
* cpu负载均衡测试
* @return
* CPU load balancing test
* @return
* [AUTO-TRANSLATED:620fe7ab]
*/
int main() {
static bool exit_flag = false;
signal(SIGINT, [](int) { exit_flag = true; });
//设置日志
//设置日志 [AUTO-TRANSLATED:50372045]
// Set log
Logger::Instance().add(std::make_shared<ConsoleChannel>());

Ticker ticker;
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ using namespace std;
using namespace toolkit;

int main() {
//初始化日志系统
//初始化日志系统 [AUTO-TRANSLATED:25c549de]
// Initialize the logging system
Logger::Instance().add(std::make_shared<ConsoleChannel> ());
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
mINI ini;
Expand Down
15 changes: 10 additions & 5 deletions tests/test_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class TestLog
};
~TestLog(){};

//通过此友元方法,可以打印自定义数据类型
//通过此友元方法,可以打印自定义数据类型 [AUTO-TRANSLATED:f9d17d41]
// Through this friend method, you can print custom data types
friend ostream& operator<<(ostream& out,const TestLog& obj){
return out << obj._ss.str();
}
Expand All @@ -32,27 +33,31 @@ class TestLog
};

int main() {
//初始化日志系统
//初始化日志系统 [AUTO-TRANSLATED:25c549de]
// Initialize the logging system
Logger::Instance().add(std::make_shared<ConsoleChannel> ());
Logger::Instance().add(std::make_shared<FileChannel>());
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());

InfoL << "测试std::cout风格打印:";
//ostream支持的数据类型都支持,可以通过友元的方式打印自定义类型数据
//ostream支持的数据类型都支持,可以通过友元的方式打印自定义类型数据 [AUTO-TRANSLATED:c857af94]
// All data types supported by ostream are supported, and custom type data can be printed through friend methods
TraceL << "object int"<< TestLog((int)1) << endl;
DebugL << "object short:"<<TestLog((short)2) << endl;
InfoL << "object float:" << TestLog((float)3.12345678) << endl;
WarnL << "object double:" << TestLog((double)4.12345678901234567) << endl;
ErrorL << "object void *:" << TestLog((void *)0x12345678) << endl;
ErrorL << "object string:" << TestLog("test string") << endl;

//这是ostream原生支持的数据类型
//这是ostream原生支持的数据类型 [AUTO-TRANSLATED:c431abc8]
// These are the data types natively supported by ostream
TraceL << "int"<< (int)1 << endl;
DebugL << "short:"<< (short)2 << endl;
InfoL << "float:" << (float)3.12345678 << endl;
WarnL << "double:" << (double)4.12345678901234567 << endl;
ErrorL << "void *:" << (void *)0x12345678 << endl;
//根据RAII的原理,此处不需要输入 endl,也会在被函数栈pop时打印log
//根据RAII的原理,此处不需要输入 endl,也会在被函数栈pop时打印log [AUTO-TRANSLATED:1ca0e0f7]
// Based on the RAII principle, there is no need to input endl here, and the log will be printed when the function is popped from the stack
ErrorL << "without endl!";

PrintI("测试printf风格打印:");
Expand Down
30 changes: 20 additions & 10 deletions tests/test_noticeCenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@
using namespace std;
using namespace toolkit;

//广播名称1
//广播名称1 [AUTO-TRANSLATED:a6c535ee]
// Broadcast Name 1
#define NOTICE_NAME1 "NOTICE_NAME1"
//广播名称2
//广播名称2 [AUTO-TRANSLATED:50cd7f16]
// Broadcast Name 2
#define NOTICE_NAME2 "NOTICE_NAME2"

//程序退出标记
//程序退出标记 [AUTO-TRANSLATED:2fc12083]
// Program Exit Flag
bool g_bExitFlag = false;


int main() {
//设置程序退出信号处理函数
//设置程序退出信号处理函数 [AUTO-TRANSLATED:419fb1c3]
// Set Program Exit Signal Handler
signal(SIGINT, [](int){g_bExitFlag = true;});
//设置日志
//设置日志 [AUTO-TRANSLATED:50372045]
// Set Log
Logger::Instance().add(std::make_shared<ConsoleChannel>());

//对事件NOTICE_NAME1新增一个监听
//addListener方法第一个参数是标签,用来删除监听时使用
//需要注意的是监听回调的参数列表个数类型需要与emitEvent广播时的完全一致,否则会有无法预知的错误
//对事件NOTICE_NAME1新增一个监听 [AUTO-TRANSLATED:c8e83e55]
// Add a Listener to the Event NOTICE_NAME1
//addListener方法第一个参数是标签,用来删除监听时使用 [AUTO-TRANSLATED:918a506c]
// The First Parameter of the addListener Method is a Tag, Used to Delete the Listener
//需要注意的是监听回调的参数列表个数类型需要与emitEvent广播时的完全一致,否则会有无法预知的错误 [AUTO-TRANSLATED:b36668f5]
// Note that the Number and Type of Parameters in the Listener Callback Must be Exactly the Same as Those in the emitEvent Broadcast, Otherwise Unpredictable Errors May Occur
NoticeCenter::Instance().addListener(0,NOTICE_NAME1,
[](int &a,const char * &b,double &c,string &d){
DebugL << a << " " << b << " " << c << " " << d;
Expand All @@ -44,7 +52,8 @@ int main() {
});
});

//监听NOTICE_NAME2事件
//监听NOTICE_NAME2事件 [AUTO-TRANSLATED:36bfaf8a]
// Listen for the NOTICE_NAME2 Event
NoticeCenter::Instance().addListener(0,NOTICE_NAME2,
[](string &d,double &c,const char *&b,int &a){
DebugL << a << " " << b << " " << c << " " << d;
Expand All @@ -61,7 +70,8 @@ int main() {
const char *b = "b";
double c = 3.14;
string d("d");
//每隔1秒广播一次事件,如果无法确定参数类型,可加强制转换
//每隔1秒广播一次事件,如果无法确定参数类型,可加强制转换 [AUTO-TRANSLATED:dc815907]
// Broadcast the Event Every 1 Second, If the Parameter Type is Uncertain, a Forced Conversion Can be Added
NoticeCenter::Instance().emitEvent(NOTICE_NAME1,++a,(const char *)"b",c,d);
NoticeCenter::Instance().emitEvent(NOTICE_NAME2,d,c,b,a);
sleep(1); // sleep 1 second
Expand Down
33 changes: 23 additions & 10 deletions tests/test_pingpong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ using namespace toolkit;

/**
* 回显会话
* Echo Session
* [AUTO-TRANSLATED:bc2a4e9e]
*/
class EchoSession : public Session {
public:
Expand All @@ -41,29 +44,37 @@ class EchoSession : public Session {
void onManager() override {}
};

//命令(http)
//命令(http) [AUTO-TRANSLATED:d96c7331]
// Command (http)
class CMD_pingpong: public CMD {
public:
CMD_pingpong(){
_parser.reset(new OptionParser(nullptr));
(*_parser) << Option('l', "listen", Option::ArgRequired, "10000", false, "服务器模式:监听端口", nullptr);
//测试客户端个数,默认10个
//测试客户端个数,默认10个 [AUTO-TRANSLATED:5a5a229a]
// Test client count, default 10
(*_parser) << Option('c', "count", Option::ArgRequired, to_string(10).data(), false, "客户端模式:测试客户端个数", nullptr);
//默认每次发送1MB的数据
//默认每次发送1MB的数据 [AUTO-TRANSLATED:22373e35]
// Default send 1MB data each time
(*_parser) << Option('b', "block", Option::ArgRequired, to_string(1024 * 1024).data(), false, "客户端模式:测试数据块大小", nullptr);
//默认1秒发送10次,总速度率为1MB/s * 10 * 10 = 100MB/s
//默认1秒发送10次,总速度率为1MB/s * 10 * 10 = 100MB/s [AUTO-TRANSLATED:d3b7bb36]
// Default send 10 times per second, total speed rate is 1MB/s * 10 * 10 = 100MB/s
(*_parser) << Option('i', "interval", Option::ArgRequired, to_string(100).data(), false, "客户端模式:测试数据发送间隔,单位毫秒", nullptr);
//客户端启动间隔时间
//客户端启动间隔时间 [AUTO-TRANSLATED:b401adf1]
// Client startup interval time
(*_parser) << Option('d', "delay", Option::ArgRequired, "50", false, "服务器模式:客户端启动间隔时间", nullptr);

//指定服务器地址
//指定服务器地址 [AUTO-TRANSLATED:867c9c2d]
// Specify server address
(*_parser) << Option('s', "server", Option::ArgRequired, "127.0.0.1:10000", false, "客户端模式:测试服务器地址", []
(const std::shared_ptr<ostream> &stream, const string &arg) {
if (arg.find(":") == string::npos) {
//中断后续选项的解析以及解析完毕回调等操作
//中断后续选项的解析以及解析完毕回调等操作 [AUTO-TRANSLATED:15b7592f]
// Interrupt subsequent option parsing and parsing completion callback, etc.
throw std::runtime_error("\t地址必须指明端口号.");
}
//如果返回false则忽略后续选项的解析
//如果返回false则忽略后续选项的解析 [AUTO-TRANSLATED:01a3d6bc]
// If return false, ignore subsequent option parsing
return true;
});
}
Expand Down Expand Up @@ -100,7 +111,8 @@ int main(int argc,char *argv[]){
return 0;
}

//初始化环境
//初始化环境 [AUTO-TRANSLATED:efbad911]
// Initialize environment
Logger::Instance().add(std::shared_ptr<ConsoleChannel>(new ConsoleChannel()));
Logger::Instance().setWriter(std::shared_ptr<LogWriter>(new AsyncLogWriter()));

Expand Down Expand Up @@ -146,7 +158,8 @@ int main(int argc,char *argv[]){
usleep(delay * 1000);
}

//设置退出信号处理函数
//设置退出信号处理函数 [AUTO-TRANSLATED:4f047770]
// Set exit signal handling function
static semaphore sem;
signal(SIGINT, [](int) { sem.post(); });// 设置退出信号
sem.wait();
Expand Down
24 changes: 16 additions & 8 deletions tests/test_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,45 @@ using namespace std;
using namespace toolkit;

int main() {
//设置日志
//设置日志 [AUTO-TRANSLATED:50372045]
// Set up logging
Logger::Instance().add(std::make_shared<ConsoleChannel>());
#if defined(_WIN32)
ErrorL << "该测试程序不能再windows下运行,因为我不会windows下的多进程编程,但是管道模块是可以在windows下正常工作的。" << endl;
#else
//获取父进程的PID
//获取父进程的PID [AUTO-TRANSLATED:0a35f39a]
// Get the parent process's PID
auto parentPid = getpid();
InfoL << "parent pid:" << parentPid << endl;

//定义一个管道,lambada类型的参数是管道收到数据的回调
//定义一个管道,lambada类型的参数是管道收到数据的回调 [AUTO-TRANSLATED:d5eeb28a]
// Define a pipe, with a lambda type parameter as the callback for when data is received
Pipe pipe([](int size,const char *buf) {
//该管道有数据可读了
//该管道有数据可读了 [AUTO-TRANSLATED:e542256f]
// The pipe has data available for reading
InfoL << getpid() << " recv:" << buf;
});

//创建子进程
//创建子进程 [AUTO-TRANSLATED:8d5746fc]
// Create a child process
auto pid = fork();

if (pid == 0) {
//子进程
//子进程 [AUTO-TRANSLATED:3f793797]
// Child process
int i = 10;
while (i--) {
//在子进程每隔一秒把数据写入管道,共计发送10次
//在子进程每隔一秒把数据写入管道,共计发送10次 [AUTO-TRANSLATED:5a340f4b]
// In the child process, write data to the pipe every second, for a total of 10 times
sleep(1);
string msg = StrPrinter << "message " << i << " form subprocess:" << getpid();
DebugL << "子进程发送:" << msg << endl;
pipe.send(msg.data(), msg.size());
}
DebugL << "子进程退出" << endl;
} else {
//父进程设置退出信号处理函数
//父进程设置退出信号处理函数 [AUTO-TRANSLATED:b2a0b432]
// Parent process sets up exit signal handling function
static semaphore sem;
signal(SIGINT, [](int) { sem.post(); });// 设置退出信号
sem.wait();
Expand Down
Loading

0 comments on commit 6a7c50f

Please sign in to comment.