END_TEST START_TEST (test_enqueue_adds_crlf) { char* message = "a message"; bool result = conditionalEnqueue(&queue, (uint8_t*)message, 9); fail_unless(result); ck_assert_int_eq(QUEUE_LENGTH(uint8_t, &queue), 11); uint8_t snapshot[QUEUE_LENGTH(uint8_t, &queue)]; QUEUE_SNAPSHOT(uint8_t, &queue, snapshot); const char* expected = "a message\r\n"; for(int i = 0; i < 11; i++) { fail_unless((char)snapshot[i] == expected[i]); } }
END_TEST START_TEST (test_force_send) { fail_if(sendCanSignal(&SIGNALS[1], cJSON_CreateString(SIGNAL_STATES[0][1].name), customStateWriter, SIGNALS, SIGNAL_COUNT, true)); ck_assert_int_eq(1, QUEUE_LENGTH(CanMessage, &SIGNALS[1].message->bus->sendQueue)); }
END_TEST START_TEST (test_enqueue) { CanMessage message = {&bus, 42}; enqueueCanMessage(&message, 0x123456); ck_assert_int_eq(1, QUEUE_LENGTH(CanMessage, &message.bus->sendQueue)); }
#include "util/bytebuffer.h" #include "strutil.h" #include "util/log.h" QUEUE_DEFINE(uint8_t) void openxc::util::bytebuffer::processQueue(QUEUE_TYPE(uint8_t)* queue, bool (*callback)(uint8_t*)) { int length = QUEUE_LENGTH(uint8_t, queue); if(length == 0) { return; } uint8_t snapshot[length]; QUEUE_SNAPSHOT(uint8_t, queue, snapshot); if(callback == NULL) { debug("Callback is NULL (%p) -- unable to handle queue at %p", callback, queue); return; } if(callback(snapshot)) { QUEUE_INIT(uint8_t, queue); } else if(QUEUE_FULL(uint8_t, queue)) { debug("Incoming write is too long"); QUEUE_INIT(uint8_t, queue); } else if(strnchr((char*)snapshot, sizeof(snapshot) - 1, '\0') != NULL) { debug("Incoming buffered write corrupted (%s) -- clearing buffer", snapshot); QUEUE_INIT(uint8_t, queue); } }