add test-app target
This commit is contained in:
parent
6c4949f31c
commit
ae53f5042c
@ -5,8 +5,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
|
||||
find_package(Neon REQUIRED)
|
||||
find_package(JsonC REQUIRED)
|
||||
|
||||
add_library(yadisk src/yandex_disk_api.c
|
||||
tests/ctest.c)
|
||||
add_library(yadisk src/yandex_disk_api.c)
|
||||
add_executable(test-app tests/app.c)
|
||||
|
||||
target_include_directories(yadisk PRIVATE ${NEON_INCLUDE_DIR} ${JSON_C_INCLUDE_DIR})
|
||||
target_link_libraries(yadisk ${NEON_LIBRARIES} ${JSON_C_LIBRARIES})
|
||||
target_link_libraries(yadisk ${NEON_LIBRARIES} ${JSON_C_LIBRARIES})
|
||||
|
||||
target_include_directories(test-app PRIVATE "${CMAKE_SOURCE_DIR}/src" ${NEON_INCLUDE_DIR} ${JSON_C_INCLUDE_DIR})
|
||||
target_link_libraries(test-app yadisk)
|
@ -17,21 +17,23 @@ static int api_http_request(
|
||||
|
||||
void yadisk_get_disk(yadisk_api_client *client, yadisk_disk_info* info) {
|
||||
char* output = NULL;
|
||||
int result = api_http_request(client, "GET", "/v1/disk", &output);
|
||||
int error = api_http_request(client, "GET", "/v1/disk", &output);
|
||||
json_object* root = json_tokener_parse(output);
|
||||
free(output);
|
||||
|
||||
if (!result) {
|
||||
if (error) {
|
||||
json_object_put(root);
|
||||
return;
|
||||
}
|
||||
|
||||
json_object* total_space = NULL;
|
||||
json_object_object_get_ex(root, "total_space", &total_space);
|
||||
info->total_space = json_object_get_int64(total_space);
|
||||
if (!json_object_object_get_ex(root, "total_space", &total_space)) {
|
||||
printf("Key total_space doesn't exists!");
|
||||
}
|
||||
info->total_space = json_object_get_uint64(total_space);
|
||||
json_object_put(total_space);
|
||||
|
||||
json_object_put(root);
|
||||
free(output);
|
||||
}
|
||||
|
||||
void yadisk_delete_disk_resources(yadisk_api_client *client) {
|
||||
|
@ -17,7 +17,7 @@ typedef struct yadisk_api_client
|
||||
|
||||
typedef struct yadisk_disk_info
|
||||
{
|
||||
long total_space;
|
||||
unsigned long total_space;
|
||||
} yadisk_disk_info;
|
||||
|
||||
void yadisk_get_disk(yadisk_api_client* client, yadisk_disk_info* info);
|
||||
|
25
tests/app.c
Normal file
25
tests/app.c
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by maxim on 27.11.23.
|
||||
//
|
||||
|
||||
#include <yandex_disk_api.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char token[1024];
|
||||
|
||||
printf("Enter OAuth token: ");
|
||||
fgets(token, sizeof(token), stdin);
|
||||
|
||||
yadisk_api_client* client = &(yadisk_api_client){
|
||||
.token = token
|
||||
};
|
||||
|
||||
yadisk_disk_info yadisk_disk_info;
|
||||
|
||||
yadisk_get_disk(client, &yadisk_disk_info);
|
||||
|
||||
printf("Total disk size: %lu", yadisk_disk_info.total_space);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user