File: format_mount_command.c

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (131 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stic.h>

#include <test-utils.h>

#include "../../src/int/fuse.h"

TEST(no_macro_string_unchanged)
{
	int foreground;
	char buf[256];
	char format[] = "FUSE_MOUNT|mount";
	char expected[] = "mount";

	format_mount_command("/mnt/point", "/file/path", "param", format, sizeof(buf),
			buf, &foreground);
	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

TEST(wrong_macro_expanded_to_empty_string)
{
	int foreground;
	char buf[256];
	char format[] = "FUSE_MOUNT|mount %SRC";
	char expected[] = "mount ";

	format_mount_command("/mnt/point", "/file/path", "param", format, sizeof(buf),
			buf, &foreground);
	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

TEST(foreground_macro_returns_non_zero)
{
	int foreground;
	char buf[256];
	char format[] = "FUSE_MOUNT|mount %FOREGROUND %SRC";
	char expected[] = "mount  ";

	format_mount_command("/mnt/point", "/file/path", "param", format, sizeof(buf),
			buf, &foreground);
	assert_int_equal(1, foreground);
	assert_string_equal(expected, buf);
}

TEST(clear_macro_returns_non_zero)
{
	int foreground;
	char buf[256];
	char format[] = "FUSE_MOUNT|mount %CLEAR %SRC";
	char expected[] = "mount  ";

	format_mount_command("/mnt/point", "/file/path", "param", format, sizeof(buf),
			buf, &foreground);
	assert_int_equal(1, foreground);
	assert_string_equal(expected, buf);
}

TEST(options_before_macros)
{
	int foreground;
	char buf[256];
	char format[] = "FUSE_MOUNT2|mount -o opt1=-,opt2 %PARAM %DESTINATION_DIR";
	const char *expected = not_windows()
	                     ? "mount -o opt1=-,opt2 param /mnt/point"
	                     : "mount -o opt1=-,opt2 param \"/mnt/point\"";

	format_mount_command("/mnt/point", "/file/path/dir/file", "param", format,
			sizeof(buf), buf, &foreground);

	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

TEST(too_long_param)
{
	int foreground;
	char buf[10];
	char format[] = "FUSE_MOUNT2|%PARAM";
	char expected[] = "012345678";

	format_mount_command("a", "b", "0123456789abcdefghijklmnopqrstuvw", format,
			sizeof(buf), buf, &foreground);

	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

TEST(too_long_destination)
{
	int foreground;
	char buf[10];
	char format[] = "FUSE_MOUNT2|%DESTINATION_DIR";
	const char *expected = (not_windows() ? "012345678" : "\"01234567");

	format_mount_command("0123456789abcdefghijklmnopqrstuvw", "y", "z", format,
			sizeof(buf), buf, &foreground);

	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

TEST(too_long_source)
{
	int foreground;
	char buf[10];
	char format[] = "FUSE_MOUNT2|%SOURCE_FILE";
	const char *expected = (not_windows() ? "012345678" : "\"01234567");

	format_mount_command("a", "0123456789abcdefghijklmnopqrstuvw", "z", format,
			sizeof(buf), buf, &foreground);

	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

TEST(no_bar_symbol)
{
	int foreground;
	char buf[10];
	char format[] = "%SOURCE_FILE\0abc";
	char expected[] = "";

	format_mount_command("a", "m", "z", format, sizeof(buf), buf, &foreground);

	assert_int_equal(0, foreground);
	assert_string_equal(expected, buf);
}

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */