Darin Petkov | ca432fc | 2011-07-08 15:56:57 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <sys/socket.h> |
| 6 | #include <linux/netlink.h> |
| 7 | |
| 8 | #include <base/callback_old.h> |
| 9 | #include <base/memory/scoped_ptr.h> |
| 10 | #include <gmock/gmock.h> |
| 11 | #include <gtest/gtest.h> |
| 12 | |
| 13 | #include "shill/rtnl_handler.h" |
| 14 | #include "shill/rtnl_listener.h" |
| 15 | |
| 16 | using testing::_; |
| 17 | using testing::Test; |
| 18 | |
| 19 | namespace shill { |
| 20 | |
| 21 | class RTNLListenerTest : public Test { |
| 22 | public: |
| 23 | RTNLListenerTest() |
| 24 | : callback_(NewCallback(this, &RTNLListenerTest::Callback)) {} |
| 25 | |
| 26 | MOCK_METHOD1(Callback, void(struct nlmsghdr *)); |
| 27 | |
| 28 | protected: |
| 29 | scoped_ptr<Callback1<struct nlmsghdr *>::Type> callback_; |
| 30 | }; |
| 31 | |
| 32 | TEST_F(RTNLListenerTest, NoRun) { |
| 33 | { |
| 34 | RTNLListener listener(RTNLHandler::kRequestAddr, callback_.get()); |
| 35 | EXPECT_EQ(1, RTNLHandler::GetInstance()->listeners_.size()); |
| 36 | struct nlmsghdr message; |
| 37 | EXPECT_CALL(*this, Callback(_)).Times(0); |
| 38 | listener.NotifyEvent(RTNLHandler::kRequestLink, &message); |
| 39 | } |
| 40 | EXPECT_EQ(0, RTNLHandler::GetInstance()->listeners_.size()); |
| 41 | } |
| 42 | |
| 43 | TEST_F(RTNLListenerTest, Run) { |
| 44 | { |
| 45 | RTNLListener listener( |
| 46 | RTNLHandler::kRequestLink | RTNLHandler::kRequestAddr, |
| 47 | callback_.get()); |
| 48 | EXPECT_EQ(1, RTNLHandler::GetInstance()->listeners_.size()); |
| 49 | struct nlmsghdr message; |
| 50 | EXPECT_CALL(*this, Callback(&message)).Times(1); |
| 51 | listener.NotifyEvent(RTNLHandler::kRequestLink, &message); |
| 52 | } |
| 53 | EXPECT_EQ(0, RTNLHandler::GetInstance()->listeners_.size()); |
| 54 | } |
| 55 | |
| 56 | } // namespace shill |