//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#if defined(__linux__)
+#include <unistd.h>
+#endif
+
#include <string>
#include <map>
#include <vector>
using namespace testing;
using namespace OIC::Service;
+#define MAX_PATH 2048
+
string CONFIG_FILE = "ResourceContainerTestConfig.xml";
+void getCurrentPath(std::string *pPath)
+{
+ char buffer[MAX_PATH];
+
+#if defined(__linux__)
+ char *strPath = NULL;
+ int length = readlink("/proc/self/exe", buffer, MAX_PATH - 1);
+
+ if (length != -1)
+ {
+ buffer[length] = '\0';
+ strPath = strrchr(buffer, '/');
+
+ if (strPath != NULL)
+ *strPath = '\0';
+ }
+#endif
+ pPath->append(buffer);
+}
/*Fake bundle resource class for testing*/
class TestBundleResource: public BundleResource
public:
RCSResourceContainer *m_pResourceContainer;
+ std::string m_strConfigPath;
protected:
void SetUp()
{
TestWithMock::SetUp();
m_pResourceContainer = RCSResourceContainer::getInstance();
+ getCurrentPath(&m_strConfigPath);
+ m_strConfigPath.append("/");
+ m_strConfigPath.append(CONFIG_FILE);
}
};
TEST_F(ResourceContainerTest, BundleRegisteredWhenContainerStartedWithValidConfigFile)
{
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
EXPECT_GT(m_pResourceContainer->listBundles().size(), (unsigned int) 0);
EXPECT_STREQ("oic.bundle.test",
TEST_F(ResourceContainerTest, BundleLoadedWhenContainerStartedWithValidConfigFile)
{
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
EXPECT_GT(m_pResourceContainer->listBundles().size(), (unsigned int) 0);
EXPECT_TRUE(((BundleInfoInternal *)(*m_pResourceContainer->listBundles().begin()))->isLoaded());
TEST_F(ResourceContainerTest, BundleActivatedWhenContainerStartedWithValidConfigFile)
{
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
EXPECT_GT(m_pResourceContainer->listBundles().size(), (unsigned int) 0);
EXPECT_TRUE(
TEST_F(ResourceContainerTest, BundleUnregisteredWhenContainerStopped)
{
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
m_pResourceContainer->stopContainer();
EXPECT_EQ((unsigned int) 0, m_pResourceContainer->listBundles().size());
TEST_F(ResourceContainerTest, BundleStoppedWithStartBundleAPI)
{
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
m_pResourceContainer->stopBundle("oic.bundle.test");
EXPECT_FALSE(
TEST_F(ResourceContainerTest, BundleStartedWithStartBundleAPI)
{
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
m_pResourceContainer->stopBundle("oic.bundle.test");
m_pResourceContainer->startBundle("oic.bundle.test");
std::map<string, string> resourceParams;
resourceParams["resourceType"] = "oic.test";
- m_pResourceContainer->startContainer(CONFIG_FILE);
+ m_pResourceContainer->startContainer(m_strConfigPath);
resources = m_pResourceContainer->listBundleResources("oic.bundle.test");
m_pResourceContainer->addResourceConfig("oic.bundle.test", "/test_resource", resourceParams);
RCSResourceObject *m_pResourceObject;
ResourceContainerBundleAPI *m_pResourceContainer;
TestBundleResource *m_pBundleResource;
+ std::string m_strConfigPath;
protected:
void SetUp()
m_pResourceObject = mocks.Mock<RCSResourceObject>();
m_pResourceContainer = ResourceContainerBundleAPI::getInstance();
+ getCurrentPath(&m_strConfigPath);
+ m_strConfigPath.append("/");
+ m_strConfigPath.append(CONFIG_FILE);
+
m_pBundleResource = new TestBundleResource();
m_pBundleResource->m_bundleId = "oic.bundle.test";
m_pBundleResource->m_uri = "/test_resource";
configInfo bundle;
map< string, string > results;
- ((ResourceContainerImpl *)m_pResourceContainer)->startContainer(CONFIG_FILE);
+ ((ResourceContainerImpl *)m_pResourceContainer)->startContainer(m_strConfigPath);
m_pResourceContainer->getBundleConfiguration("oic.bundle.test", &bundle);
results = *bundle.begin();
vector< resourceInfo > resourceConfig;
resourceInfo result;
- ((ResourceContainerImpl *)m_pResourceContainer)->startContainer(CONFIG_FILE);
+ ((ResourceContainerImpl *)m_pResourceContainer)->startContainer(m_strConfigPath);
m_pResourceContainer->getResourceConfiguration("oic.bundle.test", &resourceConfig);
result = *resourceConfig.begin();
/* Test for Configuration */
TEST(ConfigurationTest, ConfigFileLoadedWithValidPath)
{
- Configuration *config = new Configuration(CONFIG_FILE);
+ std::string strConfigPath;
+ getCurrentPath(&strConfigPath);
+ strConfigPath.append("/");
+ strConfigPath.append(CONFIG_FILE);
+
+ Configuration *config = new Configuration(strConfigPath);
EXPECT_TRUE(config->isLoaded());
}
TEST(ConfigurationTest, BundleConfigurationListParsed)
{
- Configuration *config = new Configuration(CONFIG_FILE);
+ std::string strConfigPath;
+ getCurrentPath(&strConfigPath);
+ strConfigPath.append("/");
+ strConfigPath.append(CONFIG_FILE);
+
+ Configuration *config = new Configuration(strConfigPath);
configInfo bundles;
map< string, string > results;
TEST(ConfigurationTest, BundleConfigurationParsedWithValidBundleId)
{
- Configuration *config = new Configuration(CONFIG_FILE);
+ std::string strConfigPath;
+ getCurrentPath(&strConfigPath);
+ strConfigPath.append("/");
+ strConfigPath.append(CONFIG_FILE);
+
+ Configuration *config = new Configuration(strConfigPath);
configInfo bundle;
map< string, string > results;
TEST(ConfigurationTest, BundleConfigurationNotParsedWithInvalidBundleId)
{
- Configuration *config = new Configuration(CONFIG_FILE);
+ std::string strConfigPath;
+ getCurrentPath(&strConfigPath);
+ strConfigPath.append("/");
+ strConfigPath.append(CONFIG_FILE);
+
+ Configuration *config = new Configuration(strConfigPath);
configInfo bundles;
config->getBundleConfiguration("test", &bundles);
TEST(ConfigurationTest, BundleResourceConfigurationListParsed)
{
- Configuration *config = new Configuration(CONFIG_FILE);
+ std::string strConfigPath;
+ getCurrentPath(&strConfigPath);
+ strConfigPath.append("/");
+ strConfigPath.append(CONFIG_FILE);
+
+ Configuration *config = new Configuration(strConfigPath);
vector< resourceInfo > resourceConfig;
resourceInfo result;
TEST(ConfigurationTest, BundleResourceConfigurationNotParsedWithInvalidBundleId)
{
- Configuration *config = new Configuration(CONFIG_FILE);
+ std::string strConfigPath;
+ getCurrentPath(&strConfigPath);
+ strConfigPath.append("/");
+ strConfigPath.append(CONFIG_FILE);
+
+ Configuration *config = new Configuration(strConfigPath);
configInfo bundles;
vector< resourceInfo > resourceConfig;