1//===-- AdbClientTest.cpp -------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "gtest/gtest.h"
10#include "Plugins/Platform/Android/AdbClient.h"
11#include <cstdlib>
12
13static void set_env(const char *var, const char *value) {
14#ifdef _WIN32
15 _putenv_s(var, value);
16#else
17 setenv(name: var, value: value, replace: true);
18#endif
19}
20
21using namespace lldb;
22using namespace lldb_private;
23
24namespace lldb_private {
25namespace platform_android {
26
27class AdbClientTest : public ::testing::Test {
28public:
29 void SetUp() override { set_env(var: "ANDROID_SERIAL", value: ""); }
30
31 void TearDown() override { set_env(var: "ANDROID_SERIAL", value: ""); }
32};
33
34TEST(AdbClientTest, CreateByDeviceId) {
35 AdbClient adb;
36 Status error = AdbClient::CreateByDeviceID(device_id: "device1", adb);
37 EXPECT_TRUE(error.Success());
38 EXPECT_EQ("device1", adb.GetDeviceID());
39}
40
41TEST(AdbClientTest, CreateByDeviceId_ByEnvVar) {
42 set_env(var: "ANDROID_SERIAL", value: "device2");
43
44 AdbClient adb;
45 Status error = AdbClient::CreateByDeviceID(device_id: "", adb);
46 EXPECT_TRUE(error.Success());
47 EXPECT_EQ("device2", adb.GetDeviceID());
48}
49
50} // end namespace platform_android
51} // end namespace lldb_private
52

source code of lldb/unittests/Platform/Android/AdbClientTest.cpp