IOT-1583: Fixing /W3 warnings in /resource directory - part 5. 85/19585/25
authorPawel Winogrodzki <pawelwi@microsoft.com>
Wed, 3 May 2017 07:19:05 +0000 (00:19 -0700)
committerMike Fenelon <mike.fenelon@microsoft.com>
Wed, 10 May 2017 23:13:32 +0000 (23:13 +0000)
Fixing most of the remaining /W3s inside the resource/ directory.

Change-Id: I4f84d75fc3018035ee4f9e17df7befb6ed4b26af
Signed-off-by: Pawel Winogrodzki <pawelwi@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19585
Reviewed-by: Mike Fenelon <mike.fenelon@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
30 files changed:
build_common/windows/SConscript
extlibs/cjson/SConscript
extlibs/gtest/SConscript
extlibs/libcoap/SConscript
extlibs/mbedtls/SConscript
extlibs/sqlite3/SConscript
java/jni/JniOcRepresentation.cpp
java/jni/JniOcRepresentation.h
java/jni/JniOcStack.cpp
java/jni/JniOcStack.h
resource/IPCA/unittests/SConscript
resource/c_common/SConscript
resource/c_common/unittests/SConscript
resource/csdk/connectivity/SConscript
resource/csdk/connectivity/test/SConscript
resource/csdk/security/SConscript
resource/csdk/security/unittests/SConscript
resource/csdk/stack/SConscript
resource/csdk/stack/test/SConscript
resource/include/AttributeValue.h
resource/include/OCRepresentation.h
resource/include/OCRepresentationInternal.h [new file with mode: 0644]
resource/include/StringConstants.h
resource/src/OCRepresentation.cpp
resource/src/OCRepresentationInternal.cpp [new file with mode: 0644]
resource/src/SConscript
resource/unittests/OCAccountManagerTest.cpp
resource/unittests/OCRepresentationEncodingTest.cpp
resource/unittests/OCRepresentationTest.cpp
service/notification/cpp-wrapper/examples/linux/notificationserviceprovider.cpp

index 81ea3cf..7fdbc05 100644 (file)
@@ -6,9 +6,6 @@ import os.path
 
 # Set common flags
 if env['CC'] == 'cl':
-    #  - warning C4133: incompatible type conversion
-    env.AppendUnique(CCFLAGS=['/we4133'])
-
     # Disable the following warnings:
     #  - warning C4127: conditional expression is constant
     #    - Disabled due to the widespread usage in IoTivity
@@ -25,10 +22,16 @@ if env['CC'] == 'cl':
     #    - Disabled due to IoTivity not being ANSI compatible
     #  - warning C4232: nonstandard extension used: 'read': address of dllimport 'fread' is not static, identity not guaranteed
     #    - fread, frwrite, etc are provided by the platform and cannot be changed.
+    #  - warning C4503: decorated name length exceeded, name was truncated.
+    #    - Might cause issues during linking and debugging.
+    #  - warning C4512: assignment operator could not be generated.
+    #    - It's an acceptable warning displayed only by Visual Studio 2013 compiler.
     #  - warning C4706: assignment within conditional expression
     #    - Disabled due to the widespread usage in IoTivity and low impact.
-    env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200', '/wd4201', '/wd4204', '/wd4214', '/wd4221', '/wd4232', '/wd4706'])
+    env.AppendUnique(CCFLAGS=['/wd4127', '/wd4200', '/wd4201', '/wd4204', '/wd4214', '/wd4221', '/wd4232', '/wd4503', '/wd4512', '/wd4706'])
 
+    # Enabling /W3 warnings globally for Windows builds.
+    env.AppendUnique(CCFLAGS=['/W3', '/WX'])
     env.AppendUnique(CCFLAGS=['/EHsc'])
 
     # Set release/debug flags
@@ -41,12 +44,12 @@ if env['CC'] == 'cl':
 
     env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
 
-    # Work around [IOT-1986]\r
-    # During some Windows multi-threaded builds, SCons/Python/Pywin32 appear to try\r
-    # linking with these static libraries while another SCons thread started executing\r
-    # InstallTarget() for this static LIB, but didn't finish yet. That behavior results\r
-    # in linker errors. Work around this issue by linking with the source of InstallTarget(),\r
-    # rather than the target.\r
+    # Work around [IOT-1986]
+    # During some Windows multi-threaded builds, SCons/Python/Pywin32 appear to try
+    # linking with these static libraries while another SCons thread started executing
+    # InstallTarget() for this static LIB, but didn't finish yet. That behavior results
+    # in linker errors. Work around this issue by linking with the source of InstallTarget(),
+    # rather than the target.
     env.PrependUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'src')])
     env.PrependUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'oc_logger')])
     env.PrependUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource', 'csdk', 'resource-directory')])
@@ -64,7 +67,7 @@ if env['CC'] == 'cl':
     # will not work on all systems supported by IoTivity. This will prevent Visual
     # Studio from displaying unwanted warnings.
     # See https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx for more details.
-    env.AppendUnique(CPPDEFINES=['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_WARNINGS'])
+    env.AppendUnique(CPPDEFINES=['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_WARNINGS', '_SCL_SECURE_NO_WARNINGS'])
 
 elif env['CC'] == 'gcc':
     print "\nError: gcc not supported on Windows.  Use Visual Studio!\n"
index 8365b70..58d2872 100644 (file)
@@ -26,7 +26,7 @@ if cjson_env.get('TARGET_OS') in ['windows', 'msys_nt']:
     # Macro needed for Windows builds to avoid __declspec(dllexport) and __declspec(dllimport) for cJSON APIs.
     cjson_env.AppendUnique(CPPDEFINES = ['CJSON_HIDE_SYMBOLS'])
     if cjson_env['CC'] == 'cl':
-        cjson_env.AppendUnique(CCFLAGS = ['/W4', '/WX'])
+        cjson_env.AppendUnique(CCFLAGS = ['/W4'])
 
 libcjson = cjson_env.StaticLibrary('cjson', ['cJSON.c'], OBJPREFIX='libcjson_')
 cjson_env.InstallTarget(libcjson, 'cjson');
index 39c0b5f..7fc0f40 100644 (file)
@@ -78,7 +78,8 @@ elif target_os in ['windows']:
                gtest_build_env = gtest_env.Clone()
                gtest_build_env.AppendUnique(CPPPATH = [ os.path.join(gtest_dir, 'include') ])
                gtest_build_env.AppendUnique(CXXFLAGS = ['/EHsc'])
-               gtest_build_env.AppendUnique(CCFLAGS = ['/W4', '/WX'])
+               if gtest_build_env['CC'] == 'cl':
+                       gtest_build_env.AppendUnique(CCFLAGS = ['/W4'])
                gtest = gtest_build_env.StaticLibrary(target = 'gtest', source = [ '%s/src/gtest-all.cc' % gtest_dir ])
                gtest_main = gtest_build_env.StaticLibrary(target = 'gtest_main', source = [ '%s/src/gtest_main.cc' % gtest_dir ])
                gtest_env.InstallTarget(gtest, 'gtest')
index db2bdbe..aed25af 100644 (file)
@@ -286,7 +286,7 @@ else:
     libcoap_src = glob.glob(os.path.join(libcoap_src_root, '*.c'))
 
 if libcoap_env['CC'] == 'cl':
-    libcoap_env.AppendUnique(CCFLAGS = ['/W4', '/WX'])
+    libcoap_env.AppendUnique(CCFLAGS = ['/W4'])
 
 libcoap = libcoap_env.StaticLibrary('coap', libcoap_src, OBJPREFIX='libcoap_')
 
index ed90ffb..c3568be 100644 (file)
@@ -107,7 +107,7 @@ else:
 mbedtls_env = env.Clone()
 
 if mbedtls_env['CC'] == 'cl':
