Esempio n. 1
0
static const char *create_spoolfile(SMFSession_T *session, const char *sample) {
    int src, dest;
    char buf[512];
    
    snprintf(spoolfile, sizeof(spoolfile), "%s/XXXXXX", BINARY_DIR);
    fail_if((src = open(sample, O_RDONLY)) == -1);
    fail_if((dest = mkstemp(spoolfile)) == -1);
    
    while (1) {
        size_t nread, nwritten;
        
        if ((nread = read(src, buf, sizeof(buf))) == 0)
            break;
        fail_unless(nread > 0);
        
        nwritten = write(dest, buf, nread);
        fail_unless(nread == nwritten);
    }
    
    close(src);
    close(dest);
    smf_session_set_message_file(session, spoolfile);
    
    return spoolfile;
}
Esempio n. 2
0
END_TEST

START_TEST(set_get_message_file) {
    char *s = strdup("/tmp/test.eml");
    smf_session_set_message_file(session,s);
    fail_unless(strcmp(s,smf_session_get_message_file(session)) == 0);
    free(s);
}
Esempio n. 3
0
int main (int argc, char const *argv[]) {
    SMFSession_T *session = NULL;
    
    printf("Start SMFSession_T tests...\n");

    printf("* testing smf_session_new()...\t\t\t\t");
    session = smf_session_new();
    assert(session);
    if (strlen(smf_session_get_id(session)) != 12) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");
    
    printf("* testing smf_session_set_helo()...\t\t\t");
    smf_session_set_helo(session,test_helo);
    printf("passed\n");

    printf("* testing smf_session_get_helo()...\t\t\t");
    if (strcmp(test_helo,smf_session_get_helo(session)) != 0) {
        printf("failed\n");
        return -1;
    } else
        printf("passed\n");
      
    printf("* testing smf_session_set_xfoward_addr()...\t\t");
    smf_session_set_xforward_addr(session,test_ip);
    printf("passed\n");

    printf("* testing smf_session_get_xforward_addr()...\t\t");
    if (strcmp(test_ip,smf_session_get_xforward_addr(session)) != 0) {
        printf("failed\n");
        return -1;
    } else
        printf("passed\n");

    printf("* testing smf_session_set_response_msg()...\t\t");
    smf_session_set_response_msg(session,test_response);
    printf("passed\n");

    printf("* testing smf_session_get_response_msg()...\t\t");
    if (strcmp(test_response,smf_session_get_response_msg(session)) != 0) {
        printf("failed\n");
        return -1;
    } else
        printf("passed\n");
  
    printf("* testing smf_session_set_message_file()...\t\t");
    smf_session_set_message_file(session,test_path);
    printf("passed\n");

    printf("* testing smf_session_get_message_file()...\t\t");
    if (strcmp(test_path,smf_session_get_message_file(session)) != 0) {
        printf("failed\n");
        return -1;
    }
    printf("passed\n");

    printf("* testing smf_session_free()...\t\t\t\t");
    smf_session_free(session);
    printf("passed\n");

    return 0;
}