blob: c0b3690c3ac868e2f22493a48e1f0fd89481cb6c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/posix/sysctl.h"
#include <sys/sysctl.h>
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
using SysctlTest = testing::Test;
TEST(SysctlTest, MibSuccess) {
absl::optional<std::string> result1 = StringSysctl({CTL_HW, HW_MACHINE});
EXPECT_TRUE(result1);
#if !BUILDFLAG(IS_OPENBSD)
absl::optional<std::string> result2 = StringSysctlByName("hw.machine");
EXPECT_TRUE(result2);
EXPECT_EQ(result1, result2);
#endif
}
TEST(SysctlTest, MibFailure) {
absl::optional<std::string> result = StringSysctl({-1});
EXPECT_FALSE(result);
#if !BUILDFLAG(IS_OPENBSD)
result = StringSysctlByName("banananananananana");
EXPECT_FALSE(result);
#endif
}
} // namespace
} // namespace base
|