2021-01-08 18:24:51 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-12-08 21:11:54 +00:00
|
|
|
#include <assert.h>
|
2020-06-19 20:04:06 +00:00
|
|
|
#include <string.h>
|
2019-12-08 21:11:54 +00:00
|
|
|
|
2021-01-08 18:18:02 +00:00
|
|
|
#include "cli.h"
|
2021-10-27 16:43:47 +00:00
|
|
|
#include "options.h"
|
2019-12-08 21:11:54 +00:00
|
|
|
|
|
|
|
static void test_flag_version(void) {
|
|
|
|
struct scrcpy_cli_args args = {
|
2021-10-27 16:43:47 +00:00
|
|
|
.opts = scrcpy_options_default,
|
2019-12-08 21:11:54 +00:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
char *argv[] = {"scrcpy", "-v"};
|
|
|
|
|
|
|
|
bool ok = scrcpy_parse_args(&args, 2, argv);
|
|
|
|
assert(ok);
|
|
|
|
assert(!args.help);
|
|
|
|
assert(args.version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_flag_help(void) {
|
|
|
|
struct scrcpy_cli_args args = {
|
2021-10-27 16:43:47 +00:00
|
|
|
.opts = scrcpy_options_default,
|
2019-12-08 21:11:54 +00:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
char *argv[] = {"scrcpy", "-v"};
|
|
|
|
|
|
|
|
bool ok = scrcpy_parse_args(&args, 2, argv);
|
|
|
|
assert(ok);
|
|
|
|
assert(!args.help);
|
|
|
|
assert(args.version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_options(void) {
|
|
|
|
struct scrcpy_cli_args args = {
|
2021-10-27 16:43:47 +00:00
|
|
|
.opts = scrcpy_options_default,
|
2019-12-08 21:11:54 +00:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
char *argv[] = {
|
|
|
|
"scrcpy",
|
|
|
|
"--always-on-top",
|
2023-02-21 18:56:44 +00:00
|
|
|
"--video-bit-rate", "5M",
|
2019-12-08 21:11:54 +00:00
|
|
|
"--crop", "100:200:300:400",
|
|
|
|
"--fullscreen",
|
|
|
|
"--max-fps", "30",
|
|
|
|
"--max-size", "1024",
|
|
|
|
// "--no-control" is not compatible with "--turn-screen-off"
|
2023-05-24 18:22:35 +00:00
|
|
|
// "--no-playback" is not compatible with "--fulscreen"
|
2019-12-09 20:16:09 +00:00
|
|
|
"--port", "1234:1236",
|
2019-12-08 21:11:54 +00:00
|
|
|
"--push-target", "/sdcard/Movies",
|
|
|
|
"--record", "file",
|
|
|
|
"--record-format", "mkv",
|
|
|
|
"--serial", "0123456789abcdef",
|
|
|
|
"--show-touches",
|
|
|
|
"--turn-screen-off",
|
|
|
|
"--prefer-text",
|
|
|
|
"--window-title", "my device",
|
|
|
|
"--window-x", "100",
|
|
|
|
"--window-y", "-1",
|
|
|
|
"--window-width", "600",
|
|
|
|
"--window-height", "0",
|
|
|
|
"--window-borderless",
|
|
|
|
};
|
|
|
|
|
2019-12-09 19:59:11 +00:00
|
|
|
bool ok = scrcpy_parse_args(&args, ARRAY_LEN(argv), argv);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(ok);
|
|
|
|
|
|
|
|
const struct scrcpy_options *opts = &args.opts;
|
|
|
|
assert(opts->always_on_top);
|
2023-02-21 18:56:44 +00:00
|
|
|
assert(opts->video_bit_rate == 5000000);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(!strcmp(opts->crop, "100:200:300:400"));
|
|
|
|
assert(opts->fullscreen);
|
2024-09-14 12:32:32 +00:00
|
|
|
assert(!strcmp(opts->max_fps, "30"));
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(opts->max_size == 1024);
|
2019-12-09 20:16:09 +00:00
|
|
|
assert(opts->port_range.first == 1234);
|
|
|
|
assert(opts->port_range.last == 1236);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(!strcmp(opts->push_target, "/sdcard/Movies"));
|
|
|
|
assert(!strcmp(opts->record_filename, "file"));
|
2020-06-19 20:04:06 +00:00
|
|
|
assert(opts->record_format == SC_RECORD_FORMAT_MKV);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(!strcmp(opts->serial, "0123456789abcdef"));
|
|
|
|
assert(opts->show_touches);
|
|
|
|
assert(opts->turn_screen_off);
|
2021-11-26 21:05:28 +00:00
|
|
|
assert(opts->key_inject_mode == SC_KEY_INJECT_MODE_TEXT);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(!strcmp(opts->window_title, "my device"));
|
|
|
|
assert(opts->window_x == 100);
|
|
|
|
assert(opts->window_y == -1);
|
|
|
|
assert(opts->window_width == 600);
|
|
|
|
assert(opts->window_height == 0);
|
|
|
|
assert(opts->window_borderless);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_options2(void) {
|
|
|
|
struct scrcpy_cli_args args = {
|
2021-10-27 16:43:47 +00:00
|
|
|
.opts = scrcpy_options_default,
|
2019-12-08 21:11:54 +00:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
|
|
|
};
|
|
|
|
|
|
|
|
char *argv[] = {
|
|
|
|
"scrcpy",
|
|
|
|
"--no-control",
|
2023-05-24 18:22:35 +00:00
|
|
|
"--no-playback",
|
|
|
|
"--record", "file.mp4", // cannot enable --no-playback without recording
|
2019-12-08 21:11:54 +00:00
|
|
|
};
|
|
|
|
|
2019-12-09 19:59:11 +00:00
|
|
|
bool ok = scrcpy_parse_args(&args, ARRAY_LEN(argv), argv);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(ok);
|
|
|
|
|
|
|
|
const struct scrcpy_options *opts = &args.opts;
|
|
|
|
assert(!opts->control);
|
2023-05-24 19:22:31 +00:00
|
|
|
assert(!opts->video_playback);
|
|
|
|
assert(!opts->audio_playback);
|
2019-12-08 21:11:54 +00:00
|
|
|
assert(!strcmp(opts->record_filename, "file.mp4"));
|
2020-06-19 20:04:06 +00:00
|
|
|
assert(opts->record_format == SC_RECORD_FORMAT_MP4);
|
2019-12-08 21:11:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 22:00:42 +00:00
|
|
|
static void test_parse_shortcut_mods(void) {
|
2024-03-07 22:07:01 +00:00
|
|
|
uint8_t mods;
|
2020-07-16 22:00:42 +00:00
|
|
|
bool ok;
|
|
|
|
|
|
|
|
ok = sc_parse_shortcut_mods("lctrl", &mods);
|
|
|
|
assert(ok);
|
2024-03-07 22:07:01 +00:00
|
|
|
assert(mods == SC_SHORTCUT_MOD_LCTRL);
|
2020-07-16 22:00:42 +00:00
|
|
|
|
|
|
|
ok = sc_parse_shortcut_mods("rctrl,lalt", &mods);
|
|
|
|
assert(ok);
|
2024-03-07 22:07:01 +00:00
|
|
|
assert(mods == (SC_SHORTCUT_MOD_RCTRL | SC_SHORTCUT_MOD_LALT));
|
2020-07-16 22:00:42 +00:00
|
|
|
|
2024-03-07 22:07:01 +00:00
|
|
|
ok = sc_parse_shortcut_mods("lsuper,rsuper,lctrl", &mods);
|
2020-07-16 22:00:42 +00:00
|
|
|
assert(ok);
|
2024-03-07 22:07:01 +00:00
|
|
|
assert(mods == (SC_SHORTCUT_MOD_LSUPER
|
|
|
|
| SC_SHORTCUT_MOD_RSUPER
|
|
|
|
| SC_SHORTCUT_MOD_LCTRL));
|
2020-07-16 22:00:42 +00:00
|
|
|
|
|
|
|
ok = sc_parse_shortcut_mods("", &mods);
|
|
|
|
assert(!ok);
|
|
|
|
|
|
|
|
ok = sc_parse_shortcut_mods("lctrl+", &mods);
|
|
|
|
assert(!ok);
|
|
|
|
|
|
|
|
ok = sc_parse_shortcut_mods("lctrl,", &mods);
|
|
|
|
assert(!ok);
|
|
|
|
}
|
|
|
|
|
2020-07-15 10:17:04 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2019-12-08 21:11:54 +00:00
|
|
|
test_flag_version();
|
|
|
|
test_flag_help();
|
|
|
|
test_options();
|
|
|
|
test_options2();
|
2020-07-16 22:00:42 +00:00
|
|
|
test_parse_shortcut_mods();
|
2019-12-08 21:11:54 +00:00
|
|
|
return 0;
|
2021-12-04 08:27:59 +00:00
|
|
|
}
|