Ram Gandikota / Mbed OS ABCD
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers test_m2mtlvserializer.cpp Source File

test_m2mtlvserializer.cpp

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "CppUTest/TestHarness.h"
00017 #include "test_m2mtlvserializer.h"
00018 #include "m2mobject_stub.h"
00019 #include "m2mobjectinstance_stub.h"
00020 #include "m2mresource_stub.h"
00021 #include "m2mresourceinstance_stub.h"
00022 #include "m2mbase_stub.h"
00023 
00024 
00025 Test_M2MTLVSerializer::Test_M2MTLVSerializer()
00026 {
00027     serializer = new M2MTLVSerializer();
00028 }
00029 
00030 Test_M2MTLVSerializer::~Test_M2MTLVSerializer()
00031 {
00032     delete serializer;
00033 }
00034 
00035 void Test_M2MTLVSerializer::test_serialize_object()
00036 {
00037     uint32_t size = 0;
00038     uint8_t *data = 0;
00039 
00040     M2MObject *object = new M2MObject("1", "1");
00041     M2MObjectInstance* instance = new M2MObjectInstance(*object,"1", "type", "1");
00042 
00043     m2mobject_stub::instance_list.push_back(instance);
00044 
00045 
00046 
00047     M2MResource* resource = new M2MResource(*instance,
00048                                             "1",
00049                                             "type",
00050                                             M2MResourceInstance::INTEGER,
00051                                             false,
00052                                             "1");
00053 
00054 
00055     m2mobjectinstance_stub::resource_list.push_back(resource);
00056 
00057     m2mbase_stub::name_id_value = 0;
00058     data = serializer->serialize( m2mobject_stub::instance_list,size);
00059     CHECK(data != NULL);
00060 
00061     if(data) {
00062         free(data);
00063         data = 0;
00064     }
00065 
00066     M2MResourceInstance* res_instance =  new M2MResourceInstance(*m2mobjectinstance_stub::resource,
00067                                                                  "1",
00068                                                                  "type",
00069                                                                  M2MResourceInstance::STRING,
00070                                                                  0,
00071                                                                  "1",
00072                                                                  false);
00073 
00074     M2MResourceInstance* res_instance_1 =  new M2MResourceInstance(*m2mobjectinstance_stub::resource,
00075                                                                    "2",
00076                                                                    "type",
00077                                                                    M2MResourceInstance::STRING,
00078                                                                    0,
00079                                                                    "2",
00080                                                                    false);
00081 
00082 
00083     m2mresource_stub::bool_value = true;
00084     m2mresource_stub::list.push_back(res_instance);
00085     m2mresource_stub::list.push_back(res_instance_1);
00086     data = serializer->serialize( m2mobject_stub::instance_list,size);
00087     CHECK(data != NULL);
00088 
00089     if(data) {
00090         free(data);
00091         data = 0;
00092     }
00093 
00094     m2mbase_stub::name_id_value = 256;
00095 
00096     m2mresourceinstance_stub::int_value = 6;
00097     m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
00098     data = serializer->serialize( m2mobject_stub::instance_list,size);
00099     CHECK(data != NULL);
00100 
00101     if(data) {
00102         free(data);
00103         data = 0;
00104     }
00105     free(m2mresourceinstance_stub::value);
00106     m2mresourceinstance_stub::value = NULL;
00107 
00108     m2mresourceinstance_stub::int_value = 256;
00109     m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
00110     data = serializer->serialize( m2mobject_stub::instance_list,size);
00111     CHECK(data != NULL);
00112 
00113     if(data) {
00114         free(data);
00115         data = 0;
00116     }
00117     free(m2mresourceinstance_stub::value);
00118     m2mresourceinstance_stub::value = NULL;
00119 
00120     m2mresourceinstance_stub::int_value = 65536;
00121     m2mresourceinstance_stub::value = (uint8_t*) malloc(m2mresourceinstance_stub::int_value);
00122     data = serializer->serialize( m2mobject_stub::instance_list,size);
00123     CHECK(data != NULL);
00124 
00125     if(data) {
00126         free(data);
00127         data = 0;
00128     }
00129 
00130     m2mbase_stub::name_id_value = -1;
00131     data = serializer->serialize( m2mobject_stub::instance_list,size);
00132     CHECK(data == NULL);
00133 
00134     delete res_instance_1;
00135     delete res_instance;
00136     delete resource;
00137     delete instance;
00138     delete object;
00139 
00140     free(m2mresourceinstance_stub::value);
00141 
00142     m2mresourceinstance_stub::clear();
00143     m2mresource_stub::clear();
00144     m2mobjectinstance_stub::clear();
00145     m2mobject_stub::clear();
00146 }
00147 
00148 void Test_M2MTLVSerializer::test_serialize_object_instance()
00149 {
00150     M2MObject *object = new M2MObject("1", "1");
00151     M2MObjectInstance* instance = new M2MObjectInstance(*object,"1","type", "1");
00152 
00153     uint32_t size = 0;
00154     uint8_t *data = 0;
00155     m2mbase_stub::name_id_value = 0;
00156     M2MResource* resource = new M2MResource(*instance,
00157                                             "1",
00158                                             "type",
00159                                             M2MResourceInstance::STRING,
00160                                             false,
00161                                             "1");
00162 
00163     M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
00164                                                                 "1",
00165                                                                 "type",
00166                                                                 M2MResourceInstance::STRING,
00167                                                                 0,
00168                                                                 "1",
00169                                                                 false);
00170 
00171     m2mobjectinstance_stub::resource_list.clear();
00172     m2mobjectinstance_stub::resource_list.push_back(resource);
00173 
00174     m2mresource_stub::bool_value = true;
00175     m2mresource_stub::list.push_back(res_instance);
00176 
00177     m2mbase_stub::operation = M2MBase::GET_ALLOWED;
00178 
00179     data = serializer->serialize( m2mobjectinstance_stub::resource_list,size);
00180     CHECK(data != NULL);
00181 
00182     if(data) {
00183         free(data);
00184         data = NULL;
00185     }
00186 
00187 
00188     m2mbase_stub::name_id_value = -1;
00189     data = serializer->serialize( m2mobject_stub::instance_list,size);
00190     CHECK(data == NULL);
00191 
00192     delete res_instance;
00193     delete resource;
00194     delete instance;
00195     delete object;
00196 
00197     m2mresource_stub::clear();
00198     m2mobjectinstance_stub::clear();
00199     m2mobject_stub::clear();
00200 }
00201 
00202 void Test_M2MTLVSerializer::test_serialize_resource()
00203 {
00204     M2MObject *object = new M2MObject("1","1");
00205     M2MObjectInstance* instance =new M2MObjectInstance(*object,"1","type", "1");
00206 
00207     uint32_t size = 0;
00208     uint8_t *data = 0;
00209     m2mbase_stub::name_id_value = 0;
00210     M2MResource* resource = new M2MResource(*instance,
00211                                             "1",
00212                                             "type",
00213                                             M2MResourceInstance::INTEGER,
00214                                             false,
00215                                             "1");
00216 
00217     M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
00218                                                                 "1",
00219                                                                 "type",
00220                                                                 M2MResourceInstance::INTEGER,
00221                                                                 0,
00222                                                                 "1",
00223                                                                 false);
00224 
00225 
00226     m2mobjectinstance_stub::resource_list.clear();
00227     m2mobjectinstance_stub::resource_list.push_back(resource);
00228 
00229     m2mresource_stub::bool_value = true;
00230     m2mresource_stub::list.push_back(res_instance);
00231 
00232     m2mbase_stub::operation = M2MBase::GET_ALLOWED;
00233 
00234     data = serializer->serialize( resource,size);
00235     CHECK(data != NULL);
00236 
00237     if(data) {
00238         free(data);
00239         data = NULL;
00240     }
00241 
00242     m2mbase_stub::name_id_value = -1;
00243     data = serializer->serialize( m2mobject_stub::instance_list,size);
00244     CHECK(data == NULL);
00245 
00246     delete res_instance;
00247     delete resource;
00248     delete instance;
00249     delete object;
00250 
00251     m2mresource_stub::clear();
00252     m2mobjectinstance_stub::clear();
00253     m2mobject_stub::clear();
00254 }
00255 
00256 void Test_M2MTLVSerializer::test_serialize_resource_instance()
00257 {
00258     M2MObject *object = new M2MObject("1","1");
00259     M2MObjectInstance* instance = new M2MObjectInstance(*object,"1","type", "1");
00260 
00261     uint32_t size = 0;
00262     uint8_t *data = 0;
00263     m2mbase_stub::name_id_value = 0;
00264     M2MResource* resource = new M2MResource(*instance,
00265                                             "1",
00266                                             "type",
00267                                             M2MResourceInstance::INTEGER,
00268                                             false,
00269                                             "1");
00270 
00271     M2MResourceInstance* res_instance = new M2MResourceInstance(*resource,
00272                                                                 "1",
00273                                                                 "type",
00274                                                                 M2MResourceInstance::INTEGER,
00275                                                                 0,
00276                                                                 "1",
00277                                                                 false);
00278 
00279 
00280     m2mobjectinstance_stub::resource_list.clear();
00281     m2mobjectinstance_stub::resource_list.push_back(resource);
00282 
00283     m2mresource_stub::bool_value = true;
00284     m2mresource_stub::list.push_back(res_instance);
00285 
00286     m2mbase_stub::operation = M2MBase::GET_ALLOWED;
00287 
00288     data = serializer->serialize( m2mobjectinstance_stub::resource_list,size);
00289     CHECK(data != NULL);
00290 
00291     if(data) {
00292         free(data);
00293         data = NULL;
00294     }
00295 
00296 
00297     m2mbase_stub::name_id_value = -1;
00298     data = serializer->serialize( m2mobject_stub::instance_list,size);
00299     CHECK(data == NULL);
00300 
00301     delete res_instance;
00302     delete resource;
00303     delete instance;
00304     delete object;
00305 
00306     m2mresource_stub::clear();
00307     m2mobjectinstance_stub::clear();
00308     m2mobject_stub::clear();
00309 }