1 // Copyright (C) 2011 The Libphonenumber Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Author: Fredrik Roubert 16 17 #include <cstddef> 18 #include <string> 19 20 #include <gtest/gtest.h> 21 22 #include "phonenumbers/base/synchronization/lock.h" 23 #include "phonenumbers/regexp_cache.h" 24 #include "phonenumbers/regexp_factory.h" 25 26 namespace i18n { 27 namespace phonenumbers { 28 29 using std::string; 30 31 class RegExpCacheTest : public testing::Test { 32 protected: 33 static constexpr size_t min_items_ = 2; 34 RegExpCacheTest()35 RegExpCacheTest() : cache_(regexp_factory_, min_items_) {} ~RegExpCacheTest()36 virtual ~RegExpCacheTest() {} 37 38 RegExpFactory regexp_factory_; 39 RegExpCache cache_; 40 }; 41 TEST_F(RegExpCacheTest,CacheConstructor)42TEST_F(RegExpCacheTest, CacheConstructor) { 43 AutoLock l(cache_.lock_); 44 ASSERT_TRUE(cache_.cache_impl_ != NULL); 45 EXPECT_TRUE(cache_.cache_impl_->empty()); 46 } 47 TEST_F(RegExpCacheTest,GetRegExp)48TEST_F(RegExpCacheTest, GetRegExp) { 49 static const string pattern1("foo"); 50 static const string pattern2("foo"); 51 52 const RegExp& regexp1 = cache_.GetRegExp(pattern1); 53 // "foo" has been cached therefore we must get the same object. 54 const RegExp& regexp2 = cache_.GetRegExp(pattern2); 55 56 EXPECT_TRUE(®exp1 == ®exp2); 57 } 58 59 } // namespace phonenumbers 60 } // namespace i18n 61