-    mbedtls_env.AppendUnique(CCFLAGS = ['/W4', '/WX'])
+    mbedtls_env.AppendUnique(CCFLAGS = ['/W4'])
 
 mbedtls_env.AppendUnique(CPPPATH = [
     mbedtls_dir,
index 97e4c67..a7b4c72 100755 (executable)
@@ -40,7 +40,8 @@ if target_os in targets_need_sqlite:
         shutil.rmtree(sqlite_tmp_dir)
 
 if target_os in ['windows']:
-    sqlite_env.AppendUnique(CCFLAGS = ['/W4', '/WX'])
+    if sqlite_env['CC'] == 'cl':
+        sqlite_env.AppendUnique(CCFLAGS = ['/W4'])
     libsqlite3 = sqlite_env.StaticLibrary('sqlite3', sqlite_c)
     # In multi-threaded builds, SCons appears to proceed to using sqlite3.lib
     # before finishing InstallTarget(libsqlite3, 'sqlite3') here. So, use the
index 27e96a9..a70360b 100644 (file)
@@ -127,6 +127,30 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
     rep->setValue(str, static_cast<int>(jValue));
 }
 
+/*
+* Class:     org_iotivity_base_OcRepresentation
+* Method:    setValueLong
+* Signature: (Ljava/lang/String;J)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLong
+(JNIEnv *env, jobject thiz, jstring jKey, jlong jValue)
+{
+    LOGD("OcRepresentation_setValueLong");
+    if (!jKey)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
+        return;
+    }
+    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+    if (!rep)
+    {
+        return;
+    }
+
+    std::string str = env->GetStringUTFChars(jKey, nullptr);
+    rep->setValue(str, static_cast<int64_t>(jValue));
+}
+
 /*
 * Class:     org_iotivity_base_OcRepresentation
 * Method:    setValueDouble
@@ -365,6 +389,131 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3D
     rep->setValue(key, value);
 }
 
+/*
+* Class:     org_iotivity_base_OcRepresentation
+* Method:    setValueLongArray
+* Signature: (Ljava/lang/String;[J)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLongArray
+(JNIEnv *env, jobject thiz, jstring jKey, jlongArray jValue)
+{
+    LOGD("OcRepresentation_setValueLongArray");
+    if (!jKey)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
+        return;
+    }
+
+    const jsize len = env->GetArrayLength(jValue);
+    jlong* longs = env->GetLongArrayElements(jValue, nullptr);
+
+    std::vector<int64_t> value;
+    for (jsize i = 0; i < len; ++i)
+    {
+        value.push_back(static_cast<int64_t>(longs[i]));
+    }
+    env->ReleaseLongArrayElements(jValue, longs, JNI_ABORT);
+
+    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+    if (!rep)
+    {
+        return;
+    }
+
+    std::string key = env->GetStringUTFChars(jKey, nullptr);
+    rep->setValue(key, value);
+}
+
+/*
+* Class:     org_iotivity_base_OcRepresentation
+* Method:    setValueLong2DArray
+* Signature: (Ljava/lang/String;[[J)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLong2DArray
+(JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
+{
+    LOGD("OcRepresentation__setValueLong2DArray");
+    if (!jKey)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
+        return;
+    }
+    std::vector<std::vector<int64_t>> value;
+    const jsize lenOuter = env->GetArrayLength(jValue);
+    for (jsize j = 0; j < lenOuter; ++j)
+    {
+        jlongArray jInnerArray = static_cast<jlongArray>(env->GetObjectArrayElement(jValue, j));
+        jlong* longs = env->GetLongArrayElements(jInnerArray, nullptr);
+        std::vector<int64_t> innerVector;
+        const jsize lenInner = env->GetArrayLength(jInnerArray);
+        for (jsize i = 0; i < lenInner; ++i)
+        {
+            innerVector.push_back(static_cast<int64_t>(longs[i]));
+        }
+        env->ReleaseLongArrayElements(jInnerArray, longs, JNI_ABORT);
+        env->DeleteLocalRef(jInnerArray);
+        value.push_back(innerVector);
+    }
+
+    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+    if (!rep)
+    {
+        return;
+    }
+
+    std::string key = env->GetStringUTFChars(jKey, nullptr);
+    rep->setValue(key, value);
+}
+
+/*
+* Class:     org_iotivity_base_OcRepresentation
+* Method:    setValueLong3DArray
+* Signature: (Ljava/lang/String;[[[J)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLong3DArray
+(JNIEnv *env, jobject thiz, jstring jKey, jobjectArray jValue)
+{
+    LOGD("OcRepresentation_setValueLong3DArray");
+    if (!jKey)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null");
+        return;
+    }
+    std::vector<std::vector<std::vector<int64_t>>> value;
+    const jsize lenOuter = env->GetArrayLength(jValue);
+    for (jsize k = 0; k < lenOuter; ++k)
+    {
+        jobjectArray jMiddleArray = static_cast<jobjectArray>(env->GetObjectArrayElement(jValue, k));
+        const jsize lenMiddle = env->GetArrayLength(jMiddleArray);
+        std::vector<std::vector<int64_t>> middleArray;
+        for (jsize j = 0; j < lenMiddle; ++j)
+        {
+            jlongArray jInnerArray = static_cast<jlongArray>(env->GetObjectArrayElement(jMiddleArray, j));
+            jlong* longs = env->GetLongArrayElements(jInnerArray, nullptr);
+            std::vector<int64_t> innerVector;
+            const jsize lenInner = env->GetArrayLength(jInnerArray);
+            for (jsize i = 0; i < lenInner; ++i)
+            {
+                innerVector.push_back(static_cast<int64_t>(longs[i]));
+            }
+            env->ReleaseLongArrayElements(jInnerArray, longs, JNI_ABORT);
+            env->DeleteLocalRef(jInnerArray);
+            middleArray.push_back(innerVector);
+        }
+        env->DeleteLocalRef(jMiddleArray);
+        value.push_back(middleArray);
+    }
+
+    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
+    if (!rep)
+    {
+        return;
+    }
+
+    std::string key = env->GetStringUTFChars(jKey, nullptr);
+    rep->setValue(key, value);
+}
+
 /*
 * Class:     org_iotivity_base_OcRepresentation
 * Method:    setValueDoubleArray
index dc85747..0db1c09 100644 (file)
@@ -52,6 +52,15 @@ struct JObjectConverter : boost::static_visitor < jobject >
             static_cast<jint>(val));
         return jobj;
     }
+
+    jobject operator()(const int64_t& val) const
+    {
+        jobject jobj = env->NewObject(
+            g_cls_Long,
+            g_mid_Long_ctor,
+            static_cast<jlong>(val));
+        return jobj;
+    }
     jobject operator()(const double& val) const
     {
         jobject jobj = env->NewObject(
@@ -101,6 +110,18 @@ struct JObjectConverter : boost::static_visitor < jobject >
         env->SetIntArrayRegion(jIntArray, 0, len, reinterpret_cast<const jint*>(ints));
         return jIntArray;
     }
+    jobject operator()(const std::vector<int64_t>& val) const
+    {
+        size_t len = val.size();
+        jlongArray jLongArray = env->NewLongArray(len);
+        if (!jLongArray)
+        {
+            return nullptr;
+        }
+        const int64_t* longs = &val[0];
+        env->SetLongArrayRegion(jLongArray, 0, len, reinterpret_cast<const jlong*>(longs));
+        return jLongArray;
+    }
     jobject operator()(const std::vector<double>& val) const
     {
         size_t len = val.size();
@@ -374,6 +395,86 @@ struct JObjectConverter : boost::static_visitor < jobject >
         return jOuterArr;
     }
 
+    jobject operator()(const std::vector<std::vector<int64_t>>& val) const
+    {
+        jsize lenOuter = static_cast<jsize>(val.size());
+        jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_long1DArray, nullptr);
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
+        for (jsize i = 0; i < lenOuter; ++i)
+        {
+            size_t lenInner = val[i].size();
+            jlongArray jLongArray = env->NewLongArray(lenInner);
+            if (!jLongArray)
+            {
+                return nullptr;
+            }
+            const int64_t* longs = &val[i][0];
+            env->SetLongArrayRegion(jLongArray, 0, lenInner, reinterpret_cast<const jlong*>(longs));
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
+            env->SetObjectArrayElement(jOuterArr, i, static_cast<jobject>(jLongArray));
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
+            env->DeleteLocalRef(jLongArray);
+        }
+        return jOuterArr;
+    }
+    jobject operator()(const std::vector<std::vector<std::vector<int64_t>>>& val) const
+    {
+        jsize lenOuter = static_cast<jsize>(val.size());
+        jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_long2DArray, nullptr);
+        if (!jOuterArr)
+        {
+            return nullptr;
+        }
+
+        for (jsize k = 0; k < lenOuter; ++k)
+        {
+            jsize lenMiddle = static_cast<jsize>(val[k].size());
+            jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_long1DArray, nullptr);
+            if (!jMiddleArr)
+            {
+                return nullptr;
+            }
+
+            for (jsize i = 0; i < lenMiddle; ++i)
+            {
+                jsize lenInner = static_cast<jsize>(val[k][i].size());
+                jlongArray jLongArray = env->NewLongArray(lenInner);
+                if (!jLongArray)
+                {
+                    return nullptr;
+                }
+                const int64_t* longs = &val[k][i][0];
+                env->SetLongArrayRegion(jLongArray, 0, lenInner, reinterpret_cast<const jlong*>(longs));
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
+                env->SetObjectArrayElement(jMiddleArr, i, jLongArray);
+                if (env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
+                env->DeleteLocalRef(jLongArray);
+            }
+            env->SetObjectArrayElement(jOuterArr, k, jMiddleArr);
+            if (env->ExceptionCheck())
+            {
+                return nullptr;
+            }
+            env->DeleteLocalRef(jMiddleArr);
+        }
+        return jOuterArr;
+    }
+
     jobject operator()(const std::vector<std::vector<double>>& val) const
     {
         jsize lenOuter = static_cast<jsize>(val.size());
@@ -767,6 +868,14 @@ extern "C" {
     JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger
         (JNIEnv *, jobject, jstring, jint);
 
+    /*
+    * Class:     org_iotivity_base_OcRepresentation
+    * Method:    setValueLong
+    * Signature: (Ljava/lang/String;J)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLong
+    (JNIEnv *, jobject, jstring, jlong);
+
     /*
     * Class:     org_iotivity_base_OcRepresentation
     * Method:    setValueDouble
@@ -823,6 +932,30 @@ extern "C" {
     JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3DArray
         (JNIEnv *, jobject, jstring, jobjectArray);
 
+    /*
+    * Class:     org_iotivity_base_OcRepresentation
+    * Method:    setValueLongArray
+    * Signature: (Ljava/lang/String;[J)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLongArray
+    (JNIEnv *, jobject, jstring, jlongArray);
+
+    /*
+    * Class:     org_iotivity_base_OcRepresentation
+    * Method:    setValueLong2DArray
+    * Signature: (Ljava/lang/String;[[J)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLong2DArray
+    (JNIEnv *, jobject, jstring, jobjectArray);
+
+    /*
+    * Class:     org_iotivity_base_OcRepresentation
+    * Method:    setValueLong3DArray
+    * Signature: (Ljava/lang/String;[[[J)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueLong3DArray
+    (JNIEnv *, jobject, jstring, jobjectArray);
+
     /*
     * Class:     org_iotivity_base_OcRepresentation
     * Method:    setValueDoubleArray
index 0f2df49..ea57395 100644 (file)
@@ -45,6 +45,9 @@ jclass g_cls_byte3DArray = nullptr;
 jclass g_cls_Integer = nullptr;
 jclass g_cls_int1DArray = nullptr;
 jclass g_cls_int2DArray = nullptr;
+jclass g_cls_Long = nullptr;
+jclass g_cls_long1DArray = nullptr;
+jclass g_cls_long2DArray = nullptr;
 jclass g_cls_Double = nullptr;
 jclass g_cls_double1DArray = nullptr;
 jclass g_cls_double2DArray = nullptr;
@@ -91,6 +94,7 @@ jclass g_cls_OcCloudProvisioning = nullptr;
 #endif
 
 jmethodID g_mid_Integer_ctor = nullptr;
+jmethodID g_mid_Long_ctor = nullptr;
 jmethodID g_mid_Double_ctor = nullptr;
 jmethodID g_mid_Boolean_ctor = nullptr;
 jmethodID g_mid_LinkedList_ctor = nullptr;
@@ -243,6 +247,26 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
     g_cls_int2DArray = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
+    //Long
+    clazz = env->FindClass("java/lang/Long");
+    VERIFY_VARIABLE_NULL(clazz);
+
+    g_cls_Long = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_Long_ctor = env->GetMethodID(g_cls_Long, "<init>", "(J)V");
+    VERIFY_VARIABLE_NULL(g_mid_Long_ctor);
+
+    clazz = env->FindClass("[J");
+    VERIFY_VARIABLE_NULL(clazz);
+    g_cls_long1DArray = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    clazz = env->FindClass("[[J");
+    VERIFY_VARIABLE_NULL(clazz);
+    g_cls_long2DArray = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
     //Double
     clazz = env->FindClass("java/lang/Double");
     VERIFY_VARIABLE_NULL(clazz);
@@ -652,6 +676,9 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
         env->DeleteGlobalRef(g_cls_Integer);
         env->DeleteGlobalRef(g_cls_int1DArray);
         env->DeleteGlobalRef(g_cls_int2DArray);
+        env->DeleteGlobalRef(g_cls_Long);
+        env->DeleteGlobalRef(g_cls_long1DArray);
+        env->DeleteGlobalRef(g_cls_long2DArray);
         env->DeleteGlobalRef(g_cls_Double);
         env->DeleteGlobalRef(g_cls_double1DArray);
         env->DeleteGlobalRef(g_cls_double2DArray);
index 7ba3367..2dba744 100644 (file)
@@ -66,6 +66,9 @@ extern jclass g_cls_byte3DArray;
 extern jclass g_cls_Integer;
 extern jclass g_cls_int1DArray;
 extern jclass g_cls_int2DArray;
+extern jclass g_cls_Long;
+extern jclass g_cls_long1DArray;
+extern jclass g_cls_long2DArray;
 extern jclass g_cls_Double;
 extern jclass g_cls_double1DArray;
 extern jclass g_cls_double2DArray;
@@ -112,6 +115,7 @@ extern jclass g_cls_OcOicSecAcl_resr;
 extern jclass g_cls_OcOicSecAcl_validity;
 
 extern jmethodID g_mid_Integer_ctor;
+extern jmethodID g_mid_Long_ctor;
 extern jmethodID g_mid_Double_ctor;
 extern jmethodID g_mid_Boolean_ctor;
 extern jmethodID g_mid_LinkedList_ctor;
index a9f7bff..1b31b92 100644 (file)
@@ -97,7 +97,8 @@ if use_iotivity == 0:
         'mockInProcServerWrapper.cpp',
         'mockOCPlatform_impl.cpp',
         'mockOCProvision.cpp',
-        '#/resource/src/OCRepresentation.cpp'
+        '#/resource/src/OCRepresentation.cpp',
+        '#/resource/src/OCRepresentationInternal.cpp'
         ]
 
 if target_os not in ['windows', 'msys_nt']:
index 8cd962c..7ff8eee 100644 (file)
@@ -162,8 +162,8 @@ common_env = env.Clone()
 # Enable treating all warnings as errors
 ######################################################################
 
-if target_os in ['windows', 'msys_nt']:
-    common_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+if common_env['CC'] == 'cl':
+    common_env.AppendUnique(CCFLAGS=['/W4'])
 
 ######################################################################
 # Add platform-specific helper library
index 8cf52d0..fd8f65f 100644 (file)
@@ -27,9 +27,9 @@ Import('test_env')
 common_test_env = test_env.Clone()
 target_os = common_test_env.get('TARGET_OS')
 
-# Enable treating all warnings as errors for Windows.
-if target_os in ['windows', 'msys_nt']:
-    common_test_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+# Enable treating all warnings as errors for VS compiler.
+if common_test_env['CC'] == 'cl':
+    common_test_env.AppendUnique(CCFLAGS=['/W4'])
 
 SConscript('../oic_string/test/SConscript', exports = { 'test_env' : common_test_env})
 SConscript('../oic_malloc/test/SConscript', exports = { 'test_env' : common_test_env})
index 6450bcf..8e5ba81 100644 (file)
@@ -17,8 +17,8 @@ print "Given OS is %s" % target_os
 print "BUILD_SAMPLE is %s" % build_sample
 print "MQ flag is %s" % with_mq
 
-if target_os in ['msys_nt', 'windows']:
-    connectivity_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+if connectivity_env['CC'] == 'cl':
+    connectivity_env.AppendUnique(CCFLAGS=['/W4'])
 
 targets_disallow_multitransport = ['arduino']
 
index 1d17770..5e9e2e6 100644 (file)
@@ -85,8 +85,9 @@ if 'SERVER' in rd_mode:
 
 if target_os not in ['msys_nt', 'windows']:
     catest_env.AppendUnique(LIBS = ['m'])
-else:
-    catest_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+
+if catest_env['CC'] == 'cl':
+    catest_env.AppendUnique(CCFLAGS=['/W4'])
 
 ######################################################################
 # Source files and Targets
index 081d878..158b112 100644 (file)
@@ -57,10 +57,9 @@ libocsrm_env.PrependUnique(CPPPATH = [
 
 if target_os in ['windows', 'msys_nt']:
        libocsrm_env.AppendUnique(LIBPATH = [os.path.join(libocsrm_env.get('BUILD_DIR'), 'resource', 'oc_logger')])
-    #  - warning C4200: nonstandard extension used: zero-sized array in struct/union
-    #  - warning C4214: nonstandard extension used: bit field types other than int
-    #    - warnings inherited from a header included from libcoap
-       libocsrm_env.AppendUnique(CCFLAGS=['/wd4200', '/wd4214', '/W4', '/WX'])
+
+if libocsrm_env['CC'] == 'cl':
+       libocsrm_env.AppendUnique(CCFLAGS=['/W4'])
 
 if target_os in ['linux', 'android', 'tizen', 'msys_nt', 'windows'] and libocsrm_env.get('SECURED') == '1':
        SConscript('provisioning/SConscript', 'libocsrm_env')
index f904504..99dce86 100644 (file)
@@ -26,8 +26,8 @@ Import('test_env')
 
 security_test_env = test_env.Clone()
 
-if security_test_env.get('TARGET_OS') in ['windows', 'msys_nt']:
-    security_test_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
+if security_test_env['CC'] == 'cl':
+    security_test_env.AppendUnique(CCFLAGS=['/W4'])
 
 SConscript('../unittest/SConscript', exports = { 'test_env' : security_test_env })
 SConscript('../provisioning/unittest/SConscript', exports = { 'test_env' : security_test_env })
index 7cd8486..03eb95d 100644 (file)
@@ -117,11 +117,12 @@ if target_os in ['android', 'linux', 'tizen', 'msys_nt', 'windows']:
         if with_ra:
             liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
 
+if liboctbstack_env['CC'] == 'cl':
+    liboctbstack_env.AppendUnique(CCFLAGS=['/W4'])
+
 if target_os not in ['windows', 'msys_nt']:
     liboctbstack_env.AppendUnique(LIBS = ['m'])
 else:
-    liboctbstack_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
-
     # octbstack.def specifies the list of functions exported by octbstack.dll.
     liboctbstack_env.Replace(WINDOWS_INSERT_DEF = ['1'])
 
index 5d5228b..3ed03a2 100644 (file)
@@ -70,9 +70,10 @@ if 'SERVER' in rd_mode:
 if stacktest_env.get('LOGGING'):
     stacktest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
-if target_os in ['msys_nt', 'windows']:
-    stacktest_env.AppendUnique(CCFLAGS=['/W4', '/WX'])
-else:
+if stacktest_env['CC'] == 'cl':
+    stacktest_env.AppendUnique(CCFLAGS=['/W4'])
+
+if target_os not in ['msys_nt', 'windows']:
     stacktest_env.PrependUnique(LIBS = ['m'])
     if target_os in ['tizen', 'linux']:
         stacktest_env.ParseConfig("pkg-config --cflags --libs gobject-2.0 gio-2.0 glib-2.0")
index 3315356..319743d 100644 (file)
@@ -49,7 +49,7 @@ namespace OC
     static const int AttributeValueNullIndex = 0;
     typedef boost::variant<
         NullType, // Note: this handles the null-type and must match the above static const
-        int,
+        int64_t,
         double,
         bool,
         std::string,
@@ -57,7 +57,7 @@ namespace OC
         OCByteString,
 
         // Sequences:
-        std::vector<int>,
+        std::vector<int64_t>,
         std::vector<double>,
         std::vector<bool>,
         std::vector<std::string>,
@@ -65,8 +65,8 @@ namespace OC
         std::vector<OCByteString>,
 
         // Nested sequences:
-        std::vector<std::vector<int>>,
-        std::vector<std::vector<std::vector<int>>>,
+        std::vector<std::vector<int64_t>>,
+        std::vector<std::vector<std::vector<int64_t>>>,
 
         std::vector<std::vector<double>>,
         std::vector<std::vector<std::vector<double>>>,
@@ -115,6 +115,12 @@ namespace OC
         BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Integer;
     };
 
+    template<>
+    struct AttributeTypeConvert<int64_t>
+    {
+        BOOST_STATIC_CONSTEXPR AttributeType type = AttributeType::Integer;
+    };
+
     template<>
     struct AttributeTypeConvert<double>
     {
index 541cea5..64d0ff1 100644 (file)
 #include <AttributeValue.h>
 #include <StringConstants.h>
 
+#include "platform_features.h"
+
 #ifdef __ANDROID__
 #include "OCAndroid.h"
 #endif
 
 #include <OCException.h>
+#include <OCRepresentationInternal.h>
 
 namespace OC
 {
-
     enum class InterfaceType
     {
         None,
@@ -81,8 +83,42 @@ namespace OC
         private:
             std::vector<OCRepresentation> m_reps;
     };
+
     class OCRepresentation
     {
+        // Verifies if a type is supported by AttributeValue in order to enable
+        // the correct template for a given type.
+        template <typename T>
+        struct IsSupportedType {
+            static const bool value =
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, int64_t>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, double>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, bool>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::string>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, OCRepresentation>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, OCByteString>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<int64_t>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<int64_t>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::vector<int64_t>>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<double>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<double>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::vector<double>>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<bool>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<bool>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::vector<bool>>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::string>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::string>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::vector<std::string>>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<OCRepresentation>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<OCRepresentation>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::vector<OCRepresentation>>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<OCByteString>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<OCByteString>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<std::vector<std::vector<OCByteString>>>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, std::vector<uint8_t>>::value ||
+                std::is_same<typename std::remove_cv<typename std::remove_reference<T>::type>::type, NullType>::value;
+        };
+
         public:
             friend bool operator==(const OC::OCRepresentation&, const OC::OCRepresentation&);
             // Note: Implementation of all constructors and destructors
@@ -157,21 +193,37 @@ namespace OC
 
             bool emptyData() const;
 
-            int numberOfAttributes() const;
+            size_t numberOfAttributes() const;
 
             bool erase(const std::string& str);
 
-            template <typename T>
-            void setValue(const std::string& str, const T& val)
+            // Implementation is different for all int-related types, because AttributeValue
+            // uses only one (int64_t) type for integers.
+            template<typename T, typename std::enable_if<IsSupportedType<T>::value, int>::type = 0>
+            void setValue(const std::string& str, const T& rhs)
             {
-                m_values[str] = val;
+                m_values[str] = rhs;
+            }
+
+            template<typename T, typename std::enable_if<!IsSupportedType<T>::value, int>::type = 0>
+            void setValue(const std::string& str, const T& rhs)
+            {
+                assignAttributeValueContent(rhs, m_values[str]);
             }
 
             // using R-value(or universal ref depending) to move string and vector<uint8_t>
-            template <typename T>
-            void setValue(const std::string& str, T&& val)
+            // Implementation is different for all int-related types, because AttributeValue
+            // uses only one (int64_t) type for integers.
+            template<typename T, typename std::enable_if<IsSupportedType<T>::value, int>::type = 0>
+            void setValue(const std::string& str, T&& rhs)
             {
-                m_values[str] = std::forward<T>(val);
+                m_values[str] = std::forward<T>(rhs);
+            }
+
+            template<typename T, typename std::enable_if<!IsSupportedType<T>::value, int>::type = 0>
+            void setValue(const std::string& str, T&& rhs)
+            {
+                assignAttributeValueContent(rhs, m_values[str]);
             }
 
             const std::map<std::string, AttributeValue>& getValues() const {
@@ -179,66 +231,107 @@ namespace OC
             }
 
             /**
-             *  Retrieve the attribute value associated with the supplied name
+             *  Retrieve the attribute value associated with the supplied name.
+             *  Implementation is different for all int-related types, because AttributeValue
+             *  uses only one (int64_t) type for integers.
              *
              *  @param str Name of the attribute
              *  @param val Value of the attribute
              *  @return The getValue method returns true if the attribute was
-             *        found in the representation.  Otherwise it returns false.
+             *        found in the representation. Otherwise it returns false.
+             *
+             *  @throws OCException if retrieving 'int' and the value is outside
+             *                      of 'int' range.
              */
-            template <typename T>
+            template<typename T, typename std::enable_if<IsSupportedType<T>::value, int>::type = 0>
             bool getValue(const std::string& str, T& val) const
             {
                 auto x = m_values.find(str);
 
-                if(x!= m_values.end())
+                if (x != m_values.end())
                 {
                     try
                     {
                         val = boost::get<T>(x->second);
                         return true;
                     }
-                    catch (boost::bad_get& e)
+                    catch (boost::bad_get&)
                     {
-                        val = T();
-                        return false;
                     }
                 }
-                else
+                val = T();
+                return false;
+            }
+
+            template<typename T, typename std::enable_if<!IsSupportedType<T>::value, int>::type = 0>
+            bool getValue(const std::string& str, T& val) const
+            {
+                auto item = m_values.find(str);
+
+                if (item != m_values.end())
                 {
-                    val = T();
-                    return false;
+                    try
+                    {
+                        retrieveAttributeValueContent(item->second, val);
+                        return true;
+                    }
+                    catch (boost::bad_get&)
+                    {
+                    }
                 }
+                val = T();
+                return false;
             }
 
             /**
-             *  Return the attribute value associated with the supplied name
+             *  Return the attribute value associated with the supplied name.
+             *  Implementation is different for all int-related types, because AttributeValue
+             *  uses only one (int64_t) type for integers.
              *
              *  @param str Name of the attribute
              *  @return When the representation contains the attribute, the
-             *       the associated value is returned.  Otherwise, getValue
+             *       associated value is returned. Otherwise, getValue
              *       returns the default contructed value for the type.
+             *
+             *  @throws OCException if retrieving 'int' and the value is outside
+             *                      of 'int' range.
              */
-            template <typename T>
+            template<typename T, typename std::enable_if<IsSupportedType<T>::value, int>::type = 0>
+            T getValue(const std::string& str) const
+            {
+                auto x = m_values.find(str);
+                if (x != m_values.end())
+                {
+                    try
+                    {
+                        return boost::get<T>(x->second);
+                    }
+                    catch (boost::bad_get&)
+                    {
+                    }
+                }
+                return T();
+            }
+
+            template<typename T, typename std::enable_if<!IsSupportedType<T>::value, int>::type = 0>
             T getValue(const std::string& str) const
             {
                 T val = T();
                 auto x = m_values.find(str);
-                if(x != m_values.end())
+                if (x != m_values.end())
                 {
                     try
                     {
-                        val = boost::get<T>(x->second);
+                        retrieveAttributeValueContent(x->second, val);
                     }
-                    catch (boost::bad_get& e)
+                    catch (boost::bad_get&)
                     {
-                        return val;
                     }
                 }
                 return val;
             }
 
-          /**
+           /**
             *  Retrieve the attributevalue structure associated with the supplied name
             *
             *  @param str Name of the attribute
@@ -287,29 +380,51 @@ namespace OC
                     AttributeType type() const;
                     AttributeType base_type() const;
                     size_t depth() const;
-                    template<typename T>
+
+                    template<typename T, typename std::enable_if<IsSupportedType<T>::value, int>::type = 0>
                     T getValue() const
                     {
                         try
                         {
-                            return boost::get<T>(m_values[m_attrName]);
+                            return boost::get<T>(m_values.at(m_attrName));
                         }
-                        catch (boost::bad_get& e)
+                        catch (boost::bad_get&)
                         {
                             T val = T();
                             return val;
                         }
                     }
 
+                    template<typename T, typename std::enable_if<!IsSupportedType<T>::value, int>::type = 0>
+                    T getValue() const
+                    {
+                        T val = T();
+                        try
+                        {
+                            retrieveAttributeValueContent(m_values.at(m_attrName), val);
+                        }
+                        catch (boost::bad_get&)
+                        {
+                        }
+                        return val;
+                    }
+
                     std::string getValueToString() const;
 
-                    template<typename T>
+                    template<typename T, typename std::enable_if<IsSupportedType<T>::value, int>::type = 0>
                     AttributeItem& operator=(T&& rhs)
                     {
                         m_values[m_attrName] = std::forward<T>(rhs);
                         return *this;
                     }
 
+                    template<typename T, typename std::enable_if<!IsSupportedType<T>::value, int>::type = 0>
+                    AttributeItem& operator=(T&& rhs)
+                    {
+                        assignAttributeValueContent(rhs, m_values[m_attrName]);
+                        return *this;
+                    }
+
                     AttributeItem& operator=(std::nullptr_t /*rhs*/)
                     {
                         NullType t;
@@ -323,6 +438,7 @@ namespace OC
 #if (defined(_MSC_VER) ) || (defined(__GNUC__) && (__GNUC__ <= 5))
                     template<typename T, typename std::enable_if<
                      std::is_same<T, int>::value ||
+                     std::is_same<T, int64_t>::value ||
                      std::is_same<T, double>::value ||
                      std::is_same<T, bool>::value ||
                      std::is_same<T, std::string>::value ||
@@ -331,6 +447,9 @@ namespace OC
                      std::is_same<T, std::vector<int>>::value ||
                      std::is_same<T, std::vector<std::vector<int>>>::value ||
                      std::is_same<T, std::vector<std::vector<std::vector<int>>>>::value ||
+                     std::is_same<T, std::vector<int64_t>>::value ||
+                     std::is_same<T, std::vector<std::vector<int64_t>>>::value ||
+                     std::is_same<T, std::vector<std::vector<std::vector<int64_t>>>>::value ||
                      std::is_same<T, std::vector<double>>::value ||
                      std::is_same<T, std::vector<std::vector<double>>>::value ||
                      std::is_same<T, std::vector<std::vector<std::vector<double>>>>::value ||
@@ -459,6 +578,16 @@ namespace OC
             friend class OCResourceResponse;
             friend class MessageContainer;
 
+            static void retrieveAttributeValueContent(const AttributeValue& attributeValue, int& val);
+            static void retrieveAttributeValueContent(const AttributeValue& attributeValue, std::vector<int>& val);
+            static void retrieveAttributeValueContent(const AttributeValue& attributeValue, std::vector<std::vector<int>>& val);
+            static void retrieveAttributeValueContent(const AttributeValue& attributeValue, std::vector<std::vector<std::vector<int>>>& val);
+
+            static void assignAttributeValueContent(const int& val, AttributeValue& attributeValue);
+            static void assignAttributeValueContent(const std::vector<int>&  val, AttributeValue& attributeValue);
+            static void assignAttributeValueContent(const std::vector<std::vector<int>>&  val, AttributeValue& attributeValue);
+            static void assignAttributeValueContent(const std::vector<std::vector<std::vector<int>>>&  val, AttributeValue& attributeValue);
+
             template<typename T>
             void payload_array_helper(const OCRepPayloadValue* pl, size_t depth);
             template<typename T>
diff --git a/resource/include/OCRepresentationInternal.h b/resource/include/OCRepresentationInternal.h
new file mode 100644 (file)
index 0000000..c54bc1f
--- /dev/null
@@ -0,0 +1,58 @@
+/* *****************************************************************
+ *
+ * Copyright 2017 Microsoft
+ *
+ *
+ * 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 <vector>
+#include <stdint.h>
+
+namespace OC {
+
+   /**
+    *  Checks if passed 'int64_t' values are within a regular 'int' range.
+    *
+    *  @param[in]   int64Value An 'int64_t' variable or a vector containing such values.
+    *
+    *  @throws OCException if at least one verified value is outside of 'int' range.
+    */
+    void checkValueInIntRange(int64_t int64Value);
+    void checkValueInIntRange(const std::vector<int64_t>& int64Value);
+    void checkValueInIntRange(const std::vector<std::vector<int64_t>>& int64Value);
+    void checkValueInIntRange(const std::vector<std::vector<std::vector<int64_t>>>& int64Value);
+
+   /**
+    *  Copies 'int64_t' values into an 'int' variable.
+    *
+    *  @param[in]   int64Value  An 'int64_t' variable or a vector containing such values.
+    *  @param[out]  intValue    An 'int' variable or a vector containing such values.
+    */
+    void copyInt64Type(int64_t int64Value, int& intValue);
+    void copyInt64Type(const std::vector<int64_t>& int64Value, std::vector<int>& intValue);
+    void copyInt64Type(const std::vector<std::vector<int64_t>>& int64Value, std::vector<std::vector<int>>& intValue);
+    void copyInt64Type(const std::vector<std::vector<std::vector<int64_t>>>& int64Value, std::vector<std::vector<std::vector<int>>>& intValue);
+
+   /**
+    *  Copies 'int' values into an 'int64_t' variable.
+    *
+    *  @param[in]   intValue    An 'int' variable or a vector containing such values.
+    *  @param[out]  int64Value  An 'int64_t' variable or a vector containing such values.
+    */
+    void copyIntType(int intValue, int64_t& int64Value);
+    void copyIntType(const std::vector<int>& intValue, std::vector<int64_t>& int64Value);
+    void copyIntType(const std::vector<std::vector<int>>& intValue, std::vector<std::vector<int64_t>>& int64Value);
+    void copyIntType(const std::vector<std::vector<std::vector<int>>>& intValue, std::vector<std::vector<std::vector<int64_t>>>& int64Value);
+}
\ No newline at end of file
index 87a97aa..2a406b8 100644 (file)
@@ -75,6 +75,7 @@ namespace OC
                             "Error: OptionID valid only If-Match(1), If-None-Match(5),"
                             "Location-Path(8), Location-Query(20),"
                             "and from 2048 to 3000 inclusive.";
