Start of a better C testing framework.
This commit is contained in:
@@ -1,45 +1,11 @@
|
|||||||
{
|
{
|
||||||
curl_global_init_get_compression_methods_1
|
curl_global_init_libcrypto
|
||||||
Memcheck:Leak
|
Memcheck:Leak
|
||||||
fun:malloc
|
...
|
||||||
fun:CRYPTO_malloc
|
fun:CRYPTO_malloc
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0
|
...
|
||||||
fun:SSL_COMP_get_compression_methods
|
|
||||||
fun:SSL_library_init
|
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
|
|
||||||
fun:curl_global_init
|
fun:curl_global_init
|
||||||
fun:cosmo_create
|
...
|
||||||
fun:main
|
|
||||||
}
|
|
||||||
{
|
|
||||||
curl_global_init_get_compression_methods_2
|
|
||||||
Memcheck:Leak
|
|
||||||
fun:malloc
|
|
||||||
fun:CRYPTO_malloc
|
|
||||||
fun:sk_new
|
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0
|
|
||||||
fun:SSL_COMP_get_compression_methods
|
|
||||||
fun:SSL_library_init
|
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
|
|
||||||
fun:curl_global_init
|
|
||||||
fun:cosmo_create
|
|
||||||
fun:main
|
|
||||||
}
|
|
||||||
{
|
|
||||||
curl_global_init_load_builtin_engines_1
|
|
||||||
Memcheck:Leak
|
|
||||||
fun:malloc
|
|
||||||
fun:CRYPTO_malloc
|
|
||||||
fun:lh_new
|
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
|
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
|
|
||||||
fun:ERR_get_state
|
|
||||||
fun:ERR_clear_error
|
|
||||||
fun:ENGINE_load_builtin_engines
|
|
||||||
obj:/usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
|
|
||||||
fun:curl_global_init
|
|
||||||
fun:cosmo_create
|
|
||||||
fun:main
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,11 +2,18 @@
|
|||||||
|
|
||||||
#include "cosmopolite.h"
|
#include "cosmopolite.h"
|
||||||
|
|
||||||
|
#define RUN_TEST(func) run_test(#func, func)
|
||||||
|
|
||||||
|
#define ANSI_COLOR_RED "\x1b[31m"
|
||||||
|
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||||
|
#define ANSI_COLOR_YELLOW "\x1b[33m"
|
||||||
|
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||||
|
|
||||||
void on_message(const json_t *message, void *passthrough) {
|
void on_message(const json_t *message, void *passthrough) {
|
||||||
printf("new message: %lld\n", json_integer_value(json_object_get(message, "id")));
|
printf("new message: %lld\n", json_integer_value(json_object_get(message, "id")));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
cosmo *create_client() {
|
||||||
char client_id[COSMO_UUID_SIZE];
|
char client_id[COSMO_UUID_SIZE];
|
||||||
cosmo_uuid(client_id);
|
cosmo_uuid(client_id);
|
||||||
|
|
||||||
@@ -14,12 +21,45 @@ int main(int argc, char *argv[]) {
|
|||||||
.message = on_message
|
.message = on_message
|
||||||
};
|
};
|
||||||
|
|
||||||
cosmo *instance = cosmo_create("https://playground.cosmopolite.org/cosmopolite", client_id, &callbacks, NULL);
|
return cosmo_create("https://playground.cosmopolite.org/cosmopolite", client_id, &callbacks, NULL);
|
||||||
json_t *subject = cosmo_subject("foobar", NULL, NULL);
|
}
|
||||||
cosmo_subscribe(instance, subject, -1, 0);
|
|
||||||
json_decref(subject);
|
|
||||||
sleep(20);
|
|
||||||
cosmo_shutdown(instance);
|
|
||||||
|
|
||||||
|
json_t *random_subject(const char *readable_only_by, const char *writeable_only_by) {
|
||||||
|
char uuid[COSMO_UUID_SIZE];
|
||||||
|
cosmo_uuid(uuid);
|
||||||
|
char name[COSMO_UUID_SIZE + 20];
|
||||||
|
sprintf(name, "/test/%s", uuid);
|
||||||
|
return cosmo_subject(name, readable_only_by, writeable_only_by);
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_test(const char *func_name, bool (*test)(void)) {
|
||||||
|
fprintf(stderr, ANSI_COLOR_YELLOW "%50s" ANSI_COLOR_RESET ": ", func_name);
|
||||||
|
if (test()) {
|
||||||
|
fprintf(stderr, ANSI_COLOR_GREEN "PASS" ANSI_COLOR_RESET "\n");
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, ANSI_COLOR_RED "FAIL" ANSI_COLOR_RESET "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool test_create_destroy() {
|
||||||
|
cosmo *client = create_client();
|
||||||
|
cosmo_shutdown(client);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool message_round_trip() {
|
||||||
|
cosmo *client = create_client();
|
||||||
|
|
||||||
|
json_t *subject = random_subject(NULL, NULL);
|
||||||
|
cosmo_subscribe(client, subject, -1, 0);
|
||||||
|
|
||||||
|
json_decref(subject);
|
||||||
|
cosmo_shutdown(client);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
RUN_TEST(test_create_destroy);
|
||||||
|
RUN_TEST(message_round_trip);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user