1 // 2 // Copyright (C) 2013 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 "shill/cellular/cellular_error.h" 18 19 #include <brillo/errors/error_codes.h> 20 #include <gtest/gtest.h> 21 22 namespace shill { 23 24 class CellularErrorTest : public testing::Test { 25 }; 26 27 namespace { 28 29 const char kErrorIncorrectPasswordMM[] = 30 "org.freedesktop.ModemManager.Modem.Gsm.IncorrectPassword"; 31 32 const char kErrorSimPinRequiredMM[] = 33 "org.freedesktop.ModemManager.Modem.Gsm.SimPinRequired"; 34 35 const char kErrorSimPukRequiredMM[] = 36 "org.freedesktop.ModemManager.Modem.Gsm.SimPukRequired"; 37 38 const char kErrorGprsNotSubscribedMM[] = 39 "org.freedesktop.ModemManager.Modem.Gsm.GprsNotSubscribed"; 40 41 const char kErrorIncorrectPasswordMM1[] = 42 "org.freedesktop.ModemManager1.Error.MobileEquipment.IncorrectPassword"; 43 44 const char kErrorSimPinMM1[] = 45 "org.freedesktop.ModemManager1.Error.MobileEquipment.SimPin"; 46 47 const char kErrorSimPukMM1[] = 48 "org.freedesktop.ModemManager1.Error.MobileEquipment.SimPuk"; 49 50 const char kErrorGprsNotSubscribedMM1[] = 51 "org.freedesktop.ModemManager1.Error.MobileEquipment." 52 "GprsServiceOptionNotSubscribed"; 53 54 const char kErrorWrongStateMM1[] = 55 "org.freedesktop.ModemManager1.Error.Core.WrongState"; 56 57 58 const char kErrorMessage[] = "Some error message."; 59 60 } // namespace 61 62 TEST_F(CellularErrorTest, FromDBusError) { 63 Error shill_error; 64 65 CellularError::FromChromeosDBusError(nullptr, nullptr); 66 EXPECT_TRUE(shill_error.IsSuccess()); 67 68 { 69 brillo::ErrorPtr dbus_error = 70 brillo::Error::Create(FROM_HERE, 71 brillo::errors::dbus::kDomain, 72 kErrorIncorrectPasswordMM, 73 kErrorMessage); 74 CellularError::FromChromeosDBusError(dbus_error.get(), &shill_error); 75 EXPECT_EQ(Error::kIncorrectPin, shill_error.type()); 76 } 77 { 78 brillo::ErrorPtr dbus_error = 79 brillo::Error::Create(FROM_HERE, 80 brillo::errors::dbus::kDomain, 81 kErrorSimPinRequiredMM, 82 kErrorMessage); 83 CellularError::FromChromeosDBusError(dbus_error.get(), &shill_error); 84 EXPECT_EQ(Error::kPinRequired, shill_error.type()); 85 } 86 { 87 brillo::ErrorPtr dbus_error = 88 brillo::Error::Create(FROM_HERE, 89 brillo::errors::dbus::kDomain, 90 kErrorSimPukRequiredMM, 91 kErrorMessage); 92 CellularError::FromChromeosDBusError(dbus_error.get(), &shill_error); 93 EXPECT_EQ(Error::kPinBlocked, shill_error.type()); 94 } 95 { 96 brillo::ErrorPtr dbus_error = 97 brillo::Error::Create(FROM_HERE, 98 brillo::errors::dbus::kDomain, 99 kErrorGprsNotSubscribedMM, 100 kErrorMessage); 101 CellularError::FromChromeosDBusError(dbus_error.get(), &shill_error); 102 EXPECT_EQ(Error::kInvalidApn, shill_error.type()); 103 } 104 { 105 brillo::ErrorPtr dbus_error = 106 brillo::Error::Create(FROM_HERE, 107 brillo::errors::dbus::kDomain, 108 kErrorIncorrectPasswordMM1, 109 kErrorMessage); 110 CellularError::FromChromeosDBusError(dbus_error.get(), &shill_error); 111 EXPECT_EQ(Error::kOperationFailed, shill_error.type()); 112 } 113 { 114 brillo::ErrorPtr dbus_error = 115 brillo::Error::Create(FROM_HERE, 116 brillo::errors::dbus::kDomain, 117 "Some random error name.", 118 kErrorMessage); 119 CellularError::FromChromeosDBusError(dbus_error.get(), &shill_error); 120 EXPECT_EQ(Error::kOperationFailed, shill_error.type()); 121 } 122 } 123 124 TEST_F(CellularErrorTest, FromMM1DBusError) { 125 Error shill_error; 126 127 CellularError::FromMM1ChromeosDBusError(nullptr, &shill_error); 128 EXPECT_TRUE(shill_error.IsSuccess()); 129 130 { 131 brillo::ErrorPtr dbus_error = 132 brillo::Error::Create(FROM_HERE, 133 brillo::errors::dbus::kDomain, 134 kErrorIncorrectPasswordMM1, 135 kErrorMessage); 136 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 137 EXPECT_EQ(Error::kIncorrectPin, shill_error.type()); 138 } 139 { 140 brillo::ErrorPtr dbus_error = 141 brillo::Error::Create(FROM_HERE, 142 brillo::errors::dbus::kDomain, 143 kErrorSimPinMM1, 144 kErrorMessage); 145 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 146 EXPECT_EQ(Error::kPinRequired, shill_error.type()); 147 } 148 { 149 brillo::ErrorPtr dbus_error = 150 brillo::Error::Create(FROM_HERE, 151 brillo::errors::dbus::kDomain, 152 kErrorSimPukMM1, 153 kErrorMessage); 154 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 155 EXPECT_EQ(Error::kPinBlocked, shill_error.type()); 156 } 157 { 158 brillo::ErrorPtr dbus_error = 159 brillo::Error::Create(FROM_HERE, 160 brillo::errors::dbus::kDomain, 161 kErrorGprsNotSubscribedMM1, 162 kErrorMessage); 163 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 164 EXPECT_EQ(Error::kInvalidApn, shill_error.type()); 165 } 166 { 167 brillo::ErrorPtr dbus_error = 168 brillo::Error::Create(FROM_HERE, 169 brillo::errors::dbus::kDomain, 170 kErrorWrongStateMM1, 171 kErrorMessage); 172 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 173 EXPECT_EQ(Error::kWrongState, shill_error.type()); 174 } 175 { 176 brillo::ErrorPtr dbus_error = 177 brillo::Error::Create(FROM_HERE, 178 brillo::errors::dbus::kDomain, 179 kErrorIncorrectPasswordMM, 180 kErrorMessage); 181 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 182 EXPECT_EQ(Error::kOperationFailed, shill_error.type()); 183 } 184 { 185 brillo::ErrorPtr dbus_error = 186 brillo::Error::Create(FROM_HERE, 187 brillo::errors::dbus::kDomain, 188 "Some random error name.", 189 kErrorMessage); 190 CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error); 191 EXPECT_EQ(Error::kOperationFailed, shill_error.type()); 192 } 193 } 194 195 } // namespace shill 196 197