Added OCHeaderOption unit tests
authorErich Keane <erich.keane@intel.com>
Thu, 26 Mar 2015 23:24:51 +0000 (16:24 -0700)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Sun, 29 Mar 2015 18:05:46 +0000 (18:05 +0000)
Adding a bunch of unit tests to completely validate the functionality
of OCHeaderOption

Change-Id: I53efd7e92b03a371f4a302e743128572195f1c29
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/586
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
resource/unittests/OCHeaderOptionTest.cpp [new file with mode: 0644]
resource/unittests/SConscript

diff --git a/resource/unittests/OCHeaderOptionTest.cpp b/resource/unittests/OCHeaderOptionTest.cpp
new file mode 100644 (file)
index 0000000..df1a5e3
--- /dev/null
@@ -0,0 +1,82 @@
+//******************************************************************
+//
+// Copyright 2015 Intel Mobile Communications GmbH 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 <algorithm>
+#include <gtest/gtest.h>
+#include <OCHeaderOption.h>
+#include <OCException.h>
+#include <StringConstants.h>
+
+namespace OC
+{
+    namespace test
+    {
+        namespace OCHeaderOptionTests
+        {
+            using namespace OC;
+
+            TEST(OCHeaderOptionTest, ConstructorValidRangeTest)
+            {
+                // Note: this test just assures that none of these
+                // constructors throw an exception
+                for(uint16_t i = HeaderOption::MIN_HEADER_OPTIONID;
+                        i < HeaderOption::MAX_HEADER_OPTIONID;
+                        ++i)
+                {
+                    HeaderOption::OCHeaderOption{i, ""};
+                }
+            }
+
+            TEST(OCHeaderOptionTest, ConstructorTooLowOptionIdTest)
+            {
+                for(uint16_t i = 0; i < HeaderOption::MIN_HEADER_OPTIONID; ++i)
+                {
+                    ASSERT_THROW(
+                            HeaderOption::OCHeaderOption(i,""),
+                            OCException);
+                }
+            }
+
+            TEST(OCHeaderOptionTest, ConstructorTooHighOptionIdTest)
+            {
+                for(uint16_t i = HeaderOption::MAX_HEADER_OPTIONID +1 ; i <UINT16_MAX;++i)
+                {
+                    ASSERT_THROW(
+                            HeaderOption::OCHeaderOption(i,""),
+                            OCException);
+                }
+            }
+
+            TEST(OCHeaderOptionTest, OptionIDTest)
+            {
+                HeaderOption::OCHeaderOption opt {HeaderOption::MIN_HEADER_OPTIONID + 5, ""};
+                EXPECT_EQ(HeaderOption::MIN_HEADER_OPTIONID + 5, opt.getOptionID());
+            }
+
+            TEST(OCHeaderOptionTest, OptionDataTest)
+            {
+                std::string optionData {"134kl5jt iopdfgj;lwe45 puiondj;vlk345t89o sdkl;ag"};
+                HeaderOption::OCHeaderOption opt {HeaderOption::MIN_HEADER_OPTIONID, optionData};
+                EXPECT_EQ(optionData, opt.getOptionData());
+            }
+
+        } //namespace OCHeaderOptionTests
+    } //namespace test
+} //namespace OC
index c7d93c8..63a2ada 100644 (file)
@@ -67,7 +67,8 @@ unittests = unittests_env.Program('unittests', ['ConstructResourceTest.cpp',
                                                 'OCPlatformTest.cpp',
                                                 'OCRepresentationTest.cpp',
                                                 'OCResourceTest.cpp',
-                                                'OCExceptionTest.cpp'])
+                                                'OCExceptionTest.cpp',
+                                                'OCHeaderOptionTest.cpp'])
 
 Alias("unittests", [unittests])