task_auto_plan/tests/basic_test.cpp

85 lines
2.3 KiB
C++
Raw Normal View History

2026-04-25 08:10:44 +00:00
/**
* @file basic_test.cpp
* @brief
*
*
* - TestPunchFunction: SRS-ATT_F-001
* - TestAutoCalculate: SRS-ATT_F-002
* - TestWarning: SRS-ATT_F-003
* - TestReport: SRS-ATT_F-004
* - TestThirdPartySync: SRS-ATT_F-005
*/
2026-04-25 03:15:03 +00:00
#include "app.hpp"
#include <cassert>
#include <iostream>
2026-04-25 08:10:44 +00:00
// 测试 SRS-ATT_F-001: 多终端打卡支持
void testPunchFunction() {
AttendanceSystem sys;
PunchRequest req;
req.employeeId = "EMP_TEST";
req.terminalType = "MOBILE";
req.timestamp = std::time(nullptr);
PunchResponse resp = sys.processPunch(req);
assert(resp.success);
std::cout << "TestPunchFunction passed.\n";
2026-04-25 03:15:03 +00:00
}
2026-04-25 08:10:44 +00:00
// 测试 SRS-ATT_F-002: 考勤数据自动核算(简单验证不崩溃)
void testAutoCalculate() {
AttendanceSystem sys;
// 正常情况下不应抛出异常
2026-04-25 03:15:03 +00:00
try {
2026-04-25 08:10:44 +00:00
sys.autoCalculateAttendance();
std::cout << "TestAutoCalculate passed.\n";
} catch (...) {
assert(false && "autoCalculate threw exception");
2026-04-25 03:15:03 +00:00
}
}
2026-04-25 08:10:44 +00:00
// 测试 SRS-ATT_F-003: 异常考勤预警(验证报警触发)
void testWarning() {
AttendanceSystem sys;
CalculationResult res;
res.employeeId = "EMP_WARN";
res.status = CalculationResult::LATE;
// 只需确保函数执行不崩溃
sys.sendWarningForAnomaly(res);
std::cout << "TestWarning passed.\n";
2026-04-25 03:15:03 +00:00
}
2026-04-25 08:10:44 +00:00
// 测试 SRS-ATT_F-004: 考勤报表生成导出
void testReport() {
AttendanceSystem sys;
ReportQuery query;
query.department = "TEST_DEPT";
query.startDate = 0;
query.endDate = std::time(nullptr);
query.format = ReportQuery::EXCEL;
ReportFile file = sys.generateReport(query);
assert(!file.fileName.empty());
std::cout << "TestReport passed.\n";
2026-04-25 03:15:03 +00:00
}
2026-04-25 08:10:44 +00:00
// 测试 SRS-ATT_F-005: 第三方系统集成
void testThirdPartySync() {
AttendanceSystem sys;
ThirdPartySyncRequest req;
req.apiKey = "VALID_API_KEY";
req.systemType = "HR";
SyncResponse resp = sys.syncWithThirdParty(req);
assert(resp.success);
std::cout << "TestThirdPartySync passed.\n";
2026-04-25 03:15:03 +00:00
}
int main() {
2026-04-25 08:10:44 +00:00
testPunchFunction();
testAutoCalculate();
testWarning();
testReport();
testThirdPartySync();
std::cout << "All tests passed!\n";
2026-04-25 03:15:03 +00:00
return 0;
}