1 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
3 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
19 #include "gtest/gtest.h"
21 #include "srmutility.h"
24 //ParseRestQuery Tests
25 TEST(ParseRestQueryTest, ParseRestQueryEmpty)
27 unsigned char query[] = "";
28 OicParseQueryIter_t parseIter = {};
29 ParseQueryIterInit(query, &parseIter);
30 EXPECT_EQ(NULL, GetNextQuery(&parseIter));
33 TEST(ParseRestQueryTest, ParseSingleRestQuery)
35 char attr[10], val[10];
36 unsigned char query[] = "owned=false";
38 OicParseQueryIter_t parseIter = {};
39 ParseQueryIterInit(query, &parseIter);
40 EXPECT_NE((OicParseQueryIter_t *)NULL, GetNextQuery(&parseIter));
42 strncpy(attr, (char *)parseIter.attrPos, parseIter.attrLen);
43 strncpy(val, (char *)parseIter.valPos, parseIter.valLen);
44 attr[parseIter.attrLen] = '\0';
45 val[parseIter.valLen] = '\0';
46 printf("\nAttribute: %s value: %s\n\n", attr, val);
50 TEST(ParseRestQueryTest, ParseRestMultipleQuery)
52 char attr[10], val[10];
53 unsigned char query[] = "oxm=0&owned=true&owner=owner1";
55 OicParseQueryIter_t parseIter = {};
56 ParseQueryIterInit(query, &parseIter);
58 while(GetNextQuery(&parseIter))
60 EXPECT_NE(static_cast<size_t>(0), parseIter.pi.segment_length);
62 strncpy(attr, (char *)parseIter.attrPos, parseIter.attrLen);
63 strncpy(val, (char *)parseIter.valPos, parseIter.valLen);
64 attr[parseIter.attrLen] = '\0';
65 val[parseIter.valLen] = '\0';
66 printf("Attribute: %s value: %s\n", attr, val);