mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 08:50:46 +00:00
Expose repository functions to sharedlibs
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#include "shared.h"
|
||||
|
||||
void test_CreateServerInstance();
|
||||
void test_StopServerInstance();
|
||||
void test_ServerInstanceStateMethods();
|
||||
int test_CreateServerInstance();
|
||||
int test_StopServerInstance();
|
||||
int test_ServerInstanceStateMethods();
|
||||
int test_Databases();
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -21,9 +22,24 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
printf("Running tests for library: %s\n", libPath);
|
||||
test_CreateServerInstance();
|
||||
test_ServerInstanceStateMethods();
|
||||
test_StopServerInstance();
|
||||
int results[] = {
|
||||
test_CreateServerInstance(),
|
||||
test_Databases(),
|
||||
test_ServerInstanceStateMethods(),
|
||||
test_StopServerInstance(),
|
||||
};
|
||||
|
||||
int numTests = sizeof(results) / sizeof(results[0]);
|
||||
int numPassed = 0;
|
||||
for (int i = 0; i < numTests; i++)
|
||||
{
|
||||
if (results[i])
|
||||
{
|
||||
numPassed++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Tests passed: %d/%d\n", numPassed, numTests);
|
||||
|
||||
dlclose(handle);
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "shared.h"
|
||||
|
||||
void test_CreateServerInstance()
|
||||
int test_CreateServerInstance()
|
||||
{
|
||||
typedef int (*CreateServerInstanceFn)(char *, char *);
|
||||
CreateServerInstanceFn CreateServerInstance = (CreateServerInstanceFn)load_function("CreateServerInstance");
|
||||
@@ -8,7 +8,7 @@ void test_CreateServerInstance()
|
||||
if (!CreateServerInstance)
|
||||
{
|
||||
fprintf(stderr, "Failed to find CreateServerInstance function\n");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *serverName = "TestServer";
|
||||
@@ -22,5 +22,8 @@ void test_CreateServerInstance()
|
||||
else
|
||||
{
|
||||
printf("CreateServerInstance: FAILED (result = %d)\n", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
47
sharedlibrary/tests/test_databases.c
Normal file
47
sharedlibrary/tests/test_databases.c
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "shared.h"
|
||||
|
||||
int test_Databases()
|
||||
{
|
||||
typedef int (*CreateDatabaseFn)(char *, char *);
|
||||
CreateDatabaseFn CreateDatabase = (CreateDatabaseFn)load_function("CreateDatabase");
|
||||
if (!CreateDatabase)
|
||||
{
|
||||
fprintf(stderr, "Failed to find CreateDatabase function\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *serverName = "TestServer";
|
||||
char *configJSON = "{\"id\":\"test-db\"}";
|
||||
|
||||
int result = CreateDatabase(serverName, configJSON);
|
||||
if (result == 0)
|
||||
{
|
||||
printf("CreateDatabase: SUCCESS\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("CreateDatabase: FAILED (result = %d)\n", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef char *(*GetDatabaseFn)(char *, char *);
|
||||
GetDatabaseFn GetDatabase = (GetDatabaseFn)load_function("GetDatabase");
|
||||
if (!GetDatabase)
|
||||
{
|
||||
fprintf(stderr, "Failed to find GetDatabase function\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *database = GetDatabase(serverName, "test-db");
|
||||
if (database)
|
||||
{
|
||||
printf("GetDatabase: SUCCESS (database = %s)\n", database);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("GetDatabase: FAILED\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "shared.h"
|
||||
|
||||
void test_ServerInstanceStateMethods()
|
||||
int test_ServerInstanceStateMethods()
|
||||
{
|
||||
typedef int (*LoadServerInstanceStateFn)(char *, char *);
|
||||
LoadServerInstanceStateFn LoadServerInstanceState = (LoadServerInstanceStateFn)load_function("LoadServerInstanceState");
|
||||
if (!LoadServerInstanceState)
|
||||
{
|
||||
fprintf(stderr, "Failed to find LoadServerInstanceState function\n");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *serverName = "TestServer";
|
||||
@@ -20,6 +20,7 @@ void test_ServerInstanceStateMethods()
|
||||
else
|
||||
{
|
||||
printf("LoadServerInstanceState: FAILED (result = %d)\n", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef char *(*GetServerInstanceStateFn)(char *);
|
||||
@@ -27,7 +28,7 @@ void test_ServerInstanceStateMethods()
|
||||
if (!GetServerInstanceState)
|
||||
{
|
||||
fprintf(stderr, "Failed to find GetServerInstanceState function\n");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *state = GetServerInstanceState(serverName);
|
||||
@@ -38,6 +39,7 @@ void test_ServerInstanceStateMethods()
|
||||
else
|
||||
{
|
||||
printf("GetServerInstanceState: FAILED\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *expected_state = "{\"databases\":{\"test-db\":{\"id\":\"test-db\",\"_ts\":0,\"_rid\":\"\",\"_etag\":\"\",\"_self\":\"\"}},\"collections\":{\"test-db\":{}},\"documents\":{\"test-db\":{}}}";
|
||||
@@ -45,7 +47,7 @@ void test_ServerInstanceStateMethods()
|
||||
if (!compact_state)
|
||||
{
|
||||
free(state);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(compact_state, expected_state) == 0)
|
||||
@@ -57,8 +59,10 @@ void test_ServerInstanceStateMethods()
|
||||
printf("GetServerInstanceState: State does not match expected value.\n");
|
||||
printf("Expected: %s\n", expected_state);
|
||||
printf("Actual: %s\n", compact_state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
free(state);
|
||||
free(compact_state);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "shared.h"
|
||||
|
||||
void test_StopServerInstance()
|
||||
int test_StopServerInstance()
|
||||
{
|
||||
typedef int (*StopServerInstanceFn)(char *);
|
||||
StopServerInstanceFn StopServerInstance = (StopServerInstanceFn)load_function("StopServerInstance");
|
||||
@@ -8,7 +8,7 @@ void test_StopServerInstance()
|
||||
if (!StopServerInstance)
|
||||
{
|
||||
fprintf(stderr, "Failed to find StopServerInstance function\n");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *serverName = "TestServer";
|
||||
@@ -20,5 +20,8 @@ void test_StopServerInstance()
|
||||
else
|
||||
{
|
||||
printf("StopServerInstance: FAILED (result = %d)\n", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user