Fix config type of cpu quota
authorPiotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
Thu, 8 May 2014 10:37:20 +0000 (12:37 +0200)
committerJan Olszak <j.olszak@samsung.com>
Mon, 19 May 2014 11:47:16 +0000 (13:47 +0200)
[Bug/Feature]   Type in config was double instead of int64
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: I77ee8fd87faf798a21d2327cb6955be3482e78a0

common/config/configuration.cpp
common/config/configuration.hpp
server/container-config.hpp
unit_tests/config/ut-configuration.cpp

index d8dd143..fe22aa1 100644 (file)
@@ -95,6 +95,11 @@ template<> json_object* ConfigurationBase::getJsonObjFromValue(const int& val)
     return json_object_new_int(val);
 }
 
+template<> json_object* ConfigurationBase::getJsonObjFromValue(const std::int64_t& val)
+{
+    return json_object_new_int64(val);
+}
+
 template<> json_object* ConfigurationBase::getJsonObjFromValue(const bool& val)
 {
     return json_object_new_boolean(val);
@@ -119,6 +124,11 @@ template<> int ConfigurationBase::getValueFromJsonObj(json_object* obj)
     return json_object_get_int(obj);
 }
 
+template<> std::int64_t ConfigurationBase::getValueFromJsonObj(json_object* obj)
+{
+    return json_object_get_int64(obj);
+}
+
 template<> bool ConfigurationBase::getValueFromJsonObj(json_object* obj)
 {
     return json_object_get_boolean(obj);
index f614b7f..810721a 100644 (file)
@@ -167,9 +167,9 @@ protected:
             throw ConfigException();
         }
         int len = json_object_array_length(array);
-        val.resize(len);
+        val.resize(static_cast<size_t>(len));
         for (int i = 0; i < len; ++i) {
-            val[i] = getValueFromJsonObj<T>(json_object_array_get_idx(array, i));
+            val[static_cast<size_t>(i)] = getValueFromJsonObj<T>(json_object_array_get_idx(array, i));
         }
     }
 
@@ -227,10 +227,10 @@ protected:
         }
 
         int len = json_object_array_length(obj);
-        val.resize(len);
+        val.resize(static_cast<size_t>(len));
         for (int i = 0; i < len; ++i) {
             json_object* arrayObj = json_object_array_get_idx(obj, i);
-            val[i].process(arrayObj, ConfigProcessMode::Read);
+            val[static_cast<size_t>(i)].process(arrayObj, ConfigProcessMode::Read);
         }
     }
 
index 1e35ca7..f34b929 100644 (file)
@@ -50,12 +50,12 @@ struct ContainerConfig : public config::ConfigurationBase {
     /**
      * Container's CFS quota in us when it's in the foreground
      */
-    double cpuQuotaForeground;
+    std::int64_t cpuQuotaForeground;
 
     /**
      * Container's CFS quota in us when it's in the background
      */
-    double cpuQuotaBackground;
+    std::int64_t cpuQuotaBackground;
 
     /**
      * Path to containers dbus unix socket
index 657d586..cbb84eb 100644 (file)
@@ -47,6 +47,7 @@ struct TestConfig : public ConfigurationBase {
     };
 
     int intVal;
+    std::int64_t int64Val;
     std::string stringVal;
     double floatVal;
     bool boolVal;
@@ -60,6 +61,7 @@ struct TestConfig : public ConfigurationBase {
 
     CONFIG_REGISTER {
         CONFIG_VALUE(intVal)
+        CONFIG_VALUE(int64Val)
         CONFIG_VALUE(stringVal)
         CONFIG_VALUE(floatVal)
         CONFIG_VALUE(boolVal)
@@ -75,6 +77,7 @@ struct TestConfig : public ConfigurationBase {
     bool operator== (const TestConfig& rhs) const
     {
         return (rhs.intVal == intVal &&
+                rhs.int64Val == int64Val &&
                 rhs.stringVal == stringVal &&
                 rhs.floatVal == floatVal &&
                 rhs.boolVal == boolVal &&
@@ -91,6 +94,7 @@ struct TestConfig : public ConfigurationBase {
  */
 const std::string json_test_string =
     "{ \"intVal\": 12345, "
+    "\"int64Val\": -1234567890123456789, "
     "\"stringVal\": \"blah\", "
     "\"floatVal\": -1.234, "
     "\"boolVal\": true, "
@@ -111,6 +115,7 @@ BOOST_AUTO_TEST_CASE(SimpleTypesTest)
     BOOST_REQUIRE_NO_THROW(testConfig.parseStr(json_test_string));
 
     BOOST_CHECK_EQUAL(12345, testConfig.intVal);
+    BOOST_CHECK_EQUAL(-1234567890123456789ll, testConfig.int64Val);
     BOOST_CHECK_CLOSE(-1.234, testConfig.floatVal, max_float_error);
     BOOST_CHECK_EQUAL("blah", testConfig.stringVal);
     BOOST_CHECK_EQUAL(true, testConfig.boolVal);