Skip to content
Prev Previous commit
Next Next commit
Delete rotation tests
  • Loading branch information
camsim99 committed Dec 11, 2024
commit 6efe07a68e90e7a163cceb65c365bda6ddca49f6
Original file line number Diff line number Diff line change
Expand Up @@ -1336,148 +1336,12 @@ void main() {
// bound to the lifecycle of the camera.
camera.previewInitiallyBound = true;

// Tell camera the Surface used to build camera preview is backed by a
// SurfaceTexture.
camera.isPreviewPreTransformed = true;

camera.naturalOrientation = DeviceOrientation.portraitDown;

final Widget widget = camera.buildPreview(cameraId);

expect(widget is Texture, isTrue);
expect((widget as Texture).textureId, cameraId);
});

test(
'buildPreview returns preview with expected rotation if camera is not front facing and the preview is not backed by a SurfaceTexture',
() async {
final AndroidCameraCameraX camera = AndroidCameraCameraX();
const int cameraId = 33;

// Tell camera that createCamera has been called and thus, preview has been
// bound to the lifecycle of the camera.
camera.previewInitiallyBound = true;

// Tell camera the Surface used to build camera preview is not backed by a
// SurfaceTexture.
camera.isPreviewPreTransformed = false;

// Mock sensor and device orientation.
camera.sensorOrientation = 270;
camera.cameraIsFrontFacing = false;
camera.naturalOrientation = DeviceOrientation.portraitUp;

final double expectedRotation = (camera.sensorOrientation +
0 /* the natural orientation in clockwise degrees */ *
-1 /* camera is not front facing */ +
360) %
360;
final int expectedQuarterTurns = (expectedRotation / 90).toInt();

final Widget widget = camera.buildPreview(cameraId);

expect(widget is RotatedBox, isTrue);
expect((widget as RotatedBox).quarterTurns, expectedQuarterTurns);
expect(widget.child is Texture, isTrue);
expect((widget.child! as Texture).textureId, cameraId);
});

test(
'buildPreview returns preview with expected rotation if camera is front facing, the current orientation is landscape, and the preview is not backed by a SurfaceTexture',
() async {
final AndroidCameraCameraX camera = AndroidCameraCameraX();
const int cameraId = 7;

// Tell camera that createCamera has been called and thus, preview has been
// bound to the lifecycle of the camera.
camera.previewInitiallyBound = true;

// Tell camera the Surface used to build camera preview is not backed by a
// SurfaceTexture.
camera.isPreviewPreTransformed = false;

// Mock sensor and device orientation.
camera.sensorOrientation = 270;
camera.naturalOrientation = DeviceOrientation.portraitUp;
camera.cameraIsFrontFacing = true;

// Calculate expected rotation with offset due to counter-clockwise rotation
// of the image with th efront camera in use.
final double expectedRotation = ((camera.sensorOrientation +
0 /* the natural orientation in clockwise degrees */ *
1 /* camera is front facing */ +
360) %
360) +
180;
final int expectedQuarterTurns = (expectedRotation / 90).toInt() % 4;

// Test landscape left.
camera.currentDeviceOrientation = DeviceOrientation.landscapeLeft;
Widget widget = camera.buildPreview(cameraId);

expect(widget is RotatedBox, isTrue);
expect((widget as RotatedBox).quarterTurns, expectedQuarterTurns);
expect(widget.child is Texture, isTrue);
expect((widget.child! as Texture).textureId, cameraId);

// Test landscape right.
camera.currentDeviceOrientation = DeviceOrientation.landscapeRight;
widget = camera.buildPreview(cameraId);

expect(widget is RotatedBox, isTrue);
expect((widget as RotatedBox).quarterTurns, expectedQuarterTurns);
expect(widget.child is Texture, isTrue);
expect((widget.child! as Texture).textureId, cameraId);
});

test(
'buildPreview returns preview with expected rotation if camera is front facing, the current orientation is not landscape, and the preview is not backed by a SurfaceTexture',
() async {
final AndroidCameraCameraX camera = AndroidCameraCameraX();
const int cameraId = 733;

// Tell camera that createCamera has been called and thus, preview has been
// bound to the lifecycle of the camera.
camera.previewInitiallyBound = true;

// Tell camera the Surface used to build camera preview is not backed by a
// SurfaceTexture.
camera.isPreviewPreTransformed = false;

// Mock sensor and device orientation.
camera.sensorOrientation = 270;
camera.naturalOrientation = DeviceOrientation.portraitUp;
camera.cameraIsFrontFacing = true;

// Calculate expected rotation without offset needed for landscape orientations
// due to counter-clockwise rotation of the image with th efront camera in use.
final double expectedRotation = (camera.sensorOrientation +
0 /* the natural orientation in clockwise degrees */ *
1 /* camera is front facing */ +
360) %
360;

final int expectedQuarterTurns = (expectedRotation / 90).toInt() % 4;

// Test portrait up.
camera.currentDeviceOrientation = DeviceOrientation.portraitUp;
Widget widget = camera.buildPreview(cameraId);

expect(widget is RotatedBox, isTrue);
expect((widget as RotatedBox).quarterTurns, expectedQuarterTurns);
expect(widget.child is Texture, isTrue);
expect((widget.child! as Texture).textureId, cameraId);

// Test portrait down.
camera.currentDeviceOrientation = DeviceOrientation.portraitDown;
widget = camera.buildPreview(cameraId);

expect(widget is RotatedBox, isTrue);
expect((widget as RotatedBox).quarterTurns, expectedQuarterTurns);
expect(widget.child is Texture, isTrue);
expect((widget.child! as Texture).textureId, cameraId);
});

group('video recording', () {
test(
'startVideoCapturing binds video capture use case, updates saved camera instance and its properties, and starts the recording',
Expand Down
Loading