test_discard_frame.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*************************************************************************
  2. * Copyright (C) [2019] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #include <gtest/gtest.h>
  21. #include <memory>
  22. #include "discard_frame.hpp"
  23. #include "test_base.hpp"
  24. namespace cnstream {
  25. static constexpr const char *gname = "discard_frame";
  26. TEST(DiscardFrame, Constructor) {
  27. std::shared_ptr<Module> discard_frame = std::make_shared<DiscardFrame>(gname);
  28. EXPECT_STREQ(discard_frame->GetName().c_str(), gname);
  29. // bool variable
  30. EXPECT_TRUE(discard_frame->HasTransmit());
  31. }
  32. TEST(DiscardFrame, OpenClose) {
  33. std::shared_ptr<Module> discard_frame = std::make_shared<DiscardFrame>(gname);
  34. ModuleParamSet param;
  35. // open null param
  36. param.clear();
  37. EXPECT_TRUE(discard_frame->Open(param));
  38. param.clear();
  39. param["discard_int"] = std::to_string(12);
  40. EXPECT_TRUE(discard_frame->Open(param));
  41. param["discard_interval"] = std::to_string(4);
  42. EXPECT_TRUE(discard_frame->Open(param));
  43. // send the error frameid
  44. param["discard_interval"] = std::to_string(-1);
  45. EXPECT_FALSE(discard_frame->Open(param));
  46. discard_frame->Close();
  47. }
  48. TEST(DiscardFrame, Process) {
  49. std::shared_ptr<Module> discard_frame = std::make_shared<DiscardFrame>(gname);
  50. ModuleParamSet param;
  51. auto data = cnstream::CNFrameInfo::Create(std::to_string(0));
  52. EXPECT_EQ(discard_frame->Process(data), 0);
  53. param["discard_interval"] = std::to_string(3);
  54. Pipeline Container("pipe");
  55. Container.Start();
  56. Container.AddModule(discard_frame);
  57. discard_frame->Open(param);
  58. EXPECT_EQ(discard_frame->Process(data), 1);
  59. Container.Stop();
  60. }
  61. } // namespace cnstream