test_report_generation.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <iostream>
  2. #include "config.h"
  3. #include "reporter.h"
  4. #include "rtsp_client.h"
  5. #include "scheduler.h"
  6. using namespace jtjai_media;
  7. int main() {
  8. std::cout << "测试报告生成功能" << std::endl;
  9. // 加载配置
  10. ConfigManager config_mgr;
  11. if (!config_mgr.load_from_file("/Users/wenhongquan/CLionProjects/jtjai_media/config.json")) {
  12. std::cerr << "无法加载配置文件" << std::endl;
  13. return 1;
  14. }
  15. // 创建一些模拟的统计数据
  16. std::vector<RTSPClientStats> mock_stats;
  17. // 模拟第一个流 - 不可用
  18. RTSPClientStats stats1;
  19. stats1.stream_index = 0;
  20. stats1.rtsp_url = "rtsp://test1.example.com:554/live/stream1";
  21. stats1.output_file = "./output/test_stream1.mp4";
  22. stats1.status = RTSPClientStatus::STREAM_UNAVAILABLE;
  23. stats1.error_message = "流不可用或地址错误";
  24. stats1.start_time = std::chrono::system_clock::now();
  25. stats1.end_time = stats1.start_time + std::chrono::seconds(3);
  26. stats1.duration_seconds = 15;
  27. stats1.bytes_received = 0;
  28. stats1.frames_received = 0;
  29. mock_stats.push_back(stats1);
  30. // 模拟第二个流 - 不可用
  31. RTSPClientStats stats2;
  32. stats2.stream_index = 1;
  33. stats2.rtsp_url = "rtsp://test2.example.com:554/live/stream2";
  34. stats2.output_file = "./output/test_stream2.mp4";
  35. stats2.status = RTSPClientStatus::STREAM_UNAVAILABLE;
  36. stats2.error_message = "流不可用或地址错误";
  37. stats2.start_time = std::chrono::system_clock::now();
  38. stats2.end_time = stats2.start_time + std::chrono::seconds(3);
  39. stats2.duration_seconds = 20;
  40. stats2.bytes_received = 0;
  41. stats2.frames_received = 0;
  42. mock_stats.push_back(stats2);
  43. // 创建调度器统计数据
  44. StreamScheduler::SchedulerStats scheduler_stats;
  45. scheduler_stats.total_tasks = 2;
  46. scheduler_stats.completed_tasks = 0;
  47. scheduler_stats.failed_tasks = 2;
  48. scheduler_stats.cancelled_tasks = 0;
  49. scheduler_stats.max_concurrent_used = 2;
  50. scheduler_stats.completion_rate = 0.0;
  51. scheduler_stats.start_time = std::chrono::system_clock::now();
  52. scheduler_stats.end_time = scheduler_stats.start_time + std::chrono::seconds(10);
  53. // 生成报告
  54. ResultReporter reporter(config_mgr);
  55. std::cout << "开始生成报告..." << std::endl;
  56. if (reporter.generate_report(mock_stats, scheduler_stats)) {
  57. std::cout << "报告生成成功!" << std::endl;
  58. } else {
  59. std::cout << "报告生成失败!" << std::endl;
  60. return 1;
  61. }
  62. return 0;
  63. }