From: YounghyunJoo Date: Mon, 20 Jul 2015 01:20:59 +0000 (+0900) Subject: Update ResourceCache codes for expiry Timer X-Git-Tag: 1.2.0+RC1~1430^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e25b6a3529e558a2b729955e31d8b0125749425;p=platform%2Fupstream%2Fiotivity.git Update ResourceCache codes for expiry Timer - change timerCB return type to void Add resourceCache unittest code files Change-Id: I7ebaf1d7d08febba999687258b021a97ddae6469 Signed-off-by: YounghyunJoo Reviewed-on: https://gerrit.iotivity.org/gerrit/1740 Tested-by: jenkins-iotivity Reviewed-by: Hun-je Yeon Reviewed-by: Uze Choi --- diff --git a/service/resource-manipulation/src/resourceCache/SConscript b/service/resource-manipulation/src/resourceCache/SConscript index 42c88cc..6593940 100644 --- a/service/resource-manipulation/src/resourceCache/SConscript +++ b/service/resource-manipulation/src/resourceCache/SConscript @@ -38,9 +38,11 @@ SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env') resourcecache_env = lib_env.Clone() target_os = env.get('TARGET_OS') + ###################################################################### # Build flags ###################################################################### + resourcecache_env.AppendUnique(CPPPATH = ['include']) resourcecache_env.AppendUnique(CPPPATH = ['../../include']) resourcecache_env.AppendUnique(CPPPATH = ['../common/primitiveResource/include']) @@ -48,6 +50,7 @@ resourcecache_env.AppendUnique(CPPPATH = ['../common/expiryTimer/include']) resourcecache_env.AppendUnique(CPPPATH = ['../common/expiryTimer/src']) resourcecache_env.PrependUnique(LIBS = ['service_common', 'ExpiryTimer', 'oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap']) + if target_os not in ['windows', 'winrt']: resourcecache_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x']) @@ -71,3 +74,6 @@ resourcecache_env.UserInstallTargetLib(resourcecachesdk, 'libResouceCache') # Go to build sample apps #SConscript('SampleApp/SConscript') +# Go to Unit Test +SConscript('unittests/SConscript') + diff --git a/service/resource-manipulation/src/resourceCache/include/CacheTypes.h b/service/resource-manipulation/src/resourceCache/include/CacheTypes.h old mode 100755 new mode 100644 index f5cc29e..f267b71 --- a/service/resource-manipulation/src/resourceCache/include/CacheTypes.h +++ b/service/resource-manipulation/src/resourceCache/include/CacheTypes.h @@ -38,9 +38,9 @@ namespace OIC class DataCache; - #define CACHE_TAG PCF("CACHE") - #define CACHE_DEFAULT_REPORT_MILLITIME 10000 - #define CACHE_DEFAULT_EXPIRED_MILLITIME 15000 +#define CACHE_TAG PCF("CACHE") +#define CACHE_DEFAULT_REPORT_MILLITIME 10000 +#define CACHE_DEFAULT_EXPIRED_MILLITIME 15000 enum class REPORT_FREQUENCY { @@ -70,7 +70,7 @@ namespace OIC typedef int CacheID; typedef std::function, - const ResourceAttributes &)> CacheCB; + const ResourceAttributes &)> CacheCB; typedef std::map> SubscriberInfo; typedef std::pair> SubscriberInfoPair; diff --git a/service/resource-manipulation/src/resourceCache/include/DataCache.h b/service/resource-manipulation/src/resourceCache/include/DataCache.h old mode 100755 new mode 100644 index bd5fbac..873d458 --- a/service/resource-manipulation/src/resourceCache/include/DataCache.h +++ b/service/resource-manipulation/src/resourceCache/include/DataCache.h @@ -34,58 +34,58 @@ namespace OIC { class DataCache { - public: - typedef unsigned int TimerID; - typedef std::function TimerCB; - - public: - DataCache(); - ~DataCache(); - - void initializeDataCache(PrimitiveResourcePtr pResource); - - CacheID addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatTime); - CacheID deleteSubscriber(CacheID id); - - CACHE_STATE getCacheState() const; - const ResourceAttributes getCachedData() const; - const PrimitiveResourcePtr getPrimitiveResource() const; - - void requestGet(); - bool isEmptySubscriber() const; - - private: - // resource instance - PrimitiveResourcePtr sResource; - std::shared_ptr baseHandler; - - // cached data info - ResourceAttributes attributes; - CACHE_STATE state; - - // subscriber info - std::unique_ptr subscriberList; - - ExpiryTimer networkTimer; - ExpiryTimer pollingTimer; - TimerID networkTimeOutHandle; - TimerID pollingHandle; - - ObserveCB pObserveCB; - GetCB pGetCB; - TimerCB pTimerCB; - TimerCB pPollingCB; - - // for requestCB from base - void onObserve(const HeaderOptions& _hos, - const ResponseStatement& _rep, int _result, int _seq); - void onGet(const HeaderOptions& _hos, const ResponseStatement& _rep, int _result); - void *onTimeOut(const unsigned int timerID); - void *onPollingOut(const unsigned int timerID); - - CacheID generateCacheID(); - SubscriberInfoPair findSubscriber(CacheID id); - void notifyObservers(ResourceAttributes Att); + public: + typedef unsigned int TimerID; + typedef std::function TimerCB; + + public: + DataCache(); + ~DataCache(); + + void initializeDataCache(PrimitiveResourcePtr pResource); + + CacheID addSubscriber(CacheCB func, REPORT_FREQUENCY rf, long repeatTime); + CacheID deleteSubscriber(CacheID id); + + CACHE_STATE getCacheState() const; + const ResourceAttributes getCachedData() const; + const PrimitiveResourcePtr getPrimitiveResource() const; + + void requestGet(); + bool isEmptySubscriber() const; + + private: + // resource instance + PrimitiveResourcePtr sResource; + std::shared_ptr baseHandler; + + // cached data info + ResourceAttributes attributes; + CACHE_STATE state; + + // subscriber info + std::unique_ptr subscriberList; + + ExpiryTimer networkTimer; + ExpiryTimer pollingTimer; + TimerID networkTimeOutHandle; + TimerID pollingHandle; + + ObserveCB pObserveCB; + GetCB pGetCB; + TimerCB pTimerCB; + TimerCB pPollingCB; + + // for requestCB from base + void onObserve(const HeaderOptions &_hos, + const ResponseStatement &_rep, int _result, int _seq); + void onGet(const HeaderOptions &_hos, const ResponseStatement &_rep, int _result); + void onTimeOut(const unsigned int timerID); + void onPollingOut(const unsigned int timerID); + + CacheID generateCacheID(); + SubscriberInfoPair findSubscriber(CacheID id); + void notifyObservers(ResourceAttributes Att); }; } // namespace Service } // namespace OIC diff --git a/service/resource-manipulation/src/resourceCache/include/ResourceCacheManager.h b/service/resource-manipulation/src/resourceCache/include/ResourceCacheManager.h old mode 100755 new mode 100644 index b4c5133..c1a14a7 --- a/service/resource-manipulation/src/resourceCache/include/ResourceCacheManager.h +++ b/service/resource-manipulation/src/resourceCache/include/ResourceCacheManager.h @@ -35,47 +35,47 @@ namespace OIC { class ResourceCacheManager { - public: - class InvalidParameterException: public RCSException - { public: - InvalidParameterException(std::string&& what) - : RCSException{ std::move(what) } {} - }; + class InvalidParameterException: public RCSException + { + public: + InvalidParameterException(std::string &&what) + : RCSException { std::move(what) } {} + }; - static ResourceCacheManager * getInstance(); + static ResourceCacheManager *getInstance(); - CacheID requestResourceCache( + CacheID requestResourceCache( PrimitiveResourcePtr pResource, CacheCB func = NULL, REPORT_FREQUENCY rf = REPORT_FREQUENCY::NONE, long time = 0l); - void cancelResourceCache(CacheID id); + void cancelResourceCache(CacheID id); - void updateResourceCache(PrimitiveResourcePtr pResource) const; - void updateResourceCache(CacheID id) const; + void updateResourceCache(PrimitiveResourcePtr pResource) const; + void updateResourceCache(CacheID id) const; - const ResourceAttributes getCachedData(PrimitiveResourcePtr pResource) const; - const ResourceAttributes getCachedData(CacheID id) const; + const ResourceAttributes getCachedData(PrimitiveResourcePtr pResource) const; + const ResourceAttributes getCachedData(CacheID id) const; - CACHE_STATE getResourceCacheState(PrimitiveResourcePtr pResource) const; - CACHE_STATE getResourceCacheState(CacheID id) const; + CACHE_STATE getResourceCacheState(PrimitiveResourcePtr pResource) const; + CACHE_STATE getResourceCacheState(CacheID id) const; - private: - static ResourceCacheManager * s_instance; - static std::mutex s_mutexForCreation; - static std::unique_ptr> s_cacheDataList; - std::map cacheIDmap; + private: + static ResourceCacheManager *s_instance; + static std::mutex s_mutexForCreation; + static std::unique_ptr> s_cacheDataList; + std::map cacheIDmap; - ResourceCacheManager() = default; - ~ResourceCacheManager(); - ResourceCacheManager(const ResourceCacheManager&) = delete; - ResourceCacheManager(ResourceCacheManager&&) = delete; + ResourceCacheManager() = default; + ~ResourceCacheManager(); + ResourceCacheManager(const ResourceCacheManager &) = delete; + ResourceCacheManager(ResourceCacheManager &&) = delete; - ResourceCacheManager& operator=(const ResourceCacheManager&) const = delete; - ResourceCacheManager& operator=(ResourceCacheManager&&) const = delete; + ResourceCacheManager &operator=(const ResourceCacheManager &) const = delete; + ResourceCacheManager &operator=(ResourceCacheManager && ) const = delete; - static void initializeResourceCacheManager(); - DataCachePtr findDataCache(PrimitiveResourcePtr pResource) const; - DataCachePtr findDataCache(CacheID id) const; + static void initializeResourceCacheManager(); + DataCachePtr findDataCache(PrimitiveResourcePtr pResource) const; + DataCachePtr findDataCache(CacheID id) const; }; } // namespace Service } // namespace OIC diff --git a/service/resource-manipulation/src/resourceCache/src/DataCache.cpp b/service/resource-manipulation/src/resourceCache/src/DataCache.cpp old mode 100755 new mode 100644 index cf4147f..9e2df67 --- a/service/resource-manipulation/src/resourceCache/src/DataCache.cpp +++ b/service/resource-manipulation/src/resourceCache/src/DataCache.cpp @@ -47,10 +47,10 @@ namespace OIC pollingHandle = 0; pObserveCB = (ObserveCB)(std::bind(&DataCache::onObserve, this, - std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4)); + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4)); pGetCB = (GetCB)(std::bind(&DataCache::onGet, this, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); pTimerCB = (TimerCB)(std::bind(&DataCache::onTimeOut, this, std::placeholders::_1)); pPollingCB = (TimerCB)(std::bind(&DataCache::onPollingOut, this, std::placeholders::_1)); @@ -61,7 +61,7 @@ namespace OIC state = CACHE_STATE::DESTROYED; sResource->cancelObserve(); - if(subscriberList != nullptr) + if (subscriberList != nullptr) { subscriberList->clear(); subscriberList.release(); @@ -73,7 +73,7 @@ namespace OIC sResource = pResource; sResource->requestGet(pGetCB); - if(sResource->isObservable()) + if (sResource->isObservable()) { sResource->requestObserve(pObserveCB); } @@ -89,10 +89,10 @@ namespace OIC newItem.reportID = generateCacheID(); - if(subscriberList != nullptr) + if (subscriberList != nullptr) { subscriberList->insert( - std::make_pair(newItem.reportID, std::make_pair(newItem, func))); + std::make_pair(newItem.reportID, std::make_pair(newItem, func))); } return newItem.reportID; @@ -103,7 +103,7 @@ namespace OIC CacheID ret = 0; SubscriberInfoPair pair = findSubscriber(id); - if(pair.first != 0) + if (pair.first != 0) { ret = pair.first; subscriberList->erase(pair.first); @@ -116,12 +116,12 @@ namespace OIC { SubscriberInfoPair ret; - for(auto & i : *subscriberList) + for (auto &i : *subscriberList) { - if(i.first == id) + if (i.first == id) { ret = std::make_pair(i.first, std::make_pair((Report_Info)i.second.first, - (CacheCB)i.second.second)); + (CacheCB)i.second.second)); break; } } @@ -131,12 +131,12 @@ namespace OIC const PrimitiveResourcePtr DataCache::getPrimitiveResource() const { - return (sResource!=nullptr)?sResource:nullptr; + return (sResource != nullptr) ? sResource : nullptr; } const ResourceAttributes DataCache::getCachedData() const { - if(state != CACHE_STATE::READY || attributes.empty()) + if (state != CACHE_STATE::READY || attributes.empty()) { return ResourceAttributes(); } @@ -145,15 +145,15 @@ namespace OIC } void DataCache::onObserve( - const HeaderOptions& _hos, const ResponseStatement& _rep, int _result, int _seq) + const HeaderOptions &_hos, const ResponseStatement &_rep, int _result, int _seq) { - if(_result != OC_STACK_OK || _rep.getAttributes().empty()) + if (_result != OC_STACK_OK || _rep.getAttributes().empty()) { return; } - if(state != CACHE_STATE::READY) + if (state != CACHE_STATE::READY) { state = CACHE_STATE::READY; } @@ -164,24 +164,24 @@ namespace OIC notifyObservers(_rep.getAttributes()); } - void DataCache::onGet(const HeaderOptions& _hos, - const ResponseStatement& _rep, int _result) + void DataCache::onGet(const HeaderOptions &_hos, + const ResponseStatement &_rep, int _result) { - if(_result != OC_STACK_OK || _rep.getAttributes().empty()) + if (_result != OC_STACK_OK || _rep.getAttributes().empty()) { return; } - if(state != CACHE_STATE::READY) + if (state != CACHE_STATE::READY) { state = CACHE_STATE::READY; } - if(!sResource->isObservable()) + if (!sResource->isObservable()) { networkTimer.cancelTimer(networkTimeOutHandle); networkTimeOutHandle = networkTimer.postTimer( - CACHE_DEFAULT_EXPIRED_MILLITIME, pTimerCB); + CACHE_DEFAULT_EXPIRED_MILLITIME, pTimerCB); pollingHandle = pollingTimer.postTimer(CACHE_DEFAULT_REPORT_MILLITIME, pPollingCB); } @@ -191,7 +191,7 @@ namespace OIC void DataCache::notifyObservers(ResourceAttributes Att) { - if(attributes == Att) + if (attributes == Att) { return; } @@ -199,9 +199,9 @@ namespace OIC attributes = Att; ResourceAttributes retAtt = Att; - for(auto & i : * subscriberList) + for (auto &i : * subscriberList) { - if(i.second.first.rf == REPORT_FREQUENCY::UPTODATE) + if (i.second.first.rf == REPORT_FREQUENCY::UPTODATE) { i.second.second(this->sResource, retAtt); } @@ -213,18 +213,18 @@ namespace OIC return state; } - void *DataCache::onTimeOut(unsigned int timerID) + void DataCache::onTimeOut(unsigned int timerID) { state = CACHE_STATE::LOST_SIGNAL; - return NULL; + return; } - void *DataCache::onPollingOut(const unsigned int timerID) + void DataCache::onPollingOut(const unsigned int timerID) { - if(sResource != nullptr) + if (sResource != nullptr) { sResource->requestGet(pGetCB); } - return NULL; + return; } CacheID DataCache::generateCacheID() @@ -232,9 +232,9 @@ namespace OIC CacheID retID = 0; srand(time(NULL)); - while(1) + while (1) { - if(findSubscriber(retID).first == 0 && retID != 0) + if (findSubscriber(retID).first == 0 && retID != 0) { break; } @@ -247,7 +247,7 @@ namespace OIC void DataCache::requestGet() { state = CACHE_STATE::UPDATING; - if(sResource != nullptr) + if (sResource != nullptr) { sResource->requestGet(pGetCB); } @@ -255,7 +255,7 @@ namespace OIC bool DataCache::isEmptySubscriber() const { - return (subscriberList!=nullptr)?subscriberList->empty():true; + return (subscriberList != nullptr) ? subscriberList->empty() : true; } } // namespace Service } // namespace OIC diff --git a/service/resource-manipulation/src/resourceCache/src/ResourceCacheManager.cpp b/service/resource-manipulation/src/resourceCache/src/ResourceCacheManager.cpp old mode 100755 new mode 100644 index 706a2a1..32c4782 --- a/service/resource-manipulation/src/resourceCache/src/ResourceCacheManager.cpp +++ b/service/resource-manipulation/src/resourceCache/src/ResourceCacheManager.cpp @@ -24,24 +24,24 @@ namespace OIC { namespace Service { - ResourceCacheManager * ResourceCacheManager::s_instance = NULL; + ResourceCacheManager *ResourceCacheManager::s_instance = NULL; std::mutex ResourceCacheManager::s_mutexForCreation; std::unique_ptr> ResourceCacheManager::s_cacheDataList(nullptr); ResourceCacheManager::~ResourceCacheManager() { - if(s_cacheDataList != nullptr) + if (s_cacheDataList != nullptr) { s_cacheDataList->clear(); } } - ResourceCacheManager * ResourceCacheManager::getInstance() + ResourceCacheManager *ResourceCacheManager::getInstance() { - if(s_instance == nullptr) + if (s_instance == nullptr) { s_mutexForCreation.lock(); - if(s_instance == nullptr) + if (s_instance == nullptr) { s_instance = new ResourceCacheManager(); s_instance->initializeResourceCacheManager(); @@ -52,23 +52,23 @@ namespace OIC } CacheID ResourceCacheManager::requestResourceCache( - PrimitiveResourcePtr pResource, CacheCB func, - REPORT_FREQUENCY rf, long reportTime) + PrimitiveResourcePtr pResource, CacheCB func, + REPORT_FREQUENCY rf, long reportTime) { - if(pResource == nullptr) + if (pResource == nullptr) { - throw InvalidParameterException{"[requestResourceCache] Primitive Resource is invaild"}; + throw InvalidParameterException {"[requestResourceCache] Primitive Resource is invaild"}; } CacheID retID = 0; - if(rf != REPORT_FREQUENCY::NONE) + if (rf != REPORT_FREQUENCY::NONE) { - if(func == NULL || func == nullptr) + if (func == NULL || func == nullptr) { - throw InvalidParameterException{"[requestResourceCache] CacheCB is invaild"}; + throw InvalidParameterException {"[requestResourceCache] CacheCB is invaild"}; } - if(!reportTime) + if (!reportTime) { // default setting reportTime = CACHE_DEFAULT_REPORT_MILLITIME; @@ -76,7 +76,7 @@ namespace OIC } DataCachePtr newHandler = findDataCache(pResource); - if(newHandler == nullptr) + if (newHandler == nullptr) { newHandler.reset(new DataCache()); newHandler->initializeDataCache(pResource); @@ -91,20 +91,20 @@ namespace OIC void ResourceCacheManager::cancelResourceCache(CacheID id) { - if(id == 0 || cacheIDmap.find(id) == cacheIDmap.end()) + if (id == 0 || cacheIDmap.find(id) == cacheIDmap.end()) { - throw InvalidParameterException{"[cancelResourceCache] CacheID is invaild"}; + throw InvalidParameterException {"[cancelResourceCache] CacheID is invaild"}; } DataCachePtr foundCacheHandler = findDataCache(id); - if(foundCacheHandler != nullptr) + if (foundCacheHandler != nullptr) { CacheID retID = foundCacheHandler->deleteSubscriber(id); - if(retID == id) + if (retID == id) { cacheIDmap.erase(id); } - if(foundCacheHandler->isEmptySubscriber()) + if (foundCacheHandler->isEmptySubscriber()) { s_cacheDataList->remove(foundCacheHandler); foundCacheHandler.reset(); @@ -114,14 +114,14 @@ namespace OIC void ResourceCacheManager::updateResourceCache(PrimitiveResourcePtr pResource) const { - if(pResource == nullptr) + if (pResource == nullptr) { throw InvalidParameterException {"[updateResourceCache] Primitive Resource is invaild"}; } DataCachePtr foundCache = findDataCache(pResource); - if(foundCache == nullptr) + if (foundCache == nullptr) { throw InvalidParameterException {"[updateResourceCache] Primitive Resource is invaild"}; @@ -130,60 +130,60 @@ namespace OIC } void ResourceCacheManager::updateResourceCache(CacheID updateId) const { - if(updateId == 0) + if (updateId == 0) { - throw InvalidParameterException{"[getCachedData] CacheID is invaild"}; + throw InvalidParameterException {"[getCachedData] CacheID is invaild"}; } DataCachePtr foundCache = findDataCache(updateId); - if(foundCache == nullptr) + if (foundCache == nullptr) { - throw InvalidParameterException{"[getCachedData] CacheID is invaild"}; + throw InvalidParameterException {"[getCachedData] CacheID is invaild"}; } foundCache->requestGet(); } const ResourceAttributes ResourceCacheManager::getCachedData( - PrimitiveResourcePtr pResource) const + PrimitiveResourcePtr pResource) const { - if(pResource == nullptr) + if (pResource == nullptr) { - throw InvalidParameterException{"[getCachedData] Primitive Resource is invaild"}; + throw InvalidParameterException {"[getCachedData] Primitive Resource is invaild"}; } DataCachePtr handler = findDataCache(pResource); - if(handler == nullptr) + if (handler == nullptr) { - throw InvalidParameterException{"[getCachedData] Primitive Resource is invaild"}; + throw InvalidParameterException {"[getCachedData] Primitive Resource is invaild"}; } return handler->getCachedData(); } const ResourceAttributes ResourceCacheManager::getCachedData(CacheID id) const { - if(id == 0) + if (id == 0) { - throw InvalidParameterException{"[getCachedData] CacheID is invaild"}; + throw InvalidParameterException {"[getCachedData] CacheID is invaild"}; } DataCachePtr handler = findDataCache(id); - if(handler == nullptr) + if (handler == nullptr) { - throw InvalidParameterException{"[getCachedData] CacheID is invaild"}; + throw InvalidParameterException {"[getCachedData] CacheID is invaild"}; } return handler->getCachedData(); } CACHE_STATE ResourceCacheManager::getResourceCacheState( - PrimitiveResourcePtr pResource) const + PrimitiveResourcePtr pResource) const { - if(pResource == nullptr) + if (pResource == nullptr) { - throw InvalidParameterException{"[getResourceCacheState] Primitive Resource is invaild"}; + throw InvalidParameterException {"[getResourceCacheState] Primitive Resource is invaild"}; } DataCachePtr handler = findDataCache(pResource); - if(handler == nullptr) + if (handler == nullptr) { return CACHE_STATE::NONE; } @@ -192,13 +192,13 @@ namespace OIC CACHE_STATE ResourceCacheManager::getResourceCacheState(CacheID id) const { - if(id == 0) + if (id == 0) { - throw InvalidParameterException{"[getResourceCacheState] CacheID is invaild"}; + throw InvalidParameterException {"[getResourceCacheState] CacheID is invaild"}; } DataCachePtr handler = findDataCache(id); - if(handler == nullptr) + if (handler == nullptr) { return CACHE_STATE::NONE; } @@ -207,20 +207,20 @@ namespace OIC void ResourceCacheManager::initializeResourceCacheManager() { - if(s_cacheDataList == nullptr) + if (s_cacheDataList == nullptr) { s_cacheDataList - = std::unique_ptr>(new std::list); + = std::unique_ptr>(new std::list); } } DataCachePtr ResourceCacheManager::findDataCache(PrimitiveResourcePtr pResource) const { DataCachePtr retHandler = nullptr; - for (auto & i : * s_cacheDataList) + for (auto &i : * s_cacheDataList) { - if(i->getPrimitiveResource()->getUri() == pResource->getUri() && - i->getPrimitiveResource()->getHost() == pResource->getHost()) + if (i->getPrimitiveResource()->getUri() == pResource->getUri() && + i->getPrimitiveResource()->getHost() == pResource->getHost()) { retHandler = i; break; @@ -232,9 +232,9 @@ namespace OIC DataCachePtr ResourceCacheManager::findDataCache(CacheID id) const { DataCachePtr retHandler = nullptr; - for(auto it : cacheIDmap) + for (auto it : cacheIDmap) { - if(it.first == id) + if (it.first == id) { retHandler = it.second; break; diff --git a/service/resource-manipulation/src/resourceCache/unittests/DataCacheTest.cpp b/service/resource-manipulation/src/resourceCache/unittests/DataCacheTest.cpp new file mode 100644 index 0000000..9cfc5bc --- /dev/null +++ b/service/resource-manipulation/src/resourceCache/unittests/DataCacheTest.cpp @@ -0,0 +1,256 @@ +#include +#include +#include + +#include "ResourceCacheManager.h" +#include "DataCache.h" +#include "ResourceAttributes.h" +#include "ResponseStatement.h" + +using namespace OIC::Service; + +class DataCacheTest : public ::testing::Test +{ + public: + typedef std::function < + void(const OIC::Service::HeaderOptions &, const OIC::Service::ResponseStatement &, + int) > GetCallback; + + typedef std::function < + void(const OIC::Service::HeaderOptions &, const OIC::Service::ResponseStatement &, int, + int) > ObserveCallback; + public: + MockRepository mocks; + DataCache *cacheHandler; + PrimitiveResource::Ptr pResource; + CacheCB cb; + CacheID id; + + protected: + DataCacheTest() + { + + } + + virtual ~DataCacheTest() noexcept(true) + { + + } + + virtual void SetUp() override + { + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource *) {}); + cacheHandler = new DataCache(); + cb = ([](std::shared_ptr, const ResourceAttributes &)->OCStackResult {return OC_STACK_OK;}); + } + + virtual void TearDown() + { + delete cacheHandler; + } +}; + +TEST_F(DataCacheTest, initializeDataCache_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); +} + +TEST_F(DataCacheTest, initializeDataCache_normalCaseObservable) +{ + + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do( + [](GetCallback callback) + { + OIC::Service::HeaderOptions hos; + + OIC::Service::ResourceAttributes attr; + OIC::Service::ResponseStatement rep(attr); + callback(hos, rep, OC_STACK_OK); + return; + } + ); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.OnCall(pResource.get(), PrimitiveResource::requestObserve).Do( + [](ObserveCallback callback) + { + OIC::Service::HeaderOptions hos; + OIC::Service::ResourceAttributes attr; + OIC::Service::ResponseStatement rep(attr); + int seq; + callback(hos, rep, OC_STACK_OK, seq); + return; + } + ); + mocks.OnCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); +} + +TEST_F(DataCacheTest, initializeDataCache_normalCaseNonObservable) +{ + + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do( + [](GetCallback callback) + { + OIC::Service::HeaderOptions hos; + + OIC::Service::ResourceAttributes attr; + OIC::Service::ResponseStatement rep(attr); + callback(hos, rep, OC_STACK_OK); + return; + } + ); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(false); + mocks.OnCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + sleep(3); +} + +TEST_F(DataCacheTest, initializeDataCache_normalCaseTimeOut) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + sleep(3); +} + +TEST_F(DataCacheTest, addSubscriber_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 1l; + + ASSERT_NE(cacheHandler->addSubscriber(cb, rf, reportTime), 0); +} + +TEST_F(DataCacheTest, deleteSubsciber_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 1l; + + id = cacheHandler->addSubscriber(cb, rf, reportTime); + + ASSERT_NE(cacheHandler->deleteSubscriber(id), 0); +} + +TEST_F(DataCacheTest, getCacheState_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + ASSERT_EQ(cacheHandler->getCacheState(), CACHE_STATE::READY_YET); +} + +TEST_F(DataCacheTest, getCachedData_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + ASSERT_EQ(cacheHandler->getCachedData(), ResourceAttributes()); +} + +TEST_F(DataCacheTest, getPrimitiveResource_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + ASSERT_EQ(cacheHandler->getPrimitiveResource(), pResource); +} + +TEST_F(DataCacheTest, requestGet_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + cacheHandler->requestGet(); +} + +TEST_F(DataCacheTest, isEmptySubscriber_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + ASSERT_EQ(cacheHandler->isEmptySubscriber(), true); +} + +TEST_F(DataCacheTest, requestGet_normalCasetest) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet).Do( + [](GetCallback callback) + { + std::cout << "HelloWorld" << std::endl; + OIC::Service::HeaderOptions hos; + + OIC::Service::ResourceAttributes attr; + //attr = mocks.Mcok< OIC::Service::ResourceAttributes >(); + OIC::Service::ResponseStatement rep(attr); + //rep = mocks.Mock< OIC::Service::ResponseStatement >(attr); + //fakeResource = mocks.Mock< FakeOCResource >(); + //mocks.OnCallFunc(ResourceAttributes::empty()).Return(false); + callback(hos, rep, OC_STACK_OK); + return; + } + ); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + cacheHandler->initializeDataCache(pResource); + + cacheHandler->requestGet(); +} \ No newline at end of file diff --git a/service/resource-manipulation/src/resourceCache/unittests/ResourceCacheTest.cpp b/service/resource-manipulation/src/resourceCache/unittests/ResourceCacheTest.cpp new file mode 100644 index 0000000..7c1208d --- /dev/null +++ b/service/resource-manipulation/src/resourceCache/unittests/ResourceCacheTest.cpp @@ -0,0 +1,296 @@ +#include +#include +#include + +#include "ResourceCacheManager.h" + +using namespace OIC::Service; + + + +class ResourceCacheManagerTest : public ::testing::Test +{ + public: + MockRepository mocks; + ResourceCacheManager *cacheInstance; + PrimitiveResource::Ptr pResource; + CacheCB cb; + CacheID id; + + protected: + ResourceCacheManagerTest() + { + + } + + virtual ~ResourceCacheManagerTest() noexcept(true) + { + + } + + virtual void SetUp() override + { + cacheInstance = ResourceCacheManager::getInstance(); + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource *) {}); + cb = ([](std::shared_ptr, const ResourceAttributes &)->OCStackResult {return OC_STACK_OK;}); + } + + virtual void TearDown() + { + + } +}; + +TEST_F(ResourceCacheManagerTest, requestResourceCache_resourceIsNULL) +{ + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + ASSERT_THROW(cacheInstance->requestResourceCache(NULL, func, rf, reportTime), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, requestResourceCache_cacheCBIsNULL) +{ + + CacheCB func = NULL; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + ASSERT_THROW(cacheInstance->requestResourceCache(pResource, func, rf, reportTime), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, requestResourceCache_reportTimeIsNULL) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + + id = cacheInstance->requestResourceCache(pResource, func, rf); + cacheInstance->cancelResourceCache(id); + + ASSERT_NE(id, 0); + +} + +TEST_F(ResourceCacheManagerTest, requestResourceCache_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + id = cacheInstance->requestResourceCache(pResource, func, rf, reportTime); + cacheInstance->cancelResourceCache(id); + + ASSERT_NE(id, 0); +} + +TEST_F(ResourceCacheManagerTest, cancelResourceCache_cacheIDIsZero) +{ + + ASSERT_THROW(cacheInstance->cancelResourceCache(0), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, cancelResourceCache_normalCase) +{ + + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestGet); + mocks.ExpectCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.ExpectCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.ExpectCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + id = cacheInstance->requestResourceCache(pResource, func, rf, reportTime); + + cacheInstance->cancelResourceCache(id); +} + +TEST_F(ResourceCacheManagerTest, updateResourceCachePrimitiveResource_resourceIsNULL) +{ + + pResource = NULL; + + ASSERT_THROW(cacheInstance->updateResourceCache(pResource), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, updateResourceCachePrimitiveResource_cacheIsNULL) +{ + + ASSERT_THROW(cacheInstance->updateResourceCache(pResource), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, updateResourceCachePrimitiveResource_normalCase) +{ + + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.OnCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.OnCall(pResource.get(), PrimitiveResource::getUri).Return("testUri"); + mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return("testHost"); + mocks.OnCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + id = cacheInstance->requestResourceCache(pResource, func, rf, reportTime); + + cacheInstance->updateResourceCache(pResource); + + cacheInstance->cancelResourceCache(id); +} + +TEST_F(ResourceCacheManagerTest, updateResourceCacheCacheID_cacheIDIsZero) +{ + + ASSERT_THROW(cacheInstance->updateResourceCache(0), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, updateResourceCacheCacheID_cacheIsNULL) +{ + + ASSERT_THROW(cacheInstance->updateResourceCache(id), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, updateResourceCacheCacheID_normalCase) +{ + + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.OnCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.OnCall(pResource.get(), PrimitiveResource::getUri).Return("testUri"); + mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return("testHost"); + mocks.OnCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + id = cacheInstance->requestResourceCache(pResource, func, rf, reportTime); + + cacheInstance->updateResourceCache(id); + + cacheInstance->cancelResourceCache(id); +} + +TEST_F(ResourceCacheManagerTest, getCachedDataPrimitiveResource_resourceIsNULL) +{ + + pResource = NULL; + + ASSERT_THROW(cacheInstance->getCachedData(pResource), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, getCachedDataPrimitiveResource_handlerIsNULL) +{ + + ASSERT_THROW(cacheInstance->getCachedData(pResource), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, getCachedDataCachID_resourceIsNULL) +{ + + ASSERT_THROW(cacheInstance->getCachedData(0), ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, getCachedDataCachID_handlerIsNULL) +{ + + ASSERT_THROW(cacheInstance->getCachedData(id), ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, getResourceCacheStatePrimitiveResource_resourceIsNULL) +{ + + pResource = NULL; + + ASSERT_THROW(cacheInstance->getResourceCacheState(pResource), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, getResourceCacheStatePrimitiveResource_handlerIsNULL) +{ + + ASSERT_EQ(cacheInstance->getResourceCacheState(pResource), CACHE_STATE::NONE); +} + +TEST_F(ResourceCacheManagerTest, getResourceCacheStatePrimitiveResource_normalCase) +{ + + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.OnCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.OnCall(pResource.get(), PrimitiveResource::getUri).Return("testUri"); + mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return("testHost"); + mocks.OnCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + id = cacheInstance->requestResourceCache(pResource, func, rf, reportTime); + CACHE_STATE state = cacheInstance->getResourceCacheState(pResource); + + cacheInstance->cancelResourceCache(id); + + ASSERT_EQ(state, CACHE_STATE::READY_YET); +} + +TEST_F(ResourceCacheManagerTest, getResourceCacheStateCacheID_cacheIDIsZero) +{ + + ASSERT_THROW(cacheInstance->getResourceCacheState(0), + ResourceCacheManager::InvalidParameterException); +} + +TEST_F(ResourceCacheManagerTest, getResourceCacheStateCacheID_handlerIsNULL) +{ + + ASSERT_EQ(cacheInstance->getResourceCacheState(id), CACHE_STATE::NONE); +} + +TEST_F(ResourceCacheManagerTest, getResourceCacheStateCacheID_normalCase) +{ + + mocks.OnCall(pResource.get(), PrimitiveResource::requestGet); + mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(true); + mocks.OnCall(pResource.get(), PrimitiveResource::requestObserve); + mocks.OnCall(pResource.get(), PrimitiveResource::getUri).Return("testUri"); + mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return("testHost"); + mocks.OnCall(pResource.get(), PrimitiveResource::cancelObserve); + + CacheCB func = cb; + REPORT_FREQUENCY rf = REPORT_FREQUENCY::UPTODATE; + long reportTime = 20l; + + id = cacheInstance->requestResourceCache(pResource, func, rf, reportTime); + CACHE_STATE state = cacheInstance->getResourceCacheState(id); + + cacheInstance->cancelResourceCache(id); + + ASSERT_EQ(state, CACHE_STATE::READY_YET); +} \ No newline at end of file diff --git a/service/resource-manipulation/src/resourceCache/unittests/SConscript b/service/resource-manipulation/src/resourceCache/unittests/SConscript new file mode 100644 index 0000000..a7a8933 --- /dev/null +++ b/service/resource-manipulation/src/resourceCache/unittests/SConscript @@ -0,0 +1,81 @@ +#****************************************************************** +# +# Copyright 2015 Samsung Electronics All Rights Reserved. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +## +# ResourceCache Unit Test build script +## + +Import('env') + +if env.get('RELEASE'): + env.AppendUnique(CCFLAGS = ['-Os']) + env.AppendUnique(CPPDEFINES = ['NDEBUG']) +else: + env.AppendUnique(CCFLAGS = ['-g']) + +if env.get('LOGGING'): + env.AppendUnique(CPPDEFINES = ['TB_LOG']) + +lib_env = env.Clone() +SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env') + +######################### unit test setting ########################## +src_dir = lib_env.get('SRC_DIR') +gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0' +###################################################################### + +cache_test_env = lib_env.Clone() + +target_os = env.get('TARGET_OS') + +###################################################################### +# Build flags +###################################################################### +gtest = File(gtest_dir + '/lib/.libs/libgtest.a') +gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a') + +cache_test_env.AppendUnique(CPPPATH = ['../include']) +cache_test_env.AppendUnique(CPPPATH = ['../../../include']) +cache_test_env.AppendUnique(CPPPATH = ['../../common/primitiveResource/include']) +cache_test_env.AppendUnique(CPPPATH = ['../../common/expiryTimer/include']) +cache_test_env.AppendUnique(CPPPATH = ['../../common/expiryTimer/src']) +cache_test_env.PrependUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/hippomocks-master', + gtest_dir + '/include']) +cache_test_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) +cache_test_env.PrependUnique(LIBS = ['ResourceCache', 'service_common', 'ExpiryTimer', 'oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap', gtest, gtest_main]) + + +if target_os not in ['windows', 'winrt']: + cache_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x']) + cache_test_env.AppendUnique(CCFLAGS = ['-Wnoexcept']) + +if target_os == 'linux': + cache_test_env.AppendUnique(LIBS = ['pthread']) + +###################################################################### +# Build Test +###################################################################### + + +cache_test_src = env.Glob('./*.cpp') + +cache_test = cache_test_env.Program('cache_test', cache_test_src) +Alias("cache_test", cache_test) +env.AppendTarget('cache_test')