From: Sangwan Kwon Date: Wed, 20 Nov 2019 09:44:21 +0000 (+0900) Subject: Fix policy-value to include stringfied value X-Git-Tag: submit/tizen/20200810.073515~154 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b0d17a5f2a5879c263764fc2d057b392029359b8;p=platform%2Fcore%2Fsecurity%2Fvist.git Fix policy-value to include stringfied value Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/sdk/policy-value.hpp b/src/vist/sdk/policy-value.hpp index 75f895c..a8d2003 100644 --- a/src/vist/sdk/policy-value.hpp +++ b/src/vist/sdk/policy-value.hpp @@ -16,32 +16,17 @@ #pragma once -#include +#include #include namespace vist { namespace policy { -// TODO: Support various value type struct PolicyValue final { - enum class Type { - Integer, - String, - None - }; - - explicit PolicyValue(int value) : type(Type::Integer) - { - this->buffer << value; - } - - explicit PolicyValue(const std::string& value) : type(Type::String) - { - this->buffer << value; - } - explicit PolicyValue() noexcept = default; + explicit PolicyValue(int value) : stringfied(Stringfy::Dump(value)) {} + explicit PolicyValue(const std::string& value) : stringfied(Stringfy::Dump(value)) {} ~PolicyValue() = default; PolicyValue(const PolicyValue&) = default; @@ -50,32 +35,28 @@ struct PolicyValue final { PolicyValue(PolicyValue&&) noexcept = default; PolicyValue& operator=(PolicyValue&&) noexcept = default; - inline Type getType() const noexcept + inline std::string dump() const noexcept { - return this->type; + return this->stringfied; } - operator int() const + inline Stringfy::Type getType() const { - auto clone = this->buffer; - int out; - clone >> out; + return Stringfy::GetType(this->stringfied); + } - return out; + operator int() const + { + return Stringfy::Restore(this->stringfied); } operator std::string() const { - auto clone = this->buffer; - std::string out; - clone >> out; - - return out; + return Stringfy::Restore(this->stringfied); } private: - Archive buffer; - Type type = Type::None; + std::string stringfied; }; } // namespace policy diff --git a/src/vist/sdk/tests/sdk.cpp b/src/vist/sdk/tests/sdk.cpp index 2c8942b..9b2ceb7 100644 --- a/src/vist/sdk/tests/sdk.cpp +++ b/src/vist/sdk/tests/sdk.cpp @@ -25,6 +25,7 @@ namespace { int g_value = -1; } // anonymous namespace +using namespace vist; using namespace vist::policy; class TestPolicyModel : public PolicyModel { @@ -50,15 +51,24 @@ public: TEST(PolicySDKTests, policy_value_int) { PolicyValue value(1); - EXPECT_EQ(PolicyValue::Type::Integer, value.getType()); - EXPECT_EQ((int)value, 1); + EXPECT_EQ(Stringfy::Type::Integer, value.getType()); + EXPECT_EQ(static_cast(value), 1); } TEST(PolicySDKTests, policy_value_string) { - PolicyValue value(std::string("text")); - EXPECT_EQ(PolicyValue::Type::String, value.getType()); - EXPECT_EQ((std::string)value, "text"); + PolicyValue value("TEXT"); + EXPECT_EQ(Stringfy::Type::String, value.getType()); + EXPECT_EQ(static_cast(value), "TEXT"); +} + +TEST(PolicySDKTests, policy_value_dump) +{ + PolicyValue intValue(1); + EXPECT_EQ("I/1", intValue.dump()); + + PolicyValue strValue("TEXT"); + EXPECT_EQ("S/TEXT", strValue.dump()); } TEST(PolicySDKTests, policy_model)