+        static const char OUT_OF_INT_RANGE[]           = "Value out of range of type 'int'.";
         static const char NO_ERROR[]                   = "No Error";
         static const char RESOURCE_CREATED[]           = "Resource Created";
         static const char RESOURCE_CHANGED[]           = "Resource Changed";
index 76002c4..2c0bf31 100644 (file)
@@ -123,11 +123,11 @@ namespace OC
             dimensions[2] = 0;
             dimTotal = calcDimTotal(dimensions);
 
-            array = (void*)OICMalloc(dimTotal * root_size);
+            m_array = (void*)OICMalloc(dimTotal * root_size);
 
             for(size_t i = 0; i < dimensions[0]; ++i)
             {
-                copy_to_array(arr[i], array, i);
+                copy_to_array(arr[i], m_array, i);
             }
 
         }
@@ -143,13 +143,13 @@ namespace OC
                 dimensions[1] = std::max(dimensions[1], arr[i].size());
             }
             dimTotal = calcDimTotal(dimensions);
-            array = (void*)OICCalloc(1, dimTotal * root_size);
+            m_array = (void*)OICCalloc(1, (dimTotal * root_size));
 
             for(size_t i = 0; i < dimensions[0]; ++i)
             {
                 for(size_t j = 0; j < dimensions[1] && j < arr[i].size(); ++j)
                 {
-                    copy_to_array(arr[i][j], array, i*dimensions[1] + j);
+                    copy_to_array(arr[i][j], m_array, i*dimensions[1] + j);
                 }
             }
         }
