xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
<root> / tests / misc / format_mount_command.c (e61de947e645227425b857b3e82db40f0183ce0b) (3,305B) (mode 100644) [raw]
#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 : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master