END_TEST START_TEST(from_file) { char pathname[PATH_MAX]; FILE *fh; long fsize; char *content, *dump; snprintf(pathname, sizeof(pathname), "%s/%s", SAMPLES_DIR, test_files[_i]); fail_unless(smf_message_from_file(&msg, pathname, 0) == 0); fail_unless((fh = fopen(pathname, "r")) != NULL); fail_unless(fseek(fh, 0, SEEK_END) == 0); fail_if((fsize = ftell(fh)) == -1); rewind(fh); content = malloc(fsize + 1); fail_unless(fread(content, 1, fsize, fh) == fsize); content[fsize] = '\0'; fail_unless((dump = smf_message_to_string(msg)) != NULL); ck_assert_str_eq(content, dump); free(content); free(dump); fclose(fh); }
static SMFMessage_T *create_sample_message(SMFSession_T *session, const char *sample) { SMFMessage_T *message; fail_unless((message = smf_message_new()) != NULL); fail_unless(smf_message_from_file(&message, sample, 1) == 0); session->envelope->message = message; return message; }
int main (int argc, char const *argv[]) { SMFSmtpStatus_T *status = NULL; SMFEnvelope_T *env = smf_envelope_new(); SMFMessage_T *msg = NULL; char *msg_file = NULL; printf("Start smf_smtp tests...\n"); printf("============================================\n"); printf("This test expects a running SMTP daemon, \n"); printf("listening on localhost:25 or TEST_NEXTHOP value,\n"); printf("wich accepts mails for [email protected]\n"); printf("============================================\n"); printf("* testing smf_smtp_status_new()...\t\t\t\t"); status = smf_smtp_status_new(); if (status == NULL) { printf("failed\n"); return -1; } printf("passed\n"); printf("* testing smf_smtp_status_free()...\t\t\t\t"); status->text = strdup(test_string); smf_smtp_status_free(status); printf("passed\n"); asprintf(&msg_file, "%s/m0001.txt",SAMPLES_DIR); printf("* testing smf_smtp_deliver() with file...\t\t\t"); smf_envelope_set_nexthop(env, TEST_NEXTHOP); smf_envelope_set_sender(env, test_email); smf_envelope_add_rcpt(env, test_email); status = smf_smtp_deliver(env, SMF_TLS_DISABLED, msg_file, NULL); if (status->code == -1) { printf("failed\n"); return -1; } printf("passed\n"); smf_smtp_status_free(status); printf("* testing smf_smtp_deliver() with envelope...\t\t\t"); msg = smf_message_new(); if (smf_message_from_file(&msg, msg_file, 0) != 0){ printf("failed\n"); return -1; } smf_envelope_set_message(env, msg); status = smf_smtp_deliver(env, SMF_TLS_DISABLED, NULL, NULL); if (status->code == -1) { printf("failed\n"); return -1; } printf("passed\n"); smf_smtp_status_free(status); printf("* testing smf_smtp_deliver() with envelope and TLS...\t\t"); status = smf_smtp_deliver(env, SMF_TLS_REQUIRED, NULL, NULL); if (status->code == -1) { printf("failed\n"); return -1; } printf("passed\n"); smf_smtp_status_free(status); printf("* testing smf_smtp_deliver() with smtp auth...\t\t\t"); smf_envelope_set_auth_user(env, test_auth_user); smf_envelope_set_auth_pass(env, test_auth_pass); status = smf_smtp_deliver(env, SMF_TLS_DISABLED, NULL, NULL); if (status->code == -1) { printf("failed\n"); return -1; } printf("passed\n"); smf_smtp_status_free(status); free(msg_file); smf_envelope_free(env); return 0; }