1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 #include "TaskCaseCommon.h"
18 class TaskSequentialTest : public testing::Test {
19 public:
20     TaskCase* mTestCase;
21     TaskSequential* mSequential;
22 
23 
SetUp()24     virtual void SetUp() {
25         TaskGeneric* setup = NULL;
26         TaskGeneric* action = NULL;
27         mTestCase  = getTaskCase(setup, action);
28         ASSERT_TRUE(mTestCase != NULL);
29         ASSERT_TRUE(setup != NULL);
30         ASSERT_TRUE(action != NULL);
31         mSequential = new TaskSequential();
32         action->addChild(mSequential);
33     }
34 
TearDown()35     virtual void TearDown() {
36         delete mTestCase;
37     }
38 };
39 
40 
TEST_F(TaskSequentialTest,AttributeTest)41 TEST_F(TaskSequentialTest, AttributeTest) {
42     const android::String8 REPEAT("repeat");
43     const android::String8 N_10("10");
44     const android::String8 INDEX("index");
45     const android::String8 I("i");
46     const android::String8 NO_SUCH_THING("no_such_thing");
47     const android::String8 SHOULD_FAIL("should_fail");
48     ASSERT_TRUE(mSequential->parseAttribute(REPEAT, N_10));
49     ASSERT_TRUE(mSequential->parseAttribute(INDEX, I));
50     ASSERT_TRUE(!mSequential->parseAttribute(NO_SUCH_THING, SHOULD_FAIL));
51     mSequential->run();
52     const android::String8 RE(".*");
53     std::list<TaskCase::IndexPair>* indices = mTestCase->findAllIndices(RE);
54     ASSERT_TRUE(indices != NULL);
55     ASSERT_TRUE(indices->size() == 1);
56     int index = -10;
57 
58     ASSERT_TRUE(mTestCase->findIndex(I, index));
59     ASSERT_TRUE(index == 10);
60     delete indices;
61 }
62 
63 
64 
65 
66