| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/common/byte_buf.h> |
| 7 |
#include <aws/sdkutils/endpoints_bdd_engine.h> |
| 8 |
#include <aws/sdkutils/partitions.h> |
| 9 |
#include <aws/sdkutils/private/endpoints_types_impl.h> |
| 10 |
#include <aws/testing/aws_test_harness.h> |
| 11 |
|
| 12 |
AWS_TEST_CASE(endpoints_bdd_loader_basic, s_test_bdd_loader_basic) |
| 13 |
static int s_test_bdd_loader_basic(struct aws_allocator *allocator, void *ctx) { |
| 14 |
(void)ctx; |
| 15 |
|
| 16 |
aws_sdkutils_library_init(allocator); |
| 17 |
|
| 18 |
struct aws_byte_buf bytecode; |
| 19 |
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&bytecode, allocator, "bdd_test.bin")); |
| 20 |
|
| 21 |
struct aws_byte_buf partitions_buf; |
| 22 |
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&partitions_buf, allocator, "sample_partitions.json")); |
| 23 |
struct aws_byte_cursor partitions_json = aws_byte_cursor_from_buf(&partitions_buf); |
| 24 |
|
| 25 |
struct aws_partitions_config *partitions = aws_partitions_config_new_from_string(allocator, partitions_json); |
| 26 |
ASSERT_NOT_NULL(partitions); |
| 27 |
|
| 28 |
struct aws_endpoints_bdd_engine *engine = |
| 29 |
aws_endpoints_bdd_engine_new_from_bytecode(allocator, aws_byte_cursor_from_buf(&bytecode), partitions); |
| 30 |
ASSERT_NOT_NULL(engine); |
| 31 |
|
| 32 |
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&engine->version, "1.1")); |
| 33 |
ASSERT_UINT_EQUALS(17, aws_hash_table_get_entry_count(&engine->parameters)); |
| 34 |
ASSERT_UINT_EQUALS(76, aws_array_list_length(&engine->conditions)); |
| 35 |
ASSERT_UINT_EQUALS(97, aws_array_list_length(&engine->results)); |
| 36 |
|
| 37 |
aws_endpoints_bdd_engine_release(engine); |
| 38 |
aws_partitions_config_release(partitions); |
| 39 |
aws_byte_buf_clean_up(&partitions_buf); |
| 40 |
aws_byte_buf_clean_up(&bytecode); |
| 41 |
|
| 42 |
return AWS_OP_SUCCESS; |
| 43 |
} |
| 44 |
|
| 45 |
AWS_TEST_CASE(endpoints_bdd_compiler_loader_roundtrip, s_test_bdd_compiler_loader_roundtrip) |
| 46 |
static int s_test_bdd_compiler_loader_roundtrip(struct aws_allocator *allocator, void *ctx) { |
| 47 |
(void)ctx; |
| 48 |
|
| 49 |
aws_sdkutils_library_init(allocator); |
| 50 |
|
| 51 |
struct aws_byte_buf bytecode; |
| 52 |
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&bytecode, allocator, "simple_bdd_test.bin")); |
| 53 |
|
| 54 |
struct aws_byte_buf partitions_buf; |
| 55 |
ASSERT_SUCCESS(aws_byte_buf_init_from_file(&partitions_buf, allocator, "sample_partitions.json")); |
| 56 |
struct aws_byte_cursor partitions_json = aws_byte_cursor_from_buf(&partitions_buf); |
| 57 |
|
| 58 |
struct aws_partitions_config *partitions = aws_partitions_config_new_from_string(allocator, partitions_json); |
| 59 |
ASSERT_NOT_NULL(partitions); |
| 60 |
|
| 61 |
struct aws_endpoints_bdd_engine *engine = |
| 62 |
aws_endpoints_bdd_engine_new_from_bytecode(allocator, aws_byte_cursor_from_buf(&bytecode), partitions); |
| 63 |
ASSERT_NOT_NULL(engine); |
| 64 |
|
| 65 |
ASSERT_TRUE(aws_byte_cursor_eq_c_str(&engine->version, "1.1")); |
| 66 |
ASSERT_UINT_EQUALS(2, aws_hash_table_get_entry_count(&engine->parameters)); |
| 67 |
ASSERT_UINT_EQUALS(2, aws_array_list_length(&engine->conditions)); |
| 68 |
ASSERT_UINT_EQUALS(3, aws_array_list_length(&engine->results)); |
| 69 |
ASSERT_UINT_EQUALS(3, aws_array_list_length(&engine->nodes)); |
| 70 |
|
| 71 |
aws_endpoints_bdd_engine_release(engine); |
| 72 |
aws_partitions_config_release(partitions); |
| 73 |
aws_byte_buf_clean_up(&partitions_buf); |
| 74 |
aws_byte_buf_clean_up(&bytecode); |
| 75 |
|
| 76 |
return AWS_OP_SUCCESS; |
| 77 |
} |