1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <sys/mman.h>
18
19#include <gtest/gtest.h>
20
21#include <ion/ion.h>
22
23#include "ion_test_fixture.h"
24
25class FormerlyValidHandle : public IonTest {
26 public:
27    virtual void SetUp();
28    virtual void TearDown();
29    ion_user_handle_t m_handle;
30};
31
32void FormerlyValidHandle::SetUp()
33{
34    IonTest::SetUp();
35    ASSERT_EQ(0, ion_alloc(m_ionFd, 4096, 0, 1/* ion_env->m_firstHeap */, 0, &m_handle));
36    ASSERT_TRUE(m_handle != 0);
37    ASSERT_EQ(0, ion_free(m_ionFd, m_handle));
38}
39
40void FormerlyValidHandle::TearDown()
41{
42    m_handle = 0;
43}
44
45TEST_F(FormerlyValidHandle, free)
46{
47	ASSERT_EQ(-EINVAL, ion_free(m_ionFd, m_handle));
48}
49
50TEST_F(FormerlyValidHandle, map)
51{
52    int map_fd;
53    unsigned char *ptr;
54
55    ASSERT_EQ(-EINVAL, ion_map(m_ionFd, m_handle, 4096, PROT_READ, 0, 0, &ptr, &map_fd));
56}
57
58TEST_F(FormerlyValidHandle, share)
59{
60    int share_fd;
61
62    ASSERT_EQ(-EINVAL, ion_share(m_ionFd, m_handle, &share_fd));
63}
64