Commit 5ca76eb5 authored by towhid's avatar towhid Committed by Uze Choi

Added unit TC for messaging and coap

Added more unit TC to improve coverage report

Change-Id: Ib05e8976208af8aab4d7097fa2abca80da8ac455
Signed-off-by: default avatartowhid <t.islam@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/26351Tested-by: default avatarIoTivity Jenkins <jenkins-daemon@iotivity.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent cd6faeb6
/******************************************************************
*
* Copyright 2018 Samsung Electronics All Rights Reserved.
*
*
*
* 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 <cstdlib>
#include <string>
#include <gtest/gtest.h>
extern "C" {
#include "oc_api.h"
#include "port/oc_clock.h"
}
#define RESOURCE_URI "/LightResourceURI"
#define RESOURCE_TYPE "oic.r.light"
#define RESOURCE_COLLECTION_NAME_ROOM "roomlights"
#define RESOURCE_COLLECTION_TYPE_LIGHT "/lights"
#define RESOURCE_COLLECTION_RELATION "room"
class TestCollectionRequest: public testing::Test
{
public:
static oc_resource_t *s_pResource;
static oc_resource_t *s_pCol;
static oc_link_t *s_pLink;
protected:
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
oc_resource_t *TestCollectionRequest::s_pResource = nullptr;
oc_resource_t *TestCollectionRequest::s_pCol = nullptr;
oc_link_t *TestCollectionRequest::s_pLink = nullptr;
TEST_F(TestCollectionRequest, AddCollectionTest_P)
{
s_pCol = oc_new_collection(RESOURCE_COLLECTION_NAME_ROOM,
RESOURCE_COLLECTION_TYPE_LIGHT, 1, 0);
EXPECT_TRUE(TestCollectionRequest::s_pCol != NULL) << "Failed to make new collection";
}
TEST_F(TestCollectionRequest, DeleteCollectionTest_P)
{
oc_delete_collection(TestCollectionRequest::s_pCol);
}
TEST_F(TestCollectionRequest, AddLinkTest_P)
{
s_pResource = oc_new_resource(NULL, RESOURCE_URI, 1, 0);
oc_resource_bind_resource_type(s_pResource, RESOURCE_TYPE);
oc_resource_bind_resource_interface(s_pResource, OC_IF_RW);
oc_resource_set_default_interface(s_pResource, OC_IF_RW);
oc_resource_set_discoverable(s_pResource, true);
oc_resource_set_periodic_observable(s_pResource, 1);
oc_process_baseline_interface(s_pResource);
oc_add_resource(s_pResource);
s_pLink = oc_new_link(s_pResource);
EXPECT_TRUE(s_pLink != NULL) << "Failed to make new link";
}
TEST_F(TestCollectionRequest, DeleteLinkTest_P)
{
oc_delete_link(s_pLink);
}
TEST_F(TestCollectionRequest, AddLinkRelationTest_P)
{
s_pLink = oc_new_link(s_pResource);
oc_link_add_rel(s_pLink, RESOURCE_COLLECTION_RELATION);
}
TEST_F(TestCollectionRequest, SetLinkInstanceTest_P)
{
oc_link_set_ins(s_pLink, RESOURCE_COLLECTION_RELATION);
}
TEST_F(TestCollectionRequest, AddCollectionLinkTest_P)
{
s_pCol = oc_new_collection(RESOURCE_COLLECTION_NAME_ROOM,
RESOURCE_COLLECTION_TYPE_LIGHT, 1, 0);
oc_resource_set_discoverable(s_pCol, true);
s_pLink = oc_new_link(s_pResource);
oc_collection_add_link(s_pCol, s_pLink);
}
TEST_F(TestCollectionRequest, RemoveCollectionLinkTest_P)
{
oc_collection_remove_link(s_pCol, s_pLink);
oc_delete_link(s_pLink);
oc_delete_collection(TestCollectionRequest::s_pCol);
}
TEST_F(TestCollectionRequest, GetCollectionFromLinkTest_P)
{
s_pCol = oc_new_collection(RESOURCE_COLLECTION_NAME_ROOM,
RESOURCE_COLLECTION_TYPE_LIGHT, 1, 0);
s_pLink = oc_new_link(s_pResource);
oc_collection_add_link(s_pCol, s_pLink);
oc_link_t *link = oc_collection_get_links(s_pCol);
EXPECT_TRUE(link != NULL) << "Failed to get collection links ";
}
#include <cstdlib>
#include "gtest/gtest.h"
extern "C" {
#include "coap.h"
#include "oc_api.h"
#include "oc_endpoint.h"
}
class TestCoap: public testing::Test
{
protected:
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
TEST_F(TestCoap, CoapGetMidTest_P)
{
uint16_t mid = coap_get_mid();
EXPECT_TRUE(mid) << "Failed to get mid transaction";
}
TEST_F(TestCoap, CoapUDPInitMessageTest_P)
{
coap_packet_t ack[1];
uint16_t mid = coap_get_mid();
coap_udp_init_message(ack, COAP_TYPE_ACK, 0, mid);
}
TEST_F(TestCoap, CoapSerializeMessageTest_P)
{
coap_packet_t ack[1];
uint16_t mid = coap_get_mid();
coap_udp_init_message(ack, COAP_TYPE_ACK, 0, mid);
oc_message_t *message = oc_internal_allocate_outgoing_message();
size_t size = coap_serialize_message(ack, message->data);
EXPECT_TRUE(size) << "Failed to get mid transaction";
}
#include <cstdlib>
#include "gtest/gtest.h"
extern "C" {
#include "engine.h"
#include "oc_api.h"
#include "oc_endpoint.h"
#include "oc_signal_event_loop.h"
#define delete pseudo_delete
#include "oc_core_res.h"
#undef delete
}
class TestEngine: public testing::Test
{
protected:
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
TEST_F(TestEngine, CoapInitEngineTest_P)
{
coap_init_engine();
}
TEST_F(TestEngine, CoapReceiveTest_P)
{
coap_init_engine();
oc_message_t *message = oc_internal_allocate_outgoing_message();
coap_receive(message);
}
#include <cstdlib>
#include "gtest/gtest.h"
extern "C" {
#include "observe.h"
#include "oc_api.h"
#include "oc_endpoint.h"
}
class TestObserve: public testing::Test
{
protected:
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
TEST_F(TestObserve, CreateTransactionTest_P)
{
oc_endpoint_t *endpoint = oc_new_endpoint();
int ret = coap_remove_observer_by_client(endpoint);
EXPECT_TRUE(ret == 0) << "Failed to remove observer";
}
TEST_F(TestObserve, RemoveObserverByTokenTest_P)
{
oc_endpoint_t *endpoint = oc_new_endpoint();
int ret = coap_remove_observer_by_token(endpoint, 1234, 3);
EXPECT_TRUE(ret == 0) << "Failed to remove observer by token";
}
TEST_F(TestObserve, RemoveObserverByMidTest_P)
{
oc_endpoint_t *endpoint = oc_new_endpoint();
int mid = coap_get_mid();
int ret = coap_remove_observer_by_mid(endpoint, mid);
EXPECT_TRUE(ret == 0) << "Failed to remove observer by mid";
}
TEST_F(TestObserve, FreeAllObserverTest_P)
{
coap_free_all_observers();
}
#include <cstdlib>
#include "gtest/gtest.h"
extern "C" {
#include "separate.h"
#include "oc_api.h"
}
class TestCoapPacketSeparate: public testing::Test
{
protected:
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
TEST_F(TestCoapPacketSeparate, CoapSeparateClearTest_P)
{
coap_packet_t response[1];
coap_separate_t separate_store;
int mid = coap_get_mid();
coap_separate_resume( response, &separate_store, OC_STATUS_OK, mid );
}
TEST_F(TestCoapPacketSeparate, CoapSeparateResumeTest_P)
{
coap_packet_t response[1];
coap_separate_t separate_store;
int mid = coap_get_mid();
coap_separate_resume( response, &separate_store, OC_STATUS_OK, mid);
}
......@@ -22,15 +22,16 @@
#include "gtest/gtest.h"
extern "C" {
#include "transactions.h"
#include "oc_api.h"
#include "oc_endpoint.h"
#include "oc_signal_event_loop.h"
#define delete pseudo_delete
#include "oc_core_res.h"
#undef delete
#include "transactions.h"
#include "oc_api.h"
#include "oc_endpoint.h"
#include "oc_signal_event_loop.h"
#define delete pseudo_delete
#include "oc_core_res.h"
#undef delete
}
#define MAX_WAIT_TIME 10
#define RESOURCE_URI "/LightResourceURI"
#define DEVICE_URI "/oic/d"
......@@ -52,7 +53,7 @@ class TestCoapTransaction: public testing::Test
oc_core_init();
oc_init_platform(MANUFACTURER_NAME, NULL, NULL);
oc_add_device(DEVICE_URI, DEVICE_TYPE, DEVICE_NAME,
OCF_SPEC_VERSION, OCF_DATA_MODEL_VERSION, NULL, NULL);
OCF_SPEC_VERSION, OCF_DATA_MODEL_VERSION, NULL, NULL);
}
virtual void TearDown()
......@@ -67,7 +68,7 @@ class TestCoapTransaction: public testing::Test
TEST_F(TestCoapTransaction, CreateTransactionTest_P)
{
oc_endpoint_t *endpoint = oc_new_endpoint();
uint16_t mid = 1234;
uint16_t mid = coap_get_mid();;
coap_transaction_t *transaction = NULL;
transaction = coap_new_transaction(mid, endpoint);
EXPECT_TRUE(NULL != transaction) << "Failed to create transaction";
......@@ -77,8 +78,20 @@ TEST_F(TestCoapTransaction, GetTransactionTest_P)
{
oc_endpoint_t *endpoint = oc_new_endpoint();
uint16_t mid = 12345;
uint16_t mid = coap_get_mid();;
coap_transaction_t *transaction = coap_new_transaction(mid, endpoint);
coap_transaction_t *retrievedTransaction = coap_get_transaction_by_mid(mid);
EXPECT_EQ(retrievedTransaction, transaction) << "Failed to get transaction";
}
\ No newline at end of file
}
TEST_F(TestCoapTransaction, CheckTransactionTest_P)
{
coap_check_transactions();
}
TEST_F(TestCoapTransaction, FreeAllTransactionTest_P)
{
coap_free_all_transactions();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment