本文整理汇总了C++中ATF_REQUIRE函数的典型用法代码示例。如果您正苦于以下问题:C++ ATF_REQUIRE函数的具体用法?C++ ATF_REQUIRE怎么用?C++ ATF_REQUIRE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ATF_REQUIRE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ATF_TC_BODY
ATF_TC_BODY(hexadecimal_rounding, tc)
{
ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
fesetround(FE_TOWARDZERO);
testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);
fesetround(FE_DOWNWARD);
testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
testfmt("-0x1.23457p+0", "%.5a", -0x1.23456789abcdep0);
testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
fesetround(FE_UPWARD);
testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
testfmt("0x1.23457p+0", "%.5a", 0x1.23456789abcdep0);
testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);
fesetround(FE_TONEAREST);
testfmt("0x1.23456789abcdep+4", "%a", 0x1.23456789abcdep4);
testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030);
testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030);
testfmt("0x1.83p+0", "%.2a", 1.51);
}
示例2: ATF_TC_BODY
ATF_TC_BODY(current_path__enoent, tc)
{
char* previous;
ATF_REQUIRE(!kyua_error_is_set(kyua_fs_current_path(&previous)));
ATF_REQUIRE(mkdir("root", 0755) != -1);
ATF_REQUIRE(chdir("root") != -1);
ATF_REQUIRE(rmdir("../root") != -1);
char* cwd = (char*)0xdeadbeef;
kyua_error_t error = kyua_fs_current_path(&cwd);
ATF_REQUIRE(kyua_error_is_set(error));
ATF_REQUIRE(kyua_error_is_type(error, "libc"));
ATF_REQUIRE_EQ(ENOENT, kyua_libc_error_errno(error));
ATF_REQUIRE_EQ((char*)0xdeadbeef, cwd);
kyua_error_free(error);
free(previous);
}
示例3: ATF_TC_BODY
ATF_TC_BODY(setlogin_perm, tc)
{
char *name;
pid_t pid;
int sta;
pid = fork();
ATF_REQUIRE(pid >= 0);
if (pid == 0) {
(void)setsid();
errno = 0;
if (setlogin("foobar") != -1)
_exit(EXIT_FAILURE);
if (errno != EPERM)
_exit(EXIT_FAILURE);
name = getlogin();
if (name == NULL)
_exit(EXIT_FAILURE);
if (strcmp(name, "foobar") == 0)
_exit(EXIT_FAILURE);
_exit(EXIT_SUCCESS);
}
(void)wait(&sta);
if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
atf_tc_fail("login name was set as an unprivileged user");
}
示例4: ATF_TC_BODY
ATF_TC_BODY(require_errno, tc)
{
struct test {
void (*head)(atf_tc_t *);
void (*body)(const atf_tc_t *);
bool ok;
const char *exp_regex;
} *t, tests[] = {
{ H_REQUIRE_ERRNO_HEAD_NAME(no_error),
H_REQUIRE_ERRNO_BODY_NAME(no_error),
false, "Expected true value in errno_ok_stub\\(\\) == -1" },
{ H_REQUIRE_ERRNO_HEAD_NAME(errno_ok),
H_REQUIRE_ERRNO_BODY_NAME(errno_ok),
true, NULL },
{ H_REQUIRE_ERRNO_HEAD_NAME(errno_fail),
H_REQUIRE_ERRNO_BODY_NAME(errno_fail),
false, "Expected errno 3, got 4, in errno_fail_stub\\(4\\) == -1" },
{ NULL, NULL, false, NULL }
};
for (t = &tests[0]; t->head != NULL; t++) {
init_and_run_h_tc("h_require_errno", t->head, t->body);
ATF_REQUIRE(exists("before"));
if (t->ok) {
ATF_REQUIRE(atf_utils_grep_file("^passed", "result"));
ATF_REQUIRE(exists("after"));
} else {
ATF_REQUIRE(atf_utils_grep_file(
"^failed: .*macros_test.c:[0-9]+: %s$", "result",
t->exp_regex));
ATF_REQUIRE(!exists("after"));
}
ATF_REQUIRE(unlink("before") != -1);
if (t->ok)
ATF_REQUIRE(unlink("after") != -1);
}
}
示例5: ATF_TC_BODY
ATF_TC_BODY(config, tcin)
{
atf_tc_t tc;
const char *const config[] = { "test-var", "test-value", NULL };
RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
ATF_TC_BODY_NAME(empty), NULL, NULL));
ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var"));
ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
atf_tc_fini(&tc);
RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
ATF_TC_BODY_NAME(empty), NULL, config));
ATF_REQUIRE(atf_tc_has_config_var(&tc, "test-var"));
ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc, "test-var"),
"test-value") == 0);
ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var2"));
ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc, "test-var2", "def-value"),
"def-value") == 0);
atf_tc_fini(&tc);
}
示例6: ATF_TC_BODY
ATF_TC_BODY(sigio, tc)
{
struct sockaddr_in sin;
int ls;
int cs;
int fl;
int sc;
signal(SIGIO, gotsig);
RZ(system("rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet "
RUMPSERV));
RL(setenv("RUMP_SERVER", RUMPSERV, 1));
RL(rumpclient_init());
RL(ls = rump_sys_socket(PF_INET, SOCK_STREAM, 0));
RL(rump_sys_fcntl(ls, F_SETOWN, rump_sys_getpid()));
RL(fl = rump_sys_fcntl(ls, F_GETFL));
RL(rump_sys_fcntl(ls, F_SETFL, fl | O_ASYNC));
memset(&sin, 0, sizeof(sin));
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
sin.sin_port = htons(12345);
RL(rump_sys_bind(ls, (struct sockaddr *)&sin, sizeof(sin)));
RL(rump_sys_listen(ls, 5));
RL(cs = rump_sys_socket(PF_INET, SOCK_STREAM, 0));
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
ATF_REQUIRE_EQ(sigcnt, 0);
RL(rump_sys_connect(cs, (struct sockaddr *)&sin, sizeof(sin)));
sc = sigcnt;
printf("sigcnt after connect: %d\n", sc);
ATF_REQUIRE(sc >= 1);
}
示例7: ATF_TC_BODY
ATF_TC_BODY(fpclassify_float, tc)
{
float d0, d1, d2, f, ip;
int e, i;
d0 = FLT_MIN;
ATF_REQUIRE_EQ(fpclassify(d0), FP_NORMAL);
f = frexpf(d0, &e);
ATF_REQUIRE_EQ(e, FLT_MIN_EXP);
ATF_REQUIRE_EQ(f, 0.5);
d1 = d0;
/* shift a "1" bit through the mantissa (skip the implicit bit) */
for (i = 1; i < FLT_MANT_DIG; i++) {
d1 /= 2;
ATF_REQUIRE_EQ(fpclassify(d1), FP_SUBNORMAL);
ATF_REQUIRE(d1 > 0 && d1 < d0);
d2 = ldexpf(d0, -i);
ATF_REQUIRE_EQ(d2, d1);
d2 = modff(d1, &ip);
ATF_REQUIRE_EQ(d2, d1);
ATF_REQUIRE_EQ(ip, 0);
f = frexpf(d1, &e);
ATF_REQUIRE_EQ(e, FLT_MIN_EXP - i);
ATF_REQUIRE_EQ(f, 0.5);
}
d1 /= 2;
ATF_REQUIRE_EQ(fpclassify(d1), FP_ZERO);
f = frexpf(d1, &e);
ATF_REQUIRE_EQ(e, 0);
ATF_REQUIRE_EQ(f, 0);
}
示例8: ATF_TC_BODY
ATF_TC_BODY(check_parsing, tc)
{
struct pkg_dep_formula *f;
const char *cases[] = {
"name",
"name = 1.0",
"name >= 1.0,1",
"name1, name2",
"name1 | name2, name3",
"name1 = 1.0 | name2 != 1.0, name3 > 1.0 < 2.0 != 1.5",
"name1 = 1.0 | name2 != 1.0, name3 > 1.0 < 2.0 != 1.5, name4 +opt1 -opt2"
};
char *r;
int i;
for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i ++) {
f = pkg_deps_parse_formula(cases[i]);
ATF_REQUIRE(f != NULL);
r = pkg_deps_formula_tostring(f);
ATF_REQUIRE_STREQ(r, cases[i]);
free(r);
pkg_deps_formula_free(f);
}
}
示例9: ATF_TC_BODY
ATF_TC_BODY(pkg_current_state_remote, tc)
{
struct pkg *package;
package = gen_pkg(PKG_REMOTE);
ATF_REQUIRE(package != NULL);
/* Old version newer -> available */
pkg_set(package, PKG_OLD_VERSION, "1.2.3");
ATF_CHECK_EQ(pkgutils_pkg_current_state(package),
PK_INFO_ENUM_AVAILABLE);
/* Old version the same -> installed */
pkg_set(package, PKG_OLD_VERSION, "1.1.4");
ATF_CHECK_EQ(pkgutils_pkg_current_state(package),
PK_INFO_ENUM_INSTALLED);
/* Old version older -> available */
pkg_set(package, PKG_OLD_VERSION, "1.0.0");
ATF_CHECK_EQ(pkgutils_pkg_current_state(package),
PK_INFO_ENUM_AVAILABLE);
pkg_free(package);
}
示例10: symlink_len
/*
* Test creating a symlink whose length is "len" bytes, not including
* the terminating NUL.
*/
static void
symlink_len(const atf_tc_t *tc, const char *mp, size_t len)
{
char *buf;
int r;
USES_SYMLINKS;
RL(rump_sys_chdir(mp));
buf = malloc(len + 1);
ATF_REQUIRE(buf);
memset(buf, 'a', len);
buf[len] = '\0';
r = rump_sys_symlink(buf, "afile");
if (r == -1) {
ATF_REQUIRE_ERRNO(ENAMETOOLONG, r);
} else {
RL(rump_sys_unlink("afile"));
}
free(buf);
RL(rump_sys_chdir("/"));
}
示例11: ATF_TC_BODY
ATF_TC_BODY(inet_addr_err, tc)
{
static const char *addrs[] = {
". . . .", "1.2.3.", "0.0.0.256", "255.255.255.256",
"................................................",
"a.b.c.d", "0x0.0x1.0x2.0x3", "-1.-1.-1.-1", "", " "};
struct in_addr ia;
const char *ian;
in_addr_t addr;
size_t i;
for (i = 0; i < __arraycount(addrs); i++) {
(void)fprintf(stderr, "checking %s\n", addrs[i]);;
addr = inet_addr(addrs[i]);
ia.s_addr = addr;
ian = inet_ntoa(ia);
ATF_REQUIRE(ian != NULL);
ATF_CHECK(strcmp(ian, addrs[i]) != 0);
}
}
示例12: ATF_TC_BODY
ATF_TC_BODY(mmap_loan, tc)
{
char buf[BUFSIZE];
char *vp, *vp2;
int fd;
fd = open(path, O_RDWR | O_CREAT, 0600);
ATF_REQUIRE(fd >= 0);
(void)memset(buf, 'x', sizeof(buf));
(void)write(fd, buf, sizeof(buf));
vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_PRIVATE, fd, 0);
ATF_REQUIRE(vp != MAP_FAILED);
vp2 = vp;
testloan(vp, vp2, 'A', 0);
testloan(vp, vp2, 'B', 1);
ATF_REQUIRE(munmap(vp, BUFSIZE) == 0);
vp = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, fd, 0);
vp2 = mmap(NULL, BUFSIZE, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, fd, 0);
ATF_REQUIRE(vp != MAP_FAILED);
ATF_REQUIRE(vp2 != MAP_FAILED);
testloan(vp, vp2, 'E', 1);
ATF_REQUIRE(munmap(vp, BUFSIZE) == 0);
ATF_REQUIRE(munmap(vp2, BUFSIZE) == 0);
}
示例13: ATF_TC_BODY
ATF_TC_BODY(error_new, tc)
{
atf_error_t err;
int data;
err = atf_error_new("test_error", NULL, 0, NULL);
ATF_REQUIRE(atf_error_is(err, "test_error"));
ATF_REQUIRE(!atf_error_is(err, "unknown_error"));
ATF_REQUIRE(atf_error_data(err) == NULL);
atf_error_free(err);
data = 5;
err = atf_error_new("test_data_error", &data, sizeof(data), NULL);
ATF_REQUIRE(atf_error_is(err, "test_data_error"));
ATF_REQUIRE(!atf_error_is(err, "unknown_error"));
ATF_REQUIRE(atf_error_data(err) != NULL);
ATF_REQUIRE_EQ(*((const int *)atf_error_data(err)), 5);
atf_error_free(err);
}
示例14: ATF_TC_BODY
ATF_TC_BODY(fdopen_seek, tc)
{
FILE *f;
int fd;
/*
* Verify that the file position associated
* with the stream corresponds with the offset
* set earlier for the file descriptor.
*/
fd = open(path, O_RDWR | O_CREAT);
ATF_REQUIRE(fd >= 0);
ATF_REQUIRE(write(fd, "garbage", 7) == 7);
ATF_REQUIRE(lseek(fd, 3, SEEK_SET) == 3);
f = fdopen(fd, "r+");
ATF_REQUIRE(f != NULL);
ATF_REQUIRE(ftell(f) == 3);
ATF_REQUIRE(fclose(f) == 0);
ATF_REQUIRE(unlink(path) == 0);
}
示例15: ATF_TC_BODY
ATF_TC_BODY(strtod_hex, tc)
{
const char *str;
char *end;
volatile double d;
str = "-0x0";
d = strtod(str, &end); /* -0.0 */
ATF_REQUIRE(end == str + 4);
ATF_REQUIRE(signbit(d) != 0);
ATF_REQUIRE(fabs(d) < SMALL_NUM);
str = "-0x";
d = strtod(str, &end); /* -0.0 */
ATF_REQUIRE(end == str + 2);
ATF_REQUIRE(signbit(d) != 0);
ATF_REQUIRE(fabs(d) < SMALL_NUM);
}