
Use the PRETTY_NAME variable from /etc/os-release (or /usr/lib/os-release) to get the "pretty operating system name in a format suitable for presentation to the user" as the standard says. This could allow us to drop a requirement on lsb_release binary on Linux. The os-release is presented on most new distribution like Fedora, RHEL 7, CentOS 7, Ubuntu 12.04+, Debian Wheezy+. More information could be found on https://www.freedesktop.org/software/systemd/man/os-release.html. Bug: 420439 Change-Id: If4fc3cd3d22507e47b32d6184ac6ef4ae4b4ff3f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1156504 Commit-Queue: Tomáš Popela <tomas.popela@gmail.com> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Thomas Anderson <thomasanderson@chromium.org> Auto-Submit: Tomáš Popela <tomas.popela@gmail.com> Cr-Commit-Position: refs/heads/master@{#695280}
77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
// Copyright 2019 The Chromium 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 "base/linux_util.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace {
|
|
|
|
const char kPrettyName[] = "PRETTY_NAME";
|
|
|
|
TEST(LinuxUtilTest, ParseEtcOsReleaseFile) {
|
|
const char kOsRelease[] = R"X(
|
|
NAME=Fedora
|
|
VERSION="30 (Workstation Edition\)\"
|
|
ID=fedora
|
|
VERSION_ID=30
|
|
VERSION_CODENAME=""
|
|
PLATFORM_ID="platform:f30
|
|
PRETTY_NAME="Fedora 30 (Workstation Edition)"
|
|
ANSI_COLOR="0;34"
|
|
LOGO=fedora-logo-icon
|
|
CPE_NAME="cpe:/o:fedoraproject:fedora:30"
|
|
HOME_URL="https://fedoraproject.org/"
|
|
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f30/system-administrators-guide/"
|
|
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
|
|
BUG_REPORT_URL="https://bugzilla.redhat.com/"
|
|
REDHAT_BUGZILLA_PRODUCT="Fedora"
|
|
REDHAT_BUGZILLA_PRODUCT_VERSION=30
|
|
REDHAT_SUPPORT_PRODUCT="Fedora"
|
|
REDHAT_SUPPORT_PRODUCT_VERSION=30
|
|
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
|
|
VARIANT="Workstation Edition"
|
|
VARIANT_ID=workstation)X";
|
|
|
|
const char kOsReleaseMissingPrettyName[] = R"(
|
|
NAME=Fedora
|
|
VERSION='30 (Workstation Edition)'
|
|
VARIANT_ID=workstation)";
|
|
|
|
std::string value =
|
|
base::GetKeyValueFromOSReleaseFileForTesting(kOsRelease, kPrettyName);
|
|
EXPECT_EQ(value, "Fedora 30 (Workstation Edition)");
|
|
// Missing key in the file
|
|
value = base::GetKeyValueFromOSReleaseFileForTesting(
|
|
kOsReleaseMissingPrettyName, kPrettyName);
|
|
EXPECT_EQ(value, "");
|
|
// Value quoted with single ticks
|
|
value = base::GetKeyValueFromOSReleaseFileForTesting(
|
|
kOsReleaseMissingPrettyName, "VERSION");
|
|
EXPECT_EQ(value, "30 (Workstation Edition)");
|
|
// Empty file
|
|
value = base::GetKeyValueFromOSReleaseFileForTesting("", kPrettyName);
|
|
EXPECT_EQ(value, "");
|
|
// Misspelled key
|
|
value =
|
|
base::GetKeyValueFromOSReleaseFileForTesting(kOsRelease, "PRETY_NAME");
|
|
EXPECT_EQ(value, "");
|
|
// Broken key=value format
|
|
value = base::GetKeyValueFromOSReleaseFileForTesting("A/B", kPrettyName);
|
|
EXPECT_EQ(value, "");
|
|
// Empty values
|
|
value =
|
|
base::GetKeyValueFromOSReleaseFileForTesting("PRETTY_NAME=", kPrettyName);
|
|
EXPECT_EQ(value, "");
|
|
value = base::GetKeyValueFromOSReleaseFileForTesting("PRETTY_NAME=\"\"",
|
|
kPrettyName);
|
|
EXPECT_EQ(value, "");
|
|
// Only one key=value in the whole file
|
|
value = base::GetKeyValueFromOSReleaseFileForTesting("PRETTY_NAME=\"Linux\"",
|
|
kPrettyName);
|
|
EXPECT_EQ(value, "Linux");
|
|
}
|
|
|
|
} // namespace
|