@@ -171,7 +171,7 @@ namespace OC
             }
 
             dimTotal = calcDimTotal(dimensions);
-            array = (void*)OICCalloc(1, dimTotal * root_size);
+            m_array = (void*)OICCalloc(1, dimTotal * root_size);
 
             for(size_t i = 0; i < dimensions[0]; ++i)
             {
@@ -179,7 +179,7 @@ namespace OC
                 {
                     for(size_t k = 0; k < dimensions[2] && k < arr[i][j].size(); ++k)
                     {
-                        copy_to_array(arr[i][j][k], array,
+                        copy_to_array(arr[i][j][k], m_array,
                                 dimensions[2] * j +
                                 dimensions[2] * dimensions[1] * i +
                                 k);
@@ -203,7 +203,7 @@ namespace OC
         size_t dimensions[MAX_REP_ARRAY_DEPTH];
         size_t root_size;
         size_t dimTotal;
-        void* array;
+        void* m_array;
     };
 
     template<>
@@ -291,31 +291,31 @@ namespace OC
         {
             case AttributeType::Integer:
                 OCRepPayloadSetIntArrayAsOwner(payload, item.attrname().c_str(),
-                        (int64_t*)vis.array,
+                        (int64_t*)vis.m_array,
                         vis.dimensions);
                 break;
             case AttributeType::Double:
                 OCRepPayloadSetDoubleArrayAsOwner(payload, item.attrname().c_str(),
-                        (double*)vis.array,
+                        (double*)vis.m_array,
                         vis.dimensions);
                 break;
             case AttributeType::Boolean:
                 OCRepPayloadSetBoolArrayAsOwner(payload, item.attrname().c_str(),
-                        (bool*)vis.array,
+                        (bool*)vis.m_array,
                         vis.dimensions);
                 break;
             case AttributeType::String:
                 OCRepPayloadSetStringArrayAsOwner(payload, item.attrname().c_str(),
-                        (char**)vis.array,
+                        (char**)vis.m_array,
                         vis.dimensions);
                 break;
             case AttributeType::OCByteString:
                 OCRepPayloadSetByteStringArrayAsOwner(payload, item.attrname().c_str(),
-                                                      (OCByteString *)vis.array, vis.dimensions);
+                                                      (OCByteString *)vis.m_array, vis.dimensions);
                 break;
             case AttributeType::OCRepresentation:
                 OCRepPayloadSetPropObjectArrayAsOwner(payload, item.attrname().c_str(),
-                        (OCRepPayload**)vis.array, vis.dimensions);
+                        (OCRepPayload**)vis.m_array, vis.dimensions);
                 break;
             default:
                 throw std::logic_error(std::string("GetPayloadArray: Not Implemented") +
@@ -351,7 +351,7 @@ namespace OC
                     OCRepPayloadSetNull(root, val.attrname().c_str());
                     break;
                 case AttributeType::Integer:
-                    OCRepPayloadSetPropInt(root, val.attrname().c_str(), static_cast<int>(val));
+                    OCRepPayloadSetPropInt(root, val.attrname().c_str(), val.getValue<int64_t>());
                     break;
                 case AttributeType::Double:
                     OCRepPayloadSetPropDouble(root, val.attrname().c_str(),
@@ -417,7 +417,7 @@ namespace OC
         throw std::logic_error("payload_array_helper_copy: unsupported type");
     }
     template<>
-    int OCRepresentation::payload_array_helper_copy<int>(size_t index, const OCRepPayloadValue* pl)
+    int64_t OCRepresentation::payload_array_helper_copy<int64_t>(size_t index, const OCRepPayloadValue* pl)
     {
         return pl->arr.iArray[index];
     }
@@ -527,7 +527,7 @@ namespace OC
         switch(pl->arr.type)
         {
             case OCREP_PROP_INT:
-                payload_array_helper<int>(pl, calcArrayDepth(pl->arr.dimensions));
+                payload_array_helper<int64_t>(pl, calcArrayDepth(pl->arr.dimensions));
                 break;
             case OCREP_PROP_DOUBLE:
                 payload_array_helper<double>(pl, calcArrayDepth(pl->arr.dimensions));
@@ -578,7 +578,7 @@ namespace OC
                     setNULL(val->name);
                     break;
                 case OCREP_PROP_INT:
-                    setValue<int>(val->name, val->i);
+                    setValue<int64_t>(val->name, val->i);
                     break;
                 case OCREP_PROP_DOUBLE:
                     setValue<double>(val->name, val->d);
@@ -774,14 +774,14 @@ namespace OC
         return true;
     }
 
-    int OCRepresentation::numberOfAttributes() const
+    size_t OCRepresentation::numberOfAttributes() const
     {
         return m_values.size();
     }
 
     bool OCRepresentation::erase(const std::string& str)
     {
-        return m_values.erase(str);
+        return (m_values.erase(str) != 0);
     }
 
     void OCRepresentation::setNULL(const std::string& str)
@@ -835,7 +835,7 @@ namespace OC
                 os << "Vector";
                 break;
             case AttributeType::Binary:
-                os<< "Binary";
+                os << "Binary";
         }
         return os;
     }
@@ -1145,6 +1145,62 @@ namespace OC
         str = "OC::OCRepresentation";
     }
 
