Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / resource / unittests / OCHeaderOptionTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include <algorithm>
22 #include <gtest/gtest.h>
23 #include <OCHeaderOption.h>
24 #include <OCException.h>
25 #include <StringConstants.h>
26
27 namespace OC
28 {
29     namespace test
30     {
31         namespace OCHeaderOptionTests
32         {
33             using namespace OC;
34
35             TEST(OCHeaderOptionTest, ConstructorValidRangeTest)
36             {
37                 // Note: this test just assures that none of these
38                 // constructors throw an exception
39                 for(uint16_t i = HeaderOption::MIN_HEADER_OPTIONID;
40                         i < HeaderOption::MAX_HEADER_OPTIONID;
41                         ++i)
42                 {
43                     HeaderOption::OCHeaderOption{i, ""};
44                 }
45             }
46
47             TEST(OCHeaderOptionTest, ConstructorTooLowOptionIdTest)
48             {
49                 for(uint16_t i = 0; i < HeaderOption::MIN_HEADER_OPTIONID; ++i)
50                 {
51                     if (HeaderOption::IF_MATCH_OPTION_ID != i
52                             && HeaderOption::IF_NONE_MATCH_OPTION_ID != i
53                             && HeaderOption::LOCATION_PATH_OPTION_ID != i
54                             && HeaderOption::LOCATION_QUERY_OPTION_ID != i)
55                     {
56                         ASSERT_THROW(
57                                 HeaderOption::OCHeaderOption(i,""),
58                                 OCException);
59                     }
60                 }
61             }
62
63             TEST(OCHeaderOptionTest, ConstructorTooHighOptionIdTest)
64             {
65                 for(uint16_t i = HeaderOption::MAX_HEADER_OPTIONID +1 ; i <UINT16_MAX;++i)
66                 {
67                     ASSERT_THROW(
68                             HeaderOption::OCHeaderOption(i,""),
69                             OCException);
70                 }
71             }
72
73             TEST(OCHeaderOptionTest, OptionIDTest)
74             {
75                 HeaderOption::OCHeaderOption opt {HeaderOption::MIN_HEADER_OPTIONID + 5, ""};
76                 EXPECT_EQ(HeaderOption::MIN_HEADER_OPTIONID + 5, opt.getOptionID());
77             }
78
79             TEST(OCHeaderOptionTest, OptionDataTest)
80             {
81                 std::string optionData {"134kl5jt iopdfgj;lwe45 puiondj;vlk345t89o sdkl;ag"};
82                 HeaderOption::OCHeaderOption opt {HeaderOption::MIN_HEADER_OPTIONID, optionData};
83                 EXPECT_EQ(optionData, opt.getOptionData());
84             }
85
86         } //namespace OCHeaderOptionTests
87     } //namespace test
88 } //namespace OC