1/*
2 * Copyright (C) 2012 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#define LOG_TAG "Vector_test"
18
19#include <utils/Vector.h>
20#include <cutils/log.h>
21#include <gtest/gtest.h>
22#include <unistd.h>
23
24namespace android {
25
26class VectorTest : public testing::Test {
27protected:
28    virtual void SetUp() {
29    }
30
31    virtual void TearDown() {
32    }
33
34public:
35};
36
37
38TEST_F(VectorTest, CopyOnWrite_CopyAndAddElements) {
39
40    Vector<int> vector;
41    Vector<int> other;
42    vector.setCapacity(8);
43
44    vector.add(1);
45    vector.add(2);
46    vector.add(3);
47
48    EXPECT_EQ(vector.size(), 3);
49
50    // copy the vector
51    other = vector;
52
53    EXPECT_EQ(other.size(), 3);
54
55    // add an element to the first vector
56    vector.add(4);
57
58    // make sure the sizes are correct
59    EXPECT_EQ(vector.size(), 4);
60    EXPECT_EQ(other.size(), 3);
61
62    // add an element to the copy
63    other.add(5);
64
65    // make sure the sizes are correct
66    EXPECT_EQ(vector.size(), 4);
67    EXPECT_EQ(other.size(), 4);
68
69    // make sure the content of both vectors are correct
70    EXPECT_EQ(vector[3], 4);
71    EXPECT_EQ(other[3], 5);
72}
73
74
75} // namespace android
76