Get feed test (wip)

FossilOrigin-Name: e335a0731d311b29bb58078fe2008e1cf338234770abfbd2a4cc3f941d755506
This commit is contained in:
nekobit 2023-02-28 22:59:25 +00:00
parent 839a226729
commit d979621621
5 changed files with 72 additions and 0 deletions

View file

@ -20,6 +20,9 @@ find_package(CURL REQUIRED)
# Find the real cJSON
pkg_check_modules(CJSON libcjson)
# Includes test programs... unit tests
add_subdirectory(tests)
if (NOT (CJSON_FOUND AND CJSON_VERSION VERSION_GREATER_EQUAL 1.7.14))
# This was a workaround to some distributions providing an older cJSON
message("CJSON not found or CJSON_VERSION < 1.7.14, falling back to header-only.")
@ -96,9 +99,11 @@ target_compile_options(mastodont PUBLIC
-Wall -Wextra -std=c99
-Wshadow -Wcast-align -Wstrict-prototypes
)
target_link_options(mastodont PUBLIC
${CURL_LDFLAGS_OTHER}
)
target_include_directories(mastodont PUBLIC
include/
${CURL_INCLUDE_DIRS}

11
README.md Normal file
View file

@ -0,0 +1,11 @@
# Mastodont-c
Mastodont-c is a C library to access the Mastodon API and it's variants
(Pleroma, Akkoma, Soapbox).
It was written in C due to it's portability. It's designed to be used in
Treebird, but it can be used in other programs as well.
# Documentation
Documentation is essentially non-existant, but this will improve over time.

6
tests/CMakeLists.txt Normal file
View file

@ -0,0 +1,6 @@
add_executable(get_feed get_feed.c)
target_compile_options(get_feed PUBLIC -std=c99 -Wall)
target_include_directories(get_feed PUBLIC
../include
${CURL_INCLUDE_DIRS}
../libs)

View file

50
tests/get_feed.c Normal file
View file

@ -0,0 +1,50 @@
#include <stdio.h>
#include <mastodont.h>
char* get_line(char const* prompt, size_t* res_size)
{
char* result = NULL;
#define GL_BUF_SIZE 25
size_t _res_size;
char buffer[GL_BUF_SIZE];
if (prompt)
{
fputs(prompt, stdout);
fputs(": ", stdout);
}
while (fgets(buffer, GL_BUF_SIZE, stdin) != NULL)
{
_res_size += GL_BUF_SIZE;
result = realloc(result, _res_size);
memcpy(result, buffer, GL_BUF_SIZE);
}
if (res_size)
*res_size = _res_size;
return result;
}
int
main()
{
mstdnt_global_curl_init();
mastodont_t data;
if (mstdnt_init(&data) != 0)
{
fputs("Couldn't initialize Mastodont-c!", stderr);
}
char* instance = get_line("Instance: ", NULL);
puts(instance);
free(instance);
mstdnt_cleanup(&data);
mstdnt_global_curl_cleanup();
}