Index: l2tp_manager_test.cc |
diff --git a/l2tp_manager_test.cc b/l2tp_manager_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..76431c0484040f2c56aa4520949877a6b8eeb406 |
--- /dev/null |
+++ b/l2tp_manager_test.cc |
@@ -0,0 +1,121 @@ |
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromeos/process_mock.h" |
+#include "chromeos/test_helpers.h" |
+#include "gflags/gflags.h" |
+#include "gtest/gtest.h" |
+#include "vpn-manager/l2tp_manager.h" |
petkov
2011/03/04 18:42:56
add blank line
kmixter1
2011/03/05 02:48:59
Done.
|
+ |
+DECLARE_string(password); |
+DECLARE_string(pppd_plugin); |
+DECLARE_string(user); |
+ |
+using ::chromeos::ProcessMock; |
+using ::testing::_; |
+using ::testing::InSequence; |
+using ::testing::Return; |
+ |
+class L2tpManagerTest : public ::testing::Test { |
+ public: |
+ void SetUp() { |
+ test_path_ = FilePath("test"); |
+ ServiceManager::temp_path_ = test_path_; |
+ file_util::Delete(test_path_, true); |
+ file_util::CreateDirectory(test_path_); |
+ remote_ = "1.2.3.4"; |
+ control_path_ = test_path_.Append("control"); |
+ pppd_config_path_ = test_path_.Append("pppd.config"); |
+ l2tpd_ = new ProcessMock; |
+ l2tp_.l2tpd_.reset(l2tpd_); |
+ l2tp_.l2tpd_control_path_ = control_path_; |
+ FLAGS_pppd_plugin = ""; |
+ FLAGS_user = "me"; |
+ EXPECT_TRUE(l2tp_.Initialize(remote_)); |
+ } |
+ |
+ protected: |
+ std::string remote_; |
+ FilePath test_path_; |
+ FilePath control_path_; |
+ FilePath pppd_config_path_; |
+ L2tpManager l2tp_; |
+ ProcessMock* l2tpd_; |
+}; |
+ |
+TEST_F(L2tpManagerTest, FormatL2tpdConfiguration) { |
+ static const char kBaseExpected[] = |
+ "[lac managed]\n" |
+ "lns = 1.2.3.4\n" |
+ "require chap = yes\n" |
+ "refuse pap = yes\n" |
+ "require authentication = yes\n" |
+ "name = me\n" |
+ "ppp debug = yes\n" |
+ "pppoptfile = test/pppd.config\n" |
+ "length bit = yes\n"; |
+ EXPECT_EQ(kBaseExpected, |
+ l2tp_.FormatL2tpdConfiguration(pppd_config_path_.value())); |
+} |
+ |
+TEST_F(L2tpManagerTest, FormatPppdConfiguration) { |
+ const char kBaseExpected[] = |
+ "ipcp-accept-local\n" |
+ "ipcp-accept-remote\n" |
+ "refuse-eap\n" |
+ "noccp\n" |
+ "noauth\n" |
+ "crtscts\n" |
+ "idle 1800\n" |
+ "mtu 1410\n" |
+ "mru 1410\n" |
+ "nodefaultroute\n" |
+ "debug\n" |
+ "lock\n" |
+ "connect-delay 5000\n"; |
+ std::string expected(kBaseExpected); |
+ EXPECT_EQ(expected, l2tp_.FormatPppdConfiguration()); |
+ FLAGS_pppd_plugin = "myplugin"; |
+ expected.append("plugin myplugin\n"); |
+ EXPECT_EQ(expected, l2tp_.FormatPppdConfiguration()); |
+} |
+ |
+TEST_F(L2tpManagerTest, Initiate) { |
+ FLAGS_user = "me"; |
+ FLAGS_password = "password"; |
+ EXPECT_TRUE(l2tp_.Initiate()); |
+ ExpectFileEquals("c managed me password\n", control_path_.value().c_str()); |
+ FLAGS_pppd_plugin = "set"; |
+ EXPECT_TRUE(l2tp_.Initiate()); |
+ ExpectFileEquals("c managed\n", control_path_.value().c_str()); |
+} |
+ |
+TEST_F(L2tpManagerTest, Terminate) { |
+ EXPECT_TRUE(l2tp_.Terminate()); |
+ ExpectFileEquals("d managed\n", control_path_.value().c_str()); |
+} |
+ |
+TEST_F(L2tpManagerTest, Start) { |
+ InSequence unused; |
+ const int kMockFd = 567; |
+ |
+ EXPECT_CALL(*l2tpd_, Reset(0)); |
+ EXPECT_CALL(*l2tpd_, AddArg(L2TPD)); |
+ EXPECT_CALL(*l2tpd_, AddArg("-c")); |
+ EXPECT_CALL(*l2tpd_, AddArg("test/l2tpd.conf")); |
+ EXPECT_CALL(*l2tpd_, AddArg("-C")); |
+ EXPECT_CALL(*l2tpd_, AddArg("test/l2tpd.control")); |
+ EXPECT_CALL(*l2tpd_, AddArg("-D")); |
+ EXPECT_CALL(*l2tpd_, RedirectUsingPipe(STDERR_FILENO, false)); |
+ EXPECT_CALL(*l2tpd_, Start()); |
+ EXPECT_CALL(*l2tpd_, GetPipe(STDERR_FILENO)).WillOnce(Return(kMockFd)); |
+ |
+ EXPECT_TRUE(l2tp_.Start()); |
+ EXPECT_EQ(kMockFd, l2tp_.output_fd()); |
+} |
+ |
+int main(int argc, char** argv) { |
+ SetUpTests(&argc, argv, true); |
+ return RUN_ALL_TESTS(); |
+} |