Skip to content

Commit

Permalink
#16 fix build for 2.3.19.2 removed usage of DOVECOT_PREREQ Macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Feb 26, 2023
1 parent dd81bd0 commit cfd3405
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 48 deletions.
42 changes: 30 additions & 12 deletions src/lib-test/push-notification-kafka-event-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "push-notification-event-messagenew.h"
#include "push-notification-event-messageappend.h"
#include "push-notification-events.h"
#include "push-notification-kafka-driver.h"

static void test_str_starts_with(void) {
test_begin("unit_test_str_starts_with");
Expand Down Expand Up @@ -155,20 +156,26 @@ static void write_msg_prefix_test(void) {
str_append(test,
"{\"user\":\"testuser\",\"mailbox\":\"INBOX\",\"event\":\"MailboxCreate\",\"uidvalidity\":2,\"uid\":1");
struct push_notification_driver_txn dtxn;
struct push_notification_driver_user duser;
struct push_notification_txn ptxn;
struct mail_user user;
struct push_notification_driver_kafka_context context;
context.userdb_json = NULL;

user.username = "testuser";
ptxn.muser = &user;
ptxn.pool = pool;
dtxn.ptxn = &ptxn;
duser.context = (void*)&context;

dtxn.duser = &duser;

struct push_notification_txn_msg event;
event.uid = 1;
event.uid_validity = 2;
event.mailbox = "INBOX";
#if ! DOVECOT_PREREQ(2, 3)
event.seq = 1;
#endif
array_create(&event.eventdata, pool, sizeof(void *), 1);
event.save_idx = 0;

string_t *t = write_msg_prefix(&dtxn, "MailboxCreate", &event);
// i_info("MSG: %s ", str_c(t));
Expand All @@ -188,6 +195,13 @@ static void write_flags_event_test(void) {
"\"k:old_keyword\"]}");

struct push_notification_driver_txn dtxn;

struct push_notification_driver_user duser;
struct push_notification_driver_kafka_context context;
context.userdb_json = NULL;
duser.context = (void*)&context;
dtxn.duser = &duser;

struct push_notification_txn ptxn;
struct mail_user user;
user.username = "testuser";
Expand All @@ -199,9 +213,6 @@ static void write_flags_event_test(void) {
event.uid = 1;
event.uid_validity = 2;
event.mailbox = "INBOX";
#if ! DOVECOT_PREREQ(2, 3)
event.seq = 1;
#endif

struct push_notification_driver_kafka_render_context ctx;
ctx.send_flags = TRUE;
Expand Down Expand Up @@ -283,14 +294,18 @@ static void write_event_messagenew_test(void) {
ptxn.muser = &user;
ptxn.pool = pool;
dtxn.ptxn = &ptxn;

struct push_notification_driver_user duser;
struct push_notification_driver_kafka_context context;
context.userdb_json = NULL;
duser.context = (void*)&context;
dtxn.duser = &duser;


struct push_notification_txn_msg msg;
msg.uid = 1;
msg.uid_validity = 2;
msg.mailbox = "INBOX";
#if ! DOVECOT_PREREQ(2, 3)
msg.seq = 1;
#endif

struct push_notification_txn_event event;
struct push_notification_event_messagenew_data data;
Expand Down Expand Up @@ -334,13 +349,16 @@ static void write_event_messageappend_test(void) {
ptxn.pool = pool;
dtxn.ptxn = &ptxn;

struct push_notification_driver_user duser;
struct push_notification_driver_kafka_context context;
context.userdb_json = NULL;
duser.context = (void*)&context;
dtxn.duser = &duser;

struct push_notification_txn_msg msg;
msg.uid = 1;
msg.uid_validity = 2;
msg.mailbox = "INBOX";
#if ! DOVECOT_PREREQ(2, 3)
msg.seq = 1;
#endif

struct push_notification_txn_event event;
struct push_notification_event_messageappend_data data;
Expand Down
41 changes: 5 additions & 36 deletions src/lib-test/test-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ static ssize_t test_read(struct istream_private *stream)
} else {
/* copy data to a buffer in somewhat random place. this could
help catch bugs. */
#if DOVECOT_PREREQ(2, 3)
new_skip_diff = i_rand() % 128;
#else
new_skip_diff = rand() % 128;
#endif
new_skip_diff = i_rand() % 128;
stream->skip = (stream->skip - tstream->skip_diff) +
new_skip_diff;
stream->pos = (stream->pos - tstream->skip_diff) +
Expand Down Expand Up @@ -115,12 +111,9 @@ struct istream *test_istream_create_data(const void *data, size_t size)

tstream->istream.istream.blocking = FALSE;
tstream->istream.istream.seekable = TRUE;
#if DOVECOT_PREREQ(2, 3)
i_stream_create(&tstream->istream, NULL, -1, 0);
#else
i_stream_create(&tstream->istream, NULL, -1);
#endif
tstream->istream.statbuf.st_size = tstream->max_pos = size;
i_stream_create(&tstream->istream, NULL, -1, 0);

tstream->istream.statbuf.st_size = tstream->max_pos = size;
tstream->allow_eof = TRUE;
tstream->istream.max_buffer_size = (size_t)-1;
return &tstream->istream.istream;
Expand Down Expand Up @@ -186,32 +179,8 @@ void test_assert_failed_idx(const char *code, const char *file, unsigned int lin
test_success = FALSE;
}

#ifdef DEBUG
#include "randgen.h"
static void
test_dump_rand_state(void)
{
static int64_t seen_seed = -1;
unsigned int seed;
#if DOVECOT_PREREQ(2, 3)
if (rand_get_last_seed(&seed) < 0) {
#else
if (rand_get_last_seed() < 0) {
#endif
if (seen_seed == -1) {
printf("test: random sequence not reproduceable, use DOVECOT_SRAND=kiss\n");
seen_seed = -2;
}
return;
}
if (seed == seen_seed)
return;
seen_seed = seed;
printf("test: DOVECOT_SRAND random seed was %u\n", seed);
}
#else

static inline void test_dump_rand_state(void) { }
#endif

void test_end(void)
{
Expand Down

0 comments on commit cfd3405

Please sign in to comment.