diff --git a/source/configuration/source/configuration.c b/source/configuration/source/configuration.c index 9a04c2e3e..c96fd71ec 100644 --- a/source/configuration/source/configuration.c +++ b/source/configuration/source/configuration.c @@ -86,43 +86,47 @@ int configuration_initialize(const char *reader, const char *path, void *allocat if (global == NULL) { - log_write("metacall", LOG_LEVEL_ERROR, "MetaCall could not find the global configuration, " - "either use a relative path configuration '" CONFIGURATION_DEFAULT_PATH "' or define the environment " - "variable '" CONFIGURATION_PATH "'"); + log_write("metacall", LOG_LEVEL_WARNING, "MetaCall could not find the global configuration, " + "either use a relative path configuration '" CONFIGURATION_DEFAULT_PATH "' or define the environment " + "variable '" CONFIGURATION_PATH "', MetaCall will use a default configuration"); - configuration_destroy(); + global = configuration_object_initialize(CONFIGURATION_GLOBAL_SCOPE, NULL, NULL); - return 1; + if (global == NULL) + { + log_write("metacall", LOG_LEVEL_ERROR, "Default global configuration failed to initialize"); + + goto configuration_error; + } } if (configuration_singleton_initialize(global) != 0) { log_write("metacall", LOG_LEVEL_ERROR, "Invalid configuration singleton initialization"); - configuration_destroy(); - - return 1; + goto configuration_error; } if (configuration_impl_initialize(reader) != 0) { log_write("metacall", LOG_LEVEL_ERROR, "Invalid configuration implementation initialization"); - configuration_destroy(); - - return 1; + goto configuration_error; } if (configuration_impl_load(global, allocator) != 0) { log_write("metacall", LOG_LEVEL_ERROR, "Invalid configuration implementation load <%p>", global); - configuration_destroy(); - - return 1; + goto configuration_error; } return 0; + +configuration_error: + configuration_destroy(); + + return 1; } configuration configuration_create(const char *scope, const char *path, const char *parent, void *allocator) diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 38a23906a..34502c1f7 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -161,6 +161,7 @@ add_subdirectory(metacall_inspect_test) add_subdirectory(metacall_integration_test) add_subdirectory(metacall_depends_test) add_subdirectory(metacall_configuration_exec_path_test) +add_subdirectory(metacall_configuration_default_test) add_subdirectory(metacall_clear_test) add_subdirectory(metacall_python_test) add_subdirectory(metacall_python_object_class_test) diff --git a/source/tests/metacall_configuration_default_test/CMakeLists.txt b/source/tests/metacall_configuration_default_test/CMakeLists.txt new file mode 100644 index 000000000..35771e07c --- /dev/null +++ b/source/tests/metacall_configuration_default_test/CMakeLists.txt @@ -0,0 +1,151 @@ +# +# Executable name and options +# + +# Target name +set(target metacall-configuration-default-test) +message(STATUS "Test ${target}") + +# +# Compiler warnings +# + +include(Warnings) + +# +# Compiler security +# + +include(SecurityFlags) + +# +# Sources +# + +set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}") +set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source") + +set(sources + ${source_path}/main.cpp + ${source_path}/metacall_configuration_default_test.cpp +) + +# Group source files +set(header_group "Header Files (API)") +set(source_group "Source Files") +source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$" + ${header_group} ${headers}) +source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$" + ${source_group} ${sources}) + +# +# Create executable +# + +# Build executable +add_executable(${target} + ${sources} +) + +# Create namespaced alias +add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target}) + +# +# Project options +# + +# Create a custom directory different from default for forcing metacall not to find the configuration +set(CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY "${PROJECT_OUTPUT_DIR}/configuration-default-test") + +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}) + +set_target_properties(${target} + PROPERTIES + ${DEFAULT_PROJECT_OPTIONS} + FOLDER "${IDE_FOLDER}" + + # Define custom build output directory + LIBRARY_OUTPUT_DIRECTORY "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + + RUNTIME_OUTPUT_DIRECTORY "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + + ARCHIVE_OUTPUT_DIRECTORY "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" + ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL "${CONFIGURATION_DEFAULT_OUTPUT_DIRECTORY}" +) + +# +# Include directories +# + +target_include_directories(${target} + PRIVATE + ${DEFAULT_INCLUDE_DIRECTORIES} + ${PROJECT_BINARY_DIR}/source/include +) + +# +# Libraries +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LIBRARIES} + + GTest + + ${META_PROJECT_NAME}::metacall +) + +# +# Compile definitions +# + +target_compile_definitions(${target} + PRIVATE + ${DEFAULT_COMPILE_DEFINITIONS} +) + +# +# Compile options +# + +target_compile_options(${target} + PRIVATE + ${DEFAULT_COMPILE_OPTIONS} +) + +# +# Linker options +# + +target_link_libraries(${target} + PRIVATE + ${DEFAULT_LINKER_OPTIONS} +) + +# +# Define test +# + +add_test(NAME ${target} + COMMAND $ +) + +# +# Define test properties +# + +set_property(TEST ${target} + PROPERTY LABELS ${target} +) diff --git a/source/tests/metacall_configuration_default_test/source/main.cpp b/source/tests/metacall_configuration_default_test/source/main.cpp new file mode 100644 index 000000000..628e40890 --- /dev/null +++ b/source/tests/metacall_configuration_default_test/source/main.cpp @@ -0,0 +1,28 @@ +/* + * MetaCall Library by Parra Studios + * A library for providing a foreign function interface calls. + * + * Copyright (C) 2016 - 2022 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/source/tests/metacall_configuration_default_test/source/metacall_configuration_default_test.cpp b/source/tests/metacall_configuration_default_test/source/metacall_configuration_default_test.cpp new file mode 100644 index 000000000..97b85c663 --- /dev/null +++ b/source/tests/metacall_configuration_default_test/source/metacall_configuration_default_test.cpp @@ -0,0 +1,37 @@ +/* + * MetaCall Library by Parra Studios + * A library for providing a foreign function interface calls. + * + * Copyright (C) 2016 - 2022 Vicente Eduardo Ferrer Garcia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +class metacall_configuration_default_test : public testing::Test +{ +public: +}; + +TEST_F(metacall_configuration_default_test, DefaultConstructor) +{ + metacall_print_info(); + + ASSERT_EQ((int)0, (int)metacall_initialize()); + + EXPECT_EQ((int)0, (int)metacall_destroy()); +}