smtp-client
SMTP Client C Library
test_nossl.c File Reference

Test the smtp-client library without OpenSSL. More...

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <smtp.h>
+ Include dependency graph for test_nossl.c:

Go to the source code of this file.

Functions

static void load_test_email (char *const email, size_t emailsz)
 
static void test_nossl_smtp (void)
 
int main (void)
 

Detailed Description

Test the smtp-client library without OpenSSL.

Author
James Humphrey (mail@.nosp@m.somn.nosp@m.isoft.nosp@m..com)
Version
1.00

These functional tests ensure that the smtp-client library works when configured without OpenSSL.

This software has been placed into the public domain using CC0.

Definition in file test_nossl.c.

Function Documentation

◆ load_test_email()

static void load_test_email ( char *const  email,
size_t  emailsz 
)
static

Load the test email to send from a configuration file.

Parameters
[out]emailString buffer to store the email in.
[in]emailszNumber of bytes in email.

Definition at line 25 of file test_nossl.c.

References fclose, and ferror.

Referenced by test_nossl_smtp().

26  {
27  FILE *fp;
28  int rc;
29  size_t bytes_read;
30 
31  fp = fopen("test/config/test_email.txt", "r");
32  assert(fp);
33 
34  bytes_read = fread(email, sizeof(*email), emailsz, fp);
35  assert(bytes_read > 0);
36 
37  email[bytes_read - 1] = '\0';
38 
39  rc = ferror(fp);
40  assert(rc == 0);
41 
42  rc = fclose(fp);
43  assert(rc == 0);
44 }
#define ferror
Definition: seams.h:113
#define fclose
Definition: seams.h:105
+ Here is the caller graph for this function:

◆ main()

int main ( void  )

Main program entry point for testing the smtp-client library build without OpenSSL.

Return values
0All tests passed.
1Error.

Definition at line 98 of file test_nossl.c.

References test_nossl_smtp().

98  {
100  return 0;
101 }
static void test_nossl_smtp(void)
Definition: test_nossl.c:50
+ Here is the call graph for this function:

◆ test_nossl_smtp()

static void test_nossl_smtp ( void  )
static

Load the configuration file and send a single test email.

Definition at line 50 of file test_nossl.c.

References load_test_email(), smtp_address_add(), SMTP_ADDRESS_FROM, SMTP_ADDRESS_TO, smtp_close(), SMTP_DEBUG, smtp_header_add(), smtp_mail(), smtp_open(), SMTP_SECURITY_NONE, and SMTP_STATUS_OK.

Referenced by main().

50  {
51  int rc;
52  struct smtp *smtp;
53  char email[1000];
54 
55  load_test_email(email, sizeof(email));
56 
57  rc = smtp_open("localhost",
58  "25",
60  SMTP_DEBUG,
61  NULL,
62  &smtp);
63  assert(rc == SMTP_STATUS_OK);
64 
65  rc = smtp_address_add(smtp,
67  email,
68  "Test Email");
69  assert(rc == SMTP_STATUS_OK);
70 
71  rc = smtp_address_add(smtp,
73  email,
74  "Test Email");
75  assert(rc == SMTP_STATUS_OK);
76 
77  rc = smtp_header_add(smtp,
78  "Subject",
79  "SMTP Test: Build Without OpenSSL");
80  assert(rc == SMTP_STATUS_OK);
81 
82  rc = smtp_mail(smtp,
83  "This email tests the build without OpenSSL compiled into"
84  " the library.");
85  assert(rc == SMTP_STATUS_OK);
86 
87  rc = smtp_close(smtp);
88  assert(rc == SMTP_STATUS_OK);
89 }
enum smtp_status_code smtp_close(struct smtp *smtp)
Definition: smtp.c:3168
enum smtp_status_code smtp_header_add(struct smtp *const smtp, const char *const key, const char *const value)
Definition: smtp.c:3278
enum smtp_status_code smtp_mail(struct smtp *const smtp, const char *const body)
Definition: smtp.c:3062
static void load_test_email(char *const email, size_t emailsz)
Definition: test_nossl.c:25
enum smtp_status_code smtp_address_add(struct smtp *const smtp, enum smtp_address_type type, const char *const email, const char *const name)
Definition: smtp.c:3347
Definition: smtp.c:150
enum smtp_status_code smtp_open(const char *const server, const char *const port, enum smtp_connection_security connection_security, enum smtp_flag flags, const char *const cafile, struct smtp **smtp)
Definition: smtp.c:2987
+ Here is the call graph for this function:
+ Here is the caller graph for this function: