YAIP/tests/util.test.c
Jonathan Hodgson 1beca38af6 Early SSL Certificates creation work done
Yaip is now able to generate simple SSL certificates for a given host.

I don't currently add any extensions to the certificates (such as
alternative names). When I get to testing it with a browser I'll see
what browsers require. However, I think I'll probably generate
certificates for each host, including sub domains, to make life easier
searching.

I've also added a util function to count lines in a file that was used
for testing some of the ssl functions.
2022-01-23 15:38:24 +00:00

85 lines
1.8 KiB
C

#ifndef UTIL_TEST
#define UTIL_TEST
#include "munit/munit.h"
#include "../src/util.h"
MunitResult testStrPos(const MunitParameter params[],
void* user_data_or_fixture){
munit_assert_int( strpos( "thisisatest", "test" ), ==, 7 );
munit_assert_int( strpos( "testthisisatest", "test" ), ==, 0 );
munit_assert_int( strpos( "blar", "test" ), ==, -1 );
return MUNIT_OK;
}
MunitResult testCountLines(const MunitParameter params[],
void* user_data_or_fixture){
char filename[] = "/tmp/yaip-test-file";
FILE *fp = fopen(filename, "w");
if ( fp == NULL ){
printf("Cannot open file %s\n", filename);
return MUNIT_ERROR;
}
fprintf( fp, "test\n" );
fclose(fp);
munit_assert_int( 1, ==, countLines(filename) );
fp = fopen(filename, "w");
if ( fp == NULL ){
printf("Cannot open file %s\n", filename);
return MUNIT_ERROR;
}
fprintf( fp, "test2\ntest3\n" );
fclose(fp);
munit_assert_int( 2, ==, countLines(filename) );
remove(filename);
return MUNIT_OK;
}
static MunitTest util_tests[] = {
{
"/util/versions", /* name */
testStrPos, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
}, {
"/util/countLines", /* name */
testCountLines, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},
/* Mark the end of the array with an entry where the test
* function is NULL */
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};
MunitSuite util_test_suite = {
"/request", /* name */
util_tests, /* tests */
NULL, /* suites */
1, /* iterations */
MUNIT_SUITE_OPTION_NONE /* options */
};
#ifndef MAINTEST
#define MAINTEST
int main (int argc, char* argv[]) {
return munit_suite_main(&util_test_suite, NULL, argc, argv);
}
#endif /* ifndef MAINTEST */
#endif /* ifndef REQUEST_TEST */