[Bug/Feature] Easy check if the connection is not NULL.
[Cause] N/A
[Solution] N/A
[Verification] Build, install, run tests
Change-Id: I261d0a8485f2e2bb7f2260b24c95efb139433f7b
return mCon;
}
+LibvirtConnection::operator bool() const
+{
+ return mCon != NULL;
+}
+
} // namespace libvirt
} // namespace security_containers
*/
virConnectPtr get();
+ /**
+ * @return connection pointer is not NULL
+ */
+ operator bool() const;
+
private:
virConnectPtr mCon = NULL;
};
return mDom;
}
+LibvirtDomain::operator bool() const
+{
+ return mDom != NULL;
+}
} // namespace libvirt
} // namespace security_containers
*/
virDomainPtr get();
+ /**
+ * @return libvirt domain pointer is not NULL
+ */
+ operator bool() const;
+
private:
LibvirtConnection mCon;
virDomainPtr mDom = NULL;
void ContainerAdmin::start()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
if (isRunning()) {
return;
void ContainerAdmin::stop()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
if (isStopped()) {
return;
void ContainerAdmin::shutdown()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
if (isStopped()) {
return;
void ContainerAdmin::suspend()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
if (isPaused()) {
return;
void ContainerAdmin::resume()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
if (!isPaused()) {
return;
int ContainerAdmin::getState()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
int state;
void ContainerAdmin::setSchedulerParams(std::uint64_t cpuShares, std::uint64_t vcpuPeriod, std::int64_t vcpuQuota)
{
- assert(mDom.get() != NULL);
+ assert(mDom);
int maxParams = 3;
int numParamsBuff = 0;
std::int64_t ContainerAdmin::getSchedulerQuota()
{
- assert(mDom.get() != NULL);
+ assert(mDom);
int numParamsBuff;
std::unique_ptr<char, void(*)(void*)> type(virDomainGetSchedulerType(mDom.get(), &numParamsBuff), free);
const std::string CORRECT_URI_STRING = LIBVIRT_LXC_ADDRESS;
const std::string BUGGY_URI_STRING = "some_random_string";
-BOOST_AUTO_TEST_CASE(ConstructorTest)
-{
- std::unique_ptr<LibvirtConnection> con;
- BOOST_REQUIRE_NO_THROW(con.reset(new LibvirtConnection(CORRECT_URI_STRING)));
-}
-BOOST_AUTO_TEST_CASE(DestructorTest)
+BOOST_AUTO_TEST_CASE(ConstructorDestructorTest)
{
- std::unique_ptr<LibvirtConnection> con(new LibvirtConnection(CORRECT_URI_STRING));
- BOOST_REQUIRE_NO_THROW(con.reset());
+ std::unique_ptr<LibvirtConnection> conPtr;
+ BOOST_REQUIRE_NO_THROW(conPtr.reset(new LibvirtConnection(CORRECT_URI_STRING)));
+ BOOST_REQUIRE_NO_THROW(conPtr.reset());
}
BOOST_AUTO_TEST_CASE(BuggyConfigTest)
{
- std::unique_ptr<LibvirtConnection> con;
- BOOST_REQUIRE_THROW(con.reset(new LibvirtConnection(BUGGY_URI_STRING)), LibvirtOperationException);
+ BOOST_REQUIRE_THROW(LibvirtConnection con(BUGGY_URI_STRING), LibvirtOperationException);
}
BOOST_AUTO_TEST_CASE(ConnectionTest)
{
- std::unique_ptr<LibvirtConnection> con(new LibvirtConnection(CORRECT_URI_STRING));
- BOOST_CHECK(con->get() != NULL);
+ LibvirtConnection con(CORRECT_URI_STRING);
+ BOOST_CHECK(con.get() != NULL);
+}
+
+BOOST_AUTO_TEST_CASE(BoolTest)
+{
+ LibvirtConnection con(CORRECT_URI_STRING);
+ BOOST_CHECK(con);
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace
-BOOST_AUTO_TEST_CASE(ConstructorTest)
+BOOST_AUTO_TEST_CASE(ConstructorDestructorTest)
{
- BOOST_REQUIRE_NO_THROW(LibvirtDomain dom(CORRECT_CONFIG_XML));
-}
-
-BOOST_AUTO_TEST_CASE(DestructorTest)
-{
- std::unique_ptr<LibvirtDomain> dom(new LibvirtDomain(CORRECT_CONFIG_XML));
- BOOST_REQUIRE_NO_THROW(dom.reset());
+ std::unique_ptr<LibvirtDomain> domPtr;
+ BOOST_REQUIRE_NO_THROW(domPtr.reset(new LibvirtDomain(CORRECT_CONFIG_XML)));
+ BOOST_REQUIRE_NO_THROW(domPtr.reset());
}
BOOST_AUTO_TEST_CASE(BuggyConfigTest)
BOOST_AUTO_TEST_CASE(DefinitionTest)
{
- std::unique_ptr<LibvirtDomain> dom(new LibvirtDomain(CORRECT_CONFIG_XML));
- BOOST_CHECK(dom->get() != NULL);
+ LibvirtDomain dom(CORRECT_CONFIG_XML);
+ BOOST_CHECK(dom.get() != NULL);
+}
+
+BOOST_AUTO_TEST_CASE(BoolTest)
+{
+ LibvirtDomain dom(CORRECT_CONFIG_XML);
+ BOOST_CHECK(dom);
}
BOOST_AUTO_TEST_SUITE_END()