blob: 436ec1480b5fa3307dd6222ae1137fecedd2279e [file] [log] [blame]
Arman Uguray763df862013-07-02 12:49:10 -07001// 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
10namespace shill {
11
12class CellularErrorTest : public testing::Test {
13};
14
15namespace {
16
17const char kErrorIncorrectPasswordMM[] =
18 "org.freedesktop.ModemManager.Modem.Gsm.IncorrectPassword";
19
20const char kErrorSimPinRequiredMM[] =
21 "org.freedesktop.ModemManager.Modem.Gsm.SimPinRequired";
22
23const char kErrorSimPukRequiredMM[] =
24 "org.freedesktop.ModemManager.Modem.Gsm.SimPukRequired";
25
26const char kErrorGprsNotSubscribedMM[] =
27 "org.freedesktop.ModemManager.Modem.Gsm.GprsNotSubscribed";
28
29const char kErrorIncorrectPasswordMM1[] =
Ben Chan034e6892013-08-22 14:18:14 -070030 "org.freedesktop.ModemManager1.Error.MobileEquipment.IncorrectPassword";
Arman Uguray763df862013-07-02 12:49:10 -070031
32const char kErrorSimPinMM1[] =
Ben Chan034e6892013-08-22 14:18:14 -070033 "org.freedesktop.ModemManager1.Error.MobileEquipment.SimPin";
Arman Uguray763df862013-07-02 12:49:10 -070034
35const char kErrorSimPukMM1[] =
Ben Chan034e6892013-08-22 14:18:14 -070036 "org.freedesktop.ModemManager1.Error.MobileEquipment.SimPuk";
Arman Uguray763df862013-07-02 12:49:10 -070037
Thieu Lea853df52013-09-09 14:44:07 -070038const char kErrorGprsNotSubscribedMM1[] =
39 "org.freedesktop.ModemManager1.Error.MobileEquipment."
40 "GprsServiceOptionNotSubscribed";
41
Ben Chan151d4472013-09-06 13:29:46 -070042const char kErrorWrongStateMM1[] =
43 "org.freedesktop.ModemManager1.Error.Core.WrongState";
44
45
Arman Uguray763df862013-07-02 12:49:10 -070046const char kErrorMessage[] = "Some error message.";
47
48} // namespace
49
50TEST_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
90TEST_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 Lea853df52013-09-09 14:44:07 -0700115 DBus::Error(kErrorGprsNotSubscribedMM1, kErrorMessage),
Arman Uguray763df862013-07-02 12:49:10 -0700116 &shill_error);
Thieu Lea853df52013-09-09 14:44:07 -0700117 EXPECT_EQ(Error::kInvalidApn, shill_error.type());
Arman Uguray763df862013-07-02 12:49:10 -0700118
119 CellularError::FromMM1DBusError(
Ben Chan151d4472013-09-06 13:29:46 -0700120 DBus::Error(kErrorWrongStateMM1, kErrorMessage),
121 &shill_error);
122 EXPECT_EQ(Error::kWrongState, shill_error.type());
123
124 CellularError::FromMM1DBusError(
Arman Uguray763df862013-07-02 12:49:10 -0700125 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