+    void OCRepresentation::retrieveAttributeValueContent(const AttributeValue& attributeValue, int& val)
+    {
+        int64_t int64Value = boost::get<int64_t>(attributeValue);
+        checkValueInIntRange(int64Value);
+        copyInt64Type(int64Value, val);
+    }
+
+    void OCRepresentation::retrieveAttributeValueContent(const AttributeValue& attributeValue, std::vector<int>& val)
+    {
+        std::vector<int64_t> int64Value = boost::get<std::vector<int64_t>>(attributeValue);
+        checkValueInIntRange(int64Value);
+        copyInt64Type(int64Value, val);
+    }
+
+    void OCRepresentation::retrieveAttributeValueContent(const AttributeValue& attributeValue, std::vector<std::vector<int>>& val)
+    {
+        std::vector<std::vector<int64_t>> int64Value = boost::get<std::vector<std::vector<int64_t>>>(attributeValue);
+        checkValueInIntRange(int64Value);
+        copyInt64Type(int64Value, val);
+    }
+
+    void OCRepresentation::retrieveAttributeValueContent(const AttributeValue& attributeValue, std::vector<std::vector<std::vector<int>>>& val)
+    {
+        std::vector<std::vector<std::vector<int64_t>>> int64Value = boost::get<std::vector<std::vector<std::vector<int64_t>>>>(attributeValue);
+        checkValueInIntRange(int64Value);
+        copyInt64Type(int64Value, val);
+    }
+
+    void OCRepresentation::assignAttributeValueContent(const int& val, AttributeValue& attributeValue)
+    {
+        int64_t value;
+        copyIntType(val, value);
+        attributeValue = value;
+    }
+
+    void OCRepresentation::assignAttributeValueContent(const std::vector<int>&  val, AttributeValue& attributeValue)
+    {
+        std::vector<int64_t> value;
+        copyIntType(val, value);
+        attributeValue = std::move(value);
+    }
+
+    void OCRepresentation::assignAttributeValueContent(const std::vector<std::vector<int>>&  val, AttributeValue& attributeValue)
+    {
+        std::vector<std::vector<int64_t>> value;
+        copyIntType(val, value);
+        attributeValue = std::move(value);
+    }
+
+    void OCRepresentation::assignAttributeValueContent(const std::vector<std::vector<std::vector<int>>>&  val, AttributeValue& attributeValue)
+    {
+        std::vector<std::vector<std::vector<int64_t>>> value;
+        copyIntType(val, value);
+        attributeValue = std::move(value);
+    }
+
     std::string OCRepresentation::getValueToString(const std::string& key) const
     {
         auto x = m_values.find(key);
diff --git a/resource/src/OCRepresentationInternal.cpp b/resource/src/OCRepresentationInternal.cpp
new file mode 100644 (file)
index 0000000..f839c7f
--- /dev/null
@@ -0,0 +1,122 @@
+/* *****************************************************************
+ *
+ * Copyright 2017 Microsoft
+ *
+ *
+ * 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 <limits.h>
+
+#include "OCRepresentationInternal.h"
+#include "OCException.h"
+#include "StringConstants.h"
+
+namespace OC {
+    void checkValueInIntRange(int64_t int64Value)
+    {
+        if ((int64Value > INT_MAX) || (int64Value < INT_MIN))
+        {
+            throw OCException(Exception::OUT_OF_INT_RANGE);
+        }
+    }
+
+    void checkValueInIntRange(const std::vector<int64_t>& int64Value)
+    {
+        for (int64_t value : int64Value)
+        {
+            checkValueInIntRange(value);
+        }
+    }
+
+    void checkValueInIntRange(const std::vector<std::vector<int64_t>>& int64Value)
+    {
+        for (const auto& value : int64Value)
+        {
+            checkValueInIntRange(value);
+        }
+    }
+
+    void checkValueInIntRange(const std::vector<std::vector<std::vector<int64_t>>>& int64Value)
+    {
+        for (const auto& value : int64Value)
+        {
+            checkValueInIntRange(value);
+        }
+    }
+
+    void copyInt64Type(int64_t int64Value, int& intValue)
+    {
+        intValue = (int)int64Value;
+    }
+
+    void copyInt64Type(const std::vector<int64_t>& int64Value, std::vector<int>& intValue)
+    {
+        intValue.resize(int64Value.size());
+        for (size_t index = 0; index < int64Value.size(); index++)
+        {
+            copyInt64Type(int64Value[index], intValue[index]);
+        }
+    }
+
+    void copyInt64Type(const std::vector<std::vector<int64_t>>& int64Value, std::vector<std::vector<int>>& intValue)
+    {
+        intValue.resize(int64Value.size());
+        for (size_t index = 0; index < int64Value.size(); index++)
+        {
+            copyInt64Type(int64Value[index], intValue[index]);
+        }
+    }
+
+    void copyInt64Type(const std::vector<std::vector<std::vector<int64_t>>>& int64Value, std::vector<std::vector<std::vector<int>>>& intValue)
+    {
+        intValue.resize(int64Value.size());
+        for (size_t index = 0; index < int64Value.size(); index++)
+        {
+            copyInt64Type(int64Value[index], intValue[index]);
+        }
+    }
+
+    void copyIntType(int intValue, int64_t& int64Value)
+    {
+        int64Value = intValue;
+    }
+
+    void copyIntType(const std::vector<int>& intValue, std::vector<int64_t>& int64Value)
+    {
+        int64Value.resize(intValue.size());
+        for (size_t index = 0; index < intValue.size(); index++)
+        {
+            copyIntType(intValue[index], int64Value[index]);
+        }
+    }
+
+    void copyIntType(const std::vector<std::vector<int>>& intValue, std::vector<std::vector<int64_t>>& int64Value)
+    {
+        int64Value.resize(intValue.size());
+        for (size_t index = 0; index < intValue.size(); index++)
+        {
+            copyIntType(intValue[index], int64Value[index]);
+        }
+    }
+
+    void copyIntType(const std::vector<std::vector<std::vector<int>>>& intValue, std::vector<std::vector<std::vector<int64_t>>>& int64Value)
+    {
+        int64Value.resize(intValue.size());
+        for (size_t index = 0; index < intValue.size(); index++)
+        {
+            copyIntType(intValue[index], int64Value[index]);
+        }
+    }
+}
\ No newline at end of file
index 290496b..abf9d55 100644 (file)
@@ -112,7 +112,8 @@ oclib_src = [
                'InProcClientWrapper.cpp',
                'OCResourceRequest.cpp',
                'CAManager.cpp',
-               'OCDirectPairing.cpp'
+               'OCDirectPairing.cpp',
+               'OCRepresentationInternal.cpp'
        ]
 
 if with_cloud:
index 38a079e..29f01f8 100644 (file)
@@ -306,7 +306,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         std::string groupId("AnyGroupId");
         OCRepresentation propertyValue;
-        propertyValue.setValue("AnyProperty", "AnyValue");
+        propertyValue.setValue("AnyProperty", std::string("AnyValue"));
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_EQ(OC_STACK_OK, accountManager->addPropertyValueToGroup(groupId, propertyValue,
@@ -318,7 +318,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         std::string groupId("AnyGroupId");
         OCRepresentation propertyValue;
-        propertyValue.setValue("AnyProperty", "AnyValue");
+        propertyValue.setValue("AnyProperty", std::string("AnyValue"));
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_ANY_THROW(accountManager->addPropertyValueToGroup(groupId, propertyValue,
@@ -331,7 +331,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         std::string groupId("AnyGroupId");
         OCRepresentation propertyValue;
-        propertyValue.setValue("AnyProperty", "AnyValue");
+        propertyValue.setValue("AnyProperty", std::string("AnyValue"));
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_EQ(OC_STACK_OK, accountManager->deletePropertyValueFromGroup(groupId, propertyValue,
@@ -343,7 +343,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         std::string groupId("AnyGroupId");
         OCRepresentation propertyValue;
-        propertyValue.setValue("AnyProperty", "AnyValue");
+        propertyValue.setValue("AnyProperty", std::string("AnyValue"));
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_ANY_THROW(accountManager->deletePropertyValueFromGroup(groupId, propertyValue,
@@ -356,7 +356,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         std::string groupId("AnyGroupId");
         OCRepresentation propertyValue;
-        propertyValue.setValue("AnyProperty", "AnyValue");
+        propertyValue.setValue("AnyProperty", std::string("AnyValue"));
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_EQ(OC_STACK_OK, accountManager->updatePropertyValueOnGroup(groupId, propertyValue,
@@ -368,7 +368,7 @@ namespace OCAccountManagerTest
         std::string host("coap://192.168.1.2:5000");
         std::string groupId("AnyGroupId");
         OCRepresentation propertyValue;
-        propertyValue.setValue("AnyProperty", "AnyValue");
+        propertyValue.setValue("AnyProperty", std::string("AnyValue"));
         OCAccountManager::Ptr accountManager = ConstructAccountManagerObject(host);
         EXPECT_TRUE(NULL != accountManager);
         EXPECT_ANY_THROW(accountManager->updatePropertyValueOnGroup(groupId, propertyValue,
index e0c3a45..9b1040e 100644 (file)
@@ -67,7 +67,7 @@ namespace OCRepresentationEncodingTest
         static const char piid1[] = "e987b8f5-527a-454e-98c1-1eef2e5f1cf5";
         const char devicename1[] = "device name";
         OCRepPayload *device = OCRepPayloadCreate();
-        EXPECT_TRUE(device);
+        EXPECT_NE((decltype(device))NULL, device);
         EXPECT_TRUE(OCRepPayloadAddResourceType(device, OC_RSRVD_RESOURCE_TYPE_DEVICE));
         EXPECT_TRUE(OCRepPayloadAddResourceType(device, "oic.d.tv"));
         EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_ID, sid1));
@@ -78,7 +78,7 @@ namespace OCRepresentationEncodingTest
 
         size_t dim[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
         char **dt = (char **)OICMalloc(sizeof(char *) * 1);
-        EXPECT_TRUE(dt);
+        EXPECT_NE((decltype(dt))NULL, dt);
         dt[0] = OICStrdup(OC_DATA_MODEL_VERSION);
         EXPECT_TRUE(OCRepPayloadSetStringArray(device, OC_RSRVD_DATA_MODEL_VERSION, (const char **)dt, dim));
         OICFree(dt[0]);
@@ -133,7 +133,7 @@ namespace OCRepresentationEncodingTest
         OCPayloadDestroy(parsedDevice);
 
         device = OCRepPayloadCreate();
-        EXPECT_TRUE(device);
+        EXPECT_NE((decltype(device))NULL, device);
         EXPECT_TRUE(OCRepPayloadAddResourceType(device, OC_RSRVD_RESOURCE_TYPE_DEVICE));
         EXPECT_TRUE(OCRepPayloadAddResourceType(device, "oic.d.tv"));
         EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_DEVICE_NAME, devicename1));
@@ -142,7 +142,7 @@ namespace OCRepresentationEncodingTest
         EXPECT_TRUE(OCRepPayloadSetPropString(device, OC_RSRVD_SPEC_VERSION, OC_SPEC_VERSION));
         size_t dim1[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
         char **dt1 = (char **)OICMalloc(sizeof(char *) * 2);
-        EXPECT_TRUE(dt1);
+        EXPECT_NE((decltype(dt1))NULL, dt1);
         dt1[0] = OICStrdup("ocf.res.1.1.0");
         dt1[1] = OICStrdup("ocf.sh.1.1.0");
         OCRepPayloadSetStringArray(device, OC_RSRVD_DATA_MODEL_VERSION, (const char**)dt1, dim1);
@@ -320,6 +320,7 @@ namespace OCRepresentationEncodingTest
         OC::OCRepresentation startRep;
         startRep.setNULL("NullAttr");
         startRep.setValue("IntAttr", 77);
+        startRep.setValue("Int64Attr", 77LL);
         startRep.setValue("DoubleAttr", 3.333);
         startRep.setValue("BoolAttr", true);
         startRep.setValue("StringAttr", std::string("String attr"));
@@ -352,6 +353,7 @@ namespace OCRepresentationEncodingTest
 
         EXPECT_TRUE(r.isNULL("NullAttr"));
         EXPECT_EQ(77, r.getValue<int>("IntAttr"));
+        EXPECT_EQ(77LL, r.getValue<int64_t>("Int64Attr"));
         EXPECT_EQ(3.333, r.getValue<double>("DoubleAttr"));
         EXPECT_EQ(true, r.getValue<bool>("BoolAttr"));
         EXPECT_STREQ("String attr", r.getValue<std::string>("StringAttr").c_str());
@@ -422,6 +424,7 @@ namespace OCRepresentationEncodingTest
         OC::OCRepresentation subRep;
         subRep.setNULL("NullAttr");
         subRep.setValue("IntAttr", 77);
+        subRep.setValue("Int64Attr", 77LL);
         subRep.setValue("DoubleAttr", 3.333);
         subRep.setValue("BoolAttr", true);
         subRep.setValue("StringAttr", std::string("String attr"));
@@ -453,6 +456,7 @@ namespace OCRepresentationEncodingTest
 
         EXPECT_TRUE(newSubRep.isNULL("NullAttr"));
         EXPECT_EQ(77, newSubRep.getValue<int>("IntAttr"));
+        EXPECT_EQ(77LL, newSubRep.getValue<int64_t>("Int64Attr"));
         EXPECT_EQ(3.333, newSubRep.getValue<double>("DoubleAttr"));
         EXPECT_EQ(true, newSubRep.getValue<bool>("BoolAttr"));
         EXPECT_STREQ("String attr", newSubRep.getValue<std::string>("StringAttr").c_str());
@@ -479,6 +483,7 @@ namespace OCRepresentationEncodingTest
         subRep3.setValue("StringAttr", std::string("String attr"));
 
         std::vector<int> iarr {1,2,3,4,5,6,7,8,9};
+        std::vector<int64_t> i64arr {1LL,2LL,3LL,4LL,5LL,6LL,7LL,8LL,9LL};
         std::vector<double> darr {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
         std::vector<bool> barr {false, true, false, false, true, true};
         std::vector<std::string> strarr {"item1", "item2", "item3", "item4"};
@@ -496,6 +501,7 @@ namespace OCRepresentationEncodingTest
         std::vector<OCByteString> bytestrarr {byteString1, byteString2 };
 
         startRep["iarr"] = iarr;
+        startRep["i64arr"] = i64arr;
         startRep["darr"] = darr;
         startRep["barr"] = barr;
         startRep["strarr"] = strarr;
@@ -525,6 +531,7 @@ namespace OCRepresentationEncodingTest
 
         // Test
         std::vector<int> iarr2 = r["iarr"];
+        std::vector<int64_t> i64arr2 = r["i64arr"];
         std::vector<double> darr2 = r["darr"];
         std::vector<bool> barr2 = r["barr"];
         std::vector<std::string> strarr2 = r["strarr"];
@@ -532,6 +539,7 @@ namespace OCRepresentationEncodingTest
         std::vector<OCByteString> bytestrarr2 = r["bytestrarr"];
 
         EXPECT_EQ(iarr, iarr2);
+        EXPECT_EQ(i64arr, i64arr2);
         EXPECT_EQ(darr, darr2);
         EXPECT_EQ(barr, barr2);
         EXPECT_EQ(strarr, strarr2);
@@ -560,6 +568,7 @@ namespace OCRepresentationEncodingTest
         subRep3.setValue("StringAttr", std::string("String attr"));
 
         std::vector<std::vector<int>> iarr {{1,2,3},{4,5,6},{7,8,9}};
+        std::vector<std::vector<int64_t>> i64arr {{1LL,2LL,3LL},{4LL,5LL,6LL},{7LL,8LL,9LL}};
         std::vector<std::vector<double>> darr {{1.1,2.2,3.3},{4.4,5.5,6.6},{7.7,8.8,9.9}};
         std::vector<std::vector<bool>> barr {{false, true}, {false, false}, {true, true}};
         std::vector<std::vector<std::string>> strarr {{"item1", "item2"}, {"item3", "item4"}};
@@ -592,6 +601,7 @@ namespace OCRepresentationEncodingTest
         };
 
         startRep["iarr"] = iarr;
+        startRep["i64arr"] = i64arr;
         startRep["darr"] = darr;
         startRep["barr"] = barr;
         startRep["strarr"] = strarr;
@@ -621,6 +631,7 @@ namespace OCRepresentationEncodingTest
 
         // Test
         std::vector<std::vector<int>> iarr2 = r["iarr"];
+        std::vector<std::vector<int64_t>> i64arr2 = r["i64arr"];
         std::vector<std::vector<double>> darr2 = r["darr"];
         std::vector<std::vector<bool>> barr2 = r["barr"];
         std::vector<std::vector<std::string>> strarr2 = r["strarr"];
@@ -628,6 +639,7 @@ namespace OCRepresentationEncodingTest
         std::vector<std::vector<OCByteString>> bytestrarr2 = r["bytestrarr"];
 
         EXPECT_EQ(iarr, iarr2);
+        EXPECT_EQ(i64arr, i64arr2);
         EXPECT_EQ(darr, darr2);
         EXPECT_EQ(barr, barr2);
         EXPECT_EQ(strarr, strarr2);
@@ -657,6 +669,7 @@ namespace OCRepresentationEncodingTest
         subRep3.setValue("StringAttr", std::string("String attr"));
 
         std::vector<std::vector<int>> iarr {{1,2,3},{4,6},{7,8,9}};
+        std::vector<std::vector<int64_t>> i64arr {{1LL,2LL,3LL},{4LL,6LL},{7LL,8LL,9LL}};
         std::vector<std::vector<double>> darr {{1.1,2.2,3.3},{4.4,5.5,6.6},{8.8,9.9}};
         std::vector<std::vector<bool>> barr {{false, true}, {false}, {true, true}};
         std::vector<std::vector<std::string>> strarr {{"item1"}, {"item3", "item4"}};
@@ -687,6 +700,7 @@ namespace OCRepresentationEncodingTest
         };
 
         startRep["iarr"] = iarr;
+        startRep["i64arr"] = i64arr;
         startRep["darr"] = darr;
         startRep["barr"] = barr;
         startRep["strarr"] = strarr;
@@ -722,6 +736,7 @@ namespace OCRepresentationEncodingTest
 
         // Test
         std::vector<std::vector<int>> iarr2 = r["iarr"];
+        std::vector<std::vector<int64_t>> i64arr2 = r["i64arr"];
         std::vector<std::vector<double>> darr2 = r["darr"];
         std::vector<std::vector<bool>> barr2 = r["barr"];
         std::vector<std::vector<std::string>> strarr2 = r["strarr"];
@@ -733,6 +748,7 @@ namespace OCRepresentationEncodingTest
         // Since std::vector doesn't require this, items received on the other side end up
         // being backfilled.  This section removes the backfilling
         iarr2[1].pop_back();
+        i64arr2[1].pop_back();
         darr2[2].pop_back();
         barr2[1].pop_back();
         strarr2[0].pop_back();
@@ -740,6 +756,7 @@ namespace OCRepresentationEncodingTest
         bytestrarr2[0].pop_back();
 
         EXPECT_EQ(iarr, iarr2);
+        EXPECT_EQ(i64arr, i64arr2);
         EXPECT_EQ(darr, darr2);
         EXPECT_EQ(barr, barr2);
         EXPECT_EQ(strarr, strarr2);
@@ -769,7 +786,11 @@ namespace OCRepresentationEncodingTest
         subRep3.setValue("StringAttr", std::string("String attr"));
 
         std::vector<std::vector<std::vector<int>>> iarr
-            {{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}},{{13,14,15},{16,17,18}}};
+        {{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}},{{13,14,15},{16,17,18}}};
+        std::vector<std::vector<std::vector<int64_t>>> i64arr
+        {{{1LL,2LL,3LL},{4LL,5LL,6LL}},
+         {{7LL,8LL,9LL},{10LL,11LL,12LL}},{{13LL,14LL,15LL},
+          {16LL,17LL,18LL}}};
         std::vector<std::vector<std::vector<double>>> darr
             {{{1.1,2.2,3.3},{4.4,5.5,6.6}},
                 {{7.7,8.7,9.7},{10.7,11.7,12.7}},
@@ -853,6 +874,7 @@ namespace OCRepresentationEncodingTest
         };
 
         startRep["iarr"] = iarr;
+        startRep["i64arr"] = i64arr;
         startRep["darr"] = darr;
         startRep["barr"] = barr;
         startRep["strarr"] = strarr;
@@ -882,6 +904,7 @@ namespace OCRepresentationEncodingTest
 
         // Test
         std::vector<std::vector<std::vector<int>>> iarr2 = r["iarr"];
+        std::vector<std::vector<std::vector<int64_t>>> i64arr2 = r["i64arr"];
         std::vector<std::vector<std::vector<double>>> darr2 = r["darr"];
         std::vector<std::vector<std::vector<bool>>> barr2 = r["barr"];
         std::vector<std::vector<std::vector<std::string>>> strarr2 = r["strarr"];
@@ -889,6 +912,7 @@ namespace OCRepresentationEncodingTest
         std::vector<std::vector<std::vector<OCByteString>>> bytestrarr2 = r["bytestrarr"];
 
         EXPECT_EQ(iarr, iarr2);
+        EXPECT_EQ(i64arr, i64arr2);
         EXPECT_EQ(darr, darr2);
         EXPECT_EQ(barr, barr2);
         EXPECT_EQ(strarr, strarr2);
@@ -921,6 +945,12 @@ namespace OCRepresentationEncodingTest
                 {{7,8,9},{10,12}},
                 {{13,14,15},{16,17,18}}
             };
+        std::vector<std::vector<std::vector<int64_t>>> i64arr
+            {
+                {{1LL,2LL,3LL},{4LL,5LL,6LL}},
+                {{7LL,8LL,9LL},{10LL,12LL}},
+                {{13LL,14LL,15LL},{16LL,17LL,18LL}}
+            };
         std::vector<std::vector<std::vector<double>>> darr
             {
                 {{1.1,2.2,3.3},{4.4,5.5,6.6}},
@@ -1005,6 +1035,7 @@ namespace OCRepresentationEncodingTest
         };
 
         startRep["iarr"] = iarr;
+        startRep["i64arr"] = i64arr;
         startRep["darr"] = darr;
         startRep["barr"] = barr;
         startRep["strarr"] = strarr;
@@ -1034,6 +1065,7 @@ namespace OCRepresentationEncodingTest
 
         // Test
         std::vector<std::vector<std::vector<int>>> iarr2 = r["iarr"];
+        std::vector<std::vector<std::vector<int64_t>>> i64arr2 = r["i64arr"];
         std::vector<std::vector<std::vector<double>>> darr2 = r["darr"];
         std::vector<std::vector<std::vector<bool>>> barr2 = r["barr"];
         std::vector<std::vector<std::vector<std::string>>> strarr2 = r["strarr"];
@@ -1044,6 +1076,7 @@ namespace OCRepresentationEncodingTest
         // Since std::vector doesn't require this, items received on the other side end up
         // being backfilled.  This section removes the backfilling
         iarr2[1][1].pop_back();
+        i64arr2[1][1].pop_back();
         darr2[1][1].pop_back();
         barr2[0][1].pop_back();
         strarr2[1][1].pop_back();
@@ -1052,6 +1085,7 @@ namespace OCRepresentationEncodingTest
         bytestrarr2[1][1].pop_back();
 
         EXPECT_EQ(iarr, iarr2);
+        EXPECT_EQ(i64arr, i64arr2);
         EXPECT_EQ(darr, darr2);
         EXPECT_EQ(barr, barr2);
         EXPECT_EQ(strarr, strarr2);
index b0fc992..3eb9b2f 100644 (file)
@@ -29,6 +29,52 @@ namespace OCRepresentationTest
     using std::string;
     using std::vector;
 
+    template <typename T>
+    struct ValueToStringParam
+    {
+        ValueToStringParam<T>(const char* expectedString, T expectedValue) :
+            m_expectedString(expectedString),
+            m_expectedValue(expectedValue)
+        {}
+
+        const char* m_expectedString;
+        T m_expectedValue;
+    };
+
+    template <typename T>
+    class OCRepresentationValueToStringTest : public testing::TestWithParam<ValueToStringParam<T>>
+    {
+    public:
+        OCRepresentationValueToStringTest<T>() :
+            m_attributeName("testValueName"),
+            m_expectedString(testing::TestWithParam<ValueToStringParam<T>>::GetParam().m_expectedString),
+            m_expectedValue(testing::TestWithParam<ValueToStringParam<T>>::GetParam().m_expectedValue)
+        {}
+
+        void SetUp()
+        {
+            m_rep.setValue(m_attributeName, m_expectedValue);
+        }
+
+    protected:
+        const char* m_attributeName;
+        const char* m_expectedString;
+        T m_expectedValue;
+        OCRepresentation m_rep;
+    };
+
+    class OCRepresentationInt64ValueToStringTest : public OCRepresentationValueToStringTest<int64_t>
+    {};
+
+    class OCRepresentation1VectorInt64ValueToStringTest : public OCRepresentationValueToStringTest<vector<int64_t>>
+    {};
+
+    class OCRepresentation2VectorInt64ValueToStringTest : public OCRepresentationValueToStringTest<vector<vector<int64_t>>>
+    {};
+
+    class OCRepresentation3VectorInt64ValueToStringTest : public OCRepresentationValueToStringTest<vector<vector<vector<int64_t>>>>
+    {};
+
     void parsedEqual(double expected, const std::string& actualStr)
     {
         double actual = boost::lexical_cast<double>(actualStr);
@@ -70,6 +116,20 @@ namespace OCRepresentationTest
         EXPECT_EQ("54321", rep[AttrName].getValueToString());
     }
 
+    INSTANTIATE_TEST_CASE_P(OCRepresentationInt64ValueToString,
+                            OCRepresentationInt64ValueToStringTest,
+                            ::testing::Values(
+        ValueToStringParam<int64_t>("-1", -1LL),
+        ValueToStringParam<int64_t>("0", 0LL),
+        ValueToStringParam<int64_t>("1", 1LL),
+        ValueToStringParam<int64_t>("9223372036854775807", INT64_MAX),
+        ValueToStringParam<int64_t>("-9223372036854775808", INT64_MIN)));
+    TEST_P(OCRepresentationInt64ValueToStringTest, shouldGetProperInt64String)
+    {
+        EXPECT_EQ(m_expectedString, m_rep.getValueToString(m_attributeName));
+        EXPECT_EQ(m_expectedString, m_rep[m_attributeName].getValueToString());
+    }
+
     TEST(OCRepresentationValueToString, Double)
     {
         static const std::string AttrName = "DoubleTest";
@@ -213,6 +273,60 @@ namespace OCRepresentationTest
         EXPECT_EQ(Expected, rep[AttrName].getValueToString());
     }
 
+    INSTANTIATE_TEST_CASE_P(OCRepresentation1VectorInt64ValueToString,
+                            OCRepresentation1VectorInt64ValueToStringTest,
+                            ::testing::Values(
+        ValueToStringParam<vector<int64_t>>("[-1 ]", {-1LL}),
+        ValueToStringParam<vector<int64_t>>("[1 ]", {1LL}),
+        ValueToStringParam<vector<int64_t>>("[0 ]", {0LL}),
+        ValueToStringParam<vector<int64_t>>("[9223372036854775807 ]", {INT64_MAX}),
+        ValueToStringParam<vector<int64_t>>("[-9223372036854775808 ]", {INT64_MIN}),
+        ValueToStringParam<vector<int64_t>>("[-1 0 9223372036854775807 ]", {-1LL, 0LL, INT64_MAX}),
+        ValueToStringParam<vector<int64_t>>("[-9223372036854775808 1 9223372036854775807 ]", {INT64_MIN, 1, INT64_MAX})));
+    TEST_P(OCRepresentation1VectorInt64ValueToStringTest, shouldGetProper1VectorInt64String)
+    {
+        EXPECT_EQ(m_expectedString, m_rep.getValueToString(m_attributeName));
+        EXPECT_EQ(m_expectedString, m_rep[m_attributeName].getValueToString());
+    }
+
+    INSTANTIATE_TEST_CASE_P(OCRepresentation2VectorInt64ValueToString,
+                            OCRepresentation2VectorInt64ValueToStringTest,
+                            ::testing::Values(
+        ValueToStringParam<vector<vector<int64_t>>>("[[-1 ] ]", {{-1LL}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[1 ] ]", {{1LL}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[0 ] ]", {{0LL}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[9223372036854775807 ] ]", {{INT64_MAX}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[-9223372036854775808 ] ]", {{INT64_MIN}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[-1 0 9223372036854775807 ] ]", {{-1LL, 0LL, INT64_MAX}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[-9223372036854775808 1 9223372036854775807 ] ]", {{INT64_MIN, 1, INT64_MAX}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[-1 ] [0 9223372036854775807 ] ]", {{-1LL}, {0LL, INT64_MAX}}),
+        ValueToStringParam<vector<vector<int64_t>>>("[[-9223372036854775808 1 ] [9223372036854775807 ] ]", {{INT64_MIN, 1}, {INT64_MAX}})));
+    TEST_P(OCRepresentation2VectorInt64ValueToStringTest, shouldGetProper1VectorInt64String)
+    {
+        EXPECT_EQ(m_expectedString, m_rep.getValueToString(m_attributeName));
+        EXPECT_EQ(m_expectedString, m_rep[m_attributeName].getValueToString());
+    }
+
+    INSTANTIATE_TEST_CASE_P(OCRepresentation3VectorInt64ValueToString,
+                            OCRepresentation3VectorInt64ValueToStringTest,
+                            ::testing::Values(
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-1 ] ] ]", {{{-1LL}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[1 ] ] ]", {{{1LL}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[0 ] ] ]", {{{0LL}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[9223372036854775807 ] ] ]", {{{INT64_MAX}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-9223372036854775808 ] ] ]", {{{INT64_MIN}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-1 0 9223372036854775807 ] ] ]", {{{-1LL, 0LL, INT64_MAX}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-9223372036854775808 1 9223372036854775807 ] ] ]", {{{INT64_MIN, 1, INT64_MAX}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-1 ] [0 9223372036854775807 ] ] ]", {{{-1LL},{0LL, INT64_MAX}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-9223372036854775808 1 ] [9223372036854775807 ] ] ]", {{{INT64_MIN, 1},{INT64_MAX}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-1 ] ] [[0 ] [9223372036854775807 ] ] ]", {{{-1LL}}, {{0LL}, {INT64_MAX}}}),
+        ValueToStringParam<vector<vector<vector<int64_t>>>>("[[[-9223372036854775808 ] [1 ] ] [[9223372036854775807 ] ] ]", {{{INT64_MIN}, {1}}, {{INT64_MAX}}})));
+    TEST_P(OCRepresentation3VectorInt64ValueToStringTest, shouldGetProper1VectorInt64String)
+    {
+        EXPECT_EQ(m_expectedString, m_rep.getValueToString(m_attributeName));
+        EXPECT_EQ(m_expectedString, m_rep[m_attributeName].getValueToString());
+    }
+
     TEST(OCRepresentationValueToString, DoubleVector)
     {
         static const std::string AttrName = "VectorTest";
@@ -1170,6 +1284,28 @@ namespace OCRepresentationTest
             }
         }
     }
+
+    TEST(OCRepresentationIterator, shouldReturnInt64ValueForAutoIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64";
+        int64_t expectedValue = 8;
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_FALSE(rep.empty());
+        ASSERT_EQ(1, rep.size());
+
+        for (auto& cur : rep)
+        {
+            EXPECT_EQ(expectedName, cur.attrname());
+            EXPECT_EQ(AttributeType::Integer, cur.type());
+            EXPECT_EQ(AttributeType::Integer, cur.base_type());
+            EXPECT_EQ(0u, cur.depth());
+            EXPECT_EQ(expectedValue, cur.getValue<int64_t>());
+        }
+    }
+
     // Iterator usage
     TEST(OCRepresentationIterator, iterator)
     {
@@ -1448,6 +1584,129 @@ namespace OCRepresentationTest
         }
     }
 
+    TEST(OCRepresentationIterator, shouldReturnInt64Depth1VectorForAutoIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64v";
+        vector<int64_t> expectedValue = {8};
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_EQ(1, rep.size());
+
+        for (auto& cur : rep)
+        {
+            EXPECT_EQ(expectedName, cur.attrname());
+            EXPECT_EQ(AttributeType::Vector, cur.type());
+            EXPECT_EQ(AttributeType::Integer, cur.base_type());
+            EXPECT_EQ(1u, cur.depth());
+            EXPECT_EQ(expectedValue, cur.getValue<vector<int64_t>>());
+        }
+    }
+
+    TEST(OCRepresentationIterator, shouldReturnInt64Depth2VectorForAutoIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64vv";
+        vector<vector<int64_t>> expectedValue = {{8}};
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_EQ(1, rep.size());
+
+        for (auto& cur : rep)
+        {
+            EXPECT_EQ(expectedName, cur.attrname());
+            EXPECT_EQ(AttributeType::Vector, cur.type());
+            EXPECT_EQ(AttributeType::Integer, cur.base_type());
+            EXPECT_EQ(2u, cur.depth());
+            EXPECT_EQ(expectedValue, cur.getValue<vector<vector<int64_t>>>());
+        }
+    }
+
+    TEST(OCRepresentationIterator, shouldReturnInt64Depth3VectorForAutoIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64vvv";
+        vector<vector<vector<int64_t>>> expectedValue = {{{8}}};
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_EQ(1, rep.size());
+
+        for (auto& cur : rep)
+        {
+            EXPECT_EQ(expectedName, cur.attrname());
+            EXPECT_EQ(AttributeType::Vector, cur.type());
+            EXPECT_EQ(AttributeType::Integer, cur.base_type());
+            EXPECT_EQ(3u, cur.depth());
+            EXPECT_EQ(expectedValue, cur.getValue<vector<vector<vector<int64_t>>>>());
+        }
+    }
+
+    TEST(OCRepresentationIterator, shouldReturnInt64Depth1VectorForIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64v";
+        vector<int64_t> expectedValue = {8};
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_FALSE(rep.empty());
+        ASSERT_EQ(1, rep.size());
+
+        for (OCRepresentation::iterator cur = rep.begin(); cur != rep.end(); cur++)
+        {
+            EXPECT_EQ(expectedName, cur->attrname());
+            EXPECT_EQ(AttributeType::Vector, cur->type());
+            EXPECT_EQ(AttributeType::Integer, cur->base_type());
+            EXPECT_EQ(1u, cur->depth());
+            EXPECT_EQ(expectedValue, cur->getValue<vector<int64_t>>());
+        }
+    }
+
+    TEST(OCRepresentationIterator, shouldReturnInt64Depth2VectorForIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64vv";
+        vector<vector<int64_t>> expectedValue = {{8}};
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_FALSE(rep.empty());
+        ASSERT_EQ(1, rep.size());
+
+        for (OCRepresentation::iterator cur = rep.begin(); cur != rep.end(); cur++)
+        {
+            EXPECT_EQ(expectedName, cur->attrname());
+            EXPECT_EQ(AttributeType::Vector, cur->type());
+            EXPECT_EQ(AttributeType::Integer, cur->base_type());
+            EXPECT_EQ(2u, cur->depth());
+            EXPECT_EQ(expectedValue, cur->getValue<vector<vector<int64_t>>>());
+        }
+    }
+
+    TEST(OCRepresentationIterator, shouldReturnInt64Depth3VectorForIterator)
+    {
+        OCRepresentation rep;
+        const char* expectedName = "int64vvv";
+        vector<vector<vector<int64_t>>> expectedValue = {{{8}}};
+
+        ASSERT_TRUE(rep.empty());
+        rep.setValue(expectedName, expectedValue);
+        ASSERT_FALSE(rep.empty());
+        ASSERT_EQ(1, rep.size());
+
+        for (OCRepresentation::iterator cur = rep.begin(); cur != rep.end(); cur++)
+        {
+            EXPECT_EQ(expectedName, cur->attrname());
+            EXPECT_EQ(AttributeType::Vector, cur->type());
+            EXPECT_EQ(AttributeType::Integer, cur->base_type());
+            EXPECT_EQ(3u, cur->depth());
+            EXPECT_EQ(expectedValue, cur->getValue<vector<vector<vector<int64_t>>>>());
+        }
+    }
+
     TEST(OCRepresentationHostTest, ValidHost)
     {
         OCDevAddr addr = {OC_DEFAULT_ADAPTER, OC_IP_USE_V6, 5000, "fe80::1%eth0", 0, "", ""};
index 87d33d6..328f110 100755 (executable)
@@ -242,8 +242,8 @@ int main()
                     msg.setMediaContents(mediaContents);
 
                     OC::OCRepresentation rep;
-                    rep.setValue("Key1", "Value1");
-                    rep.setValue("Key2", "Value2");
+                    rep.setValue("Key1", std::string("Value1"));
+                    rep.setValue("Key2", std::string("Value2"));
                     msg.setExtraInfo(rep);
 
                     mainMessageId = msg.getMessageId();