1. Copied over some of the test infrastructure from wolfSSL.

2. Added API test cases for only wolfSSH_Init and wolfSSH_Cleanup.
pull/32/head
John Safranek 2017-06-13 10:35:11 -07:00
parent c3d0c895d2
commit 24b19daa16
3 changed files with 101 additions and 1 deletions

View File

@ -19,10 +19,48 @@
*/
#include <wolfssh/ssh.h>
#include <tests/unit.h>
#define TEST_SUCCESS (1)
#define TEST_FAIL (0)
#define testingFmt " %s:"
#define resultFmt " %s\n"
static const char* passed = "passed";
static const char* failed = "failed";
static int test_wolfSSH_Init(void)
{
int result;
printf(testingFmt, "wolfSSH_Init()");
result = wolfSSH_Init();
printf(resultFmt, result == WS_SUCCESS ? passed : failed);
return result;
}
static int test_wolfSSH_Cleanup(void)
{
int result;
printf(testingFmt, "wolfSSH_Cleanup()");
result = wolfSSH_Cleanup();
printf(resultFmt, result == WS_SUCCESS ? passed : failed);
return result;
}
int ApiTest(void)
{
printf(" Begin API Tests\n");
AssertIntEQ(test_wolfSSH_Init(), WS_SUCCESS);
AssertIntEQ(test_wolfSSH_Cleanup(), WS_SUCCESS);
printf(" End API Tests\n");
return 0;
}

View File

@ -394,8 +394,8 @@ int main(void)
testResult = testResult || unitResult;
#endif
printf("Running the API tests\n");
unitResult = ApiTest();
printf("API: %s\n", (unitResult == 0 ? "SUCCESS" : "FAILED"));
testResult = testResult || unitResult;
return (testResult ? 1 : 0);

View File

@ -26,12 +26,74 @@
#pragma once
#ifndef WOLFSSH_TESTS_UNIT_H
#define WOLFSSH_TESTS_UNIT_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define Fail(description, result) do { \
printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__); \
printf("\n expected: "); printf description; \
printf("\n result: "); printf result; printf("\n\n"); \
abort(); \
} while(0)
#define Assert(test, description, result) if (!(test)) Fail(description, result)
#define AssertTrue(x) Assert( (x), ("%s is true", #x), (#x " => FALSE"))
#define AssertFalse(x) Assert(!(x), ("%s is false", #x), (#x " => TRUE"))
#define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
#define AssertNull(x) do { \
void* _x = (void *) (x); \
\
Assert(!_x, ("%s is null", #x), (#x " => %p", _x)); \
} while(0)
#define AssertInt(x, y, op, er) do { \
int _x = x; \
int _y = y; \
\
Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y)); \
} while(0)
#define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
#define AssertIntNE(x, y) AssertInt(x, y, !=, ==)
#define AssertIntGT(x, y) AssertInt(x, y, >, <=)
#define AssertIntLT(x, y) AssertInt(x, y, <, >=)
#define AssertIntGE(x, y) AssertInt(x, y, >=, <)
#define AssertIntLE(x, y) AssertInt(x, y, <=, >)
#define AssertStr(x, y, op, er) do { \
const char* _x = x; \
const char* _y = y; \
int _z = strcmp(_x, _y); \
\
Assert(_z op 0, ("%s " #op " %s", #x, #y), \
("\"%s\" " #er " \"%s\"", _x, _y));\
} while(0)
#define AssertStrEQ(x, y) AssertStr(x, y, ==, !=)
#define AssertStrNE(x, y) AssertStr(x, y, !=, ==)
#define AssertStrGT(x, y) AssertStr(x, y, >, <=)
#define AssertStrLT(x, y) AssertStr(x, y, <, >=)
#define AssertStrGE(x, y) AssertStr(x, y, >=, <)
#define AssertStrLE(x, y) AssertStr(x, y, <=, >)
int ApiTest(void);
#ifdef __cplusplus
}
#endif
#endif