-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from PowerGridModel/feature/c-tests
C api and unit tests for vnf converter
- Loading branch information
Showing
7 changed files
with
225 additions
and
34 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...io_native_c/power_grid_model_io_native/include/power_grid_model_io_native/common/enum.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#pragma once | ||
|
||
#include "common.hpp" | ||
|
||
namespace power_grid_model_io_native { | ||
|
||
enum class ExperimentalFeatures : IntS { | ||
experimental_features_disabled = 0, | ||
experimental_features_enabled = 1, | ||
}; | ||
|
||
} // namespace power_grid_model_io_native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-FileCopyrightText: Contributors to the Power Grid Model project <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
# | ||
|
||
#include <power_grid_model_io_native_c/basics.h> | ||
#include <power_grid_model_io_native_c/handle.h> | ||
#include <power_grid_model_io_native_c/vnf_pgm_converter.h> | ||
|
||
#include <power_grid_model/common/exception.hpp> | ||
|
||
#include <cstring> | ||
#include <doctest/doctest.h> | ||
|
||
namespace power_grid_model_io_native { | ||
|
||
using enum PGM_IO_ExperimentalFeatures; | ||
|
||
TEST_CASE("Test PGM_IO_create_vnf_converter") { | ||
PGM_IO_ExperimentalFeatures experimental_feature_flag = PGM_IO_experimental_features_disabled; | ||
|
||
SUBCASE("Test PGM_IO_create_vnf_converter without experimental feature flag") { | ||
PGM_IO_Handle* handle = PGM_IO_create_handle(); | ||
auto converter = PGM_IO_create_vnf_converter(handle, "", experimental_feature_flag); | ||
CHECK(PGM_IO_error_code(handle) == PGM_IO_regular_error); | ||
PGM_IO_destroy_vnf_converter(converter); | ||
PGM_IO_destroy_handle(handle); | ||
} | ||
|
||
SUBCASE("Test PGM_IO_create_vnf_converter with experimental feature flag") { | ||
PGM_IO_Handle* handle = PGM_IO_create_handle(); | ||
experimental_feature_flag = PGM_IO_experimental_features_enabled; | ||
auto converter = PGM_IO_create_vnf_converter(handle, "", experimental_feature_flag); | ||
CHECK(converter != nullptr); | ||
PGM_IO_destroy_vnf_converter(converter); | ||
PGM_IO_destroy_handle(handle); | ||
} | ||
} | ||
|
||
TEST_CASE("Test PGM_IO_get_vnf_input_data") { | ||
PGM_IO_Handle* handle = PGM_IO_create_handle(); | ||
PGM_IO_ExperimentalFeatures experimental_feature_flag = PGM_IO_experimental_features_enabled; | ||
|
||
auto converter = PGM_IO_create_vnf_converter(handle, "", experimental_feature_flag); | ||
CHECK(converter != nullptr); | ||
|
||
auto json_result = PGM_IO_get_vnf_input_data(handle, converter); | ||
std::string_view json_string = R"({"version":"1.0","type":"input","is_batch":false,"attributes":{},"data":{}})"; | ||
CHECK(json_string == json_result); | ||
|
||
PGM_IO_destroy_vnf_converter(converter); | ||
PGM_IO_destroy_handle(handle); | ||
} | ||
|
||
} // namespace power_grid_model_io_native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters