compare method

  1. @override
Future<bool> compare (Uint8List imageBytes, Uri golden)
override

Compares imageBytes against the golden file identified by golden.

The returned future completes with a boolean value that indicates whether imageBytes matches the golden file's bytes within the tolerance defined by the comparator.

In the case of comparison mismatch, the comparator may choose to throw a TestFailure if it wants to control the failure message.

The method by which golden is located and by which its bytes are loaded is left up to the implementation class. For instance, some implementations may load files from the local file system, whereas others may load files over the network or from a remote repository.

Implementation

@override
Future<bool> compare(Uint8List imageBytes, Uri golden) async {
  final File goldenFile = _getFile(golden);
  if (!goldenFile.existsSync()) {
    throw test_package.TestFailure('Could not be compared against non-existent file: "$golden"');
  }
  final List<int> goldenBytes = await goldenFile.readAsBytes();
  return _areListsEqual<int>(imageBytes, goldenBytes);
}