blob: 01fa8515948719cdf48669da221d4964d7d20826 [file] [log] [blame]
Chaitrashree G Sfd15c8c2019-09-09 18:46:15 -04001/*
2 * Copyright 2018-present Open Networking Foundation
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 "gtest/gtest.h"
17#include "bal_mocker.h"
18#include "core.h"
19using namespace testing;
20using namespace std;
21int num_of_pon_ports = 16;
22
23// This is used to set custom bcmolt_cfg value to bcmolt_cfg pointer coming in
24// .bcmolt_cfg_get__olt_topology_stub
25ACTION_P(SetArg1ToBcmOltCfg, value) {*static_cast<bcmolt_olt_cfg*>(arg1) = value;};
26
27
28// Create a mock function for bcmolt_cfg_get__olt_topology_stub C++ function
29MOCK_GLOBAL_FUNC2(bcmolt_cfg_get__olt_topology_stub, bcmos_errno(bcmolt_oltid, void*));
30
31class TestOltDisableReenable : public Test {
32 protected:
33 virtual void SetUp() {
34 NiceMock<BalMocker> balMock;
35 bcmos_errno bal_cfg_get_stub_res = BCM_ERR_OK;
36
37 bcmolt_olt_cfg olt_cfg = { };
38 bcmolt_olt_key olt_key = { };
39
40 BCMOLT_CFG_INIT(&olt_cfg, olt, olt_key);
41
42 olt_cfg.data.topology.topology_maps.len = num_of_pon_ports;
43 EXPECT_GLOBAL_CALL(bcmolt_cfg_get__olt_topology_stub, bcmolt_cfg_get__olt_topology_stub(_, _))
44 .WillOnce(DoAll(SetArg1ToBcmOltCfg(olt_cfg), Return(bal_cfg_get_stub_res)));
45
46 ProbeDeviceCapabilities_();
47
48 }
49
50 virtual void TearDown() {
51 // Code here will be called immediately after each test
52 // (right before the destructor).
53 }
54};
55
56
57// Test Fixture for OltDisable
58
59// Test 1: OltDisableSuccess case
60TEST_F(TestOltDisableReenable, OltDisableSuccess){
61 // NiceMock is used to suppress 'WillByDefault' return errors.
62 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
63 NiceMock<BalMocker> balMock;
64 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
65
66 Status olt_disable_res;
67
68 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
69 .Times(num_of_pon_ports)
70 .WillRepeatedly(Return(bal_cfg_get_res));
71
72 olt_disable_res = Disable_();
73 ASSERT_TRUE( olt_disable_res.error_message() == Status::OK.error_message() );
74
75}
76
77// Test 2: OltDisableAllPonFailed case
78TEST_F(TestOltDisableReenable, OltDisableAllPonFailed){
79 // NiceMock is used to suppress 'WillByDefault' return errors.
80 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
81 NiceMock<BalMocker> balMock;
82 bcmos_errno bal_cfg_get_res = BCM_ERR_INTERNAL;
83
84 Status olt_disable_res;
85
86 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
87 .Times(num_of_pon_ports)
88 .WillRepeatedly(Return(bal_cfg_get_res));
89
90 olt_disable_res = Disable_();
91 ASSERT_TRUE( olt_disable_res.error_code() == grpc::StatusCode::INTERNAL);
92}
93
94
95// Test Fixture for OltReenable
96
97// Test 1: OltReenableSuccess case
98TEST_F(TestOltDisableReenable, OltReenableSuccess){
99 // NiceMock is used to suppress 'WillByDefault' return errors.
100 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
101 NiceMock<BalMocker> balMock;
102 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
103
104 Status olt_reenable_res;
105
106 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
107 .Times(num_of_pon_ports*2)
108 .WillRepeatedly(Return(bal_cfg_get_res));
109
110 olt_reenable_res = Reenable_();
111 ASSERT_TRUE( olt_reenable_res.error_message() == Status::OK.error_message() );
112
113}
114
115// Test 2: OltReenableAllPonFailed case
116TEST_F(TestOltDisableReenable, OltReenableAllPonFailed){
117 // NiceMock is used to suppress 'WillByDefault' return errors.
118 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
119 NiceMock<BalMocker> balMock;
120 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
121 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
122
123 Status olt_reenable_res;
124
125 EXPECT_CALL(balMock, bcmolt_cfg_get(_, _))
126 .Times(num_of_pon_ports)
127 .WillRepeatedly(Return(bal_cfg_get_res));
128 EXPECT_CALL(balMock,bcmolt_oper_submit(_, _))
129 .Times(num_of_pon_ports)
130 .WillRepeatedly(Return(olt_oper_res));
131 olt_reenable_res = Reenable_();
132 ASSERT_TRUE( olt_reenable_res.error_code() == grpc::StatusCode::INTERNAL);
133}
134