1c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Copyright (C) 2013 The Android Open Source Project 3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Licensed under the Apache License, Version 2.0 (the "License"); 5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// you may not use this file except in compliance with the License. 6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// You may obtain a copy of the License at 7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// http://www.apache.org/licenses/LICENSE-2.0 9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Unless required by applicable law or agreed to in writing, software 11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// distributed under the License is distributed on an "AS IS" BASIS, 12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// See the License for the specific language governing permissions and 14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// limitations under the License. 15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// 1643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 17c54afe521739065a5d77e7c049acdb5e603f0592Ben Chan#include "shill/cellular/subscription_state_out_of_credits_detector.h" 1843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 19c20ed13f5c0e87e7a5164d1b5330ccd99cced58fBen Chan#include <memory> 20c20ed13f5c0e87e7a5164d1b5330ccd99cced58fBen Chan 2143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include <gtest/gtest.h> 2243ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include "ModemManager/ModemManager.h" 2343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 24c54afe521739065a5d77e7c049acdb5e603f0592Ben Chan#include "shill/cellular/mock_cellular.h" 25c54afe521739065a5d77e7c049acdb5e603f0592Ben Chan#include "shill/cellular/mock_cellular_service.h" 26c54afe521739065a5d77e7c049acdb5e603f0592Ben Chan#include "shill/cellular/mock_modem_info.h" 2743ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include "shill/mock_connection.h" 2843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include "shill/mock_connection_health_checker.h" 2943ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include "shill/mock_device_info.h" 3043ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include "shill/mock_manager.h" 3143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le#include "shill/mock_traffic_monitor.h" 3205d87e34869f44473edc1eec25d2fe1110d777a7Peter Qiu#include "shill/test_event_dispatcher.h" 3343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 3443ce4d428d619bda64eea6d37534f02c179a1756Thieu Leusing testing::Mock; 3543ce4d428d619bda64eea6d37534f02c179a1756Thieu Leusing testing::NiceMock; 3643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 3743ce4d428d619bda64eea6d37534f02c179a1756Thieu Lenamespace shill { 3843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 3943ce4d428d619bda64eea6d37534f02c179a1756Thieu Leclass SubscriptionStateOutOfCreditsDetectorTest : public testing::Test { 4043ce4d428d619bda64eea6d37534f02c179a1756Thieu Le public: 4143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le SubscriptionStateOutOfCreditsDetectorTest() 42bad1c10ffd2d4ac14f7bd9f4ef6a8982e711f566mukesh agrawal : modem_info_(nullptr, &dispatcher_, &metrics_, &manager_), 4343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le device_info_(modem_info_.control_interface(), modem_info_.dispatcher(), 4443ce4d428d619bda64eea6d37534f02c179a1756Thieu Le modem_info_.metrics(), modem_info_.manager()), 4543ce4d428d619bda64eea6d37534f02c179a1756Thieu Le manager_(modem_info_.control_interface(), modem_info_.dispatcher(), 46bad1c10ffd2d4ac14f7bd9f4ef6a8982e711f566mukesh agrawal modem_info_.metrics()), 4743ce4d428d619bda64eea6d37534f02c179a1756Thieu Le metrics_(modem_info_.dispatcher()), 4843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le cellular_(new NiceMock<MockCellular>(&modem_info_, 4943ce4d428d619bda64eea6d37534f02c179a1756Thieu Le "usb0", 5043ce4d428d619bda64eea6d37534f02c179a1756Thieu Le kAddress, 5143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 3, 5243ce4d428d619bda64eea6d37534f02c179a1756Thieu Le Cellular::kTypeCDMA, 5343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le "", 54608ec29525f553d51f0a92e84176e3d4b45930a9Peter Qiu "")), 5543ce4d428d619bda64eea6d37534f02c179a1756Thieu Le service_(new NiceMock<MockCellularService>(&modem_info_, cellular_)), 5643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le connection_(new NiceMock<MockConnection>(&device_info_)), 5743ce4d428d619bda64eea6d37534f02c179a1756Thieu Le out_of_credits_detector_( 5843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le new SubscriptionStateOutOfCreditsDetector( 5943ce4d428d619bda64eea6d37534f02c179a1756Thieu Le modem_info_.dispatcher(), modem_info_.manager(), 600951ccbfca977a9cf218b2e4308aa26fb4d06ef9Alex Vakulenko modem_info_.metrics(), service_.get())) {} 6143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 6243ce4d428d619bda64eea6d37534f02c179a1756Thieu Le virtual void SetUp() { 6343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le service_->connection_ = connection_; 6443ce4d428d619bda64eea6d37534f02c179a1756Thieu Le cellular_->service_ = service_; 6543ce4d428d619bda64eea6d37534f02c179a1756Thieu Le service_->SetRoamingState(kRoamingStateHome); 6643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le } 6743ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 6843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le virtual void TearDown() { 69ea18c6c99743aeee9b2e544532ef9fe55dbd182dBen Chan cellular_->service_ = nullptr; // Break circular reference. 7043ce4d428d619bda64eea6d37534f02c179a1756Thieu Le } 7143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 7243ce4d428d619bda64eea6d37534f02c179a1756Thieu Le protected: 7343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le static const char kAddress[]; 7443ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 7505d87e34869f44473edc1eec25d2fe1110d777a7Peter Qiu EventDispatcherForTest dispatcher_; 7643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le MockModemInfo modem_info_; 7743ce4d428d619bda64eea6d37534f02c179a1756Thieu Le NiceMock<MockDeviceInfo> device_info_; 7843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le NiceMock<MockManager> manager_; 7943ce4d428d619bda64eea6d37534f02c179a1756Thieu Le NiceMock<MockMetrics> metrics_; 8043ce4d428d619bda64eea6d37534f02c179a1756Thieu Le scoped_refptr<NiceMock<MockCellular>> cellular_; 8143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le scoped_refptr<NiceMock<MockCellularService>> service_; 8243ce4d428d619bda64eea6d37534f02c179a1756Thieu Le scoped_refptr<NiceMock<MockConnection>> connection_; 83c20ed13f5c0e87e7a5164d1b5330ccd99cced58fBen Chan std::unique_ptr<SubscriptionStateOutOfCreditsDetector> 84c20ed13f5c0e87e7a5164d1b5330ccd99cced58fBen Chan out_of_credits_detector_; 8543ce4d428d619bda64eea6d37534f02c179a1756Thieu Le}; 8643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 8743ce4d428d619bda64eea6d37534f02c179a1756Thieu Leconst char 8843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le SubscriptionStateOutOfCreditsDetectorTest::kAddress[] = "000102030405"; 8943ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 9043ce4d428d619bda64eea6d37534f02c179a1756Thieu LeTEST_F(SubscriptionStateOutOfCreditsDetectorTest, OutOfCreditsDetection) { 9143ce4d428d619bda64eea6d37534f02c179a1756Thieu Le out_of_credits_detector_->NotifySubscriptionStateChanged( 9243ce4d428d619bda64eea6d37534f02c179a1756Thieu Le MM_MODEM_3GPP_SUBSCRIPTION_STATE_OUT_OF_DATA); 9343ce4d428d619bda64eea6d37534f02c179a1756Thieu Le EXPECT_TRUE(out_of_credits_detector_->out_of_credits()); 9443ce4d428d619bda64eea6d37534f02c179a1756Thieu Le out_of_credits_detector_->NotifySubscriptionStateChanged( 9543ce4d428d619bda64eea6d37534f02c179a1756Thieu Le MM_MODEM_3GPP_SUBSCRIPTION_STATE_PROVISIONED); 9643ce4d428d619bda64eea6d37534f02c179a1756Thieu Le EXPECT_FALSE(out_of_credits_detector_->out_of_credits()); 9743ce4d428d619bda64eea6d37534f02c179a1756Thieu Le} 9843ce4d428d619bda64eea6d37534f02c179a1756Thieu Le 9943ce4d428d619bda64eea6d37534f02c179a1756Thieu Le} // namespace shill 100