Merge branch 'master' into 'security-basecamp'
[platform/upstream/iotivity.git] / resource / csdk / security / unittest / srmutility.cpp
1 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
2 //
3 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
18
19 #include "gtest/gtest.h"
20 #include "ocstack.h"
21 #include "srmutility.h"
22 #include "oic_string.h"
23
24
25 //ParseRestQuery Tests
26 TEST(ParseRestQueryTest, ParseRestQueryEmpty)
27 {
28     unsigned char query[] = "";
29     OicParseQueryIter_t parseIter = {};
30     ParseQueryIterInit(query, &parseIter);
31     EXPECT_EQ(NULL,  GetNextQuery(&parseIter));
32 }
33
34 TEST(ParseRestQueryTest, ParseSingleRestQuery)
35 {
36     char attr[10], val[10];
37     unsigned char query[] = "owned=false";
38
39     OicParseQueryIter_t parseIter = {};
40     ParseQueryIterInit(query, &parseIter);
41     EXPECT_NE((OicParseQueryIter_t *)NULL,  GetNextQuery(&parseIter));
42
43     OICStrcpyPartial(attr, sizeof(attr), (char *)parseIter.attrPos, parseIter.attrLen);
44     OICStrcpyPartial(val, sizeof(val), (char *)parseIter.valPos, parseIter.valLen);
45     printf("\nAttribute: %s  value: %s\n\n", attr, val);
46
47 }
48
49 TEST(ParseRestQueryTest, ParseRestMultipleQuery)
50 {
51     char attr[10], val[10];
52     unsigned char query[] = "oxm=0&owned=true&owner=owner1";
53
54     OicParseQueryIter_t parseIter = {};
55     ParseQueryIterInit(query, &parseIter);
56     printf("\n");
57     while(GetNextQuery(&parseIter))
58     {
59         EXPECT_NE(static_cast<size_t>(0),  parseIter.pi.segment_length);
60
61         OICStrcpyPartial(attr, sizeof(attr), (char *)parseIter.attrPos, parseIter.attrLen);
62         OICStrcpyPartial(val, sizeof(val), (char *)parseIter.valPos, parseIter.valLen);
63         printf("Attribute: %s  value: %s\n", attr, val);
64
65     }
66     printf("\n");
67 }
68