hondavert-dev/test/neg8_test.dart
HVBT Dev 11cf7c2b63 v1.0.1 — Phase 1 complete + BT connection test UI
- Phase 1 core protocol: temp_table, neg8, sensor_state, s300_parser,
  kpro_parser, dtc_map, sensor_defs (50/50 tests passing)
- BT layer: bt_service.dart, bt_poller.dart (100ms poll, NEG8 validation)
- Connection test UI: device picker, protocol selector, live sensor screen
  with LIVE DATA + DEBUG LOG tabs
- Runtime BT permission request (Android 12+) + auto-enable Bluetooth
- Android: minSdk=26, all BT+location permissions in manifest
- Fixed flutter_bluetooth_serial namespace for AGP compatibility
2026-04-12 18:07:37 +05:30

39 lines
1.3 KiB
Dart

import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:hvbt_dash/core/protocol/neg8.dart';
void main() {
group('NEG8 checksum', () {
test('S300 request header [0x1B, 0x00] produces 0xE5', () {
// NEG8 of [0x1B, 0x00] = (0 - 0x1B - 0x00) & 0xFF = 0xE5
final buf = Uint8List.fromList([0x1B, 0x00]);
expect(calculateNeg8(buf), equals(0xE5));
});
test('KPro request header [0x1B, 0x01] produces 0xE4', () {
final buf = Uint8List.fromList([0x1B, 0x01]);
expect(calculateNeg8(buf), equals(0xE4));
});
test('validateFrame passes for correctly checksummed frame', () {
// Build a 4-byte frame where last byte = NEG8 of first 3
final data = Uint8List.fromList([0x1B, 0x00, 0x00, 0xE5]);
expect(validateFrame(data), isTrue);
});
test('validateFrame fails for corrupted frame', () {
final data = Uint8List.fromList([0x1B, 0x00, 0x00, 0xFF]);
expect(validateFrame(data), isFalse);
});
test('validateFrame returns false for empty frame', () {
expect(validateFrame(Uint8List(0)), isFalse);
});
test('single byte 0x00 validates as [0x00, 0x00]', () {
// NEG8([0x00]) = 0x00, so frame [0x00, 0x00] should pass
expect(validateFrame(Uint8List.fromList([0x00, 0x00])), isTrue);
});
});
}