|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:typed_data'; |
| 6 | +import 'dart:ui'; |
| 7 | + |
| 8 | +import 'package:litetest/litetest.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + test('Vertices checks', () { |
| 12 | + try { |
| 13 | + Vertices( |
| 14 | + VertexMode.triangles, |
| 15 | + const <Offset>[Offset.zero, Offset.zero, Offset.zero], |
| 16 | + indices: Uint16List.fromList(const <int>[0, 2, 5]), |
| 17 | + ); |
| 18 | + throw 'Vertices did not throw the expected error.'; |
| 19 | + } on ArgumentError catch (e) { |
| 20 | + expect('$e', 'Invalid argument(s): "indices" values must be valid indices in the positions list (i.e. numbers in the range 0..2), but indices[2] is 5, which is too big.'); |
| 21 | + } |
| 22 | + Vertices( // This one does not throw. |
| 23 | + VertexMode.triangles, |
| 24 | + const <Offset>[Offset.zero], |
| 25 | + ).dispose(); |
| 26 | + Vertices( // This one should not throw. |
| 27 | + VertexMode.triangles, |
| 28 | + const <Offset>[Offset.zero, Offset.zero, Offset.zero], |
| 29 | + indices: Uint16List.fromList(const <int>[0, 2, 1, 2, 0, 1, 2, 0]), // Uint16List implements List<int> so this is ok. |
| 30 | + ).dispose(); |
| 31 | + }); |
| 32 | + |
| 33 | + test('Vertices.raw checks', () { |
| 34 | + try { |
| 35 | + Vertices.raw( |
| 36 | + VertexMode.triangles, |
| 37 | + Float32List.fromList(const <double>[0.0]), |
| 38 | + ); |
| 39 | + throw 'Vertices.raw did not throw the expected error.'; |
| 40 | + } on ArgumentError catch (e) { |
| 41 | + expect('$e', 'Invalid argument(s): "positions" must have an even number of entries (each coordinate is an x,y pair).'); |
| 42 | + } |
| 43 | + try { |
| 44 | + Vertices.raw( |
| 45 | + VertexMode.triangles, |
| 46 | + Float32List.fromList(const <double>[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]), |
| 47 | + indices: Uint16List.fromList(const <int>[0, 2, 5]), |
| 48 | + ); |
| 49 | + throw 'Vertices.raw did not throw the expected error.'; |
| 50 | + } on ArgumentError catch (e) { |
| 51 | + expect('$e', 'Invalid argument(s): "indices" values must be valid indices in the positions list (i.e. numbers in the range 0..2), but indices[2] is 5, which is too big.'); |
| 52 | + } |
| 53 | + Vertices.raw( // This one does not throw. |
| 54 | + VertexMode.triangles, |
| 55 | + Float32List.fromList(const <double>[0.0, 0.0]), |
| 56 | + ).dispose(); |
| 57 | + Vertices.raw( // This one should not throw. |
| 58 | + VertexMode.triangles, |
| 59 | + Float32List.fromList(const <double>[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]), |
| 60 | + indices: Uint16List.fromList(const <int>[0, 2, 1, 2, 0, 1, 2, 0]), |
| 61 | + ).dispose(); |
| 62 | + }); |
| 63 | +} |
0 commit comments