mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
switched tests to google test
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test_util.h"
|
||||
#include "wsfs/util.h"
|
||||
|
||||
extern void test_request_parser();
|
||||
|
||||
int main(int WSFS_UNUSED_PARAM(argc), char* WSFS_UNUSED_PARAM(argv[]))
|
||||
{
|
||||
test_request_parser();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "test_util.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
extern "C" {
|
||||
#include "wsfs/response_parser.h"
|
||||
}
|
||||
|
||||
static void wsfs_response_parse_str(
|
||||
char const * buffer,
|
||||
@@ -12,7 +13,7 @@ static void wsfs_response_parse_str(
|
||||
wsfs_response_parse(buffer, length, response);
|
||||
}
|
||||
|
||||
void test_request_parser()
|
||||
TEST(response_parser, test)
|
||||
{
|
||||
struct wsfs_response response;
|
||||
|
||||
@@ -20,43 +21,43 @@ void test_request_parser()
|
||||
wsfs_response_parse_str("", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(NULL, response.result);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// invalid json
|
||||
wsfs_response_parse_str("invalid_json", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(NULL, response.result);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no object
|
||||
wsfs_response_parse_str("[]", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(NULL, response.result);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// empty
|
||||
wsfs_response_parse_str("{}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(NULL, response.result);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no data
|
||||
wsfs_response_parse_str("{\"id\":42}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(NULL, response.result);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// custom error code
|
||||
wsfs_response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(NULL, response.result);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// valid response
|
||||
wsfs_response_parse_str("{\"result\": true, \"id\": 42}", &response);
|
||||
ASSERT_EQ(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(NULL, response.result);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
json_decref(response.result);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "test_util.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void fail(
|
||||
char const * file_name,
|
||||
int line,
|
||||
char const * message
|
||||
)
|
||||
{
|
||||
fprintf(stderr, "error: %s:%d: %s\n", file_name, line, message);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef _WSFS_TEST_UTIL_H
|
||||
#define _WSFS_TEST_UTIL_H
|
||||
|
||||
#define ASSERT_EQ(expected, actual) \
|
||||
do \
|
||||
{ \
|
||||
if ((expected) != (actual)) \
|
||||
{ \
|
||||
fail(__FILE__, __LINE__, "expected " #expected ", but was " #actual); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define ASSERT_NE(expected, actual) \
|
||||
do \
|
||||
{ \
|
||||
if ((expected) == (actual)) \
|
||||
{ \
|
||||
fail(__FILE__, __LINE__, "expected " #expected ", but was " #actual); \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
extern void fail(
|
||||
char const * file_name,
|
||||
int line,
|
||||
char const * message
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user