blob: 10c52e8cf8d32545573513651d80019256632889 [file] [log] [blame]
Alex Light40320712017-12-14 11:52:04 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "jdwp.h"
18
19#include "gtest/gtest.h"
20
21namespace art {
22namespace JDWP {
23
24TEST(JdwpOptionsTest, Options) {
25 {
26 /*
27 * "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
28 */
29 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
30 const char *opt_args = "transport=dt_socket,address=8000,server=y";
31
32 EXPECT_TRUE(ParseJdwpOptions(opt_args, &opt));
33 EXPECT_EQ(opt.transport, JdwpTransportType::kJdwpTransportSocket);
34 EXPECT_EQ(opt.port, 8000u);
35 EXPECT_EQ(opt.server, true);
36 EXPECT_EQ(opt.suspend, false);
37 }
38
39 {
40 /*
41 * Example: transport=dt_socket,address=localhost:6500,server=n
42 */
43 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
44 const char *opt_args = "transport=dt_socket,address=localhost:6500,server=y";
45
46 EXPECT_TRUE(ParseJdwpOptions(opt_args, &opt));
47 EXPECT_EQ(opt.transport, JdwpTransportType::kJdwpTransportSocket);
48 EXPECT_EQ(opt.port, 6500u);
49 EXPECT_EQ(opt.host, "localhost");
50 EXPECT_EQ(opt.server, true);
51 EXPECT_EQ(opt.suspend, false);
52 }
53
54 {
55 /*
56 * Example: transport=dt_android_adb,server=n,suspend=y;
57 */
58 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
59 const char *opt_args = "transport=dt_android_adb,server=y";
60
61 EXPECT_TRUE(ParseJdwpOptions(opt_args, &opt));
62 EXPECT_EQ(opt.transport, JdwpTransportType::kJdwpTransportAndroidAdb);
63 EXPECT_EQ(opt.port, 0xFFFF);
64 EXPECT_EQ(opt.host, "");
65 EXPECT_EQ(opt.server, true);
66 EXPECT_EQ(opt.suspend, false);
67 }
68
69 /*
70 * Test failures
71 */
72 JDWP::JdwpOptions opt = JDWP::JdwpOptions();
73 EXPECT_FALSE(ParseJdwpOptions("help", &opt));
74 EXPECT_FALSE(ParseJdwpOptions("blabla", &opt));
75 EXPECT_FALSE(ParseJdwpOptions("transport=dt_android_adb,server=n", &opt));
76}
77
78} // namespace JDWP
79} // namespace art