action_pipe_unittest.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // Copyright (C) 2009 The Android Open Source Project
  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. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include "update_engine/common/action_pipe.h"
  17. #include <gtest/gtest.h>
  18. #include <string>
  19. #include "update_engine/common/action.h"
  20. using std::string;
  21. namespace chromeos_update_engine {
  22. using chromeos_update_engine::ActionPipe;
  23. class ActionPipeTestAction;
  24. template <>
  25. class ActionTraits<ActionPipeTestAction> {
  26. public:
  27. typedef string OutputObjectType;
  28. typedef string InputObjectType;
  29. };
  30. // This is a simple Action class for testing.
  31. class ActionPipeTestAction : public Action<ActionPipeTestAction> {
  32. public:
  33. typedef string InputObjectType;
  34. typedef string OutputObjectType;
  35. ActionPipe<string>* in_pipe() { return in_pipe_.get(); }
  36. ActionPipe<string>* out_pipe() { return out_pipe_.get(); }
  37. void PerformAction() {}
  38. string Type() const { return "ActionPipeTestAction"; }
  39. };
  40. class ActionPipeTest : public ::testing::Test {};
  41. // This test creates two simple Actions and sends a message via an ActionPipe
  42. // from one to the other.
  43. TEST(ActionPipeTest, SimpleTest) {
  44. ActionPipeTestAction a, b;
  45. BondActions(&a, &b);
  46. a.out_pipe()->set_contents("foo");
  47. EXPECT_EQ("foo", b.in_pipe()->contents());
  48. }
  49. } // namespace chromeos_update_engine