Home | History | Annotate | Download | only in dicnode
      1 /*
      2  * Copyright (C) 2014 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 "suggest/core/dicnode/dic_node_pool.h"
     18 
     19 #include <gtest/gtest.h>
     20 
     21 namespace latinime {
     22 namespace {
     23 
     24 TEST(DicNodePoolTest, TestGet) {
     25     static const int CAPACITY = 10;
     26     DicNodePool dicNodePool(CAPACITY);
     27 
     28     for (int i = 0; i < CAPACITY; ++i) {
     29         EXPECT_NE(nullptr, dicNodePool.getInstance());
     30     }
     31     EXPECT_EQ(nullptr, dicNodePool.getInstance());
     32 }
     33 
     34 TEST(DicNodePoolTest, TestPlaceBack) {
     35     static const int CAPACITY = 1;
     36     DicNodePool dicNodePool(CAPACITY);
     37 
     38     DicNode *const dicNode = dicNodePool.getInstance();
     39     EXPECT_NE(nullptr, dicNode);
     40     EXPECT_EQ(nullptr, dicNodePool.getInstance());
     41     dicNodePool.placeBackInstance(dicNode);
     42     EXPECT_EQ(dicNode, dicNodePool.getInstance());
     43 }
     44 
     45 TEST(DicNodePoolTest, TestReset) {
     46     static const int CAPACITY_SMALL = 2;
     47     static const int CAPACITY_LARGE = 10;
     48     DicNodePool dicNodePool(CAPACITY_SMALL);
     49 
     50     for (int i = 0; i < CAPACITY_SMALL; ++i) {
     51         EXPECT_NE(nullptr, dicNodePool.getInstance());
     52     }
     53     EXPECT_EQ(nullptr, dicNodePool.getInstance());
     54 
     55     dicNodePool.reset(CAPACITY_LARGE);
     56     for (int i = 0; i < CAPACITY_LARGE; ++i) {
     57         EXPECT_NE(nullptr, dicNodePool.getInstance());
     58     }
     59     EXPECT_EQ(nullptr, dicNodePool.getInstance());
     60 
     61     dicNodePool.reset(CAPACITY_SMALL);
     62     for (int i = 0; i < CAPACITY_SMALL; ++i) {
     63         EXPECT_NE(nullptr, dicNodePool.getInstance());
     64     }
     65     EXPECT_EQ(nullptr, dicNodePool.getInstance());
     66 }
     67 
     68 }  // namespace
     69 }  // namespace latinime
     70