blob: 0ba7161aaa2d31b4dd187aa7fb6a356192d0f3b1 [file] [log] [blame]
Mathias Agopian03b168a2012-05-17 16:52:21 -07001/*
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
Nick Kralevich3e6c4512015-08-17 18:26:13 -070048 EXPECT_EQ(3U, vector.size());
Mathias Agopian03b168a2012-05-17 16:52:21 -070049
50 // copy the vector
51 other = vector;
52
Nick Kralevich3e6c4512015-08-17 18:26:13 -070053 EXPECT_EQ(3U, other.size());
Mathias Agopian03b168a2012-05-17 16:52:21 -070054
55 // add an element to the first vector
56 vector.add(4);
57
58 // make sure the sizes are correct
Nick Kralevich3e6c4512015-08-17 18:26:13 -070059 EXPECT_EQ(4U, vector.size());
60 EXPECT_EQ(3U, other.size());
Mathias Agopian03b168a2012-05-17 16:52:21 -070061
62 // add an element to the copy
63 other.add(5);
64
65 // make sure the sizes are correct
Nick Kralevich3e6c4512015-08-17 18:26:13 -070066 EXPECT_EQ(4U, vector.size());
67 EXPECT_EQ(4U, other.size());
Mathias Agopian03b168a2012-05-17 16:52:21 -070068
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