本文整理汇总了C++中STRING_CONST函数的典型用法代码示例。如果您正苦于以下问题:C++ STRING_CONST函数的具体用法?C++ STRING_CONST怎么用?C++ STRING_CONST使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了STRING_CONST函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buffer_stream_initialize
void
buffer_stream_initialize(stream_buffer_t* stream, void* buffer, unsigned int mode, size_t size,
size_t capacity, bool adopt, bool grow) {
memset(stream, 0, sizeof(stream_buffer_t));
stream_initialize((stream_t*)stream, system_byteorder());
if (!adopt && grow) {
log_warn(0, WARNING_INVALID_VALUE, STRING_CONST("Cannot grow buffer streams that are not adopted"));
grow = false;
}
if (!buffer) {
size = 0;
capacity = 0;
}
if (size > capacity)
size = capacity;
stream->type = STREAMTYPE_MEMORY;
stream->path = string_allocate_format(STRING_CONST("buffer://0x%" PRIfixPTR), (uintptr_t)stream);
stream->mode = mode & (STREAM_OUT | STREAM_IN | STREAM_BINARY);
stream->buffer = buffer;
stream->size = size;
stream->capacity = capacity;
stream->own = adopt;
stream->grow = (adopt && grow);
stream->lastmod = time_current();
if ((mode & STREAM_OUT) && (mode & STREAM_TRUNCATE))
stream->size = 0;
if (mode & STREAM_ATEND)
stream->current = stream->size;
stream->vtable = &_buffer_stream_vtable;
}
示例2: hashify_check_local_consistency
int
hashify_check_local_consistency(string_const_t string, hash_t hash_value,
const hashify_string_t* local_hashes) {
size_t ilocal, localsize;
for (ilocal = 0, localsize = array_size(local_hashes); ilocal < localsize; ++ilocal) {
if (local_hashes[ilocal].hash == hash_value) {
if (!string_equal(local_hashes[ilocal].string.str, local_hashes[ilocal].string.length, string.str,
string.length)) {
log_errorf(0, ERROR_INVALID_VALUE,
STRING_CONST(" hash string mismatch, \"%.*s\" with hash 0x%" PRIx64
" stored in output file, read \"%.*s\" from input file"),
STRING_FORMAT(local_hashes[ilocal].string), local_hashes[ilocal].hash, STRING_FORMAT(string));
return HASHIFY_RESULT_HASH_STRING_MISMATCH;
}
break;
}
else if (string_equal(local_hashes[ilocal].string.str, local_hashes[ilocal].string.length,
string.str, string.length)) {
log_errorf(0, ERROR_INVALID_VALUE,
STRING_CONST(" hash mismatch, \"%.*s\" with hash 0x%" PRIx64
" stored in output file, read \"%.*s\" with hash 0x%" PRIx64 " from input file"),
STRING_FORMAT(local_hashes[ilocal].string), local_hashes[ilocal].hash, STRING_FORMAT(string),
hash_value);
return HASHIFY_RESULT_HASH_MISMATCH;
}
}
if (ilocal == localsize) {
log_errorf(0, ERROR_INVALID_VALUE,
STRING_CONST(" hash missing in output file, \"%.*s\" with hash 0x%" PRIx64), STRING_FORMAT(string),
hash_value);
return HASHIFY_RESULT_HASH_MISSING;
}
return HASHIFY_RESULT_OK;
}
示例3: DECLARE_TEST
DECLARE_TEST(md5, reference) {
md5_t* md5;
char md5str[32];
string_t digest;
md5 = md5_allocate();
md5_digest_finalize(md5);
md5_digest(md5, "testing md5 implementation", 26);
md5_digest_finalize(md5);
digest = md5_get_digest(md5, md5str, sizeof(md5str));
EXPECT_STRINGEQ(digest, string_const(STRING_CONST("4E24E37E5E06F23210FA1518E97A50C4")));
md5_digest(md5, "testing md5 implementation", 26);
md5_digest(md5, "", 0);
md5_digest(md5, "further testing md5 implementation with long buffer > 32 bytes", 62);
md5_digest_finalize(md5);
digest = md5_get_digest(md5, md5str, sizeof(md5str));
EXPECT_STRINGEQ(digest, string_const(STRING_CONST("BD870884942EA7B32A9CB2547B02B871")));
md5_digest(md5, digest_test_string, 2000);
md5_digest_finalize(md5);
digest = md5_get_digest(md5, md5str, sizeof(md5str));
EXPECT_STRINGEQ(digest, string_const(STRING_CONST("137D3C94230A0E230C4DDFC97EACCCD2")));
md5_deallocate(md5);
return 0;
}
示例4: stream_blocking_thread
static void*
stream_blocking_thread(void* arg) {
int iloop;
socket_t* sock = (socket_t*)arg;
char buffer_out[317] = {0};
char buffer_in[317] = {0};
stream_t* stream = socket_stream(sock);
for (iloop = 0; !thread_try_wait(0) && iloop < 512; ++iloop) {
log_infof(HASH_NETWORK, STRING_CONST("UDP write pass %d"), iloop);
EXPECT_SIZEEQ(stream_write(stream, buffer_out, 127), 127);
EXPECT_SIZEEQ(stream_write(stream, buffer_out + 127, 180), 180);
stream_flush(stream);
EXPECT_SIZEEQ(stream_write(stream, buffer_out + 307, 10), 10);
stream_flush(stream);
log_infof(HASH_NETWORK, STRING_CONST("UDP read pass %d"), iloop);
EXPECT_SIZEEQ(stream_read(stream, buffer_in, 235), 235);
EXPECT_SIZEEQ(stream_read(stream, buffer_in + 235, 82), 82);
thread_yield();
}
log_debugf(HASH_NETWORK, STRING_CONST("IO complete on socket 0x%llx"), sock);
stream_deallocate(stream);
return 0;
}
示例5: DECLARE_TEST
DECLARE_TEST(mutex, sync) {
mutex_t* mutex;
thread_t thread[32];
size_t ith;
mutex = mutex_allocate(STRING_CONST("test"));
mutex_lock(mutex);
for (ith = 0; ith < 32; ++ith)
thread_initialize(&thread[ith], mutex_thread, mutex, STRING_CONST("mutex_thread"),
THREAD_PRIORITY_NORMAL, 0);
for (ith = 0; ith < 32; ++ith)
thread_start(&thread[ith]);
test_wait_for_threads_startup(thread, 32);
mutex_unlock(mutex);
test_wait_for_threads_finish(thread, 32);
for (ith = 0; ith < 32; ++ith)
thread_finalize(&thread[ith]);
mutex_deallocate(mutex);
EXPECT_EQ(thread_counter, 32 * 128);
return 0;
}
示例6: hashify_write_file
int
hashify_write_file(stream_t* generated_file, string_t output_filename) {
bool need_update = false;
stream_t* output_file = 0;
int result = HASHIFY_RESULT_OK;
output_file = stream_open(STRING_ARGS(output_filename), STREAM_OUT | STREAM_IN);
if (!output_file) {
need_update = true;
output_file = stream_open(STRING_ARGS(output_filename), STREAM_OUT);
if (!output_file) {
log_warnf(0, WARNING_INVALID_VALUE, STRING_CONST("Unable to open output file: %.*s"),
STRING_FORMAT(output_filename));
return HASHIFY_RESULT_MISSING_OUTPUT_FILE;
}
}
if (!need_update)
need_update = !uint128_equal(stream_md5(generated_file), stream_md5(output_file));
if (need_update) {
char local_buffer[1024];
size_t read = 0;
size_t written = 0;
uint64_t total_written = 0;
stream_seek(generated_file, 0, STREAM_SEEK_BEGIN);
stream_seek(output_file, 0, STREAM_SEEK_BEGIN);
while (!stream_eos(generated_file)) {
read = stream_read(generated_file, local_buffer, 1024);
if (!read)
break;
written = stream_write(output_file, local_buffer, read);
total_written += written;
if (written != read) {
log_errorf(0, ERROR_SYSTEM_CALL_FAIL,
STRING_CONST("Unable to write to output file '%.*s': %" PRIsize " of %" PRIsize " bytes written"),
STRING_FORMAT(output_filename), written, read);
result = HASHIFY_RESULT_OUTPUT_FILE_WRITE_FAIL;
break;
}
}
if (result == HASHIFY_RESULT_OK) {
stream_truncate(output_file, (size_t)total_written);
log_infof(0, STRING_CONST(" wrote %.*s : %" PRIu64 " bytes"), STRING_FORMAT(output_filename),
total_written);
}
}
else {
log_info(0, STRING_CONST(" hash file already up to date"));
}
stream_deallocate(output_file);
return result;
}
示例7: datagram_client_blocking_thread
static void*
datagram_client_blocking_thread(void* arg) {
int iloop;
test_datagram_arg_t* darg = arg;
socket_t* sock = darg->sock;
network_address_t* target = darg->target;
const network_address_t* address;
char buffer[1024] = {0};
size_t send = 973;
size_t recv;
log_debugf(HASH_NETWORK, STRING_CONST("IO start on socket 0x%llx"), sock);
for (iloop = 0; iloop < 512; ++iloop) {
log_infof(HASH_NETWORK, STRING_CONST("UDP read/write pass %d"), iloop);
EXPECT_EQ(udp_socket_sendto(sock, buffer, send, target), send);
recv = udp_socket_recvfrom(sock, buffer, send, &address);
EXPECT_EQ(recv, send);
EXPECT_TRUE(network_address_equal(target, address));
thread_yield();
}
log_infof(HASH_NETWORK, STRING_CONST("IO complete on socket 0x%llx"), sock);
return 0;
}
示例8: blast_client_read_ack
static void
blast_client_read_ack(blast_client_t* client) {
const network_address_t* address = 0;
char databuf[PACKET_DATABUF_SIZE];
size_t size = udp_socket_recvfrom(client->sock, databuf, sizeof(databuf), &address);
while (size > 0) {
packet_t* packet = (packet_t*)databuf;
if (network_address_equal(address, socket_address_remote(client->sock))) {
if (packet->type == PACKET_ACK) {
packet_ack_t* ack = (packet_ack_t*)packet;
blast_client_process_ack(client, ack->ack, packet->timestamp);
}
else if (packet->type == PACKET_TERMINATE) {
log_info(HASH_BLAST, STRING_CONST("Client terminating due to TERMINATE packet from server"));
client->state = BLAST_STATE_FINISHED;
break;
}
}
else {
char buffer[NETWORK_ADDRESS_NUMERIC_MAX_LENGTH];
string_t addr = network_address_to_string(buffer, sizeof(buffer), address, true);
log_warnf(HASH_BLAST, WARNING_SUSPICIOUS, STRING_CONST("Ignoring datagram from unknown host %.*s"),
STRING_FORMAT(addr));
}
size = udp_socket_recvfrom(client->sock, databuf, sizeof(databuf), &address);
}
}
示例9: test_error_application
static application_t
test_error_application(void) {
application_t app;
memset(&app, 0, sizeof(app));
app.name = string_const(STRING_CONST("Foundation error tests"));
app.short_name = string_const(STRING_CONST("test_error"));
app.company = string_const(STRING_CONST("Rampant Pixels"));
app.flags = APPLICATION_UTILITY;
app.exception_handler = test_exception_handler;
return app;
}
示例10: test_environment_application
static application_t
test_environment_application(void) {
application_t app;
memset(&app, 0, sizeof(app));
app.name = string_const(STRING_CONST("Foundation environment tests"));
app.short_name = string_const(STRING_CONST("test_environment"));
app.config_dir = string_const(STRING_CONST("test_environment"));
app.flags = APPLICATION_UTILITY;
app.dump_callback = test_crash_handler;
return app;
}
示例11: test_exception_handler
void
test_exception_handler(const char* dump_file, size_t length) {
FOUNDATION_UNUSED(dump_file);
FOUNDATION_UNUSED(length);
log_error(HASH_TEST, ERROR_EXCEPTION, STRING_CONST("Test raised exception"));
#if (FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID) && !BUILD_ENABLE_LOG
test_log_view_append(STRING_CONST("Test raised exception\n"));
thread_sleep(5000);
#endif
process_exit(-1);
}
示例12: blast_client
int
blast_client(network_address_t** * target, string_t* files) {
int itarg, tsize = 0;
int iclient, csize = 0;
int ifile, fsize = 0;
bool running = true;
int result = BLAST_RESULT_OK;
blast_reader_t* reader = 0;
blast_reader_t** readers = 0;
for (ifile = 0, fsize = array_size(files); ifile < fsize; ++ifile) {
reader = blast_reader_open(files[ifile]);
if (!reader) {
log_warnf(HASH_BLAST, WARNING_SUSPICIOUS, STRING_CONST("Unable to open reader for: %.*s"),
STRING_ARGS(files[ifile]));
return BLAST_ERROR_UNABLE_TO_OPEN_FILE;
}
array_push(readers, reader);
}
if (array_size(readers) == 0) {
log_warnf(HASH_BLAST, WARNING_INVALID_VALUE, STRING_CONST("No input files given"));
return BLAST_ERROR_UNABLE_TO_OPEN_FILE;
}
for (itarg = 0, tsize = array_size(target); itarg < tsize; ++itarg) {
blast_client_t client;
if (blast_client_initialize(&client, target[itarg]) == BLAST_RESULT_OK) {
client.readers = readers;
array_push(clients, client);
}
}
while (running && !blast_should_exit()) {
running = false;
for (iclient = 0, csize = array_size(clients); iclient < csize; ++iclient)
running |= blast_client_process(clients + iclient);
blast_process_system_events();
}
for (iclient = 0, csize = array_size(clients); iclient < csize; ++iclient)
blast_client_deallocate(&clients[iclient]);
array_deallocate(clients);
for (ifile = 0, fsize = array_size(readers); ifile < fsize; ++ifile)
blast_reader_close(readers[ifile]);
array_deallocate(readers);
return result;
}
示例13: assert_report
int
assert_report(hash_t context, const char* condition, size_t cond_length, const char* file,
size_t file_length, unsigned int line, const char* msg, size_t msg_length) {
static const char nocondition[] = "<Static fail>";
static const char nofile[] = "<No file>";
static const char nomsg[] = "<No message>";
static const char assert_format[] =
"****** ASSERT FAILED ******\nCondition: %.*s\nFile/line: %.*s : %d\n%.*s%.*s\n%.*s\n";
#if BUILD_ENABLE_ASSERT
string_t tracestr = { _assert_stacktrace_buffer, sizeof(_assert_stacktrace_buffer) };
string_t contextstr = { _assert_context_buffer, sizeof(_assert_context_buffer) };
string_t messagestr = { _assert_message_buffer, sizeof(_assert_message_buffer) };
#endif
if (!condition || !cond_length) { condition = nocondition; cond_length = sizeof(nocondition); }
if (!file || !file_length) { file = nofile; file_length = sizeof(nofile); }
if (!msg || !msg_length) { msg = nomsg; msg_length = sizeof(nomsg); }
if (_assert_handler && (_assert_handler != assert_report))
return (*_assert_handler)(context, condition, cond_length, file, file_length, line, msg,
msg_length);
#if BUILD_ENABLE_ASSERT
contextstr = error_context_buffer(STRING_ARGS(contextstr));
if (foundation_is_initialized()) {
size_t num_frames = stacktrace_capture(_assert_stacktrace, ASSERT_STACKTRACE_MAX_DEPTH,
ASSERT_STACKTRACE_SKIP_FRAMES);
if (num_frames)
tracestr = stacktrace_resolve(STRING_ARGS(tracestr), _assert_stacktrace, num_frames, 0U);
else
tracestr = string_copy(STRING_ARGS(tracestr), STRING_CONST("<no stacktrace>"));
}
else {
tracestr = string_copy(STRING_ARGS(tracestr), STRING_CONST("<no stacktrace - not initialized>"));
}
messagestr = string_format(STRING_ARGS(messagestr), assert_format, sizeof(assert_format) - 1,
(int)cond_length, condition, (int)file_length, file, line,
STRING_FORMAT(contextstr), (int)msg_length, msg,
STRING_FORMAT(tracestr));
log_errorf(context, ERROR_ASSERT, STRING_CONST("%.*s"), STRING_FORMAT(messagestr));
system_message_box(STRING_CONST("Assert Failure"), STRING_ARGS(messagestr), false);
#else
log_errorf(context, ERROR_ASSERT, assert_format, sizeof(assert_format) - 1,
(int)cond_length, condition, (int)file_length, file, line,
0, "", (int)msg_length, msg, 0, "");
#endif
return 1;
}
示例14: main_initialize
int
main_initialize(void) {
foundation_config_t config;
application_t application;
int ret;
size_t iarg, asize;
const string_const_t* cmdline = environment_command_line();
_test_memory_tracker = true;
for (iarg = 0, asize = array_size(cmdline); iarg < asize; ++iarg) {
if (string_equal(STRING_ARGS(cmdline[iarg]), STRING_CONST("--no-memory-tracker")))
_test_memory_tracker = false;
}
if (_test_memory_tracker)
memory_set_tracker(memory_tracker_local());
memset(&config, 0, sizeof(config));
memset(&application, 0, sizeof(application));
application.name = string_const(STRING_CONST("Task library test suite"));
application.short_name = string_const(STRING_CONST("test_all"));
application.company = string_const(STRING_CONST("Rampant Pixels"));
application.version = task_module_version();
application.flags = APPLICATION_UTILITY;
application.exception_handler = test_exception_handler;
log_set_suppress(0, ERRORLEVEL_INFO);
#if ( FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID ) && BUILD_ENABLE_LOG
log_set_handler(test_log_handler);
#endif
#if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_PNACL
_test_should_start = true;
#endif
ret = foundation_initialize(memory_system_malloc(), application, config);
#if BUILD_MONOLITHIC
if (ret == 0) {
task_config_t task_config;
memset(&task_config, 0, sizeof(task_config));
ret = task_module_initialize(task_config);
test_set_suitable_working_directory();
}
#endif
return ret;
}
示例15: event_loop
static void*
event_loop(void* arg) {
event_block_t* block;
event_t* event = 0;
FOUNDATION_UNUSED(arg);
event_stream_set_beacon(system_event_stream(), &thread_self()->beacon);
while (!_test_should_terminate) {
block = event_stream_process(system_event_stream());
event = 0;
while ((event = event_next(block, event))) {
switch (event->id) {
case FOUNDATIONEVENT_START:
#if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID || FOUNDATION_PLATFORM_PNACL
log_debug(HASH_TEST, STRING_CONST("Application start event received"));
_test_should_start = true;
#endif
break;
case FOUNDATIONEVENT_TERMINATE:
#if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID || FOUNDATION_PLATFORM_PNACL
log_debug(HASH_TEST, STRING_CONST("Application stop/terminate event received"));
_test_should_terminate = true;
break;
#else
log_warn(HASH_TEST, WARNING_SUSPICIOUS, STRING_CONST("Terminating tests due to event"));
process_exit(-2);
#endif
case FOUNDATIONEVENT_FOCUS_GAIN:
_test_have_focus = true;
break;
case FOUNDATIONEVENT_FOCUS_LOST:
_test_have_focus = false;
break;
default:
break;
}
test_event(event);
}
thread_wait();
}
log_debug(HASH_TEST, STRING_CONST("Application event thread exiting"));
return 0;
}