本文整理汇总了C++中ASSERT_INT_EQ函数的典型用法代码示例。如果您正苦于以下问题:C++ ASSERT_INT_EQ函数的具体用法?C++ ASSERT_INT_EQ怎么用?C++ ASSERT_INT_EQ使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ASSERT_INT_EQ函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sig_fuzz
static void
sig_fuzz(struct sshkey *k, const char *sig_alg)
{
struct fuzz *fuzz;
u_char *sig, c[] = "some junk to be signed";
size_t l;
u_int fuzzers = FUZZ_1_BIT_FLIP | FUZZ_1_BYTE_FLIP | FUZZ_2_BYTE_FLIP |
FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END;
if (test_is_fast())
fuzzers &= ~FUZZ_2_BYTE_FLIP;
if (test_is_slow())
fuzzers |= FUZZ_2_BIT_FLIP;
ASSERT_INT_EQ(sshkey_sign(k, &sig, &l, c, sizeof(c), sig_alg, 0), 0);
ASSERT_SIZE_T_GT(l, 0);
fuzz = fuzz_begin(fuzzers, sig, l);
ASSERT_INT_EQ(sshkey_verify(k, sig, l, c, sizeof(c), NULL, 0), 0);
free(sig);
TEST_ONERROR(onerror, fuzz);
for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
/* Ensure 1-bit difference at least */
if (fuzz_matches_original(fuzz))
continue;
ASSERT_INT_NE(sshkey_verify(k, fuzz_ptr(fuzz), fuzz_len(fuzz),
c, sizeof(c), NULL, 0), 0);
}
fuzz_cleanup(fuzz);
}
示例2: test_ensure
static void
test_ensure(void)
{
struct sol_buffer buf = SOL_BUFFER_INIT_EMPTY;
const int size = 1024;
char *buf_data;
int i;
sol_buffer_ensure(&buf, size);
memset(buf.data, 22, size);
sol_buffer_ensure(&buf, size * 2);
buf_data = buf.data;
for (i = 0; i < size; i++) {
ASSERT_INT_EQ(buf_data[i], 22);
}
sol_buffer_ensure(&buf, size / 2);
buf_data = buf.data;
for (i = 0; i < size / 2; i++) {
ASSERT_INT_EQ(buf_data[i], 22);
}
sol_buffer_fini(&buf);
}
示例3: munch
static void
munch(int fd, enum ev_type ev, void *arg)
{
ssize_t nbytes;
char buf[32] = { 0 };
int err;
if ((nbytes = read(fd, buf, sizeof (buf))) < 0) {
FAIL_ERRNO("bad read");
}
VERBOSE(("read %ld bytes '%s'", nbytes, buf));
err = mevent_disable(read_event);
ASSERT_INT_EQ(("mevent_disable: ", strerror(err)), err, 0);
pthread_mutex_lock(&mtx);
ASSERT_INT_EQ(("wrong lastwake"), lastwake, CB_NONE);
lastwake = CB_READ;
pthread_cond_signal(&cv);
VERBOSE(("wakeup"));
pthread_mutex_unlock(&mtx);
}
示例4: test_append_from_base64
static void
test_append_from_base64(void)
{
struct sol_buffer buf;
struct sol_str_slice slice;
const char to_decode[] = "VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXJz";
int err;
#define B64_DECODED "This is a message that is multiple of 3 chars"
sol_buffer_init(&buf);
slice = sol_str_slice_from_str("XYZ");
err = sol_buffer_append_slice(&buf, slice);
ASSERT_INT_EQ(err, 0);
ASSERT_INT_EQ(buf.used, strlen("XYZ"));
ASSERT_STR_EQ(buf.data, "XYZ");
slice = sol_str_slice_from_str(to_decode);
err = sol_buffer_append_from_base64(&buf, slice, SOL_BASE64_MAP);
ASSERT_INT_EQ(err, 0);
ASSERT_INT_EQ(buf.used, strlen("XYZ" B64_DECODED));
ASSERT_STR_EQ(buf.data, "XYZ" B64_DECODED);
sol_buffer_fini(&buf);
#undef B64_DECODED
}
示例5: test_append_from_base16
static void
test_append_from_base16(void)
{
struct sol_buffer buf;
struct sol_str_slice slice;
const char to_decode[] = "546573742001090a0f2048656c6c6f";
int err;
#define B16_DECODED "Test \x01\x09\x0a\x0f Hello"
sol_buffer_init(&buf);
slice = sol_str_slice_from_str("XYZ");
err = sol_buffer_append_slice(&buf, slice);
ASSERT_INT_EQ(err, 0);
ASSERT_INT_EQ(buf.used, strlen("XYZ"));
ASSERT_STR_EQ(buf.data, "XYZ");
slice = sol_str_slice_from_str(to_decode);
err = sol_buffer_append_from_base16(&buf, slice, SOL_DECODE_LOWERCASE);
ASSERT_INT_EQ(err, 0);
ASSERT_INT_EQ(buf.used, strlen("XYZ" B16_DECODED));
ASSERT_STR_EQ(buf.data, "XYZ" B16_DECODED);
sol_buffer_fini(&buf);
#undef B16_DECODED
}
示例6: public_fuzz
static void
public_fuzz(struct sshkey *k)
{
struct sshkey *k1;
struct sshbuf *buf;
struct fuzz *fuzz;
ASSERT_PTR_NE(buf = sshbuf_new(), NULL);
ASSERT_INT_EQ(sshkey_to_blob_buf(k, buf), 0);
/* XXX need a way to run the tests in "slow, but complete" mode */
fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | /* XXX too slow FUZZ_2_BIT_FLIP | */
FUZZ_1_BYTE_FLIP | /* XXX too slow FUZZ_2_BYTE_FLIP | */
FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END,
sshbuf_mutable_ptr(buf), sshbuf_len(buf));
ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(buf), sshbuf_len(buf),
&k1), 0);
sshkey_free(k1);
sshbuf_free(buf);
TEST_ONERROR(onerror, fuzz);
for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
if (sshkey_from_blob(fuzz_ptr(fuzz), fuzz_len(fuzz), &k1) == 0)
sshkey_free(k1);
}
fuzz_cleanup(fuzz);
}
示例7: test_no_nul_byte
static void
test_no_nul_byte(void)
{
struct sol_buffer buf;
int32_t backend;
int32_t value = 0xdeadbeef;
int err;
sol_buffer_init_flags(&buf, &backend, sizeof(backend),
SOL_BUFFER_FLAGS_MEMORY_NOT_OWNED | SOL_BUFFER_FLAGS_NO_NUL_BYTE);
err = sol_buffer_ensure(&buf, sizeof(int32_t));
ASSERT_INT_EQ(err, 0);
err = sol_buffer_append_slice(&buf, SOL_STR_SLICE_STR((const char *)&value, sizeof(value)));
ASSERT_INT_EQ(err, 0);
err = sol_buffer_append_slice(&buf, SOL_STR_SLICE_STR((const char *)&value, sizeof(value)));
ASSERT_INT_NE(err, 0);
sol_buffer_fini(&buf);
sol_buffer_init_flags(&buf, NULL, 0, SOL_BUFFER_FLAGS_NO_NUL_BYTE);
err = sol_buffer_append_printf(&buf, "123");
ASSERT_INT_EQ(err, 0);
err = sol_buffer_append_printf(&buf, "4");
ASSERT_INT_EQ(err, 0);
ASSERT(sol_str_slice_eq(sol_buffer_get_slice(&buf),
SOL_STR_SLICE_STR("1234", 4)));
sol_buffer_fini(&buf);
}
示例8: test_s2k
void
test_s2k(void)
{
TEST_START("s2k");
static unsigned char salt[S2K_SALT_BYTES] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
const char * pphrase = "ImGumbyAndYouAreNot";
static unsigned char expected_key1[AES128_KEY_BYTES] = {
0x0e, 0xa5, 0x00, 0x1c, 0xce, 0xad, 0x7e, 0xa8, 0xa0, 0x81, 0x38, 0xae, 0xaf, 0x4e, 0x28, 0xd5
};
unsigned char s2k_key1[AES128_KEY_BYTES];
compute_gpg_s2k_key(pphrase, sizeof(s2k_key1), salt, S2K_ITER_BYTE_COUNT, s2k_key1);
ASSERT_INT_EQ(memcmp(s2k_key1, expected_key1, sizeof(s2k_key1)), 0);
// Second test to handle the case where we need to run multiple hashes to generate enough bits
// Note that the first 16 bytes are the same as the previous test - this is to be expected, since the
// salt and passphrase are the same, so the first hash is executed identically.
static unsigned char expected_key2[48] = {
0x0e, 0xa5, 0x00, 0x1c, 0xce, 0xad, 0x7e, 0xa8, 0xa0, 0x81, 0x38, 0xae, 0xaf, 0x4e, 0x28, 0xd5,
0x21, 0xf1, 0xee, 0x4b, 0x02, 0xc0, 0x0f, 0x63, 0x6a, 0x17, 0xbf, 0x62, 0x34, 0x10, 0x26, 0x48,
0x7b, 0xc6, 0x3f, 0x08, 0x9d, 0xb5, 0x6b, 0x34, 0x70, 0x3b, 0x71, 0xdb, 0x67, 0x92, 0x6f, 0x5f
};
unsigned char s2k_key2[48];
compute_gpg_s2k_key(pphrase, sizeof(s2k_key2), salt, S2K_ITER_BYTE_COUNT, s2k_key2);
ASSERT_INT_EQ(memcmp(s2k_key2, expected_key2, sizeof(s2k_key2)), 0);
TEST_DONE();
}
示例9: test_coap_parse_empty_pdu
static void
test_coap_parse_empty_pdu(void)
{
uint8_t pdu[] = { 0x40, 0x01, 0, 0 };
struct sol_coap_packet *pkt;
struct sol_buffer *buf;
size_t offset;
uint8_t ver, type, code;
uint16_t id;
pkt = sol_coap_packet_new(NULL);
ASSERT(pkt);
ASSERT(!sol_coap_packet_get_payload(pkt, &buf, &offset));
ASSERT(!sol_buffer_remove_data(buf, 0, offset));
ASSERT(!sol_buffer_insert_bytes(buf, 0, pdu, sizeof(pdu)));
ASSERT(!coap_packet_parse(pkt));
sol_coap_header_get_version(pkt, &ver);
sol_coap_header_get_type(pkt, &type);
sol_coap_header_get_code(pkt, &code);
sol_coap_header_get_id(pkt, &id);
ASSERT_INT_EQ(ver, 1);
ASSERT_INT_EQ(type, SOL_COAP_MESSAGE_TYPE_CON);
ASSERT_INT_EQ(code, SOL_COAP_METHOD_GET);
ASSERT_INT_EQ(id, 0);
sol_coap_packet_unref(pkt);
}
示例10: test_coap_find_options
static void
test_coap_find_options(void)
{
uint8_t pdu[] = { 0x55, 0xA5, 0x12, 0x34, 't', 'o', 'k', 'e', 'n',
0x00, 0xC1, 0x00, 0xff, 'p', 'a', 'y', 'l', 'o', 'a', 'd', 0x00 };
struct sol_str_slice options[16];
struct sol_coap_packet *pkt;
struct sol_buffer *buf;
int count = 16;
size_t offset;
pkt = sol_coap_packet_new(NULL);
ASSERT(pkt);
ASSERT(!sol_coap_packet_get_payload(pkt, &buf, &offset));
ASSERT(!sol_buffer_remove_data(buf, 0, offset));
ASSERT(!sol_buffer_insert_bytes(buf, 0, pdu, sizeof(pdu)));
ASSERT(!coap_packet_parse(pkt));
count = sol_coap_find_options(pkt, SOL_COAP_OPTION_CONTENT_FORMAT, options, count);
ASSERT_INT_EQ(count, 1);
ASSERT_INT_EQ(options[0].len, 1);
ASSERT_INT_EQ((uint8_t)options[0].data[0], 0);
count = sol_coap_find_options(pkt, SOL_COAP_OPTION_IF_MATCH, options, count);
ASSERT_INT_EQ(count, 0);
sol_coap_packet_unref(pkt);
}
示例11: TEST_MAINLOOP_MAIN_FN
int
TEST_MAINLOOP_MAIN_FN(int argc, char *argv[])
{
int err, i;
struct sol_timeout *timeout_to_del;
struct sol_idle *idler_to_del;
err = sol_init();
ASSERT(!err);
timeout_to_del = sol_timeout_add(100, timeout_never_called, NULL);
sol_timeout_add(20, on_timeout_del_and_new, timeout_to_del);
sol_timeout_add(1, on_timeout_renew_twice, NULL);
sol_idle_add(on_idler_renew_twice, NULL);
for (i = 0; i < 5; i++)
sol_idle_add(on_idler, (void *)(intptr_t)i);
sol_idle_add(on_idler_del_another, &idler_to_del);
idler_to_del = sol_idle_add(on_idler_never_called, NULL);
sol_run();
ASSERT_INT_EQ(timeout_called, 3);
ASSERT_INT_EQ(timeout_renewed, 2);
ASSERT_INT_EQ(idler_renewed, 2);
for (i = 0; i < 10; i++)
ASSERT_INT_EQ(idler_sequence[i], i);
sol_shutdown();
return 0;
}
示例12: test_base64_encode
static void
test_base64_encode(void)
{
const char base64_map[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const char instr[] = "This is a message that is multiple of 3 chars";
const char *expectstrs[] = {
"VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXJz",
"VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYXI=",
"VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNoYQ==",
"VGhpcyBpcyBhIG1lc3NhZ2UgdGhhdCBpcyBtdWx0aXBsZSBvZiAzIGNo"
};
struct sol_str_slice slice;
char outstr[(sizeof(instr) / 3 + 1) * 4 + 1];
size_t r, i;
slice = sol_str_slice_from_str(instr);
for (i = 0; i < SOL_UTIL_ARRAY_SIZE(expectstrs); i++) {
struct sol_str_slice exp = sol_str_slice_from_str(expectstrs[i]);
memset(outstr, 0xff, sizeof(outstr));
r = sol_util_base64_encode(outstr, sizeof(outstr), slice, base64_map);
ASSERT_INT_EQ(r, exp.len);
ASSERT_INT_EQ(outstr[r], (char)0xff);
outstr[r] = '\0';
ASSERT_STR_EQ(outstr, exp.data);
slice.len--;
}
}
示例13: public_fuzz
static void
public_fuzz(struct sshkey *k)
{
struct sshkey *k1;
struct sshbuf *buf;
struct fuzz *fuzz;
u_int fuzzers = FUZZ_1_BIT_FLIP | FUZZ_1_BYTE_FLIP |
FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END;
if (test_is_fast())
fuzzers &= ~FUZZ_1_BIT_FLIP;
if (test_is_slow())
fuzzers |= FUZZ_2_BIT_FLIP | FUZZ_2_BYTE_FLIP;
ASSERT_PTR_NE(buf = sshbuf_new(), NULL);
ASSERT_INT_EQ(sshkey_putb(k, buf), 0);
fuzz = fuzz_begin(fuzzers, sshbuf_mutable_ptr(buf), sshbuf_len(buf));
ASSERT_INT_EQ(sshkey_from_blob(sshbuf_ptr(buf), sshbuf_len(buf),
&k1), 0);
sshkey_free(k1);
sshbuf_free(buf);
TEST_ONERROR(onerror, fuzz);
for(; !fuzz_done(fuzz); fuzz_next(fuzz)) {
if (sshkey_from_blob(fuzz_ptr(fuzz), fuzz_len(fuzz), &k1) == 0)
sshkey_free(k1);
}
fuzz_cleanup(fuzz);
}
示例14: test_coap_find_options
static void
test_coap_find_options(void)
{
uint8_t pdu[] = { 0x55, 0xA5, 0x12, 0x34, 't', 'o', 'k', 'e', 'n',
0x00, 0xC1, 0x00, 0xff, 'p', 'a', 'y', 'l', 'o', 'a', 'd', 0x00 };
struct sol_coap_packet *pkt;
struct sol_str_slice options[16];
int count = 16;
pkt = sol_coap_packet_new(NULL);
ASSERT(pkt);
memcpy(pkt->buf, pdu, sizeof(pdu));
pkt->payload.size = sizeof(pdu);
ASSERT(!coap_packet_parse(pkt));
count = sol_coap_find_options(pkt, SOL_COAP_OPTION_CONTENT_FORMAT, options, count);
ASSERT_INT_EQ(count, 1);
ASSERT_INT_EQ(options[0].len, 1);
ASSERT_INT_EQ((uint8_t)options[0].data[0], 0);
count = sol_coap_find_options(pkt, SOL_COAP_OPTION_IF_MATCH, options, count);
ASSERT_INT_EQ(count, 0);
sol_coap_packet_unref(pkt);
}
示例15: test_coap_parse_simple_pdu
static void
test_coap_parse_simple_pdu(void)
{
uint8_t pdu[] = { 0x55, 0xA5, 0x12, 0x34, 't', 'o', 'k', 'e',
'n', 0x00, 0xc1, 0x00, 0xff, 'p', 'a', 'y',
'l', 'o', 'a', 'd', 0x00 };
struct sol_str_slice options[16];
struct sol_coap_packet *pkt;
struct sol_buffer *buf;
uint8_t *token;
int count = 16;
size_t offset;
uint8_t tkl, code, ver, type;
uint16_t id;
pkt = sol_coap_packet_new(NULL);
ASSERT(pkt);
ASSERT(!sol_coap_packet_get_payload(pkt, &buf, &offset));
ASSERT(!sol_buffer_remove_data(buf, 0, offset));
ASSERT(!sol_buffer_insert_bytes(buf, 0, pdu, sizeof(pdu)));
ASSERT(!coap_packet_parse(pkt));
sol_coap_header_get_version(pkt, &ver);
sol_coap_header_get_type(pkt, &type);
ASSERT_INT_EQ(ver, 1);
ASSERT_INT_EQ(type, SOL_COAP_MESSAGE_TYPE_NON_CON);
token = sol_coap_header_get_token(pkt, &tkl);
ASSERT(token);
ASSERT_INT_EQ(tkl, 5);
ASSERT(!strcmp((char *)token, "token"));
sol_coap_header_get_code(pkt, &code);
sol_coap_header_get_id(pkt, &id);
ASSERT_INT_EQ(code, SOL_COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED);
ASSERT_INT_EQ(id, 0x1234);
count = sol_coap_find_options(pkt, SOL_COAP_OPTION_CONTENT_FORMAT, options, count);
ASSERT_INT_EQ(count, 1);
ASSERT_INT_EQ(options[0].len, 1);
ASSERT_INT_EQ((uint8_t)options[0].data[0], 0);
/* Not existent. */
count = sol_coap_find_options(pkt, SOL_COAP_OPTION_ETAG, options, count);
ASSERT_INT_EQ(count, 0);
ASSERT(!sol_coap_packet_get_payload(pkt, &buf, &offset));
ASSERT_INT_EQ(offset + sizeof("payload"), buf->used);
ASSERT(!strcmp((char *)buf->data + offset, "payload"));
sol_coap_packet_unref(pkt);
}