test(tests/shared): add test for the options C API
This commit is contained in:
parent
da11f7738d
commit
a1798ed331
3 changed files with 91 additions and 2 deletions
|
@ -9,3 +9,9 @@ target_link_libraries(c_name_test ${EXTRA_LIBS} leanshared)
|
||||||
add_test(NAME c_name_test
|
add_test(NAME c_name_test
|
||||||
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
|
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
|
||||||
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_name_test")
|
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_name_test")
|
||||||
|
|
||||||
|
add_executable(c_options_test options.c)
|
||||||
|
target_link_libraries(c_options_test ${EXTRA_LIBS} leanshared)
|
||||||
|
add_test(OPTIONS c_options_test
|
||||||
|
WORKING_DIRECTORY "${LEAN_BINARY_DIR}"
|
||||||
|
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/c_options_test")
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
|
Author: Leonardo de Moura
|
||||||
|
*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "api/lean.h"
|
#include "api/lean.h"
|
||||||
|
|
||||||
void check(int v) {
|
void check_core(int v, unsigned l) {
|
||||||
if (!v) {
|
if (!v) {
|
||||||
printf("test failed\n");
|
printf("Test failed at line %d\n", l);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define check(v) check_core(v, __LINE__)
|
||||||
|
|
||||||
void anonymous_unique() {
|
void anonymous_unique() {
|
||||||
lean_exception ex;
|
lean_exception ex;
|
||||||
lean_name a1, a2;
|
lean_name a1, a2;
|
||||||
|
|
75
src/tests/shared/options.c
Normal file
75
src/tests/shared/options.c
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
|
Author: Leonardo de Moura
|
||||||
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "api/lean.h"
|
||||||
|
|
||||||
|
void check_core(int v, unsigned l) {
|
||||||
|
if (!v) {
|
||||||
|
printf("Test failed at line %d\n", l);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define check(v) check_core(v, __LINE__)
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
lean_exception ex;
|
||||||
|
lean_name an, verbose, pp, pp_unicode, seed, output;
|
||||||
|
lean_options o1, o2, o3, o4, o5, o6;
|
||||||
|
char const * s1;
|
||||||
|
char const * s2;
|
||||||
|
lean_bool b; unsigned u;
|
||||||
|
|
||||||
|
check(lean_name_mk_anonymous(&an, &ex));
|
||||||
|
check(lean_name_mk_str(an, "verbose", &verbose, &ex));
|
||||||
|
check(lean_name_mk_str(an, "pp", &pp, &ex));
|
||||||
|
check(lean_name_mk_str(pp, "unicode", &pp_unicode, &ex));
|
||||||
|
check(lean_name_mk_str(an, "seed", &seed, &ex));
|
||||||
|
check(lean_name_mk_str(an, "output", &output, &ex));
|
||||||
|
|
||||||
|
check(lean_options_mk_empty(&o1, &ex));
|
||||||
|
check(lean_options_set_bool(o1, pp_unicode, lean_true, &o2, &ex));
|
||||||
|
check(lean_options_set_unsigned(o2, verbose, 10, &o3, &ex));
|
||||||
|
check(lean_options_set_double(o3, seed, 1.23, &o4, &ex));
|
||||||
|
|
||||||
|
check(lean_options_set_bool(o1, pp_unicode, lean_true, &o5, &ex));
|
||||||
|
check(lean_options_eq(o2, o5));
|
||||||
|
|
||||||
|
check(lean_options_to_string(o4, &s1, &ex));
|
||||||
|
|
||||||
|
printf("Lean options: %s\n", s1);
|
||||||
|
|
||||||
|
check(lean_options_get_bool(o3, pp_unicode, &b, &ex));
|
||||||
|
check(b == lean_true);
|
||||||
|
|
||||||
|
check(lean_options_get_unsigned(o4, verbose, &u, &ex));
|
||||||
|
check(u == 10);
|
||||||
|
|
||||||
|
check(lean_options_set_string(o4, output, "~/tmp/file.olean", &o6, &ex));
|
||||||
|
|
||||||
|
check(lean_options_get_string(o6, output, &s2, &ex));
|
||||||
|
check(strcmp("~/tmp/file.olean", s2) == 0);
|
||||||
|
|
||||||
|
lean_name_del(an);
|
||||||
|
lean_name_del(verbose);
|
||||||
|
lean_name_del(pp);
|
||||||
|
lean_name_del(pp_unicode);
|
||||||
|
lean_name_del(seed);
|
||||||
|
lean_name_del(output);
|
||||||
|
|
||||||
|
lean_options_del(o1);
|
||||||
|
lean_options_del(o2);
|
||||||
|
lean_options_del(o3);
|
||||||
|
lean_options_del(o4);
|
||||||
|
lean_options_del(o5);
|
||||||
|
lean_options_del(o6);
|
||||||
|
|
||||||
|
lean_string_del(s1);
|
||||||
|
lean_string_del(s2);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue