175 lines
6.8 KiB
Dart
175 lines
6.8 KiB
Dart
/*
|
|
* Copyright (c) 2025
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:splash_video/splash_video.dart';
|
|
|
|
void main() {
|
|
group('VideoConfig', () {
|
|
test('creates with default values', () {
|
|
const config = VideoConfig();
|
|
|
|
expect(config.playImmediately, isTrue);
|
|
expect(config.scale, equals(VideoScaleMode.cover));
|
|
expect(config.useSafeArea, isFalse);
|
|
expect(config.volume, equals(80.0));
|
|
expect(config.onPlayerInitialized, isNull);
|
|
});
|
|
|
|
test('creates with custom values', () {
|
|
final config = VideoConfig(
|
|
playImmediately: false,
|
|
scale: VideoScaleMode.contain,
|
|
useSafeArea: true,
|
|
volume: 50.0,
|
|
onPlayerInitialized: (player) {},
|
|
);
|
|
|
|
expect(config.playImmediately, isFalse);
|
|
expect(config.scale, equals(VideoScaleMode.contain));
|
|
expect(config.useSafeArea, isTrue);
|
|
expect(config.volume, equals(50.0));
|
|
expect(config.onPlayerInitialized, isNotNull);
|
|
});
|
|
|
|
test('backward compatibility: videoVisibilityEnum getter works', () {
|
|
const config = VideoConfig(scale: VideoScaleMode.cover);
|
|
// ignore: deprecated_member_use_from_same_package
|
|
expect(config.videoVisibilityEnum, equals(VideoScaleMode.cover));
|
|
});
|
|
|
|
test('accepts volume range 0-100', () {
|
|
const config1 = VideoConfig(volume: 0.0);
|
|
const config2 = VideoConfig(volume: 100.0);
|
|
const config3 = VideoConfig(volume: 50.0);
|
|
|
|
expect(config1.volume, equals(0.0));
|
|
expect(config2.volume, equals(100.0));
|
|
expect(config3.volume, equals(50.0));
|
|
});
|
|
|
|
test('onPlayerInitialized callback can be invoked', () {
|
|
var callbackInvoked = false;
|
|
|
|
final config = VideoConfig(
|
|
onPlayerInitialized: (player) {
|
|
callbackInvoked = true;
|
|
},
|
|
);
|
|
|
|
// Mock Player call - we can't create real Player in unit tests
|
|
// because MediaKit requires native libraries
|
|
expect(config.onPlayerInitialized, isNotNull);
|
|
|
|
// Verify the callback is callable (just testing the API surface)
|
|
if (config.onPlayerInitialized != null) {
|
|
// We can't actually create a Player without MediaKit native libs
|
|
// but we can verify the callback signature is correct
|
|
expect(callbackInvoked, isFalse);
|
|
}
|
|
});
|
|
});
|
|
|
|
group('VideoFitMode', () {
|
|
test('has all expected values', () {
|
|
expect(VideoScaleMode.values.length, equals(7));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.fill));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.cover));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.contain));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.fitWidth));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.fitHeight));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.none));
|
|
expect(VideoScaleMode.values, contains(VideoScaleMode.scaleDown));
|
|
});
|
|
|
|
test('values are unique', () {
|
|
final values = VideoScaleMode.values.toSet();
|
|
expect(values.length, equals(VideoScaleMode.values.length));
|
|
});
|
|
|
|
test('converts correctly to BoxFit', () {
|
|
expect(VideoScaleMode.fill.toBoxFit(), equals(BoxFit.fill));
|
|
expect(VideoScaleMode.cover.toBoxFit(), equals(BoxFit.cover));
|
|
expect(VideoScaleMode.contain.toBoxFit(), equals(BoxFit.contain));
|
|
expect(VideoScaleMode.fitWidth.toBoxFit(), equals(BoxFit.fitWidth));
|
|
expect(VideoScaleMode.fitHeight.toBoxFit(), equals(BoxFit.fitHeight));
|
|
expect(VideoScaleMode.none.toBoxFit(), equals(BoxFit.none));
|
|
expect(VideoScaleMode.scaleDown.toBoxFit(), equals(BoxFit.scaleDown));
|
|
});
|
|
});
|
|
|
|
group('HwdecMode', () {
|
|
test('has all expected values', () {
|
|
expect(HwdecMode.values.length, equals(9));
|
|
expect(HwdecMode.values, contains(HwdecMode.auto));
|
|
expect(HwdecMode.values, contains(HwdecMode.autoSafe));
|
|
expect(HwdecMode.values, contains(HwdecMode.autoCopy));
|
|
expect(HwdecMode.values, contains(HwdecMode.disabled));
|
|
expect(HwdecMode.values, contains(HwdecMode.d3d11va));
|
|
expect(HwdecMode.values, contains(HwdecMode.dxva2));
|
|
expect(HwdecMode.values, contains(HwdecMode.videoToolbox));
|
|
expect(HwdecMode.values, contains(HwdecMode.vaapi));
|
|
expect(HwdecMode.values, contains(HwdecMode.mediaCodec));
|
|
});
|
|
|
|
test('values are unique', () {
|
|
final values = HwdecMode.values.toSet();
|
|
expect(values.length, equals(HwdecMode.values.length));
|
|
});
|
|
|
|
test('each mode has correct string value', () {
|
|
expect(HwdecMode.auto.value, equals('auto'));
|
|
expect(HwdecMode.autoSafe.value, equals('auto-safe'));
|
|
expect(HwdecMode.autoCopy.value, equals('auto-copy'));
|
|
expect(HwdecMode.disabled.value, equals('no'));
|
|
expect(HwdecMode.d3d11va.value, equals('d3d11va'));
|
|
expect(HwdecMode.dxva2.value, equals('dxva2'));
|
|
expect(HwdecMode.videoToolbox.value, equals('videotoolbox'));
|
|
expect(HwdecMode.vaapi.value, equals('vaapi'));
|
|
expect(HwdecMode.mediaCodec.value, equals('mediacodec'));
|
|
});
|
|
});
|
|
|
|
group('VideoConfig hwdec', () {
|
|
test('default hwdec is null', () {
|
|
const config = VideoConfig();
|
|
expect(config.hwdec, isNull);
|
|
});
|
|
|
|
test('accepts HwdecMode enum values', () {
|
|
const config1 = VideoConfig(hwdec: HwdecMode.autoSafe);
|
|
const config2 = VideoConfig(hwdec: HwdecMode.disabled);
|
|
const config3 = VideoConfig(hwdec: HwdecMode.d3d11va);
|
|
|
|
expect(config1.hwdec, equals(HwdecMode.autoSafe));
|
|
expect(config2.hwdec, equals(HwdecMode.disabled));
|
|
expect(config3.hwdec, equals(HwdecMode.d3d11va));
|
|
});
|
|
|
|
test('hwdec value property returns correct string', () {
|
|
const config = VideoConfig(hwdec: HwdecMode.autoSafe);
|
|
expect(config.hwdec?.value, equals('auto-safe'));
|
|
});
|
|
});
|
|
}
|