Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 1 | #ifndef CPER_IR_TEST_UTILS_H |
| 2 | #define CPER_IR_TEST_UTILS_H |
| 3 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 4 | #include <valijson/adapters/nlohmann_json_adapter.hpp> |
| 5 | #include <valijson/schema.hpp> |
| 6 | #include <valijson/schema_parser.hpp> |
| 7 | #include <valijson/validator.hpp> |
| 8 | #include <nlohmann/json.hpp> |
| 9 | |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 10 | extern "C" { |
Ed Tanous | c97c041 | 2025-02-04 11:31:31 -0800 | [diff] [blame] | 11 | #include <stdio.h> |
Thu Nguyen | e42fb48 | 2024-10-15 14:43:11 +0000 | [diff] [blame] | 12 | #include <libcper/BaseTypes.h> |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 13 | #include <libcper/generator/sections/gen-section.h> |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 14 | } |
| 15 | |
Ed Tanous | d6b6263 | 2025-03-14 15:30:07 -0700 | [diff] [blame] | 16 | // Controls whether required properties are added to the majority of property |
| 17 | // definitions. This is useful for unit tests that are validating JSON where |
| 18 | // all fields are valid |
| 19 | enum class AddRequiredProps { YES, NO }; |
| 20 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 21 | FILE *generate_record_memstream(const char **types, UINT16 num_types, |
| 22 | char **buf, size_t *buf_size, |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 23 | int single_section, |
| 24 | GEN_VALID_BITS_TEST_TYPE validBitsType); |
Ed Tanous | d6b6263 | 2025-03-14 15:30:07 -0700 | [diff] [blame] | 25 | |
| 26 | std::unique_ptr<valijson::Schema> |
| 27 | load_schema(AddRequiredProps add_required_props, int single_section); |
| 28 | |
| 29 | int schema_validate_from_file(const valijson::Schema &schema, |
| 30 | nlohmann::json &jsonData, |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 31 | std::string &error_message); |
Ed Tanous | d6b6263 | 2025-03-14 15:30:07 -0700 | [diff] [blame] | 32 | |
Aushim Nagarkatti | ae8f6d9 | 2025-01-29 17:34:44 -0800 | [diff] [blame] | 33 | nlohmann::json loadJson(const char *filePath); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 34 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 35 | #endif |