omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / v2 / singleedit.c
| 1 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | #include "omega_native.h" |
| 3 | #include <stdint.h> |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #ifdef SINGLE_OM1 |
| 7 | #define CALL omega_e3 |
| 8 | #elif defined(SINGLE_DEVICE) |
| 9 | #define CALL(result, bytes, count) omega2_ctx_e3(context, result, bytes, count) |
| 10 | #else |
| 11 | #define CALL omega2_e3 |
| 12 | #endif |
| 13 | int main(void) { |
| 14 | #ifdef SINGLE_DEVICE |
| 15 | omega_native_context *context = NULL; |
| 16 | if (omega_native_context_create(1, &context) != 0) |
| 17 | return 5; |
| 18 | #endif |
| 19 | _Alignas(8) unsigned char bytes[8] = {1, 2, 3}; |
| 20 | const unsigned char expected[8] = {1, 2, 3}; |
| 21 | uint64_t result = 99; |
| 22 | if (CALL(&result, bytes, 3) != 0 || result != 3 || |
| 23 | memcmp(bytes, expected, sizeof bytes) != 0) |
| 24 | return 1; |
| 25 | #ifdef SINGLE_OM1 |
| 26 | if (CALL(&result, NULL, 0) != 32) |
| 27 | return 2; |
| 28 | #else |
| 29 | if (CALL(&result, NULL, 0) != 0 || result != 0) |
| 30 | return 2; |
| 31 | #endif |
| 32 | if (CALL(NULL, bytes, 3) != 32) |
| 33 | return 3; |
| 34 | if (CALL((uint64_t *)bytes, bytes, 3) != 32 || |
| 35 | memcmp(bytes, expected, sizeof bytes) != 0) |
| 36 | return 4; |
| 37 | #ifdef SINGLE_DEVICE |
| 38 | if (omega_native_context_destroy(context) != 0) |
| 39 | return 6; |
| 40 | #endif |
| 41 | puts("SINGLE-EDIT caller PASS length, empty, null-result and alias controls"); |
| 42 | return 0; |
| 43 | } |