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;
|
|
|
|
|
|
}
|