83 lines
2.5 KiB
C
83 lines
2.5 KiB
C
/*
|
|
* Copyright (C) 2023 The Trinitrix Project <soispha@vhack.eu,
|
|
* antifallobst@systemausfall.org>
|
|
*
|
|
* This file is part of the RPC crate for Trinitrix.
|
|
*
|
|
* RPC is free software: you can redistribute it and/or modify
|
|
* it under the terms of the Lesser GNU General Public License as
|
|
* published by the Free Software Foundation, either version 3 of
|
|
* the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* and the Lesser GNU General Public License along with this program.
|
|
* If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "../dist/interface.h"
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main() {
|
|
printf("Checking result\n");
|
|
result_t result;
|
|
if (!initialize_socket(&result, "hi")) {
|
|
int error_length = last_error_length();
|
|
char *buffer = malloc(error_length);
|
|
last_error_message(buffer, error_length);
|
|
printf("error: %s\n", buffer);
|
|
}
|
|
if (result.tag == ok) {
|
|
printf("Hurray! Value is: %p\n", result.value);
|
|
}
|
|
printf("Type is: %d\n", result.type_id);
|
|
|
|
printf("\n\nChecking enum\n");
|
|
enum_a_t enum_a;
|
|
if (fn_alone(&enum_a, "hi")) {
|
|
printf("Call succeded, it returned: %d\n", enum_a);
|
|
assert(enum_a == Val1);
|
|
} else {
|
|
int error_length = last_error_length();
|
|
char *buffer = malloc(error_length);
|
|
last_error_message(buffer, error_length);
|
|
printf("error: %s\n", buffer);
|
|
};
|
|
|
|
printf("\n\nChecking str\n");
|
|
str_t str;
|
|
if (one.fn_one(&str)) {
|
|
printf("Call succeded, it returned: %s\n", str);
|
|
}
|
|
|
|
printf("\n\nChecking string\n");
|
|
string_t string;
|
|
if (one.two.fn_two(&string)) {
|
|
printf("Call succeded, it returned: %s\n", string);
|
|
}
|
|
string = strcpy(string, "some other text");
|
|
printf("String is after the strcpy: %s\n", string);
|
|
free(string);
|
|
|
|
printf("\n\nChecking result with string\n");
|
|
result_t str_result;
|
|
if (one.two.three.fn_three(&str_result)) {
|
|
if (str_result.tag == err) {
|
|
printf("Call failed, it returned: %s\n", (str_t)str_result.value);
|
|
} else {
|
|
printf("Call succeded, it returned: %s\n", (string_t)str_result.value);
|
|
}
|
|
printf("Type is: %d\n", str_result.type_id);
|
|
assert(str_result.type_id == type_string_t);
|
|
}
|
|
|
|
return 0;
|
|
}
|