/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "alloc-util.h"
#include "ctype.h"
#include "def.h"
#include "env-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "parse-util.h"
#include "process-util.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
static void test_parse_env_file(void) {
char t[] = "/tmp/test-fileio-in-XXXXXX",
p[] = "/tmp/test-fileio-out-XXXXXX";
int fd, r;
FILE *f;
char **i;
unsigned k;
assert_se(f);
fputs("one=BAR \n"
"# comment\n"
" # comment \n"
" ; comment \n"
" two = bar \n"
"invalid line\n"
"invalid line #comment\n"
"three = \"333\n"
"xxxx\"\n"
"four = \'44\\\"44\'\n"
"five = \'55\\\'55\' \"FIVE\" cinco \n"
"six = seis sechs\\\n"
" sis\n"
"seven=\"sevenval\" #nocomment\n"
"eight=eightval #nocomment\n"
"export nine=nineval\n"
"ten=", f);
fflush(f);
fclose(f);
assert_se(r >= 0);
STRV_FOREACH(i, a)
log_info("Got: <%s>", *i);
strv_env_clean(a);
k = 0;
STRV_FOREACH(i, b) {
log_info("Got2: <%s>", *i);
}
r = parse_env_file(
t, NULL,
"one", &one,
"two", &two,
"three", &three,
"four", &four,
"five", &five,
"six", &six,
"seven", &seven,
"eight", &eight,
"export nine", &nine,
"ten", &ten,
NULL);
assert_se(r >= 0);
r = write_env_file(p, a);
assert_se(r >= 0);
assert_se(r >= 0);
unlink(t);
unlink(p);
}
static void test_parse_multiline_env_file(void) {
char t[] = "/tmp/test-fileio-in-XXXXXX",
p[] = "/tmp/test-fileio-out-XXXXXX";
int fd, r;
FILE *f;
char **i;
assert_se(f);
fputs("one=BAR\\\n"
" VAR\\\n"
"\tGAR\n"
"#comment\n"
"two=\"bar\\\n"
" var\\\n"
"\tgar\"\n"
"#comment\n"
"tri=\"bar \\\n"
" var \\\n"
"\tgar \"\n", f);
fflush(f);
fclose(f);
assert_se(r >= 0);
STRV_FOREACH(i, a)
log_info("Got: <%s>", *i);
r = write_env_file(p, a);
assert_se(r >= 0);
assert_se(r >= 0);
unlink(t);
unlink(p);
}
static void test_executable_is_script(void) {
char t[] = "/tmp/test-executable-XXXXXX";
int fd, r;
FILE *f;
char *command;
assert_se(f);
fflush(f);
r = executable_is_script(t, &command);
assert_se(r > 0);
assert_se(r == 0);
if (r > 0) {
}
fclose(f);
unlink(t);
}
static void test_status_field(void) {
int r;
puts(t);
if (r != -ENOENT) {
assert_se(r == 0);
puts(p);
}
if (r != -ENOENT) {
assert_se(r == 0);
puts(s);
}
if (p)
/* Seccomp should be a good test for field full of zeros. */
if (r != -ENOENT) {
assert_se(r == 0);
puts(z);
}
}
static void test_capeff(void) {
int pid, p;
int r;
r = get_process_capeff(0, &capeff);
return;
assert_se(r == 0);
}
}
static void test_write_string_stream(void) {
int fd;
assert_se(f);
assert_se(f);
rewind(f);
assert_se(f);
rewind(f);
}
static void test_write_string_file(void) {
}
static void test_write_string_file_no_create(void) {
}
static void test_write_string_file_verify(void) {
int r;
r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
}
static void test_load_env_file_pairs(void) {
int fd;
int r;
_cleanup_strv_free_ char **l = NULL;
char **k, **v;
r = write_string_file(fn,
"NAME=\"Arch Linux\"\n"
"ID=arch\n"
"PRETTY_NAME=\"Arch Linux\"\n"
"ANSI_COLOR=\"0;36\"\n"
"HOME_URL=\"https://www.archlinux.org/\"\n"
"SUPPORT_URL=\"https://bbs.archlinux.org/\"\n"
"BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n",
assert_se(r == 0);
assert_se(f);
assert_se(r >= 0);
STRV_FOREACH_PAIR(k, v, l) {
assert_se(STR_IN_SET(*k, "NAME", "ID", "PRETTY_NAME", "ANSI_COLOR", "HOME_URL", "SUPPORT_URL", "BUG_REPORT_URL"));
printf("%s=%s\n", *k, *v);
}
}
log_open();
test_capeff();
return 0;
}