test_module.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <cstdlib>
  22. #include <ctime>
  23. #include <iostream>
  24. #include <memory>
  25. #include <string>
  26. #include <unordered_map>
  27. #include <vector>
  28. #include "cnstream_module.hpp"
  29. #include "cnstream_pipeline.hpp"
  30. namespace cnstream {
  31. const EventType T_type = EventType::EVENT_WARNING;
  32. const char *T_messgge = "test_post_event";
  33. class TestModuleBase : public Module {
  34. public:
  35. TestModuleBase() : Module("test-module-base") {}
  36. ~TestModuleBase() {}
  37. bool Open(ModuleParamSet set) { return true; }
  38. void Close() {}
  39. int Process(std::shared_ptr<CNFrameInfo> data) { return 0; }
  40. };
  41. class TestModuleBaseEx : public ModuleEx {
  42. public:
  43. TestModuleBaseEx() : ModuleEx("test-module-base") {}
  44. ~TestModuleBaseEx() {}
  45. bool Open(ModuleParamSet set) { return true; }
  46. void Close() {}
  47. int Process(std::shared_ptr<CNFrameInfo> data) { return 0; }
  48. };
  49. TEST(CoreModule, OpenCloseProcess) {
  50. TestModuleBase module;
  51. ModuleParamSet params;
  52. EXPECT_TRUE(module.Open(params));
  53. module.Close();
  54. module.Process(nullptr);
  55. }
  56. TEST(CoreModule, TransmitAttr) {
  57. TestModuleBase module;
  58. EXPECT_FALSE(module.HasTransmit());
  59. TestModuleBaseEx module_ex;
  60. EXPECT_TRUE(module_ex.HasTransmit());
  61. }
  62. TEST(CoreModule, postevent) {
  63. Pipeline pipe("pipe");
  64. std::shared_ptr<TestModuleBase> ptr(new (TestModuleBase));
  65. ModuleParamSet parames;
  66. ASSERT_TRUE(ptr->Open(parames));
  67. ptr->SetContainer(&pipe);
  68. pipe.Start();
  69. EXPECT_TRUE(ptr->PostEvent(T_type, T_messgge));
  70. pipe.Stop();
  71. }
  72. } // namespace cnstream