OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium 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 package org.chromium.shape_detection; | |
6 | |
7 import static org.junit.Assert.assertNull; | |
8 | |
9 import org.junit.Before; | |
10 import org.junit.Test; | |
11 import org.junit.runner.RunWith; | |
12 import org.mockito.Mockito; | |
13 import org.mockito.MockitoAnnotations; | |
14 import org.robolectric.annotation.Config; | |
15 import org.robolectric.shadows.ShadowLog; | |
16 | |
17 import org.chromium.base.test.util.Feature; | |
18 import org.chromium.mojo.system.SharedBufferHandle; | |
19 import org.chromium.mojo.system.SharedBufferHandle.MapFlags; | |
20 import org.chromium.testing.local.LocalRobolectricTestRunner; | |
21 | |
22 import java.nio.ByteBuffer; | |
23 | |
24 /** | |
25 * Test suite for conversion-to-Frame utils. | |
26 */ | |
27 @RunWith(LocalRobolectricTestRunner.class) | |
28 @Config(manifest = Config.NONE) | |
29 public class SharedBufferUtilsTest { | |
30 private static final int VALID_WIDTH = 1; | |
31 private static final int VALID_HEIGHT = 1; | |
32 private static final int INVALID_WIDTH = 0; | |
33 private static final long NUM_BYTES = VALID_WIDTH * VALID_HEIGHT * 4; | |
34 | |
35 public SharedBufferUtilsTest() {} | |
36 | |
37 @Before | |
38 public void setUp() { | |
39 ShadowLog.stream = System.out; | |
40 MockitoAnnotations.initMocks(this); | |
41 } | |
42 | |
43 /** | |
44 * Verify conversion fails if the SharedBufferHandle is invalid. | |
45 */ | |
46 @Test | |
47 @Feature({"ShapeDetection"}) | |
48 public void testConversionFailsWithInvalidHandle() { | |
49 SharedBufferHandle handle = Mockito.mock(SharedBufferHandle.class); | |
50 Mockito.when(handle.isValid()).thenReturn(false); | |
51 | |
52 assertNull(SharedBufferUtils.convertToFrame(handle, VALID_WIDTH, VALID_H
EIGHT)); | |
53 } | |
54 | |
55 /** | |
56 * Verify conversion fails if the sent dimensions are ugly. | |
57 */ | |
58 @Test | |
59 @Feature({"ShapeDetection"}) | |
60 public void testConversionFailsWithInvalidDimensions() { | |
61 SharedBufferHandle handle = Mockito.mock(SharedBufferHandle.class); | |
62 Mockito.when(handle.isValid()).thenReturn(true); | |
63 | |
64 assertNull(SharedBufferUtils.convertToFrame(handle, INVALID_WIDTH, VALID
_HEIGHT)); | |
65 } | |
66 | |
67 /** | |
68 * Verify conversion fails if SharedBufferHandle fails to map(). | |
69 */ | |
70 @Test | |
71 @Feature({"ShapeDetection"}) | |
72 public void testConversionFailsWithWronglyMappedBuffer() { | |
73 SharedBufferHandle handle = Mockito.mock(SharedBufferHandle.class); | |
74 Mockito.when(handle.isValid()).thenReturn(true); | |
75 Mockito.when(handle.map(Mockito.eq(0L), Mockito.eq(NUM_BYTES), Mockito.a
ny(MapFlags.class))) | |
76 .thenReturn(ByteBuffer.allocate(0)); | |
77 | |
78 assertNull(SharedBufferUtils.convertToFrame(handle, VALID_WIDTH, VALID_H
EIGHT)); | |
79 } | |
80 } | |
OLD | NEW |