| 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 |
|
| 13 |
static void set_env(const char *var, const char *value) { |
| 14 |
#ifdef _WIN32 |
| 15 |
_putenv_s(var, value); |
| 16 |
#else |
| 17 |
setenv(var, value, true); |
| 18 |
#endif |
| 19 |
} |
| 20 |
|
| 21 |
using namespace lldb; |
| 22 |
using namespace lldb_private; |
| 23 |
|
| 24 |
namespace lldb_private { |
| 25 |
namespace platform_android { |
| 26 |
|
| 27 |
class AdbClientTest : public ::testing::Test { |
| 28 |
public: |
| 29 |
void SetUp() override { set_env("ANDROID_SERIAL", ""); } |
| 30 |
|
| 31 |
void TearDown() override { set_env("ANDROID_SERIAL", ""); } |
| 32 |
}; |
| 33 |
|
| 34 |
TEST(AdbClientTest, CreateByDeviceId) { |
| 35 |
AdbClient adb; |
| 36 |
Status error = AdbClient::CreateByDeviceID("device1", adb); |
| 37 |
EXPECT_TRUE(error.Success()); |
| 38 |
EXPECT_EQ("device1", adb.GetDeviceID()); |
| 39 |
} |
| 40 |
|
| 41 |
TEST(AdbClientTest, CreateByDeviceId_ByEnvVar) { |
| 42 |
set_env("ANDROID_SERIAL", "device2"); |
| 43 |
|
| 44 |
AdbClient adb; |
| 45 |
Status error = AdbClient::CreateByDeviceID("", adb); |
| 46 |
EXPECT_TRUE(error.Success()); |
| 47 |
EXPECT_EQ("device2", adb.GetDeviceID()); |
| 48 |
} |
| 49 |
|
| 50 |
} // end namespace platform_android |
| 51 |
} // end namespace lldb_private |