test_muxer_fix.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "code/muxer/muxer_file_muxer.h"
  2. #include "code/base/logger.h"
  3. #include <iostream>
  4. using namespace av::muxer;
  5. using namespace av;
  6. int main() {
  7. // 初始化日志
  8. Logger::instance().setLevel(LogLevel::DEBUG);
  9. std::cout << "测试 FileMuxer 初始化修复..." << std::endl;
  10. try {
  11. // 创建文件复用器
  12. FileMuxer muxer;
  13. // 测试1: 使用正确的 FileMuxerParams
  14. std::cout << "\n=== 测试1: 正确的 FileMuxerParams ===" << std::endl;
  15. FileMuxerParams correctParams;
  16. correctParams.type = MuxerType::FILE_MUXER;
  17. correctParams.outputPath = "./test_output.mp4";
  18. correctParams.outputFile = "./test_output.mp4";
  19. correctParams.format = "mp4";
  20. correctParams.overwrite = true;
  21. ErrorCode result = muxer.initialize(correctParams);
  22. if (result == ErrorCode::SUCCESS) {
  23. std::cout << "✓ 正确参数初始化成功!" << std::endl;
  24. } else {
  25. std::cout << "✗ 正确参数初始化失败,错误码: " << static_cast<int>(result) << std::endl;
  26. }
  27. muxer.close();
  28. // 测试2: 使用错误类型的 MuxerParams(基类)
  29. std::cout << "\n=== 测试2: 错误的 MuxerParams 类型 ===" << std::endl;
  30. MuxerParams wrongParams;
  31. wrongParams.type = MuxerType::FILE_MUXER; // 类型正确但实际是基类
  32. wrongParams.outputPath = "./test_output2.mp4";
  33. FileMuxer muxer2;
  34. result = muxer2.initialize(wrongParams);
  35. if (result != ErrorCode::SUCCESS) {
  36. std::cout << "✓ 错误参数类型被正确拒绝,错误码: " << static_cast<int>(result) << std::endl;
  37. } else {
  38. std::cout << "✗ 错误参数类型未被拒绝!" << std::endl;
  39. }
  40. // 测试3: 空输出路径
  41. std::cout << "\n=== 测试3: 空输出路径 ===" << std::endl;
  42. FileMuxerParams emptyPathParams;
  43. emptyPathParams.type = MuxerType::FILE_MUXER;
  44. emptyPathParams.outputPath = ""; // 空路径
  45. emptyPathParams.outputFile = ""; // 空文件
  46. FileMuxer muxer3;
  47. result = muxer3.initialize(emptyPathParams);
  48. if (result != ErrorCode::SUCCESS) {
  49. std::cout << "✓ 空路径参数被正确拒绝,错误码: " << static_cast<int>(result) << std::endl;
  50. } else {
  51. std::cout << "✗ 空路径参数未被拒绝!" << std::endl;
  52. }
  53. // 测试4: 错误的复用器类型
  54. std::cout << "\n=== 测试4: 错误的复用器类型 ===" << std::endl;
  55. FileMuxerParams wrongTypeParams;
  56. wrongTypeParams.type = MuxerType::STREAM_MUXER; // 错误的类型
  57. wrongTypeParams.outputPath = "./test_output4.mp4";
  58. FileMuxer muxer4;
  59. result = muxer4.initialize(wrongTypeParams);
  60. if (result != ErrorCode::SUCCESS) {
  61. std::cout << "✓ 错误复用器类型被正确拒绝,错误码: " << static_cast<int>(result) << std::endl;
  62. } else {
  63. std::cout << "✗ 错误复用器类型未被拒绝!" << std::endl;
  64. }
  65. } catch (const std::exception& e) {
  66. std::cout << "✗ 异常: " << e.what() << std::endl;
  67. return 1;
  68. }
  69. std::cout << "\n测试完成!" << std::endl;
  70. return 0;
  71. }