mirror of
https://github.com/Solido/mixbox.git
synced 2026-03-19 14:39:34 +01:00
init
This commit is contained in:
84
test/mixbox_loader_test.dart
Normal file
84
test/mixbox_loader_test.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mixbox/mixbox.dart';
|
||||
import 'package:mixbox/mixbox_loader.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('MixboxLoader', () {
|
||||
test('initializeFromAsset loads and decompress LUT', () async {
|
||||
// Read the actual LUT file from the assets directory for mocking
|
||||
// In a real environment, we'd use the relative path from the project root
|
||||
final lutFile = File('assets/mixbox_lut.dat');
|
||||
if (!lutFile.existsSync()) {
|
||||
fail('LUT file not found at ${lutFile.absolute.path}. Run tests from project root.');
|
||||
}
|
||||
final lutBytes = await lutFile.readAsBytes();
|
||||
|
||||
// Mock rootBundle
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler('flutter/assets', (
|
||||
ByteData? message,
|
||||
) async {
|
||||
// The message contains the asset key encoded as UTF-8
|
||||
final key = utf8.decode(message!.buffer.asUint8List());
|
||||
if (key.contains('mixbox_lut.dat')) {
|
||||
return ByteData.view(lutBytes.buffer);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
// Call initializeFromAsset
|
||||
await MixboxLoader.initializeFromAsset('assets/mixbox_lut.dat');
|
||||
|
||||
expect(Mixbox.isInitialized, isTrue);
|
||||
|
||||
// Verify basic color mixing
|
||||
// Blue: 0, 0, 255 -> 0xFF0000FF
|
||||
// Yellow: 255, 255, 0 -> 0xFFFFFF00
|
||||
const blue = 0xFF0000FF;
|
||||
const yellow = 0xFFFFFF00;
|
||||
|
||||
final mixed = Mixbox.lerp(blue, yellow, 0.5);
|
||||
|
||||
final r = (mixed >> 16) & 0xFF;
|
||||
final g = (mixed >> 8) & 0xFF;
|
||||
final b = mixed & 0xFF;
|
||||
|
||||
// In Mixbox, blue + yellow = green
|
||||
// (Standard lerp would give gray/brown: 127, 127, 127)
|
||||
expect(g, greaterThan(r), reason: 'Mixed color should be greenish (high Green)');
|
||||
expect(g, greaterThan(b), reason: 'Mixed color should be greenish (high Green)');
|
||||
expect(r, lessThanOrEqualTo(100), reason: 'Red should be relatively low in green');
|
||||
expect(b, lessThanOrEqualTo(100), reason: 'Blue should be relatively low in green');
|
||||
});
|
||||
|
||||
test('generateTestLut creates a valid sized LUT', () {
|
||||
final lut = MixboxLoader.generateTestLut();
|
||||
// Expected size: 64 * 64 * 64 * 3 + 4353 = 790785
|
||||
expect(lut.length, equals(790785));
|
||||
});
|
||||
});
|
||||
|
||||
group('MixboxColorExtension', () {
|
||||
test('toMixboxInt and fromMixboxInt', () {
|
||||
const color = Color(0xFF123456);
|
||||
expect(color.toMixboxInt(), equals(0xFF123456));
|
||||
});
|
||||
|
||||
test('mixWith', () {
|
||||
// This test depends on Mixbox being initialized
|
||||
// If the first test passed, it is.
|
||||
if (Mixbox.isInitialized) {
|
||||
const blue = Color(0xFF0000FF);
|
||||
const yellow = Color(0xFFFFFF00);
|
||||
final green = blue.mixWith(yellow, 0.5);
|
||||
|
||||
expect(green.green, greaterThan(green.red));
|
||||
expect(green.green, greaterThan(green.blue));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user