blob: 0cdb965bfff7c5aca10769cf4d94155777b5c86f [file] [log] [blame]
Girish Gowdrae538dfd2019-09-30 11:07:30 +05301/*
2 Copyright (C) 2018 Open Networking Foundation
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "gtest/gtest.h"
18#include "bal_mocker.h"
19#include "core.h"
20
21class TestOltEnable : public ::testing::Test {
22 protected:
23 virtual void SetUp() {
24 }
25
26 virtual void TearDown() {
27 // Code here will be called immediately after each test
28 // (right before the destructor).
29 }
30};
31
32
33// Test Fixture for OltEnable
34
35// Test 1: OltEnableSuccess case
36TEST_F(TestOltEnable, OltEnableSuccess){
37 // NiceMock is used to suppress 'WillByDefault' return errors on using 'NiceMock'.
38 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
39 ::testing::NiceMock<BalMocker> balMock;
40 bcmos_errno host_init_res = BCM_ERR_OK;
41 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
42 bcmos_errno olt_oper_res = BCM_ERR_OK;
43
44 Status olt_enable_res;
45
46 // The 'EXPECT_CALL' will do strict validation of input parameters. This may not be relevant for
47 // the current test case. Use 'ON_CALL' instead.
48 // The ON_CALL results in WARNINGs when running tests. Use NickMock instead of directly using BalMocker.
49 // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#the-nice-the-strict-and-the-naggy-nicestrictnaggy
50 // In below tests '::testing::_' does no validation on argument.
51 ON_CALL(balMock, bcmolt_host_init(::testing::_)).WillByDefault(::testing::Return(host_init_res));
52 ON_CALL(balMock, bcmolt_cfg_get(::testing::_,::testing::_)).WillByDefault(::testing::Return(bal_cfg_get_res));
53 ON_CALL(balMock, bcmolt_oper_submit(::testing::_, ::testing::_)).WillByDefault(::testing::Return(olt_oper_res));
54
55 olt_enable_res = Enable_(1, NULL);
56 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
57}
58
Girish Gowdrad18f0d32019-10-11 20:46:15 +053059// Test 2: OltEnableFail_host_init_fail
60TEST_F(TestOltEnable, OltEnableFail_host_init_fail) {
61 // NiceMock is used to suppress 'WillByDefault' return errors on using 'NiceMock'.
62 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
63 ::testing::NiceMock<BalMocker> balMock;
64 bcmos_errno host_init_res = BCM_ERR_INTERNAL;
65 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
66 bcmos_errno olt_oper_res = BCM_ERR_OK;
67
68 Status olt_enable_res;
69
70 // The 'EXPECT_CALL' will do strict validation of input parameters. This may not be relevant for
71 // the current test case. Use 'ON_CALL' instead.
72 // The ON_CALL results in WARNINGs when running tests. Use NickMock instead of directly using BalMocker.
73 // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#the-nice-the-strict-and-the-naggy-nicestrictnaggy
74 // In below tests '::testing::_' does no validation on argument.
75 ON_CALL(balMock, bcmolt_host_init(::testing::_)).WillByDefault(::testing::Return(host_init_res));
76 ON_CALL(balMock, bcmolt_cfg_get(::testing::_,::testing::_)).WillByDefault(::testing::Return(bal_cfg_get_res));
77 ON_CALL(balMock, bcmolt_oper_submit(::testing::_, ::testing::_)).WillByDefault(::testing::Return(olt_oper_res));
78
79 olt_enable_res = Enable_(1, NULL);
80 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
81}
82
83// Test 3: OltEnableSuccess_PON_Device_Connected
84TEST_F(TestOltEnable, OltEnableSuccess_PON_Device_Connected) {
85 // NiceMock is used to suppress 'WillByDefault' return errors on using 'NiceMock'.
86 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
87 ::testing::NiceMock<BalMocker> balMock;
88 bcmos_errno host_init_res = BCM_ERR_OK;
89 bcmos_errno bal_cfg_get_res = BCM_ERR_OK;
90
91 Status olt_enable_res;
92
93 // The 'EXPECT_CALL' will do strict validation of input parameters. This may not be relevant for
94 // the current test case. Use 'ON_CALL' instead.
95 // The ON_CALL results in WARNINGs when running tests. Use NickMock instead of directly using BalMocker.
96 // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#the-nice-the-strict-and-the-naggy-nicestrictnaggy
97 // In below tests '::testing::_' does no validation on argument.
98 ON_CALL(balMock, bcmolt_host_init(::testing::_)).WillByDefault(::testing::Return(host_init_res));
99 ON_CALL(balMock, bcmolt_cfg_get(::testing::_,::testing::_)).WillByDefault(::testing::Return(bal_cfg_get_res));
100
101 olt_enable_res = Enable_(1, NULL);
102 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
103}
104
105// Test 4: OltEnableFail_All_PON_Enable_Fail
106TEST_F(TestOltEnable, OltEnableFail_All_PON_Enable_Fail) {
107 // NiceMock is used to suppress 'WillByDefault' return errors on using 'NiceMock'.
108 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
109 ::testing::NiceMock<BalMocker> balMock;
110 bcmos_errno host_init_res = BCM_ERR_OK;
111 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
112 bcmos_errno olt_oper_res = BCM_ERR_INTERNAL;
113
114 Status olt_enable_res;
115
116 // Ensure that the state of the OLT is in deactivated to start with..
117 state.deactivate();
118
119 // The 'EXPECT_CALL' will do strict validation of input parameters. This may not be relevant for
120 // the current test case. Use 'ON_CALL' instead.
121 // The ON_CALL results in WARNINGs when running tests. Use NickMock instead of directly using BalMocker.
122 // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#the-nice-the-strict-and-the-naggy-nicestrictnaggy
123 // In below tests '::testing::_' does no validation on argument.
124 ON_CALL(balMock, bcmolt_host_init(::testing::_)).WillByDefault(::testing::Return(host_init_res));
125 ON_CALL(balMock, bcmolt_cfg_get(::testing::_,::testing::_)).WillByDefault(::testing::Return(bal_cfg_get_res));
126 ON_CALL(balMock, bcmolt_oper_submit(::testing::_, ::testing::_)).WillByDefault(::testing::Return(olt_oper_res));
127
128 olt_enable_res = Enable_(1, NULL);
129 ASSERT_TRUE( olt_enable_res.error_message() != Status::OK.error_message() );
130}
131
132// Test 5 OltEnableSuccess_One_PON_Enable_Fail : One PON device enable fails, but all others succeed.
133TEST_F(TestOltEnable, OltEnableSuccess_One_PON_Enable_Fail) {
134 // NiceMock is used to suppress 'WillByDefault' return errors on using 'NiceMock'.
135 // This is described in https://github.com/arangodb-helper/gtest/blob/master/googlemock/docs/CookBook.md
136 ::testing::NiceMock<BalMocker> balMock;
137 bcmos_errno host_init_res = BCM_ERR_OK;
138 bcmos_errno bal_cfg_get_res = BCM_ERR_NOT_CONNECTED;
139 bcmos_errno olt_oper_res_fail = BCM_ERR_INTERNAL;
140 bcmos_errno olt_oper_res_success = BCM_ERR_OK;
141
142 Status olt_enable_res;
143
144 // Ensure that the state of the OLT is in deactivated to start with..
145 state.deactivate();
146
147 // The 'EXPECT_CALL' will do strict validation of input parameters. This may not be relevant for
148 // the current test case. Use 'ON_CALL' instead.
149 // The ON_CALL results in WARNINGs when running tests. Use NickMock instead of directly using BalMocker.
150 // https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#the-nice-the-strict-and-the-naggy-nicestrictnaggy
151 // In below tests '::testing::_' does no validation on argument.
152 ON_CALL(balMock, bcmolt_host_init(::testing::_)).WillByDefault(::testing::Return(host_init_res));
153 ON_CALL(balMock, bcmolt_cfg_get(::testing::_,::testing::_)).WillByDefault(::testing::Return(bal_cfg_get_res));
154 // For the the first PON mac device, the activation result will fail, and will succeed for all other PON mac devices.
155 EXPECT_CALL(balMock, bcmolt_oper_submit(::testing::_, ::testing::_))
156 .WillOnce(::testing::Return(olt_oper_res_fail))
157 .WillRepeatedly(::testing::Return(olt_oper_res_success));
158
159 olt_enable_res = Enable_(1, NULL);
160 // The OLT activation should succeed if at least one PON mac device activation succeeds.
161 ASSERT_TRUE( olt_enable_res.error_message() == Status::OK.error_message() );
162}