25 lines
1.3 KiB
C
25 lines
1.3 KiB
C
#include "ble_identity.h"
|
|
#include "debug_config.h"
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
int main(void) {
|
|
debug_config_init();
|
|
uint8_t bytes[24]; struct ble_identity peer;
|
|
int n = ble_identity_encode(bytes, 0x0102030405060708ULL, "АБВГДЕЖ");
|
|
assert(n == 23 && bytes[0] == 'V' && bytes[1] == 'C' && bytes[2] == 2 && bytes[3] == 1 && bytes[10] == 8);
|
|
assert(ble_identity_decode(&peer, bytes, n) == 0);
|
|
assert(peer.node_id == 0x0102030405060708ULL && !strcmp(peer.name, "АБВГДЕ"));
|
|
assert(ble_identity_encode(bytes, 1, "123456789012😀") == 23);
|
|
assert(ble_identity_encode(bytes, 1, "1234567890123tail") == 24);
|
|
assert(ble_identity_decode(&peer, bytes, 24) == 0 && !strcmp(peer.name, "1234567890123"));
|
|
assert(ble_identity_decode(&peer, bytes, 25) < 0);
|
|
bytes[2] = 1; assert(ble_identity_decode(&peer, bytes, 24) < 0);
|
|
bytes[2] = 3; assert(ble_identity_decode(&peer, bytes, 24) < 0);
|
|
n = ble_identity_encode(bytes, 1, ""); assert(n == 11 && ble_identity_decode(&peer, bytes, n) == 0);
|
|
bytes[11] = 0xc0; bytes[12] = 0x80; assert(ble_identity_decode(&peer, bytes, 13) < 0);
|
|
assert(ble_identity_encode(bytes, 0, "name") < 0);
|
|
assert(ble_identity_encode(bytes, 1, "\xed\xa0\x80") < 0);
|
|
puts("BLE identity PASS"); return 0;
|
|
}
|