Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/cellular_error.h" |
| 6 | |
| 7 | #include <dbus-c++/error.h> |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace shill { |
| 11 | |
| 12 | class CellularErrorTest : public testing::Test { |
| 13 | }; |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | const char kErrorIncorrectPasswordMM[] = |
| 18 | "org.freedesktop.ModemManager.Modem.Gsm.IncorrectPassword"; |
| 19 | |
| 20 | const char kErrorSimPinRequiredMM[] = |
| 21 | "org.freedesktop.ModemManager.Modem.Gsm.SimPinRequired"; |
| 22 | |
| 23 | const char kErrorSimPukRequiredMM[] = |
| 24 | "org.freedesktop.ModemManager.Modem.Gsm.SimPukRequired"; |
| 25 | |
| 26 | const char kErrorGprsNotSubscribedMM[] = |
| 27 | "org.freedesktop.ModemManager.Modem.Gsm.GprsNotSubscribed"; |
| 28 | |
| 29 | const char kErrorIncorrectPasswordMM1[] = |
Ben Chan | 034e689 | 2013-08-22 14:18:14 -0700 | [diff] [blame] | 30 | "org.freedesktop.ModemManager1.Error.MobileEquipment.IncorrectPassword"; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 31 | |
| 32 | const char kErrorSimPinMM1[] = |
Ben Chan | 034e689 | 2013-08-22 14:18:14 -0700 | [diff] [blame] | 33 | "org.freedesktop.ModemManager1.Error.MobileEquipment.SimPin"; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 34 | |
| 35 | const char kErrorSimPukMM1[] = |
Ben Chan | 034e689 | 2013-08-22 14:18:14 -0700 | [diff] [blame] | 36 | "org.freedesktop.ModemManager1.Error.MobileEquipment.SimPuk"; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 37 | |
Thieu Le | a853df5 | 2013-09-09 14:44:07 -0700 | [diff] [blame] | 38 | const char kErrorGprsNotSubscribedMM1[] = |
| 39 | "org.freedesktop.ModemManager1.Error.MobileEquipment." |
| 40 | "GprsServiceOptionNotSubscribed"; |
| 41 | |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame^] | 42 | const char kErrorWrongStateMM1[] = |
| 43 | "org.freedesktop.ModemManager1.Error.Core.WrongState"; |
| 44 | |
| 45 | |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 46 | const char kErrorMessage[] = "Some error message."; |
| 47 | |
| 48 | } // namespace |
| 49 | |
| 50 | TEST_F(CellularErrorTest, FromDBusError) { |
| 51 | Error shill_error; |
| 52 | |
| 53 | CellularError::FromDBusError(DBus::Error(), NULL); |
| 54 | EXPECT_TRUE(shill_error.IsSuccess()); |
| 55 | |
| 56 | CellularError::FromDBusError(DBus::Error(), &shill_error); |
| 57 | EXPECT_TRUE(shill_error.IsSuccess()); |
| 58 | |
| 59 | CellularError::FromDBusError( |
| 60 | DBus::Error(kErrorIncorrectPasswordMM, kErrorMessage), |
| 61 | &shill_error); |
| 62 | EXPECT_EQ(Error::kIncorrectPin, shill_error.type()); |
| 63 | |
| 64 | CellularError::FromDBusError( |
| 65 | DBus::Error(kErrorSimPinRequiredMM, kErrorMessage), |
| 66 | &shill_error); |
| 67 | EXPECT_EQ(Error::kPinRequired, shill_error.type()); |
| 68 | |
| 69 | CellularError::FromDBusError( |
| 70 | DBus::Error(kErrorSimPukRequiredMM, kErrorMessage), |
| 71 | &shill_error); |
| 72 | EXPECT_EQ(Error::kPinBlocked, shill_error.type()); |
| 73 | |
| 74 | CellularError::FromDBusError( |
| 75 | DBus::Error(kErrorGprsNotSubscribedMM, kErrorMessage), |
| 76 | &shill_error); |
| 77 | EXPECT_EQ(Error::kInvalidApn, shill_error.type()); |
| 78 | |
| 79 | CellularError::FromDBusError( |
| 80 | DBus::Error(kErrorIncorrectPasswordMM1, kErrorMessage), |
| 81 | &shill_error); |
| 82 | EXPECT_EQ(Error::kOperationFailed, shill_error.type()); |
| 83 | |
| 84 | CellularError::FromDBusError( |
| 85 | DBus::Error("Some random error name.", kErrorMessage), |
| 86 | &shill_error); |
| 87 | EXPECT_EQ(Error::kOperationFailed, shill_error.type()); |
| 88 | } |
| 89 | |
| 90 | TEST_F(CellularErrorTest, FromMM1DBusError) { |
| 91 | Error shill_error; |
| 92 | |
| 93 | CellularError::FromDBusError(DBus::Error(), NULL); |
| 94 | EXPECT_TRUE(shill_error.IsSuccess()); |
| 95 | |
| 96 | CellularError::FromMM1DBusError(DBus::Error(), &shill_error); |
| 97 | EXPECT_TRUE(shill_error.IsSuccess()); |
| 98 | |
| 99 | CellularError::FromMM1DBusError( |
| 100 | DBus::Error(kErrorIncorrectPasswordMM1, kErrorMessage), |
| 101 | &shill_error); |
| 102 | EXPECT_EQ(Error::kIncorrectPin, shill_error.type()); |
| 103 | |
| 104 | CellularError::FromMM1DBusError( |
| 105 | DBus::Error(kErrorSimPinMM1, kErrorMessage), |
| 106 | &shill_error); |
| 107 | EXPECT_EQ(Error::kPinRequired, shill_error.type()); |
| 108 | |
| 109 | CellularError::FromMM1DBusError( |
| 110 | DBus::Error(kErrorSimPukMM1, kErrorMessage), |
| 111 | &shill_error); |
| 112 | EXPECT_EQ(Error::kPinBlocked, shill_error.type()); |
| 113 | |
| 114 | CellularError::FromMM1DBusError( |
Thieu Le | a853df5 | 2013-09-09 14:44:07 -0700 | [diff] [blame] | 115 | DBus::Error(kErrorGprsNotSubscribedMM1, kErrorMessage), |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 116 | &shill_error); |
Thieu Le | a853df5 | 2013-09-09 14:44:07 -0700 | [diff] [blame] | 117 | EXPECT_EQ(Error::kInvalidApn, shill_error.type()); |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 118 | |
| 119 | CellularError::FromMM1DBusError( |
Ben Chan | 151d447 | 2013-09-06 13:29:46 -0700 | [diff] [blame^] | 120 | DBus::Error(kErrorWrongStateMM1, kErrorMessage), |
| 121 | &shill_error); |
| 122 | EXPECT_EQ(Error::kWrongState, shill_error.type()); |
| 123 | |
| 124 | CellularError::FromMM1DBusError( |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 125 | DBus::Error(kErrorIncorrectPasswordMM, kErrorMessage), |
| 126 | &shill_error); |
| 127 | EXPECT_EQ(Error::kOperationFailed, shill_error.type()); |
| 128 | |
| 129 | CellularError::FromMM1DBusError( |
| 130 | DBus::Error("Some random error name.", kErrorMessage), |
| 131 | &shill_error); |
| 132 | EXPECT_EQ(Error::kOperationFailed, shill_error.type()); |
| 133 | } |
| 134 | |
| 135 | } // namespace shill |
| 136 | |