本文整理汇总了C++中Autowired::IsAutowired方法的典型用法代码示例。如果您正苦于以下问题:C++ Autowired::IsAutowired方法的具体用法?C++ Autowired::IsAutowired怎么用?C++ Autowired::IsAutowired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autowired
的用法示例。
在下文中一共展示了Autowired::IsAutowired方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: injector
TEST_F(AutoInjectableTest, VerifyCombinedInjection) {
auto injector = MakeInjectable<StealsConstructorArgument>("Hello") + MakeInjectable<SimpleObject>();
injector();
Autowired<StealsConstructorArgument> myobj;
Autowired<SimpleObject> mySimpleObj;
ASSERT_TRUE(myobj.IsAutowired()) << "Combined injectable failed to introduce a single-arguments constructed item into the context";
ASSERT_EQ("Hello", myobj->myVal) << "Combined injectable failed to copy an rvalue argument properly";
ASSERT_TRUE(mySimpleObj.IsAutowired()) << "Combined injectable failed to introduce a zero-arguments constructed item into the context";
}
示例2:
TEST_F(AutoInjectableTest, VerifyInjectableAdditionPermutation2) {
auto injector = MakeInjectable<StealsConstructorArgument>("Hello");
auto injector2 = MakeInjectable<SimpleObject>() + injector;
injector2();
Autowired<StealsConstructorArgument> myStealObj;
Autowired<SimpleObject> mySimpleObj;
ASSERT_TRUE(myStealObj.IsAutowired()) << "Combined injectable failed to introduce a single-argument constructed item";
ASSERT_EQ("Hello", myStealObj->myVal) << "Combined injectable failed to copy an rvalue argument";
ASSERT_TRUE(mySimpleObj.IsAutowired()) << "Combined injectable failed to introduce a zero-arguments constructed";
}
示例3: OnTestEnd
void AutowiringEnclosure::OnTestEnd(const testing::TestInfo& info) {
// Verify we can grab the test case back out and that the pointer is correct:
Autowired<TestInfoProxy> ti;
Autowired<AutowiringEnclosureExceptionFilter> ecef;
auto ctxt = ecef ? ecef->GetContext() : nullptr;
// Unconditionally reset the global context as the current context
AutoGlobalContext()->SetCurrent();
// Global initialization tests are special, we don't bother checking closure principle on them:
if(!strcmp("GlobalInitTest", info.test_case_name()))
return;
// Need to make sure we got back our exception filter before continuing:
ASSERT_TRUE(ecef.IsAutowired()) << "Failed to find the enclosed context exception filter; unit test may have incorrectly reset the enclosing context before returning";
// Now try to tear down the test context enclosure:
ctxt->SignalShutdown();
// Do not allow teardown to take more than 250 milliseconds or so
if(!ctxt->Wait(std::chrono::milliseconds(250))) {
// Critical error--took too long to tear down
assert(false);
}
static const char s_autothrow[] = "AUTOTHROW_";
if(!strncmp(s_autothrow, info.name(), ARRAYCOUNT(s_autothrow) - 1))
// Throw expected, end here
return;
// If an exception occurred somewhere, report it:
ASSERT_FALSE(ecef->m_excepted)
<< "An unhandled exception occurred in this context" << std::endl
<< "[" << (ecef->m_ti ? ecef->m_ti->name() : "unknown") << "] " << ecef->m_what;
}
示例4: AutoCurrentContext
TEST_F(AutoInjectableTest, VerifySimpleThreadWait) {
// Immediate kickoff:
AutoCurrentContext()->Initiate();
// Make an injectable, run it, and stuff it right into a future:
AutoFuture future;
MakeInjectable<CoreThread>()(&future);
// Make a thread and then start it going:
Autowired<CoreThread> thread;
ASSERT_TRUE(thread.IsAutowired()) << "Thread was not injected by an injector as expected";
AutoRequired<std::mutex> barr;
{
std::lock_guard<std::mutex> lk(*barr);
// Add a lambda that we intentionally block:
*thread += [] {
Autowired<CoreThread> thread;
Autowired<std::mutex> barr;
ASSERT_TRUE(thread && barr) << "Failed to find a required type in the current context";
std::lock_guard<std::mutex> lk(*barr);
thread->Stop();
};
// Instant wait:
ASSERT_FALSE(future.WaitFor(std::chrono::nanoseconds(1))) << "Premature wait return on an injector-provided future";
}
// Now that the thread is unblocked, verify that it quits:
ASSERT_TRUE(future.WaitFor(std::chrono::seconds(5))) << "Wait failed to return on an injector-provided future";
}
示例5:
TEST_F(CoreContextTest, CoreContextAdd) {
auto myClass = std::make_shared<CoreContextAddTestClass>();
AutoCurrentContext ctxt;
ctxt->Add(myClass);
Autowired<CoreContextAddTestClass> mc;
ASSERT_TRUE(mc.IsAutowired()) << "Manually registered interface was not detected as expected";
}
示例6: pshr
TEST_F(MultiInheritTest, VerifyCast) {
// Create a dummy context and make it current:
AutoCreateContext ctxt;
CurrentContextPusher pshr(ctxt);
// Insert a MultiInherit object:
auto obj = ctxt->Inject<MultiInherit>();
// Autowire in the pObj:
Autowired<MultiInherit> wiredPobj;
ASSERT_TRUE(wiredPobj.IsAutowired()) << "Autowiring failed for a multi-inheritance object";
// Verify that we get a pObj back with correct casting:
ASSERT_EQ(obj.get(), wiredPobj.get()) << "Autowiring failed on a multiple inheritance object";
}
示例7:
TEST_F(PostConstructTest, VerifySmartBehavior) {
AutoCurrentContext ctxt;
// Add the smart class, which has a member that autowired type A
ctxt->Inject<Smarter>();
// Check that we can get the item we just injected
Autowired<Smarter> smarter;
ASSERT_TRUE(smarter.IsAutowired()) << "Slot was not satisfied as expected";
ASSERT_EQ(1, smarter->value) << "Unexpected initial value of SmarterA instance";
// Now inject A, and see if delayed autowiring has taken place:
ctxt->Inject<A>();
ASSERT_FALSE(!smarter->m_a.get()) << "Autowired member was not wired as expected";
// Verify the value was updated by the notification routine
ASSERT_EQ(2, smarter->value) << "Post-construction notification routine wasn't invoked as expected";
}