EasySetup:Fix for static analyzer reported issues 19/21519/11
authorHarry <h.marappa@samsung.com>
Tue, 4 Jul 2017 13:07:48 +0000 (18:37 +0530)
committerUze Choi <uzchoi@samsung.com>
Tue, 26 Sep 2017 07:06:04 +0000 (07:06 +0000)
Removal of never used methods and catching exceptions by reference.

Change-Id: I10d3c83ce5b14174b6f82a49897738c98a461af7
Signed-off-by: Harry <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21233
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Senthil Kumar G S <senthil.gs@samsung.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
(cherry picked from commit e450d10699a504c90cb37fba3e9a551d93278e25)

service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniEasySetup.cpp
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniEsUtils.cpp
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniRemoteEnrollee.cpp
service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.cpp

index 1f28db9..fcd76c8 100644 (file)
@@ -325,13 +325,13 @@ TEST_F(EasysetupEnrolleeTest, DevicePropertyIsWellConstructedInResponsePayload)
             {
                 EnrolleeConf conf = status->getEnrolleeConf();
                 if(conf.getWiFiModes().size() > 0 && conf.getWiFiModes().at(0) == WIFI_11G &&
-                    conf.getWiFiFreq() == WIFI_5G &&
-                    !strcmp(conf.getDeviceName().c_str(), "Test Device"))
+                    conf.getWiFiFreq() == WIFI_BOTH && conf.getDeviceName() ==  "Test Device")
                 {
                     isWellConstructed = true;
                 }
             }
         });
+
     ESResult ret = startEnrollee();
     ret = setDeviceProperty();
 
@@ -340,7 +340,7 @@ TEST_F(EasysetupEnrolleeTest, DevicePropertyIsWellConstructedInResponsePayload)
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-    EXPECT_EQ(ret, ES_OK);
+    EXPECT_TRUE(isWellConstructed);
 
     ESTerminateEnrollee();
 }
@@ -363,6 +363,7 @@ TEST_F(EasysetupEnrolleeTest, ProvisioningPropertiesIsWellConstructedInResponseP
                 }
             }
         });
+
     ESResult ret = startEnrollee();
     ret = setDeviceProperty();
     ret = ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
@@ -373,7 +374,7 @@ TEST_F(EasysetupEnrolleeTest, ProvisioningPropertiesIsWellConstructedInResponseP
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-    EXPECT_EQ(ret, ES_OK);
+    EXPECT_TRUE(isWellConstructed);
 
     ESTerminateEnrollee();
 }
@@ -455,7 +456,6 @@ TEST_F(EasysetupEnrolleeTest, GetWifiRsrcTest)
     mocks.ExpectCallFunc(onGetWifiRsrc).Do(
         [& isRepFlag](const OCRepresentation& /*rep*/)
         {
-
             isRepFlag = true;
         });
 
@@ -465,7 +465,7 @@ TEST_F(EasysetupEnrolleeTest, GetWifiRsrcTest)
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-    EXPECT_EQ(ret, ES_OK);
+    EXPECT_TRUE(isRepFlag);
 
     ESTerminateEnrollee();
 }
@@ -485,7 +485,7 @@ TEST_F(EasysetupEnrolleeTest, GetCloudRsrcTest)
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-    EXPECT_EQ(ret, ES_OK);
+    EXPECT_TRUE(isRepFlag);
 
     ESTerminateEnrollee();
 }
@@ -507,7 +507,7 @@ TEST_F(EasysetupEnrolleeTest, GetDevConfTest)
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-    EXPECT_EQ(ret, ES_OK);
+    EXPECT_TRUE(isRepFlag);
 
     ESTerminateEnrollee();
 }
@@ -528,7 +528,7 @@ TEST_F(EasysetupEnrolleeTest, PutRequestTest)
     std::unique_lock< std::mutex > lock{ mutexForCondition };
     responseCon.wait_for(lock, g_waitForResponse);
 
-    EXPECT_EQ(ret, ES_OK);
+    EXPECT_TRUE(isRepFlag);
 
     ESTerminateEnrollee();
 }
index 4332919..2b67e7e 100644 (file)
@@ -76,11 +76,11 @@ Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrolle
         JniRemoteEnrollee *jniRemoteEnrollee = new JniRemoteEnrollee(nativeRemoteEnrollee);
         ESSetHandle<JniRemoteEnrollee>(env, jRemoteEnrollee, jniRemoteEnrollee);
     }
-    catch (ESBadRequestException exception)
+    catch (ESBadRequestException &exception)
     {
         ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the Native EnrolleeDevice");
         //throw the exception to java layer
-        throwESException( env,  exception.what());
+        throwESException(env,  exception.what());
     }
 
     ES_LOGI("JniEasySetup::nativeCreateRemoteEnrollee exit");
index 106c18e..14a7f8e 100644 (file)
@@ -31,82 +31,3 @@ void throwESException(JNIEnv *env, std::string reason)
     env->Throw((jthrowable)ex);
 }
 
-OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType)
-{
-    switch (connectivityType)
-    {
-        case CT_DEFAULT:
-            return CT_DEFAULT;
-        case CT_ADAPTER_IP:
-            return CT_ADAPTER_IP;
-
-            //May be need to add more types, if easy setup service support more transport.
-    }
-    return CT_DEFAULT;
-}
-
-WIFI_AUTHTYPE getWifiAuthTypeFromInt(int authType)
-{
-    switch (authType)
-    {
-        case 0:
-            return WIFI_AUTHTYPE::NONE_AUTH;
-        case 1:
-            return WIFI_AUTHTYPE::WEP;
-        case 2:
-            return WIFI_AUTHTYPE::WPA_PSK;
-        case 3:
-            return WIFI_AUTHTYPE::WPA2_PSK;
-    }
-    return NONE_AUTH;
-}
-
-WIFI_ENCTYPE getWifiEncTypeFromInt(int encType)
-{
-    switch (encType)
-    {
-        case 0:
-            return WIFI_ENCTYPE::NONE_ENC;
-        case 1:
-            return WIFI_ENCTYPE::WEP_64;
-        case 2:
-            return WIFI_ENCTYPE::WEP_128;
-        case 3:
-            return WIFI_ENCTYPE::TKIP;
-        case 4:
-            return WIFI_ENCTYPE::AES;
-        case 5:
-            return WIFI_ENCTYPE::TKIP_AES;
-    }
-    return NONE_ENC;
-}
-
-int convertNativeWifiFreqToInt(WIFI_FREQ wifiFreq)
-{
-    switch (wifiFreq)
-    {
-        case WIFI_FREQ::WIFI_24G:
-            return 0;
-        case WIFI_FREQ::WIFI_5G:
-            return 1;
-        case WIFI_FREQ::WIFI_BOTH:
-            return 2;
-    }
-}
-
-int convertNativeWifiModeToInt(WIFI_MODE wifiMode)
-{
-    switch (wifiMode)
-    {
-        case WIFI_MODE::WIFI_11A:
-            return 0;
-        case WIFI_MODE::WIFI_11B:
-            return 1;
-        case WIFI_MODE::WIFI_11G:
-            return 2;
-        case WIFI_MODE::WIFI_11N:
-            return 3;
-        case WIFI_MODE::WIFI_11AC:
-            return 4;
-    }
-}
\ No newline at end of file
index 851aeab..06bbc42 100644 (file)
@@ -68,11 +68,11 @@ void JniRemoteEnrollee::getStatus(JNIEnv *env, jobject jListener)
     {
         m_sharedResource->getStatus(getEnrolleeStatusCallback);
     }
-    catch (ESBadRequestException exception)
+    catch (ESBadRequestException &exception)
     {
         ES_LOGE("JNI getStatus :: Exception occured");
         //throw the exception to java
-        throwESException( env,  exception.what());
+        throwESException(env, exception.what());
     }
 }
 
@@ -91,11 +91,11 @@ void JniRemoteEnrollee::getConfiguration(JNIEnv *env, jobject jListener)
     {
         m_sharedResource->getConfiguration(getConfigurationStatusCallback);
     }
-    catch (ESBadRequestException exception)
+    catch (ESBadRequestException &exception)
     {
         ES_LOGE("JNI getConfiguration :: Exception occured");
         //throw the exception to java
-        throwESException( env,  exception.what());
+        throwESException(env, exception.what());
     }
 }
 
@@ -114,11 +114,11 @@ void JniRemoteEnrollee::provisionSecurity(JNIEnv *env, jobject jListener)
     {
         m_sharedResource->provisionSecurity(secProvStatusCallback);
     }
-    catch (ESBadRequestException exception)
+    catch (ESBadRequestException &exception)
     {
         ES_LOGE("JNI provisionSecurity :: Exception occured");
         //throw the exception to java
-        throwESException( env,  exception.what());
+        throwESException(env, exception.what());
     }
 }
 
@@ -146,11 +146,11 @@ void JniRemoteEnrollee::provisionDeviceProperties(JNIEnv *env,
     {
         m_sharedResource->provisionDeviceProperties(deviceProp, devicePropProvStatusCallback);
     }
-    catch (ESBadRequestException exception)
+    catch (ESBadRequestException &exception)
     {
         ES_LOGE("JNI provisionDeviceProperties :: Exception occured");
         //throw the exception to java
-        throwESException( env,  exception.what());
+        throwESException(env, exception.what());
     }
 }
 
@@ -188,7 +188,7 @@ void JniRemoteEnrollee::provisionCloudProperties(JNIEnv *env,
     {
         m_sharedResource->provisionCloudProperties(cloudProp, cloudPropProvStatusCallback);
     }
-    catch (ESBadRequestException exception)
+    catch (ESBadRequestException &exception)
     {
         ES_LOGE("JNI startProvisioning :: Exception occured");
         //throw the exception to java
index a27c3a7..6d5c27d 100644 (file)
@@ -1076,12 +1076,10 @@ namespace OIC
         {
             OIC_LOG(DEBUG, ENROLEE_SECURITY_TAG, "isOwnedDeviceRegisteredInDB IN");
 
-            OCStackResult res = OC_STACK_ERROR;
-
             OCUuidList_t *uuidList = NULL;
             size_t numOfDevices = 0;
 
-            res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
+            OCStackResult res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
             if (OC_STACK_OK != res)
             {
                 OIC_LOG(ERROR, ENROLEE_SECURITY_TAG, "Error while getting info from DB");