#include <string>
#include <map>
+static char gLongHostAddress[] = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111:5000";
+
namespace OCResourceTest
{
using namespace OC;
//Helper method
OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
{
- OCConnectivityType connectivityType = OC_WIFI;
+ OCConnectivityType connectivityType = CT_DEFAULT;
std::vector<std::string> types = {"intel.rpost"};
std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
- return OCPlatform::constructResourceObject(host, uri,
+ auto ret = OCPlatform::constructResourceObject(host, uri,
connectivityType, false, types, ifaces);
+
+ if(!ret)
+ {
+ ADD_FAILURE() << "ConstructResourceObject result was null";
+ throw std::runtime_error("ConstructResourceObject result was null");
+ }
+
+ return ret;
+ }
+
+ //ConstructResourceObject Test
+ TEST(ConstructResourceTest, ConstructResourceObjectWithValidHost)
+ {
+ EXPECT_NO_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectWithValidHost2)
+ {
+ EXPECT_NO_THROW(ConstructResourceObject("coap://[ffff::ffff]:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectWithValidHost3)
+ {
+ EXPECT_NO_THROW(ConstructResourceObject("coap://[ffff::ffff%25eth0]:5000", "/resource"));
}
- //Get Test
TEST(ConstructResourceTest, ConstructResourceObject)
{
EXPECT_ANY_THROW(ConstructResourceObject(std::string(""), std::string("")));
}
+ TEST(ConstructResourceTest, ConstructResourceObjectWithoutCoapScheme)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("//192.168.1.2:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectWithoutPortNumber)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectWithoutPortNumber2)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectWithLongHostAddress)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject(gLongHostAddress, "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("192.168.1.2:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost2)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost3)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://[ffff:::ffff]:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost4)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://[ffff::ffff%eth0]:5000", "/resource"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectInvalidUri)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "/"));
+ }
+
+ TEST(ConstructResourceTest, ConstructResourceObjectInvalidUri2)
+ {
+ EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "resource"));
+ }
+
+ //Get Test
TEST(ResourceGetTest, DISABLED_ResourceGetForValidUri)
{
OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
OCRepresentation rep;
EXPECT_ANY_THROW(
resource->put(nullptr, DEFAULT_INTERFACE, rep, QueryParamsMap(), &onGetPut));
- HeaderOptions headerOptions = {};
+ HeaderOptions headerOptions;
onGetPut(headerOptions, rep, OC_STACK_OK);
}
EXPECT_TRUE(resource->host() == "coap://192.168.1.2:5000");
}
+ TEST(HostTest, Host2)
+ {
+ OCResource::Ptr resource = ConstructResourceObject("coap://[ffff::ffff%25eth0]:5000", "/resource");
+ EXPECT_TRUE(resource != NULL);
+ EXPECT_TRUE(resource->host() == "coap://[ffff::ffff%25eth0]:5000");
+ }
+
//Uri Test
TEST(UriTest, Uri)
{
{
OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
EXPECT_TRUE(resource != NULL);
- EXPECT_TRUE(resource->connectivityType() == OC_WIFI);
+ EXPECT_TRUE(resource->connectivityType() == CT_DEFAULT);
}
//IsObservable Test
{
OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
EXPECT_TRUE(resource != NULL);
- EXPECT_TRUE(resource->sid() == "0");
+ EXPECT_TRUE(resource->sid() == "");
}
//UniqueIdentifier Test
EXPECT_TRUE(resource != NULL);
std::ostringstream ss;
ss << resource->uniqueIdentifier();
- EXPECT_TRUE(ss.str() == "0/resource");
+ EXPECT_TRUE(ss.str() == "/resource");
}
// HeaderOptions Test
{
OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
EXPECT_TRUE(resource != NULL);
- HeaderOptions headerOptions = {};
+ HeaderOptions headerOptions;
EXPECT_NO_THROW(resource->setHeaderOptions(headerOptions));
EXPECT_NO_THROW(resource->unsetHeaderOptions());
}