blob: 6d63bbc4cb0ef5614c47a06d050b1159dda4a25d [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[] =
30 "org.freedesktop.ModemManager1.MobileEquipment.IncorrectPassword";
31
32const char kErrorSimPinMM1[] =
33 "org.freedesktop.ModemManager1.MobileEquipment.SimPin";
34
35const char kErrorSimPukMM1[] =
36 "org.freedesktop.ModemManager1.MobileEquipment.SimPuk";
37
38const char kErrorMessage[] = "Some error message.";
39
40} // namespace
41
42TEST_F(CellularErrorTest, FromDBusError) {
43 Error shill_error;
44
45 CellularError::FromDBusError(DBus::Error(), NULL);
46 EXPECT_TRUE(shill_error.IsSuccess());
47
48 CellularError::FromDBusError(DBus::Error(), &shill_error);
49 EXPECT_TRUE(shill_error.IsSuccess());
50
51 CellularError::FromDBusError(
52 DBus::Error(kErrorIncorrectPasswordMM, kErrorMessage),
53 &shill_error);
54 EXPECT_EQ(Error::kIncorrectPin, shill_error.type());
55
56 CellularError::FromDBusError(
57 DBus::Error(kErrorSimPinRequiredMM, kErrorMessage),
58 &shill_error);
59 EXPECT_EQ(Error::kPinRequired, shill_error.type());
60
61 CellularError::FromDBusError(
62 DBus::Error(kErrorSimPukRequiredMM, kErrorMessage),
63 &shill_error);
64 EXPECT_EQ(Error::kPinBlocked, shill_error.type());
65
66 CellularError::FromDBusError(
67 DBus::Error(kErrorGprsNotSubscribedMM, kErrorMessage),
68 &shill_error);
69 EXPECT_EQ(Error::kInvalidApn, shill_error.type());
70
71 CellularError::FromDBusError(
72 DBus::Error(kErrorIncorrectPasswordMM1, kErrorMessage),
73 &shill_error);
74 EXPECT_EQ(Error::kOperationFailed, shill_error.type());
75
76 CellularError::FromDBusError(
77 DBus::Error("Some random error name.", kErrorMessage),
78 &shill_error);
79 EXPECT_EQ(Error::kOperationFailed, shill_error.type());
80}
81
82TEST_F(CellularErrorTest, FromMM1DBusError) {
83 Error shill_error;
84
85 CellularError::FromDBusError(DBus::Error(), NULL);
86 EXPECT_TRUE(shill_error.IsSuccess());
87
88 CellularError::FromMM1DBusError(DBus::Error(), &shill_error);
89 EXPECT_TRUE(shill_error.IsSuccess());
90
91 CellularError::FromMM1DBusError(
92 DBus::Error(kErrorIncorrectPasswordMM1, kErrorMessage),
93 &shill_error);
94 EXPECT_EQ(Error::kIncorrectPin, shill_error.type());
95
96 CellularError::FromMM1DBusError(
97 DBus::Error(kErrorSimPinMM1, kErrorMessage),
98 &shill_error);
99 EXPECT_EQ(Error::kPinRequired, shill_error.type());
100
101 CellularError::FromMM1DBusError(
102 DBus::Error(kErrorSimPukMM1, kErrorMessage),
103 &shill_error);
104 EXPECT_EQ(Error::kPinBlocked, shill_error.type());
105
106 CellularError::FromMM1DBusError(
107 DBus::Error(kErrorGprsNotSubscribedMM, kErrorMessage),
108 &shill_error);
109 EXPECT_EQ(Error::kOperationFailed, shill_error.type());
110
111 CellularError::FromMM1DBusError(
112 DBus::Error(kErrorIncorrectPasswordMM, kErrorMessage),
113 &shill_error);
114 EXPECT_EQ(Error::kOperationFailed, shill_error.type());
115
116 CellularError::FromMM1DBusError(
117 DBus::Error("Some random error name.", kErrorMessage),
118 &shill_error);
119 EXPECT_EQ(Error::kOperationFailed, shill_error.type());
120}
121
122} // namespace shill
123