blob: 31765006b985b09bd86b9caf0f19f05de51972b0 [file] [log] [blame]
Narayan Kamatha5ace892017-01-06 15:10:02 +00001/*
2 * Copyright 2017 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
17#include <string>
18
19#include <gtest/gtest.h>
20
21#include "IptablesRestoreController.h"
22#include "NetdConstants.h"
23
24class IptablesRestoreControllerHolder {
25public:
26 IptablesRestoreControllerHolder() {
27 IptablesRestoreController::installSignalHandler(&ctrl);
28 }
29
30 IptablesRestoreController ctrl;
31};
32
33IptablesRestoreControllerHolder holder;
34
35TEST(IptablesRestoreControllerTest, TestBasicCommand) {
36 IptablesRestoreController& con = holder.ctrl;
37 EXPECT_EQ(0, con.execute(IptablesTarget::V4, "#Test\n"));
38 EXPECT_EQ(0, con.execute(IptablesTarget::V4V6, "#Test\n"));
39 EXPECT_EQ(0, con.execute(IptablesTarget::V6, "#Test\n"));
40}
41
42TEST(IptablesRestoreControllerTest, TestRestartOnMalformedCommand) {
43 IptablesRestoreController& con = holder.ctrl;
44 EXPECT_EQ(-1, con.execute(IptablesTarget::V4V6, "malformed command\n"));
45 EXPECT_EQ(0, con.execute(IptablesTarget::V4V6, "#Test\n"));
46}