blob: c81edeef03093b4422849f860cb1884f9b0feefe [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "shill/cellular/cellular_error.h"
#include <brillo/errors/error_codes.h>
#include <gtest/gtest.h>
namespace shill {
namespace {
const char kErrorIncorrectPasswordMM1[] =
"org.freedesktop.ModemManager1.Error.MobileEquipment.IncorrectPassword";
const char kErrorSimPinMM1[] =
"org.freedesktop.ModemManager1.Error.MobileEquipment.SimPin";
const char kErrorSimPukMM1[] =
"org.freedesktop.ModemManager1.Error.MobileEquipment.SimPuk";
const char kErrorGprsNotSubscribedMM1[] =
"org.freedesktop.ModemManager1.Error.MobileEquipment."
"GprsServiceOptionNotSubscribed";
const char kErrorWrongStateMM1[] =
"org.freedesktop.ModemManager1.Error.Core.WrongState";
const char kErrorMessage[] = "Some error message.";
struct TestParam {
TestParam(const char* dbus_error, Error::Type error_type)
: dbus_error(dbus_error), error_type(error_type) {}
const char* dbus_error;
Error::Type error_type;
};
class CellularErrorMM1Test : public testing::TestWithParam<TestParam> {};
TEST_P(CellularErrorMM1Test, FromDBusError) {
TestParam param = GetParam();
brillo::ErrorPtr dbus_error =
brillo::Error::Create(FROM_HERE, brillo::errors::dbus::kDomain,
param.dbus_error, kErrorMessage);
Error shill_error;
CellularError::FromMM1ChromeosDBusError(dbus_error.get(), &shill_error);
EXPECT_EQ(param.error_type, shill_error.type());
}
INSTANTIATE_TEST_SUITE_P(
CellularErrorMM1Test,
CellularErrorMM1Test,
testing::Values(TestParam(kErrorIncorrectPasswordMM1, Error::kIncorrectPin),
TestParam(kErrorSimPinMM1, Error::kPinRequired),
TestParam(kErrorSimPukMM1, Error::kPinBlocked),
TestParam(kErrorGprsNotSubscribedMM1, Error::kInvalidApn),
TestParam(kErrorWrongStateMM1, Error::kWrongState),
TestParam("Some random error name.",
Error::kOperationFailed)));
} // namespace
} // namespace shill