Skip to content

Commit 6621675

Browse files
committed
Update Java test.
1 parent a72d15c commit 6621675

File tree

6 files changed

+107
-83
lines changed

6 files changed

+107
-83
lines changed

source/scripts/java/fibonacci/source/fibonacci.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
public class Fibonacci
33
{
4-
public static long fib_impl(int n)
4+
public static int fib_impl(int n)
55
{
66
if (n <= 2)
77
{

source/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ add_subdirectory(rb_loader_parser_test)
112112
add_subdirectory(rb_loader_parser_integration_test)
113113
#add_subdirectory(rb_rails_integration_test) # TODO
114114
add_subdirectory(node_loader_test)
115-
add_subdirectory(java_loader_test)
116115
add_subdirectory(loader_path_test)
117116
add_subdirectory(metacall_logs_test)
118117
add_subdirectory(metacall_load_memory_test)
@@ -193,3 +192,4 @@ add_subdirectory(metacall_llvm_test)
193192
add_subdirectory(metacall_ruby_test)
194193
add_subdirectory(metacall_cs_test)
195194
add_subdirectory(metacall_julia_test)
195+
add_subdirectory(metacall_java_test)

source/tests/java_loader_test/source/java_loader_test.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

source/tests/java_loader_test/CMakeLists.txt renamed to source/tests/metacall_java_test/CMakeLists.txt

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ endif()
88
#
99

1010
# Target name
11-
set(target java-loader-test)
11+
set(target metacall-java-test)
1212
message(STATUS "Test ${target}")
1313

1414
#
@@ -32,7 +32,7 @@ set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
3232

3333
set(sources
3434
${source_path}/main.cpp
35-
${source_path}/java_loader_test.cpp
35+
${source_path}/metacall_java_test.cpp
3636
)
3737

3838
# Group source files
@@ -85,22 +85,7 @@ target_link_libraries(${target}
8585

8686
GTest
8787

88-
${META_PROJECT_NAME}::version
89-
${META_PROJECT_NAME}::preprocessor
90-
${META_PROJECT_NAME}::environment
91-
${META_PROJECT_NAME}::format
92-
${META_PROJECT_NAME}::threading
93-
${META_PROJECT_NAME}::log
94-
${META_PROJECT_NAME}::memory
95-
${META_PROJECT_NAME}::portability
96-
${META_PROJECT_NAME}::adt
97-
${META_PROJECT_NAME}::filesystem
98-
${META_PROJECT_NAME}::dynlink
99-
${META_PROJECT_NAME}::detour
100-
${META_PROJECT_NAME}::reflect
101-
${META_PROJECT_NAME}::serial
102-
${META_PROJECT_NAME}::configuration
103-
${META_PROJECT_NAME}::loader
88+
${META_PROJECT_NAME}::metacall
10489
)
10590

10691
#
@@ -135,11 +120,7 @@ target_link_libraries(${target}
135120
#
136121

137122
add_test(NAME ${target}
138-
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
139123
COMMAND $<TARGET_FILE:${target}>
140-
141-
# TODO: Remove this
142-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/source/ports/scala_port
143124
)
144125

145126
#
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include <gtest/gtest.h>
22+
23+
#include <metacall/metacall.h>
24+
#include <metacall/metacall_loaders.h>
25+
#include <metacall/metacall_value.h>
26+
27+
class metacall_java_test : public testing::Test
28+
{
29+
public:
30+
};
31+
32+
TEST_F(metacall_java_test, DefaultConstructor)
33+
{
34+
metacall_print_info();
35+
36+
ASSERT_EQ((int)0, (int)metacall_initialize());
37+
38+
/* Java */
39+
#if defined(OPTION_BUILD_LOADERS_JAVA)
40+
{
41+
const char *java_scripts[] = {
42+
"fibonacci.java"
43+
};
44+
45+
const enum metacall_value_id fib_int_ids[] = {
46+
METACALL_INT
47+
};
48+
49+
const size_t args_size = sizeof(fib_int_ids) / sizeof(fib_int_ids[0]);
50+
51+
static const char tag[] = "java";
52+
53+
ASSERT_EQ((int)0, (int)metacall_load_from_file(tag, java_scripts, sizeof(java_scripts) / sizeof(java_scripts[0]), NULL));
54+
55+
/* TODO: Uncomment this when calls are implemented */
56+
/*
57+
void *ret = metacallt_s("fib_impl", fib_int_ids, args_size, 6);
58+
59+
EXPECT_NE((void *)NULL, (void *)ret);
60+
61+
EXPECT_EQ((int)metacall_value_to_int(ret), (int)8);
62+
63+
metacall_value_destroy(ret);
64+
*/
65+
66+
/* TODO: Test load from memory */
67+
/*
68+
static const char buffer[] =
69+
"...\n"
70+
"...\n"
71+
"...\n";
72+
73+
EXPECT_EQ((int)0, (int)metacall_load_from_memory(tag, buffer, sizeof(buffer), NULL));
74+
*/
75+
76+
/* TODO: Call to the functions of the load from memory script */
77+
78+
/* TODO: Test load from package */
79+
}
80+
#endif /* OPTION_BUILD_LOADERS_JAVA */
81+
82+
/* Print inspect information */
83+
{
84+
size_t size = 0;
85+
86+
struct metacall_allocator_std_type std_ctx = { &std::malloc, &std::realloc, &std::free };
87+
88+
void *allocator = metacall_allocator_create(METACALL_ALLOCATOR_STD, (void *)&std_ctx);
89+
90+
char *inspect_str = metacall_inspect(&size, allocator);
91+
92+
EXPECT_NE((char *)NULL, (char *)inspect_str);
93+
94+
EXPECT_GT((size_t)size, (size_t)0);
95+
96+
metacall_allocator_free(allocator, inspect_str);
97+
98+
metacall_allocator_destroy(allocator);
99+
}
100+
101+
EXPECT_EQ((int)0, (int)metacall_destroy());
102+
}

0 commit comments

Comments
 (0)