X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FSingletonVaultCTest.cpp;fp=folly%2Ftest%2FSingletonVaultCTest.cpp;h=1182278e1e28138b34e70acd3e1c1cc80e829991;hb=d58181e677965b609be89b49ed7fbc4e78bf70b5;hp=0000000000000000000000000000000000000000;hpb=124877d36e116d624542155f9d463c76ab80cfe5;p=folly.git diff --git a/folly/test/SingletonVaultCTest.cpp b/folly/test/SingletonVaultCTest.cpp new file mode 100644 index 00000000..1182278e --- /dev/null +++ b/folly/test/SingletonVaultCTest.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2015 Facebook, Inc. + * + * 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. + */ + +#include +#include + +#include + +#include + +__thread long instance_counter_instances = 0; + +class InstanceCounter { + public: + InstanceCounter() { + instance_counter_instances++; + } + + ~InstanceCounter() { + instance_counter_instances--; + } +}; + +TEST(SingletonVault, singletonReturnsSingletonInstance) { + SingletonVault_t *c = SingletonVault_singleton(); + auto *cpp = folly::SingletonVault::singleton(); + EXPECT_EQ(c, cpp); +} + +struct TestTag {}; +template +using SingletonTest = folly::Singleton ; + +TEST(SingletonVault, singletonsAreCreatedAndDestroyed) { + auto vault = folly::SingletonVault::singleton(); + SingletonTest counter_singleton; + SingletonVault_registrationComplete((SingletonVault_t*) vault); + InstanceCounter *counter = SingletonTest::get(); + EXPECT_EQ(instance_counter_instances, 1); + SingletonVault_destroyInstances((SingletonVault_t*) vault); + EXPECT_EQ(instance_counter_instances, 0); +}